summaryrefslogtreecommitdiff
path: root/deps/npm/lib/prune.js
blob: b839301d5194c12d0ae7c30f795fc0f98c0e0980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// prune extraneous packages
const Arborist = require('@npmcli/arborist')
const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')

class Prune {
  constructor (npm) {
    this.npm = npm
  }

  /* istanbul ignore next - see test/lib/load-all-commands.js */
  get usage () {
    return usageUtil('prune',
      'npm prune [[<@scope>/]<pkg>...] [--production]'
    )
  }

  exec (args, cb) {
    this.prune().then(() => cb()).catch(cb)
  }

  async prune () {
    const where = this.npm.prefix
    const arb = new Arborist({
      ...this.npm.flatOptions,
      path: where,
    })
    await arb.prune(this.npm.flatOptions)
    await reifyFinish(this.npm, arb)
  }
}
module.exports = Prune