@mui/codemod 7.3.8 → 9.0.0-alpha.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/CHANGELOG.md +74 -0
- package/README.md +150 -144
- package/codemod.js +68 -124
- package/package.json +6 -5
- package/v5.0.0/path-imports.js +0 -5
- package/v5.0.0/top-level-imports.js +1 -5
package/codemod.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
2
3
|
|
|
3
4
|
const childProcess = require('child_process');
|
|
4
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
promises: fs
|
|
7
|
+
} = require('fs');
|
|
5
8
|
const path = require('path');
|
|
6
9
|
const yargs = require('yargs');
|
|
7
10
|
const jscodeshiftPackage = require('jscodeshift/package.json');
|
|
8
11
|
const postcssCliPackage = require('postcss-cli/package.json');
|
|
9
|
-
|
|
10
12
|
const jscodeshiftDirectory = path.dirname(require.resolve('jscodeshift'));
|
|
11
13
|
const jscodeshiftExecutable = path.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
12
|
-
|
|
13
14
|
const postcssCliDirectory = path.dirname(require.resolve('postcss-cli'));
|
|
14
15
|
const postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.postcss);
|
|
15
|
-
|
|
16
16
|
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
17
|
-
const paths = [
|
|
18
|
-
path.resolve(__dirname, './src', `${transform}/index.js`),
|
|
19
|
-
path.resolve(__dirname, './src', `${transform}.js`),
|
|
20
|
-
path.resolve(__dirname, './', `${transform}/index.js`),
|
|
21
|
-
path.resolve(__dirname, './', `${transform}.js`),
|
|
22
|
-
];
|
|
23
|
-
|
|
17
|
+
const paths = [path.resolve(__dirname, './src', `${transform}/index.js`), path.resolve(__dirname, './src', `${transform}.js`), path.resolve(__dirname, './', `${transform}/index.js`), path.resolve(__dirname, './', `${transform}.js`)];
|
|
24
18
|
let transformerPath;
|
|
25
19
|
let error;
|
|
26
20
|
for (const item of paths) {
|
|
@@ -35,35 +29,15 @@ async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
|
35
29
|
continue;
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
if (error) {
|
|
40
33
|
if (error?.code === 'ENOENT') {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Transform '${transform}' not found. Check out ${path.resolve(
|
|
43
|
-
__dirname,
|
|
44
|
-
'./README.md for a list of available codemods.',
|
|
45
|
-
)}`,
|
|
46
|
-
);
|
|
34
|
+
throw new Error(`Transform '${transform}' not found. Check out ${path.resolve(__dirname, './README.md for a list of available codemods.')}`);
|
|
47
35
|
}
|
|
48
36
|
throw error;
|
|
49
37
|
}
|
|
50
|
-
|
|
51
38
|
const args = [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
'--transform',
|
|
55
|
-
transformerPath,
|
|
56
|
-
...codemodFlags,
|
|
57
|
-
'--extensions',
|
|
58
|
-
'js,ts,jsx,tsx,json',
|
|
59
|
-
'--parser',
|
|
60
|
-
flags.parser || 'tsx',
|
|
61
|
-
'--ignore-pattern',
|
|
62
|
-
'**/node_modules/**',
|
|
63
|
-
'--ignore-pattern',
|
|
64
|
-
'**/*.css',
|
|
65
|
-
];
|
|
66
|
-
|
|
39
|
+
// can't directly spawn `jscodeshiftExecutable` due to https://github.com/facebook/jscodeshift/issues/424
|
|
40
|
+
jscodeshiftExecutable, '--transform', transformerPath, ...codemodFlags, '--extensions', 'js,ts,jsx,tsx,json', '--parser', flags.parser || 'tsx', '--ignore-pattern', '**/node_modules/**', '--ignore-pattern', '**/*.css'];
|
|
67
41
|
if (flags.dry) {
|
|
68
42
|
args.push('--dry');
|
|
69
43
|
}
|
|
@@ -76,43 +50,33 @@ async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
|
76
50
|
if (flags.packageName) {
|
|
77
51
|
args.push(`--packageName=${flags.packageName}`);
|
|
78
52
|
}
|
|
79
|
-
|
|
80
53
|
args.push(...files);
|
|
81
54
|
|
|
82
55
|
// eslint-disable-next-line no-console -- debug information
|
|
83
56
|
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
84
|
-
const jscodeshiftProcess = childProcess.spawnSync('node', args, {
|
|
85
|
-
|
|
57
|
+
const jscodeshiftProcess = childProcess.spawnSync('node', args, {
|
|
58
|
+
stdio: 'inherit'
|
|
59
|
+
});
|
|
86
60
|
if (jscodeshiftProcess.error) {
|
|
87
61
|
throw jscodeshiftProcess.error;
|
|
88
62
|
}
|
|
89
63
|
}
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
}),
|
|
104
|
-
);
|
|
105
|
-
|
|
64
|
+
const parseCssFilePaths = async files => {
|
|
65
|
+
const cssFiles = await Promise.all(files.map(async filePath => {
|
|
66
|
+
const stat = await fs.stat(filePath);
|
|
67
|
+
if (stat.isDirectory()) {
|
|
68
|
+
return `${filePath}/**/*.css`;
|
|
69
|
+
}
|
|
70
|
+
if (filePath.endsWith('.css')) {
|
|
71
|
+
return filePath;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}));
|
|
106
75
|
return cssFiles.filter(Boolean);
|
|
107
76
|
};
|
|
108
|
-
|
|
109
77
|
async function runPostcssTransform(transform, files) {
|
|
110
78
|
// local postcss plugins are loaded through config files https://github.com/postcss/postcss-load-config/issues/17#issuecomment-253125559
|
|
111
|
-
const paths = [
|
|
112
|
-
path.resolve(__dirname, './src', `${transform}/postcss.config.js`),
|
|
113
|
-
path.resolve(__dirname, './', `${transform}/postcss.config.js`),
|
|
114
|
-
];
|
|
115
|
-
|
|
79
|
+
const paths = [path.resolve(__dirname, './src', `${transform}/postcss.config.js`), path.resolve(__dirname, './', `${transform}/postcss.config.js`)];
|
|
116
80
|
let configPath;
|
|
117
81
|
let error;
|
|
118
82
|
for (const item of paths) {
|
|
@@ -127,7 +91,6 @@ async function runPostcssTransform(transform, files) {
|
|
|
127
91
|
continue;
|
|
128
92
|
}
|
|
129
93
|
}
|
|
130
|
-
|
|
131
94
|
if (error) {
|
|
132
95
|
// don't throw if the file is not found, postcss transform is optional
|
|
133
96
|
if (error?.code !== 'ENOENT') {
|
|
@@ -135,81 +98,62 @@ async function runPostcssTransform(transform, files) {
|
|
|
135
98
|
}
|
|
136
99
|
} else {
|
|
137
100
|
const cssPaths = await parseCssFilePaths(files);
|
|
138
|
-
|
|
139
101
|
if (cssPaths.length > 0) {
|
|
140
|
-
const args = [
|
|
141
|
-
postcssExecutable,
|
|
142
|
-
...cssPaths,
|
|
143
|
-
'--config',
|
|
144
|
-
configPath,
|
|
145
|
-
'--replace',
|
|
146
|
-
'--verbose',
|
|
147
|
-
];
|
|
102
|
+
const args = [postcssExecutable, ...cssPaths, '--config', configPath, '--replace', '--verbose'];
|
|
148
103
|
|
|
149
104
|
// eslint-disable-next-line no-console -- debug information
|
|
150
105
|
console.log(`Executing command: postcss ${args.join(' ')}`);
|
|
151
|
-
const postcssProcess = childProcess.spawnSync('node', args, {
|
|
152
|
-
|
|
106
|
+
const postcssProcess = childProcess.spawnSync('node', args, {
|
|
107
|
+
stdio: 'inherit'
|
|
108
|
+
});
|
|
153
109
|
if (postcssProcess.error) {
|
|
154
110
|
throw postcssProcess.error;
|
|
155
111
|
}
|
|
156
112
|
}
|
|
157
113
|
}
|
|
158
114
|
}
|
|
159
|
-
|
|
160
115
|
function run(argv) {
|
|
161
|
-
const {
|
|
162
|
-
|
|
163
|
-
|
|
116
|
+
const {
|
|
117
|
+
codemod,
|
|
118
|
+
paths,
|
|
119
|
+
...flags
|
|
120
|
+
} = argv;
|
|
121
|
+
const files = paths.map(filePath => path.resolve(filePath));
|
|
164
122
|
runJscodeshiftTransform(codemod, files, flags, argv._);
|
|
165
123
|
runPostcssTransform(codemod, files);
|
|
166
124
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})
|
|
203
|
-
.option('packageName', {
|
|
204
|
-
description: 'The package name to look for in the import statements',
|
|
205
|
-
default: '@mui/material',
|
|
206
|
-
type: 'string',
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
handler: run,
|
|
210
|
-
})
|
|
211
|
-
.scriptName('npx @mui/codemod')
|
|
212
|
-
.example('$0 v4.0.0/theme-spacing-api src')
|
|
213
|
-
.example('$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp')
|
|
214
|
-
.help()
|
|
215
|
-
.parse();
|
|
125
|
+
yargs.command({
|
|
126
|
+
command: '$0 <codemod> <paths...>',
|
|
127
|
+
describe: 'Applies a `@mui/codemod` to the specified paths',
|
|
128
|
+
builder: command => {
|
|
129
|
+
return command.positional('codemod', {
|
|
130
|
+
description: 'The name of the codemod',
|
|
131
|
+
type: 'string'
|
|
132
|
+
}).positional('paths', {
|
|
133
|
+
array: true,
|
|
134
|
+
description: 'Paths forwarded to `jscodeshift`',
|
|
135
|
+
type: 'string'
|
|
136
|
+
}).option('dry', {
|
|
137
|
+
description: 'dry run (no changes are made to files)',
|
|
138
|
+
default: false,
|
|
139
|
+
type: 'boolean'
|
|
140
|
+
}).option('parser', {
|
|
141
|
+
description: 'which parser for jscodeshift to use',
|
|
142
|
+
default: 'tsx',
|
|
143
|
+
type: 'string'
|
|
144
|
+
}).option('print', {
|
|
145
|
+
description: 'print transformed files to stdout, useful for development',
|
|
146
|
+
default: false,
|
|
147
|
+
type: 'boolean'
|
|
148
|
+
}).option('jscodeshift', {
|
|
149
|
+
description: '(Advanced) Pass options directly to jscodeshift',
|
|
150
|
+
default: false,
|
|
151
|
+
type: 'string'
|
|
152
|
+
}).option('packageName', {
|
|
153
|
+
description: 'The package name to look for in the import statements',
|
|
154
|
+
default: '@mui/material',
|
|
155
|
+
type: 'string'
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
handler: run
|
|
159
|
+
}).scriptName('npx @mui/codemod').example('$0 v4.0.0/theme-spacing-api src').example('$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp').help().parse();
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/codemod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-alpha.1",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Codemod scripts for Material UI.",
|
|
6
|
-
"bin": "./codemod.js",
|
|
7
6
|
"keywords": [
|
|
8
7
|
"react",
|
|
9
8
|
"react-component",
|
|
@@ -23,9 +22,10 @@
|
|
|
23
22
|
"url": "https://opencollective.com/mui-org"
|
|
24
23
|
},
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@babel/core": "^7.
|
|
25
|
+
"@babel/core": "^7.29.0",
|
|
27
26
|
"@babel/runtime": "^7.28.6",
|
|
28
|
-
"@babel/traverse": "^7.
|
|
27
|
+
"@babel/traverse": "^7.29.0",
|
|
28
|
+
"@mui/material-v5": "npm:@mui/material@5.18.0",
|
|
29
29
|
"jscodeshift": "^17.1.2",
|
|
30
30
|
"jscodeshift-add-imports": "^1.0.11",
|
|
31
31
|
"postcss": "^8.5.6",
|
|
@@ -42,5 +42,6 @@
|
|
|
42
42
|
"type": "commonjs",
|
|
43
43
|
"exports": {
|
|
44
44
|
"./package.json": "./package.json"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"bin": "./codemod.js"
|
|
46
47
|
}
|
package/v5.0.0/path-imports.js
CHANGED
|
@@ -6,11 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
8
|
var _jscodeshiftAddImports = _interopRequireDefault(require("jscodeshift-add-imports"));
|
|
9
|
-
// istanbul ignore next
|
|
10
|
-
if (globalThis.MUI_TEST_ENV) {
|
|
11
|
-
const resolve = require.resolve;
|
|
12
|
-
require.resolve = source => resolve(source.replace(/^@mui\/material\/modern/, '../../../mui-material/src'));
|
|
13
|
-
}
|
|
14
9
|
const barrelImportsToTransform = {
|
|
15
10
|
material: {},
|
|
16
11
|
'icons-material': {}
|
|
@@ -12,11 +12,7 @@ function transformer(fileInfo, api, options) {
|
|
|
12
12
|
const j = api.jscodeshift;
|
|
13
13
|
const importModule = options.importModule || '@mui/material';
|
|
14
14
|
const targetModule = options.targetModule || '@mui/material';
|
|
15
|
-
|
|
16
|
-
if (globalThis.MUI_TEST_ENV) {
|
|
17
|
-
resolveModule = resolveModule.replace(/^@mui\/material/, '@mui/material-v5');
|
|
18
|
-
}
|
|
19
|
-
const whitelist = (0, _getJSExports.default)(require.resolve(`${resolveModule}/modern`, {
|
|
15
|
+
const whitelist = (0, _getJSExports.default)(require.resolve(`@mui/material-v5/modern`, {
|
|
20
16
|
paths: [(0, _path.dirname)(fileInfo.path)]
|
|
21
17
|
}));
|
|
22
18
|
const printOptions = options.printOptions || {
|