Skip to content

[rush-lib] Support pnpm lockfile v9 #5009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/lockfile-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"js-yaml": "~3.13.1",
"open": "~8.4.0",
"update-notifier": "~5.1.0",
"@pnpm/dependency-path": "~2.1.2",
"@pnpm/dependency-path-lockfile-pre-v9": "npm:@pnpm/dependency-path@~2.1.2",
"semver": "~7.5.4",
"@rushstack/rush-sdk": "workspace:*",
"@rushstack/ts-command-line": "workspace:*"
Expand Down
6 changes: 3 additions & 3 deletions apps/lockfile-explorer/src/utils/shrinkwrap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import * as dp from '@pnpm/dependency-path';
import * as dependencyPathLockfilePreV9 from '@pnpm/dependency-path-lockfile-pre-v9';

interface IPackageInfo {
name: string;
Expand All @@ -12,7 +12,7 @@ interface IPackageInfo {
export function convertLockfileV6DepPathToV5DepPath(newDepPath: string): string {
if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:')) return newDepPath;
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2);
if (newDepPath.includes('(') && index > dp.indexOfPeersSuffix(newDepPath)) return newDepPath;
if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath)) return newDepPath;
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`;
}

Expand All @@ -21,7 +21,7 @@ export function parseDependencyPath(shrinkwrapFileMajorVersion: number, newDepPa
if (shrinkwrapFileMajorVersion === 6) {
dependencyPath = convertLockfileV6DepPathToV5DepPath(newDepPath);
}
const packageInfo = dp.parse(dependencyPath);
const packageInfo = dependencyPathLockfilePreV9.parse(dependencyPath);
return {
name: packageInfo.name as string,
peersSuffix: packageInfo.peersSuffix,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Support pnpm lockfile v9, which is used by default starting in pnpm v9.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/lockfile-explorer",
"comment": "",
"type": "none"
}
],
"packageName": "@rushstack/lockfile-explorer"
}
4 changes: 4 additions & 0 deletions common/config/rush/nonbrowser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
"name": "@pnpm/logger",
"allowedCategories": [ "libraries" ]
},
{
"name": "@pnpm/lockfile.types",
"allowedCategories": [ "libraries" ]
},
{
"name": "@redis/client",
"allowedCategories": [ "libraries" ]
Expand Down
49 changes: 43 additions & 6 deletions common/config/subspaces/build-tests-subspace/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "a3198248beff4dfe8ef9d9c798b873ead75ef5cd",
"pnpmShrinkwrapHash": "bd75fc59a5df40deec1cf3db51e99ab1a7eb35f6",
"preferredVersionsHash": "ce857ea0536b894ec8f346aaea08cfd85a5af648",
"packageJsonInjectedDependenciesHash": "35920c267d4a49b8de4b78d88cf91c7f46b83ebb"
"packageJsonInjectedDependenciesHash": "3f1f7f2e64fc15d64eef6c0311adc38dff344509"
}
56 changes: 51 additions & 5 deletions common/config/subspaces/default/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/subspaces/default/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "387d2507a3b0dee1dd0ca694ced243f0edaa0dc1",
"pnpmShrinkwrapHash": "7b913e5ca364b30654436bba1a36ea570496f25c",
"preferredVersionsHash": "ce857ea0536b894ec8f346aaea08cfd85a5af648"
}
4 changes: 3 additions & 1 deletion libraries/rush-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"license": "MIT",
"dependencies": {
"@pnpm/dependency-path": "~2.1.2",
"@pnpm/dependency-path-lockfile-pre-v9": "npm:@pnpm/dependency-path@~2.1.2",
"@pnpm/dependency-path": "~5.1.7",
"@pnpm/link-bins": "~5.3.7",
"@rushstack/heft-config-file": "workspace:*",
"@rushstack/lookup-by-path": "workspace:*",
Expand Down Expand Up @@ -66,6 +67,7 @@
"pnpm-sync-lib": "0.2.9"
},
"devDependencies": {
"@pnpm/lockfile.types": "~1.0.3",
"@pnpm/logger": "4.0.0",
"local-node-rig": "workspace:*",
"@rushstack/heft-webpack5-plugin": "workspace:*",
Expand Down
22 changes: 19 additions & 3 deletions libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ export class PnpmLinkManager extends BaseLinkManager {
const pathToLocalInstallation: string = await this._getPathToLocalInstallationAsync(
tarballEntry,
absolutePathToTgzFile,
folderNameSuffix
folderNameSuffix,
tempProjectDependencyKey
);

const parentShrinkwrapEntry: IPnpmShrinkwrapDependencyYaml | undefined =
Expand Down Expand Up @@ -289,7 +290,8 @@ export class PnpmLinkManager extends BaseLinkManager {
private async _getPathToLocalInstallationAsync(
tarballEntry: string,
absolutePathToTgzFile: string,
folderSuffix: string
folderSuffix: string,
tempProjectDependencyKey: string
): Promise<string> {
if (this._pnpmVersion.major === 6) {
// PNPM 6 changed formatting to replace all ':' and '/' chars with '+'. Additionally, folder names > 120
Expand Down Expand Up @@ -319,8 +321,22 @@ export class PnpmLinkManager extends BaseLinkManager {
folderName,
RushConstants.nodeModulesFolderName
);
} else if (this._pnpmVersion.major >= 8) {
} else if (this._pnpmVersion.major >= 9) {
const { depPathToFilename } = await import('@pnpm/dependency-path');

// project@file+projects+presentation-integration-tests.tgz_jsdom@11.12.0
// The second parameter is max length of virtual store dir, default is 120 https://pnpm.io/next/npmrc#virtual-store-dir-max-length
// TODO Read virtual-store-dir-max-length from .npmrc
const folderName: string = depPathToFilename(tempProjectDependencyKey, 120);
return path.join(
this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.pnpm',
folderName,
RushConstants.nodeModulesFolderName
);
} else if (this._pnpmVersion.major >= 8) {
const { depPathToFilename } = await import('@pnpm/dependency-path-lockfile-pre-v9');
// PNPM 8 changed the local path format again and the hashing algorithm, and
// is now using the scoped '@pnpm/dependency-path' package
// See https://github.com/pnpm/pnpm/releases/tag/v8.0.0
Expand Down
Loading
Loading