diff --git a/common/changes/@microsoft/rush/chao-fix-pnpm9_2024-12-13-21-43.json b/common/changes/@microsoft/rush/chao-fix-pnpm9_2024-12-13-21-43.json new file mode 100644 index 00000000000..2d13c24c385 --- /dev/null +++ b/common/changes/@microsoft/rush/chao-fix-pnpm9_2024-12-13-21-43.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix an issue in pnpm9, where a subspace is empty, the rush install fails", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 7812c840621..6fc993a929b 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -334,11 +334,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { this.overrides = new Map(Object.entries(shrinkwrapJson.overrides || {})); this.packageExtensionsChecksum = shrinkwrapJson.packageExtensionsChecksum; - // Lockfile v9 always has "." in importers filed. - this.isWorkspaceCompatible = - this.shrinkwrapFileMajorVersion >= ShrinkwrapFileMajorVersion.V9 - ? this.importers.size > 1 - : this.importers.size > 0; + this.isWorkspaceCompatible = this.importers.size > 0; this._integrities = new Map(); } @@ -355,7 +351,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (/https?:/.test(version)) { return /@https?:/.test(version) ? version : `${name}@${version}`; } else if (/file:/.test(version)) { - return /@file:/.test(version)? version : `${name}@${version}`; + return /@file:/.test(version) ? version : `${name}@${version}`; } return dependencyPath.removeSuffix(version).includes('@', 1) ? version : `${name}@${version}`; @@ -556,7 +552,8 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { private _convertLockfileV6DepPathToV5DepPath(newDepPath: string): string { if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:')) return newDepPath; const index: number = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2); - if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath)) return newDepPath; + if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath)) + return newDepPath; return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`; } @@ -570,7 +567,8 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (this.shrinkwrapFileMajorVersion >= 6) { depPath = this._convertLockfileV6DepPathToV5DepPath(packagePath); } - const pkgInfo: ReturnType = dependencyPathLockfilePreV9.parse(depPath); + const pkgInfo: ReturnType = + dependencyPathLockfilePreV9.parse(depPath); return this._getPackageId(pkgInfo.name as string, pkgInfo.version as string); } @@ -1126,7 +1124,11 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { let resolvedVersion: string = this.overrides.get(name) ?? version; // convert path in posix style, otherwise pnpm install will fail in subspace case resolvedVersion = Path.convertToSlashes(resolvedVersion); - if (specifierFromLockfile.specifier !== resolvedVersion && !isDevDepFallThrough && !isOptional) { + if ( + specifierFromLockfile.specifier !== resolvedVersion && + !isDevDepFallThrough && + !isOptional + ) { return true; } }