@mui/x-codemod 8.0.0-alpha.11 → 8.0.0-alpha.13
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 +114 -4
- package/package.json +6 -6
- package/v8.0.0/charts/preset-safe/index.js +2 -0
- package/v8.0.0/charts/rename-sparkline-colors-to-color/index.js +40 -0
- package/v8.0.0/{pickers/rename-and-move-field-value-type → charts/rename-unstable-use-series}/index.js +10 -4
- package/v8.0.0/data-grid/preset-safe/index.js +4 -0
- package/v8.0.0/data-grid/remove-props/index.js +24 -0
- package/v8.0.0/data-grid/rename-props/index.js +26 -0
- package/v8.0.0/pickers/preset-safe/index.js +2 -2
- package/v8.0.0/pickers/rename-type-imports/index.js +50 -0
package/README.md
CHANGED
|
@@ -256,6 +256,59 @@ Remove the `<ChartsOnAxisClickHandler />` and move the associated `onAxisClick`
|
|
|
256
256
|
</ChartContainer>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
+
#### `rename-unstable-use-series`
|
|
260
|
+
|
|
261
|
+
Remove `unstable_` prefix from `useSeries` and `use*Series` hooks, as they have now become stable.
|
|
262
|
+
|
|
263
|
+
```diff
|
|
264
|
+
import {
|
|
265
|
+
- unstable_useSeries,
|
|
266
|
+
+ useSeries,
|
|
267
|
+
- unstable_usePieSeries,
|
|
268
|
+
+ usePieSeries,
|
|
269
|
+
- unstable_useLineSeries,
|
|
270
|
+
+ useLineSeries,
|
|
271
|
+
- unstable_useBarSeries,
|
|
272
|
+
+ useBarSeries,
|
|
273
|
+
- unstable_useScatterSeries,
|
|
274
|
+
+ useScatterSeries,
|
|
275
|
+
} from '@mui/x-charts/hooks';
|
|
276
|
+
import {
|
|
277
|
+
- unstable_useHeatmapSeries,
|
|
278
|
+
+ useHeatmapSeries,
|
|
279
|
+
} from '@mui/x-charts-pro/hooks';
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### `rename-sparkline-colors-to-color`
|
|
283
|
+
|
|
284
|
+
Renames the `colors` prop of a `SparkLineChart` to `color` and accesses its first element.
|
|
285
|
+
|
|
286
|
+
```diff
|
|
287
|
+
<SparkLineChart
|
|
288
|
+
- colors={['red']}
|
|
289
|
+
+ color={'red'}
|
|
290
|
+
/>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
If `colors` is a function, it will be wrapped in another function that returns its first element.
|
|
294
|
+
|
|
295
|
+
```diff
|
|
296
|
+
<SparkLineChart
|
|
297
|
+
- colors={fn}
|
|
298
|
+
+ color={typeof fn === 'function' ? mode => fn(mode)[0] : fn[0]}
|
|
299
|
+
/>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
If there are cases that the codemod cannot handle, you should see a comment with a `mui-x-codemod` prefix in the code.
|
|
303
|
+
|
|
304
|
+
```diff
|
|
305
|
+
<SparkLineChart
|
|
306
|
+
- colors={(mode) => (mode === 'light' ? ['black'] : ['white'])}
|
|
307
|
+
+ /* mui-x-codemod: We renamed the `colors` prop to `color`, but didn't change the value. Please ensure sure this prop receives a string or a function that returns a string. */
|
|
308
|
+
+ color={(mode) => (mode === 'light' ? ['black'] : ['white'])}
|
|
309
|
+
/>
|
|
310
|
+
```
|
|
311
|
+
|
|
259
312
|
### Data Grid codemods
|
|
260
313
|
|
|
261
314
|
#### `preset-safe` for Data Grid v8.0.0
|
|
@@ -271,6 +324,8 @@ npx @mui/x-codemod@next v8.0.0/data-grid/preset-safe <path|folder>
|
|
|
271
324
|
The list includes these transformers
|
|
272
325
|
|
|
273
326
|
- [`remove-stabilized-v8-experimentalFeatures`](#remove-stabilized-v8-experimentalFeatures)
|
|
327
|
+
- [`remove-props`](#remove-props)
|
|
328
|
+
- [`rename-props`](#rename-props)
|
|
274
329
|
|
|
275
330
|
#### `remove-stabilized-v8-experimentalFeatures`
|
|
276
331
|
|
|
@@ -290,6 +345,49 @@ Remove feature flags for stabilized `experimentalFeatures`.
|
|
|
290
345
|
npx @mui/x-codemod@next v8.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
|
|
291
346
|
```
|
|
292
347
|
|
|
348
|
+
#### `remove-props`
|
|
349
|
+
|
|
350
|
+
Remove props that are no longer supported.
|
|
351
|
+
|
|
352
|
+
The list includes these props:
|
|
353
|
+
|
|
354
|
+
- `indeterminateCheckboxAction`
|
|
355
|
+
- `rowPositionsDebounceMs`
|
|
356
|
+
|
|
357
|
+
```diff
|
|
358
|
+
<DataGrid
|
|
359
|
+
- indeterminateCheckboxAction="deselect"
|
|
360
|
+
- rowPositionsDebounceMs={100}
|
|
361
|
+
/>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
<!-- #default-branch-switch -->
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
npx @mui/x-codemod@next v8.0.0/data-grid/remove-props <path>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### `rename-props`
|
|
371
|
+
|
|
372
|
+
Rename props to the new ones.
|
|
373
|
+
|
|
374
|
+
The list includes these props:
|
|
375
|
+
|
|
376
|
+
- `unstable_rowSpanning` to `rowSpanning`
|
|
377
|
+
|
|
378
|
+
```diff
|
|
379
|
+
<DataGrid
|
|
380
|
+
- unstable_rowSpanning
|
|
381
|
+
+ rowSpanning
|
|
382
|
+
/>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
<!-- #default-branch-switch -->
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
npx @mui/x-codemod@next v8.0.0/data-grid/rename-props <path>
|
|
389
|
+
```
|
|
390
|
+
|
|
293
391
|
### Pickers codemods
|
|
294
392
|
|
|
295
393
|
#### `preset-safe` for Pickers v8.0.0
|
|
@@ -305,7 +403,7 @@ npx @mui/x-codemod@next v8.0.0/pickers/preset-safe <path|folder>
|
|
|
305
403
|
The list includes these transformers
|
|
306
404
|
|
|
307
405
|
- [`rename-adapter-date-fns-imports`](#rename-adapter-date-fns-imports)
|
|
308
|
-
- [`rename-
|
|
406
|
+
- [`rename-type-imports`](#rename-type-imports)
|
|
309
407
|
|
|
310
408
|
#### `rename-adapter-date-fns-imports`
|
|
311
409
|
|
|
@@ -337,13 +435,25 @@ The list includes these transformers
|
|
|
337
435
|
npx @mui/x-codemod@next v8.0.0/pickers/rename-adapter-date-fns-imports <path>
|
|
338
436
|
```
|
|
339
437
|
|
|
340
|
-
#### `rename-
|
|
438
|
+
#### `rename-type-imports`
|
|
439
|
+
|
|
440
|
+
Renames:
|
|
341
441
|
|
|
342
|
-
|
|
442
|
+
- `usePickersTranslations` to `usePickerTranslations`
|
|
443
|
+
- `usePickersContext` to `usePickerContext`
|
|
444
|
+
- `FieldValueType` to `PickerValueType`
|
|
445
|
+
- `RangeFieldSection` to `FieldRangeSection`
|
|
446
|
+
- `PickerShortcutChangeImportance` to `PickerChangeImportance`
|
|
343
447
|
|
|
344
448
|
```diff
|
|
449
|
+
-import { usePickersTranslations, usePickersContext } from '@mui/x-date-pickers/hooks';
|
|
450
|
+
+import { usePickerTranslations, usePickerContext } from '@mui/x-date-pickers/hooks';
|
|
345
451
|
-import { FieldValueType } from '@mui/x-date-pickers';
|
|
346
452
|
+import { PickerValueType } from '@mui/x-date-pickers';
|
|
453
|
+
-import { RangeFieldSection } from '@mui/x-date-pickers-pro/models';
|
|
454
|
+
+import { FieldRangeSection } from '@mui/x-date-pickers-pro/models';
|
|
455
|
+
-import { PickerShortcutChangeImportance } from '@mui/x-date-pickers/PickersShortcuts';
|
|
456
|
+
+import { PickerChangeImportance } from '@mui/x-date-pickers/models';
|
|
347
457
|
|
|
348
458
|
interface MyComponentProps {
|
|
349
459
|
- valueType: FieldValueType;
|
|
@@ -356,7 +466,7 @@ Renames `FieldValueType` to `PickerValueType`.
|
|
|
356
466
|
<!-- #default-branch-switch -->
|
|
357
467
|
|
|
358
468
|
```bash
|
|
359
|
-
npx @mui/x-codemod@next v8.0.0/pickers/rename-
|
|
469
|
+
npx @mui/x-codemod@next v8.0.0/pickers/rename-type-imports <path>
|
|
360
470
|
```
|
|
361
471
|
|
|
362
472
|
## v7.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.13",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"url": "https://opencollective.com/mui-org"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@babel/core": "^7.26.
|
|
29
|
-
"@babel/runtime": "^7.26.
|
|
30
|
-
"@babel/traverse": "^7.26.
|
|
28
|
+
"@babel/core": "^7.26.9",
|
|
29
|
+
"@babel/runtime": "^7.26.9",
|
|
30
|
+
"@babel/traverse": "^7.26.9",
|
|
31
31
|
"jscodeshift": "17.1.2",
|
|
32
32
|
"yargs": "^17.7.2",
|
|
33
|
-
"@mui/x-internals": "8.0.0-alpha.
|
|
33
|
+
"@mui/x-internals": "8.0.0-alpha.13"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jscodeshift": "^0.12.0",
|
|
37
37
|
"dayjs": "^1.11.13",
|
|
38
|
-
"moment-timezone": "^0.5.
|
|
38
|
+
"moment-timezone": "^0.5.47",
|
|
39
39
|
"rimraf": "^6.0.1"
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": false,
|
|
@@ -13,6 +13,7 @@ var _replaceLegendPositionValues = _interopRequireDefault(require("../replace-le
|
|
|
13
13
|
var _removeExperimentalMarkRendering = _interopRequireDefault(require("../remove-experimental-mark-rendering"));
|
|
14
14
|
var _renameLegendPositionType = _interopRequireDefault(require("../rename-legend-position-type"));
|
|
15
15
|
var _removeOnAxisClickHandler = _interopRequireDefault(require("../remove-on-axis-click-handler"));
|
|
16
|
+
var _renameUnstableUseSeries = _interopRequireDefault(require("../rename-unstable-use-series"));
|
|
16
17
|
function transformer(file, api, options) {
|
|
17
18
|
file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
|
|
18
19
|
file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
|
|
@@ -22,5 +23,6 @@ function transformer(file, api, options) {
|
|
|
22
23
|
file.source = (0, _removeExperimentalMarkRendering.default)(file, api, options);
|
|
23
24
|
file.source = (0, _renameLegendPositionType.default)(file, api, options);
|
|
24
25
|
file.source = (0, _removeOnAxisClickHandler.default)(file, api, options);
|
|
26
|
+
file.source = (0, _renameUnstableUseSeries.default)(file, api, options);
|
|
25
27
|
return file.source;
|
|
26
28
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const printOptions = options.printOptions;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const componentNames = ['SparkLineChart'];
|
|
16
|
+
const props = {
|
|
17
|
+
colors: 'color'
|
|
18
|
+
};
|
|
19
|
+
const colorAttributes = root.find(j.JSXElement).filter(path => {
|
|
20
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
21
|
+
}).find(j.JSXAttribute).filter(attribute => Object.keys(props).includes(attribute.node.name.name));
|
|
22
|
+
return colorAttributes.forEach(attribute => {
|
|
23
|
+
const colorsAttributeExpression = attribute.node.value?.type === 'JSXExpressionContainer' ? attribute.node.value.expression : null;
|
|
24
|
+
let colorAttributeExpression;
|
|
25
|
+
if (colorsAttributeExpression?.type === 'ArrayExpression') {
|
|
26
|
+
colorAttributeExpression = colorsAttributeExpression.elements[0];
|
|
27
|
+
} else if (colorsAttributeExpression?.type === 'Identifier') {
|
|
28
|
+
colorAttributeExpression = j.conditionalExpression(j.binaryExpression('===', j.unaryExpression('typeof', colorsAttributeExpression), j.literal('function')), j.arrowFunctionExpression([j.identifier('mode')], j.chainExpression(j.optionalMemberExpression(j.callExpression(colorsAttributeExpression, [j.identifier('mode')]), j.literal(0)))), colorsAttributeExpression);
|
|
29
|
+
} else {
|
|
30
|
+
// Don't know how to handle this case
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Only transform the value if we know how to handle it, otherwise rename the prop and add a comment
|
|
34
|
+
if (colorAttributeExpression) {
|
|
35
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), j.jsxExpressionContainer(colorAttributeExpression)));
|
|
36
|
+
} else {
|
|
37
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), attribute.node.value)).insertBefore(j.commentBlock(" mui-x-codemod: We renamed the `colors` prop to `color`, but didn't change the value. Please ensure sure this prop receives a string or a function that returns a string. "));
|
|
38
|
+
}
|
|
39
|
+
}).toSource(printOptions);
|
|
40
|
+
}
|
|
@@ -10,16 +10,22 @@ function transformer(file, api, options) {
|
|
|
10
10
|
const root = j(file.source);
|
|
11
11
|
const printOptions = options.printOptions || {
|
|
12
12
|
quote: 'single',
|
|
13
|
-
trailingComma: true
|
|
13
|
+
trailingComma: true,
|
|
14
|
+
wrapColumn: 40
|
|
14
15
|
};
|
|
15
16
|
(0, _renameImports.renameImports)({
|
|
16
17
|
j,
|
|
17
18
|
root,
|
|
18
|
-
packageNames: ['@mui/x-
|
|
19
|
+
packageNames: ['@mui/x-charts', '@mui/x-charts-pro'],
|
|
19
20
|
imports: [{
|
|
20
|
-
oldEndpoint: '
|
|
21
|
+
oldEndpoint: 'hooks',
|
|
21
22
|
importsMapping: {
|
|
22
|
-
|
|
23
|
+
unstable_useSeries: 'useSeries',
|
|
24
|
+
unstable_usePieSeries: 'usePieSeries',
|
|
25
|
+
unstable_useLineSeries: 'useLineSeries',
|
|
26
|
+
unstable_useBarSeries: 'useBarSeries',
|
|
27
|
+
unstable_useScatterSeries: 'useScatterSeries',
|
|
28
|
+
unstable_useHeatmapSeries: 'useHeatmapSeries'
|
|
23
29
|
}
|
|
24
30
|
}]
|
|
25
31
|
});
|
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
8
|
var _removeStabilizedExperimentalFeatures = _interopRequireDefault(require("../remove-stabilized-experimentalFeatures"));
|
|
9
|
+
var _removeProps = _interopRequireDefault(require("../remove-props"));
|
|
10
|
+
var _renameProps = _interopRequireDefault(require("../rename-props"));
|
|
9
11
|
function transformer(file, api, options) {
|
|
10
12
|
file.source = (0, _removeStabilizedExperimentalFeatures.default)(file, api, options);
|
|
13
|
+
file.source = (0, _renameProps.default)(file, api, options);
|
|
14
|
+
file.source = (0, _removeProps.default)(file, api, options);
|
|
11
15
|
return file.source;
|
|
12
16
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
9
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const props = ['indeterminateCheckboxAction', 'rowPositionsDebounceMs'];
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const root = j(file.source);
|
|
14
|
+
const printOptions = options.printOptions || {
|
|
15
|
+
quote: 'single',
|
|
16
|
+
trailingComma: true
|
|
17
|
+
};
|
|
18
|
+
return (0, _removeProps.default)({
|
|
19
|
+
root,
|
|
20
|
+
j,
|
|
21
|
+
props,
|
|
22
|
+
componentNames
|
|
23
|
+
}).toSource(printOptions);
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const props = {
|
|
11
|
+
unstable_rowSpanning: 'rowSpanning'
|
|
12
|
+
};
|
|
13
|
+
function transformer(file, api, options) {
|
|
14
|
+
const j = api.jscodeshift;
|
|
15
|
+
const root = j(file.source);
|
|
16
|
+
const printOptions = options.printOptions || {
|
|
17
|
+
quote: 'single',
|
|
18
|
+
trailingComma: true
|
|
19
|
+
};
|
|
20
|
+
return (0, _renameProps.default)({
|
|
21
|
+
root,
|
|
22
|
+
j,
|
|
23
|
+
props,
|
|
24
|
+
componentNames
|
|
25
|
+
}).toSource(printOptions);
|
|
26
|
+
}
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
8
|
var _renameAdapterDateFnsImports = _interopRequireDefault(require("../rename-adapter-date-fns-imports"));
|
|
9
|
-
var
|
|
9
|
+
var _renameTypeImports = _interopRequireDefault(require("../rename-type-imports"));
|
|
10
10
|
function transformer(file, api, options) {
|
|
11
11
|
file.source = (0, _renameAdapterDateFnsImports.default)(file, api, options);
|
|
12
|
-
file.source = (0,
|
|
12
|
+
file.source = (0, _renameTypeImports.default)(file, api, options);
|
|
13
13
|
return file.source;
|
|
14
14
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
var _renameImports = require("../../../util/renameImports");
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
const j = api.jscodeshift;
|
|
10
|
+
let root = j(file.source);
|
|
11
|
+
const printOptions = options.printOptions || {
|
|
12
|
+
quote: 'single',
|
|
13
|
+
trailingComma: true
|
|
14
|
+
};
|
|
15
|
+
root = (0, _renameImports.renameImports)({
|
|
16
|
+
j,
|
|
17
|
+
root,
|
|
18
|
+
packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
|
|
19
|
+
imports: [{
|
|
20
|
+
oldEndpoint: 'hooks',
|
|
21
|
+
importsMapping: {
|
|
22
|
+
usePickersTranslations: 'usePickerTranslations',
|
|
23
|
+
usePickersContext: 'usePickerContext'
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
oldEndpoint: 'models',
|
|
27
|
+
importsMapping: {
|
|
28
|
+
FieldValueType: 'PickerValueType'
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
oldEndpoint: 'PickersShortcuts',
|
|
32
|
+
newEndpoint: 'models',
|
|
33
|
+
importsMapping: {
|
|
34
|
+
PickerShortcutChangeImportance: 'PickerChangeImportance'
|
|
35
|
+
}
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
root = (0, _renameImports.renameImports)({
|
|
39
|
+
j,
|
|
40
|
+
root,
|
|
41
|
+
packageNames: ['@mui/x-date-pickers-pro'],
|
|
42
|
+
imports: [{
|
|
43
|
+
oldEndpoint: 'models',
|
|
44
|
+
importsMapping: {
|
|
45
|
+
RangeFieldSection: 'FieldRangeSection'
|
|
46
|
+
}
|
|
47
|
+
}]
|
|
48
|
+
});
|
|
49
|
+
return root.toSource(printOptions);
|
|
50
|
+
}
|