Skip to content

fix(cli): run main() when invoked via npx symlink#7

Merged
faraa2m merged 1 commit into
mainfrom
fix/cli-npx-entry-guard
May 8, 2026
Merged

fix(cli): run main() when invoked via npx symlink#7
faraa2m merged 1 commit into
mainfrom
fix/cli-npx-entry-guard

Conversation

@faraa2m
Copy link
Copy Markdown
Owner

@faraa2m faraa2m commented May 8, 2026

Summary

  • npx tokenometer <file> was a silent no-op. Entry-point guard import.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.
  • Fix: resolve the symlink with realpathSync and build the URL via pathToFileURL. Works for direct node, npm bin shims, and npx.
  • Bump all packages 0.0.1 → 0.0.2 (core, cli, web, action + workspace dep pins) so the fix can publish.

Test plan

  • node packages/cli/dist/index.js --versiontokenometer 0.0.2
  • Symlink-via-temp-dir invocation (mimics npx layout) → version + table render correctly
  • vitest run — 13/13 passing (args + render)
  • After merge: trigger the manual release workflow to publish 0.0.2, then npx -y tokenometer@0.0.2 <file> end-to-end

🤖 Generated with Claude Code

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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tokenometer Ready Ready Preview, Comment May 8, 2026 4:30pm

@faraa2m faraa2m merged commit 9ace594 into main May 8, 2026
7 checks passed
@faraa2m faraa2m deleted the fix/cli-npx-entry-guard branch May 9, 2026 04:11
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant