@mui/x-codemod 9.0.0-alpha.4 → 9.0.0
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 +374 -2
- package/README.md +211 -4
- package/package.json +3 -3
- package/util/addComponentsSlots.js +21 -4
- package/util/renameClasses.js +7 -0
- package/v9.0.0/pickers/migrate-text-field-props/index.js +192 -0
- package/v9.0.0/pickers/preset-safe/index.js +18 -2
- package/v9.0.0/pickers/remove-disable-margin/index.js +134 -0
- package/v9.0.0/pickers/remove-enable-accessible-field-dom-structure/index.js +72 -0
- package/v9.0.0/pickers/remove-picker-day-2/index.js +155 -0
- package/v9.0.0/pickers/rename-picker-classes/index.js +126 -0
- package/v9.0.0/pickers/rename-picker-day-2/index.js +105 -0
- package/v9.0.0/pickers/rename-pickers-day/index.js +90 -0
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
var _renameClasses = require("../../../util/renameClasses");
|
|
12
|
+
const classRenames = {
|
|
13
|
+
outsideCurrentMonth: 'dayOutsideMonth',
|
|
14
|
+
hiddenDayFiller: 'fillerCell',
|
|
15
|
+
hiddenDaySpacingFiller: 'fillerCell',
|
|
16
|
+
rangeIntervalDayHighlightStart: 'selectionStart',
|
|
17
|
+
rangeIntervalDayHighlightEnd: 'selectionEnd',
|
|
18
|
+
rangeIntervalDayPreviewStart: 'previewStart',
|
|
19
|
+
rangeIntervalDayPreviewEnd: 'previewEnd',
|
|
20
|
+
dayInsideRangeInterval: 'insideSelection',
|
|
21
|
+
rangeIntervalPreview: 'insidePreviewing',
|
|
22
|
+
rangeIntervalDayHighlight: 'selectionStart',
|
|
23
|
+
rangeIntervalDayPreview: 'previewStart'
|
|
24
|
+
};
|
|
25
|
+
function transformer(file, api, options) {
|
|
26
|
+
const j = api.jscodeshift;
|
|
27
|
+
const root = j(file.source);
|
|
28
|
+
const printOptions = options.printOptions || {
|
|
29
|
+
quote: 'single',
|
|
30
|
+
trailingComma: true
|
|
31
|
+
};
|
|
32
|
+
(0, _renameClasses.renameClasses)({
|
|
33
|
+
j,
|
|
34
|
+
root,
|
|
35
|
+
packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
|
|
36
|
+
classes: {
|
|
37
|
+
dateRangePickerDayClasses: {
|
|
38
|
+
newClassName: 'dateRangePickerDayClasses',
|
|
39
|
+
properties: classRenames
|
|
40
|
+
},
|
|
41
|
+
pickerDayClasses: {
|
|
42
|
+
newClassName: 'pickerDayClasses',
|
|
43
|
+
properties: classRenames
|
|
44
|
+
},
|
|
45
|
+
pickersDayClasses: {
|
|
46
|
+
newClassName: 'pickerDayClasses',
|
|
47
|
+
properties: classRenames
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Rename properties in styleOverrides
|
|
53
|
+
const componentsToHandle = ['MuiDateRangePickerDay', 'MuiPickerDay', 'MuiPickersDay'];
|
|
54
|
+
root.find(j.ObjectProperty).forEach(objPropPath => {
|
|
55
|
+
const keyName = objPropPath.node.key.type === 'Identifier' ? objPropPath.node.key.name : objPropPath.node.key.value;
|
|
56
|
+
if (componentsToHandle.includes(keyName) && objPropPath.node.value.type === 'ObjectExpression') {
|
|
57
|
+
j(objPropPath.node.value).find(j.ObjectProperty).filter(p => {
|
|
58
|
+
const k = p.node.key.type === 'Identifier' ? p.node.key.name : p.node.key.value;
|
|
59
|
+
return k === 'styleOverrides';
|
|
60
|
+
}).forEach(styleOverridesPath => {
|
|
61
|
+
if (styleOverridesPath.node.value.type === 'ObjectExpression') {
|
|
62
|
+
const seenProperties = new Map();
|
|
63
|
+
const indicesToRemove = new Set();
|
|
64
|
+
styleOverridesPath.node.value.properties.forEach((prop, index) => {
|
|
65
|
+
if (prop.type === 'ObjectProperty') {
|
|
66
|
+
const propKey = prop.key.type === 'Identifier' ? prop.key.name : prop.key.value;
|
|
67
|
+
const newKey = classRenames[propKey];
|
|
68
|
+
if (newKey) {
|
|
69
|
+
if (seenProperties.has(newKey)) {
|
|
70
|
+
const firstProp = seenProperties.get(newKey);
|
|
71
|
+
if (firstProp.value.type === 'ObjectExpression' && prop.value.type === 'ObjectExpression') {
|
|
72
|
+
firstProp.value.properties.push(...prop.value.properties);
|
|
73
|
+
}
|
|
74
|
+
indicesToRemove.add(index);
|
|
75
|
+
} else {
|
|
76
|
+
if (prop.key.type === 'Identifier') {
|
|
77
|
+
prop.key.name = newKey;
|
|
78
|
+
} else if (prop.key.type === 'StringLiteral') {
|
|
79
|
+
prop.key.value = newKey;
|
|
80
|
+
}
|
|
81
|
+
seenProperties.set(newKey, prop);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
styleOverridesPath.node.value.properties = styleOverridesPath.node.value.properties.filter((_, index) => !indicesToRemove.has(index));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Rename class names in strings and template literals.
|
|
93
|
+
// Only replace within known MUI component CSS class prefixes to avoid false positives.
|
|
94
|
+
const muiClassPrefixes = componentsToHandle.map(c => `${c}-`);
|
|
95
|
+
const replaceClasses = value => {
|
|
96
|
+
let newValue = value;
|
|
97
|
+
muiClassPrefixes.forEach(prefix => {
|
|
98
|
+
Object.keys(classRenames).forEach(oldClass => {
|
|
99
|
+
const newClass = classRenames[oldClass];
|
|
100
|
+
newValue = newValue.replace(new RegExp(`${prefix}${oldClass}\\b`, 'g'), `${prefix}${newClass}`);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
return newValue;
|
|
104
|
+
};
|
|
105
|
+
root.find(j.StringLiteral).forEach(strPath => {
|
|
106
|
+
strPath.node.value = replaceClasses(strPath.node.value);
|
|
107
|
+
});
|
|
108
|
+
root.find(j.TemplateLiteral).forEach(templatePath => {
|
|
109
|
+
templatePath.node.quasis.forEach(quasi => {
|
|
110
|
+
quasi.value.raw = replaceClasses(quasi.value.raw);
|
|
111
|
+
if (quasi.value.cooked) {
|
|
112
|
+
quasi.value.cooked = replaceClasses(quasi.value.cooked);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return root.toSource(printOptions);
|
|
117
|
+
}
|
|
118
|
+
const testConfig = () => ({
|
|
119
|
+
name: 'rename-picker-classes',
|
|
120
|
+
specFiles: [{
|
|
121
|
+
name: 'rename PickerDay and DateRangePickerDay class keys',
|
|
122
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
123
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
124
|
+
}]
|
|
125
|
+
});
|
|
126
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
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
|
+
const renames = {
|
|
19
|
+
PickerDay2: 'PickerDay',
|
|
20
|
+
PickerDay2Props: 'PickerDayProps',
|
|
21
|
+
pickerDay2Classes: 'pickerDayClasses',
|
|
22
|
+
PickerDay2ClassKey: 'PickerDayClassKey',
|
|
23
|
+
PickerDay2Slots: 'PickerDaySlots',
|
|
24
|
+
PickerDay2SlotProps: 'PickerDaySlotProps',
|
|
25
|
+
PickerDay2OwnerState: 'PickerDayOwnerState',
|
|
26
|
+
DateRangePickerDay2: 'DateRangePickerDay',
|
|
27
|
+
DateRangePickerDay2Props: 'DateRangePickerDayProps',
|
|
28
|
+
dateRangePickerDay2Classes: 'dateRangePickerDayClasses',
|
|
29
|
+
DateRangePickerDay2ClassKey: 'DateRangePickerDayClassKey',
|
|
30
|
+
DateRangePickerDay2Slots: 'DateRangePickerDaySlots',
|
|
31
|
+
DateRangePickerDay2SlotProps: 'DateRangePickerDaySlotProps',
|
|
32
|
+
DateRangePickerDay2OwnerState: 'DateRangePickerDayOwnerState'
|
|
33
|
+
};
|
|
34
|
+
const renameKeys = Object.keys(renames);
|
|
35
|
+
|
|
36
|
+
// Rename imports and usages
|
|
37
|
+
renameKeys.forEach(oldName => {
|
|
38
|
+
const newName = renames[oldName];
|
|
39
|
+
root.find(j.Identifier, {
|
|
40
|
+
name: oldName
|
|
41
|
+
}).forEach(keyPath => {
|
|
42
|
+
// Avoid renaming property keys in objects unless they are shorthand or identifiers in other contexts
|
|
43
|
+
if (keyPath.parent.value.type === 'Property' && keyPath.parent.value.key === keyPath.node && !keyPath.parent.value.shorthand) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Avoid renaming member expressions like something.PickerDay2
|
|
47
|
+
if (keyPath.parent.value.type === 'MemberExpression' && keyPath.parent.value.property === keyPath.node && !keyPath.parent.value.computed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
j(keyPath).replaceWith(j.identifier(newName));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Rename theme components in createTheme / theme augmentation
|
|
55
|
+
root.find(j.Identifier, {
|
|
56
|
+
name: 'MuiPickerDay2'
|
|
57
|
+
}).forEach(keyPath => {
|
|
58
|
+
j(keyPath).replaceWith(j.identifier('MuiPickerDay'));
|
|
59
|
+
});
|
|
60
|
+
root.find(j.Identifier, {
|
|
61
|
+
name: 'MuiDateRangePickerDay2'
|
|
62
|
+
}).forEach(keyPath => {
|
|
63
|
+
j(keyPath).replaceWith(j.identifier('MuiDateRangePickerDay'));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Also handle string literals and template literals
|
|
67
|
+
const replaceClass = value => value.replace(/MuiPickerDay2\b/g, 'MuiPickerDay').replace(/MuiDateRangePickerDay2\b/g, 'MuiDateRangePickerDay');
|
|
68
|
+
root.find(j.StringLiteral).forEach(keyPath => {
|
|
69
|
+
if (keyPath.value.value.includes('MuiPickerDay2') || keyPath.value.value.includes('MuiDateRangePickerDay2')) {
|
|
70
|
+
j(keyPath).replaceWith(j.stringLiteral(replaceClass(keyPath.value.value)));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
root.find(j.TemplateLiteral).forEach(keyPath => {
|
|
74
|
+
keyPath.value.quasis.forEach(quasi => {
|
|
75
|
+
if (quasi.value.raw.includes('MuiPickerDay2') || quasi.value.raw.includes('MuiDateRangePickerDay2')) {
|
|
76
|
+
quasi.value.raw = replaceClass(quasi.value.raw);
|
|
77
|
+
}
|
|
78
|
+
if (quasi.value.cooked && (quasi.value.cooked.includes('MuiPickerDay2') || quasi.value.cooked.includes('MuiDateRangePickerDay2'))) {
|
|
79
|
+
quasi.value.cooked = replaceClass(quasi.value.cooked);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Update import sources
|
|
85
|
+
root.find(j.ImportDeclaration).forEach(importPath => {
|
|
86
|
+
if (typeof importPath.value.source.value === 'string') {
|
|
87
|
+
if (importPath.value.source.value.includes('/PickerDay2')) {
|
|
88
|
+
importPath.value.source.value = importPath.value.source.value.replace('/PickerDay2', '/PickerDay');
|
|
89
|
+
}
|
|
90
|
+
if (importPath.value.source.value.includes('/DateRangePickerDay2')) {
|
|
91
|
+
importPath.value.source.value = importPath.value.source.value.replace('/DateRangePickerDay2', '/DateRangePickerDay');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return root.toSource(printOptions);
|
|
96
|
+
}
|
|
97
|
+
const testConfig = () => ({
|
|
98
|
+
name: 'rename-picker-day-2',
|
|
99
|
+
specFiles: [{
|
|
100
|
+
name: 'rename PickerDay2 and DateRangePickerDay2 to PickerDay and DateRangePickerDay',
|
|
101
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
102
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
103
|
+
}]
|
|
104
|
+
});
|
|
105
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
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
|
+
const renames = {
|
|
19
|
+
PickersDay: 'PickerDay',
|
|
20
|
+
PickersDayProps: 'PickerDayProps',
|
|
21
|
+
pickersDayClasses: 'pickerDayClasses',
|
|
22
|
+
PickersDayClassKey: 'PickerDayClassKey',
|
|
23
|
+
PickersDaySlots: 'PickerDaySlots',
|
|
24
|
+
PickersDaySlotProps: 'PickerDaySlotProps',
|
|
25
|
+
PickersDayOwnerState: 'PickerDayOwnerState'
|
|
26
|
+
};
|
|
27
|
+
const renameKeys = Object.keys(renames);
|
|
28
|
+
|
|
29
|
+
// Rename imports and usages
|
|
30
|
+
renameKeys.forEach(oldName => {
|
|
31
|
+
const newName = renames[oldName];
|
|
32
|
+
root.find(j.Identifier, {
|
|
33
|
+
name: oldName
|
|
34
|
+
}).forEach(keyPath => {
|
|
35
|
+
// Avoid renaming property keys in objects unless they are shorthand or identifiers in other contexts
|
|
36
|
+
if (keyPath.parent.value.type === 'Property' && keyPath.parent.value.key === keyPath.node && !keyPath.parent.value.shorthand) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Avoid renaming member expressions like something.PickersDay
|
|
40
|
+
if (keyPath.parent.value.type === 'MemberExpression' && keyPath.parent.value.property === keyPath.node && !keyPath.parent.value.computed) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
j(keyPath).replaceWith(j.identifier(newName));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Rename theme components in createTheme / theme augmentation
|
|
48
|
+
root.find(j.Identifier, {
|
|
49
|
+
name: 'MuiPickersDay'
|
|
50
|
+
}).forEach(keyPath => {
|
|
51
|
+
j(keyPath).replaceWith(j.identifier('MuiPickerDay'));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Also handle string literals and template literals for MuiPickersDay if any (e.g. in theme overrides or sx)
|
|
55
|
+
const replaceClass = value => value.replace(/MuiPickersDay\b/g, 'MuiPickerDay');
|
|
56
|
+
root.find(j.StringLiteral).forEach(keyPath => {
|
|
57
|
+
if (keyPath.value.value.includes('MuiPickersDay')) {
|
|
58
|
+
j(keyPath).replaceWith(j.stringLiteral(replaceClass(keyPath.value.value)));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
root.find(j.TemplateLiteral).forEach(keyPath => {
|
|
62
|
+
keyPath.value.quasis.forEach(quasi => {
|
|
63
|
+
if (quasi.value.raw.includes('MuiPickersDay')) {
|
|
64
|
+
quasi.value.raw = replaceClass(quasi.value.raw);
|
|
65
|
+
}
|
|
66
|
+
if (quasi.value.cooked && quasi.value.cooked.includes('MuiPickersDay')) {
|
|
67
|
+
quasi.value.cooked = replaceClass(quasi.value.cooked);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Update import sources if they point to PickersDay (though usually they point to @mui/x-date-pickers)
|
|
73
|
+
root.find(j.ImportDeclaration).forEach(importPath => {
|
|
74
|
+
if (typeof importPath.value.source.value === 'string') {
|
|
75
|
+
if (importPath.value.source.value.includes('/PickersDay')) {
|
|
76
|
+
importPath.value.source.value = importPath.value.source.value.replace('/PickersDay', '/PickerDay');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return root.toSource(printOptions);
|
|
81
|
+
}
|
|
82
|
+
const testConfig = () => ({
|
|
83
|
+
name: 'rename-pickers-day',
|
|
84
|
+
specFiles: [{
|
|
85
|
+
name: 'rename PickersDay to PickerDay and related types',
|
|
86
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
87
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
88
|
+
}]
|
|
89
|
+
});
|
|
90
|
+
exports.testConfig = testConfig;
|