Skip to content

fix(cli): normalize argv[1] path separators for Windows compatibility#600

Open
JonnieSparkles wants to merge 2 commits intoar-io:mainfrom
JonnieSparkles:fix/windows-cli-path-separator
Open

fix(cli): normalize argv[1] path separators for Windows compatibility#600
JonnieSparkles wants to merge 2 commits intoar-io:mainfrom
JonnieSparkles:fix/windows-cli-path-separator

Conversation

@JonnieSparkles
Copy link
Copy Markdown
Contributor

@JonnieSparkles JonnieSparkles commented Mar 24, 2026

Problem

On Windows, the CLI silently exits without output when run via node lib/esm/cli/cli.js or the globally installed ar.io command. No error is thrown, nothing is printed — including --help.

The root cause is the conditional at the bottom of cli.ts that determines whether to call program.parse():

if (
  process.argv[1].includes('bin/ar.io') ||
  process.argv[1].includes('cli/cli')
) {
  program.parse(process.argv);
}

On Windows, process.argv[1] uses backslashes, e.g.:

C:\Users\jp\AppData\Roaming\npm\node_modules\@ar.io\sdk\lib\esm\cli\cli.js

Neither 'bin/ar.io' nor 'cli/cli' match because the path contains cli\cli, so program.parse() is never called and the CLI exits silently.

Fix

Normalize the path separators before the check:

const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');

if (
  normalizedArgv1.includes('bin/ar.io') ||
  normalizedArgv1.includes('cli/cli')
) {
  program.parse(process.argv);
}

Testing

Confirmed on Windows (PowerShell) that:

  • Without the fix: node lib/esm/cli/cli.js --help produces no output
  • With the fix: --help and commands like get-arns-record --name ardrive --mainnet work correctly

No impact on macOS/Linux — backslashes don't appear in those paths so the replace is a no-op.

Summary by CodeRabbit

This release includes important fixes for cross-platform compatibility.

  • Bug Fixes
    • Improved command-line interface initialization to work reliably across all operating systems by properly normalizing file path handling, ensuring consistent detection and configuration on Windows, macOS, Linux, and other platforms regardless of their specific path separator formats and conventions.

@JonnieSparkles JonnieSparkles requested a review from a team as a code owner March 24, 2026 17:15
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0354f2f5-c549-4e0d-86c2-c141329f6262

📥 Commits

Reviewing files that changed from the base of the PR and between afeb7aa and 7d79189.

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

📝 Walkthrough

Walkthrough

Modified src/cli/cli.ts to normalize process.argv[1] by converting backslashes to forward slashes, then using the normalized value in path checks instead of the original value. The control flow and target path substrings remain unchanged.

Changes

Cohort / File(s) Summary
Path Normalization
src/cli/cli.ts
Added normalized argv[1] constant that converts backslashes to forward slashes, updated downstream path checks to use normalized value for cross-platform path compatibility.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A little rabbit hops with glee,
Paths now unified, forward slash decree!
No more backslash confusion on display,
Windows and Unix agree today. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: normalizing path separators in argv[1] for Windows compatibility in the CLI module.
Description check ✅ Passed The PR description provides comprehensive context including the problem, root cause, fix implementation, and testing confirmation, though the template checklist is not explicitly completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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