Navigation Menu

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

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

Closed
3 tasks done
ghdoergeloh opened this issue Aug 24, 2022 · 12 comments
Closed
3 tasks done

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

ghdoergeloh opened this issue Aug 24, 2022 · 12 comments
Labels

Comments

@ghdoergeloh
Copy link

  • I have searched for similar issues
  • I am using the latest version of npm-check-updates
  • 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. vanillajs@1.0.0 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.

@sunnysingh
Copy link

sunnysingh commented Sep 15, 2022

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.

@raineorshine
Copy link
Owner

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
Copy link
Owner

raineorshine commented Sep 16, 2022

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

npx npm-check-updates@v16.2.0-0 --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

@sunnysingh
Copy link

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.

@httpete
Copy link

httpete commented Sep 16, 2022

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",

@raineorshine
Copy link
Owner

raineorshine commented Sep 16, 2022

@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
Copy link
Owner

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.

@imguolao
Copy link
Contributor

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

@mesqueeb
Copy link

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

@raineorshine
Copy link
Owner

Flags are enabled and working as expected.

@apetta
Copy link

apetta commented Dec 18, 2023

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

@raineorshine
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants