Skip to content

fix(cli): use pathToFileURL for portable main-module guard - #71

Merged
theDakshJaitly merged 3 commits into
mex-memory:mainfrom
advancedresearcharray:fix/cli-main-module-guard-46
Jun 6, 2026
Merged

fix(cli): use pathToFileURL for portable main-module guard#71
theDakshJaitly merged 3 commits into
mex-memory:mainfrom
advancedresearcharray:fix/cli-main-module-guard-46

Conversation

@advancedresearcharray

@advancedresearcharray advancedresearcharray commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Addresses the remaining review feedback on #46.

Context

CLI-level test coverage for mex log / mex timeline option 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/.bin layouts.

Change

  • Import realpathSync from node:fs and pathToFileURL from node:url
  • Gate program.parse() on import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href (try/catch when argv[1] is absent, e.g. test imports)
  • Integration tests: built CLI via symlinked bin (--version) and import-without-auto-parse
  • Updated patterns/cli-option-parsing-tests.md to document the guard

Verification

Closes the actionable items from @theDakshJaitly's review on #46. Supersedes accidentally closed #67 after a bad force-push orphaned the PR head.

root and others added 3 commits June 6, 2026 19:13
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.
@advancedresearcharray

Copy link
Copy Markdown
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):

  • src/cli.ts: compare import.meta.url against pathToFileURL(realpathSync(process.argv[1])).href, with try/catch when argv[1] is absent
  • test/cli.test.ts: integration tests for symlinked-bin invocation and import-without-auto-parse
  • patterns/cli-option-parsing-tests.md: documents the realpathSync guard

Verification (rebased on latest main, head 5b062cd)

  • npm test — 181/181
  • npm run typecheck — clean

@theDakshJaitly — ready for re-review.

@theDakshJaitly theDakshJaitly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@theDakshJaitly
theDakshJaitly merged commit 9d83a1a into mex-memory:main Jun 6, 2026
2 checks passed
@advancedresearcharray
advancedresearcharray deleted the fix/cli-main-module-guard-46 branch June 10, 2026 20:03
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.

2 participants