Skip to content

Commit c15c4cc

Browse files
authored
Merge pull request #18 from simple-frontend-dev/fix/exec-command
fix: exec command according to package manager
2 parents bc4a428 + 80a7d58 commit c15c4cc

8 files changed

Lines changed: 86 additions & 10 deletions

File tree

.changeset/rotten-rivers-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"simplefrontend": minor
3+
---
4+
5+
Fix exec command according to package manager

.github/workflows/quality-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run code quality lint check
3535
run: pnpm exec eslint --no-warn-ignored src
3636

37-
- name: Run integration tests
37+
- name: Run tests
3838
run: pnpm run test
3939

4040
- name: Build

src/templates/github-actions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ function getSetupSteps(agent: AgentName) {
5353
function getPrettierActionSetup(agent: AgentName) {
5454
return {
5555
name: "Run code quality format check",
56-
run: `${getExecCommand(agent)} prettier --check --ignore-unknown src`,
56+
run: getExecCommand(agent, "prettier", [
57+
"--check",
58+
"--ignore-unknown",
59+
"src",
60+
]),
5761
};
5862
}
5963

6064
function getEslintActionSetup(agent: AgentName) {
6165
return {
6266
name: "Run code quality lint check",
63-
run: `${getExecCommand(agent)} eslint --no-warn-ignored src`,
67+
run: getExecCommand(agent, "eslint", ["--no-warn-ignored", "src"]),
6468
};
6569
}
6670

src/templates/lefthook.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ function prettierPrePushHook(agent: AgentName) {
88
format: {
99
tags: "code-quality",
1010
// files: "git diff-tree --no-commit-id --name-only -r HEAD..origin/main",
11-
// run: `${getExecCommand(agent)} prettier --check --ignore-unknown {files}`,
12-
run: `${getExecCommand(agent)} prettier --check --ignore-unknown src`,
11+
// run: getExecCommand(agent, "prettier", ["--check", "--ignore-unknown", "{files}"]),
12+
run: getExecCommand(agent, "prettier", [
13+
"--check",
14+
"--ignore-unknown",
15+
"src",
16+
]),
1317
},
1418
};
1519
}
@@ -19,8 +23,8 @@ function eslintPrePushHook(agent: AgentName) {
1923
lint: {
2024
tags: "code-quality",
2125
// files: "git diff-tree --no-commit-id --name-only -r HEAD..origin/main",
22-
// run: `${getExecCommand(agent)} eslint --no-warn-ignored {files}`,
23-
run: `${getExecCommand(agent)} eslint --no-warn-ignored src`,
26+
// run: getExecCommand(agent, "eslint", ["--no-warn-ignored", "{files}"]),
27+
run: getExecCommand(agent, "eslint", ["--no-warn-ignored", "src"]),
2428
},
2529
};
2630
}

src/tests/package-manager.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect } from "vitest";
2+
import { getExecCommand } from "../utils/package-manager";
3+
4+
test("getExecCommand for prettier with pnpm", () => {
5+
const command = getExecCommand("pnpm", "prettier", [
6+
"--check",
7+
"--ignore-unknown",
8+
"src",
9+
]);
10+
expect(command).toBe("pnpm exec prettier --check --ignore-unknown src");
11+
});
12+
13+
test("getExecCommand for prettier with npm", () => {
14+
const command = getExecCommand("npm", "prettier", [
15+
"--check",
16+
"--ignore-unknown",
17+
"src",
18+
]);
19+
expect(command).toBe("npm exec prettier -- --check --ignore-unknown src");
20+
});
21+
22+
test("getExecCommand for prettier with yarn", () => {
23+
const command = getExecCommand("yarn", "prettier", [
24+
"--check",
25+
"--ignore-unknown",
26+
"src",
27+
]);
28+
expect(command).toBe("yarn exec prettier -- --check --ignore-unknown src");
29+
});
30+
31+
test("getExecCommand for prettier with bun", () => {
32+
const command = getExecCommand("bun", "prettier", [
33+
"--check",
34+
"--ignore-unknown",
35+
"src",
36+
]);
37+
expect(command).toBe("bunx prettier --check --ignore-unknown src");
38+
});
39+
40+
test("getExecCommand for eslint with pnpm", () => {
41+
const command = getExecCommand("pnpm", "eslint", ["--no-warn-ignore", "src"]);
42+
expect(command).toBe("pnpm exec eslint --no-warn-ignore src");
43+
});
44+
45+
test("getExecCommand for eslint with npm", () => {
46+
const command = getExecCommand("npm", "eslint", ["--no-warn-ignore", "src"]);
47+
expect(command).toBe("npm exec eslint -- --no-warn-ignore src");
48+
});
49+
test("getExecCommand for eslint with yarn", () => {
50+
const command = getExecCommand("yarn", "eslint", ["--no-warn-ignore", "src"]);
51+
expect(command).toBe("yarn exec eslint -- --no-warn-ignore src");
52+
});
53+
54+
test("getExecCommand for eslint with bun", () => {
55+
const command = getExecCommand("bun", "eslint", ["--no-warn-ignore", "src"]);
56+
expect(command).toBe("bunx eslint --no-warn-ignore src");
57+
});

src/utils/package-manager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ function getExactArg(agent: AgentName) {
4141
}
4242
}
4343

44-
export function getExecCommand(agent: AgentName) {
44+
export function getExecCommand(
45+
agent: AgentName,
46+
packageName: string,
47+
args: string[],
48+
): string {
4549
switch (agent) {
4650
case "bun":
47-
return "bunx";
51+
return ["bunx", packageName, ...args].join(" ");
52+
case "pnpm":
53+
return ["pnpm", "exec", packageName, ...args].join(" ");
4854
default:
49-
return `${agent} exec`;
55+
return [agent, "exec", packageName, "--", ...args].join(" ");
5056
}
5157
}
5258

0 commit comments

Comments
 (0)