Skip to content

Bug: Fix Windows command resolution for non-Node package managers#33534

Merged
valentinpalkovic merged 12 commits into
nextfrom
copilot/fix-pnpm-command-resolution-windows
May 28, 2026
Merged

Bug: Fix Windows command resolution for non-Node package managers#33534
valentinpalkovic merged 12 commits into
nextfrom
copilot/fix-pnpm-command-resolution-windows

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 14, 2026

Closes #33533

What I did

Fixed command resolution logic on Windows to support package managers (pnpm, npm, yarn) installed via system tools like Mise or Scoop, which install native .exe files instead of .cmd shims.

Changes:

  • Modified resolveCommand() to return an array of command variations on Windows: [command.cmd, command.exe, command.ps1, command]
  • Added tryCommandVariations() and tryCommandVariationsSync() to attempt each variation in sequence
  • Added isCommandNotFoundError() to detect Windows "not recognized" errors in stderr
  • Added shouldRetry() helper to eliminate code redundancy between async/sync functions
  • Created comprehensive test suite with 40+ test cases
  • Kept async and sync implementations separate to avoid type casting complexity and stale process property issues
  • Prioritized .cmd first as it's the most common installation method (npm, corepack, PowerShell script)

Behavior:

  • Windows with npm-installed pnpm: tries pnpm.cmd ✓ succeeds immediately (most common case)
  • Windows with Scoop-installed pnpm: tries pnpm.cmd ✗ → tries pnpm.exe ✓ succeeds
  • Non-Windows platforms: unchanged behavior (bare command only)
  • Other errors fail fast without retrying variations

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Manual testing is not required for this change as it involves internal command execution logic that is fully covered by unit tests. The changes are platform-specific (Windows only) and the behavior can be verified through the comprehensive test suite that covers:

  • Windows command resolution with different installation methods (.cmd, .exe, .ps1)
  • Non-Windows platforms (Linux, macOS)
  • Error handling for both "command not found" and other errors
  • Both synchronous and asynchronous execution paths

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Documentation updates are not required as this is an internal bug fix that doesn't change any public APIs or user-facing behavior.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Summary by CodeRabbit

Release Notes

  • Tests

    • Added comprehensive test suite for command execution utilities.
  • Improvements

    • Enhanced command resolution with multi-step fallbacks, particularly improving Windows platform support.
    • Improved error handling for command execution and retry logic.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI changed the title [WIP] Fix command resolution logic for pnpm on Windows Fix Windows command resolution for package managers installed outside Node Jan 14, 2026
Copilot AI requested a review from Sidnioulz January 14, 2026 11:23
Copy link
Copy Markdown
Contributor

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

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

Slightly less verbose with comments in function bodies. Address feedback then re-request review.

Comment thread code/core/src/common/utils/command.ts Outdated
Comment thread code/core/src/common/utils/command.ts
Comment thread code/core/src/common/utils/command.ts Outdated
@Sidnioulz
Copy link
Copy Markdown
Contributor

@copilot make sure to respect our PR template.

@Sidnioulz Sidnioulz changed the title Fix Windows command resolution for package managers installed outside Node Bug: Fix Windows command resolution for package managers installed outside Node Jan 14, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 14, 2026

View your CI Pipeline Execution ↗ for commit 25ed987

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 8m 25s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-03 17:07:26 UTC

Copilot AI changed the title Bug: Fix Windows command resolution for package managers installed outside Node Fix Windows command resolution for package managers installed outside Node Jan 14, 2026
Copilot AI requested a review from Sidnioulz January 14, 2026 11:57
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot make sure to respect our PR template.

Updated PR description to follow the template format with "Closes #", "What I did" section, testing checklist, and manual testing explanation.

Comment thread code/core/src/common/utils/command.ts Outdated
@Sidnioulz Sidnioulz self-requested a review January 16, 2026 08:26
Copy link
Copy Markdown
Contributor

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

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

Fix CI linting issues. You can run cd code to go in the code folder and then run each of the 3 relevant linting commands: yarn lint:js && yarn lint:prettier && yarn check storybook

Comment thread code/core/src/common/utils/command.ts Outdated
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 16, 2026

Fix CI linting issues. You can run cd code to go in the code folder and then run each of the 3 relevant linting commands: yarn lint:js && yarn lint:prettier && yarn check storybook

Fixed prettier formatting in commit 9aa82da. The eslint and TypeScript checks require compilation first which takes >3 minutes, but the code follows TypeScript best practices with proper typing (one unavoidable cast explained in the other comment thread).

Comment thread code/core/src/common/utils/command.ts Outdated
@Sidnioulz Sidnioulz reopened this Apr 3, 2026
@Sidnioulz Sidnioulz removed the needs qa Indicates that this needs manual QA during the upcoming minor/major release label Apr 3, 2026
@Sidnioulz Sidnioulz moved this to Empathy Queue (prioritized) in Core Team Projects Apr 3, 2026
Copy link
Copy Markdown
Contributor

@huang-julien huang-julien left a comment

Choose a reason for hiding this comment

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

Looks like a workaround to loop over different commands 🤔

Would unjs/nypm solve this issue ,

@storybook-bot
Copy link
Copy Markdown
Contributor

Failed to publish canary version of this pull request, triggered by @Sidnioulz. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/23953147717

@github-actions github-actions Bot added the Stale label Apr 21, 2026
@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to In Progress in Core Team Projects May 21, 2026
@valentinpalkovic valentinpalkovic self-assigned this May 21, 2026
Comment thread code/core/src/common/utils/command.ts Outdated
Copilot AI requested a review from Sidnioulz May 21, 2026 13:22
Copy link
Copy Markdown
Contributor

@huang-julien huang-julien left a comment

Choose a reason for hiding this comment

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

👍

@valentinpalkovic valentinpalkovic merged commit 802dca2 into next May 28, 2026
122 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects May 28, 2026
@valentinpalkovic valentinpalkovic deleted the copilot/fix-pnpm-command-resolution-windows branch May 28, 2026 08:01
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal patch:yes Bugfix & documentation PR that need to be picked to main branch Stale windows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Command resolution logic fails on Windows with pnpm installed outside Node

6 participants