Description
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
andpackages/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