@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user