Skip to content

Commit ec4c452

Browse files
fix(cli): fix entrypoint guard so binary executes
The current guard is the bug: `process.argv[1] === import.meta.filename` only works when you execute `node dist/cli.js` directly, not when npm runs the installed bin symlink. Switched that check to compare the real path of `argv[1]`.
1 parent f9a5392 commit ec4c452

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/cli.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
import { realpathSync } from 'node:fs';
4+
35
import cac from 'cac';
46

57
import { PACKAGE, ROLE } from './constants';
@@ -85,7 +87,20 @@ export async function main(
8587
cli.parse(['node', 'code-ollama', ...args]);
8688
}
8789

88-
// v8 ignore next 3
89-
if (process.argv[1] === import.meta.filename) {
90+
/* v8 ignore start */
91+
function isEntrypoint(argv1 = process.argv[1]): boolean {
92+
if (!argv1) {
93+
return false;
94+
}
95+
96+
try {
97+
return realpathSync(argv1) === import.meta.filename;
98+
} catch {
99+
return false;
100+
}
101+
}
102+
103+
if (isEntrypoint()) {
90104
void main();
91105
}
106+
/* v8 ignore stop */

0 commit comments

Comments
 (0)