diff --git a/spec/package-spec.coffee b/spec/package-spec.coffee index c106689f2..d518613a2 100644 --- a/spec/package-spec.coffee +++ b/spec/package-spec.coffee @@ -13,29 +13,29 @@ describe "Package", -> it "does not activate it", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-incompatible-native-module') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack.isCompatible()).toBe false expect(pack.incompatibleModules[0].name).toBe 'native-module' expect(pack.incompatibleModules[0].path).toBe path.join(packagePath, 'node_modules', 'native-module') it "utilizes _atomModuleCache if present to determine the package's native dependencies", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-ignored-incompatible-native-module') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack.getNativeModuleDependencyPaths().length).toBe(1) # doesn't see the incompatible module expect(pack.isCompatible()).toBe true packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-cached-incompatible-native-module') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack.isCompatible()).toBe false it "caches the incompatible native modules in local storage", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-incompatible-native-module') - expect(new Package(path: packagePath, packageManager: atom.packages).isCompatible()).toBe false + expect(new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles).isCompatible()).toBe false expect(global.localStorage.getItem.callCount).toBe 1 expect(global.localStorage.setItem.callCount).toBe 1 - expect(new Package(path: packagePath, packageManager: atom.packages).isCompatible()).toBe false + expect(new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles).isCompatible()).toBe false expect(global.localStorage.getItem.callCount).toBe 2 expect(global.localStorage.setItem.callCount).toBe 1 @@ -49,7 +49,7 @@ describe "Package", -> it "returns a promise resolving to the results of `apm rebuild`", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-index') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) rebuildCallbacks = [] spyOn(pack, 'runRebuildProcess').andCallFake ((callback) -> rebuildCallbacks.push(callback)) @@ -63,7 +63,7 @@ describe "Package", -> it "persists build failures in local storage", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-index') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack.isCompatible()).toBe true expect(pack.getBuildFailureOutput()).toBeNull() @@ -79,7 +79,7 @@ describe "Package", -> expect(pack.isCompatible()).toBe false # A different package instance has the same failure output (simulates reload) - pack2 = new Package(path: packagePath, packageManager: atom.packages) + pack2 = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack2.getBuildFailureOutput()).toBe 'It is broken' expect(pack2.isCompatible()).toBe false @@ -92,7 +92,7 @@ describe "Package", -> it "sets cached incompatible modules to an empty array when the rebuild completes (there may be a build error, but rebuilding *deletes* native modules)", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-incompatible-native-module') - pack = new Package(path: packagePath, packageManager: atom.packages) + pack = new Package(path: packagePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) expect(pack.getIncompatibleNativeModules().length).toBeGreaterThan(0) @@ -118,14 +118,14 @@ describe "Package", -> it "loads and applies css", -> expect(getComputedStyle(editorElement).paddingBottom).not.toBe "1234px" themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-with-index-css') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() expect(getComputedStyle(editorElement).paddingTop).toBe "1234px" it "parses, loads and applies less", -> expect(getComputedStyle(editorElement).paddingBottom).not.toBe "1234px" themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-with-index-less') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() expect(getComputedStyle(editorElement).paddingTop).toBe "4321px" @@ -136,7 +136,7 @@ describe "Package", -> expect(getComputedStyle(editorElement).paddingBottom).not.toBe("103px") themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-with-package-file') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() expect(getComputedStyle(editorElement).paddingTop).toBe("101px") expect(getComputedStyle(editorElement).paddingRight).toBe("102px") @@ -149,7 +149,7 @@ describe "Package", -> expect(getComputedStyle(editorElement).paddingBottom).not.toBe "30px" themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-without-package-file') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() expect(getComputedStyle(editorElement).paddingTop).toBe "10px" expect(getComputedStyle(editorElement).paddingRight).toBe "20px" @@ -158,7 +158,7 @@ describe "Package", -> describe "reloading a theme", -> beforeEach -> themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-with-package-file') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() it "reloads without readding to the stylesheets list", -> @@ -169,7 +169,7 @@ describe "Package", -> describe "events", -> beforeEach -> themePath = atom.project.getDirectories()[0]?.resolve('packages/theme-with-package-file') - theme = new ThemePackage(path: themePath, packageManager: atom.packages) + theme = new ThemePackage(path: themePath, packageManager: atom.packages, config: atom.config, styleManager: atom.styles) theme.activate() it "deactivated event fires on .deactivate()", -> diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 60ef08ed7..cbb4b218c 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -142,12 +142,12 @@ class AtomEnvironment extends Model @commands = new CommandRegistry registerDefaultCommands(this) - PackageManager = require './package-manager' - @packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode, @config}) - StyleManager = require './style-manager' @styles = new StyleManager({configDirPath}) + PackageManager = require './package-manager' + @packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode, @config, styleManager: @styles}) + ThemeManager = require './theme-manager' @themes = new ThemeManager({ packageManager: @packages, configDirPath, resourcePath, safeMode, @config, diff --git a/src/package-manager.coffee b/src/package-manager.coffee index 9b382d093..09a76c109 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -28,7 +28,7 @@ ThemePackage = require './theme-package' # settings and also by calling `enablePackage()/disablePackage()`. module.exports = class PackageManager - constructor: ({configDirPath, @devMode, safeMode, @resourcePath, @config}) -> + constructor: ({configDirPath, @devMode, safeMode, @resourcePath, @config, @styleManager}) -> @emitter = new Emitter @activationHookEmitter = new Emitter @packageDirPaths = [] @@ -354,9 +354,9 @@ class PackageManager return null if metadata.theme - pack = new ThemePackage({path: packagePath, metadata, packageManager: this}) + pack = new ThemePackage({path: packagePath, metadata, packageManager: this, @config, @styleManager}) else - pack = new Package({path: packagePath, metadata, packageManager: this}) + pack = new Package({path: packagePath, metadata, packageManager: this, @config, @styleManager}) pack.load() @loadedPackages[pack.name] = pack @emitter.emit 'did-load-package', pack diff --git a/src/package.coffee b/src/package.coffee index 584000b57..97bfd774e 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -29,7 +29,7 @@ class Package Section: Construction ### - constructor: ({@path, @metadata, @packageManager}) -> + constructor: ({@path, @metadata, @packageManager, @config, @styleManager}) -> @emitter = new Emitter @metadata ?= @packageManager.loadPackageMetadata(@path) @bundledPackage = @packageManager.isBundledPackagePath(@path) @@ -54,10 +54,10 @@ class Package ### enable: -> - atom.config.removeAtKeyPath('core.disabledPackages', @name) + @config.removeAtKeyPath('core.disabledPackages', @name) disable: -> - atom.config.pushAtKeyPath('core.disabledPackages', @name) + @config.pushAtKeyPath('core.disabledPackages', @name) isTheme: -> @metadata?.theme? @@ -114,7 +114,7 @@ class Package @activateConfig() @activateStylesheets() if @mainModule? and not @mainActivated - @mainModule.activate?(atom.packages.getPackageState(@name) ? {}) + @mainModule.activate?(@packageManager.getPackageState(@name) ? {}) @mainActivated = true @activateServices() catch error @@ -128,7 +128,7 @@ class Package @requireMainModule() unless @mainModule? if @mainModule? if @mainModule.config? and typeof @mainModule.config is 'object' - atom.config.setSchema @name, {type: 'object', properties: @mainModule.config} + @config.setSchema @name, {type: 'object', properties: @mainModule.config} @mainModule.activateConfig?() @configActivated = true @@ -146,13 +146,13 @@ class Package else context = undefined - @stylesheetDisposables.add(atom.styles.addStyleSheet(source, {sourcePath, priority, context})) + @stylesheetDisposables.add(@styleManager.addStyleSheet(source, {sourcePath, priority, context})) @stylesheetsActivated = true activateResources: -> @activationDisposables = new CompositeDisposable - keymapIsDisabled = _.include(atom.config.get("core.packagesWithKeymapsDisabled") ? [], @name) + keymapIsDisabled = _.include(@config.get("core.packagesWithKeymapsDisabled") ? [], @name) if keymapIsDisabled @deactivateKeymaps() else @@ -207,24 +207,24 @@ class Package for version, methodName of versions if typeof @mainModule[methodName] is 'function' servicesByVersion[version] = @mainModule[methodName]() - @activationDisposables.add atom.packages.serviceHub.provide(name, servicesByVersion) + @activationDisposables.add @packageManager.serviceHub.provide(name, servicesByVersion) for name, {versions} of @metadata.consumedServices for version, methodName of versions if typeof @mainModule[methodName] is 'function' - @activationDisposables.add atom.packages.serviceHub.consume(name, version, @mainModule[methodName].bind(@mainModule)) + @activationDisposables.add @packageManager.serviceHub.consume(name, version, @mainModule[methodName].bind(@mainModule)) return loadKeymaps: -> if @bundledPackage and @packageManager.packagesCache[@name]? - @keymaps = (["#{atom.packages.resourcePath}#{path.sep}#{keymapPath}", keymapObject] for keymapPath, keymapObject of @packageManager.packagesCache[@name].keymaps) + @keymaps = (["#{@packageManager.resourcePath}#{path.sep}#{keymapPath}", keymapObject] for keymapPath, keymapObject of @packageManager.packagesCache[@name].keymaps) else @keymaps = @getKeymapPaths().map (keymapPath) -> [keymapPath, CSON.readFileSync(keymapPath) ? {}] return loadMenus: -> if @bundledPackage and @packageManager.packagesCache[@name]? - @menus = (["#{atom.packages.resourcePath}#{path.sep}#{menuPath}", menuObject] for menuPath, menuObject of @packageManager.packagesCache[@name].menus) + @menus = (["#{@packageManager.resourcePath}#{path.sep}#{menuPath}", menuObject] for menuPath, menuObject of @packageManager.packagesCache[@name].menus) else @menus = @getMenuPaths().map (menuPath) -> [menuPath, CSON.readFileSync(menuPath) ? {}] return @@ -394,7 +394,7 @@ class Package if @bundledPackage and @packageManager.packagesCache[@name]? if @packageManager.packagesCache[@name].main - @mainModulePath = "#{atom.packages.resourcePath}#{path.sep}#{@packageManager.packagesCache[@name].main}" + @mainModulePath = "#{@packageManager.resourcePath}#{path.sep}#{@packageManager.packagesCache[@name].main}" else @mainModulePath = null else @@ -467,7 +467,7 @@ class Package @activationHookSubscriptions = new CompositeDisposable for hook in @getActivationHooks() do (hook) => - @activationHookSubscriptions.add(atom.packages.onDidTriggerActivationHook(hook, => @activateNow())) if hook? and _.isString(hook) and hook.trim().length > 0 + @activationHookSubscriptions.add(@packageManager.onDidTriggerActivationHook(hook, => @activateNow())) if hook? and _.isString(hook) and hook.trim().length > 0 return @@ -529,7 +529,7 @@ class Package isCompatible: -> return @compatible if @compatible? - if @path.indexOf(path.join(atom.packages.resourcePath, 'node_modules') + path.sep) is 0 + if @path.indexOf(path.join(@packageManager.resourcePath, 'node_modules') + path.sep) is 0 # Bundled packages are always considered compatible @compatible = true else if @getMainModulePath() @@ -565,7 +565,7 @@ class Package stderr = '' stdout = '' new BufferedProcess({ - command: atom.packages.getApmPath() + command: @packageManager.getApmPath() args: ['rebuild', '--no-color'] options: {cwd: @path} stderr: (output) -> stderr += output diff --git a/src/theme-package.coffee b/src/theme-package.coffee index 6d0a88052..084728869 100644 --- a/src/theme-package.coffee +++ b/src/theme-package.coffee @@ -7,10 +7,10 @@ class ThemePackage extends Package getStyleSheetPriority: -> 1 enable: -> - atom.config.unshiftAtKeyPath('core.themes', @name) + @config.unshiftAtKeyPath('core.themes', @name) disable: -> - atom.config.removeAtKeyPath('core.themes', @name) + @config.removeAtKeyPath('core.themes', @name) load: -> @loadTime = 0