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

Skip to content

Allow "pnpm add" command to generate "workspace:*" when adding a workspace dependency #6770

@Mufasa

Description

@Mufasa

Discussed in https://github.com/orgs/pnpm/discussions/6713

Originally posted by Mufasa June 25, 2023
I have been using npm for many years and have now started to move over to use pnpm. My initial feedback on pnpm is that it is indeed far superior to npm and I absolutely love it. However, I have spotted a strange issue which I have described below.

When I add a workspace dependency using pnpm add myWorkspaceLibA --workspace --filter myWorkspaceLibB, pnpm generates this in myWorkspaceLibB's package.json file:

"dependencies": {
    ...
    "myWorkspaceLibA": "workspace:^",
    ...
  },

It also generates this in the root pnpm-lock.yaml file:

  packages/myWorkspaceLibB:
    dependencies:
      'myWorkspaceLibA':
        specifier: workspace:^
        version: link:../myWorkspaceLibA

From the various articles and videos that I have seen on this, I understand that after running the pnpm add command I should change the package.json entry in myWorkspaceLibB to:

"dependencies": {
    ...
    "myWorkspaceLibA": "workspace:*",
    ...
  },

in order to ensure that it always picks up the latest version of myWorkspaceLibA in my monorepo.

However, this leaves the pnpm-lock.yaml file inconsistent with the package.json file.

I have the following questions on this:

  1. Does this matter (i.e. will this cause some unexpected behaviour in some future commands that I may run)?
  2. Should I also update the pnpm-lock.yaml file to make it consistent with the package.json file?

My gut feeling tells me that it is not a good idea for me to be manually changing the pnpm-lock.yaml file. I would therefore like to suggest that the pnpm add command be enhanced in some way so that it automagically sets workspace:* in both the package.json and pnpm-lock.yaml files.

Is this a reasonable request or have I misunderstood something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions