-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from 201-created/module-unification
Initial implementation of the module unification feature flag
- Loading branch information
Showing
13 changed files
with
972 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,88 @@ | ||
/* | ||
* This config describes canonical Ember, as described in the | ||
* module unification spec: | ||
* | ||
* https://github.com/dgeb/rfcs/blob/module-unification/text/0000-module-unification.md | ||
* | ||
*/ | ||
export default function generateConfig(name) { | ||
return { | ||
app: { | ||
name, | ||
rootName: name | ||
}, | ||
types: { | ||
adapter: { definitiveCollection: 'models' }, | ||
application: { definitiveCollection: 'main' }, | ||
controller: { definitiveCollection: 'routes' }, | ||
component: { definitiveCollection: 'components' }, | ||
'component-lookup': { definitiveCollection: 'main' }, | ||
event_dispatcher: { definitiveCollection: 'main' }, | ||
helper: { definitiveCollection: 'components' }, | ||
initializer: { definitiveCollection: 'initializers' }, | ||
'instance-initializers': { definitiveCollection: 'instance-initializer' }, | ||
location: { definitiveCollection: 'main' }, | ||
model: { definitiveCollection: 'models' }, | ||
partial: { definitiveCollection: 'partials' }, | ||
renderer: { definitiveCollection: 'main' }, | ||
route: { definitiveCollection: 'routes' }, | ||
router: { definitiveCollection: 'main' }, | ||
serializer: { definitiveCollection: 'models' }, | ||
service: { definitiveCollection: 'services' }, | ||
template: { | ||
definitiveCollection: 'routes', | ||
fallbackCollectionPrefixes: { | ||
'components': 'components' | ||
} | ||
}, | ||
transform: { definitiveCollection: 'transforms' }, | ||
util: { definitiveCollection: 'utils' }, | ||
view: { definitiveCollection: 'views' }, | ||
'-view-registry': { definitiveCollection: 'main' }, | ||
'-bucket-cache': { definitiveCollection: 'main' } | ||
}, | ||
collections: { | ||
'main': { | ||
types: ['router', '-bucket-cache', 'component-lookup', '-view-registry', 'event_dispatcher', 'application', 'location', 'renderer'] | ||
}, | ||
components: { | ||
group: 'ui', | ||
types: ['component', 'helper', 'template'] | ||
}, | ||
initializers: { | ||
group: 'init', | ||
types: ['initializer'] | ||
}, | ||
'instance-initializers': { | ||
group: 'init', | ||
types: ['instance-initializers'] | ||
}, | ||
models: { | ||
group: 'data', | ||
types: ['model', 'adapter', 'serializer'] | ||
}, | ||
partials: { | ||
group: 'ui', | ||
types: ['partial'] | ||
}, | ||
routes: { | ||
group: 'ui', | ||
privateCollections: ['components'], | ||
types: ['route', 'controller', 'template'] | ||
}, | ||
services: { | ||
types: ['service'] | ||
}, | ||
utils: { | ||
unresolvable: true | ||
}, | ||
views: { | ||
types: ['view'] | ||
}, | ||
transforms: { | ||
group: 'data', | ||
types: ['transform'] | ||
} | ||
} | ||
}; | ||
} |
This file contains 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,72 @@ | ||
/* global require, requirejs */ | ||
import { | ||
deserializeSpecifier | ||
} from '@glimmer/di'; | ||
|
||
export default class RequireJSRegistry { | ||
|
||
constructor(config, modulePrefix) { | ||
this._config = config; | ||
this._modulePrefix = modulePrefix; | ||
} | ||
|
||
normalize(specifier) { | ||
let s = deserializeSpecifier(specifier); | ||
|
||
// This is hacky solution to get around the fact that Ember | ||
// doesn't know it is requesting a partial. It requests something like | ||
// 'template:/my-app/routes/-author' | ||
// Would be better to request 'template:my-app/partials/author' | ||
let isPartial = s.type === 'template' && s.name[0] === '-'; | ||
if (isPartial) { | ||
s.name = s.name.slice(1); | ||
s.collection = 'partials'; | ||
} | ||
|
||
let collectionDefinition = this._config.collections[s.collection]; | ||
let group = collectionDefinition && collectionDefinition.group; | ||
let segments = [ s.rootName, this._modulePrefix ]; | ||
|
||
if (group) { | ||
segments.push(group); | ||
} | ||
|
||
// Special case to handle definiteCollection for templates | ||
// eventually want to find a better way to address. | ||
// Dgeb wants to find a better way to handle these | ||
// in config without needing definiteCollections. | ||
let ignoreCollection = s.type === 'template' && | ||
s.collection === 'routes' && | ||
s.namespace === 'components'; | ||
|
||
if (s.collection !== 'main' && !ignoreCollection) { | ||
segments.push(s.collection); | ||
} | ||
|
||
if (s.namespace) { | ||
segments.push(s.namespace); | ||
} | ||
|
||
if (s.name !== 'main') { | ||
segments.push(s.name); | ||
} | ||
|
||
if (!isPartial) { | ||
segments.push(s.type); | ||
} | ||
|
||
let path = segments.join('/'); | ||
|
||
return path; | ||
} | ||
|
||
has(specifier) { | ||
let path = this.normalize(specifier); | ||
return path in requirejs.entries; | ||
} | ||
|
||
get(specifier) { | ||
let path = this.normalize(specifier); | ||
return require(path).default; | ||
} | ||
} |
This file contains 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,34 @@ | ||
import Ember from 'ember'; | ||
import GlimmerResolver from '@glimmer/resolver/resolver'; | ||
import RequireJSRegistry from '../../module-registries/requirejs'; | ||
|
||
const { DefaultResolver } = Ember; | ||
|
||
/* | ||
* Wrap the @glimmer/resolver in Ember's resolver API. Although | ||
* this code extends from the DefaultResolver, it should never | ||
* call `_super` or call into that code. | ||
*/ | ||
const Resolver = DefaultResolver.extend({ | ||
init() { | ||
this._super(...arguments); | ||
|
||
if (!this.glimmerModuleRegistry) { | ||
this.glimmerModuleRegistry = new RequireJSRegistry(this.config, 'src'); | ||
} | ||
|
||
this._glimmerResolver = new GlimmerResolver(this.config, this.glimmerModuleRegistry); | ||
}, | ||
|
||
normalize: null, | ||
|
||
resolve(lookupString) { | ||
return this._resolve(lookupString); | ||
}, | ||
|
||
_resolve(lookupString) { | ||
return this._glimmerResolver.resolve(lookupString); | ||
} | ||
}); | ||
|
||
export default Resolver; |
Oops, something went wrong.