diff --git a/index.js b/index.js index 1f325ecc..30904069 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ 'use strict'; const VersionChecker = require('ember-cli-version-checker'); -const path = require('path'); -let isModuleUnification; module.exports = { name: require('./package.json').name, @@ -24,7 +22,6 @@ module.exports = { } } this._emberResolverFeatureFlags = this.emberResolverFeatureFlags(); - isModuleUnification = !!this.project.isModuleUnification && this.project.isModuleUnification(); this.options.babel = { loose: true, @@ -47,45 +44,6 @@ module.exports = { }; }, - treeForAddon() { - const MergeTrees = require('broccoli-merge-trees'); - const addonTrees = [].concat( - this._super.treeForAddon.apply(this, arguments), - isModuleUnification && this._moduleUnificationTrees() - ).filter(Boolean); - - return new MergeTrees(addonTrees); - }, - - _moduleUnificationTrees() { - const resolve = require('resolve'); - const Funnel = require('broccoli-funnel'); - - let featureTreePath = path.join(this.root, 'mu-trees/addon'); - let featureTree = new Funnel(featureTreePath, { - destDir: 'ember-resolver' - }); - - const glimmerResolverSrc = require.resolve('@glimmer/resolver/package'); - let glimmerResolverPath = path.dirname(glimmerResolverSrc); - let glimmerResolverTree = new Funnel(glimmerResolverPath, { - srcDir: 'dist/modules/es2017', - destDir: '@glimmer/resolver' - }); - - let glimmerDISrc = resolve.sync('@glimmer/di', { basedir: glimmerResolverPath }); - let glimmerDITree = new Funnel(path.join(glimmerDISrc, '../../../..'), { - srcDir: 'dist/modules/es2017', - destDir: '@glimmer/di' - }); - - return [ - this.preprocessJs(featureTree, { registry: this.registry }), - this.preprocessJs(glimmerResolverTree, { registry: this.registry }), - this.preprocessJs(glimmerDITree, { registry: this.registry }), - ]; - }, - included() { this._super.included.apply(this, arguments); diff --git a/mu-trees/addon/ember-config.js b/mu-trees/addon/ember-config.js deleted file mode 100644 index 624ab7ee..00000000 --- a/mu-trees/addon/ember-config.js +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 function generateConfig(name) { - return { - 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'] - } - } - }; -} diff --git a/mu-trees/addon/module-registries/requirejs.js b/mu-trees/addon/module-registries/requirejs.js deleted file mode 100644 index 7c4eefaa..00000000 --- a/mu-trees/addon/module-registries/requirejs.js +++ /dev/null @@ -1,94 +0,0 @@ -import { - deserializeSpecifier -} from '@glimmer/di'; - -export default class RequireJSRegistry { - - constructor(config, modulePrefix, require=self.requirejs) { - this._config = config; - this._modulePrefix = modulePrefix; - this._require = require; - } - - _baseSegments(s) { - 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 definitiveCollection 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 definitiveCollection. - 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' || s.collection !== 'main') { - segments.push(s.name); - } - - return segments; - } - - _detectModule(specifier, lookupDefault, lookupNamed) { - let segments = this._baseSegments(specifier); - let basePath = `${segments.join('/')}`; - let typedPath = `${basePath}/${specifier.type}`; - - let lookupResult = lookupDefault(typedPath); - - if (!lookupResult) { - if (this._checkDefaultType(specifier)) { - lookupResult = lookupDefault(basePath); - } else { - lookupResult = lookupNamed(basePath); - } - } - - return lookupResult; - } - - _checkDefaultType(specifier) { - let collection = this._config.collections[specifier.collection]; - return collection && collection.defaultType && collection.defaultType === specifier.type; - } - - has(specifierString) { - let specifier = deserializeSpecifier(specifierString); - - /* return a boolean */ - return this._detectModule(specifier, path => { - return (path in this._require.entries); - }, path => { - if (path in this._require.entries) { - let result = this._require(path); - return (specifier.type in result); - } - }); - } - - get(specifierString) { - let specifier = deserializeSpecifier(specifierString); - - /* return an export */ - let moduleExport = this._detectModule(specifier, path => { - return (path in this._require.entries) && this._require(path).default; - }, path => { - return (path in this._require.entries) && this._require(path)[specifier.type]; - }); - - return moduleExport; - } -} diff --git a/mu-trees/addon/resolvers/fallback/index.js b/mu-trees/addon/resolvers/fallback/index.js deleted file mode 100644 index d7938e94..00000000 --- a/mu-trees/addon/resolvers/fallback/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import ClassicResolver from 'ember-resolver'; -import Resolver from 'ember-resolver/resolvers/glimmer-wrapper'; -import { assign } from '@ember/polyfills'; - -export default Resolver.extend({ - init(options) { - this._super(options); - this._fallback = ClassicResolver.create(assign({ - namespace: { modulePrefix: this.config.app.name } - }, options)); - }, - resolve(name) { - let result = this._super(name); - return result || this._fallback.resolve(this._fallback.normalize(name)); - } -}); diff --git a/mu-trees/addon/resolvers/glimmer-wrapper/index.js b/mu-trees/addon/resolvers/glimmer-wrapper/index.js deleted file mode 100644 index 27486908..00000000 --- a/mu-trees/addon/resolvers/glimmer-wrapper/index.js +++ /dev/null @@ -1,153 +0,0 @@ -import { DEBUG } from '@glimmer/env'; -import GlimmerResolver from '@glimmer/resolver/resolver'; -import RequireJSRegistry from '../../module-registries/requirejs'; -import GlobalsResolver from '@ember/application/globals-resolver'; -import { dasherize } from '@ember/string'; - -function slasherize(dotted) { - return dotted.replace(/\./g, '/'); -} - -const TEMPLATE_TO_PARTIAL = /^template:(.*\/)?_([\w-]+)/; - -function isAbsoluteSpecifier(specifier) { - return specifier.indexOf(':/') !== -1; -} - -function cleanupEmberSpecifier(specifier, source, _namespace) { - let [type, name] = specifier.split(':'); - if (!name) { - return [specifier, null]; - } - - if (type === 'component' && name) { - specifier = `${type}:${name}`; - } else if (type === 'service') { - /* Services may be camelCased */ - specifier = `service:${dasherize(name)}`; - } else if (type === 'route') { - /* Routes may have.dot.paths */ - specifier = `route:${slasherize(name)}`; - } else if (type === 'controller') { - /* Controllers may have.dot.paths */ - specifier = `controller:${slasherize(name)}`; - } else if (type === 'template') { - if (name && name.indexOf('components/') === 0) { - let sliced = name.slice(11); - specifier = `template:${sliced}`; - } else { - /* - * Ember partials are looked up as templates. Here we replace the template - * resolution with a partial resolute when appropriate. Try to keep this - * code as "pay-go" as possible. - */ - let match = TEMPLATE_TO_PARTIAL.exec(specifier); - if (match) { - let namespace = match[1] || ''; - let name = match[2]; - - specifier = `partial:${namespace}${name}`; - } else { - if (source) { - throw new Error(`Cannot look up a route template ${specifier} with a source`); - } - /* - * Templates for routes must be looked up with a source. They may - * have dots.in.paths - */ - specifier = `template`; - source = `route:/${_namespace}/routes/${slasherize(name)}`; - } - } - } - - return [specifier, source]; -} -const normalize = !DEBUG ? null : function(fullName) { - // This method is called by `Registry#validateInjections` in dev mode. - // https://github.com/ember-cli/ember-resolver/issues/299 - if (fullName) { - const [type, name] = fullName.split(':', 2); - if (name && (type === 'service' || type === 'controller')) { - return `${type}:${dasherize(name)}`; - } - } - return fullName; -}; - -/* - * 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 = GlobalsResolver.extend({ - init() { - this._super(...arguments); - - this._configRootName = this.config.app.rootName || 'app'; - - if (!this.glimmerModuleRegistry) { - this.glimmerModuleRegistry = new RequireJSRegistry(this.config, 'src'); - } - - this._glimmerResolver = new GlimmerResolver(this.config, this.glimmerModuleRegistry); - }, - - normalize, - - expandLocalLookup(specifier, source, namespace) { - if (isAbsoluteSpecifier(specifier)) { - return specifier; // specifier is absolute - } - - if (source || namespace) { - let rootName = namespace || this._configRootName; - - /* - * Ember components require their lookupString to be massaged. Make this - * as "pay-go" as possible. - */ - if (namespace) { - let [type] = specifier.split(':'); - // This is only required because: - // https://github.com/glimmerjs/glimmer-di/issues/45 - source = `${type}:/${rootName}/`; - } else if (source) { - // make absolute - let parts = source.split(':src/ui/'); - source = `${parts[0]}:/${rootName}/${parts[1]}`; - source = source.split('/template.hbs')[0]; - } - - let [_specifier, _source] = cleanupEmberSpecifier(specifier, source, rootName); - - let absoluteSpecifier = this._glimmerResolver.identify(_specifier, _source); - - if (absoluteSpecifier) { - return absoluteSpecifier; - } - - absoluteSpecifier = this._glimmerResolver.identify(_specifier); - - if (absoluteSpecifier) { - return specifier; - } - } - - return specifier; - }, - - resolve(specifier) { - let source = null; - if (!isAbsoluteSpecifier(specifier)) { - let [_specifier, _source] = cleanupEmberSpecifier(specifier, source, this._configRootName); - specifier = _specifier; - source = _source; - } - - return this._glimmerResolver.resolve(specifier, source); - } - -}); - -export default Resolver; diff --git a/mu-trees/tests/unit/module-registries/requirejs-test.js b/mu-trees/tests/unit/module-registries/requirejs-test.js deleted file mode 100644 index a0832d28..00000000 --- a/mu-trees/tests/unit/module-registries/requirejs-test.js +++ /dev/null @@ -1,135 +0,0 @@ -import RequireJSRegistry from 'ember-resolver/module-registries/requirejs'; -import { module, test} from 'qunit'; - -export let config = { - app: { - name: 'example-app', - rootName: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - partial: { definiteCollection: 'partials' }, - service: { definitiveCollection: 'services' }, - route: { definitiveCollection: 'routes' }, - router: { definitiveCollection: 'main' }, - template: { definitiveCollection: 'components' } - }, - collections: { - 'main': { - types: ['router'] - }, - components: { - group: 'ui', - types: ['component', 'helper', 'template'] - }, - partials: { - group: 'ui', - types: [ 'template' ] - }, - routes: { - defaultType: 'route', - group: 'ui', - privateCollections: ['components'], - types: ['route', 'controller', 'template'] - }, - services: { - defaultType: 'service', - types: ['service'] - } - } -}; - -function buildMockRequire() { - let mockRequire = modulePath => mockRequire.entries[modulePath]; - mockRequire.entries = {}; - return mockRequire; -} - -module('RequireJS Registry', { - beforeEach() { - this.mockRequire = buildMockRequire(); - this.mockRequire.entries = {}; - this.config = config; - this.registry = new RequireJSRegistry(this.config, 'src', this.mockRequire); - }, - - addModule(name, module) { - this.mockRequire.entries[name] = module; - } - -}); - -test('basic get', function(assert) { - assert.expect(11); - - [ - /* - * Over time lets move these general cases into specific tests that - * describe their aim. - */ - [ 'router:/my-app/main/main', 'my-app/src/router' ], - [ 'route:/my-app/routes/application', 'my-app/src/ui/routes/application/route' ], - [ 'template:/my-app/routes/application', 'my-app/src/ui/routes/application/template' ], - [ 'component:/my-app/components/my-input', 'my-app/src/ui/components/my-input/component' ], - [ 'template:/my-app/routes/components/my-input', 'my-app/src/ui/components/my-input/template' ], - [ 'template:/my-app/components/my-input', 'my-app/src/ui/components/my-input/template' ], - [ 'component:/my-app/components/my-input/my-button', 'my-app/src/ui/components/my-input/my-button/component' ], - [ 'template:/my-app/components/my-input/my-button', 'my-app/src/ui/components/my-input/my-button/template' ], - [ 'service:/my-app/services/main', 'my-app/src/services/main' ], - [ 'component:/my-app/components/main', 'my-app/src/ui/components/main/component' ], - [ 'template:/my-app/components/main', 'my-app/src/ui/components/main/template' ], - - ] - .forEach(([ lookupString, expected ]) => { - let expectedModule = {}; - this.mockRequire.entries = { - [expected]: {default: expectedModule} - }; - let actualModule = this.registry.get(lookupString); - assert.equal(actualModule, expectedModule, `get ${lookupString} -> ${expected}`); - }); -}); - -test('typed module name with default export', function(assert) { - let expectedModule = {}; - this.addModule(`my-app/src/ui/routes/index/route`, {default: expectedModule}); - - let actualModule = this.registry.get(`route:/my-app/routes/index`); - assert.equal( - actualModule, expectedModule, - `resolved the module` - ); -}); - -test('un-typed module name with default export when resolved type is the defaultType', function(assert) { - let expectedModule = {}; - this.addModule(`my-app/src/ui/routes/index`, {default: expectedModule}); - - let actualModule = this.registry.get(`route:/my-app/routes/index`); - assert.equal( - actualModule, expectedModule, - `resolved the module` - ); -}); - -test('un-typed module name with default export when resolved type is not the defaultType', function(assert) { - let expectedModule = {}; - this.addModule(`my-app/src/ui/routes/index`, {default: expectedModule}); - - let actualModule = this.registry.get(`template:/my-app/routes/index`); - assert.notOk( - actualModule, - `did not resolve the module` - ); -}); - -test('un-typed module name with named export of resolved type', function(assert) { - let expectedModule = {}; - this.addModule(`my-app/src/ui/routes/index`, {template: expectedModule}); - - let actualModule = this.registry.get(`template:/my-app/routes/index`); - assert.equal( - actualModule, expectedModule, - `did not resolve the module` - ); -}); diff --git a/mu-trees/tests/unit/resolvers/fallback/basic-test.js b/mu-trees/tests/unit/resolvers/fallback/basic-test.js deleted file mode 100644 index b86827bd..00000000 --- a/mu-trees/tests/unit/resolvers/fallback/basic-test.js +++ /dev/null @@ -1,64 +0,0 @@ -import { module, test } from 'qunit'; -import Resolver from 'ember-resolver/resolvers/fallback'; -import BasicRegistry from '@glimmer/resolver/module-registries/basic-registry'; - -module('ember-resolver/resolvers/fallback', { - beforeEach() { - this.main = {}; - let glimmerModuleRegistry = new BasicRegistry({ - 'router:/app/main/main': this.main - }); - - this.resolver = Resolver.create({ - config: { - app: { - name: 'example-app' - }, - types: { - router: { definitiveCollection: 'main' } - }, - collections: { - main: { - types: [ 'router' ] - } - } - }, - glimmerModuleRegistry - }); - - this.classicResolverCalls = []; - this.classic = {}; - this.resolver._fallback.resolve = (specifier) => { - this.classicResolverCalls.push(specifier); - return specifier.indexOf('classic') !== -1 ? this.classic : null; - }; - } -}); - -test('resolves from glimmer resolver', function(assert) { - assert.equal(this.resolver.resolve('router:/app/main/main'), this.main, 'returns glimmer resolver result'); - assert.equal(this.classicResolverCalls.length, 0, 'no calls to classic resolver'); -}); - -test('resolves from classic resolver', function(assert) { - assert.equal(this.resolver.resolve('router:/app/main/classic', 'referrer'), this.classic, 'returns classic resolver result'); -}); - -test('resolves normalized specifiers classic resolver', function(assert) { - this.resolver._fallback.resolve = (specifier) => { - return specifier === 'router:classic-router' ? this.classic : null; - }; - - assert.equal(this.resolver.resolve('router:classicRouter'), this.classic, 'returns classic resolver result'); -}); - -test('returns null if neither resolver resolves', function(assert) { - let specifier = 'router:/app/main/nowhere'; - let referrer = 'router:/app/main/referrer'; - assert.equal(this.resolver.resolve(specifier, referrer), null, 'returns null when neither resolver resolves'); - assert.deepEqual(this.classicResolverCalls, [ specifier ], 'classic resolver called'); -}); - -test('it sets the correct namespace on the fallback resolver', function(assert) { - assert.deepEqual(this.resolver._fallback.namespace, { modulePrefix: 'example-app' }); -}); diff --git a/mu-trees/tests/unit/resolvers/glimmer-wrapper/expand-local-lookup-test.js b/mu-trees/tests/unit/resolvers/glimmer-wrapper/expand-local-lookup-test.js deleted file mode 100644 index af6ac1af..00000000 --- a/mu-trees/tests/unit/resolvers/glimmer-wrapper/expand-local-lookup-test.js +++ /dev/null @@ -1,315 +0,0 @@ -import { module, test } from 'qunit'; -import Resolver from 'ember-resolver/resolvers/glimmer-wrapper'; -import BasicRegistry from '@glimmer/resolver/module-registries/basic-registry'; - -module('ember-resolver/resolvers/glimmer-wrapper#expandLocalLookup', { - beforeEach() { - this.resolverForEntries = (config, entries) => { - let glimmerModuleRegistry = new BasicRegistry(entries); - return Resolver.create({ - config, - glimmerModuleRegistry - }); - }; - } -}); - -test('Can expand private component template', function(assert) { - let template = {}; - let notTemplate = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - }, - routes: { - group: 'ui', - types: [ 'template' ], - privateCollections: ['components'] - } - } - }, { - 'template:/app/routes/my-page/my-input': notTemplate, - 'template:/app/routes/my-page/-components/my-input': template - }); - - - assert.equal( - resolver.expandLocalLookup('template:components/my-input', 'template:src/ui/routes/my-page'), - 'template:/app/routes/my-page/-components/my-input', - 'relative module specifier with source resolved w/ normalization' - ); -}); - -test('Can expand a local component for a route', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'component:/app/routes/posts/-components/my-input': component - }); - - assert.equal( - resolver.expandLocalLookup('component:my-input', 'template:src/ui/routes/posts'), - 'component:/app/routes/posts/-components/my-input', - 'component resolved' - ); - assert.equal( - resolver.expandLocalLookup('component:my-input'), - 'component:my-input', - 'component not resolved at global level' - ); -}); - -test('Can expand a namespaced service lookup', function(assert) { - let service = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - service: { definitiveCollection: 'services' } - }, - collections: { - services: { - types: [ 'service' ] - } - } - }, { - 'service:/other-namespace/services/i18n': service - }); - - assert.equal( - resolver.expandLocalLookup('service:i18n', null, 'other-namespace'), - 'service:/other-namespace/services/i18n', - 'namespaced resolution resolved' - ); -}); - -test('Can expand a namespaced component template', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - } - } - }, { - 'template:/other-namespace/components/my-component': template - }); - - assert.equal( - resolver.expandLocalLookup('template:components/my-component', null, 'other-namespace'), - 'template:/other-namespace/components/my-component', - 'namespaced resolution resolved' - ); -}); - -test('Can expand a namespaced component object', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component' ] - } - } - }, { - 'component:/other-namespace/components/my-component': component - }); - - assert.equal( - resolver.expandLocalLookup('component:my-component', null, 'other-namespace'), - 'component:/other-namespace/components/my-component', - 'namespaced resolution resolved' - ); -}); - -test('Can expand a local component for another component', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'component:/app/components/my-parent/my-input': component - }); - - assert.equal( - resolver.expandLocalLookup('component:my-input', 'template:src/ui/components/my-parent'), - 'component:/app/components/my-parent/my-input', - 'component resolved' - ); - assert.equal( - resolver.expandLocalLookup('component:my-input'), - 'component:my-input', - 'component not resolved at global levelt' - ); -}); - -test('Can expand a local helper for another component', function(assert) { - let helper = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - helper: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'helper:/app/components/my-parent/my-input': helper - }); - - assert.equal( - resolver.expandLocalLookup('helper:my-input', 'template:src/ui/components/my-parent'), - 'helper:/app/components/my-parent/my-input', - 'helper resolved' - ); - assert.equal( - resolver.expandLocalLookup('helper:my-input'), - 'helper:my-input', - 'helper not resolved at global levelt' - ); -}); - -// Main addon component and service - -test('Can expand a namespaced main service lookup', function(assert) { - let service = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - service: { definitiveCollection: 'services' } - }, - collections: { - services: { - types: [ 'service' ] - } - } - }, { - 'service:/other-namespace/services/main': service - }); - - assert.equal( - resolver.expandLocalLookup('service:other-namespace'), - 'service:other-namespace', - 'namespaced resolution resolved' - ); -}); - -test('Can expand a namespaced main component template', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - } - } - }, { - 'template:/other-namespace/components/main': template - }); - - assert.equal( - resolver.expandLocalLookup('template:components/other-namespace'), - 'template:components/other-namespace', - 'namespaced resolution resolved' - ); -}); - -test('Can expand a namespaced component object', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component' ] - } - } - }, { - 'component:/other-namespace/components/main': component - }); - - assert.equal( - resolver.expandLocalLookup('component:other-namespace'), - 'component:other-namespace', - 'namespaced resolution resolved' - ); -}); diff --git a/mu-trees/tests/unit/resolvers/glimmer-wrapper/normalize-test.js b/mu-trees/tests/unit/resolvers/glimmer-wrapper/normalize-test.js deleted file mode 100644 index 6fc143e2..00000000 --- a/mu-trees/tests/unit/resolvers/glimmer-wrapper/normalize-test.js +++ /dev/null @@ -1,30 +0,0 @@ -import { module, test } from 'qunit'; -import Resolver from 'ember-resolver/resolvers/glimmer-wrapper'; -import BasicRegistry from '@glimmer/resolver/module-registries/basic-registry'; - -let resolver; -module('ember-resolver/resolvers/glimmer-wrapper#normalize', { - beforeEach() { - - let glimmerModuleRegistry = new BasicRegistry(); - - resolver = Resolver.create({ - config: { - app: { - name: 'example-app' - } - }, - glimmerModuleRegistry - }); - } -}); - -test('normalization', function(assert) { - assert.ok(resolver.normalize, 'resolver#normalize is present'); - - assert.equal(resolver.normalize('service:myService'), 'service:my-service'); - - // `expandLocalLookup` calls this.normalize(options.source) with `source` empty with MU addon - assert.equal(resolver.normalize(), undefined); - -}); diff --git a/mu-trees/tests/unit/resolvers/glimmer-wrapper/resolve-test.js b/mu-trees/tests/unit/resolvers/glimmer-wrapper/resolve-test.js deleted file mode 100644 index 85f9430c..00000000 --- a/mu-trees/tests/unit/resolvers/glimmer-wrapper/resolve-test.js +++ /dev/null @@ -1,754 +0,0 @@ -import { module, test } from 'qunit'; -import Resolver from 'ember-resolver/resolvers/glimmer-wrapper'; -import BasicRegistry from '@glimmer/resolver/module-registries/basic-registry'; - -module('ember-resolver/resolvers/glimmer-wrapper#resolve', { - beforeEach() { - this.resolverForEntries = (config, entries) => { - let glimmerModuleRegistry = new BasicRegistry(entries); - return Resolver.create({ - config, - glimmerModuleRegistry - }); - }; - } -}); - -/* - * "Rule 1" of the unification RFC. - * - * See: https://github.com/dgeb/rfcs/blob/module-unification/text/0000-module-unification.md#module-type - */ - -test('Modules named main', function(assert) { - let main = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - router: { definitiveCollection: 'main' } - }, - collections: { - main: { - types: [ 'router' ] - } - } - }, { - 'router:/app/main/main': main - }); - - assert.equal( - resolver.resolve('router:/app/main/main'), - main, - 'absolute module specifier resolved' - ); - - assert.equal( - resolver.resolve('router:main'), - main, - 'relative module specifier resolved' - ); -}); - -test('Resolving when a module is not defined', function(assert) { - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - router: { definitiveCollection: 'main' } - }, - collections: { - main: { - types: [ 'router' ] - } - } - }, {}); - - assert.equal( - resolver.resolve('router:/app/main/main'), - undefined, - 'absolute module specifier resolved undefined' - ); - - assert.equal( - resolver.resolve('router:main'), - undefined, - 'relative module specifier resolved undefined' - ); -}); - -test('Services with camelCare are normalized', function(assert) { - let expectedModule = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - service: { definitiveCollection: 'services' } - }, - collections: { - services: { - types: [ 'service' ] - } - } - }, { - 'service:/app/services/camel-case': expectedModule - }); - - assert.equal( - resolver.resolve('service:camelCase'), - expectedModule, - 'camelCase services are dasherized' - ); -}); - -test('Routes with dots are normalized', function(assert) { - let expectedModule = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - route: { definitiveCollection: 'routes' } - }, - collections: { - routes: { - types: [ 'route' ] - } - } - }, { - 'route:/app/routes/parent/child': expectedModule - }); - - assert.equal( - resolver.resolve('route:parent.child'), - expectedModule, - 'route names with dots are slasherized' - ); -}); - -test('Controllers with dots are normalized', function(assert) { - let expectedModule = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - controller: { definitiveCollection: 'controllers' } - }, - collections: { - controllers: { - types: [ 'controller' ] - } - } - }, { - 'controller:/app/controllers/parent/child': expectedModule - }); - - assert.equal( - resolver.resolve('controller:parent.child'), - expectedModule, - 'controller names with dots are slasherized' - ); -}); - -/* - * "Rule 2" of the unification RFC. - * - * See: https://github.com/dgeb/rfcs/blob/module-unification/text/0000-module-unification.md#module-type - */ - -test('Resolving in a collection', function(assert) { - let service = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - service: { definitiveCollection: 'services' } - }, - collections: { - services: { - types: [ 'service' ] - } - } - }, { - 'service:/app/services/i18n': service - }); - - assert.equal( - resolver.resolve('service:/app/services/i18n'), - service, - 'absolute module specifier resolved' - ); - - assert.equal( - resolver.resolve('service:i18n'), - service, - 'relative module specifier resolved' - ); -}); - -/* - * "Rule 2" of the unification RFC with a group. - */ - -test('Resolving within a definitiveCollection', function(assert) { - let helper = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - helper: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'helper' ] - } - } - }, { - 'helper:/app/components/capitalize': helper - }); - - assert.equal( - resolver.resolve('helper:/app/components/capitalize'), - helper, - 'absolute module specifier resolved' - ); - - assert.equal( - resolver.resolve('helper:capitalize'), - helper, - 'relative module specifier resolved' - ); -}); - -test('Resolving within a definitiveCollection', function(assert) { - let helper = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - helper: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'helper' ] - } - } - }, { - 'helper:/app/components/capitalize': helper - }); - - assert.equal( - resolver.resolve('helper:/app/components/capitalize'), - helper, - 'absolute module specifier resolved' - ); - - assert.equal( - resolver.resolve('helper:capitalize'), - helper, - 'relative module specifier resolved' - ); -}); - -test('Resolving within a definitiveCollection with other defined types', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - helper: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'helper' ] - } - } - }, { - 'component:/app/components/capitalize': component - }); - - assert.equal( - resolver.resolve('component:/app/components/capitalize'), - component, - 'absolute module specifier resolved' - ); - - assert.equal( - resolver.resolve('component:capitalize'), - component, - 'relative module specifier resolved' - ); -}); - -test('Can resolve with a / in the specifier', function(assert) { - let route = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - route: { definitiveCollection: 'routes' } - }, - collections: { - routes: { - group: 'ui', - types: [ 'route' ] - } - } - }, { - 'route:/app/routes/my-form/my-input': route - }); - - assert.equal( - resolver.resolve('route:/app/routes/my-form/my-input'), - route, - 'absolute module specifier not resolved' - ); - - assert.equal( - resolver.resolve('route:my-form/my-input'), - route, - 'relative module specifier not resolved' - ); -}); - -/* - * "Rule 3" of the unification RFC. Rule 3 means a default type for a collection - * is configured. - * - * There is no runtime implementation of this part of the spec. - */ - -/* - * Other tests. - * - */ -test('Can not resolve a top level template of a non-definitive type', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'template:/app/routes/my-input': template - }); - - assert.equal( - resolver.resolve('template:components/my-input', 'template:/app/routes/posts'), - undefined, - 'route collection module not resolved' - ); - assert.equal( - resolver.resolve('template:components/my-input', 'template:src/ui/routes/posts'), - undefined, - 'route collection module not resolved' - ); -}); - -test('Can resolve a top level template of a definitive type', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'template:/app/components/my-input': template - }); - - assert.equal( - resolver.resolve('template:components/my-input', 'template:/app/routes/posts'), - template, - 'relative module specifier with source resolved' - ); - assert.equal( - resolver.resolve('template:components/my-input', 'template:src/ui/routes/posts'), - template, - 'relative module specifier with source resolved' - ); -}); - -test('Can resolve component template', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - }, - routes: { - group: 'ui', - types: [ 'template' ] - } - } - }, { - 'template:/app/components/my-input': template - }); - - assert.equal( - resolver.resolve('template:components/my-input'), - template, - 'relative module specifier with source resolved' - ); -}); - -test('Can resolve a partial', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - partial: { definitiveCollection: 'partials' } - }, - collections: { - partials: { - group: 'ui', - defaultType: 'partial', - types: ['partial'] - } - } - }, { - 'partial:/app/partials/author': template - }); - - assert.equal( - resolver.resolve('template:_author', ''), - template, - 'partial resolved' - ); -}); - -test('Can normalize and resolve a template for route', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - routes: { - group: 'ui', - defaultType: 'route', - types: ['route', 'template'] - }, - components: { - group: 'ui', - types: ['template'] - } - } - }, { - 'template:/app/routes/parent/child': template - }); - - assert.equal( - resolver.resolve('template:parent/child'), - template, - 'template resolved' - ); - assert.equal( - resolver.resolve('template:parent.child'), - template, - 'template normalized and resolved' - ); -}); - -test('Can resolve template in a route correctly', function(assert) { - let routeTemplate = {}; - let componentTemplate = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - }, - routes: { - group: 'ui', - types: [ 'template' ], - privateCollections: ['components'] - } - } - }, { - 'template:/app/routes/my-page': routeTemplate, - 'template:/app/components/my-page': componentTemplate - }); - - assert.equal( - resolver.resolve('template:my-page'), - routeTemplate, - 'relative module found in routes' - ); - assert.equal( - resolver.resolve('template:components/my-page'), - componentTemplate, - 'relative module found in routes' - ); -}); - -test('Does not fall back when resolving route', function(assert) { - let componentTemplate = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - }, - routes: { - group: 'ui', - types: [ 'template' ], - privateCollections: ['components'] - } - } - }, { - 'template:/app/components/my-page': componentTemplate - }); - - assert.equal( - resolver.resolve('template:my-page'), - undefined, - 'relative module found in routes' - ); - assert.equal( - resolver.resolve('template:components/my-page'), - componentTemplate, - 'relative module found in routes' - ); -}); - -test('Can not resolve a local component for a route without source', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'component:/app/routes/posts/-components/my-input': component - }); - - assert.equal( - resolver.resolve('component:my-input'), - undefined, - 'component not resolved at global level' - ); -}); - -test('Can not resolve a local component for another component without source', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - route: { definitiveCollection: 'routes' }, - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'component:/app/components/my-parent/my-input': component - }); - - assert.equal( - resolver.resolve('component:my-input'), - undefined, - 'component not resolved at global levelt' - ); -}); - -test('Can not resolve a local helper for another component without source', function(assert) { - let helper = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' }, - helper: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component', 'template' ] - }, - routes: { - group: 'ui', - types: [ 'route', 'template' ] - } - } - }, { - 'helper:/app/components/my-parent/my-input': helper - }); - - assert.equal( - resolver.resolve('helper:my-input'), - undefined, - 'helper not resolved at global levelt' - ); -}); - -// Main addon component and service - -test('Can resolve a namespaced main service lookup', function(assert) { - let service = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - service: { definitiveCollection: 'services' } - }, - collections: { - services: { - types: [ 'service' ] - } - } - }, { - 'service:/other-namespace/services/main': service - }); - - assert.equal( - resolver.resolve('service:other-namespace'), - service, - 'namespaced resolution resolved' - ); -}); - -test('Can resolve a namespaced main component template', function(assert) { - let template = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - template: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'template' ] - } - } - }, { - 'template:/other-namespace/components/main': template - }); - - assert.equal( - resolver.resolve('template:components/other-namespace'), - template, - 'namespaced resolution resolved' - ); -}); - -test('Can resolve a namespaced component object', function(assert) { - let component = {}; - let resolver = this.resolverForEntries({ - app: { - name: 'example-app' - }, - types: { - component: { definitiveCollection: 'components' } - }, - collections: { - components: { - group: 'ui', - types: [ 'component' ] - } - } - }, { - 'component:/other-namespace/components/main': component - }); - - assert.equal( - resolver.resolve('component:other-namespace'), - component, - 'namespaced resolution resolved' - ); -}); diff --git a/package.json b/package.json index 17804b8b..b34f9062 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "test:all": "ember try:each" }, "dependencies": { - "@glimmer/resolver": "^0.4.1", "babel-plugin-debug-macros": "^0.3.3", "broccoli-funnel": "^2.0.2", "broccoli-merge-trees": "^3.0.0",