fix(coding-agent): resolve pnpm global packages

Fixes #4501
This commit is contained in:
Armin Ronacher
2026-05-17 00:08:51 +02:00
parent 43d3cdd48a
commit 27a193070d
2 changed files with 123 additions and 2 deletions

View File

@@ -1221,13 +1221,14 @@ export class DefaultPackageManager implements PackageManager {
};
if (parsed.type === "npm") {
const installedPath = this.getNpmInstallPath(parsed, scope);
let installedPath = this.getNpmInstallPath(parsed, scope);
const needsInstall =
!existsSync(installedPath) ||
(parsed.pinned && !(await this.installedNpmMatchesPinnedVersion(parsed, installedPath)));
if (needsInstall) {
const installed = await installMissing();
if (!installed) continue;
installedPath = this.getNpmInstallPath(parsed, scope);
}
metadata.baseDir = installedPath;
this.collectPackageResources(installedPath, accumulator, filter, metadata);
@@ -1855,6 +1856,27 @@ export class DefaultPackageManager implements PackageManager {
return this.globalNpmRoot;
}
private getPnpmGlobalPackagePath(packageName: string): string | undefined {
const npmCommand = this.getNpmCommand();
const commandParts = [npmCommand.command, ...npmCommand.args];
const separatorIndex = commandParts.lastIndexOf("--");
const packageManagerCommand = separatorIndex >= 0 ? commandParts[separatorIndex + 1] : npmCommand.command;
const packageManagerName = packageManagerCommand
? basename(packageManagerCommand).replace(/\.(cmd|exe)$/i, "")
: "";
if (packageManagerName !== "pnpm") {
return undefined;
}
const output = this.runNpmCommandSync(["list", "-g", "--depth", "0", "--json"]);
const entries = JSON.parse(output) as Array<{ dependencies?: Record<string, { path?: string }> }>;
for (const entry of entries) {
const path = entry.dependencies?.[packageName]?.path;
if (path) return path;
}
return undefined;
}
private getNpmInstallPath(source: NpmSource, scope: SourceScope): string {
if (scope === "temporary") {
return join(this.getTemporaryDir("npm"), "node_modules", source.name);
@@ -1862,7 +1884,7 @@ export class DefaultPackageManager implements PackageManager {
if (scope === "project") {
return join(this.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
}
return join(this.getGlobalNpmRoot(), source.name);
return this.getPnpmGlobalPackagePath(source.name) ?? join(this.getGlobalNpmRoot(), source.name);
}
private getGitInstallPath(source: GitSource, scope: SourceScope): string {