Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pnpm add should use the default catalog #8640

@gluxon

Description

@gluxon

Contribution

Describe the user story

When running pnpm add, pnpm currently adds the latest version with of that dependency with ^. For example, running pnpm add is-positive edits package.json with the following contents:

{
  "name": "@example/lib",
  "dependencies": {
    "is-positive": "^3.1.0"
  }
}

Describe the solution you'd like

When a user has set up a default catalog entry for a dependency, it's likely that new usages of this dependency in a workspace package are intended to use the catalog protocol. Instead of adding a new version, use the catalog protocol:

{
  "name": "@example/lib",
  "dependencies": {
    "is-positive": "catalog:"
  }
}

Related: I realized we don't do this for workspace packages at the moment. It likely makes sense to add workspace:* out of the box too. (#6770)

Describe the drawbacks of your solution

Some users may prefer not using the catalog protocol out of the box, but I expect this to be exceedingly rare and somewhat defeats the purpose of catalogs.

There's a few more ambiguous cases with named catalogs though:

  • When a user has a dependency to a named catalog, should we use that?
  • When a user has a dependency in multiple named catalogs, which one should be added?
  • When a user has a default catalog and one more more named catalogs, does it still make sense to use the default catalog?

We can probably start by simply using the default catalog on pnpm add and ignoring named catalogs, but perhaps a future version prompts users if there's multiple named catalogs.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions