ember-css-modules 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/helpers/local-class.js +10 -3
- package/addon/index.js +0 -1
- package/app/initializers/ensure-local-class-included.js +2 -2
- package/config/environment.js +2 -2
- package/index.js +49 -58
- package/lib/htmlbars-plugin/index.js +64 -68
- package/lib/htmlbars-plugin/utils.js +7 -7
- package/lib/modules-preprocessor.js +61 -58
- package/lib/output-styles-preprocessor.js +48 -57
- package/lib/plugin/registry.js +25 -11
- package/lib/resolve-path.js +37 -13
- package/lib/utils/normalize-postcss-plugins.js +1 -1
- package/package.json +57 -51
- package/.template-lintrc.js +0 -8
- package/addon/decorators.js +0 -168
- package/addon/extensions.js +0 -4
- package/addon/mixins/component-mixin.js +0 -111
- package/index.d.ts +0 -40
- package/lib/make-postcss-plugin.js +0 -18
- package/lib/postcss-module-order-directive.js +0 -29
- package/vendor/~ember-css-modules/ext.js +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Funnel = require('broccoli-funnel');
|
|
3
|
+
const { Funnel } = require('broccoli-funnel');
|
|
4
4
|
const MergeTrees = require('broccoli-merge-trees');
|
|
5
5
|
const Bridge = require('broccoli-bridge');
|
|
6
6
|
const ensurePosixPath = require('ensure-posix-path');
|
|
@@ -31,35 +31,37 @@ module.exports = class ModulesPreprocessor {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
toTree(inputTree, path) {
|
|
34
|
-
if (path !== '/') {
|
|
34
|
+
if (path !== '/') {
|
|
35
|
+
return inputTree;
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
let merged = new MergeTrees([inputTree, this.buildModulesTree(inputTree)], {
|
|
38
|
+
let merged = new MergeTrees([inputTree, this.buildModulesTree(inputTree)], {
|
|
39
|
+
overwrite: true,
|
|
40
|
+
});
|
|
37
41
|
|
|
38
42
|
// Exclude the individual CSS files – those will be concatenated into the styles tree later
|
|
39
|
-
return new Funnel(merged, {
|
|
43
|
+
return new Funnel(merged, {
|
|
44
|
+
exclude: ['**/*.' + this.owner.getFileExtension()],
|
|
45
|
+
});
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
buildModulesTree(modulesInput) {
|
|
43
49
|
if (!this._modulesTree) {
|
|
44
|
-
let inputRoot = this.owner.belongsToAddon()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (outputRoot) {
|
|
48
|
-
inputRoot = new Funnel(inputRoot, {
|
|
49
|
-
destDir: outputRoot,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
50
|
+
let inputRoot = this.owner.belongsToAddon()
|
|
51
|
+
? this.owner.getParentAddonTree()
|
|
52
|
+
: this.owner.app.trees.app;
|
|
52
53
|
|
|
53
54
|
// If moduleName is defined, that should override the parent's name.
|
|
54
55
|
// Otherwise, the template and generated module will disagree as to what the path should be.
|
|
55
56
|
let ownerParent = this.owner.getParent();
|
|
56
57
|
this._parentName = this.owner.getParentName();
|
|
57
|
-
let ownerName = ownerParent.moduleName
|
|
58
|
+
let ownerName = ownerParent.moduleName
|
|
59
|
+
? ownerParent.moduleName()
|
|
60
|
+
: this._parentName;
|
|
58
61
|
this._ownerName = ownerName;
|
|
59
62
|
|
|
60
63
|
let modulesSources = new ModuleSourceFunnel(inputRoot, modulesInput, {
|
|
61
64
|
include: ['**/*.' + this.owner.getFileExtension()],
|
|
62
|
-
outputRoot,
|
|
63
65
|
parentName: ownerName,
|
|
64
66
|
});
|
|
65
67
|
|
|
@@ -67,12 +69,12 @@ module.exports = class ModulesPreprocessor {
|
|
|
67
69
|
extension: this.owner.getFileExtension(),
|
|
68
70
|
plugins: this.getPostcssPlugins(),
|
|
69
71
|
enableSourceMaps: this.owner.enableSourceMaps(),
|
|
70
|
-
sourceMapBaseDir:
|
|
72
|
+
sourceMapBaseDir: '',
|
|
71
73
|
postcssOptions: this.owner.getPostcssOptions(),
|
|
72
74
|
virtualModules: this.owner.getVirtualModules(),
|
|
73
75
|
generateScopedName: this.scopedNameGenerator(),
|
|
74
76
|
resolvePath: this.resolveAndRecordPath.bind(this),
|
|
75
|
-
getJSFilePath: cssPath => this.getJSFilePath(cssPath, modulesSources),
|
|
77
|
+
getJSFilePath: (cssPath) => this.getJSFilePath(cssPath, modulesSources),
|
|
76
78
|
onBuildStart: () => this.owner.notifyPlugins('buildStart'),
|
|
77
79
|
onBuildEnd: () => this.owner.notifyPlugins('buildEnd'),
|
|
78
80
|
onBuildSuccess: () => this.owner.notifyPlugins('buildSuccess'),
|
|
@@ -80,7 +82,7 @@ module.exports = class ModulesPreprocessor {
|
|
|
80
82
|
onProcessFile: this.resetFileDependencies.bind(this),
|
|
81
83
|
onModuleResolutionFailure: this.onModuleResolutionFailure.bind(this),
|
|
82
84
|
onImportResolutionFailure: this.onImportResolutionFailure.bind(this),
|
|
83
|
-
formatJS: formatJS
|
|
85
|
+
formatJS: formatJS,
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
this._modulesTree = modulesTree;
|
|
@@ -108,7 +110,10 @@ module.exports = class ModulesPreprocessor {
|
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
let extensionRegex = new RegExp(`\\.${this.owner.getFileExtension()}$`);
|
|
111
|
-
let cssPathWithoutExtension = cssPathWithExtension.replace(
|
|
113
|
+
let cssPathWithoutExtension = cssPathWithExtension.replace(
|
|
114
|
+
extensionRegex,
|
|
115
|
+
''
|
|
116
|
+
);
|
|
112
117
|
|
|
113
118
|
if (modulesSource.has(`${cssPathWithoutExtension}.hbs`)) {
|
|
114
119
|
return `${cssPathWithExtension}.js`;
|
|
@@ -119,7 +124,7 @@ module.exports = class ModulesPreprocessor {
|
|
|
119
124
|
|
|
120
125
|
scopedNameGenerator() {
|
|
121
126
|
let generator = this.owner.getScopedNameGenerator();
|
|
122
|
-
return function(className, modulePath, fullRule, dependency) {
|
|
127
|
+
return function (className, modulePath, fullRule, dependency) {
|
|
123
128
|
let realPath = '/' + (dependency.keyPath || modulePath);
|
|
124
129
|
return generator(className, realPath, fullRule);
|
|
125
130
|
};
|
|
@@ -142,7 +147,7 @@ module.exports = class ModulesPreprocessor {
|
|
|
142
147
|
|
|
143
148
|
this._plugins = {
|
|
144
149
|
before: [this.rootPathPlugin()].concat(plugins.before || []),
|
|
145
|
-
after:
|
|
150
|
+
after: plugins.after || [],
|
|
146
151
|
};
|
|
147
152
|
}
|
|
148
153
|
|
|
@@ -150,7 +155,9 @@ module.exports = class ModulesPreprocessor {
|
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
onModuleResolutionFailure(failure, modulePath, fromFile) {
|
|
153
|
-
throw new Error(
|
|
158
|
+
throw new Error(
|
|
159
|
+
'Unable to locate module "' + modulePath + '" imported from ' + fromFile
|
|
160
|
+
);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
onImportResolutionFailure(symbol, modulePath, fromFile) {
|
|
@@ -161,42 +168,34 @@ module.exports = class ModulesPreprocessor {
|
|
|
161
168
|
absolutePath = this.resolvePath(modulePath, fromFile);
|
|
162
169
|
}
|
|
163
170
|
|
|
164
|
-
throw new Error(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
recordDependencies(fromFile, type, resolvedPaths) {
|
|
168
|
-
debug('recording %s dependencies from %s to %o', type, fromFile, resolvedPaths);
|
|
169
|
-
let deps = this.getDependencies();
|
|
170
|
-
let fileDeps = deps[fromFile] || (deps[fromFile] = {});
|
|
171
|
-
fileDeps[type] = (fileDeps[type] || []).concat(resolvedPaths);
|
|
171
|
+
throw new Error(
|
|
172
|
+
`No class or value named '${symbol}' was found in ${absolutePath}, imported from ${fromFile}.`
|
|
173
|
+
);
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
// Records dependencies from `composes` and `@value` imports
|
|
175
177
|
resolveAndRecordPath(importPath, fromFile) {
|
|
176
|
-
let
|
|
177
|
-
this.
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
let resolvedPath = this.resolvePath(importPath, fromFile);
|
|
179
|
+
let allDependencies = this.getDependencies();
|
|
180
|
+
let fileDependencies =
|
|
181
|
+
allDependencies[fromFile] || (allDependencies[fromFile] = []);
|
|
180
182
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return require('./postcss-module-order-directive')({
|
|
186
|
-
ui: this.owner.ui,
|
|
187
|
-
emitDeprecationWarning: !this.owner.cssModulesOptions._silenceAfterModuleDeprecation,
|
|
188
|
-
updateDependencies: function(fromFile, relativePaths) {
|
|
189
|
-
recordDependencies(fromFile, 'explicit', relativePaths.map(function(relativePath) {
|
|
190
|
-
return resolve(relativePath, fromFile);
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
193
|
-
});
|
|
183
|
+
debug('recording dependency from %s to %s', fromFile, resolvedPath);
|
|
184
|
+
fileDependencies.push(resolvedPath);
|
|
185
|
+
|
|
186
|
+
return resolvedPath;
|
|
194
187
|
}
|
|
195
188
|
|
|
196
189
|
rootPathPlugin() {
|
|
197
|
-
return
|
|
198
|
-
|
|
199
|
-
|
|
190
|
+
return Object.assign(
|
|
191
|
+
() => ({
|
|
192
|
+
postcssPlugin: 'root-path-tag',
|
|
193
|
+
Once: (css) => {
|
|
194
|
+
css.source.input.rootPath = this._modulesTree.inputPaths[0];
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
{ postcss: true }
|
|
198
|
+
);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
resolvePath(importPath, fromFile) {
|
|
@@ -206,10 +205,9 @@ module.exports = class ModulesPreprocessor {
|
|
|
206
205
|
defaultExtension: this.owner.getFileExtension(),
|
|
207
206
|
ownerName: this._ownerName,
|
|
208
207
|
parentName: this._parentName,
|
|
209
|
-
addonModulesRoot: this.owner.getAddonModulesRoot(),
|
|
210
208
|
root: ensurePosixPath(this._modulesTree.inputPaths[0]),
|
|
211
209
|
parent: this.owner.getParent(),
|
|
212
|
-
ui: this.owner.ui
|
|
210
|
+
ui: this.owner.ui,
|
|
213
211
|
});
|
|
214
212
|
}
|
|
215
213
|
};
|
|
@@ -223,23 +221,28 @@ function formatJS(classMapping) {
|
|
|
223
221
|
|
|
224
222
|
class ModuleSourceFunnel extends Funnel {
|
|
225
223
|
constructor(input, stylesTree, options) {
|
|
226
|
-
super(input, options);
|
|
227
|
-
this.stylesTree = stylesTree;
|
|
224
|
+
super([input, stylesTree], options);
|
|
228
225
|
this.parentName = options.parentName;
|
|
229
|
-
this.destDir = options.outputRoot;
|
|
230
226
|
this.inputHasParentName = null;
|
|
231
227
|
}
|
|
232
228
|
|
|
233
229
|
has(filePath) {
|
|
234
|
-
let relativePath = this.inputHasParentName
|
|
230
|
+
let relativePath = this.inputHasParentName
|
|
231
|
+
? filePath
|
|
232
|
+
: filePath.replace(`${this.parentName}/`, '');
|
|
235
233
|
return fs.existsSync(`${this.inputPaths[0]}/${relativePath}`);
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
build() {
|
|
239
237
|
if (this.inputHasParentName === null) {
|
|
240
|
-
this.inputHasParentName = fs.existsSync(
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
this.inputHasParentName = fs.existsSync(
|
|
239
|
+
`${this.inputPaths[0]}/${this.parentName}`
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
let stylesTreePath = this.inputPaths[1];
|
|
243
|
+
let stylesTreeHasParentName = fs.existsSync(
|
|
244
|
+
`${stylesTreePath}/${this.parentName}`
|
|
245
|
+
);
|
|
243
246
|
if (stylesTreeHasParentName && !this.inputHasParentName) {
|
|
244
247
|
this.destDir += `/${this.parentName}`;
|
|
245
248
|
}
|
|
@@ -4,7 +4,7 @@ const debug = require('debug')('ember-css-modules:output-styles-preprocessor');
|
|
|
4
4
|
const Concat = require('broccoli-concat');
|
|
5
5
|
const MergeTrees = require('broccoli-merge-trees');
|
|
6
6
|
const PostCSS = require('broccoli-postcss');
|
|
7
|
-
const Funnel = require('broccoli-funnel');
|
|
7
|
+
const { Funnel } = require('broccoli-funnel');
|
|
8
8
|
|
|
9
9
|
module.exports = class OutputStylesPreprocessor {
|
|
10
10
|
constructor(options) {
|
|
@@ -12,12 +12,14 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
toTree(inputNode, inputPath, outputDirectory, options) {
|
|
15
|
-
let outputFile =
|
|
15
|
+
let outputFile =
|
|
16
|
+
this.owner.getIntermediateOutputPath() ||
|
|
17
|
+
options.outputPaths[this.owner.belongsToAddon() ? 'addon' : 'app'];
|
|
16
18
|
let concatOptions = {
|
|
17
19
|
inputFiles: ['**/*.' + this.owner.getFileExtension()],
|
|
18
20
|
outputFile: outputFile,
|
|
19
21
|
allowNone: true,
|
|
20
|
-
sourceMapConfig: this.sourceMapConfig()
|
|
22
|
+
sourceMapConfig: this.sourceMapConfig(),
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
debug('concatenating module stylesheets: %o', concatOptions);
|
|
@@ -32,7 +34,7 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
32
34
|
|
|
33
35
|
concat = new PostCSS(concat, {
|
|
34
36
|
plugins: postprocessPlugins,
|
|
35
|
-
exclude: ['**/*.map']
|
|
37
|
+
exclude: ['**/*.map'],
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -41,7 +43,9 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
41
43
|
if (this.owner.getIntermediateOutputPath()) {
|
|
42
44
|
let passthroughExtensions = this.owner.getPassthroughFileExtensions();
|
|
43
45
|
if (passthroughExtensions.length) {
|
|
44
|
-
inputNode = new Funnel(inputNode, {
|
|
46
|
+
inputNode = new Funnel(inputNode, {
|
|
47
|
+
include: passthroughExtensions.map((ext) => `**/*.${ext}`),
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
return new MergeTrees([inputNode, concat], { overwrite: true });
|
|
47
51
|
} else {
|
|
@@ -50,20 +54,27 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/*
|
|
53
|
-
* A broccoli-concat tree that will dynamically order header files based on
|
|
57
|
+
* A broccoli-concat tree that will dynamically order header files based on dependencies
|
|
58
|
+
* between modules and declared header files.
|
|
54
59
|
*/
|
|
55
60
|
dynamicHeaderConcat(options) {
|
|
56
61
|
let modulesTree = this.owner.getModulesTree();
|
|
57
62
|
let fixedHeaders = this.owner.getFixedModules('header');
|
|
58
63
|
let fixedFooters = this.owner.getFixedModules('footer');
|
|
59
|
-
let
|
|
64
|
+
let getDependentFiles = this.getDependentFiles.bind(
|
|
65
|
+
this,
|
|
66
|
+
new Set(fixedHeaders.concat(fixedFooters))
|
|
67
|
+
);
|
|
60
68
|
|
|
61
69
|
let concat = new Concat(modulesTree, options);
|
|
62
70
|
let build = concat.build;
|
|
63
|
-
concat.build = function() {
|
|
71
|
+
concat.build = function () {
|
|
64
72
|
this.footerFiles = fixedFooters;
|
|
65
|
-
this.headerFiles = fixedHeaders.concat(
|
|
66
|
-
this._headerFooterFilesIndex = makeIndex(
|
|
73
|
+
this.headerFiles = fixedHeaders.concat(getDependentFiles());
|
|
74
|
+
this._headerFooterFilesIndex = makeIndex(
|
|
75
|
+
this.headerFiles,
|
|
76
|
+
this.footerFiles
|
|
77
|
+
);
|
|
67
78
|
return build.apply(this, arguments);
|
|
68
79
|
};
|
|
69
80
|
|
|
@@ -71,54 +82,27 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
/*
|
|
74
|
-
* Based on
|
|
75
|
-
* boosted to the top of
|
|
85
|
+
* Based on dependencies between modules, produce an ordered list of modules that
|
|
86
|
+
* should be boosted to the top of output, just below
|
|
76
87
|
*/
|
|
77
|
-
|
|
78
|
-
let explicitDeps = this.explicitDependencies(fixedModules);
|
|
88
|
+
getDependentFiles(fixedModules) {
|
|
79
89
|
let implicitDeps = this.implicitDependencies(fixedModules);
|
|
80
|
-
let sorted = require('toposort')(
|
|
90
|
+
let sorted = require('toposort')(implicitDeps);
|
|
81
91
|
debug('sorted dependencies %o', sorted);
|
|
82
|
-
return sorted.filter(file => !fixedModules.has(file));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Dependencies due to explicit `@after-module` declarations
|
|
86
|
-
explicitDependencies(fixedModules) {
|
|
87
|
-
let edges = [];
|
|
88
|
-
|
|
89
|
-
this.eachFileWithDependencies('explicit', function(file, deps) {
|
|
90
|
-
let currentFile = file, dep;
|
|
91
|
-
|
|
92
|
-
if (fixedModules.has(currentFile)) {
|
|
93
|
-
throw new Error(`Configured headerFiles and footerFiles can't use @after-module`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// For each file with explicit dependencies, create a chain of edges in the reverse order they appear in source
|
|
97
|
-
for (let i = deps.length - 1; i >= 0; i--) {
|
|
98
|
-
dep = deps[i];
|
|
99
|
-
|
|
100
|
-
if (fixedModules.has(dep)) {
|
|
101
|
-
throw new Error(`Configured headerFiles and footerFiles can't be the target of @after-module`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
edges.push([dep, currentFile]);
|
|
105
|
-
currentFile = dep;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
debug('explicit dependencies: %o', edges);
|
|
110
|
-
return edges;
|
|
92
|
+
return sorted.filter((file) => !fixedModules.has(file));
|
|
111
93
|
}
|
|
112
94
|
|
|
113
95
|
// Dependencies stemming from `composes:` and `@value` directives
|
|
114
96
|
implicitDependencies(fixedModules) {
|
|
115
97
|
let edges = [];
|
|
116
98
|
|
|
117
|
-
this.eachFileWithDependencies(
|
|
99
|
+
this.eachFileWithDependencies(function (file, deps) {
|
|
118
100
|
// headerFiles and footerFiles ignore implicit ordering constraints
|
|
119
|
-
if (fixedModules.has(file)) {
|
|
101
|
+
if (fixedModules.has(file)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
120
104
|
|
|
121
|
-
deps.forEach(function(dep) {
|
|
105
|
+
deps.forEach(function (dep) {
|
|
122
106
|
if (!fixedModules.has(dep)) {
|
|
123
107
|
edges.push([dep, file]);
|
|
124
108
|
}
|
|
@@ -129,19 +113,26 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
129
113
|
return edges;
|
|
130
114
|
}
|
|
131
115
|
|
|
132
|
-
eachFileWithDependencies(
|
|
116
|
+
eachFileWithDependencies(callback) {
|
|
133
117
|
let depMap = this.owner.getModuleDependencies();
|
|
134
118
|
|
|
135
119
|
Object.keys(depMap).forEach((file) => {
|
|
136
|
-
let deps = depMap[file] && depMap[file]
|
|
137
|
-
if (!deps || !deps.length) {
|
|
120
|
+
let deps = depMap[file] && depMap[file];
|
|
121
|
+
if (!deps || !deps.length) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
138
124
|
|
|
139
125
|
let relativeFile = this.owner.getModuleRelativePath(file);
|
|
140
|
-
callback(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
callback(
|
|
127
|
+
relativeFile,
|
|
128
|
+
deps
|
|
129
|
+
.filter(function (dep) {
|
|
130
|
+
return dep.type === 'internal';
|
|
131
|
+
})
|
|
132
|
+
.map(function (dep) {
|
|
133
|
+
return dep.keyPath;
|
|
134
|
+
})
|
|
135
|
+
);
|
|
145
136
|
});
|
|
146
137
|
}
|
|
147
138
|
|
|
@@ -149,7 +140,7 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
149
140
|
if (this.owner.enableSourceMaps()) {
|
|
150
141
|
return {
|
|
151
142
|
extensions: ['css'],
|
|
152
|
-
mapCommentType: 'block'
|
|
143
|
+
mapCommentType: 'block',
|
|
153
144
|
};
|
|
154
145
|
}
|
|
155
146
|
}
|
|
@@ -159,7 +150,7 @@ module.exports = class OutputStylesPreprocessor {
|
|
|
159
150
|
function makeIndex(a, b) {
|
|
160
151
|
let index = Object.create(null);
|
|
161
152
|
|
|
162
|
-
(
|
|
153
|
+
(a || []).concat(b || []).forEach(function (a) {
|
|
163
154
|
index[a] = true;
|
|
164
155
|
});
|
|
165
156
|
|
package/lib/plugin/registry.js
CHANGED
|
@@ -38,13 +38,25 @@ module.exports = class PluginRegistry {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
_instantiatePlugins() {
|
|
41
|
-
let plugins = this._discoverPlugins(
|
|
41
|
+
let plugins = this._discoverPlugins(
|
|
42
|
+
this.parent.addons,
|
|
43
|
+
'ember-css-modules-plugin'
|
|
44
|
+
);
|
|
42
45
|
|
|
43
46
|
// For addons under development, crawl the host app's available plugins for linting tools so they can be devDependencies
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (
|
|
48
|
+
typeof this.parent.isDevelopingAddon === 'function' &&
|
|
49
|
+
this.parent.isDevelopingAddon()
|
|
50
|
+
) {
|
|
51
|
+
let parentAddonNames = new Set(
|
|
52
|
+
this.parent.addons.map((addon) => addon.name)
|
|
53
|
+
);
|
|
54
|
+
let hostAddons = this.parent.project.addons.filter(
|
|
55
|
+
(addon) => !parentAddonNames.has(addon.name)
|
|
56
|
+
);
|
|
57
|
+
plugins = plugins.concat(
|
|
58
|
+
this._discoverPlugins(hostAddons, 'ember-css-modules-lint-plugin')
|
|
59
|
+
);
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
return plugins;
|
|
@@ -52,14 +64,16 @@ module.exports = class PluginRegistry {
|
|
|
52
64
|
|
|
53
65
|
_discoverPlugins(addons, keyword) {
|
|
54
66
|
return addons
|
|
55
|
-
.filter(addon => this._isPlugin(addon, keyword))
|
|
56
|
-
.map(addon => this._instantiatePluginFor(addon));
|
|
67
|
+
.filter((addon) => this._isPlugin(addon, keyword))
|
|
68
|
+
.map((addon) => this._instantiatePluginFor(addon));
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
_isPlugin(addon, keyword) {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
return (
|
|
73
|
+
addon.pkg &&
|
|
74
|
+
addon.pkg.keywords &&
|
|
75
|
+
addon.pkg.keywords.indexOf(keyword) >= 0
|
|
76
|
+
);
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
_instantiatePluginFor(addon) {
|
|
@@ -83,4 +97,4 @@ module.exports = class PluginRegistry {
|
|
|
83
97
|
}
|
|
84
98
|
return options;
|
|
85
99
|
}
|
|
86
|
-
}
|
|
100
|
+
};
|
package/lib/resolve-path.js
CHANGED
|
@@ -4,24 +4,39 @@ const path = require('path');
|
|
|
4
4
|
const ensurePosixPath = require('ensure-posix-path');
|
|
5
5
|
|
|
6
6
|
module.exports = function resolvePath(importPath, fromFile, options) {
|
|
7
|
-
let pathWithExtension = path.extname(importPath)
|
|
7
|
+
let pathWithExtension = path.extname(importPath)
|
|
8
|
+
? importPath
|
|
9
|
+
: importPath + '.' + options.defaultExtension;
|
|
8
10
|
|
|
9
11
|
if (isRelativePath(pathWithExtension)) {
|
|
10
12
|
return resolveRelativePath(pathWithExtension, fromFile, options);
|
|
11
13
|
} else if (isLocalPath(pathWithExtension, options)) {
|
|
12
14
|
return resolveLocalPath(pathWithExtension, fromFile, options);
|
|
13
15
|
} else if (isLocalPathWithOldPackageNameRef(pathWithExtension, options)) {
|
|
14
|
-
const amendedPathWithExtension = pathWithExtension.replace(
|
|
16
|
+
const amendedPathWithExtension = pathWithExtension.replace(
|
|
17
|
+
options.parentName,
|
|
18
|
+
options.ownerName
|
|
19
|
+
);
|
|
15
20
|
options.ui.writeWarnLine(
|
|
16
21
|
'For addons that define a moduleName, you should reference any CSS Modules provided by that addon ' +
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
'using its moduleName instead of the package name.\n' +
|
|
23
|
+
'Current path: ' +
|
|
24
|
+
importPath +
|
|
25
|
+
'\n' +
|
|
26
|
+
'Replace with: ' +
|
|
27
|
+
importPath.replace(options.parentName, options.ownerName) +
|
|
28
|
+
'\n' +
|
|
29
|
+
'File: ' +
|
|
30
|
+
fromFile
|
|
21
31
|
);
|
|
22
32
|
return resolveLocalPath(amendedPathWithExtension, fromFile, options);
|
|
23
33
|
} else {
|
|
24
|
-
return resolveExternalPath(
|
|
34
|
+
return resolveExternalPath(
|
|
35
|
+
pathWithExtension,
|
|
36
|
+
importPath,
|
|
37
|
+
fromFile,
|
|
38
|
+
options
|
|
39
|
+
);
|
|
25
40
|
}
|
|
26
41
|
};
|
|
27
42
|
|
|
@@ -34,17 +49,24 @@ function isLocalPath(importPath, options) {
|
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
function isLocalPathWithOldPackageNameRef(importPath, options) {
|
|
37
|
-
return (
|
|
52
|
+
return (
|
|
53
|
+
options.ownerName !== options.parentName &&
|
|
54
|
+
importPath.indexOf(options.parentName + '/') === 0
|
|
55
|
+
);
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
function resolveRelativePath(importPath, fromFile, options) {
|
|
41
|
-
let absolutePath = ensurePosixPath(
|
|
59
|
+
let absolutePath = ensurePosixPath(
|
|
60
|
+
path.resolve(path.dirname(fromFile), importPath)
|
|
61
|
+
);
|
|
42
62
|
return internalDep(absolutePath, options);
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
// Resolve absolute paths pointing to the same app/addon as the importer
|
|
46
66
|
function resolveLocalPath(importPath, fromFile, options) {
|
|
47
|
-
const fromFileStartsWithOwnerName = fromFile
|
|
67
|
+
const fromFileStartsWithOwnerName = fromFile
|
|
68
|
+
.substring(options.root.length + 1)
|
|
69
|
+
.startsWith(options.ownerName);
|
|
48
70
|
|
|
49
71
|
// Depending on the exact version of Ember CLI and/or Embroider in play, the
|
|
50
72
|
// app/addon name may or may not be included in `fromFile`'s path. If not, we
|
|
@@ -71,15 +93,17 @@ function resolveExternalPath(importPath, originalPath, fromFile, options) {
|
|
|
71
93
|
if (!addon) {
|
|
72
94
|
throw new Error(
|
|
73
95
|
`Unable to resolve styles module '${originalPath}' imported from '${fromFile}'. ` +
|
|
74
|
-
|
|
96
|
+
`No virtual module with that name was defined and no corresponding addon was found.`
|
|
75
97
|
);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
100
|
let pathWithinAddon = importPath.substring(addonName.length + 1);
|
|
79
101
|
let addonTreePath = path.join(addon.root, addon.treePaths.addon);
|
|
80
102
|
|
|
81
|
-
let absolutePath = ensurePosixPath(
|
|
82
|
-
|
|
103
|
+
let absolutePath = ensurePosixPath(
|
|
104
|
+
path.resolve(addonTreePath, pathWithinAddon)
|
|
105
|
+
);
|
|
106
|
+
let keyPath = addonName + '/' + pathWithinAddon;
|
|
83
107
|
return new DependencyPath('external', absolutePath, keyPath);
|
|
84
108
|
}
|
|
85
109
|
|