fix(cli): use pathToFileURL for portable main-module guard - #71
Merged
theDakshJaitly merged 3 commits intoJun 6, 2026
Merged
Conversation
Addresses review feedback on #46. Gate program.parse() on the module being the invoked script via Node's pathToFileURL helper so Windows paths and unicode segments are handled correctly. Test coverage for mex log/timeline option parsing already landed via #47; this PR carries the remaining portable main-module guard change.
Update cli-option-parsing-tests.md to reflect that src/cli.ts only auto-parses when run as the invoked script, matching the pathToFileURL guard landed in this PR.
realpathSync(process.argv[1]) so npm global/npx/node_modules/.bin symlinks match import.meta.url. Add a symlinked-bin integration test and guard against missing argv paths in test imports.
Contributor
Author
|
Re-submitted after #67 was auto-closed when a bad force-push orphaned the PR head. Symlink regression fix (addresses @theDakshJaitly's review on #67):
Verification (rebased on latest
@theDakshJaitly — ready for re-review. |
theDakshJaitly
approved these changes
Jun 6, 2026
theDakshJaitly
left a comment
Collaborator
There was a problem hiding this comment.
Approved. This is the corrected resubmit of #67 after it auto-closed on an orphaned force-push. The symlink regression is fixed (realpathSync(process.argv[1]) so symlinked bins match import.meta.url), with a try/catch when argv[1] is absent. The new symlinked-bin integration test covers the exact path that was broken and slips past direct-invocation testing. CI green on Node 20 and 22. Thanks for the quick turnaround.
3 tasks
2 tasks
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.
Addresses the remaining review feedback on #46.
Context
CLI-level test coverage for
mex log/mex timelineoption parsing already merged via #47. PR #46's review requested a portable main-module guard; this PR lands it with symlink-safe resolution for npm global / npx /node_modules/.binlayouts.Change
realpathSyncfromnode:fsandpathToFileURLfromnode:urlprogram.parse()onimport.meta.url === pathToFileURL(realpathSync(process.argv[1])).href(try/catch whenargv[1]is absent, e.g. test imports)--version) and import-without-auto-parsepatterns/cli-option-parsing-tests.mdto document the guardVerification
npx vitest run test/cli.test.ts— 13/13 passingnpm test— 181/181 passingnpm run typecheck— passingmain(includes fix(path-checker): resolve workspace aliases and filter URLs (review fixes) #68)Closes the actionable items from @theDakshJaitly's review on #46. Supersedes accidentally closed #67 after a bad force-push orphaned the PR head.