summaryrefslogtreecommitdiff
path: root/deps/npm/lib/dedupe.js
blob: 5e455192bcab0aa0d34ba90d7040c9d8f53062ca (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
// dedupe duplicated packages, or find them in the tree
const npm = require('./npm.js')
const Arborist = require('@npmcli/arborist')
const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')

const usage = usageUtil('dedupe', 'npm dedupe')
const completion = require('./utils/completion/none.js')

const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb)

const dedupe = async (args) => {
  if (npm.flatOptions.global) {
    const er = new Error('`npm dedupe` does not work in global mode.')
    er.code = 'EDEDUPEGLOBAL'
    throw er
  }

  const dryRun = (args && args.dryRun) || npm.flatOptions.dryRun
  const where = npm.prefix
  const arb = new Arborist({
    ...npm.flatOptions,
    path: where,
    dryRun,
  })
  await arb.dedupe(npm.flatOptions)
  await reifyFinish(arb)
}

module.exports = Object.assign(cmd, { usage, completion })