ember-codemod-remove-ember-css-modules 0.1.0 → 0.1.1
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/README.md +6 -1
- package/package.json +7 -7
- package/src/migration/ember-app/steps/analyze-app.js +7 -7
- package/src/migration/ember-app/steps/create-options.js +2 -2
- package/src/migration/ember-app/steps/shared/import-styles.js +12 -12
- package/src/migration/ember-app/steps/shared/update-templates.js +12 -12
- package/src/migration/ember-app/steps/update-app-app-js.js +3 -3
- package/src/utils/abstract-syntax-tree/javascript.js +10 -16
- package/src/utils/blueprints/decide-version.js +4 -4
- package/src/utils/files/map-file-paths.js +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Step 3. Celebrate.
|
|
|
41
41
|
<details>
|
|
42
42
|
<summary>Optional: Specify the component structure</summary>
|
|
43
43
|
|
|
44
|
-
By default, an Octane
|
|
44
|
+
By default, an Octane project has the flat component structure. Pass `--component-structure` to indicate otherwise.
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
47
|
npx ember-codemod-remove-ember-css-modules --component-structure="nested"
|
|
@@ -217,6 +217,11 @@ The codemod is not responsible for fixing complex expressions. Refactor template
|
|
|
217
217
|
* Node.js v16 or above
|
|
218
218
|
|
|
219
219
|
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
See the [Contributing](../../CONTRIBUTING.md) guide for details.
|
|
223
|
+
|
|
224
|
+
|
|
220
225
|
## License
|
|
221
226
|
|
|
222
227
|
This project is licensed under the [MIT License](LICENSE.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-remove-ember-css-modules",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Codemod to replace ember-css-modules with embroider-css-modules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -27,25 +27,25 @@
|
|
|
27
27
|
"test": "tests"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/parser": "^7.21.
|
|
30
|
+
"@babel/parser": "^7.21.5",
|
|
31
31
|
"ember-template-recast": "^6.1.4",
|
|
32
|
-
"glob": "^10.
|
|
32
|
+
"glob": "^10.2.2",
|
|
33
33
|
"lodash.template": "^4.5.0",
|
|
34
34
|
"recast": "^0.23.1",
|
|
35
|
-
"yargs": "^17.7.
|
|
35
|
+
"yargs": "^17.7.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "^7.21.
|
|
38
|
+
"@babel/core": "^7.21.5",
|
|
39
39
|
"@babel/eslint-parser": "^7.21.3",
|
|
40
40
|
"@sondr3/minitest": "^0.1.1",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.39.0",
|
|
42
42
|
"eslint-config-prettier": "^8.8.0",
|
|
43
43
|
"eslint-plugin-import": "^2.27.5",
|
|
44
44
|
"eslint-plugin-n": "^15.7.0",
|
|
45
45
|
"eslint-plugin-prettier": "^4.2.1",
|
|
46
46
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
47
47
|
"fixturify": "^3.0.0",
|
|
48
|
-
"prettier": "^2.8.
|
|
48
|
+
"prettier": "^2.8.8"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": "16.* || >= 18"
|
|
@@ -57,7 +57,7 @@ function analyzeComponents(options) {
|
|
|
57
57
|
{
|
|
58
58
|
from: 'app/components',
|
|
59
59
|
to: '',
|
|
60
|
-
}
|
|
60
|
+
},
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
const stylesheetFilePaths = findAndRenameFiles(
|
|
@@ -68,7 +68,7 @@ function analyzeComponents(options) {
|
|
|
68
68
|
{
|
|
69
69
|
from: 'app/components',
|
|
70
70
|
to: '',
|
|
71
|
-
}
|
|
71
|
+
},
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
const templateFilePaths = findAndRenameFiles(
|
|
@@ -79,7 +79,7 @@ function analyzeComponents(options) {
|
|
|
79
79
|
{
|
|
80
80
|
from: 'app/components',
|
|
81
81
|
to: '',
|
|
82
|
-
}
|
|
82
|
+
},
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
const entities = analyzeEntities({
|
|
@@ -94,7 +94,7 @@ function analyzeComponents(options) {
|
|
|
94
94
|
const newEntityName = entityName.replace(/\/index$/, '');
|
|
95
95
|
|
|
96
96
|
return [newEntityName, extensions];
|
|
97
|
-
})
|
|
97
|
+
}),
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -113,7 +113,7 @@ function analyzeRoutes(options) {
|
|
|
113
113
|
{
|
|
114
114
|
from: 'app/controllers',
|
|
115
115
|
to: '',
|
|
116
|
-
}
|
|
116
|
+
},
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
const stylesheetFilePaths = findAndRenameFiles(
|
|
@@ -125,7 +125,7 @@ function analyzeRoutes(options) {
|
|
|
125
125
|
{
|
|
126
126
|
from: 'app/styles',
|
|
127
127
|
to: '',
|
|
128
|
-
}
|
|
128
|
+
},
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
const templateFilePaths = findAndRenameFiles(
|
|
@@ -137,7 +137,7 @@ function analyzeRoutes(options) {
|
|
|
137
137
|
{
|
|
138
138
|
from: 'app/templates',
|
|
139
139
|
to: '',
|
|
140
|
-
}
|
|
140
|
+
},
|
|
141
141
|
);
|
|
142
142
|
|
|
143
143
|
return analyzeEntities({
|
|
@@ -7,7 +7,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
7
7
|
try {
|
|
8
8
|
const packageJsonFile = readFileSync(
|
|
9
9
|
join(projectRoot, 'package.json'),
|
|
10
|
-
'utf8'
|
|
10
|
+
'utf8',
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
const { dependencies, devDependencies } = JSON.parse(packageJsonFile);
|
|
@@ -25,7 +25,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
25
25
|
};
|
|
26
26
|
} catch (e) {
|
|
27
27
|
throw new SyntaxError(
|
|
28
|
-
`ERROR: package.json is missing or is not valid. (${e.message})\n
|
|
28
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`,
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -29,10 +29,10 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
29
29
|
AST.builders.classBody([
|
|
30
30
|
AST.builders.classProperty(
|
|
31
31
|
AST.builders.identifier(data.__styles__),
|
|
32
|
-
AST.builders.identifier(data.__styles__)
|
|
32
|
+
AST.builders.identifier(data.__styles__),
|
|
33
33
|
),
|
|
34
34
|
]),
|
|
35
|
-
superClass
|
|
35
|
+
superClass,
|
|
36
36
|
);
|
|
37
37
|
},
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const defaultImport = path.value.specifiers.find(
|
|
45
|
-
(specifier) => specifier.type === 'ImportDefaultSpecifier'
|
|
45
|
+
(specifier) => specifier.type === 'ImportDefaultSpecifier',
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
if (defaultImport?.local?.name !== 'templateOnlyComponent') {
|
|
@@ -52,10 +52,10 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
52
52
|
return AST.builders.importDeclaration(
|
|
53
53
|
[
|
|
54
54
|
AST.builders.importDefaultSpecifier(
|
|
55
|
-
AST.builders.identifier('Component')
|
|
55
|
+
AST.builders.identifier('Component'),
|
|
56
56
|
),
|
|
57
57
|
],
|
|
58
|
-
AST.builders.literal('@glimmer/component')
|
|
58
|
+
AST.builders.literal('@glimmer/component'),
|
|
59
59
|
);
|
|
60
60
|
},
|
|
61
61
|
});
|
|
@@ -91,11 +91,11 @@ function importStylesInClass(file, data) {
|
|
|
91
91
|
AST.builders.importDeclaration(
|
|
92
92
|
[
|
|
93
93
|
AST.builders.importDefaultSpecifier(
|
|
94
|
-
AST.builders.identifier(data.__styles__)
|
|
94
|
+
AST.builders.identifier(data.__styles__),
|
|
95
95
|
),
|
|
96
96
|
],
|
|
97
|
-
AST.builders.literal(`./${data.fileName}.css`)
|
|
98
|
-
)
|
|
97
|
+
AST.builders.literal(`./${data.fileName}.css`),
|
|
98
|
+
),
|
|
99
99
|
);
|
|
100
100
|
|
|
101
101
|
return AST.print(ast);
|
|
@@ -111,7 +111,7 @@ function addStylesAsClassProperty(file, data) {
|
|
|
111
111
|
const nodesToAdd = [
|
|
112
112
|
AST.builders.classProperty(
|
|
113
113
|
AST.builders.identifier(data.__styles__),
|
|
114
|
-
AST.builders.identifier(data.__styles__)
|
|
114
|
+
AST.builders.identifier(data.__styles__),
|
|
115
115
|
),
|
|
116
116
|
];
|
|
117
117
|
|
|
@@ -135,7 +135,7 @@ function createClass(customizations, options) {
|
|
|
135
135
|
blueprintFilePaths.map((blueprintFilePath) => {
|
|
136
136
|
const blueprintFile = readFileSync(
|
|
137
137
|
join(blueprintRoot, blueprintFilePath),
|
|
138
|
-
'utf8'
|
|
138
|
+
'utf8',
|
|
139
139
|
);
|
|
140
140
|
|
|
141
141
|
const file = processTemplate(blueprintFile, {
|
|
@@ -144,7 +144,7 @@ function createClass(customizations, options) {
|
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
return [filePath, file];
|
|
147
|
-
})
|
|
147
|
+
}),
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
createFiles(fileMapping, options);
|
|
@@ -181,7 +181,7 @@ function updateClass(customizations, options) {
|
|
|
181
181
|
createFiles(fileMapping, options);
|
|
182
182
|
} catch (e) {
|
|
183
183
|
console.warn(
|
|
184
|
-
`WARNING: updateClass could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
184
|
+
`WARNING: updateClass could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -7,7 +7,7 @@ import { createFiles } from '../../../../utils/files.js';
|
|
|
7
7
|
function sanitizeClassAndLocalClassAttributes(file) {
|
|
8
8
|
function removeAttributeWithoutValue(attributeName, attributes) {
|
|
9
9
|
const attributeIndex = attributes.findIndex(
|
|
10
|
-
(attribute) => attribute.name === attributeName
|
|
10
|
+
(attribute) => attribute.name === attributeName,
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
if (attributeIndex === -1) {
|
|
@@ -52,10 +52,10 @@ function mergeClassAndLocalClassAttributes(file, data) {
|
|
|
52
52
|
const { attributes } = node;
|
|
53
53
|
|
|
54
54
|
const localClassAttributeIndex = attributes.findIndex(
|
|
55
|
-
(attribute) => attribute.name === 'local-class'
|
|
55
|
+
(attribute) => attribute.name === 'local-class',
|
|
56
56
|
);
|
|
57
57
|
const classAttributeIndex = attributes.findIndex(
|
|
58
|
-
(attribute) => attribute.name === 'class'
|
|
58
|
+
(attribute) => attribute.name === 'class',
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
if (localClassAttributeIndex === -1 || classAttributeIndex === -1) {
|
|
@@ -97,7 +97,7 @@ function mergeClassAndLocalClassAttributes(file, data) {
|
|
|
97
97
|
|
|
98
98
|
attributes[classAttributeIndex].value = AST.builders.mustache(
|
|
99
99
|
AST.builders.path('concat'),
|
|
100
|
-
params
|
|
100
|
+
params,
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
// Remove the local-class attribute
|
|
@@ -119,7 +119,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
119
119
|
|
|
120
120
|
if (hasFromArgument) {
|
|
121
121
|
throw new RangeError(
|
|
122
|
-
`Unable to handle the {{local-class}} helper's \`from\` key. See lines ${path.loc.start.line}-${path.loc.end.line}
|
|
122
|
+
`Unable to handle the {{local-class}} helper's \`from\` key. See lines ${path.loc.start.line}-${path.loc.end.line}.`,
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -166,7 +166,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
166
166
|
|
|
167
167
|
if (localClassNames.length === 1) {
|
|
168
168
|
node.value = AST.builders.mustache(
|
|
169
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`)
|
|
169
|
+
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
170
170
|
);
|
|
171
171
|
|
|
172
172
|
return;
|
|
@@ -199,7 +199,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
199
199
|
|
|
200
200
|
if (localClassNames.length === 1) {
|
|
201
201
|
return AST.builders.path(
|
|
202
|
-
`this.${data.__styles__}.${localClassNames[0]}
|
|
202
|
+
`this.${data.__styles__}.${localClassNames[0]}`,
|
|
203
203
|
);
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -224,7 +224,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
224
224
|
} else {
|
|
225
225
|
param = AST.builders.sexpr(
|
|
226
226
|
'array',
|
|
227
|
-
localClassNames.map(AST.builders.string)
|
|
227
|
+
localClassNames.map(AST.builders.string),
|
|
228
228
|
);
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -305,7 +305,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
305
305
|
|
|
306
306
|
if (localClassNames.length === 1) {
|
|
307
307
|
return AST.builders.mustache(
|
|
308
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`)
|
|
308
|
+
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
309
309
|
);
|
|
310
310
|
}
|
|
311
311
|
|
|
@@ -337,7 +337,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
337
337
|
const { attributes } = node;
|
|
338
338
|
|
|
339
339
|
const localClassAttributeIndex = attributes.findIndex(
|
|
340
|
-
(attribute) => attribute.name === 'local-class'
|
|
340
|
+
(attribute) => attribute.name === 'local-class',
|
|
341
341
|
);
|
|
342
342
|
|
|
343
343
|
if (localClassAttributeIndex === -1) {
|
|
@@ -351,7 +351,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
351
351
|
case 'ConcatStatement': {
|
|
352
352
|
localClassAttribute.name = 'class';
|
|
353
353
|
localClassAttribute.value.parts = transformParts(
|
|
354
|
-
localClassAttribute.value.parts
|
|
354
|
+
localClassAttribute.value.parts,
|
|
355
355
|
);
|
|
356
356
|
|
|
357
357
|
break;
|
|
@@ -415,7 +415,7 @@ function updateTemplate(customizations, options) {
|
|
|
415
415
|
createFiles(fileMapping, options);
|
|
416
416
|
} catch (e) {
|
|
417
417
|
console.warn(
|
|
418
|
-
`WARNING: updateTemplate could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
418
|
+
`WARNING: updateTemplate could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
421
|
}
|
|
@@ -12,7 +12,7 @@ function addCssEntryPoint(file, data) {
|
|
|
12
12
|
const nodesToAdd = [
|
|
13
13
|
AST.builders.importDeclaration(
|
|
14
14
|
[],
|
|
15
|
-
AST.builders.literal('./assets/app.css')
|
|
15
|
+
AST.builders.literal('./assets/app.css'),
|
|
16
16
|
),
|
|
17
17
|
AST.builders.noop(),
|
|
18
18
|
];
|
|
@@ -35,7 +35,7 @@ export function updateAppAppJs(options) {
|
|
|
35
35
|
|
|
36
36
|
if (filePaths.length !== 1) {
|
|
37
37
|
console.warn(
|
|
38
|
-
'WARNING: updateAppAppJs could not find app.{js,ts} in the app folder. Will skip this step.\n'
|
|
38
|
+
'WARNING: updateAppAppJs could not find app.{js,ts} in the app folder. Will skip this step.\n',
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
return;
|
|
@@ -58,7 +58,7 @@ export function updateAppAppJs(options) {
|
|
|
58
58
|
createFiles(fileMapping, options);
|
|
59
59
|
} catch (e) {
|
|
60
60
|
console.warn(
|
|
61
|
-
`WARNING: updateAppAppJs could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
61
|
+
`WARNING: updateAppAppJs could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -71,29 +71,25 @@ const tsOptions = {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
function getParseOptions(hasTypeScript) {
|
|
74
|
+
const options = hasTypeScript ? tsOptions : jsOptions;
|
|
75
|
+
|
|
74
76
|
return {
|
|
75
77
|
parser: {
|
|
76
78
|
parse(file) {
|
|
77
|
-
return babelParser(file,
|
|
79
|
+
return babelParser(file, options);
|
|
78
80
|
},
|
|
79
81
|
},
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
visit(ast, visitMethods);
|
|
87
|
-
|
|
88
|
-
return ast;
|
|
89
|
-
}
|
|
85
|
+
function traverse(hasTypeScript) {
|
|
86
|
+
return function (file, visitMethods) {
|
|
87
|
+
const ast = parse(file, getParseOptions(hasTypeScript));
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
const ast = parse(file, getParseOptions(true));
|
|
89
|
+
visit(ast, visitMethods);
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return ast;
|
|
91
|
+
return ast;
|
|
92
|
+
};
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
const tools = {
|
|
@@ -101,9 +97,7 @@ const tools = {
|
|
|
101
97
|
print(ast) {
|
|
102
98
|
return print(ast, formattingOptions).code;
|
|
103
99
|
},
|
|
104
|
-
traverse
|
|
105
|
-
return hasTypeScript ? traverseTypeScript : traverseJavaScript;
|
|
106
|
-
},
|
|
100
|
+
traverse,
|
|
107
101
|
};
|
|
108
102
|
|
|
109
103
|
export default tools;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const latestVersions = new Map([
|
|
2
|
-
['embroider-css-modules', '0.1.
|
|
3
|
-
['type-css-modules', '0.1.
|
|
4
|
-
['webpack', '5.
|
|
2
|
+
['embroider-css-modules', '0.1.1'],
|
|
3
|
+
['type-css-modules', '0.1.1'],
|
|
4
|
+
['webpack', '5.81.0'],
|
|
5
5
|
]);
|
|
6
6
|
|
|
7
7
|
export function decideVersion(packageName, options) {
|
|
@@ -17,7 +17,7 @@ export function decideVersion(packageName, options) {
|
|
|
17
17
|
|
|
18
18
|
if (!latestVersion) {
|
|
19
19
|
throw new RangeError(
|
|
20
|
-
`ERROR: The latest version of \`${packageName}\` is unknown.\n
|
|
20
|
+
`ERROR: The latest version of \`${packageName}\` is unknown.\n`,
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|