Skip to content

Commit

Permalink
Revert "Enable all supported extensions by default in config (#770)"
Browse files Browse the repository at this point in the history
This reverts commit c8343a7.
  • Loading branch information
trivikr committed Feb 22, 2024
1 parent dedf1f5 commit b83fa48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import path from "path";
import { DEFAULT_EXTENSIONS } from "@babel/core";
import Runner from "jscodeshift/dist/Runner";

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

// Refs: https://github.com/facebook/jscodeshift/issues/582
if (!args.some((arg) => arg.startsWith("--extensions"))) {
// Explicitly add all extensions as default to avoid bug in jscodeshift.
// Refs: https://github.com/facebook/jscodeshift/blob/51da1a5c4ba3707adb84416663634d4fc3141cbb/src/Worker.js#L80
const babelExtensions = DEFAULT_EXTENSIONS.map((ext) =>
ext.startsWith(".") ? ext.substring(1) : ext
);
args.push(`--extensions=${[...babelExtensions, "ts", "tsx"].join(",")}`);
}

const disclaimerLines = [
`╔════════════════════════════════════════════════════════╗`,
`║ Please review the code change thoroughly for required ║`,
Expand Down
12 changes: 1 addition & 11 deletions src/utils/getJsCodeshiftParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { readFileSync } from "fs";
import { dirname, join } from "path";
import { DEFAULT_EXTENSIONS } from "@babel/core";
import argsParser from "jscodeshift/dist/argsParser";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -77,16 +76,7 @@ export const getJsCodeshiftParser = () =>
},
extensions: {
display_index: 3,
// Explicitly add all extensions as default to avoid bug in jscodeshift.
// Refs: https://github.com/facebook/jscodeshift/issues/582
// Source code: https://github.com/facebook/jscodeshift/blob/51da1a5c4ba3707adb84416663634d4fc3141cbb/src/Worker.js#L80
default: [
...DEFAULT_EXTENSIONS.map((ext) => (ext.startsWith(".") ? ext.substring(1) : ext)),
"ts",
"tsx",
]
.sort()
.join(","),
default: "js",
help: "transform files with these file extensions (comma separated list)",
metavar: "EXT",
},
Expand Down

0 comments on commit b83fa48

Please sign in to comment.