fix(coding-agent): redo Bun package manager node_modules handling (#3998)
* Revert "fix(coding-agent): use alternate logic to find Bun's node_modules (#3861)"
This reverts commit c241c6d6d0. The logic
is faulty: the original strategy of looking for node_modules by asking
the package manager is not incorrect even on bun. Instead, it should
learn a different method of asking the package manager for node_modules
when the *package manager* is bun, not the *runtime*.
* feat(coding-agent): detect bun as package manager and use alternate root query
When `"npmCommand": ["bun"]` is configured in settings.json, pi fails to
start because it invokes `bun root -g`, which doesn't exist:
error: Failed to run bun root -g: error: Script not found "root"
Add a (simple) check for Bun being used as package manager, and instead
build the relative path starting from Bun's bin directory.
This commit is contained in:
@@ -153,7 +153,9 @@ When a provider requests a retry delay longer than `retry.provider.maxRetryDelay
|
||||
}
|
||||
```
|
||||
|
||||
`npmCommand` is used for all npm package-manager operations, including `npm root -g`, installs, uninstalls, and dependency installs inside git packages. Use argv-style entries exactly as the process should be launched. When `npmCommand` is configured, git package dependency installs use plain `install` to avoid npm-specific flags in wrappers or alternate package managers.
|
||||
`npmCommand` is used for all npm package-manager operations, including installs, uninstalls, and dependency installs inside git packages. Use argv-style entries exactly as the process should be launched. When `npmCommand` is configured, git package dependency installs use plain `install` to avoid npm-specific flags in wrappers or alternate package managers.
|
||||
|
||||
Normally the package manager's global modules location is queried using `root -g`. As a special case, if the first element of `npmCommand` is `"bun"`, the modules location will instead be queried with `pm bin -g`.
|
||||
|
||||
### Sessions
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import type { Readable } from "node:stream";
|
||||
import { globSync } from "glob";
|
||||
import ignore from "ignore";
|
||||
import { minimatch } from "minimatch";
|
||||
import { CONFIG_DIR_NAME, isBunRuntime } from "../config.js";
|
||||
import { CONFIG_DIR_NAME } from "../config.js";
|
||||
import { type GitSource, parseGitUrl } from "../utils/git.js";
|
||||
import { canonicalizePath, isLocalPath } from "../utils/paths.js";
|
||||
import { isStdoutTakenOver } from "./output-guard.js";
|
||||
@@ -1843,8 +1843,9 @@ export class DefaultPackageManager implements PackageManager {
|
||||
if (this.globalNpmRoot && this.globalNpmRootCommandKey === commandKey) {
|
||||
return this.globalNpmRoot;
|
||||
}
|
||||
if (isBunRuntime) {
|
||||
const binDir = this.runCommandSync("bun", ["pm", "bin", "-g"]).trim();
|
||||
const isBunPackageManager = npmCommand.command === "bun";
|
||||
if (isBunPackageManager) {
|
||||
const binDir = this.runNpmCommandSync(["pm", "bin", "-g"]).trim();
|
||||
this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules");
|
||||
} else {
|
||||
this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim();
|
||||
|
||||
Reference in New Issue
Block a user