-
Notifications
You must be signed in to change notification settings - Fork 607
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
[rush-lib] Support pnpm lockfile v9 #5009
Conversation
@microsoft-github-policy-service agree |
8111dd3
to
28db14d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together! I'll take a closer look, hopefully tomorrow.
It'd also be good to get some more eyes on this. @octogonz, @dmichon-msft, @D4N14L?
common/changes/@microsoft/rush/feature-support_pnpmv9_2024-11-19-08-24.json
Outdated
Show resolved
Hide resolved
4d3d410
to
2cd17d5
Compare
common/changes/@rushstack/lockfile-explorer/feature-support_pnpmv9_2024-11-25-14-05.json
Outdated
Show resolved
Hide resolved
libraries/rush-lib/src/logic/pnpm/PnpmShrinkWrapFileConverters.ts
Outdated
Show resolved
Hide resolved
2cd17d5
to
21a7a65
Compare
@fzxen it is great to see support for pnpm v9 coming! I tested the changes against our repo which is not using workspaces. It reported an error:
I ran this github workflow. Do you have any insights? |
21a7a65
to
91f2e9f
Compare
I took a deep look. Lockfile v9 has a breaking change that I have ignored, namely that In the following example, The key of "packages" field is always in the format of "name@version", but the "version" field is missing the "name" information, which causes rush to be unable to obtain package data. importers:
.:
dependencies:
'project1':
specifier: file:./projects/project1
version: file:projects/project1
packages:
project1@file:projects/project1:
resolution: {directory: projects/project1, type: directory}
I have fixed this issue on my branch, you can try again. |
91f2e9f
to
c7bbff2
Compare
@fzxen Thanks a lot! Yes the latest version of your feature branch and |
I've published a prerelease as version 5.143.0-pr5009.0. If that looks good in a few repos, we'll merge this in and publish it as a regular release. |
c7bbff2
to
ff02844
Compare
I tried 5.143.0-pr5009.1 on Azure/azure-sdk-for-js@main...pnpm-9.14.2.
We pin this chai version in common-versions.json https://github.com/Azure/azure-sdk-for-js/blob/c2b7ebafb3919daa306a895d42a910c7fa8530aa/common/config/rush/common-versions.json#L19 |
@fzxen - can you investigate @jeremymeng's issue? |
@fzxen - Seeing issues here too: microsoft/tsdoc#430. Looks like this breaks non-workspaces projects. |
Alright, I'll take a look in the next few days. |
ff02844
to
d9efedb
Compare
@jeremymeng I found the cause of this issue and fixed it on my branch. This issue will only affect non-workspaces projects. |
@iclanton This error seems to be caused by an incorrect |
The latest version of this branch has been published as |
@jeremymeng's repo looks good, so I'm going to go ahead and merge this. |
Thanks @fzxen! |
Thanks @fzxen! |
Thanks a lot @fzxen!! |
Note that pnpm 9 makes |
Great to see support being added for pnpm v9! Unfortunately it looks like Here are the exact steps I took: $ nvm use 20
$ npm install --global @microsoft/rush
$ git clone https://github.com/microsoft/rushstack
$ cd rushstack
$ git config --local user.name "Vellu Luoto"
$ git config --local user.email "[email protected]"
$ rush update
$ rush build
$ rush publish --pack --include-all --publish Global installation from tarball: $ nvm use 22
$ npm install --global /absolute/path/to/rushstack/common/temp/artifacts/packages/rushstack-lockfile-explorer-1.7.11.tgz Verifying it's actually the one with @pnpm/dependency-path-lockfile-pre-v9: $ npm --global list @rushstack/lockfile-explorer
/Users/vluoto/.nvm/versions/node/v22.11.0/lib
└── @rushstack/[email protected]
$ cat /Users/vluoto/.nvm/versions/node/v22.11.0/lib/node_modules/@rushstack/lockfile-explorer/package.json | grep @pnpm/dependency-path-lockfile-pre-v9
"@pnpm/dependency-path-lockfile-pre-v9": "npm:@pnpm/dependency-path@~2.1.2", And here's the error this resulted in: $ lockfile-explorer
Rush Lockfile Explorer 1.7.12 - https://lfx.rushstack.io/
App launched on http://localhost:8091
/Users/vluoto/.nvm/versions/node/v22.11.0/lib/node_modules/@rushstack/lockfile-explorer/lib/utils/shrinkwrap.js:65
throw new Error('The current lockfile version is not supported.');
^
Error: The current lockfile version is not supported.
at getShrinkwrapFileMajorVersion (/Users/vluoto/.nvm/versions/node/v22.11.0/lib/node_modules/@rushstack/lockfile-explorer/lib/utils/shrinkwrap.js:65:15)
at /Users/vluoto/.nvm/versions/node/v22.11.0/lib/node_modules/@rushstack/lockfile-explorer/lib/cli/explorer/ExplorerCommandLineParser.js:109:95
Node.js v22.11.0 |
Summary
pnpm lockfile v9 have some breaking changes on the lockfile format. Rush cannot parse pnpm lockfile v9 correctly with latest version.
After i execute
rush install
orrush update
with pnpm v9, the content of.rush/temp/shrinkwrap-deps.json
is not correct. It may break rush cache system.The expected output should correctly display the hash of each dependency., but actually:
Details
pnpm have some breaking changes on lockfile v9 format.
importers['.']
.slolution to 1:
Rush will load the lockfile and parse the information in the lockfile by itself.
rushstack/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts
Lines 318 to 347 in 3c6117e
To ensure consistency with pnpm's parsing logic, I copied the relevant logic from
@pnpm/lockfile.fs
toPnpmshrinwrapFileConverters.ts
.The
convertLockfileV9ToLockfileObject
method will automatically merge the snapshots field information into the packages field.solution to 2:
In the
PnpmShrinkwrapFile.loadFromString
method, readimporters['.'].dependencies
instead of top-level dependencies.solution to 3:
rush try to parse an encoded pnpm dependency key in parsePnpmDependencyKey method. However, the logic here is no longer applicable to lockfile v9. For example, lockfile v9 will not add a
/
prefix in the specifier field.rushstack/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts
Lines 188 to 198 in 3c6117e
Summary of changes to specifier in lockfile v9:
https:
.<PACKAGE_NAME>@
if resolved package name is not same as dependency name in package.jsonIt is difficult to maintain those complex regular expressions in the original function. Therefore, I added a new function named as
parsePnpm9DependencyKey
. It will be called when the expressionshrinkwrapFileMajorVersion >= 9
is true in runtime.This MR will not cause any breaking changes. But, pnpm9 and rush subspaces still cannot work together, because pnpm-sync not support pnpm9 yet. tiktok/pnpm-sync#37
I tried use commonly rush command in my own project.
rush install/update
-> The content ofshrinkwrap-deps.json
file is correct.rush build
-> Build cache and Cobuild work as expected.I added some unit test cases in
PnpmShrinkwrapFile.test.ts
andShrinkwrapFile.test.ts
.At the same time, unit tests have also been added for the
PnpmShrinkWrapFileConverters.ts
file.