diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 8331d5ce7..fc8e7fff1 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -18,14 +18,19 @@ require.paths.unshift(fixturePackagesPath) [bindingSetsToRestore, bindingSetsByFirstKeystrokeToRestore] = [] # Specs rely on TextMate bundles (but not atom packages) -textMatePackages = atom.loadTextMatePackages() +window.loadTextMatePackages = -> + TextMatePackage = require 'text-mate-package' + config.packageDirPaths.unshift(fixturePackagesPath) + window.textMatePackages = [] + for path in atom.getPackagePaths() when TextMatePackage.testName(path) + window.textMatePackages.push atom.loadPackage(fs.base(path)) + +window.loadTextMatePackages() beforeEach -> window.fixturesProject = new Project(require.resolve('fixtures')) window.resetTimeouts() - atom.loadedPackages = _.clone(textMatePackages) - # used to reset keymap after each spec bindingSetsToRestore = _.clone(keymap.bindingSets) bindingSetsByFirstKeystrokeToRestore = _.clone(keymap.bindingSetsByFirstKeystroke) diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 15a4e465a..260589325 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -7,7 +7,7 @@ class AtomPackage extends Package keymapsDirPath: null autoloadStylesheets: true - constructor: (@name) -> + constructor: -> super @keymapsDirPath = fs.join(@path, 'keymaps') @@ -16,7 +16,7 @@ class AtomPackage extends Package @loadMetadata() @loadKeymaps() @loadStylesheets() if @autoloadStylesheets - rootView?.activatePackage(@name, this) unless @isDirectory + rootView?.activatePackage(@name, this) if require.resolve(@path) catch e console.warn "Failed to load package named '#{@name}'", e.stack this diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 70c821ed0..44bad21a5 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -15,20 +15,16 @@ _.extend atom, loadedPackages: [] loadPackage: (name) -> - if pack = Package.build(name) - @loadedPackages.push(pack) - pack.load() - pack - - loadTextMatePackages: -> - @loadPackage(name) for name in @getPackageNames() when TextMatePackage.testName(name) + packagePath = _.find @getPackagePaths(), (packagePath) -> fs.base(packagePath) == name + pack = Package.build(packagePath) + pack?.load() loadPackages: -> textMatePackages = [] - for name in @getPackageNames() - pack = Package.build(name) + for path in @getPackagePaths() + pack = Package.build(path) @loadedPackages.push(pack) - if pack instanceof TextMatePackage and pack.name isnt 'text.tmbundle' + if pack instanceof TextMatePackage and fs.base(pack.path) isnt 'text.tmbundle' textMatePackages.push(pack) if pack else pack.load() @@ -38,17 +34,17 @@ _.extend atom, getLoadedPackages: -> _.clone(@loadedPackages) - getPackageNames: -> + getPackagePaths: -> disabledPackages = config.get("core.disabledPackages") ? [] - packageNames = [] + packagePaths = [] for packageDirPath in config.packageDirPaths - for packagePath in fs.list(packageDirPath) when fs.isDirectory(packagePath) - packageName = fs.base(packagePath) - continue if packageName in disabledPackages - continue if packageName in packageNames - packageNames.push(packageName) + for packagePath in fs.list(packageDirPath) + continue if not fs.isDirectory(packagePath) + continue if fs.base(packagePath) in disabledPackages + continue if packagePath in packagePaths + packagePaths.push(packagePath) - packageNames + packagePaths loadThemes: -> themeNames = config.get("core.themes") ? ['atom-dark-ui', 'atom-dark-syntax'] diff --git a/src/app/package.coffee b/src/app/package.coffee index 4d571f506..89ece0a15 100644 --- a/src/app/package.coffee +++ b/src/app/package.coffee @@ -3,39 +3,29 @@ _ = require 'underscore' module.exports = class Package - @resolve: (name) -> - path = require.resolve(name, verifyExistence: false) - return path if path - throw new Error("No package found named '#{name}'") - - @build: (name) -> + @build: (path) -> TextMatePackage = require 'text-mate-package' AtomPackage = require 'atom-package' - path = @resolve(name) - newStylePackage = _.find fs.list(path), (filePath) => - /package\.[cj]son$/.test filePath + oldStylePackage = _.find fs.list(path), (filePath) => + /index\.coffee$/.test filePath - if TextMatePackage.testName(name) - new TextMatePackage(name) + if TextMatePackage.testName(path) + new TextMatePackage(path) else - if newStylePackage or fs.isDirectory(path) - new AtomPackage(name) + if not oldStylePackage + new AtomPackage(path) else try - PackageClass = require name - new PackageClass(name) if typeof PackageClass is 'function' + PackageClass = require path + new PackageClass(path) if typeof PackageClass is 'function' catch e - console.warn "Failed to load package named '#{name}'", e.stack + console.warn "Failed to load package at '#{path}'", e.stack name: null path: null - isDirectory: false - module: null - constructor: (@name) -> - @path = Package.resolve(@name) - @isDirectory = fs.isDirectory(@path) - @path = fs.directory(@path) unless @isDirectory + constructor: (@path) -> + @name = fs.base(@path) activate: (rootView) -> diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 97eea6189..2a54d12fe 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -28,7 +28,7 @@ class TextMatePackage extends Package try @loadGrammars() catch e - console.warn "Failed to load package named '#{@name}'", e.stack + console.warn "Failed to load package at '#{@path}'", e.stack this getGrammars: -> @grammars diff --git a/src/packages/snippets/spec/snippets-spec.coffee b/src/packages/snippets/spec/snippets-spec.coffee index d07fc9d4e..6b8c5cdc2 100644 --- a/src/packages/snippets/spec/snippets-spec.coffee +++ b/src/packages/snippets/spec/snippets-spec.coffee @@ -13,7 +13,11 @@ describe "Snippets extension", -> rootView = new RootView(require.resolve('fixtures/sample.js')) spyOn(LoadSnippetsTask.prototype, 'start') - atom.loadPackage("package-with-snippets") + packageWithSnippets = atom.loadPackage("package-with-snippets") + + spyOn(atom, "getLoadedPackages").andCallFake -> + window.textMatePackages.concat([packageWithSnippets]) + atom.loadPackage("snippets") editor = rootView.getActiveEditor()