Skip to content

fix: resolve bun.exe when npm shim is in PATH#1621

Closed
zerone0x wants to merge 1 commit intothedotmack:mainfrom
zerone0x:fix/windows-bun-npm-exe-1595
Closed

fix: resolve bun.exe when npm shim is in PATH#1621
zerone0x wants to merge 1 commit intothedotmack:mainfrom
zerone0x:fix/windows-bun-npm-exe-1595

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

@zerone0x zerone0x commented Apr 6, 2026

Summary

  • avoid returning "bun" on Windows when "where bun" only finds bun.cmd
  • resolve bun.exe from the shim location or npm global install dir
  • keep bun resolver in sync for the NPX CLI

Testing

  • not run (path resolution change only)

Fixes thedotmack#1595

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 6, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Bun detection on Windows: The tool now more reliably locates Bun installations across additional locations, including user AppData directories, and intelligently handles different executable file formats for improved compatibility with various Windows setup configurations.

Walkthrough

Both files update Windows-specific Bun binary resolution logic. Instead of returning 'bun' when where bun succeeds, they now parse the output to intelligently select the correct executable: preferring .exe, falling back to non-.cmd/.bat files, and checking sibling .exe or node_modules/bun/bin/bun.exe. Windows search paths expanded to include AppData roaming directory. Non-Windows behavior unchanged.

Changes

Cohort / File(s) Summary
Bun binary resolution on Windows
plugin/scripts/bun-runner.js, src/npx-cli/utils/bun-resolver.ts
Updated findBun()/resolveBunBinaryPath() to parse where bun command output into candidate paths instead of returning 'bun' directly. Implements fallback logic: prefer existing .exe, then non-.cmd/.bat executable, then attempt to resolve .cmd/.bat results to sibling .exe or node_modules/bun/bin/bun.exe. Added %APPDATA%/npm/node_modules/bun/bin/bun.exe to Windows-specific search candidate list.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 Windows bugs bunny used to fear,
.cmd shims caused bitter tears dear,
But now with parsing and .exe grace,
Bun finds its rightful place!
APPDATA searched, fallbacks abound,
Resolution hopping—solutions found! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: resolving bun.exe when npm shim is in PATH on Windows.
Description check ✅ Passed The description relates to the changeset, detailing the Windows-specific bun.exe resolution improvements and sync efforts across files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
plugin/scripts/bun-runner.js (2)

100-105: Minor inconsistency with bun-resolver.ts candidate paths.

The TypeScript version (bun-resolver.ts line 24) includes an additional candidate using USERPROFILE:

join(process.env.USERPROFILE || homedir(), '.bun', 'bin', 'bun.exe'),

This file omits that path. While homedir() and USERPROFILE typically resolve identically on Windows, adding it here would maintain exact parity.

📝 Suggested addition for consistency
   const bunPaths = IS_WINDOWS
     ? [
         join(homedir(), '.bun', 'bin', 'bun.exe'),
+        join(process.env.USERPROFILE || homedir(), '.bun', 'bin', 'bun.exe'),
         join(windowsAppData, 'npm', 'node_modules', 'bun', 'bin', 'bun.exe')
       ]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugin/scripts/bun-runner.js` around lines 100 - 105, The bunPaths array for
IS_WINDOWS is missing the USERPROFILE-based candidate present in
bun-resolver.ts; update the bunPaths declaration (used with IS_WINDOWS,
windowsAppData, homedir) to include a candidate that uses
process.env.USERPROFILE || homedir() joining '.bun', 'bin', 'bun.exe' so the JS
runner has identical Windows search paths as bun-resolver.ts.

58-94: Logic correctly mirrors bun-resolver.ts.

The Windows resolution logic is identical to the TypeScript version, which aligns with the PR objective to keep them in sync.

Consider future consolidation: Both files now have identical complex resolution logic. If feasible, bun-runner.js could potentially import from a shared module to avoid maintaining duplicate code. However, given that bun-runner.js is a standalone Node.js script (no build step) and needs to work independently, the current duplication is acceptable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugin/scripts/bun-runner.js` around lines 58 - 94, The Windows bun
resolution logic duplicates the implementation in bun-resolver.ts; add a short
comment immediately above the Windows-resolution block in
plugin/scripts/bun-runner.js (the section that checks IS_WINDOWS, parses
pathCheck.stdout, and searches for exeCandidate/plainCandidate/cmdCandidate)
stating that this logic intentionally mirrors bun-resolver.ts and explaining why
it must remain standalone (no build step) to prevent future maintainers from
removing or attempting to centralize it; keep the comment concise and reference
bun-resolver.ts by name.
src/npx-cli/utils/bun-resolver.ts (1)

