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

Feature Request - Support Workspaces -w / --workspace=(PATH|PROJECT_NAME) #1099

Closed
metawrap-dev opened this issue Apr 27, 2022 · 11 comments
Closed

Comments

@metawrap-dev
Copy link

Feature Request - Support Workspaces -w / --workspace=(PATH|PROJECT_NAME)

Upgrade all workspaces

ncu -u --workspace=modules/*
ncu -u -w=*

Upgrade just one workspace,

ncu -u --workspace=@metawrap/metawrap-core
ncu -u --workspace=modules//metawrap-core
ncu -u -w=@metawrap/metawrap-core

See:

https://docs.npmjs.com/cli/v7/using-npm/workspaces#running-commands-in-the-context-of-workspaces

@raineorshine
Copy link
Owner

raineorshine commented Apr 27, 2022

Thanks for the suggestion!

Is the proposed ncu -u -w=* any different than ncu -u --deep?

Is the proposed ncu -u -w=@metawrap/metawrap-core any different than ncu -u --packageFile modules/@metawrap/metawrap-core/package.json?

Trying to clarify if this is more of an alias or a new feature.

@raineorshine
Copy link
Owner

@metawrap-dev?

@metawrap-dev
Copy link
Author

Thanks for the suggestion!

Is the proposed ncu -u -w=* any different than ncu -u --deep?

ncu -u --deep could affect more dirs than those specified as workspaces. Would be equivalent only when dirs equals workspaces.

Would also be great to be able to go ncu -u -w=@metawrap/client-* to specify a named subset of worspaces.

Is the proposed ncu -u -w=@metawrap/metawrap-core any different than ncu -u --packageFile modules/@metawrap/metawrap-core/package.json?

Would be the same effect, but would be nicer to refer to workspaces instead of folders.

What is driving this suggestion is that If workspaces are going to be the way of referring to sub-projects across all the node tooling, would be great to support that for consitency.

Trying to clarify if this is more of an alias or a new feature.

Thanks! Sorry for the delay. Not in GH as often as I need to be :)

@httpete
Copy link

httpete commented Jun 29, 2022

this is really important - I love ncu but now that we are a monorepo with npm workspaces, I need the -w flag exactly as it is proposed.

@rogeriorc
Copy link

rogeriorc commented Jul 14, 2022

You can use npm exec:

npm exec --workspaces --include-workspace-root -- ncu -u
npm exec --workspace=@metawrap/metawrap-core -- ncu -u

But... it show warnings for the workspace projects:

@totvs/webapp-frontend        404 Not Found - GET https://npm.totvs.io/@totvs%2fwebapp-frontend - no such package available. Either your internet connection is down or unstable and all 3 retry attempts failed, or the registry is not accessible, or the package does not exist.  

@ghdoergeloh
Copy link

I would also love to have this option.

An additional bug to have a look at would be the parallel run of npm install.

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

If you have two package.json with the same dependency both will try to put the package into the root node_modules which causes errors like npm ERR! EEXIST: file already exists.
So I would ether need an option to disable npm install after a ncu execution to run npm install manually afterwards or ncu musst check for workspaces and run npm install just once in a workspace (preferred in the root directory).

@raineorshine
Copy link
Owner

raineorshine commented Aug 18, 2022

@ghdoergeloh Thanks for reporting. Please create a separate issue with exact steps to reproduce, including your folder layout and ncu config.

It is only loosely related to the topic of this issue, which is to add a new option --workspace [name] as a shorthand for --packageFile [path-to-workspace].

@httpete
Copy link

httpete commented Sep 4, 2022

I am finding in my pure npm workspaces monorepo this works just great: I have two scripts at the root package. One updates the root, and one updates all the workspaces interactively.

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

@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.

The API is slightly different than the OP in order to more closely match npm's --workspaces and --workspace options.

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

@httpete
Copy link

httpete commented Sep 16, 2022

Seems to work exactly the same for me @raineorshine thanks!

@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.

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

No branches or pull requests

5 participants