Skip to content

Commit

Permalink
Merge pull request #186 from salsify/improve-missing-module-error-mes…
Browse files Browse the repository at this point in the history
…sage

Restore 1.2.x timing for config calculation
  • Loading branch information
dfreeman authored Apr 8, 2020
2 parents b337c2a + 7a03cd3 commit c55e655
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 17 additions & 3 deletions packages/ember-css-modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ module.exports = {
}

this._super.included.apply(this, arguments);

this.cssModulesOptions = this.plugins.computeOptions(includer.options && includer.options.cssModules);
this.setupTemplateTransform();
},

treeForAddon() {
Expand All @@ -56,12 +59,23 @@ module.exports = {
// Skip if we're setting up this addon's own registry
if (type !== 'parent') { return; }

let includerOptions = this.app ? this.app.options : this.parent.options;
this.cssModulesOptions = this.plugins.computeOptions(includerOptions && includerOptions.cssModules);
this.parentPreprocessorRegistry = registry;

registry.add('js', this.modulesPreprocessor);
registry.add('css', this.outputStylesPreprocessor);
registry.add('htmlbars-ast-plugin', HtmlbarsPlugin.instantiate({
},

setupTemplateTransform() {
// This is a pretty sketchy approach, as we're adding another entry to the
// template transform registry long after `setupPreprocessorRegistry` was called,
// but for backcompat reasons, we need to wait to compute the effective ECM
// options until our own `included()` hook, and we need those options in order
// to configure the template transform.
if (!this.parentPreprocessorRegistry) {
throw new Error('[ember-css-modules] internal error: unable to locate parent preprocessor registry');
}

this.parentPreprocessorRegistry.add('htmlbars-ast-plugin', HtmlbarsPlugin.instantiate({
emberVersion: this.checker.forEmber().version,
options: {
fileExtension: this.getFileExtension(),
Expand Down
9 changes: 6 additions & 3 deletions packages/ember-css-modules/lib/resolve-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function resolvePath(importPath, fromFile, options) {
} else if (isLocalPath(pathWithExtension, options)) {
return resolveLocalPath(pathWithExtension, fromFile, options);
} else {
return resolveExternalPath(pathWithExtension, options);
return resolveExternalPath(pathWithExtension, importPath, fromFile, options);
}
};

Expand All @@ -37,13 +37,16 @@ function resolveLocalPath(importPath, fromFile, options) {
}

// Resolve absolute paths pointing to external addons
function resolveExternalPath(importPath, options) {
function resolveExternalPath(importPath, originalPath, fromFile, options) {
let baseIndex = importPath[0] === '@' ? importPath.indexOf('/') + 1 : 0;
let addonName = importPath.substring(0, importPath.indexOf('/', baseIndex));
let addon = options.parent.addons.find(addon => addon.name === addonName);

if (!addon) {
throw new Error(`Unable to resolve styles from addon ${addonName}; is it installed?`);
throw new Error(
`Unable to resolve styles module '${originalPath}' imported from '${fromFile}'. ` +
`No virtual module with that name was defined and no corresponding addon was found.`
);
}

let pathWithinAddon = importPath.substring(addonName.length + 1);
Expand Down

0 comments on commit c55e655

Please sign in to comment.