Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm update not scoped to workspace when no package targeted #3960

Closed
1 task done
jharvey10 opened this issue Oct 28, 2021 · 4 comments
Closed
1 task done

[BUG] npm update not scoped to workspace when no package targeted #3960

jharvey10 opened this issue Oct 28, 2021 · 4 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@jharvey10
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Running an npm update in a workspaces environment is updating the deps for all workspaces unless you provide a specific package to update.

Works properly:

npm --workspace="some/workspace" update immer

Does not work properly:

npm --workspace="some/workspace" update

What it currently does:

  • Updates all dependencies across all workspaces.
  • Outputs warning messages like:
    npm WARN workspaces <my package's name> in filter set, but no workspace folder present
    

Expected Behavior

  • The npm update command should be scoped to updating only the specified workspace.
  • There should be no warning messages saying there is "no workspace folder present".

Steps To Reproduce

  • Initialize a new package
  • Create two folders, packages/first-package and packages/second-package
  • Initialize a new package in each of them
  • Update the top-level package.json to define workspaces covering these package dirs
  • npm install --workspaces --include-workspace-root immer@7 to install immer (as an example) in all three packages
  • Manually update packages/first-package/package.json to depend on "immer": "^8"
  • Manually update packages/second-package/package.json to depend on "immer": "^9"
  • npm --workspace packages/first-package update
  • Observe that first-package has been updated to use immer@8 (good)
  • Observe that second-package has been updated to use immer@9 (bad)
    Note that the manual update is irrelevant to the end result. The same behavior can be seen when simply trying to update a node module that has a newer version published on npmjs.com.

I did a little research into the code by adding some logging statements and discovered that when a command like npm install is run, the tree.inventory provided to getWorkspaceNodes has many entries in it for the node modules across the project. However, when this is called for the npm --workspace packages/first-package update command, there is only a single entry in the inventory. It maps to '', or the root of the project. I suspect this is related to the issue, but I don't know how the flow works to actually provide a tree to this function, or whose responsibility it is to ensure it is fully populated prior to the getWorkspaceNodes call.

Environment

  • OS: MacOS, GitHub Actions CI Servers (ubuntu-latest)
  • Node: v16.13.0
  • npm: 8.1.0
@jharvey10 jharvey10 added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Oct 28, 2021
@ais-one
Copy link

ais-one commented Nov 4, 2021

I also found something.

If you just do npm update

The package/s version in package-lock.json FILE will be updated, but the package/s version in package.json FILES of the workspaces with the updated package/s are not updated

I think this should actually be escalated as it has a huge impact, packages may potentially not be able to be updated properly.

@gildub
Copy link

gildub commented Nov 29, 2021

I also found something.

If you just do npm update

The package/s version in package-lock.json FILE will be updated, but the package/s version in package.json FILES of the workspaces with the updated package/s are not updated

I think this should actually be escalated as it has a huge impact, packages may potentially not be able to be updated properly.

Running npm update doesn't seems to be the same as npm update -ws or npm update --workspaces.

Effectively when I have dependencies at the top level (as opposed to any underneath workspace) which is great for sharing packages, they need to be installed with a separate npm install. A npm install -ws won't cover them.

This was initially confusing but it makes sense to apply install/update or any other command for a specific workspace or to all workspaces but that never includes the top level. I suppose it would be great to have a flag to also add the top level to avoid running a separate command.

@ais-one
Copy link

ais-one commented Nov 29, 2021 via email

@wraithgar
Copy link
Member

It looks like this was fixed. Using npm@8.8.0

npm update updates everything

~/D/n/s/ws (main|●5) $ npm ls
ws@1.0.2 /Users/wraithgar/Development/npm/scratch/ws
├── abbrev@1.0.3
├─┬ wsa@1.0.0 -> ./wsa
│ └── wsa@1.0.0 deduped -> ./wsa
└─┬ wsb@1.0.0 -> ./wsb
  ├── lodash@1.0.0
  └── wsa@1.0.0 deduped -> ./wsa

~/D/n/s/ws (main|●5) $ npm update --no-audit

added 1 package, removed 1 package, and changed 1 package in 196ms
~/D/n/s/ws (main|●5✚1) $ npm ls
ws@1.0.2 /Users/wraithgar/Development/npm/scratch/ws
├── abbrev@1.1.1
├─┬ wsa@1.0.0 -> ./wsa
│ └── wsa@1.0.0 deduped -> ./wsa
└─┬ wsb@1.0.0 -> ./wsb
  ├── lodash@1.3.1
  └── wsa@1.0.0 deduped -> ./wsa

npm update -w workspace updates just the workspace

~/D/n/s/ws (main|●5) $ npm ls
npws@1.0.2 /Users/wraithgar/Development/npm/scratch/ws
├── abbrev@1.0.3
├─┬ wsa@1.0.0 -> ./wsa
│ └── wsa@1.0.0 deduped -> ./wsa
└─┬ wsb@1.0.0 -> ./wsb
  ├── lodash@1.0.0
  └── wsa@1.0.0 deduped -> ./wsa

~/D/n/s/ws (main|●5) $ npm update -w wsb --no-audit
npm WARN workspaces wsb in filter set, but no workspace folder present

added 1 package, and removed 1 package in 204ms
~/D/n/s/ws (main|●5✚1) $ npm ls
ws@1.0.2 /Users/wraithgar/Development/npm/scratch/ws
├── abbrev@1.0.3
├─┬ wsa@1.0.0 -> ./wsa
│ └── wsa@1.0.0 deduped -> ./wsa
└─┬ wsb@1.0.0 -> ./wsb
  ├── lodash@1.3.1
  └── wsa@1.0.0 deduped -> ./wsa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

4 participants