@mui/x-codemod 9.0.0-alpha.0 → 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 +118 -0
- package/README.md +12 -0
- package/codemod.js +23 -15
- package/package.json +3 -3
- package/util/renameImports.js +1 -1
- package/v6.0.0/data-grid/column-menu-components-rename/index.js +1 -1
- package/v7.0.0/pickers/rename-slots-types/index.js +1 -1
- package/v8.0.0/charts/rename-label-and-tick-font-size/index.js +1 -1
- package/v8.0.0/charts/rename-legend-to-slots-legend/index.js +1 -1
- package/v8.0.0/charts/replace-legend-direction-values/index.js +1 -1
- package/v8.0.0/charts/replace-legend-hidden-slot-prop/index.js +1 -1
- package/v8.0.0/charts/replace-legend-position-values/index.js +1 -1
- package/v8.0.0/data-grid/add-showToolbar-prop/index.js +2 -2
- package/v9.0.0/charts/preset-safe/index.js +2 -1
- package/v9.0.0/charts/replace-show-mark-default/index.js +91 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,123 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 9.0.0-alpha.1
|
|
4
|
+
|
|
5
|
+
_Feb 26, 2026_
|
|
6
|
+
|
|
7
|
+
We'd like to extend a big thank you to the 18 contributors who made this release possible. Here are some highlights ✨:
|
|
8
|
+
|
|
9
|
+
- ⚡️ Improved dynamic data support and cache invalidation in lazy loading for Data Grid Pro
|
|
10
|
+
- ⌨️ Keyboard support for selecting day, month, and year in Date Pickers
|
|
11
|
+
- 📊 Axis tooltip sorting and control improvements in Charts
|
|
12
|
+
- 🐞 Bugfixes and internal improvements
|
|
13
|
+
|
|
14
|
+
Special thanks go out to these community members for their valuable contributions:
|
|
15
|
+
@EllGree, @lion1963
|
|
16
|
+
|
|
17
|
+
The following team members contributed to this release:
|
|
18
|
+
@alexfauquette, @arminmeh, @brijeshb42, @cherniavskii, @dav-is, @flaviendelangle, @Janpot, @JCQuintas, @mapache-salvaje, @MBilalShafi, @michelengelen, @noraleonte, @rita-codes, @sai6855, @siriwatknp, @ZeeshanTamboli
|
|
19
|
+
|
|
20
|
+
### Data Grid
|
|
21
|
+
|
|
22
|
+
#### `@mui/x-data-grid@9.0.0-alpha.1`
|
|
23
|
+
|
|
24
|
+
- [DataGrid] Forward rest props in `GridFilterInputMultipleValue` (#21407) @siriwatknp
|
|
25
|
+
- [DataGrid] Preserve key input during row edit when using `rowModesModel` (#20759) @michelengelen
|
|
26
|
+
- [DataGrid] Remove double rtl inversion logic for columns pinning (#21371) @siriwatknp
|
|
27
|
+
|
|
28
|
+
#### `@mui/x-data-grid-pro@9.0.0-alpha.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
29
|
+
|
|
30
|
+
Same changes as in `@mui/x-data-grid@9.0.0-alpha.1`, plus:
|
|
31
|
+
|
|
32
|
+
- [DataGridPro] Fix number input visibility in header filters (#21328) @michelengelen
|
|
33
|
+
- [DataGridPro] Improve dynamic data support and cache invalidation in lazy loading (#21282) @MBilalShafi
|
|
34
|
+
|
|
35
|
+
#### `@mui/x-data-grid-premium@9.0.0-alpha.1` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
36
|
+
|
|
37
|
+
Same changes as in `@mui/x-data-grid-pro@9.0.0-alpha.1`.
|
|
38
|
+
|
|
39
|
+
### Date and Time Pickers
|
|
40
|
+
|
|
41
|
+
#### `@mui/x-date-pickers@9.0.0-alpha.1`
|
|
42
|
+
|
|
43
|
+
- [DatePicker] Add keyboard support for selecting day, month, and year (#20859) @michelengelen
|
|
44
|
+
|
|
45
|
+
#### `@mui/x-date-pickers-pro@9.0.0-alpha.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
46
|
+
|
|
47
|
+
Same changes as in `@mui/x-date-pickers@9.0.0-alpha.1`, plus:
|
|
48
|
+
|
|
49
|
+
- [DateRangePicker] Fix timezone update issue leading to `invalidRange` error (#20863) @michelengelen
|
|
50
|
+
|
|
51
|
+
### Charts
|
|
52
|
+
|
|
53
|
+
#### `@mui/x-charts@9.0.0-alpha.1`
|
|
54
|
+
|
|
55
|
+
- [charts] Add `sort` props to the axis tooltip (#21293) @alexfauquette
|
|
56
|
+
- [charts] Controll axis tooltip (#21351) @alexfauquette
|
|
57
|
+
- [charts] De duplicate keyboard focus handler function (#21267) @sai6855
|
|
58
|
+
- [charts] Make `type` optional in identifiers (#21311) @alexfauquette
|
|
59
|
+
- [charts] Move ref to the root component (#21396) @alexfauquette
|
|
60
|
+
- [charts] Refactor loading and no data overlays to use a shared OverlayText component (#21414) @sai6855
|
|
61
|
+
- [charts] Require series ids to be unique (#21330) @alexfauquette
|
|
62
|
+
- [charts] Set `showMark` as `false` by default (#21373) @alexfauquette
|
|
63
|
+
- [charts] Use `createGetNextIndexFocusedItem()` util in Funnel and RangeBar charts (#21390) @sai6855
|
|
64
|
+
- [charts] Remove unnecessary string concatenation (#21418) @sai6855
|
|
65
|
+
|
|
66
|
+
#### `@mui/x-charts-pro@9.0.0-alpha.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
67
|
+
|
|
68
|
+
Same changes as in `@mui/x-charts@9.0.0-alpha.1`.
|
|
69
|
+
|
|
70
|
+
#### `@mui/x-charts-premium@9.0.0-alpha.1` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
71
|
+
|
|
72
|
+
Same changes as in `@mui/x-charts-pro@9.0.0-alpha.1`.
|
|
73
|
+
|
|
74
|
+
### Tree View
|
|
75
|
+
|
|
76
|
+
#### `@mui/x-tree-view@9.0.0-alpha.1`
|
|
77
|
+
|
|
78
|
+
- [tree view] Focus item sibling on unmount instead of the 1st item (#21254) @flaviendelangle
|
|
79
|
+
|
|
80
|
+
#### `@mui/x-tree-view-pro@9.0.0-alpha.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
81
|
+
|
|
82
|
+
Same changes as in `@mui/x-tree-view@9.0.0-alpha.1`.
|
|
83
|
+
|
|
84
|
+
### Codemod
|
|
85
|
+
|
|
86
|
+
#### `@mui/x-codemod@9.0.0-alpha.1`
|
|
87
|
+
|
|
88
|
+
Internal changes.
|
|
89
|
+
|
|
90
|
+
### Docs
|
|
91
|
+
|
|
92
|
+
- [docs] Fix external 301s (#21377) @Janpot
|
|
93
|
+
- [docs] Show premium in the overview (#21343) @alexfauquette
|
|
94
|
+
- [docs][charts] Revise the useLegend hook doc (#21352) @mapache-salvaje
|
|
95
|
+
- [docs][charts] Revise the axis hooks doc (#21317) @mapache-salvaje
|
|
96
|
+
- [docs][charts] Revise the scale hooks doc (#21316) @mapache-salvaje
|
|
97
|
+
- [docs][charts] Revise the series hooks doc (#21353) @mapache-salvaje
|
|
98
|
+
- [docs][charts] Revise the useDataset doc (#21336) @mapache-salvaje
|
|
99
|
+
- [docs][charts] Revise the useDrawingArea doc (#21333) @mapache-salvaje
|
|
100
|
+
|
|
101
|
+
### Core
|
|
102
|
+
|
|
103
|
+
- [core] Update docs deploy script to the `docs-next` branch (#21341) @siriwatknp
|
|
104
|
+
- [code-infra] Cleanup unused babel plugins (#21453) @brijeshb42
|
|
105
|
+
- [code-infra] Do not append `x` to the last version for the compare API (#21408) @arminmeh
|
|
106
|
+
- [code-infra] Upgrade react-docgen to v8 X (#21155) @JCQuintas
|
|
107
|
+
- [code-infra] Modernize codemod (#21096) @JCQuintas
|
|
108
|
+
- [docs-infra] Fix current version detection logic (#21417) @cherniavskii
|
|
109
|
+
- [docs-infra] Reapply Cookie Banner (#21281) @dav-is
|
|
110
|
+
- [internal] Headless filtering plugin (#21302) @arminmeh
|
|
111
|
+
- [internal] Headless pagination plugin (#21183) @arminmeh
|
|
112
|
+
- [internal] Headless virtualization followups (#21327) @cherniavskii
|
|
113
|
+
- [internal] Keep cached data for disabled pipe processors (#21348) @arminmeh
|
|
114
|
+
- [internal] Remove autoprefixer package (#21440) @ZeeshanTamboli
|
|
115
|
+
|
|
116
|
+
### Miscellaneous
|
|
117
|
+
|
|
118
|
+
- [l10n] Fix Czech (csCZ) locale: sort/filter labels are swapped (#21400) @EllGree
|
|
119
|
+
- [l10n] Improve Ukrainian (uk-UA) locale (#21366) @lion1963
|
|
120
|
+
|
|
3
121
|
## 9.0.0-alpha.0
|
|
4
122
|
|
|
5
123
|
_Feb 16, 2026_
|
package/README.md
CHANGED
|
@@ -97,6 +97,7 @@ The list includes these transformers
|
|
|
97
97
|
- [`replace-heatmap-hide-legend-false`](#replace-heatmap-hide-legend-false)
|
|
98
98
|
- [`rename-chart-api-import`](#rename-chart-api-import)
|
|
99
99
|
- [`rename-id-to-series-id`](#rename-id-to-series-id)
|
|
100
|
+
- [`replace-show-mark-default`](#replace-show-mark-default)
|
|
100
101
|
|
|
101
102
|
### `replace-heatmap-hide-legend-false`
|
|
102
103
|
|
|
@@ -165,6 +166,17 @@ Here is the list of slots and components that are impacted by the renaming:
|
|
|
165
166
|
| mark | MarkElement |
|
|
166
167
|
| lineHighlight | LineHighlightElement |
|
|
167
168
|
|
|
169
|
+
#### `replace-show-mark-default`
|
|
170
|
+
|
|
171
|
+
Add `showMark: true` to line series when not defined to keep the same default behavior.
|
|
172
|
+
|
|
173
|
+
```diff
|
|
174
|
+
- <LineChart series={[{ data: [/* ... */] }]} />
|
|
175
|
+
+ <LineChart series={[{ data: [/* ... */] showMark: true }]} />
|
|
176
|
+
- <ChartDataProvider series={[{ type: 'line', data: [/* ... */] }]} />
|
|
177
|
+
+ <ChartDataProvider series={[{ type: 'line', data: [/* ... */] showMark: true }]} />
|
|
178
|
+
```
|
|
179
|
+
|
|
168
180
|
## v8.0.0
|
|
169
181
|
|
|
170
182
|
### 🚀 `preset-safe` for v8.0.0
|
package/codemod.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
var
|
|
5
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
6
6
|
var _fs = require("fs");
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _yargs = _interopRequireDefault(require("yargs"));
|
|
9
|
-
|
|
10
|
-
const jscodeshiftDirectory = _path.default.dirname(require.resolve('jscodeshift'));
|
|
11
|
-
const jscodeshiftExecutable = _path.default.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
9
|
+
var _Runner = require("jscodeshift/src/Runner");
|
|
12
10
|
async function runTransform(transform, files, flags, codemodFlags) {
|
|
13
11
|
const transformerSrcPath = _path.default.resolve(__dirname, './src', transform);
|
|
14
12
|
const transformerBuildPath = _path.default.resolve(__dirname, transform);
|
|
@@ -27,13 +25,25 @@ async function runTransform(transform, files, flags, codemodFlags) {
|
|
|
27
25
|
throw buildPathError;
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
|
|
29
|
+
// Parse additional jscodeshift options from flags
|
|
30
|
+
const additionalOptions = {};
|
|
31
|
+
[...codemodFlags, ...flags.jscodeshift].forEach(flag => {
|
|
32
|
+
const match = flag.match(/^--([^=]+)(?:=(.*))?$/);
|
|
33
|
+
if (match) {
|
|
34
|
+
const [, key, value] = match;
|
|
35
|
+
additionalOptions[key] = value ?? true;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const options = (0, _extends2.default)({
|
|
39
|
+
extensions: 'js,ts,jsx,tsx',
|
|
40
|
+
parser: flags.parser || 'tsx',
|
|
41
|
+
ignorePattern: ['**/node_modules/**', ...(additionalOptions.ignorePattern || [])],
|
|
42
|
+
verbose: 2
|
|
43
|
+
}, additionalOptions);
|
|
34
44
|
|
|
35
45
|
// eslint-disable-next-line no-console -- debug information
|
|
36
|
-
console.log(`
|
|
46
|
+
console.log(`Running jscodeshift with transform: ${transformerPath}`);
|
|
37
47
|
console.warn(`
|
|
38
48
|
====================================
|
|
39
49
|
IMPORTANT NOTICE ABOUT CODEMOD USAGE
|
|
@@ -42,14 +52,12 @@ Not all use cases are covered by codemods. In some scenarios, like props spreadi
|
|
|
42
52
|
|
|
43
53
|
For example, if a codemod tries to rename a prop, but this prop is hidden with the spread operator, it won't be transformed as expected.
|
|
44
54
|
<DatePicker {...pickerProps} />
|
|
45
|
-
|
|
55
|
+
|
|
46
56
|
After running the codemods, make sure to test your application and that you don't have any formatting or console errors.
|
|
47
57
|
`);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (jscodeshiftProcess.error) {
|
|
52
|
-
throw jscodeshiftProcess.error;
|
|
58
|
+
const result = await (0, _Runner.run)(transformerPath, files, options);
|
|
59
|
+
if (result.error > 0) {
|
|
60
|
+
process.exit(1);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
function run(argv) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.1",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Codemod scripts for MUI X.",
|
|
6
|
-
"bin": "./codemod.js",
|
|
7
6
|
"keywords": [
|
|
8
7
|
"react",
|
|
9
8
|
"react-component",
|
|
@@ -41,5 +40,6 @@
|
|
|
41
40
|
"type": "commonjs",
|
|
42
41
|
"exports": {
|
|
43
42
|
"./package.json": "./package.json"
|
|
44
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"bin": "./codemod.js"
|
|
45
45
|
}
|
package/util/renameImports.js
CHANGED
|
@@ -23,7 +23,7 @@ const getMatchingNestedImport = (path, parameters) => {
|
|
|
23
23
|
};
|
|
24
24
|
const getMatchingRootImport = (path, parameters) => {
|
|
25
25
|
return parameters.imports.find(importConfig => {
|
|
26
|
-
return importConfig.importsMapping.hasOwnProperty(path.node.imported.name);
|
|
26
|
+
return importConfig.importsMapping.hasOwnProperty(path.node.imported.name.toString());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -29,7 +29,7 @@ function transformer(file, api, options) {
|
|
|
29
29
|
// Rename the import specifiers
|
|
30
30
|
// - import { GridFilterMenuItem } from '@mui/x-data-grid'
|
|
31
31
|
// + import { GridColumnMenuFilterItem } from '@mui/x-data-grid'
|
|
32
|
-
matchingImports.find(j.ImportSpecifier).filter(path => VARIABLES.hasOwnProperty(path.node.imported.name)).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name])));
|
|
32
|
+
matchingImports.find(j.ImportSpecifier).filter(path => VARIABLES.hasOwnProperty(path.node.imported.name.toString())).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name.toString()])));
|
|
33
33
|
|
|
34
34
|
// Rename the import usage
|
|
35
35
|
// - <GridFilterMenuItem />
|
|
@@ -124,7 +124,7 @@ function transformer(file, api, options) {
|
|
|
124
124
|
// Rename the import specifiers
|
|
125
125
|
// - import { DayCalendarSlotsComponent } from '@mui/x-date-pickers'
|
|
126
126
|
// + import { DayCalendarSlots } from '@mui/x-date-pickers'
|
|
127
|
-
matchingImports.find(j.ImportSpecifier).filter(path => Object.keys(rename).includes(path.node.imported.name)).replaceWith(path => j.importSpecifier(j.identifier(rename[path.node.imported.name]), path.value.local));
|
|
127
|
+
matchingImports.find(j.ImportSpecifier).filter(path => Object.keys(rename).includes(path.node.imported.name.toString())).replaceWith(path => j.importSpecifier(j.identifier(rename[path.node.imported.name.toString()]), path.value.local));
|
|
128
128
|
|
|
129
129
|
// Rename the import usage
|
|
130
130
|
// - DayCalendarSlotsComponent
|
|
@@ -19,7 +19,7 @@ function transformer(file, api, options) {
|
|
|
19
19
|
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
20
20
|
}).forEach(path => {
|
|
21
21
|
path.node.specifiers?.forEach(node => {
|
|
22
|
-
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
22
|
+
root.findJSXElements(node.local?.name.toString()).forEach(elementPath => {
|
|
23
23
|
if (elementPath.node.type !== 'JSXElement') {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -19,7 +19,7 @@ function transformer(file, api, options) {
|
|
|
19
19
|
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
20
20
|
}).forEach(path => {
|
|
21
21
|
path.node.specifiers?.forEach(node => {
|
|
22
|
-
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
22
|
+
root.findJSXElements(node.local?.name.toString()).forEach(elementPath => {
|
|
23
23
|
if (elementPath.node.type !== 'JSXElement') {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -19,7 +19,7 @@ function transformer(file, api, options) {
|
|
|
19
19
|
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
20
20
|
}).forEach(path => {
|
|
21
21
|
path.node.specifiers?.forEach(node => {
|
|
22
|
-
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
22
|
+
root.findJSXElements(node.local?.name.toString()).forEach(elementPath => {
|
|
23
23
|
if (elementPath.node.type !== 'JSXElement') {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -18,7 +18,7 @@ function transformer(file, api, options) {
|
|
|
18
18
|
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
19
19
|
}).forEach(path => {
|
|
20
20
|
path.node.specifiers?.forEach(node => {
|
|
21
|
-
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
21
|
+
root.findJSXElements(node.local?.name.toString()).forEach(elementPath => {
|
|
22
22
|
if (elementPath.node.type !== 'JSXElement') {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -19,7 +19,7 @@ function transformer(file, api, options) {
|
|
|
19
19
|
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
20
20
|
}).forEach(path => {
|
|
21
21
|
path.node.specifiers?.forEach(node => {
|
|
22
|
-
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
22
|
+
root.findJSXElements(node.local?.name.toString()).forEach(elementPath => {
|
|
23
23
|
if (elementPath.node.type !== 'JSXElement') {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -16,9 +16,9 @@ function transformer(file, api, options) {
|
|
|
16
16
|
// Find relevant DataGrid imports
|
|
17
17
|
const importedDataGrids = new Set();
|
|
18
18
|
root.find(j.ImportDeclaration).forEach(path => {
|
|
19
|
-
if (dataGridSources.has(path.node.source.value)) {
|
|
19
|
+
if (dataGridSources.has(path.node.source.value?.toString() ?? '')) {
|
|
20
20
|
path.node.specifiers?.forEach(specifier => {
|
|
21
|
-
if (specifier.type === 'ImportSpecifier' && dataGridComponents.has(specifier.imported.name)) {
|
|
21
|
+
if (specifier.type === 'ImportSpecifier' && dataGridComponents.has(specifier.imported.name.toString())) {
|
|
22
22
|
const localName = specifier.local?.name;
|
|
23
23
|
if (localName) {
|
|
24
24
|
importedDataGrids.add(localName);
|
|
@@ -9,9 +9,10 @@ exports.testConfig = void 0;
|
|
|
9
9
|
var renameIdToSeriesId = _interopRequireWildcard(require("../rename-id-to-series-id"));
|
|
10
10
|
var renameChartApiImport = _interopRequireWildcard(require("../rename-chart-api-import"));
|
|
11
11
|
var replaceHeatmapHideLegend = _interopRequireWildcard(require("../replace-heatmap-hide-legend-false"));
|
|
12
|
+
var replaceShowMarkDefault = _interopRequireWildcard(require("../replace-show-mark-default"));
|
|
12
13
|
const allModules = [
|
|
13
14
|
// Add other transforms here as they are created
|
|
14
|
-
replaceHeatmapHideLegend, renameIdToSeriesId, renameChartApiImport];
|
|
15
|
+
replaceHeatmapHideLegend, replaceShowMarkDefault, renameIdToSeriesId, renameChartApiImport];
|
|
15
16
|
function transformer(file, api, options) {
|
|
16
17
|
allModules.forEach(module => {
|
|
17
18
|
file.source = module.default(file, api, options);
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
11
|
+
const COMPONENT_NAMES = ['LineChart', 'LineChartPro', 'LineChartPremium'];
|
|
12
|
+
const PROVIDER_NAMES = ['ChartDataProvider', 'ChartDataProviderPro', 'ChartDataProviderPremium',
|
|
13
|
+
// With the new naming to be sure codemod order does not matter
|
|
14
|
+
'ChartsDataProvider', 'ChartsDataProviderPro', 'ChartsDataProviderPremium',
|
|
15
|
+
// The component that includes the data provider.
|
|
16
|
+
'ChartsContainer', 'ChartsContainerPro', 'ChartsContainerPremium'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Codemod for v9.0.0: Updates line series objects to preserve v8 behavior after the `showMark` default changes from true to false.
|
|
20
|
+
*
|
|
21
|
+
* If `showMark` is not defined, adds `showMark: true` to preserve v8 behavior.
|
|
22
|
+
*
|
|
23
|
+
* The `showmMark: false` cases are left unchanged to stay idempotent.
|
|
24
|
+
*
|
|
25
|
+
* Ths codemod applies on LineChart components and providers when series type is set to 'line'.
|
|
26
|
+
*/
|
|
27
|
+
function transformer(file, api, options) {
|
|
28
|
+
const j = api.jscodeshift;
|
|
29
|
+
const root = j(file.source);
|
|
30
|
+
const printOptions = options.printOptions || {
|
|
31
|
+
quote: 'single',
|
|
32
|
+
trailingComma: true
|
|
33
|
+
};
|
|
34
|
+
root.find(j.JSXElement).filter(p => COMPONENT_NAMES.includes(p.value.openingElement.name.name)).forEach(p => {
|
|
35
|
+
const seriesAttr = p.value.openingElement.attributes?.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'series');
|
|
36
|
+
if (!seriesAttr || seriesAttr.type !== 'JSXAttribute') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const seriesValue = seriesAttr.value;
|
|
40
|
+
if (!seriesValue || seriesValue.type !== 'JSXExpressionContainer') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const expr = seriesValue.expression;
|
|
44
|
+
if (expr.type !== 'ArrayExpression') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
expr.elements.forEach(element => {
|
|
48
|
+
if (!element || element.type !== 'ObjectExpression') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const hasShowMark = element.properties.some(prop => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && prop.key.name === 'showMark');
|
|
52
|
+
if (!hasShowMark) {
|
|
53
|
+
element.properties.push(j.objectProperty(j.identifier('showMark'), j.booleanLiteral(true)));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
root.find(j.JSXElement).filter(p => PROVIDER_NAMES.includes(p.value.openingElement.name.name)).forEach(p => {
|
|
58
|
+
const seriesAttr = p.value.openingElement.attributes?.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'series');
|
|
59
|
+
if (!seriesAttr || seriesAttr.type !== 'JSXAttribute') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const seriesValue = seriesAttr.value;
|
|
63
|
+
if (!seriesValue || seriesValue.type !== 'JSXExpressionContainer') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const expr = seriesValue.expression;
|
|
67
|
+
if (expr.type !== 'ArrayExpression') {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
expr.elements.forEach(element => {
|
|
71
|
+
if (!element || element.type !== 'ObjectExpression') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const lineSeriesType = element.properties.some(prop => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && prop.key.name === 'type' && prop.value.type === 'StringLiteral' && prop.value.value === 'line');
|
|
75
|
+
const hasShowMark = element.properties.some(prop => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && prop.key.name === 'showMark');
|
|
76
|
+
if (lineSeriesType && !hasShowMark) {
|
|
77
|
+
element.properties.push(j.objectProperty(j.identifier('showMark'), j.booleanLiteral(true)));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return root.toSource(printOptions);
|
|
82
|
+
}
|
|
83
|
+
const testConfig = () => ({
|
|
84
|
+
name: 'replace-show-mark-default',
|
|
85
|
+
specFiles: [{
|
|
86
|
+
name: 'imports',
|
|
87
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
88
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
89
|
+
}]
|
|
90
|
+
});
|
|
91
|
+
exports.testConfig = testConfig;
|