Skip to content

Commit 9b6cca7

Browse files
authored
Explicitly pass all extensions by default when calling jscodeshift (#767)
1 parent 151b5f4 commit 9b6cca7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

.changeset/nice-windows-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Explicitly pass all extensions by default when calling jscodeshift

src/cli.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2525
// @ts-nocheck
2626
import path from "path";
27+
import { DEFAULT_EXTENSIONS } from "@babel/core";
2728
import Runner from "jscodeshift/dist/Runner";
2829

2930
import {
@@ -40,6 +41,16 @@ if (args[2] === "--help" || args[2] === "-h") {
4041
process.stdout.write(getHelpParagraph(transforms));
4142
}
4243

44+
// Refs: https://github.com/facebook/jscodeshift/issues/582
45+
if (!args.some((arg) => arg.startsWith("--extensions"))) {
46+
// Explicitly add all extensions as default to avoid bug in jscodeshift.
47+
// Refs: https://github.com/facebook/jscodeshift/blob/51da1a5c4ba3707adb84416663634d4fc3141cbb/src/Worker.js#L80
48+
const babelExtensions = DEFAULT_EXTENSIONS.map((ext) =>
49+
ext.startsWith(".") ? ext.substring(1) : ext
50+
);
51+
args.push(`--extensions=${[...babelExtensions, "ts", "tsx"].join(",")}`);
52+
}
53+
4354
const disclaimerLines = [
4455
`╔════════════════════════════════════════════════════════╗`,
4556
`║ Please review the code change thoroughly for required ║`,

0 commit comments

Comments
 (0)