Skip to content

Commit

Permalink
fix: Ensure jscodeshift can be executed (#210)
Browse files Browse the repository at this point in the history
* Add smoke test for being able to run jscodeshift

* f

* fix: Ensure jscodeshift can be executed
  • Loading branch information
eps1lon committed Mar 26, 2023
1 parent 4f128b9 commit a47bd09
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/nervous-bulldogs-scream.md
@@ -0,0 +1,7 @@
---
"types-react-codemod": patch
---

Ensure jscodeshift can be executed

Fixes `/usr/bin/env: ‘node\r’: No such file or directory`
1 change: 1 addition & 0 deletions bin/__tests__/__fixtures__/smoke-test/index.ts
@@ -0,0 +1 @@
export const version = 0;
9 changes: 9 additions & 0 deletions bin/__tests__/types-react-codemod.js
Expand Up @@ -49,4 +49,13 @@ describe("types-react-codemod", () => {
const { stdout } = await execTypesReactCodemod("--version");
expect(stdout.trim()).toBe(version);
});

test("can execute jscodeshift", async () => {
const fixture = path.resolve(__dirname, "./__fixtures__/smoke-test");
// Does't matter which transform as long as it is one that doesn't change code in the fixture
const { stderr } = await execTypesReactCodemod(`context-any ${fixture}`);

// Everything ok
expect(stderr).toMatchInlineSnapshot(`""`);
});
});
6 changes: 4 additions & 2 deletions bin/types-react-codemod.cjs
Expand Up @@ -56,7 +56,9 @@ async function main() {
const { codemod, dry, paths, verbose } = argv;

// TODO: npx instead?
const jscodeshiftExecutable = require.resolve(".bin/jscodeshift");
const jscodeshiftExecutable = require.resolve(
"jscodeshift/bin/jscodeshift.js"
);

/**
* @type {string[]}
Expand Down Expand Up @@ -115,7 +117,7 @@ async function main() {

args.push(...paths);

const command = `${jscodeshiftExecutable} ${args.join(" ")}`;
const command = `node ${jscodeshiftExecutable} ${args.join(" ")}`;
console.info(`executing "${command}"`);
childProcess.execSync(command, { stdio: "inherit" });
}
Expand Down
4 changes: 1 addition & 3 deletions jest.config.js
Expand Up @@ -156,9 +156,7 @@ const config = {
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
testPathIgnorePatterns: ["/node_modules/", "/__fixtures__/"],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
Expand Down

0 comments on commit a47bd09

Please sign in to comment.