Commit 461fc5b
Fix bin entry-guard to handle npm symlinked invocation (v0.1.1) (#54)
Found post-publish: 0.1.0's CLI exits 0 with no output when invoked
via npm bin symlink (e.g. ./node_modules/.bin/nativeapptemplate-agent
or `npx nativeapptemplate-agent`). The pipeline never runs.
Root cause: src/index.ts entry-guard compared the wrong shapes:
if (import.meta.url === `file://${process.argv[1]}`) { main() }
- import.meta.url resolves to the actual module file URL (e.g.
file:///.../node_modules/nativeapptemplate-agent/dist/index.js)
- process.argv[1] under npm bin invocation is the symlink path
(e.g. /tmp/x/node_modules/.bin/nativeapptemplate-agent)
- The two never match, the guard fails silently, main() is never
called, the script exits with no error.
Direct `node dist/index.js` worked because both sides resolved
to the same path; symlinked bin invocation didn't, but the bug
was invisible until the package was published and tested via
`npx`.
Fix: resolve both sides to canonical (symlink-followed) paths
using realpathSync + fileURLToPath:
function isEntryPoint(): boolean {
const argv1 = process.argv[1];
if (!argv1) return false;
try {
const modulePath = fileURLToPath(import.meta.url);
const argv1Real = realpathSync(argv1);
return argv1Real === modulePath;
} catch {
return false;
}
}
Verified post-fix:
- direct invocation: `node dist/index.js "test spec"` → full
output, overall: PASS, exit 0.
- symlink invocation: ln -s dist/index.js /tmp/x/nat-bin &&
/tmp/x/nat-bin "test spec" → identical output. Confirms the
fix works for the published-package code path.
- npm run ci: 19/19 green.
Bumps version 0.1.0 -> 0.1.1 for the patch release.
Out of scope (next, manual):
- User runs `npm publish` to release 0.1.1.
- Once 0.1.1 is on the registry, deprecate 0.1.0:
`npm deprecate nativeapptemplate-agent@0.1.0 \
"Silent no-op when invoked via npm bin symlink. Use 0.1.1+."`
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1db714c commit 461fc5b
2 files changed
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments