prune.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // prune extraneous packages
  2. const Arborist = require('@npmcli/arborist')
  3. const reifyFinish = require('./utils/reify-finish.js')
  4. const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js')
  5. class Prune extends ArboristWorkspaceCmd {
  6. /* istanbul ignore next - see test/lib/load-all-commands.js */
  7. static get description () {
  8. return 'Remove extraneous packages'
  9. }
  10. /* istanbul ignore next - see test/lib/load-all-commands.js */
  11. static get name () {
  12. return 'prune'
  13. }
  14. /* istanbul ignore next - see test/lib/load-all-commands.js */
  15. static get params () {
  16. return ['omit', 'dry-run', 'json', ...super.params]
  17. }
  18. /* istanbul ignore next - see test/lib/load-all-commands.js */
  19. static get usage () {
  20. return ['[[<@scope>/]<pkg>...]']
  21. }
  22. exec (args, cb) {
  23. this.prune().then(() => cb()).catch(cb)
  24. }
  25. async prune () {
  26. const where = this.npm.prefix
  27. const opts = {
  28. ...this.npm.flatOptions,
  29. path: where,
  30. log: this.npm.log,
  31. workspaces: this.workspaceNames,
  32. }
  33. const arb = new Arborist(opts)
  34. await arb.prune(opts)
  35. await reifyFinish(this.npm, arb)
  36. }
  37. }
  38. module.exports = Prune