Skip to content

Commit 0baf388

Browse files
authored
Use npm exec instead of ./node_modules/.bin (#10)
1 parent e8c453e commit 0baf388

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

.changeset/quiet-lizards-run.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+
Use npm exec instead of ./node_modules/.bin

src/__tests__/cli.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { run } from "../cli";
88
jest.mock("child_process");
99

1010
describe("cli", () => {
11-
const jscodeshiftPath = "./node_modules/.bin/jscodeshift";
11+
const verifySpawnCall = (args: string[]) => {
12+
expect(spawn).toHaveBeenCalledWith("npm", ["exec", "jscodeshift", "--", ...args], {
13+
stdio: "inherit",
14+
shell: process.platform == "win32",
15+
});
16+
};
1217

1318
afterEach(() => {
1419
jest.clearAllMocks();
@@ -23,12 +28,12 @@ describe("cli", () => {
2328
expect(process.stdout.write).toHaveBeenCalledWith(
2429
expect.stringMatching(`aws-sdk-js-codemod: ${version}`)
2530
);
26-
expect(spawn).toHaveBeenCalledWith(jscodeshiftPath, mockArgs, { stdio: "inherit" });
31+
verifySpawnCall(mockArgs);
2732
});
2833

2934
it("should pass args to jscodeshift", async () => {
3035
const mockArgs = ["random", "args", "one", "two", "three"];
3136
await run(mockArgs);
32-
expect(spawn).toHaveBeenCalledWith(jscodeshiftPath, mockArgs, { stdio: "inherit" });
37+
verifySpawnCall(mockArgs);
3338
});
3439
});

src/cli.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { spawn } from "child_process";
66
// @ts-ignore: package.json will be imported from dist folders
77
import { version } from "../package.json"; // eslint-disable-line
88

9-
const [, , ...args] = process.argv;
10-
const jscodeshiftPath = "./node_modules/.bin/jscodeshift";
11-
129
export const run = async (args): Promise<void> => {
1310
if (args[0] === "--version") {
1411
process.stdout.write(`aws-sdk-js-codemod: ${version}\n\n`);
15-
spawn(jscodeshiftPath, ["--version"], { stdio: "inherit" });
16-
} else {
17-
spawn(jscodeshiftPath, args, { stdio: "inherit" });
1812
}
13+
spawn("npm", ["exec", "jscodeshift", "--", ...args], {
14+
stdio: "inherit",
15+
shell: process.platform == "win32",
16+
});
1917
};
2018

19+
const [, , ...args] = process.argv;
20+
2121
run(args);

0 commit comments

Comments
 (0)