Skip to content

Commit 8539c54

Browse files
authored
Merge pull request salsify#258 from salsify/compat-cleanup
2 parents 404646f + 82072f6 commit 8539c54

File tree

8 files changed

+23
-123
lines changed

8 files changed

+23
-123
lines changed

packages/ember-css-modules/index.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const path = require('path');
44
const fs = require('fs');
55
const debug = require('debug')('ember-css-modules:addon');
6-
const VersionChecker = require('ember-cli-version-checker');
76

87
const HtmlbarsPlugin = require('./lib/htmlbars-plugin');
98
const ModulesPreprocessor = require('./lib/modules-preprocessor');
@@ -19,7 +18,6 @@ module.exports = {
1918
this.outputStylesPreprocessor = new OutputStylesPreprocessor({
2019
owner: this,
2120
});
22-
this.checker = new VersionChecker(this.project);
2321
this.plugins = new PluginRegistry(this.parent);
2422
},
2523

@@ -66,11 +64,8 @@ module.exports = {
6664
this.parentPreprocessorRegistry.add(
6765
'htmlbars-ast-plugin',
6866
HtmlbarsPlugin.instantiate({
69-
emberVersion: this.checker.for('ember-source').version,
70-
options: {
71-
fileExtension: this.getFileExtension(),
72-
includeExtensionInModulePath: this.includeExtensionInModulePath(),
73-
},
67+
fileExtension: this.getFileExtension(),
68+
includeExtensionInModulePath: this.includeExtensionInModulePath(),
7469
})
7570
);
7671
},
@@ -169,15 +164,6 @@ module.exports = {
169164
return this.cssModulesOptions.postcssOptions;
170165
},
171166

172-
getAddonModulesRoot() {
173-
// CLI 2.12 stopped exposing addon stuff nested under `modules/`
174-
if (this.checker.for('ember-cli', 'npm').satisfies('< 2.12')) {
175-
return 'modules/';
176-
} else {
177-
return '';
178-
}
179-
},
180-
181167
getParentAddonTree() {
182168
return path.join(this.parentAddon.root, this.parentAddon.treePaths.addon);
183169
},

packages/ember-css-modules/lib/htmlbars-plugin/index.js

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
'use strict';
22

33
const utils = require('./utils');
4-
const semver = require('semver');
54

