diff --git a/eslint.config.mjs b/eslint.config.mjs index d7c27a8dbee..5bc31d6cf6c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -60,7 +60,8 @@ export default [{ "packages/dev/storybook-builder-parcel/*", "packages/dev/storybook-react-parcel/*", "packages/dev/s2-docs/pages/**", - "packages/dev/mcp/*/dist" + "packages/dev/mcp/*/dist", + "packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/**" ], }, ...compat.extends("eslint:recommended"), { plugins: { @@ -533,4 +534,4 @@ export default [{ ...globals.browser } } -}]; \ No newline at end of file +}]; diff --git a/packages/dev/codemods/package.json b/packages/dev/codemods/package.json index 432b48facc1..5e7a927b54e 100644 --- a/packages/dev/codemods/package.json +++ b/packages/dev/codemods/package.json @@ -21,6 +21,7 @@ "url": "https://github.com/adobe/react-spectrum" }, "dependencies": { + "@adobe/react-spectrum": "^3.46.2", "@babel/parser": "^7.24.5", "@babel/traverse": "^7.24.5", "@babel/types": "^7.24.5", diff --git a/packages/dev/codemods/src/index.ts b/packages/dev/codemods/src/index.ts index 3bb350ba739..e6859e47d7d 100644 --- a/packages/dev/codemods/src/index.ts +++ b/packages/dev/codemods/src/index.ts @@ -35,7 +35,14 @@ export interface S1ToS2CodemodOptions extends JSCodeshiftOptions { * An optional subset of components to have the s1-to-s2 codemod apply to. * Provide a comma-separated list of component names. */ - components?: string + components?: string, + /** + * Whether to run the codemod in agent mode, which skips interactive prompts + * and package installation. This matches the shipped CLI behavior. + * + * @default false + */ + agent?: boolean } export interface UseMonopackagesCodemodOptions extends JSCodeshiftOptions { @@ -67,6 +74,9 @@ const options = { }, 'components': { type: 'string' + }, + 'agent': { + type: 'boolean' } }; @@ -80,22 +90,24 @@ if (positionals.length < 1) { process.exit(1); } -const codemodName = positionals[0]; -const codemodFunction = codemods[codemodName]; +async function main() { + const codemodName = positionals[0]; + const codemodFunction = codemods[codemodName]; -if (!codemodFunction) { - console.error(`Unknown codemod: ${codemodName}, available codemods: ${Object.keys(codemods).join(', ')}`); - process.exit(1); -} + if (!codemodFunction) { + console.error(`Unknown codemod: ${codemodName}, available codemods: ${Object.keys(codemods).join(', ')}`); + process.exit(1); + } -try { - codemodFunction({ + await Promise.resolve(codemodFunction({ parser: 'tsx', ignorePattern: '**/node_modules/**', path: '.', ...values - }); -} catch (error) { + })); +} + +main().catch((error) => { console.error(`Error running codemod: ${error}`); process.exit(1); -} +}); diff --git a/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/package.fixture.json b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/package.fixture.json new file mode 100644 index 00000000000..edb334cd571 --- /dev/null +++ b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/package.fixture.json @@ -0,0 +1,7 @@ +{ + "name": "s1-to-s2-cli-fixture", + "private": true, + "devDependencies": { + "parcel": "^2.12.0" + } +} diff --git a/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/App.tsx b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/App.tsx new file mode 100644 index 00000000000..52665e97a53 --- /dev/null +++ b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/App.tsx @@ -0,0 +1,10 @@ +import {Button} from '@adobe/react-spectrum'; +import React from 'react'; + +export function App() { + return ( + + ); +} diff --git a/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/Form.tsx b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/Form.tsx new file mode 100644 index 00000000000..057d14955fb --- /dev/null +++ b/packages/dev/codemods/src/s1-to-s2/__testfixtures__/cli/full-project/input/src/Form.tsx @@ -0,0 +1,6 @@ +import React from 'react'; +import {TextArea} from '@adobe/react-spectrum'; + +export function Form() { + return