From 4400f98f65fc08c6faea2966a2e96222afdbedae Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 20 Apr 2016 18:46:58 -0700 Subject: [PATCH] rm(package): Remove unused grammars, settings, scopedProperties --- .../index.coffee | 10 --- .../package.json | 17 ---- .../index.coffee | 13 --- .../package.json | 19 ---- spec/package-manager-spec.coffee | 58 ------------ src/package.coffee | 90 +------------------ 6 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 spec/fixtures/packages/package-with-consumed-services/index.coffee delete mode 100644 spec/fixtures/packages/package-with-consumed-services/package.json delete mode 100644 spec/fixtures/packages/package-with-provided-services/index.coffee delete mode 100644 spec/fixtures/packages/package-with-provided-services/package.json diff --git a/spec/fixtures/packages/package-with-consumed-services/index.coffee b/spec/fixtures/packages/package-with-consumed-services/index.coffee deleted file mode 100644 index ccb893175..000000000 --- a/spec/fixtures/packages/package-with-consumed-services/index.coffee +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = - activate: -> - - deactivate: -> - - consumeFirstServiceV3: -> - - consumeFirstServiceV4: -> - - consumeSecondService: -> diff --git a/spec/fixtures/packages/package-with-consumed-services/package.json b/spec/fixtures/packages/package-with-consumed-services/package.json deleted file mode 100644 index b8a25709f..000000000 --- a/spec/fixtures/packages/package-with-consumed-services/package.json +++ /dev/null @@ -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" - } - } - } -} diff --git a/spec/fixtures/packages/package-with-provided-services/index.coffee b/spec/fixtures/packages/package-with-provided-services/index.coffee deleted file mode 100644 index b6413b119..000000000 --- a/spec/fixtures/packages/package-with-provided-services/index.coffee +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = - activate: -> - - deactivate: -> - - provideFirstServiceV3: -> - 'first-service-v3' - - provideFirstServiceV4: -> - 'first-service-v4' - - provideSecondService: -> - 'second-service' diff --git a/spec/fixtures/packages/package-with-provided-services/package.json b/spec/fixtures/packages/package-with-provided-services/package.json deleted file mode 100644 index 144fc2dac..000000000 --- a/spec/fixtures/packages/package-with-provided-services/package.json +++ /dev/null @@ -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" - } - } - } -} diff --git a/spec/package-manager-spec.coffee b/spec/package-manager-spec.coffee index ec59d62b8..c39d79b80 100644 --- a/spec/package-manager-spec.coffee +++ b/spec/package-manager-spec.coffee @@ -377,55 +377,6 @@ describe "PackageManager", -> 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)", -> afterEach -> NylasEnv.packages.unloadPackages() @@ -520,15 +471,6 @@ describe "PackageManager", -> expect(NylasEnv.themes.stylesheetElementForId(two)).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", -> waitsForPromise -> NylasEnv.packages.activatePackage("package-with-main") diff --git a/src/package.coffee b/src/package.coffee index 01d3091ee..b4c049ef8 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -60,8 +60,6 @@ class Package menus: null stylesheets: null stylesheetDisposables: null - grammars: null - settings: null mainModulePath: null resolvedMainModulePath: false mainModule: null @@ -145,7 +143,6 @@ class Package @loadKeymaps() @loadMenus() @loadStylesheets() - @settingsPromise = @loadSettings() if not @hasActivationCommands() mainModule = @requireMainModule() return unless mainModule @@ -172,12 +169,8 @@ class Package @stylesheets = [] @keymaps = [] @menus = [] - @grammars = [] - @settings = [] activate: -> - @grammarsPromise ?= @loadGrammars() - unless @activationDeferred? @activationDeferred = Q.defer() @measure 'activateTime', => @@ -187,7 +180,7 @@ class Package else @activateNow() - Q.all([@grammarsPromise, @settingsPromise, @activationDeferred.promise]) + Q.all([@activationDeferred.promise]) activateNow: -> try @@ -197,7 +190,6 @@ class Package localState = NylasEnv.packages.getPackageState(@name) ? {} @mainModule.activate(localState) @mainActivated = true - @activateServices() catch e console.log e.message 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.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: -> if @bundledPackage and packagesCache[@name]? @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) -> 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: -> if @mainActivated try @@ -390,13 +306,9 @@ class Package @configActivated = false deactivateResources: -> - grammar.deactivate() for grammar in @grammars - settings.deactivate() for settings in @settings @stylesheetDisposables?.dispose() @activationDisposables?.dispose() @stylesheetsActivated = false - @grammarsActivated = false - @settingsActivated = false reloadStylesheets: -> oldSheets = _.clone(@stylesheets)