8

Is there a way to run npm prune but a single package that is not in the dependencies?

I know it sounds weird, but there is a legit use-case.

Use case:

  1. Inside an abstracted CI/CD flow, I want to npm install any new additions to the package.json
  2. Then npm prune should remove any extraneous packages that may have been removed from the package.json
  3. Then I want to npm install XXXX a single dependency that is required only for the CI/CD flow, however subsequent flows should not install this if it is already present, thus on the second execution of the CI/CD flow, this XXXX package would be removed via the npm prune command. :-(
tatemz
  • 111
  • 1
  • 7
  • A possible workaround for the specific use-case mentioned above is to use the [`npm ci`](https://docs.npmjs.com/cli/v9/commands/npm-ci) command. Note that this will delete all dependencies so it is a bit slower than the `npm install`. – somethingRandom Dec 22 '22 at 18:36

1 Answers1

0

As of version 9 of npm, it is still not possible to exclude packages when using npm prune.

A possible workaround for this issue is to convert the dependency to a peer dependency. But this will depend on your use case.

somethingRandom
  • 811
  • 11
  • 16