From ed78c5f59f182f88c022b2a9ef2d7ac96adf4e3a Mon Sep 17 00:00:00 2001 From: Chao Guo <10736839+g-chao@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:42:28 -0800 Subject: [PATCH 1/3] fix: support empty subspace in pnpm9 --- .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 7812c840621..026bc04a4ec 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -337,7 +337,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { // Lockfile v9 always has "." in importers filed. this.isWorkspaceCompatible = this.shrinkwrapFileMajorVersion >= ShrinkwrapFileMajorVersion.V9 - ? this.importers.size > 1 + ? this.importers.size >= 1 : this.importers.size > 0; this._integrities = new Map(); @@ -355,7 +355,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 +556,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 +571,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 +1128,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; } } From bc6d58de4bf4a1a7dafe0b01a08867ebdf90ac13 Mon Sep 17 00:00:00 2001 From: Chao Guo <10736839+g-chao@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:44:09 -0800 Subject: [PATCH 2/3] chore: rush change --- .../rush/chao-fix-pnpm9_2024-12-13-21-43.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/chao-fix-pnpm9_2024-12-13-21-43.json 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 From 2ffe13f9c4ee50a7da8892e8390bf6e32991bf51 Mon Sep 17 00:00:00 2001 From: Chao Guo <10736839+g-chao@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:41:04 -0800 Subject: [PATCH 3/3] chore: address the PR comments --- libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 026bc04a4ec..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(); }