npm-check-updates icon indicating copy to clipboard operation
npm-check-updates copied to clipboard

ncu -i should execute npm install just once in a workspace.

Open ghdoergeloh opened this issue 2 years ago • 6 comments

  • [x] I have searched for similar issues
  • [x] I am using the latest version of npm-check-updates
  • [x] I am using node >= 14

Steps to Reproduce

  • node v16.15.1
  • npm v8.11.0

Create the following structure:

├── package.json
└── packages
    ├── a
    │   └── package.json
    └── b
        └── package.json

root package.json:

{
  "name": "ncu-bug",
  "workspaces": [
    "packages/**"
  ]
}
  • Install e.g. [email protected] in "a" as well as in "b".
  • Run ncu -i -deep in ncu-bug
  • Accept every change
  • Chhose "yes" if it asks to install.

Current Behavior

Upgrading /path/to/package/ncu-bug/package.json

No dependencies.
Upgrading /path/to/package/ncu-bug/packages/a/package.json
[====================] 1/1 100%

✔ Choose which packages to update › 

 vanillajs  ^1.0.0  →  ^1.0.1
Upgrading /path/to/package/ncu-bug/packages/b/package.json
[====================] 1/1 100%

✔ Choose which packages to update › 

 vanillajs  ^1.0.0  →  ^1.0.1

✔ npm install in each project directory to install new versions? … yes

/home/georg/.nvm/versions/node/v16.15.1/lib/node_modules/npm-check-updates/build/src/index.js:56
    throw err;
    ^
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /path/to/package/ncu-bug/node_modules/vanillajs
npm ERR! dest /path/to/package/ncu-bug/node_modules/.vanillajs-OvN89i9k
npm ERR! errno -39
npm ERR! ENOTEMPTY: directory not empty, rename '/path/to/package/ncu-bug/node_modules/vanillajs' -> '/path/to/package/ncu-bug/node_modules/.vanillajs-OvN89i9k'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/georg/.npm/_logs/2022-08-24T12_55_19_273Z-debug-0.log

(Use `node --trace-uncaught ...` to show where the exception was thrown)

Expected Behavior

It should run npm install only once in a workspace.

ghdoergeloh avatar Aug 24 '22 13:08 ghdoergeloh

I am also running into this, and as a quick fix it would be nice if a CLI option was available to avoid the auto-install prompt altogether. This way I can add a package.json script with something like this: npm-check-updates --deep --interactive --noInstall && npm install (note the imaginary --noInstall option). In the long term though, it would definitely be nice to have workspaces detected and the install command to work correctly so that I don't need to add the && npm install command myself.

sunnysingh avatar Sep 15 '22 18:09 sunnysingh

It should run npm install only once in a workspace.

@ghdoergeloh Is this literally just run npm install in the root project? Just want to confirm, as I haven't used workspaces yet myself.

raineorshine avatar Sep 16 '22 13:09 raineorshine

Workspace support added in prerelease v16.2.0-0. Open for feedback :). Your help is much appreciated in finding unidentified edge cases.

npx [email protected] --workspaces

How it works

UPDATED 2023-09-23

Upgrade all workspaces:

ncu --workspaces
ncu -ws

Upgrade a single workspace:

ncu --workspace a
ncu -w a

Upgrade more than one workspace:

ncu --workspace a --workspace b
ncu -w a -w b

Upgrade all workspaces AND the root project:

ncu --workspaces --root

Upgrade a single workspace AND the root project:

ncu --workspace a --root

Notes

  • If run in --interactive mode, ncu will prompt to npm install once in the root project rather than separately in each workspace (#1182).
  • Running --deep will not trigger workspace support.

raineorshine avatar Sep 16 '22 16:09 raineorshine

Wow you work fast @raineorshine! This worked well for me, I confirmed that --workspaces does not upgrade the root project, and --withWorkspaces does. It seems to only run npm install within the root project, but I didn't do any extensive testing here. I will keep using the prerelease version and report back if I happen to come across any issues.

sunnysingh avatar Sep 16 '22 16:09 sunnysingh

I have been using this with seemingly no problems, can I expect different behavior with the new support, and thanks!

    "update": "ncu -u -i",
    "update:workspaces": "npm exec --workspaces -- ncu -u -i",

httpete avatar Sep 16 '22 17:09 httpete

@httpete The only difference is the auto npm install in interactive mode.

  • npm exec --workspaces -- ncu -u -i prompts to run npm install after each workspace is upgraded (i.e. once for each workspace).
  • npm --workspaces -i upgrades each workspace and then prompts once at the end to run npm install in the project root.

The end result appears to be the same.

raineorshine avatar Sep 16 '22 20:09 raineorshine

Published to latest on v16.3.0.

Note that --withWorkspaces has changed to a cleaner syntax of --workspaces --root (and --withWorkspace to --workspace X --root). Thanks to @mesqueeb for the suggestion.

raineorshine avatar Sep 23 '22 17:09 raineorshine

Published to latest on v16.3.0.

Note that --withWorkspaces has changed to a cleaner syntax of --workspaces --root (and --withWorkspace to --workspace X --root). Thanks to @mesqueeb for the suggestion.

But it not working in v16.3.2.

image

imguolao avatar Sep 28 '22 06:09 imguolao

@raineorshine FYI -ws is shorthand for --workspaces, maybe you didn't enable this flag on the NCU side?

mesqueeb avatar Sep 28 '22 06:09 mesqueeb

Flags are enabled and working as expected.

raineorshine avatar Sep 28 '22 14:09 raineorshine

Is there a way to run on all except a select few workspaces when using -ws?

apetta avatar Dec 18 '23 17:12 apetta

No, they would have to be specified explicitly with -w.

raineorshine avatar Dec 18 '23 18:12 raineorshine