Skip to content

Commit

Permalink
Enable all supported extensions by default in config (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Feb 21, 2024
1 parent f29a836 commit c8343a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-peaches-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Enable all supported extensions by default in config
11 changes: 0 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// 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 @@ -41,16 +40,6 @@ 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: 11 additions & 1 deletion src/utils/getJsCodeshiftParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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 @@ -76,7 +77,16 @@ export const getJsCodeshiftParser = () =>
},
extensions: {
display_index: 3,
default: "js",
// 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(","),
help: "transform files with these file extensions (comma separated list)",
metavar: "EXT",
},
Expand Down

0 comments on commit c8343a7

Please sign in to comment.