Skip to content

fix(cli): run main() when invoked via a symlinked bin (npx) (#427)#454

Open
dsitmilis wants to merge 1 commit into
CloakHQ:mainfrom
dsitmilis:fix/cli-npx-entry-guard
Open

fix(cli): run main() when invoked via a symlinked bin (npx) (#427)#454
dsitmilis wants to merge 1 commit into
CloakHQ:mainfrom
dsitmilis:fix/cli-npx-entry-guard

Conversation

@dsitmilis

Copy link
Copy Markdown

Summary

Fixes #427npx cloakbrowser info (and every subcommand) produced no output and exited 0. The CLI entry guard compared import.meta.url against pathToFileURL(invokedPath) but only realpathed the invoked side; under npx/pnpm-exec the bin is a symlink (node_modules/.bin/cloakbrowser -> dist/cli.js) and the two realpaths did not match, so main() never ran.

Fix

  • js/src/cli.ts: extract isCliEntry(invokedPath, metaUrl) which realpaths both sides before comparing and returns false (never auto-running main()) on any resolution error. The module-level guard now uses it.
  • js/tests/cli.test.ts: unit tests for isCliEntry — symlink resolution, missing path, unrelated file, and undefined argv[1].

Validation

  • node_modules/.bin/vitest run tests/cli.test.ts -> 6 passed.
  • End-to-end: a symlinked bin shim invoking dist/cli.js now prints CloakBrowser diagnostics (exit 0) instead of silently exiting. Importing cli.js in tests does NOT auto-run main() (the import-by-test case stays safe).
  • tsc build clean.

Closes #427.

)

The CLI entry guard compared import.meta.url directly against
pathToFileURL(invokedPath) but only realpathed the invoked side. Under
npx/pnpm-exec the bin is a symlink (node_modules/.bin/cloakbrowser -> dist/cli.js)
and the two realpaths did not match, so main() never ran and every
subcommand exited 0 with no output.

- js/src/cli.ts: extract isCliEntry(invokedPath, metaUrl) which realpaths
  BOTH sides before comparing, returning false (never auto-running) on any
  resolution error. Use it in the module-level guard.
- js/tests/cli.test.ts: unit tests for isCliEntry (symlink resolution, missing
  path, unrelated file, undefined argv[1]).

Verified: a symlinked bin shim invoking dist/cli.js now prints diagnostics
instead of silently exiting; importing cli.js in tests does not auto-run main().

Closes CloakHQ#427
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.

CLI silently exits with no output when run via npx

1 participant