Skip to content

Commit 64aade6

Browse files
fix: use local binaries, nicer error messages
1 parent fe70777 commit 64aade6

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

.github/workflows/test-pr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
node-version: [16, 18]
12+
node-version: [16, 18, 20]
1313
steps:
1414
- uses: actions/checkout@v3
1515
- uses: actions/setup-node@v3

.github/workflows/test-push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
node-version: [16, 18]
14+
node-version: [16, 18, 20]
1515
steps:
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-node@v3

package.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
],
3535
"scripts": {
3636
"prepare": "npm run build",
37-
"build": "tsc -p tsconfig.build.json && execify --pkg --fix-shebang",
37+
"build": "tsc -p tsconfig.build.json && execify --all",
3838
"lint": "xo",
39-
"test": "listr 'tsc --noEmit' 'c8 ava'"
39+
"test": "tsc --noEmit && npm run ava",
40+
"ava": "node -e 'if (process.version.startsWith(`v20`)) process.exit(1)' && ava || npm run ava:20",
41+
"ava:20": "cross-env NODE_OPTIONS='--loader=ts-node/esm --loader=esmock --no-warnings=ExperimentalWarning' ava"
4042
},
4143
"ava": {
4244
"files": [
@@ -55,8 +57,9 @@
5557
]
5658
},
5759
"dependencies": {
58-
"execa": "^7.2.0",
59-
"get-bin-path": "^10.0.0"
60+
"execa": "^8.0.1",
61+
"get-bin-path": "^10.0.0",
62+
"log-symbols": "^5.1.0"
6063
},
6164
"devDependencies": {
6265
"@shopify/semaphore": "^3.0.2",
@@ -65,14 +68,14 @@
6568
"ava": "^5.3.1",
6669
"c8": "^8.0.1",
6770
"cross-env": "^7.0.3",
68-
"esmock": "^2.3.6",
69-
"execify-cli": "^0.1.0",
71+
"esmock": "^2.3.8",
72+
"execify-cli": "beta",
7073
"is-executable": "^2.0.1",
71-
"listr-cli": "^0.3.0",
7274
"meow": "^11.0.0",
75+
"strip-ansi": "^7.1.0",
7376
"testtriple": "^2.2.3",
7477
"ts-node": "^10.9.1",
7578
"typescript": "~5.1.6",
76-
"xo": "^0.54.2"
79+
"xo": "^0.56.0"
7780
}
7881
}

readme.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ The syntax for mapping to a source binary can be verbose. Adding the following a
141141
alias bin-path-map="bin-path dist.js:::src.ts"
142142
```
143143

144-
#### Notice
145-
146-
The feature is under-tested and the syntax is subject to change. If you have any problems or suggestings, please [file an issue](https://github.com/tommy-mitchell/bin-path-cli/issues/new).
144+
> [!NOTE]
145+
> The feature is under-tested and the syntax is subject to change. If you have any problems or suggestings, please [file an issue](https://github.com/tommy-mitchell/bin-path-cli/issues/new).
147146
148147
## Related
149148

src/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ts-node-esm
22
import process from "node:process";
3-
import { execaCommand, type ExecaError } from "execa";
3+
import { execa, type ExecaError } from "execa";
44
import { exit, tryGetBinPath, tryMapBinPath } from "./helpers.js";
55

66
// First two arguments are Node binary and this binary
@@ -24,7 +24,7 @@ if (shouldMap) {
2424
}
2525

2626
try {
27-
await execaCommand(`${binPath!}${" " + args.join(" ")}`, { stdio: "inherit" });
27+
await execa(binPath!, args, { preferLocal: true, stdio: "inherit" });
2828
} catch (error: unknown) {
2929
const potentialError = error as ExecaError | undefined;
3030

src/helpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import process from "node:process";
22
import { getBinPath } from "get-bin-path";
3+
import logSymbols from "log-symbols";
34
import type { Match } from "./types.js";
45

56
type ExitArgs = {
@@ -10,7 +11,7 @@ type ExitArgs = {
1011
/** Exit with an optional error message. */
1112
export const exit = ({ message, exitCode = 1 }: ExitArgs = {}): never => {
1213
if (message) {
13-
console.error(message);
14+
console.error(`${logSymbols.error} ${message}`);
1415
}
1516

1617
process.exit(exitCode);

test/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test("no bin", verifyCli, {
9999
fixture: "no-bin",
100100
expectations: {
101101
exitCode: 1,
102-
stderr: `No binary found. ${helpText}`,
102+
stderr: `No binary found. ${helpText}`,
103103
},
104104
});
105105

@@ -145,7 +145,7 @@ test("named binary - no default - errors", verifyCli, {
145145
fixture: "named-binaries/no-default",
146146
expectations: {
147147
exitCode: 1,
148-
stderr: `No binary found. ${helpText}`,
148+
stderr: `No binary found. ${helpText}`,
149149
},
150150
});
151151

@@ -169,15 +169,15 @@ test("handles incorrect execute permissions", verifyCli, {
169169
fixture: "bad-permissions",
170170
expectations: {
171171
exitCode: 1,
172-
stderr: "The binary could not be executed. Does it have the right permissions?",
172+
stderr: "The binary could not be executed. Does it have the right permissions?",
173173
},
174174
});
175175

176176
test("missing binary", verifyCli, {
177177
fixture: "missing-binary",
178178
expectations: {
179179
exitCode: 1,
180-
stderr: "The binary does not exist. Does it need to be built?",
180+
stderr: "The binary does not exist. Does it need to be built?",
181181
},
182182
});
183183

test/exit.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from "ava";
22
import esmock from "esmock";
3+
import stripAnsi from "strip-ansi";
34

45
type MacroArgs = [{
56
exitCode?: number;
@@ -22,7 +23,7 @@ const verifyHelper = test.macro<MacroArgs>(async (t, { exitCode = 1, message = "
2223
},
2324
import: {
2425
console: {
25-
error: (errorMessage: string) => verify(errorMessage, message, "message"),
26+
error: (errorMessage: string) => verify(stripAnsi(errorMessage), `✖ ${message}`, "message"),
2627
},
2728
},
2829
}) as typeof import("../src/helpers.js");

0 commit comments

Comments
 (0)