fix(cli): run main() when invoked via npx symlink#7
Merged
Conversation
The entry-point guard compared `import.meta.url` against a naively
constructed `file://${process.argv[1]}`. Under `npx`, argv[1] points at
the symlink in the npx cache while import.meta.url resolves to the real
dist path, so the guard was always false and the CLI silently exited 0.
Resolve the symlink with realpathSync and convert with pathToFileURL so
the comparison matches whether the binary is invoked directly, via npm
bin shim, or via npx. Bump all packages 0.0.1 -> 0.0.2 so the fix can
ship.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
faraa2m
added a commit
that referenced
this pull request
May 11, 2026
The entry-point guard compared `import.meta.url` against a naively
constructed `file://${process.argv[1]}`. Under `npx`, argv[1] points at
the symlink in the npx cache while import.meta.url resolves to the real
dist path, so the guard was always false and the CLI silently exited 0.
Resolve the symlink with realpathSync and convert with pathToFileURL so
the comparison matches whether the binary is invoked directly, via npm
bin shim, or via npx. Bump all packages 0.0.1 -> 0.0.2 so the fix can
ship.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
npx tokenometer <file>was a silent no-op. Entry-point guardimport.meta.url === \file://${process.argv[1]}`is false under npx because argv[1] is the symlink in npx cache whileimport.meta.urlresolves to the realdist/index.js.main()` never ran, exit 0, no output.realpathSyncand build the URL viapathToFileURL. Works for directnode, npm bin shims, andnpx.Test plan
node packages/cli/dist/index.js --version→tokenometer 0.0.2vitest run— 13/13 passing (args + render)npx -y tokenometer@0.0.2 <file>end-to-end🤖 Generated with Claude Code