Skip to content

Commit 1c7980b

Browse files
authored
feat(codemod): improvements to s1-to-s2 codemod (agent mode, E2E tests, more) (adobe#9754)
* fixed TabList render function children kept Item instead of converting to Tab * import cleanup: removeComponentImport was only checking the first matching import and could miss v3 imports when an @react-spectrum/s2 import appears first * dynamic import('@react-spectrum/s2') was incorrectly flagged as a v3 dynamic import * Fixed in codemod options parsing * more import fixes * add agent mode (non-interactive, run transforms only) * add e2e tests * have --components include related components * yarn.lock * update outdated links * bump @adobe/react-spectrum version * fix missing imports and remove unused * fix snapshot * yarn.lock * map illustrations to s2 illustrations
1 parent c45205e commit 1c7980b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1190
-141
lines changed

eslint.config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export default [{
6060
"packages/dev/storybook-builder-parcel/*",
6161
"packages/dev/storybook-react-parcel/*",
6262
"packages/dev/s2-docs/pages/**",
63-
"packages/dev/mcp/*/dist"
63+
"packages/dev/mcp/*/dist",
64+
"packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/**"
6465
],
6566
}, ...compat.extends("eslint:recommended"), {
6667
plugins: {
@@ -534,4 +535,4 @@ export default [{
534535
...globals.browser
535536
}
536537
}
537-
}];
538+
}];

packages/dev/codemods/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"url": "https://github.com/adobe/react-spectrum"
2222
},
2323
"dependencies": {
24+
"@adobe/react-spectrum": "^3.46.2",
2425
"@babel/parser": "^7.24.5",
2526
"@babel/traverse": "^7.24.5",
2627
"@babel/types": "^7.24.5",

packages/dev/codemods/src/index.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ export interface S1ToS2CodemodOptions extends JSCodeshiftOptions {
3535
* An optional subset of components to have the s1-to-s2 codemod apply to.
3636
* Provide a comma-separated list of component names.
3737
*/
38-
components?: string
38+
components?: string,
39+
/**
40+
* Whether to run the codemod in agent mode, which skips interactive prompts
41+
* and package installation. This matches the shipped CLI behavior.
42+
*
43+
* @default false
44+
*/
45+
agent?: boolean
3946
}
4047

4148
export interface UseMonopackagesCodemodOptions extends JSCodeshiftOptions {
@@ -67,6 +74,9 @@ const options = {
6774
},
6875
'components': {
6976
type: 'string'
77+
},
78+
'agent': {
79+
type: 'boolean'
7080
}
7181
};
7282

@@ -80,22 +90,24 @@ if (positionals.length < 1) {
8090
process.exit(1);
8191
}
8292

83-
const codemodName = positionals[0];
84-
const codemodFunction = codemods[codemodName];
93+
async function main() {
94+
const codemodName = positionals[0];
95+
const codemodFunction = codemods[codemodName];
8596

86-
if (!codemodFunction) {
87-
console.error(`Unknown codemod: ${codemodName}, available codemods: ${Object.keys(codemods).join(', ')}`);
88-
process.exit(1);
89-
}
97+
if (!codemodFunction) {
98+
console.error(`Unknown codemod: ${codemodName}, available codemods: ${Object.keys(codemods).join(', ')}`);
99+
process.exit(1);
100+
}
90101

91-
try {
92-
codemodFunction({
102+
await Promise.resolve(codemodFunction({
93103
parser: 'tsx',
94104
ignorePattern: '**/node_modules/**',
95105
path: '.',
96106
...values
97-
});
98-
} catch (error) {
107+
}));
108+
}
109+
110+
main().catch((error) => {
99111
console.error(`Error running codemod: ${error}`);
100112
process.exit(1);
101-
}
113+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "s1-to-s2-cli-fixture",
3+
"private": true,
4+
"devDependencies": {
5+
"parcel": "^2.12.0"
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Button} from '@adobe/react-spectrum';
2+
import React from 'react';
3+
4+
export function App() {
5+
return (
6+
<Button variant="cta">
7+
Save
8+
</Button>
9+
);
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import {TextArea} from '@adobe/react-spectrum';
3+
4+
export function Form() {
5+
return <TextArea isQuiet />;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# yarn lockfile v1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "s1-to-s2-cli-fixture",
3+
"private": true,
4+
"devDependencies": {
5+
"parcel": "^2.12.0"
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Button } from "@react-spectrum/s2";
2+
import React from 'react';
3+
4+
export function App() {
5+
return (<Button variant="accent">Save</Button>);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import { TextArea } from "@react-spectrum/s2";
3+
4+
export function Form() {
5+
return <TextArea />;
6+
}

0 commit comments

Comments
 (0)