Skip to content

Corepack-style auto-pinning behavior with pnpm add, pnpm remove, etc? #9768

@karlhorky

Description

@karlhorky

Contribution

Describe the user story

Corepack introduced a feature called "auto-pinning" in 0.26.0, which writes the package manager version to a packageManager field in package.json:

Two things will reduce the usage of this auto-pinning feature:

Currently, pnpm auto-pins (without a hash) in packageManager in package.json on pnpm init.

For existing projects, I don't see functionality to add a packageManager field to package.json using only pnpm.

Is there any appetite for a feature to auto-pin packageManager (only if it doesn't exist) on usage of mutative commands such as:

  • pnpm add
  • pnpm remove
  • others?

(if controversial, disabled by default)

Describe the solution you'd like

package.json

{
  "dependencies": {}
}

pnpm add sharp with the package.json above will yield:

{
  "dependencies": {
    "sharp": "^0.34.3"
  },
  "packageManager": "pnpm@10.13.1"
}

Alternatives considered

A separate, focused command like pnpm pin or something, that would only write packageManager to package.json

Describe the drawbacks of your solution

Community objection to auto-pinning, such as this issue:

Describe alternatives you've considered

Manually setting packageManager in package.json using npm pkg set packageManager="pnpm@$(pnpm -v)"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions