@react-spectrum/codemods 1.2.1 → 1.2.3
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/dist/index.js +12 -10
- package/dist/s1-to-s2/src/codemods/codemod.js +33 -17
- package/dist/s1-to-s2/src/codemods/components/ActionGroup/transform.js +34 -11
- package/dist/s1-to-s2/src/codemods/components/Avatar/transform.js +5 -1
- package/dist/s1-to-s2/src/codemods/components/ContextualHelpTrigger/transform.js +1 -1
- package/dist/s1-to-s2/src/codemods/components/DialogContainer/transform.js +3 -4
- package/dist/s1-to-s2/src/codemods/components/DialogTrigger/transform.js +33 -11
- package/dist/s1-to-s2/src/codemods/components/Item/transform.js +28 -7
- package/dist/s1-to-s2/src/codemods/components/Link/transform.js +6 -4
- package/dist/s1-to-s2/src/codemods/components/Row/transform.js +12 -5
- package/dist/s1-to-s2/src/codemods/components/Section/transform.js +12 -3
- package/dist/s1-to-s2/src/codemods/components/TableView/transform.js +36 -19
- package/dist/s1-to-s2/src/codemods/components/Tabs/transform.js +25 -9
- package/dist/s1-to-s2/src/codemods/icons/iconMap.js +319 -1276
- package/dist/s1-to-s2/src/codemods/shared/dimensions.js +5 -32
- package/dist/s1-to-s2/src/codemods/shared/styleProps.js +55 -19
- package/dist/s1-to-s2/src/codemods/shared/transforms.js +130 -67
- package/dist/s1-to-s2/src/codemods/shared/unsafeStyle.js +102 -48
- package/dist/s1-to-s2/src/codemods/shared/utils.js +31 -28
- package/dist/s1-to-s2/src/getComponents.js +8 -8
- package/dist/s1-to-s2/src/index.js +10 -6
- package/dist/s1-to-s2/src/utils/installPackage.js +5 -1
- package/dist/s1-to-s2/src/utils/waitForKeypress.js +1 -1
- package/dist/test-utils-rc-update/src/codemod.js +236 -0
- package/dist/test-utils-rc-update/src/index.js +13 -0
- package/dist/use-monopackages/src/codemod.js +25 -27
- package/dist/use-subpaths/src/codemod.js +11 -5
- package/dist/use-subpaths/src/specifiers.js +3 -1
- package/package.json +24 -22
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
4
|
+
const parser_1 = require("@babel/parser");
|
|
5
|
+
const recast_1 = require("recast");
|
|
6
|
+
const RENAME_MAP = {
|
|
7
|
+
checkboxgroup: 'getCheckboxGroup',
|
|
8
|
+
checkboxes: 'getCheckboxes',
|
|
9
|
+
selectedCheckboxes: 'getSelectedCheckboxes',
|
|
10
|
+
combobox: 'getCombobox',
|
|
11
|
+
trigger: 'getTrigger',
|
|
12
|
+
listbox: 'getListbox',
|
|
13
|
+
sections: 'getSections',
|
|
14
|
+
options: 'getOptions',
|
|
15
|
+
focusedOption: 'getFocusedOption',
|
|
16
|
+
selectOption: 'toggleOptionSelection',
|
|
17
|
+
dialog: 'getDialog',
|
|
18
|
+
gridlist: 'getGridlist',
|
|
19
|
+
rows: 'getRows',
|
|
20
|
+
selectedRows: 'getSelectedRows',
|
|
21
|
+
cells: 'getCells',
|
|
22
|
+
selectedOptions: 'getSelectedOptions',
|
|
23
|
+
menu: 'getMenu',
|
|
24
|
+
submenuTriggers: 'getSubmenuTriggers',
|
|
25
|
+
radiogroup: 'getRadioGroup',
|
|
26
|
+
radios: 'getRadios',
|
|
27
|
+
selectedRadio: 'getSelectedRadio',
|
|
28
|
+
table: 'getTable',
|
|
29
|
+
rowGroups: 'getRowGroups',
|
|
30
|
+
columns: 'getColumns',
|
|
31
|
+
rowHeaders: 'getRowHeaders',
|
|
32
|
+
tablist: 'getTablist',
|
|
33
|
+
tabpanels: 'getTabpanels',
|
|
34
|
+
selectedTab: 'getSelectedTab',
|
|
35
|
+
tabs: 'getTabs',
|
|
36
|
+
activeTabpanel: 'getActiveTabpanel',
|
|
37
|
+
tree: 'getTree'
|
|
38
|
+
};
|
|
39
|
+
const FIND_PARAM_KEY_MAP = {
|
|
40
|
+
findCheckbox: 'checkboxIndexOrText',
|
|
41
|
+
findOption: 'optionIndexOrText',
|
|
42
|
+
findRow: 'rowIndexOrText',
|
|
43
|
+
findRadio: 'radioIndexOrText',
|
|
44
|
+
findTab: 'tabIndexOrText'
|
|
45
|
+
};
|
|
46
|
+
// Methods on a tester that return another tester object
|
|
47
|
+
const TESTER_RETURNING_METHODS = new Set(['openSubmenu']);
|
|
48
|
+
function transformer(file, api) {
|
|
49
|
+
let j = api.jscodeshift.withParser({
|
|
50
|
+
parse(source) {
|
|
51
|
+
return (0, recast_1.parse)(source, {
|
|
52
|
+
parser: {
|
|
53
|
+
parse(innerSource) {
|
|
54
|
+
return (0, parser_1.parse)(innerSource, {
|
|
55
|
+
sourceType: 'module',
|
|
56
|
+
plugins: [
|
|
57
|
+
'jsx',
|
|
58
|
+
'typescript',
|
|
59
|
+
'importAssertions',
|
|
60
|
+
'dynamicImport',
|
|
61
|
+
'decorators-legacy',
|
|
62
|
+
'classProperties',
|
|
63
|
+
'classPrivateProperties',
|
|
64
|
+
'classPrivateMethods',
|
|
65
|
+
'exportDefaultFrom',
|
|
66
|
+
'exportNamespaceFrom',
|
|
67
|
+
'objectRestSpread',
|
|
68
|
+
'optionalChaining',
|
|
69
|
+
'nullishCoalescingOperator',
|
|
70
|
+
'topLevelAwait'
|
|
71
|
+
],
|
|
72
|
+
tokens: true,
|
|
73
|
+
errorRecovery: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
let root = j(file.source);
|
|
81
|
+
let testerVarNames = new Set();
|
|
82
|
+
function unwrapAwait(node) {
|
|
83
|
+
while (node?.type === 'AwaitExpression' || node?.type === 'TSNonNullExpression') {
|
|
84
|
+
node = node.type === 'TSNonNullExpression' ? node.expression : node.argument;
|
|
85
|
+
}
|
|
86
|
+
return node;
|
|
87
|
+
}
|
|
88
|
+
function isCallOf(node) {
|
|
89
|
+
return node?.type === 'CallExpression' || node?.type === 'OptionalCallExpression';
|
|
90
|
+
}
|
|
91
|
+
function isMemberOf(node) {
|
|
92
|
+
return node?.type === 'MemberExpression' || node?.type === 'OptionalMemberExpression';
|
|
93
|
+
}
|
|
94
|
+
// Initial pass: find variables directly from createTester(...)
|
|
95
|
+
root.find(j.VariableDeclarator).forEach(path => {
|
|
96
|
+
let id = path.node.id;
|
|
97
|
+
if (id.type !== 'Identifier') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
let call = unwrapAwait(path.node.init);
|
|
101
|
+
if (!isCallOf(call)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let callee = call.callee;
|
|
105
|
+
let isCreateTester = (isMemberOf(callee) && callee.property?.name === 'createTester') ||
|
|
106
|
+
(callee?.type === 'Identifier' && callee?.name === 'createTester');
|
|
107
|
+
if (isCreateTester) {
|
|
108
|
+
testerVarNames.add(id.name);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (testerVarNames.size === 0) {
|
|
112
|
+
return file.source;
|
|
113
|
+
}
|
|
114
|
+
// Multi-pass: propagate tracking through methods that return testers (e.g. openSubmenu)
|
|
115
|
+
let propagating = true;
|
|
116
|
+
while (propagating) {
|
|
117
|
+
propagating = false;
|
|
118
|
+
root.find(j.VariableDeclarator).forEach(path => {
|
|
119
|
+
let id = path.node.id;
|
|
120
|
+
if (id.type !== 'Identifier' || testerVarNames.has(id.name)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let call = unwrapAwait(path.node.init);
|
|
124
|
+
if (!isCallOf(call) || !isMemberOf(call.callee)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let obj = call.callee.object;
|
|
128
|
+
let methodName = call.callee.property?.type === 'Identifier' ? call.callee.property.name : '';
|
|
129
|
+
if (obj?.type === 'Identifier' &&
|
|
130
|
+
testerVarNames.has(obj.name) &&
|
|
131
|
+
TESTER_RETURNING_METHODS.has(methodName)) {
|
|
132
|
+
testerVarNames.add(id.name);
|
|
133
|
+
propagating = true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
let didChange = false;
|
|
138
|
+
function renamePropInCallee(callee) {
|
|
139
|
+
if (!isMemberOf(callee) ||
|
|
140
|
+
callee.object?.type !== 'Identifier' ||
|
|
141
|
+
!testerVarNames.has(callee.object.name)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
let propName = callee.property?.type === 'Identifier' ? callee.property.name : '';
|
|
145
|
+
let newName = RENAME_MAP[propName];
|
|
146
|
+
if (!newName) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
callee.property = j.identifier(newName);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
// Pass 1: Rename method calls — tester.options() → tester.getOptions()
|
|
153
|
+
root.find(j.CallExpression, { callee: { type: 'MemberExpression' } }).forEach(path => {
|
|
154
|
+
if (path.node.type !== 'CallExpression') {
|
|
155
|
+
return; // skip OptionalCallExpression matched by babel parser
|
|
156
|
+
}
|
|
157
|
+
if (renamePropInCallee(path.node.callee)) {
|
|
158
|
+
didChange = true;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
// Pass 1B: tester?.options() → tester?.getOptions()
|
|
162
|
+
root.find(j.OptionalCallExpression).forEach(path => {
|
|
163
|
+
if (renamePropInCallee(path.node.callee)) {
|
|
164
|
+
didChange = true;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
// Pass 2: Property access → call — tester.rows → tester.getRows()
|
|
168
|
+
root.find(j.MemberExpression).forEach(path => {
|
|
169
|
+
let node = path.node;
|
|
170
|
+
if (node.type !== 'MemberExpression') {
|
|
171
|
+
return; // skip OptionalMemberExpression matched by babel parser
|
|
172
|
+
}
|
|
173
|
+
if (node.object?.type !== 'Identifier' || !testerVarNames.has(node.object.name)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
let propName = node.property?.type === 'Identifier' ? node.property.name : '';
|
|
177
|
+
let newName = RENAME_MAP[propName];
|
|
178
|
+
if (!newName) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
let parent = path.parent?.node;
|
|
182
|
+
if (parent?.type === 'CallExpression' && parent.callee === path.node) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
j(path).replaceWith(j.callExpression(j.memberExpression(node.object, j.identifier(newName)), []));
|
|
186
|
+
didChange = true;
|
|
187
|
+
});
|
|
188
|
+
// Pass 2B: tester?.rows → tester?.getRows()
|
|
189
|
+
root.find(j.OptionalMemberExpression).forEach(path => {
|
|
190
|
+
let node = path.node;
|
|
191
|
+
if (node.object?.type !== 'Identifier' || !testerVarNames.has(node.object.name)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
let propName = node.property?.type === 'Identifier' ? node.property.name : '';
|
|
195
|
+
let newName = RENAME_MAP[propName];
|
|
196
|
+
if (!newName) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
let parent = path.parent?.node;
|
|
200
|
+
if ((parent?.type === 'OptionalCallExpression' || parent?.type === 'CallExpression') &&
|
|
201
|
+
parent.callee === path.node) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
j(path).replaceWith(j.optionalCallExpression(j.optionalMemberExpression(node.object, j.identifier(newName), false, true), [], false));
|
|
205
|
+
didChange = true;
|
|
206
|
+
});
|
|
207
|
+
// Pass 3: Rename param keys inside find* calls — {optionIndexOrText: x} → {indexOrText: x}
|
|
208
|
+
function renameFindParamKey(callPath) {
|
|
209
|
+
let callee = callPath.node.callee;
|
|
210
|
+
if (!isMemberOf(callee) ||
|
|
211
|
+
callee.object?.type !== 'Identifier' ||
|
|
212
|
+
!testerVarNames.has(callee.object.name)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
let methodName = callee.property?.type === 'Identifier' ? callee.property.name : '';
|
|
216
|
+
let oldKey = FIND_PARAM_KEY_MAP[methodName];
|
|
217
|
+
if (!oldKey) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let firstArg = callPath.node.arguments[0];
|
|
221
|
+
if (firstArg?.type !== 'ObjectExpression') {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (let prop of firstArg.properties) {
|
|
225
|
+
if (prop.type === 'ObjectProperty' &&
|
|
226
|
+
prop.key?.type === 'Identifier' &&
|
|
227
|
+
prop.key.name === oldKey) {
|
|
228
|
+
prop.key = j.identifier('indexOrText');
|
|
229
|
+
didChange = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
root.find(j.CallExpression, { callee: { type: 'MemberExpression' } }).forEach(renameFindParamKey);
|
|
234
|
+
root.find(j.OptionalCallExpression).forEach(renameFindParamKey);
|
|
235
|
+
return didChange ? root.toSource({ quote: 'single' }) : file.source;
|
|
236
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.test_utils_rc_update = test_utils_rc_update;
|
|
7
|
+
const Runner_js_1 = require("jscodeshift/src/Runner.js");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const transformPath = path_1.default.join(__dirname, 'codemod.js');
|
|
10
|
+
async function test_utils_rc_update(options) {
|
|
11
|
+
let { path: filePath = '.', ...rest } = options;
|
|
12
|
+
return await (0, Runner_js_1.run)(transformPath, [filePath], rest);
|
|
13
|
+
}
|
|
@@ -5,7 +5,7 @@ const path = require('path');
|
|
|
5
5
|
const Module = require('module');
|
|
6
6
|
const url = require('url');
|
|
7
7
|
function areSpecifiersAlphabetized(specifiers) {
|
|
8
|
-
const specifierNames = specifiers.map(
|
|
8
|
+
const specifierNames = specifiers.map(specifier => specifier.imported.name);
|
|
9
9
|
const sortedNames = [...specifierNames].sort();
|
|
10
10
|
return specifierNames.join() === sortedNames.join();
|
|
11
11
|
}
|
|
@@ -13,13 +13,17 @@ function areSpecifiersAlphabetized(specifiers) {
|
|
|
13
13
|
* Replaces individual package imports with monopackage imports, where possible.
|
|
14
14
|
*
|
|
15
15
|
* Works for:
|
|
16
|
+
*
|
|
16
17
|
* - `@react-spectrum/*` -> `@adobe/react-spectrum`.
|
|
17
18
|
* - `@react-aria/*` -> `react-aria`.
|
|
18
19
|
* - `@react-stately/*` -> `react-stately`.
|
|
19
20
|
*
|
|
20
|
-
* By default this will apply to all the above packages, or optionally you can specify which
|
|
21
|
+
* By default this will apply to all the above packages, or optionally you can specify which
|
|
22
|
+
* packages to apply this by passing a comma-separated list to the packages option:
|
|
23
|
+
* `--packages=react-aria,react-stately,react-spectrum`.
|
|
21
24
|
*
|
|
22
|
-
* Run this from a directory where the relevant packages are installed in node_modules so it knows
|
|
25
|
+
* Run this from a directory where the relevant packages are installed in node_modules so it knows
|
|
26
|
+
* which monopackage exports are available to use (since exports may vary by version).
|
|
23
27
|
*/
|
|
24
28
|
const transformer = function transformer(file, api, options) {
|
|
25
29
|
const j = api.jscodeshift;
|
|
@@ -38,11 +42,10 @@ const transformer = function transformer(file, api, options) {
|
|
|
38
42
|
individualPrefix: '@react-stately/'
|
|
39
43
|
}
|
|
40
44
|
};
|
|
41
|
-
const selectedPackages = options?.packages?.split(',').filter(
|
|
42
|
-
Object.keys(packages);
|
|
45
|
+
const selectedPackages = options?.packages?.split(',').filter(pkg => packages[pkg]) || Object.keys(packages);
|
|
43
46
|
let anyIndexFound = false;
|
|
44
47
|
const monopackageExports = {};
|
|
45
|
-
selectedPackages.forEach(
|
|
48
|
+
selectedPackages.forEach(pkg => {
|
|
46
49
|
let indexPath;
|
|
47
50
|
try {
|
|
48
51
|
let pkgPath = path.dirname(Module.findPackageJSON(packages[pkg].monopackage, url.pathToFileURL(file.path || `${process.cwd()}/index`)));
|
|
@@ -60,8 +63,8 @@ const transformer = function transformer(file, api, options) {
|
|
|
60
63
|
const indexRoot = j(indexFile);
|
|
61
64
|
monopackageExports[pkg] = [];
|
|
62
65
|
// Collect all named exports from the monopackage index file
|
|
63
|
-
indexRoot.find(j.ExportNamedDeclaration).forEach(
|
|
64
|
-
path.node.specifiers?.forEach(
|
|
66
|
+
indexRoot.find(j.ExportNamedDeclaration).forEach(path => {
|
|
67
|
+
path.node.specifiers?.forEach(specifier => {
|
|
65
68
|
monopackageExports[pkg].push(specifier.exported.name);
|
|
66
69
|
});
|
|
67
70
|
});
|
|
@@ -72,8 +75,8 @@ const transformer = function transformer(file, api, options) {
|
|
|
72
75
|
type: 'Literal'
|
|
73
76
|
}
|
|
74
77
|
})
|
|
75
|
-
.forEach(
|
|
76
|
-
path.node.specifiers?.forEach(
|
|
78
|
+
.forEach(path => {
|
|
79
|
+
path.node.specifiers?.forEach(specifier => {
|
|
77
80
|
monopackageExports[pkg].push(specifier.exported.name);
|
|
78
81
|
});
|
|
79
82
|
});
|
|
@@ -86,21 +89,18 @@ const transformer = function transformer(file, api, options) {
|
|
|
86
89
|
console.warn('None of the index files for the selected packages exist. Ensure that the packages are installed.');
|
|
87
90
|
return root.toSource();
|
|
88
91
|
}
|
|
89
|
-
selectedPackages.forEach(
|
|
92
|
+
selectedPackages.forEach(pkg => {
|
|
90
93
|
// Find all imports from individual packages
|
|
91
|
-
const individualPackageImports = root
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return path.node.source.value !== '@react-spectrum/s2' && path.node.source.value?.startsWith(packages[pkg].individualPrefix);
|
|
94
|
+
const individualPackageImports = root.find(j.ImportDeclaration).filter(path => {
|
|
95
|
+
return (path.node.source.value !== '@react-spectrum/s2' &&
|
|
96
|
+
path.node.source.value?.startsWith(packages[pkg].individualPrefix));
|
|
95
97
|
});
|
|
96
98
|
if (individualPackageImports.size() === 0) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
99
101
|
// Collect all imported specifiers from individual packages that are also in the monopackage exports
|
|
100
|
-
const importedSpecifiers = individualPackageImports
|
|
101
|
-
.
|
|
102
|
-
.reduce((acc, node) => {
|
|
103
|
-
node.specifiers?.forEach((specifier) => {
|
|
102
|
+
const importedSpecifiers = individualPackageImports.nodes().reduce((acc, node) => {
|
|
103
|
+
node.specifiers?.forEach(specifier => {
|
|
104
104
|
if (monopackageExports[pkg].includes(specifier.imported.name)) {
|
|
105
105
|
acc.push(specifier);
|
|
106
106
|
}
|
|
@@ -108,15 +108,13 @@ const transformer = function transformer(file, api, options) {
|
|
|
108
108
|
return acc;
|
|
109
109
|
}, []);
|
|
110
110
|
// Remove the old imports if they are present in monopackage exports
|
|
111
|
-
individualPackageImports.forEach(
|
|
112
|
-
path.node.specifiers = path.node.specifiers?.filter(
|
|
111
|
+
individualPackageImports.forEach(path => {
|
|
112
|
+
path.node.specifiers = path.node.specifiers?.filter(specifier => !monopackageExports[pkg].includes(specifier.imported.name));
|
|
113
113
|
});
|
|
114
114
|
// Remove import declarations with no specifiers left
|
|
115
|
-
individualPackageImports
|
|
116
|
-
.filter((path) => path.node.specifiers?.length === 0)
|
|
117
|
-
.remove();
|
|
115
|
+
individualPackageImports.filter(path => path.node.specifiers?.length === 0).remove();
|
|
118
116
|
// Find existing monopackage import if it exists
|
|
119
|
-
const monopackageImport = root.find(j.ImportDeclaration).filter(
|
|
117
|
+
const monopackageImport = root.find(j.ImportDeclaration).filter(path => {
|
|
120
118
|
return path.node.source.value === packages[pkg].monopackage;
|
|
121
119
|
});
|
|
122
120
|
if (monopackageImport.size() > 0) {
|
|
@@ -124,8 +122,8 @@ const transformer = function transformer(file, api, options) {
|
|
|
124
122
|
const specifiers = existingImport.specifiers;
|
|
125
123
|
if (areSpecifiersAlphabetized(specifiers)) {
|
|
126
124
|
// If imports are sorted, add the new import in sorted order
|
|
127
|
-
importedSpecifiers.forEach(
|
|
128
|
-
const index = specifiers.findIndex(
|
|
125
|
+
importedSpecifiers.forEach(newSpecifier => {
|
|
126
|
+
const index = specifiers.findIndex(specifier => specifier.imported.name > newSpecifier.imported.name);
|
|
129
127
|
if (index === -1) {
|
|
130
128
|
specifiers.push(newSpecifier);
|
|
131
129
|
}
|
|
@@ -39,7 +39,9 @@ const parser_1 = require("@babel/parser");
|
|
|
39
39
|
const recast_1 = require("recast");
|
|
40
40
|
const t = __importStar(require("@babel/types"));
|
|
41
41
|
function getImportedName(specifier) {
|
|
42
|
-
return specifier.imported.type === 'Identifier'
|
|
42
|
+
return specifier.imported.type === 'Identifier'
|
|
43
|
+
? specifier.imported.name
|
|
44
|
+
: specifier.imported.value;
|
|
43
45
|
}
|
|
44
46
|
function getImportKey(specifier) {
|
|
45
47
|
const importedName = getImportedName(specifier);
|
|
@@ -82,7 +84,9 @@ function resolveTargetSource(candidates, uniqueSources, existingImports) {
|
|
|
82
84
|
}
|
|
83
85
|
function moduleAugmentsRouterConfig(body) {
|
|
84
86
|
for (let stmt of body.body) {
|
|
85
|
-
if (stmt.type === 'TSInterfaceDeclaration' &&
|
|
87
|
+
if (stmt.type === 'TSInterfaceDeclaration' &&
|
|
88
|
+
stmt.id.type === 'Identifier' &&
|
|
89
|
+
stmt.id.name === 'RouterConfig') {
|
|
86
90
|
return true;
|
|
87
91
|
}
|
|
88
92
|
if (stmt.type === 'ExportNamedDeclaration' &&
|
|
@@ -147,7 +151,8 @@ function transformer(file, api) {
|
|
|
147
151
|
}
|
|
148
152
|
let importedName = getImportedName(specifier);
|
|
149
153
|
let candidates = sourceMap[importedName];
|
|
150
|
-
if (candidates &&
|
|
154
|
+
if (candidates &&
|
|
155
|
+
(candidates.length === 1 || candidates[0] === `${source}/${importedName}`)) {
|
|
151
156
|
let importKind = node.importKind || 'value';
|
|
152
157
|
uniqueSources.add(importKind + ':' + candidates[0]);
|
|
153
158
|
}
|
|
@@ -156,7 +161,9 @@ function transformer(file, api) {
|
|
|
156
161
|
}
|
|
157
162
|
if (node.type === 'TSModuleDeclaration' && node.declare && node.id.type === 'StringLiteral') {
|
|
158
163
|
let mod = node.id.value;
|
|
159
|
-
if (!specifiers_1.MONOPACKAGE_ROOTS.includes(mod) ||
|
|
164
|
+
if (!specifiers_1.MONOPACKAGE_ROOTS.includes(mod) ||
|
|
165
|
+
node.body?.type !== 'TSModuleBlock' ||
|
|
166
|
+
!moduleAugmentsRouterConfig(node.body)) {
|
|
160
167
|
continue;
|
|
161
168
|
}
|
|
162
169
|
let target = `${mod}/Provider`;
|
|
@@ -225,4 +232,3 @@ function transformer(file, api) {
|
|
|
225
232
|
});
|
|
226
233
|
return didChange ? root.toSource({ quote: 'single' }) : file.source;
|
|
227
234
|
}
|
|
228
|
-
;
|
|
@@ -57,7 +57,9 @@ function getSpecifiersByPackage(from) {
|
|
|
57
57
|
if (specifier.type !== 'ExportSpecifier') {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
|
-
let exported = specifier.exported.type === 'Identifier'
|
|
60
|
+
let exported = specifier.exported.type === 'Identifier'
|
|
61
|
+
? specifier.exported.name
|
|
62
|
+
: specifier.exported.value;
|
|
61
63
|
exports[exported] ?? (exports[exported] = []);
|
|
62
64
|
if (exported.startsWith(subpath)) {
|
|
63
65
|
exports[exported].unshift(importSpecifier);
|
package/package.json
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/codemods",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"main": false
|
|
9
|
-
},
|
|
10
|
-
"engines": {
|
|
11
|
-
"node": ">=22.14.0"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"prepublishOnly": "yarn build"
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
16
8
|
},
|
|
9
|
+
"bin": "dist/index.js",
|
|
10
|
+
"source": "src/index.ts",
|
|
17
11
|
"files": [
|
|
18
12
|
"dist"
|
|
19
13
|
],
|
|
20
14
|
"type": "commonjs",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"prepublishOnly": "yarn build"
|
|
25
22
|
},
|
|
26
23
|
"dependencies": {
|
|
27
|
-
"@adobe/react-spectrum": "3.47.0",
|
|
24
|
+
"@adobe/react-spectrum": "^3.47.0",
|
|
28
25
|
"@babel/parser": "^7.24.5",
|
|
29
26
|
"@babel/traverse": "^7.24.5",
|
|
30
27
|
"@babel/types": "^7.24.5",
|
|
31
|
-
"@react-spectrum/s2": "1.
|
|
28
|
+
"@react-spectrum/s2": "1.4.0",
|
|
32
29
|
"@react-types/shared": "^3.34.0",
|
|
33
30
|
"@types/node": "^24",
|
|
34
31
|
"boxen": "^5.1.2",
|
|
@@ -41,17 +38,22 @@
|
|
|
41
38
|
},
|
|
42
39
|
"devDependencies": {
|
|
43
40
|
"@types/jscodeshift": "^0.11.11",
|
|
41
|
+
"react": "^18.0.0 || ^19.0.0-rc.1",
|
|
42
|
+
"react-dom": "^18.0.0 || ^19.0.0-rc.1",
|
|
44
43
|
"typescript": "^5.8.2"
|
|
45
44
|
},
|
|
46
45
|
"peerDependencies": {
|
|
47
46
|
"react": "^18.0.0 || ^19.0.0-rc.1",
|
|
48
47
|
"react-dom": "^18.0.0 || ^19.0.0-rc.1"
|
|
49
48
|
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.14.0"
|
|
51
|
+
},
|
|
50
52
|
"rsp": {
|
|
51
53
|
"type": "cli"
|
|
52
54
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
+
"targets": {
|
|
56
|
+
"main": false
|
|
55
57
|
},
|
|
56
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "a24af13dbea967239f9daf9c0736e6946145e045"
|
|
57
59
|
}
|