Skip to content

Fix Windows npm resolution for extension installs - #85

Merged
unbraind merged 2 commits into
mainfrom
fix/windows-npm-command-resolution-20260530
May 30, 2026
Merged

unbraind merged 2 commits into
mainfrom
fix/windows-npm-command-resolution-20260530

Conversation

@unbraind

@unbraind unbraind commented May 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • fix extension package install npm subprocess resolution on Windows by using npm.cmd
  • add focused unit coverage for platform-specific npm command selection
  • record and close pm-arax with linked test evidence

Validation

  • pm test pm-arax --run --progress
  • node scripts/run-tests.mjs test -- tests/unit/extension-command.spec.ts tests/integration/cli.integration.spec.ts
  • pnpm typecheck
  • pnpm quality:static
  • node scripts/check-secrets.mjs
  • git diff --check

Context

This addresses the stale Nightly Validation failure on windows-latest Node 20 after PR #84 merged: extension npm pack/install paths failed with spawn npm ENOENT.

Summary by Sourcery

Fix cross-platform npm command resolution for extension package installs, ensuring Windows uses the correct npm shim and documenting the fix.

Bug Fixes:

  • Resolve npm subprocess failures on Windows by selecting the appropriate npm command shim for extension install operations.

Documentation:

  • Update changelog to record the Windows npm command resolution fix and link the associated internal issue.

Tests:

  • Add unit coverage to verify platform-specific npm command name resolution for extension installs.

Chores:

  • Record the pm-arax issue and history entries for the Windows npm resolution problem.

Select npm.cmd when extension package install paths invoke npm on Windows, avoiding the Nightly Validation spawn npm ENOENT failure. Add focused coverage for platform command selection and record pm-arax tracker evidence.
@sourcery-ai

sourcery-ai Bot commented May 30, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts npm command resolution for extension installs to work on Windows by introducing a platform-aware npm command helper, updates the error messaging, and adds focused unit coverage and changelog/issue artifacts for the fix.

Sequence diagram for platform-aware npm command execution in extension install

sequenceDiagram
    participant CliExtensionInstall
    participant runNpmCommand
    participant resolveNpmCommandName
    participant execFileAsync

    CliExtensionInstall->>runNpmCommand: runNpmCommand(args, cwd)
    runNpmCommand->>resolveNpmCommandName: resolveNpmCommandName(platform)
    resolveNpmCommandName-->>runNpmCommand: npmCommand
    runNpmCommand->>execFileAsync: execFileAsync(npmCommand, args, cwd)
    alt [execFileAsync succeeds]
        execFileAsync-->>runNpmCommand: stdout
        runNpmCommand-->>CliExtensionInstall: trimmed stdout
    else [execFileAsync throws]
        execFileAsync-->>runNpmCommand: error
        runNpmCommand-->>CliExtensionInstall: throw PmCliError("npm command failed: " + npmCommand + args)
    end
Loading

Flow diagram for resolveNpmCommandName platform-specific selection

flowchart TD
    A[Call resolveNpmCommandName] --> B{platform === win32}
    B -->|Yes| C[Return npm.cmd]
    B -->|No| D[Return npm]
    C --> E[runNpmCommand uses npm.cmd in execFileAsync]
    D --> E[runNpmCommand uses npm in execFileAsync]
Loading

File-Level Changes

Change Details Files
Make npm invocation for extension installs platform-aware so Windows uses npm.cmd instead of npm.
  • Introduce a resolveNpmCommandName helper that returns npm.cmd on win32 and npm otherwise, defaulting its platform parameter from process.platform.
  • Update runNpmCommand to call execFileAsync with the resolved npm command name rather than hard-coding npm.
  • Include the resolved npm command name in the PmCliError message to accurately reflect the invoked command.
src/cli/commands/extension/install-sources.ts
Add unit coverage for npm command resolution behavior.
  • Extend the extension-command.spec.ts test suite with a focused test ensuring resolveNpmCommandName returns npm.cmd for win32 and npm for non-Windows platforms.
