Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
dedupe.js52 linesDownload Raw Back to commands
1const reifyFinish = require('../utils/reify-finish.js')
2const ArboristWorkspaceCmd = require('../arborist-cmd.js')
3
4// dedupe duplicated packages, or find them in the tree
5class Dedupe extends ArboristWorkspaceCmd {
6  static description = 'Reduce duplication in the package tree'
7  static name = 'dedupe'
8  static params = [
9    'install-strategy',
10    'legacy-bundling',
11    'global-style',
12    'strict-peer-deps',
13    'package-lock',
14    'omit',
15    'include',
16    'ignore-scripts',
17    'allow-git',
18    'audit',
19    'bin-links',
20    'fund',
21    'dry-run',
22    ...super.params,
23  ]
24
25  async exec () {
26    if (this.npm.global) {
27      const er = new Error('`npm dedupe` does not work in global mode.')
28      er.code = 'EDEDUPEGLOBAL'
29      throw er
30    }
31
32    const dryRun = this.npm.config.get('dry-run')
33    const where = this.npm.prefix
34    const Arborist = require('@npmcli/arborist')
35    const opts = {
36      ...this.npm.flatOptions,
37      path: where,
38      dryRun,
39      // Saving during dedupe would only update if one of your direct dependencies was also duplicated somewhere in your tree.
40      // It would be confusing if running this were to also update your package.json.
41      // In order to reduce potential confusion we set this to false.
42      save: false,
43      workspaces: this.workspaceNames,
44    }
45    const arb = new Arborist(opts)
46    await arb.dedupe(opts)
47    await reifyFinish(this.npm, arb)
48  }
49}
50
51module.exports = Dedupe
52 
codekingpro/portable-devtools · Team Ai