[rush-lib] Support pnpm lockfile v9 #5009
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.