Skip to content

Commit 7124bcc

Browse files
author
Tim Lindvall
committed
Fix resolution of addons with moduleName.
- For CSS processing, use moduleName() if it's defined on the parent. This is the name that the template and other references in the build will go by, so without this, the template and CSS module will disagree. - When resolving external import paths, prefer moduleName() if it's defined.
1 parent 2179f72 commit 7124bcc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/ember-css-modules/lib/modules-preprocessor.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = class ModulesPreprocessor {
1515
this._modulesTree = null;
1616
this._modulesBasePath = null;
1717
this._modulesBridge = new Bridge();
18+
this._parentName = null;
1819
}
1920

2021
toTree(inputTree, path) {
@@ -37,10 +38,16 @@ module.exports = class ModulesPreprocessor {
3738
});
3839
}
3940

41+
// If moduleName is defined, that should override the parent's name.
42+
// Otherwise, the template and generated module will disagree as to what the path should be.
43+
let ownerParent = this.owner.getParent();
44+
let parentName = ownerParent.moduleName ? ownerParent.moduleName() : this.owner.getParentName();
45+
this._parentName = parentName;
46+
4047
let modulesSources = new ModuleSourceFunnel(inputRoot, modulesInput, {
4148
include: ['**/*.' + this.owner.getFileExtension()],
4249
outputRoot,
43-
parentName: this.owner.getParentName()
50+
parentName,
4451
});
4552

4653
let modulesTree = new (require('broccoli-css-modules'))(modulesSources, {
@@ -184,7 +191,7 @@ module.exports = class ModulesPreprocessor {
184191

185192
return this._resolvePath(importPath, fromFile, {
186193
defaultExtension: this.owner.getFileExtension(),
187-
ownerName: this.owner.getParentName(),
194+
ownerName: this._parentName || this.owner.getParentName(),
188195
addonModulesRoot: this.owner.getAddonModulesRoot(),
189196
root: ensurePosixPath(this._modulesTree.inputPaths[0]),
190197
parent: this.owner.getParent()

packages/ember-css-modules/lib/resolve-path.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ function resolveLocalPath(importPath, fromFile, options) {
4949
function resolveExternalPath(importPath, originalPath, fromFile, options) {
5050
let baseIndex = importPath[0] === '@' ? importPath.indexOf('/') + 1 : 0;
5151
let addonName = importPath.substring(0, importPath.indexOf('/', baseIndex));
52-
let addon = options.parent.addons.find(addon => addon.name === addonName);
52+
let addon = options.parent.addons.find((addon) => {
53+
if (addon.moduleName) {
54+
return addon.moduleName() === addonName;
55+
}
56+
return addon.name === addonName;
57+
});
5358

5459
if (!addon) {
5560
throw new Error(

0 commit comments

Comments
 (0)