From 2d29fd6e79262bd5b8c902f86456ef5a21f224ae Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 20 Nov 2015 13:28:05 -0800 Subject: [PATCH] Load config schemas from packages' package.json files --- .../package-with-json-config-schema/package.json | 13 +++++++++++++ spec/package-manager-spec.coffee | 15 +++++++++++++++ src/package.coffee | 13 ++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/packages/package-with-json-config-schema/package.json diff --git a/spec/fixtures/packages/package-with-json-config-schema/package.json b/spec/fixtures/packages/package-with-json-config-schema/package.json new file mode 100644 index 000000000..960d87fc1 --- /dev/null +++ b/spec/fixtures/packages/package-with-json-config-schema/package.json @@ -0,0 +1,13 @@ +{ + "name": "package-with-json-config-schema", + "configSchema": { + "a": { + "type": "number", + "default": 5 + }, + "b": { + "type": "string", + "default": "five" + } + } +} diff --git a/spec/package-manager-spec.coffee b/spec/package-manager-spec.coffee index 169e09b76..656b4b691 100644 --- a/spec/package-manager-spec.coffee +++ b/spec/package-manager-spec.coffee @@ -194,6 +194,21 @@ describe "PackageManager", -> expect(atom.config.set('package-with-config-schema.numbers.one', '10')).toBe true expect(atom.config.get('package-with-config-schema.numbers.one')).toBe 10 + it "assigns the config schema when the package contains a schema in its package.json", -> + expect(atom.config.get('package-with-json-config-schema')).toBeUndefined() + + waitsForPromise -> + atom.packages.activatePackage('package-with-json-config-schema') + + runs -> + expect(atom.config.getSchema('package-with-json-config-schema')).toEqual { + type: 'object' + properties: { + a: {type: 'number', default: 5} + b: {type: 'string', default: 'five'} + } + } + describe "when the package metadata includes `activationCommands`", -> [mainModule, promise, workspaceCommandListener, registration] = [] diff --git a/src/package.coffee b/src/package.coffee index 1d98c8161..d1354340f 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -133,11 +133,14 @@ class Package activateConfig: -> return if @configActivated - @requireMainModule() unless @mainModule? - if @mainModule? - if @mainModule.config? and typeof @mainModule.config is 'object' - @config.setSchema @name, {type: 'object', properties: @mainModule.config} - @mainModule.activateConfig?() + if configSchema = @metadata.configSchema + @config.setSchema @name, {type: 'object', properties: configSchema} + else + @requireMainModule() unless @mainModule? + if @mainModule? + if @mainModule.config? and typeof @mainModule.config is 'object' + @config.setSchema @name, {type: 'object', properties: @mainModule.config} + @mainModule.activateConfig?() @configActivated = true activateStylesheets: ->