Skip to content

Commit 53247a5

Browse files
Switch to execaCommand
1 parent 77cf326 commit 53247a5

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

Diff for: src/shared/packages.test.ts

+23-24
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@ import { describe, expect, it, vi } from "vitest";
22

33
import { removeDependencies } from "./packages.js";
44

5-
const mock$ = vi.fn();
5+
const mockExecaCommand = vi.fn();
66

77
vi.mock("execa", () => ({
8-
get $() {
9-
return mock$;
8+
get execaCommand() {
9+
return mockExecaCommand;
1010
},
1111
}));
1212

1313
describe("removeDependencies", () => {
14+
it("removes all packages that already exist when all already exist", async () => {
15+
await removeDependencies(["one", "two"], {
16+
one: "1.2.3",
17+
two: "4.5.6",
18+
});
19+
20+
expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(`
21+
[
22+
[
23+
"pnpm remove one two",
24+
],
25+
]
26+
`);
27+
});
28+
1429
it("removes only packages that already exist when some don't exist", async () => {
1530
await removeDependencies(["exists", "missing"], {
1631
exists: "1.2.3",
1732
});
1833

19-
expect(mock$.mock.calls).toMatchInlineSnapshot(`
34+
expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(`
2035
[
2136
[
22-
[
23-
"pnpm remove ",
24-
"",
25-
"",
26-
],
27-
[
28-
"exists",
29-
],
30-
"",
37+
"pnpm remove exists",
3138
],
3239
]
3340
`);
@@ -42,18 +49,10 @@ describe("removeDependencies", () => {
4249
"-D",
4350
);
4451

45-
expect(mock$.mock.calls).toMatchInlineSnapshot(`
52+
expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(`
4653
[
4754
[
48-
[
49-
"pnpm remove ",
50-
"",
51-
"",
52-
],
53-
[
54-
"exists",
55-
],
56-
" -D",
55+
"pnpm remove exists -D",
5756
],
5857
]
5958
`);
@@ -62,6 +61,6 @@ describe("removeDependencies", () => {
6261
it("does nothing when no packages already exist", async () => {
6362
await removeDependencies(["missing"]);
6463

65-
expect(mock$.mock.calls).toMatchInlineSnapshot("[]");
64+
expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot("[]");
6665
});
6766
});

Diff for: src/shared/packages.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $ } from "execa";
1+
import { execaCommand } from "execa";
22

33
import { readFileSafe } from "./readFileSafe.js";
44
import { PartialPackageData } from "./types.js";
@@ -17,6 +17,8 @@ export async function removeDependencies(
1717
const present = packageNames.filter((packageName) => packageName in existing);
1818

1919
if (present.length) {
20-
await $`pnpm remove ${present}${flags ? ` ${flags}` : ""}`;
20+
await execaCommand(
21+
`pnpm remove ${present.join(" ")}${flags ? ` ${flags}` : ""}`,
22+
);
2123
}
2224
}

0 commit comments

Comments
 (0)