65
module.exports = class ClassTransformPlugin {
76
constructor(env, options) {
87
this.syntax = env.syntax;
98
this.builders = env.syntax.builders;
109
this.options = options;
1110
this.stylesModule = this.determineStylesModule(env);
12-
this.isGlimmer = this.detectGlimmer();
1311
this.visitor = this.buildVisitor(env);
14-
15-
// Alias for 2.15 <= Ember < 3.1
16-
this.visitors = this.visitor;
1712
}
1813

19-
static instantiate({ emberVersion, options }) {
14+
static instantiate(options) {
2015
return {
2116
name: 'ember-css-modules',
22-
plugin: semver.lt(emberVersion, '2.15.0-alpha')
23-
? LegacyAdapter.bind(null, this, options)
24-
: (env) => new this(env, options),
17+
plugin: (env) => new this(env, options),
2518
parallelBabel: {
2619
requireFile: __filename,
2720
buildUsing: 'instantiate',
28-
params: { emberVersion, options },
21+
params: options,
2922
},
3023
baseDir() {
3124
return `${__dirname}/../..`;
@@ -54,17 +47,6 @@ module.exports = class ClassTransformPlugin {
5447
return name;
5548
}
5649

57-
detectGlimmer() {
58-
if (!this.syntax.parse) {
59-
return false;
60-
}
61-
62-
// HTMLBars builds ConcatStatements with StringLiterals + raw PathExpressions
63-
// Glimmer builds ConcatStatements with TextNodes + MustacheStatements
64-
let ast = this.syntax.parse('<div class="foo {{bar}}"></div>');
65-
return ast.body[0].attributes[0].value.parts[0].type === 'TextNode';
66-
}
67-
6850
buildVisitor(env) {
6951
if (env.moduleName === env.filename) {
7052
// No-op for the stage 1 Embroider pass (which only contains relative paths)
@@ -133,7 +115,6 @@ module.exports = class ClassTransformPlugin {
133115

134116
utils.removeAttr(node, localClassAttr);
135117

136-
let stringBuilder = this.isGlimmer ? 'text' : 'string';
137118
let classAttr = utils.getAttr(node, 'class');
138119
let parts = [];
139120
let classAttrValue;
@@ -149,26 +130,18 @@ module.exports = class ClassTransformPlugin {
149130
parts.push(
150131
this.builders.mustache(
151132
this.builders.path('concat'),
152-
utils.concatStatementToParams(
153-
this.builders,
154-
classAttrValue,
155-
this.isGlimmer
156-
)
133+
utils.concatStatementToParams(this.builders, classAttrValue)
157134
)
158135
);
159136
} else if (classAttrValue.type === 'TextNode') {
160-
parts.push(this.builders[stringBuilder](classAttrValue.chars));
137+
parts.push(this.builders.text(classAttrValue.chars));
161138
} else if (classAttrValue.type === 'MustacheStatement') {
162-
if (classAttrValue.params.length || this.isGlimmer) {
163-
parts.push(classAttrValue);
164-
} else {
165-
parts.push(this.builders.path(classAttrValue.path.original));
166-
}
139+
parts.push(classAttrValue);
167140
}
168141
}
169142

170143
utils.pushAll(parts, this.localToPath(localClassAttr.value));
171-
this.divide(parts, this.isGlimmer ? 'text' : 'string');
144+
this.divide(parts, 'text');
172145
node.attributes.unshift(
173146
this.builders.attr('class', this.builders.concat(parts))
174147
);
@@ -225,11 +198,7 @@ module.exports = class ClassTransformPlugin {
225198

226199
concatLocalPath(node) {
227200
let concatPath = this.builders.path('concat');
228-
let concatParts = utils.concatStatementToParams(
229-
this.builders,
230-
node,
231-
this.isGlimmer
232-
);
201+
let concatParts = utils.concatStatementToParams(this.builders, node);
233202
let concatStatement = this.builders.mustache(concatPath, concatParts);
234203
return this.dynamicLocalPath(concatStatement);
235204
}
@@ -268,22 +237,3 @@ module.exports = class ClassTransformPlugin {
268237
return parts;
269238
}
270239
};
271-
272-
// For Ember < 2.15
273-
class LegacyAdapter {
274-
constructor(plugin, options, env) {
275-
this.plugin = plugin;
276-
this.options = options;
277-
this.meta = env.meta;
278-
this.syntax = null;
279-
}
280-
281-
transform(ast) {
282-
let plugin = new this.plugin(
283-
Object.assign({ syntax: this.syntax }, this.meta),
284-
this.options
285-
);
286-
this.syntax.traverse(ast, plugin.visitor);
287-
return ast;
288-
}
289-
}

packages/ember-css-modules/lib/htmlbars-plugin/utils.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ function textToString(builders, node) {
4444
}
4545
}
4646

47-
function concatStatementToParams(builders, node, isGlimmer) {
48-
if (!isGlimmer) {
49-
return node.parts;
50-
}
51-
47+
function concatStatementToParams(builders, node) {
5248
return node.parts.map(function (part) {
5349
if (part.type === 'MustacheStatement') {
5450
if (!part.params.length && !part.hash.pairs.length) {

packages/ember-css-modules/lib/make-postcss-plugin.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ module.exports = class ModulesPreprocessor {
5050
let inputRoot = this.owner.belongsToAddon()
5151
? this.owner.getParentAddonTree()
5252
: this.owner.app.trees.app;
53-
let outputRoot = this.owner.belongsToAddon()
54-
? this.owner.getAddonModulesRoot()
55-
: '';
56-
57-
if (outputRoot) {
58-
inputRoot = new Funnel(inputRoot, {
59-
destDir: outputRoot,
60-
});
61-
}
6253

6354
// If moduleName is defined, that should override the parent's name.
6455
// Otherwise, the template and generated module will disagree as to what the path should be.
@@ -71,17 +62,14 @@ module.exports = class ModulesPreprocessor {
7162

7263
let modulesSources = new ModuleSourceFunnel(inputRoot, modulesInput, {
7364
include: ['**/*.' + this.owner.getFileExtension()],
74-
outputRoot,
7565
parentName: ownerName,
7666
});
7767

7868
let modulesTree = new (require('broccoli-css-modules'))(modulesSources, {
7969
extension: this.owner.getFileExtension(),
8070
plugins: this.getPostcssPlugins(),
8171
enableSourceMaps: this.owner.enableSourceMaps(),
82-
sourceMapBaseDir: this.owner.belongsToAddon()
83-
? this.owner.getAddonModulesRoot()
84-
: '',
72+
sourceMapBaseDir: '',
8573
postcssOptions: this.owner.getPostcssOptions(),
8674
virtualModules: this.owner.getVirtualModules(),
8775
generateScopedName: this.scopedNameGenerator(),
@@ -199,9 +187,15 @@ module.exports = class ModulesPreprocessor {
199187
}
200188

201189
rootPathPlugin() {
202-
return require('./make-postcss-plugin')('root-path-tag', () => (css) => {
203-
css.source.input.rootPath = this._modulesTree.inputPaths[0];
204-
});
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+
);
205199
}
206200

207201
resolvePath(importPath, fromFile) {
@@ -211,7 +205,6 @@ module.exports = class ModulesPreprocessor {
211205
defaultExtension: this.owner.getFileExtension(),
212206
ownerName: this._ownerName,
213207
parentName: this._parentName,
214-
addonModulesRoot: this.owner.getAddonModulesRoot(),
215208
root: ensurePosixPath(this._modulesTree.inputPaths[0]),
216209
parent: this.owner.getParent(),
217210
ui: this.owner.ui,
@@ -230,7 +223,6 @@ class ModuleSourceFunnel extends Funnel {
230223
constructor(input, stylesTree, options) {
231224
super([input, stylesTree], options);
232225
this.parentName = options.parentName;
233-
this.destDir = options.outputRoot;
234226
this.inputHasParentName = null;
235227
}
236228

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function resolveExternalPath(importPath, originalPath, fromFile, options) {
103103
let absolutePath = ensurePosixPath(
104104
path.resolve(addonTreePath, pathWithinAddon)
105105
);
106-
let keyPath = options.addonModulesRoot + addonName + '/' + pathWithinAddon;
106+
let keyPath = addonName + '/' + pathWithinAddon;
107107
return new DependencyPath('external', absolutePath, keyPath);
108108
}
109109

packages/ember-css-modules/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@
8181
"debug": "^4.3.2",
8282
"ember-cli-babel": "^7.26.6",
8383
"ember-cli-htmlbars": "^6.0.0",
84-
"ember-cli-version-checker": "^5.1.2",
8584
"ensure-posix-path": "^1.0.2",
8685
"hash-string": "^1.0.0",
8786
"lodash.merge": "^4.6.1",
8887
"postcss": "^8.0.0",
89-
"semver": "^7.3.5",
9088
"toposort": "^2.0.2"
9189
},
9290
"ember": {

packages/ember-css-modules/tests/helpers/render-with-styles.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* global require, define */
22

33
import Ember from 'ember';
4-
import { VERSION } from '@ember/version';
54
import ClassTransformPlugin from 'ecm-template-transform';
65

76
const { compile } = Ember.__loader.require('ember-template-compiler');
@@ -22,10 +21,7 @@ export default function registerStyles(styles) {
2221
}
2322

2423
const { plugin } = ClassTransformPlugin.instantiate({
25-
emberVersion: VERSION,
26-
options: {
27-
includeExtensionInModulePath: false,
28-
},
24+
includeExtensionInModulePath: false,
2925
});
3026

3127
const plugins = { ast: [plugin] };

0 commit comments

Comments
 (0)