mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-27 10:28:31 +08:00
rm(package): Remove unused grammars, settings, scopedProperties
This commit is contained in:
parent
476431bcb1
commit
4400f98f65
6 changed files with 1 additions and 206 deletions
|
@ -1,10 +0,0 @@
|
||||||
module.exports =
|
|
||||||
activate: ->
|
|
||||||
|
|
||||||
deactivate: ->
|
|
||||||
|
|
||||||
consumeFirstServiceV3: ->
|
|
||||||
|
|
||||||
consumeFirstServiceV4: ->
|
|
||||||
|
|
||||||
consumeSecondService: ->
|
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"name": "package-with-consumed-services",
|
|
||||||
|
|
||||||
"consumedServices": {
|
|
||||||
"service-1": {
|
|
||||||
"versions": {
|
|
||||||
">=0.2 <=0.3.6": "consumeFirstServiceV3",
|
|
||||||
"^0.4.1": "consumeFirstServiceV4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"service-2": {
|
|
||||||
"versions": {
|
|
||||||
"0.2.1 || 0.2.2": "consumeSecondService"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
module.exports =
|
|
||||||
activate: ->
|
|
||||||
|
|
||||||
deactivate: ->
|
|
||||||
|
|
||||||
provideFirstServiceV3: ->
|
|
||||||
'first-service-v3'
|
|
||||||
|
|
||||||
provideFirstServiceV4: ->
|
|
||||||
'first-service-v4'
|
|
||||||
|
|
||||||
provideSecondService: ->
|
|
||||||
'second-service'
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"name": "package-with-provided-services",
|
|
||||||
|
|
||||||
"providedServices": {
|
|
||||||
"service-1": {
|
|
||||||
"description": "The first service",
|
|
||||||
"versions": {
|
|
||||||
"0.3.1": "provideFirstServiceV3",
|
|
||||||
"0.4.1": "provideFirstServiceV4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"service-2": {
|
|
||||||
"description": "The second service",
|
|
||||||
"versions": {
|
|
||||||
"0.2.1": "provideSecondService"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -377,55 +377,6 @@ describe "PackageManager", ->
|
||||||
|
|
||||||
expect(count).toBe 4
|
expect(count).toBe 4
|
||||||
|
|
||||||
describe "scoped-property loading", ->
|
|
||||||
it "loads the scoped properties", ->
|
|
||||||
waitsForPromise ->
|
|
||||||
NylasEnv.packages.activatePackage("package-with-settings")
|
|
||||||
|
|
||||||
runs ->
|
|
||||||
expect(NylasEnv.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBe '^a'
|
|
||||||
|
|
||||||
describe "service registration", ->
|
|
||||||
it "registers the package's provided and consumed services", ->
|
|
||||||
consumerModule = require "./fixtures/packages/package-with-consumed-services"
|
|
||||||
firstServiceV3Disposed = false
|
|
||||||
firstServiceV4Disposed = false
|
|
||||||
secondServiceDisposed = false
|
|
||||||
spyOn(consumerModule, 'consumeFirstServiceV3').andReturn(new Disposable -> firstServiceV3Disposed = true)
|
|
||||||
spyOn(consumerModule, 'consumeFirstServiceV4').andReturn(new Disposable -> firstServiceV4Disposed = true)
|
|
||||||
spyOn(consumerModule, 'consumeSecondService').andReturn(new Disposable -> secondServiceDisposed = true)
|
|
||||||
|
|
||||||
waitsForPromise ->
|
|
||||||
NylasEnv.packages.activatePackage("package-with-consumed-services")
|
|
||||||
|
|
||||||
waitsForPromise ->
|
|
||||||
NylasEnv.packages.activatePackage("package-with-provided-services")
|
|
||||||
|
|
||||||
runs ->
|
|
||||||
expect(consumerModule.consumeFirstServiceV3).toHaveBeenCalledWith('first-service-v3')
|
|
||||||
expect(consumerModule.consumeFirstServiceV4).toHaveBeenCalledWith('first-service-v4')
|
|
||||||
expect(consumerModule.consumeSecondService).toHaveBeenCalledWith('second-service')
|
|
||||||
|
|
||||||
consumerModule.consumeFirstServiceV3.reset()
|
|
||||||
consumerModule.consumeFirstServiceV4.reset()
|
|
||||||
consumerModule.consumeSecondService.reset()
|
|
||||||
|
|
||||||
NylasEnv.packages.deactivatePackage("package-with-provided-services")
|
|
||||||
|
|
||||||
expect(firstServiceV3Disposed).toBe true
|
|
||||||
expect(firstServiceV4Disposed).toBe true
|
|
||||||
expect(secondServiceDisposed).toBe true
|
|
||||||
|
|
||||||
NylasEnv.packages.deactivatePackage("package-with-consumed-services")
|
|
||||||
|
|
||||||
waitsForPromise ->
|
|
||||||
NylasEnv.packages.activatePackage("package-with-provided-services")
|
|
||||||
|
|
||||||
runs ->
|
|
||||||
expect(consumerModule.consumeFirstServiceV3).not.toHaveBeenCalled()
|
|
||||||
expect(consumerModule.consumeFirstServiceV4).not.toHaveBeenCalled()
|
|
||||||
expect(consumerModule.consumeSecondService).not.toHaveBeenCalled()
|
|
||||||
|
|
||||||
describe "::deactivatePackage(id)", ->
|
describe "::deactivatePackage(id)", ->
|
||||||
afterEach ->
|
afterEach ->
|
||||||
NylasEnv.packages.unloadPackages()
|
NylasEnv.packages.unloadPackages()
|
||||||
|
@ -520,15 +471,6 @@ describe "PackageManager", ->
|
||||||
expect(NylasEnv.themes.stylesheetElementForId(two)).not.toExist()
|
expect(NylasEnv.themes.stylesheetElementForId(two)).not.toExist()
|
||||||
expect(NylasEnv.themes.stylesheetElementForId(three)).not.toExist()
|
expect(NylasEnv.themes.stylesheetElementForId(three)).not.toExist()
|
||||||
|
|
||||||
it "removes the package's scoped-properties", ->
|
|
||||||
waitsForPromise ->
|
|
||||||
NylasEnv.packages.activatePackage("package-with-settings")
|
|
||||||
|
|
||||||
runs ->
|
|
||||||
expect(NylasEnv.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBe '^a'
|
|
||||||
NylasEnv.packages.deactivatePackage("package-with-settings")
|
|
||||||
expect(NylasEnv.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBeUndefined()
|
|
||||||
|
|
||||||
it "invokes ::onDidDeactivatePackage listeners with the deactivated package", ->
|
it "invokes ::onDidDeactivatePackage listeners with the deactivated package", ->
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
NylasEnv.packages.activatePackage("package-with-main")
|
NylasEnv.packages.activatePackage("package-with-main")
|
||||||
|
|
|
@ -60,8 +60,6 @@ class Package
|
||||||
menus: null
|
menus: null
|
||||||
stylesheets: null
|
stylesheets: null
|
||||||
stylesheetDisposables: null
|
stylesheetDisposables: null
|
||||||
grammars: null
|
|
||||||
settings: null
|
|
||||||
mainModulePath: null
|
mainModulePath: null
|
||||||
resolvedMainModulePath: false
|
resolvedMainModulePath: false
|
||||||
mainModule: null
|
mainModule: null
|
||||||
|
@ -145,7 +143,6 @@ class Package
|
||||||
@loadKeymaps()
|
@loadKeymaps()
|
||||||
@loadMenus()
|
@loadMenus()
|
||||||
@loadStylesheets()
|
@loadStylesheets()
|
||||||
@settingsPromise = @loadSettings()
|
|
||||||
if not @hasActivationCommands()
|
if not @hasActivationCommands()
|
||||||
mainModule = @requireMainModule()
|
mainModule = @requireMainModule()
|
||||||
return unless mainModule
|
return unless mainModule
|
||||||
|
@ -172,12 +169,8 @@ class Package
|
||||||
@stylesheets = []
|
@stylesheets = []
|
||||||
@keymaps = []
|
@keymaps = []
|
||||||
@menus = []
|
@menus = []
|
||||||
@grammars = []
|
|
||||||
@settings = []
|
|
||||||
|
|
||||||
activate: ->
|
activate: ->
|
||||||
@grammarsPromise ?= @loadGrammars()
|
|
||||||
|
|
||||||
unless @activationDeferred?
|
unless @activationDeferred?
|
||||||
@activationDeferred = Q.defer()
|
@activationDeferred = Q.defer()
|
||||||
@measure 'activateTime', =>
|
@measure 'activateTime', =>
|
||||||
|
@ -187,7 +180,7 @@ class Package
|
||||||
else
|
else
|
||||||
@activateNow()
|
@activateNow()
|
||||||
|
|
||||||
Q.all([@grammarsPromise, @settingsPromise, @activationDeferred.promise])
|
Q.all([@activationDeferred.promise])
|
||||||
|
|
||||||
activateNow: ->
|
activateNow: ->
|
||||||
try
|
try
|
||||||
|
@ -197,7 +190,6 @@ class Package
|
||||||
localState = NylasEnv.packages.getPackageState(@name) ? {}
|
localState = NylasEnv.packages.getPackageState(@name) ? {}
|
||||||
@mainModule.activate(localState)
|
@mainModule.activate(localState)
|
||||||
@mainActivated = true
|
@mainActivated = true
|
||||||
@activateServices()
|
|
||||||
catch e
|
catch e
|
||||||
console.log e.message
|
console.log e.message
|
||||||
console.log e.stack
|
console.log e.stack
|
||||||
|
@ -239,22 +231,6 @@ class Package
|
||||||
@activationDisposables.add(NylasEnv.keymaps.add(keymapPath, map)) for [keymapPath, map] in @keymaps
|
@activationDisposables.add(NylasEnv.keymaps.add(keymapPath, map)) for [keymapPath, map] in @keymaps
|
||||||
@activationDisposables.add(NylasEnv.menu.add(map['menu'])) for [menuPath, map] in @menus when map['menu']?
|
@activationDisposables.add(NylasEnv.menu.add(map['menu'])) for [menuPath, map] in @menus when map['menu']?
|
||||||
|
|
||||||
unless @grammarsActivated
|
|
||||||
grammar.activate() for grammar in @grammars
|
|
||||||
@grammarsActivated = true
|
|
||||||
|
|
||||||
settings.activate() for settings in @settings
|
|
||||||
@settingsActivated = true
|
|
||||||
|
|
||||||
activateServices: ->
|
|
||||||
for name, {versions} of @metadata.providedServices
|
|
||||||
for version, methodName of versions
|
|
||||||
@activationDisposables.add NylasEnv.packages.serviceHub.provide(name, version, @mainModule[methodName]())
|
|
||||||
|
|
||||||
for name, {versions} of @metadata.consumedServices
|
|
||||||
for version, methodName of versions
|
|
||||||
@activationDisposables.add NylasEnv.packages.serviceHub.consume(name, version, @mainModule[methodName].bind(@mainModule))
|
|
||||||
|
|
||||||
loadKeymaps: ->
|
loadKeymaps: ->
|
||||||
if @bundledPackage and packagesCache[@name]?
|
if @bundledPackage and packagesCache[@name]?
|
||||||
@keymaps = (["#{NylasEnv.packages.resourcePath}#{path.sep}#{keymapPath}", keymapObject] for keymapPath, keymapObject of packagesCache[@name].keymaps)
|
@keymaps = (["#{NylasEnv.packages.resourcePath}#{path.sep}#{keymapPath}", keymapObject] for keymapPath, keymapObject of packagesCache[@name].keymaps)
|
||||||
|
@ -304,66 +280,6 @@ class Package
|
||||||
_.filter fs.listSync(stylesheetDirPath, ['css', 'less']), (file) ->
|
_.filter fs.listSync(stylesheetDirPath, ['css', 'less']), (file) ->
|
||||||
path.basename(file)[0] isnt '.'
|
path.basename(file)[0] isnt '.'
|
||||||
|
|
||||||
loadGrammarsSync: ->
|
|
||||||
return if @grammarsLoaded
|
|
||||||
|
|
||||||
grammarsDirPath = path.join(@path, 'grammars')
|
|
||||||
grammarPaths = fs.listSync(grammarsDirPath, ['json', 'cson'])
|
|
||||||
for grammarPath in grammarPaths
|
|
||||||
try
|
|
||||||
grammar = NylasEnv.grammars.readGrammarSync(grammarPath)
|
|
||||||
grammar.packageName = @name
|
|
||||||
@grammars.push(grammar)
|
|
||||||
grammar.activate()
|
|
||||||
catch error
|
|
||||||
console.warn("Failed to load grammar: #{grammarPath}", error.stack ? error)
|
|
||||||
|
|
||||||
@grammarsLoaded = true
|
|
||||||
@grammarsActivated = true
|
|
||||||
|
|
||||||
loadGrammars: ->
|
|
||||||
return Q() if @grammarsLoaded
|
|
||||||
|
|
||||||
loadGrammar = (grammarPath, callback) =>
|
|
||||||
NylasEnv.grammars.readGrammar grammarPath, (error, grammar) =>
|
|
||||||
if error?
|
|
||||||
console.warn("Failed to load grammar: #{grammarPath}", error.stack ? error)
|
|
||||||
else
|
|
||||||
grammar.packageName = @name
|
|
||||||
@grammars.push(grammar)
|
|
||||||
grammar.activate() if @grammarsActivated
|
|
||||||
callback()
|
|
||||||
|
|
||||||
deferred = Q.defer()
|
|
||||||
grammarsDirPath = path.join(@path, 'grammars')
|
|
||||||
fs.list grammarsDirPath, ['json', 'cson'], (error, grammarPaths=[]) ->
|
|
||||||
async.each grammarPaths, loadGrammar, -> deferred.resolve()
|
|
||||||
deferred.promise
|
|
||||||
|
|
||||||
loadSettings: ->
|
|
||||||
@settings = []
|
|
||||||
|
|
||||||
loadSettingsFile = (settingsPath, callback) =>
|
|
||||||
ScopedProperties.load settingsPath, (error, settings) =>
|
|
||||||
if error?
|
|
||||||
console.warn("Failed to load package settings: #{settingsPath}", error.stack ? error)
|
|
||||||
else
|
|
||||||
@settings.push(settings)
|
|
||||||
settings.activate() if @settingsActivated
|
|
||||||
callback()
|
|
||||||
|
|
||||||
deferred = Q.defer()
|
|
||||||
|
|
||||||
if fs.isDirectorySync(path.join(@path, 'scoped-properties'))
|
|
||||||
settingsDirPath = path.join(@path, 'scoped-properties')
|
|
||||||
deprecate("Store package settings files in the `settings/` directory instead of `scoped-properties/`", packageName: @name)
|
|
||||||
else
|
|
||||||
settingsDirPath = path.join(@path, 'settings')
|
|
||||||
|
|
||||||
fs.list settingsDirPath, ['json', 'cson'], (error, settingsPaths=[]) ->
|
|
||||||
async.each settingsPaths, loadSettingsFile, -> deferred.resolve()
|
|
||||||
deferred.promise
|
|
||||||
|
|
||||||
serialize: ->
|
serialize: ->
|
||||||
if @mainActivated
|
if @mainActivated
|
||||||
try
|
try
|
||||||
|
@ -390,13 +306,9 @@ class Package
|
||||||
@configActivated = false
|
@configActivated = false
|
||||||
|
|
||||||
deactivateResources: ->
|
deactivateResources: ->
|
||||||
grammar.deactivate() for grammar in @grammars
|
|
||||||
settings.deactivate() for settings in @settings
|
|
||||||
@stylesheetDisposables?.dispose()
|
@stylesheetDisposables?.dispose()
|
||||||
@activationDisposables?.dispose()
|
@activationDisposables?.dispose()
|
||||||
@stylesheetsActivated = false
|
@stylesheetsActivated = false
|
||||||
@grammarsActivated = false
|
|
||||||
@settingsActivated = false
|
|
||||||
|
|
||||||
reloadStylesheets: ->
|
reloadStylesheets: ->
|
||||||
oldSheets = _.clone(@stylesheets)
|
oldSheets = _.clone(@stylesheets)
|
||||||
|
|
Loading…
Reference in a new issue