43-44: Docstring is now inaccurate for Windows behavior.

The comment states it returns 'bun' if found in PATH, but the new Windows logic returns the full path instead. Consider updating to clarify this platform difference.

📝 Suggested docstring update
- * Returns the absolute path to the binary, `'bun'` if it is in PATH,
- * or `null` if Bun cannot be found.
+ * Returns the absolute path to the binary, `'bun'` if it is in PATH (non-Windows),
+ * the resolved `.exe` path on Windows, or `null` if Bun cannot be found.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/npx-cli/utils/bun-resolver.ts` around lines 43 - 44, Update the docstring
for the exported resolver (resolveBunPath) in src/npx-cli/utils/bun-resolver.ts
to reflect the Windows-specific behavior: describe that the function returns a
path string when Bun is found (on Windows this will be the absolute path to the
bun executable; on POSIX it will return 'bun' when using PATH or an absolute
path when resolved), and returns null if Bun cannot be found; replace the
current line "Returns the absolute path to the binary, 'bun' if it is in PATH,
or null if Bun cannot be found." with this clarified platform-aware description.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plugin/scripts/bun-runner.js`:
- Around line 100-105: The bunPaths array for IS_WINDOWS is missing the
USERPROFILE-based candidate present in bun-resolver.ts; update the bunPaths
declaration (used with IS_WINDOWS, windowsAppData, homedir) to include a
candidate that uses process.env.USERPROFILE || homedir() joining '.bun', 'bin',
'bun.exe' so the JS runner has identical Windows search paths as
bun-resolver.ts.
- Around line 58-94: The Windows bun resolution logic duplicates the
implementation in bun-resolver.ts; add a short comment immediately above the
Windows-resolution block in plugin/scripts/bun-runner.js (the section that
checks IS_WINDOWS, parses pathCheck.stdout, and searches for
exeCandidate/plainCandidate/cmdCandidate) stating that this logic intentionally
mirrors bun-resolver.ts and explaining why it must remain standalone (no build
step) to prevent future maintainers from removing or attempting to centralize
it; keep the comment concise and reference bun-resolver.ts by name.

In `@src/npx-cli/utils/bun-resolver.ts`:
- Around line 43-44: Update the docstring for the exported resolver
(resolveBunPath) in src/npx-cli/utils/bun-resolver.ts to reflect the
Windows-specific behavior: describe that the function returns a path string when
Bun is found (on Windows this will be the absolute path to the bun executable;
on POSIX it will return 'bun' when using PATH or an absolute path when
resolved), and returns null if Bun cannot be found; replace the current line
"Returns the absolute path to the binary, 'bun' if it is in PATH, or null if Bun
cannot be found." with this clarified platform-aware description.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6428f19-44a2-4303-b6f6-43fe918a0014

📥 Commits

Reviewing files that changed from the base of the PR and between 76a2729 and 5fca0c9.

📒 Files selected for processing (2)
  • plugin/scripts/bun-runner.js
  • src/npx-cli/utils/bun-resolver.ts

@thedotmack
Copy link
Copy Markdown
Owner

Closed during the April 2026 backlog cleanup. This was verified already-fixed in v12.1.1 HEAD. Please update to the latest build. If you still see the issue on current version, open a fresh ticket with repro.

@thedotmack thedotmack closed this Apr 15, 2026
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