fix(cli): run main() when invoked via a symlinked bin (npx) (#427)#454
Open
dsitmilis wants to merge 1 commit into
Open
fix(cli): run main() when invoked via a symlinked bin (npx) (#427)#454dsitmilis wants to merge 1 commit into
dsitmilis wants to merge 1 commit into
Conversation
) 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
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
Fixes #427 —
npx cloakbrowser info(and every subcommand) produced no output and exited 0. The CLI entry guard comparedimport.meta.urlagainstpathToFileURL(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, somain()never ran.Fix
isCliEntry(invokedPath, metaUrl)which realpaths both sides before comparing and returnsfalse(never auto-runningmain()) on any resolution error. The module-level guard now uses it.isCliEntry— symlink resolution, missing path, unrelated file, and undefinedargv[1].Validation
node_modules/.bin/vitest run tests/cli.test.ts-> 6 passed.dist/cli.jsnow printsCloakBrowser diagnostics(exit 0) instead of silently exiting. Importingcli.jsin tests does NOT auto-runmain()(the import-by-test case stays safe).tscbuild clean.Closes #427.