npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.39k stars 3.12k forks source link

[BUG] Install production dependencies for a single package in a workspace #5969

Closed sinedied closed 1 year ago

sinedied commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

I'm trying to achieve the same as asked in this SO question: https://stackoverflow.com/questions/70540116/how-do-i-install-dependencies-for-a-single-package-when-using-npm-workspaces

Basically I have a workspace with multiples packages, and I want to get only production dependencies for one of them in the context of packaging a container through a Dockerfile.

I tried running npm ci --omit=dev -w <name>, but the result is not the one I expected, as running npm ls --omit=dev -w settings-api immediately after shows that it installed extraneous packages.

Expected Behavior

Only production dependencies for the specified workspace should be installed.

Bonus point: in that context, there's also 2 missing features that would be helpful (sorry I couldn't find anywhere else to suggest them)

Steps To Reproduce

  1. In this environment: node v18.12.1 / npm 9.2.0
  2. With this repo: https://github.com/sinedied/azure-nodejs-microservices
  3. Run npm ci --omit=dev -w settings-api
  4. Run npm ls --omit=dev -w settings-api:
azure-nodejs-microservices@1.0.0 /Users/sinedied/projects/nest-docker-demo
├── brace-expansion@1.1.11 extraneous
├── buffer-from@1.1.2 extraneous
├── concat-map@0.0.1 extraneous
├── get-caller-file@2.0.5 extraneous
├── glob@7.2.3 extraneous
├── minimatch@3.1.2 extraneous
├── path-is-absolute@1.0.1 extraneous
├── rimraf@3.0.2 extraneous
├─┬ settings-api@1.0.0 -> ./packages/settings-api
│ ├── @fastify/autoload@5.6.0
│ ├── @fastify/sensible@5.2.0
│ ├── fastify-cli@5.7.0
│ ├── fastify-plugin@4.4.0
│ └── fastify@4.10.2
└── uuid@8.3.2 extraneous

Environment

//registry.npmjs.org/:_authToken = (protected)

; "cli" config from command line options

location = "project"

; node bin location = /Users/sinedied/.nvm/versions/node/v18.12.1/bin/node ; node version = v18.12.1 ; npm local prefix = /Users/sinedied/projects/nest-docker-demo ; npm version = 9.2.0 ; cwd = /Users/sinedied/projects/nest-docker-demo ; HOME = /Users/sinedied ; Run npm config ls -l to show all defaults.

fritzy commented 1 year ago

These are features that we could add to the linked install strategy! It just isn't possible to separate out the tree with the default hoisted install strategy. Would you be willing to start an RFC to get the ball rolling?

Can you create an RRFC in that rep with some details on how you would like to see this changed? Reference this issue. Thanks!