mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Build packages using paths instead of filenames
This commit is contained in:
parent
bdac42b188
commit
3b4f07701b
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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']
|
||||
|
@ -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) ->
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user