tests/unit/extension-command.spec.ts
Document and trace the Windows npm resolution fix in project metadata.
  • Add a Fixed entry in the Unreleased section of the changelog describing the Windows npm command resolution fix and linking to the pm-arax tracking issue.
  • Introduce new history and issue tracking artifacts for pm-arax and update managed extensions metadata as part of the tracking data.
CHANGELOG.md
.agents/pm/extensions/.managed-extensions.json
.agents/pm/history/pm-arax.jsonl
.agents/pm/issues/pm-arax.toon

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@unbraind, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6e935ddf-a08a-4ef9-ad75-f30d3133e27e

📥 Commits

Reviewing files that changed from the base of the PR and between 5e42d5c and 4dbf1bd.

📒 Files selected for processing (6)
  • .agents/pm/extensions/.managed-extensions.json
  • .agents/pm/history/pm-arax.jsonl
  • .agents/pm/issues/pm-arax.toon
  • CHANGELOG.md
  • src/cli/commands/extension/install-sources.ts
  • tests/unit/extension-command.spec.ts

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.

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request resolves an issue with npm command resolution on Windows during extension package installations by introducing a platform-aware helper resolveNpmCommandName that selects npm.cmd on Windows. However, a critical issue was pointed out in the review: executing .cmd files via execFile on Windows requires the shell option to be enabled to prevent execution failures. It is recommended to apply the suggested fix to pass shell: process.platform === 'win32' to execFileAsync.

const npmCommand = resolveNpmCommandName();
try {
const result = await execFileAsync("npm", args, { cwd, encoding: "utf8" });
const result = await execFileAsync(npmCommand, args, { cwd, encoding: "utf8" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

On Windows, batch files like npm.cmd cannot be executed directly using child_process.execFile without a shell. Attempting to do so will result in a spawn npm.cmd ENOENT or EINVAL error because Windows requires cmd.exe to interpret .cmd files.

To fix this, you should pass shell: true (or shell: process.platform === 'win32') in the options when executing the command on Windows.

Suggested change
const result = await execFileAsync(npmCommand, args, { cwd, encoding: "utf8" });
const result = await execFileAsync(npmCommand, args, { cwd, encoding: "utf8", shell: process.platform === "win32" });

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b95741cdef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const npmCommand = resolveNpmCommandName();
try {
const result = await execFileAsync("npm", args, { cwd, encoding: "utf8" });
const result = await execFileAsync(npmCommand, args, { cwd, encoding: "utf8" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Invoke npm.cmd through a shell on Windows

When process.platform is win32, this now passes npm.cmd to execFileAsync, but it still does so without a shell. Node's child_process docs state that .bat/.cmd files are not executable on their own and cannot be launched with execFile() on Windows (https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows); the existing integration helper also uses shell: isWindows for npm.cmd in tests/integration/cli.integration.spec.ts. As a result, Windows extension installs that reach npm pack/npm install will continue to fail instead of fixing the reported spawn npm ENOENT path.

Useful? React with 👍 / 👎.

Run npm.cmd through shell mode on Windows for execFile compatibility and cover the shell decision in tests. Record the Gemini review follow-up and rerun pm-arax linked tests.
@unbraind

Copy link
Copy Markdown
Owner Author

Review follow-up: addressed Gemini's Windows execFile note in 4dbf1bd by running npm.cmd through shell mode on win32, with focused unit coverage and pm-arax linked tests rerun.

@unbraind
unbraind merged commit f21b648 into main May 30, 2026
13 checks passed
@unbraind
unbraind deleted the fix/windows-npm-command-resolution-20260530 branch May 30, 2026 07:37
unbraind added a commit that referenced this pull request Jul 14, 2026
… PR#564), j8z6 baseline verification

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C7MgYjKgXUkcUtA9Er3ifw
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.

1 participant