[rush-lib] Support pnpm lockfile v9 #5009
Draft
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
I use the @pnpm/lockfile.fs library to load the pnpm lockfile. Ensure that the parsing logic is consistent with pnpm. The
readWantedLockfile
method will automatically merge the snapshot field information into the package field. If we need to support pnpm's git branch lockfile, only the parameters of the method need to be adjusted.solution to 2:
In the
PnpmShrinkwrapFile.loadFile
method, use importers['.'].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. 例如,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 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 added some unit test cases in
PnpmShrinkwrapFile.test.ts
andShrinkwrapFile.test.ts
.