Skip to content

Commit

Permalink
Make tsx default parser csf-2-to-3 codemod
Browse files Browse the repository at this point in the history
And don't transform storybook source code with babel when running jscodeshift
  • Loading branch information
kasperpeulen committed Dec 15, 2022
1 parent 67a0309 commit 96570de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ program
.description('Run a Storybook codemod migration on your source files')
.option('-l --list', 'List available migrations')
.option('-g --glob <glob>', 'Glob for files upon which to apply the migration', '**/*.js')
.option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser')
.option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser (default: tsx)')
.option(
'-n --dry-run',
'Dry run: verify the migration exists and show the files to which it will be applied'
Expand Down
14 changes: 12 additions & 2 deletions code/lib/codemod/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ export async function runCodemod(codemod, { glob, logger, dryRun, rename, parser
const files = await globby([glob, '!**/node_modules', '!**/dist']);
logger.log(`=> Applying ${codemod}: ${files.length} files`);
if (!dryRun) {
const parserArgs = inferredParser ? ['--parser', inferredParser] : [];
const parserArgs = ['--parser', inferredParser ?? 'tsx'];
spawnSync(
'npx',
['jscodeshift', '-t', `${TRANSFORM_DIR}/${codemod}.js`, ...parserArgs, ...files],
[
'jscodeshift',
// this makes sure codeshift doesn't transform our own source code with babel
// which is faster, and also makes sure the user won't see babel messages such as:
// [BABEL] Note: The code generator has deoptimised the styling of repo/node_modules/prettier/index.js as it exceeds the max of 500KB.
'--no-babel',
'-t',
`${TRANSFORM_DIR}/${codemod}.js`,
...parserArgs,
...files,
],
{
stdio: 'inherit',
shell: true,
Expand Down
2 changes: 2 additions & 0 deletions code/lib/codemod/src/transforms/csf-2-to-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,6 @@ function transform({ source }: { source: string }, api: any, options: { parser?:
});
}

export const parser = 'tsx';

export default transform;

0 comments on commit 96570de

Please sign in to comment.