-
-
Notifications
You must be signed in to change notification settings - Fork 101
Addons can provide their resolver module configuration via resolverConfig()
#348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
532ef05
Addons can provide their resolver module configuration via `addon.res…
ppcano 3762945
Include `resolverConfig` on nested addons
ppcano 4d29950
`mergeAddonsConfig` is executed within `ember-resolver/ember-config`
ppcano 00ba6fc
Fix `mergeAddonsConfig` comments
ppcano 0f519c8
Refactor: rename `result` to `config`
ppcano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,115 +1,17 @@ | ||
| /* | ||
| * This config describes canonical Ember, as described in the | ||
| * module unification spec: | ||
| * | ||
| * https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md | ||
| * | ||
| */ | ||
| import addonsConfig from 'ember-resolver/addons-config'; | ||
| import moduleConfig from 'ember-resolver/module-config'; | ||
| import mergeAddonsConfig from 'ember-resolver/utils/merge-addons-config'; | ||
|
|
||
| export default function generateConfig(name) { | ||
| return { | ||
|
|
||
| let config = { | ||
| app: { | ||
| name, | ||
| rootName: name | ||
| }, | ||
| types: { | ||
| adapter: { definitiveCollection: 'models' }, | ||
| application: { definitiveCollection: 'main' }, | ||
| config: { definitiveCollection: 'config' }, | ||
| controller: { definitiveCollection: 'routes' }, | ||
| component: { definitiveCollection: 'components' }, | ||
| 'component-lookup': { definitiveCollection: 'main' }, | ||
| 'component-manager': { definitiveCollection: 'component-managers' }, | ||
| event_dispatcher: { definitiveCollection: 'main' }, | ||
| helper: { definitiveCollection: 'components' }, | ||
| initializer: { definitiveCollection: 'initializers' }, | ||
| 'instance-initializers': { definitiveCollection: 'instance-initializer' }, | ||
| location: { definitiveCollection: 'main' }, | ||
| model: { definitiveCollection: 'models' }, | ||
| modifier: { definitiveCollection: 'components' }, | ||
| 'modifier-manager': { definitiveCollection: 'modifier-managers' }, | ||
| partial: { definitiveCollection: 'partials' }, | ||
| renderer: { definitiveCollection: 'main' }, | ||
| route: { definitiveCollection: 'routes' }, | ||
| router: { definitiveCollection: 'main' }, | ||
| 'route-map': { definitiveCollection: 'main' }, | ||
| serializer: { definitiveCollection: 'models' }, | ||
| service: { definitiveCollection: 'services' }, | ||
| template: { definitiveCollection: 'components' }, | ||
| 'template-compiler': { definitiveCollection: 'main' }, | ||
| transform: { definitiveCollection: 'transforms' }, | ||
| view: { definitiveCollection: 'views' }, | ||
| '-view-registry': { definitiveCollection: 'main' }, | ||
| '-bucket-cache': { definitiveCollection: 'main' }, | ||
| '-environment': { definitiveCollection: 'main' }, | ||
| '-application-instance': { definitiveCollection: 'main' } | ||
| }, | ||
| collections: { | ||
| 'main': { | ||
| types: ['router', '-bucket-cache', 'component-lookup', '-view-registry', 'event_dispatcher', 'application', 'location', 'renderer', '-environment', '-application-instance', 'route-map'] | ||
| }, | ||
| components: { | ||
| group: 'ui', | ||
| privateCollections: ['utils'], | ||
| types: ['component', 'helper', 'template', 'modifier'] | ||
| }, | ||
| 'component-managers': { | ||
| types: ['component-manager'] | ||
| }, | ||
| config: { | ||
| unresolvable: true | ||
| }, | ||
| initializers: { | ||
| group: 'init', | ||
| defaultType: 'initializer', | ||
| privateCollections: ['utils'], | ||
| types: ['initializer'] | ||
| }, | ||
| 'instance-initializers': { | ||
| group: 'init', | ||
| defaultType: 'instance-initializer', | ||
| privateCollections: ['utils'], | ||
| types: ['instance-initializers'] | ||
| }, | ||
| models: { | ||
| group: 'data', | ||
| defaultType: 'model', | ||
| privateCollections: ['utils'], | ||
| types: ['model', 'adapter', 'serializer'] | ||
| }, | ||
| 'modifier-managers': { | ||
| types: ['modifier-manager'] | ||
| }, | ||
| partials: { | ||
| group: 'ui', | ||
| defaultType: 'partial', | ||
| privateCollections: ['utils'], | ||
| types: ['partial'] | ||
| }, | ||
| routes: { | ||
| group: 'ui', | ||
| defaultType: 'route', | ||
| privateCollections: ['components', 'utils'], | ||
| types: ['route', 'controller', 'template'] | ||
| }, | ||
| services: { | ||
| defaultType: 'service', | ||
| privateCollections: ['utils'], | ||
| types: ['service'] | ||
| }, | ||
| utils: { | ||
| unresolvable: true | ||
| }, | ||
| views: { | ||
| defaultType: 'view', | ||
| privateCollections: ['utils'], | ||
| types: ['view'] | ||
| }, | ||
| transforms: { | ||
| group: 'data', | ||
| defaultType: 'transform', | ||
| privateCollections: ['utils'], | ||
| types: ['transform'] | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| mergeAddonsConfig(moduleConfig, addonsConfig); | ||
|
|
||
| return Object.assign(config, moduleConfig); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * This config describes canonical Ember, as described in the | ||
| * module unification spec: | ||
| * | ||
| * https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md | ||
| * | ||
| */ | ||
| export default { | ||
| types: { | ||
| adapter: { definitiveCollection: 'models' }, | ||
| application: { definitiveCollection: 'main' }, | ||
| config: { definitiveCollection: 'config' }, | ||
| controller: { definitiveCollection: 'routes' }, | ||
| component: { definitiveCollection: 'components' }, | ||
| 'component-lookup': { definitiveCollection: 'main' }, | ||
| 'component-manager': { definitiveCollection: 'component-managers' }, | ||
| event_dispatcher: { definitiveCollection: 'main' }, | ||
| helper: { definitiveCollection: 'components' }, | ||
| initializer: { definitiveCollection: 'initializers' }, | ||
| 'instance-initializers': { definitiveCollection: 'instance-initializer' }, | ||
| location: { definitiveCollection: 'main' }, | ||
| model: { definitiveCollection: 'models' }, | ||
| modifier: { definitiveCollection: 'components' }, | ||
| 'modifier-manager': { definitiveCollection: 'modifier-managers' }, | ||
| partial: { definitiveCollection: 'partials' }, | ||
| renderer: { definitiveCollection: 'main' }, | ||
| route: { definitiveCollection: 'routes' }, | ||
| router: { definitiveCollection: 'main' }, | ||
| 'route-map': { definitiveCollection: 'main' }, | ||
| serializer: { definitiveCollection: 'models' }, | ||
| service: { definitiveCollection: 'services' }, | ||
| template: { definitiveCollection: 'components' }, | ||
| 'template-compiler': { definitiveCollection: 'main' }, | ||
| transform: { definitiveCollection: 'transforms' }, | ||
| view: { definitiveCollection: 'views' }, | ||
| '-view-registry': { definitiveCollection: 'main' }, | ||
| '-bucket-cache': { definitiveCollection: 'main' }, | ||
| '-environment': { definitiveCollection: 'main' }, | ||
| '-application-instance': { definitiveCollection: 'main' } | ||
| }, | ||
| collections: { | ||
| 'main': { | ||
| types: ['router', '-bucket-cache', 'component-lookup', '-view-registry', 'event_dispatcher', 'application', 'location', 'renderer', '-environment', '-application-instance', 'route-map'] | ||
| }, | ||
| components: { | ||
| group: 'ui', | ||
| privateCollections: ['utils'], | ||
| types: ['component', 'helper', 'template', 'modifier'] | ||
| }, | ||
| 'component-managers': { | ||
| types: ['component-manager'] | ||
| }, | ||
| config: { | ||
| unresolvable: true | ||
| }, | ||
| initializers: { | ||
| group: 'init', | ||
| defaultType: 'initializer', | ||
| privateCollections: ['utils'], | ||
| types: ['initializer'] | ||
| }, | ||
| 'instance-initializers': { | ||
| group: 'init', | ||
| defaultType: 'instance-initializer', | ||
| privateCollections: ['utils'], | ||
| types: ['instance-initializers'] | ||
| }, | ||
| models: { | ||
| group: 'data', | ||
| defaultType: 'model', | ||
| privateCollections: ['utils'], | ||
| types: ['model', 'adapter', 'serializer'] | ||
| }, | ||
| 'modifier-managers': { | ||
| types: ['modifier-manager'] | ||
| }, | ||
| partials: { | ||
| group: 'ui', | ||
| defaultType: 'partial', | ||
| privateCollections: ['utils'], | ||
| types: ['partial'] | ||
| }, | ||
| routes: { | ||
| group: 'ui', | ||
| defaultType: 'route', | ||
| privateCollections: ['components', 'utils'], | ||
| types: ['route', 'controller', 'template'] | ||
| }, | ||
| services: { | ||
| defaultType: 'service', | ||
| privateCollections: ['utils'], | ||
| types: ['service'] | ||
| }, | ||
| utils: { | ||
| unresolvable: true | ||
| }, | ||
| views: { | ||
| defaultType: 'view', | ||
| privateCollections: ['utils'], | ||
| types: ['view'] | ||
| }, | ||
| transforms: { | ||
| group: 'data', | ||
| defaultType: 'transform', | ||
| privateCollections: ['utils'], | ||
| types: ['transform'] | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| This function merges the types and collections from addons `addonsConfig` into `config`. | ||
|
|
||
| It will throw an exception if an addon tries to override | ||
| an existing type or collection on the resolver config object or | ||
| if two addons provide the same type or collection. | ||
|
|
||
| - `config`: is a resolver config object. | ||
|
|
||
| - `addonsConfig`: is a hash object containing the result of the call of | ||
| `addon.resolverConfig` method on all the project addons. | ||
|
|
||
| ```js | ||
| { | ||
| my-addon1: { types: { ... } }, | ||
| my-addon2: { collections: { ... } }, | ||
| hola-addon: { types: { ... }, collections: { ... } } | ||
| } | ||
| ``` | ||
| */ | ||
| export default function mergeAddonsConfig(config, addonsConfig) { | ||
|
|
||
| Object.keys(addonsConfig).forEach(function (addonName) { | ||
| let addonConfig = addonsConfig[addonName]; | ||
| let addonTypes = addonConfig.types || {}; | ||
| let addonCollections = addonConfig.collections || {}; | ||
|
|
||
| Object.keys(addonTypes).forEach(function (key) { | ||
| if (!config.types.hasOwnProperty(key)) { | ||
| config.types[key] = addonTypes[key]; | ||
| } else { | ||
| throw new Error(`Addon '${addonName}' attempts to configure the type '${key}' on the resolver but '${key}' has already been configured.`); | ||
| } | ||
| }); | ||
| Object.keys(addonCollections).forEach(function (key) { | ||
| if (!config.collections.hasOwnProperty(key)) { | ||
| config.collections[key] = addonCollections[key]; | ||
| } else { | ||
| throw new Error(`Addon '${addonName}' attempts to configure the collection '${key}' on the resolver but '${key}' has already been configured.`); | ||
| } | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.