Skip to content

[rush] PNPM Overrides with more advanced syntax will cause Rush to always complain that shrinkwrap file need to be updated #4675

Open
@kenrick95

Description

@kenrick95

Summary

Using PNPM Overrides feature with a more advanced syntax like <pkg-name>@^<ver> in the keys will cause rush install to always fail

Repro steps

At common/config/rush/pnpm-config.json, I have:

  "globalOverrides": {
    "react-router@^5": "5.3.4"
  },

At meow/package.json, I have:

{
  "dependencies": {
    "react-router": "^5.0.0"
  }
}

Then I run:

rush update
rush install

Expected result: rush install runs successfully

Actual result: rush install failed with:

Rush Multi-Project Build Tool 5.122.1 - https://rushjs.io
Node.js version is 18.20.2 (LTS)


Starting "rush install"

Validating package manager shrinkwrap file.

Trying to acquire lock for pnpm-8.15.8
Acquired lock for pnpm-8.15.8
Found pnpm version 8.15.8 in /user-path/.rush/node-v18.20.2/pnpm-8.15.8

Symlinking "/path-to-repo/common/temp/pnpm-local"
  --> "/user-path/.rush/node-v18.20.2/pnpm-8.15.8"
Transforming /path-to-repo/common/config/rush/.npmrc
  --> "/path-to-repo/common/temp/.npmrc"

Updating workspace files in /path-to-repo/common/temp
Copying "/path-to-repo/common/config/rush/pnpm-lock.yaml"
  --> "/path-to-repo/common/temp/pnpm-lock.yaml"
Copying "/path-to-repo/common/config/rush/pnpm-lock.yaml"
  --> "/path-to-repo/common/temp/pnpm-lock-preinstall.yaml"

The shrinkwrap file (pnpm-lock.yaml) contains the following issues:
  Dependencies of project "@kenrick95/meow-1" do not match the current shrinkwrap.


The shrinkwrap file (pnpm-lock.yaml) is out of date. You need to run "rush update".

Repo: https://github.com/kenrick95/rush-repro-pnpm-overrides

Details

I found that this code:

const resolvedVersion: string = this.overrides.get(importerPackageName) ?? foundDependency.version;

only handle case where importerPackageName exist exactly in the overrides map.

However, from PNPM Overrides docs, we can specify overrides like:

"bar@^2.1.0": "3.0.0"

or

"qar@1>zoo": "2"

but it seems like it is not handled when it is first implemented in the PR: #4252 ( cc @chengcyber )


As for why pnpm overrides is used, for my case, it is from migrating from a repo that plainly uses PNPM Workspaces to Rush, so naturally we'll migrate those overrides config. For this case, the intention was to make sure everyone (whether projects within same workspace or external dependencies) are on the same react-router version without changing too many codes that isn't "owned" by the "platform-level" team.


TODO: Emit an error message when someone tries to override a version of something in one of their local repo packages.

Update 2024-05-06: I saw the TODO there and it actually makes sense to throw error too... So I'm not sure whether this should be fixed by adding override parsing, or fixed by throwing error when this case occurred.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.117.8
rushVersion from rush.json? 5.122.1
useWorkspaces from rush.json? true
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? 18.20.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as intendedpriorityThe maintainers consider it to be an important issue. We should try to fix it soon.

    Type

    No type

    Projects

    Status

    Waiting for Author

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions