Skip to content

fix: resolve symlinks in entry guard so npx invocation runs main()#6

Merged
callumreid merged 2 commits into
mainfrom
fix/entry-guard
Mar 10, 2026
Merged

fix: resolve symlinks in entry guard so npx invocation runs main()#6
callumreid merged 2 commits into
mainfrom
fix/entry-guard

Conversation

@callumreid

@callumreid callumreid commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Summary

When invoked via npx, process.argv[1] is the symlink path (node_modules/.bin/coval-wizard) while import.meta.url resolves to the real file path. The strict equality check fails so main() never runs.

Fix: use realpathSync + fileURLToPath to resolve both sides before comparing.

Fixes

  • Resolve symlinks in entry guard: compare real paths of import.meta.url and process.argv[1] (using fileURLToPath + realpathSync) so main() runs when invoked via npx (where argv[1] is a symlink).
  • Guard realpathSync against empty argv when imported as a module: avoid calling realpathSync on undefined by using process.argv[1] ?? '' and catching errors so the module is safe to import.

Changes

Filename Change Type Lines
src/index.ts fix +13/-5

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

The module now imports realpathSync and fileURLToPath, resolves real filesystem paths for the current module (realSelf = realpathSync(fileURLToPath(import.meta.url))) and the first CLI argument (realArgv = realpathSync(process.argv[1] ?? '')), and compares them. If they match, main() is invoked with existing error handling; the resolution/comparison is wrapped in a try/catch, allowing normal fallthrough when path resolution fails.

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits v1.0.0 format with 'fix' type and clearly describes the main change: resolving symlinks in the entry guard to fix npx invocation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/entry-guard

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/index.ts`:
- Around line 146-148: The code calls realpathSync(process.argv[1]) unguarded
which throws if process.argv[1] is undefined or the path is missing; change the
logic in src/index.ts around realSelf/realArgv to first check/process.argv[1]
and handle errors before comparing: compute realSelf as before, then set
realArgv to null by default and, if process.argv[1] is a non-empty string,
attempt to realpathSync it inside a try/catch (or use fs.existsSync) and set
realArgv only on success; finally only perform the equality check if realArgv is
non-null. Reference symbols: realSelf, realArgv, realpathSync, fileURLToPath,
import.meta.url, process.argv[1].

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ef407c9b-268c-43e3-97ba-47433c07c809

📥 Commits

Reviewing files that changed from the base of the PR and between 6e216ad and 49dd8ec.

📒 Files selected for processing (1)
  • src/index.ts

Comment thread src/index.ts Outdated
@callumreid callumreid merged commit 68b98fd into main Mar 10, 2026
2 checks passed
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