Skip to content

Local package.json are altered when --lockfile-only and readPackage are used together #5670

@Silic0nS0ldier

Description

@Silic0nS0ldier

pnpm version: 7.16.0

Code to reproduce the issue:

foo/package.json

{
  "name": "foo"
}

.pnpmfile.cjs

module.exports = {
  hooks: {
    readPackage(pkg, ctx) {
      pkg.dependencies = {
        lodash: "*"
      };
      return pkg;
    }
  }
}

pnpm-workspace.yaml

packages:
  - foo
  1. pnpm i --lockfile-only to generate pnpm-lock.yaml
  2. pnpm i --lockfile-only to trigger package.json mutation bug

Expected behavior:

pnpm-lock.yaml and package.json which have invalid state are updated.

Actual behavior:

pnpm-lock.yaml and all package.json modified in readPackage hook are updated with changes from readPackage.

Note that this behavioural difference is different from running pnpm install alone.

Additional information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions