2021-11-04 20:42:47 +00:00
|
|
|
const reifyFinish = require('../utils/reify-finish.js')
|
|
|
|
const ArboristWorkspaceCmd = require('../arborist-cmd.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
// dedupe duplicated packages, or find them in the tree
|
2021-05-20 15:54:50 -04:00
|
|
|
class Dedupe extends ArboristWorkspaceCmd {
|
2021-11-18 20:58:02 +00:00
|
|
|
static description = 'Reduce duplication in the package tree'
|
|
|
|
static name = 'dedupe'
|
|
|
|
static params = [
|
2022-12-06 22:18:33 -05:00
|
|
|
'install-strategy',
|
2021-11-18 20:58:02 +00:00
|
|
|
'legacy-bundling',
|
2022-12-06 22:18:33 -05:00
|
|
|
'global-style',
|
2021-11-18 20:58:02 +00:00
|
|
|
'strict-peer-deps',
|
|
|
|
'package-lock',
|
|
|
|
'omit',
|
2023-10-13 06:55:37 -07:00
|
|
|
'include',
|
2021-11-18 20:58:02 +00:00
|
|
|
'ignore-scripts',
|
|
|
|
'audit',
|
|
|
|
'bin-links',
|
|
|
|
'fund',
|
|
|
|
'dry-run',
|
|
|
|
...super.params,
|
|
|
|
]
|
2021-05-20 15:54:50 -04:00
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
async exec () {
|
2022-05-25 21:26:36 +00:00
|
|
|
if (this.npm.global) {
|
2021-03-04 17:40:28 -05:00
|
|
|
const er = new Error('`npm dedupe` does not work in global mode.')
|
|
|
|
er.code = 'EDEDUPEGLOBAL'
|
|
|
|
throw er
|
|
|
|
}
|
|
|
|
|
|
|
|
const dryRun = this.npm.config.get('dry-run')
|
|
|
|
const where = this.npm.prefix
|
2023-05-07 03:37:34 -07:00
|
|
|
const Arborist = require('@npmcli/arborist')
|
2021-03-23 14:58:11 -04:00
|
|
|
const opts = {
|
2021-03-04 17:40:28 -05:00
|
|
|
...this.npm.flatOptions,
|
|
|
|
path: where,
|
|
|
|
dryRun,
|
2022-04-14 21:57:02 +00:00
|
|
|
// Saving during dedupe would only update if one of your direct
|
|
|
|
// dependencies was also duplicated somewhere in your tree. It would be
|
|
|
|
// confusing if running this were to also update your package.json. In
|
|
|
|
// order to reduce potential confusion we set this to false.
|
|
|
|
save: false,
|
2021-06-17 18:59:38 +00:00
|
|
|
workspaces: this.workspaceNames,
|
2021-03-23 14:58:11 -04:00
|
|
|
}
|
|
|
|
const arb = new Arborist(opts)
|
|
|
|
await arb.dedupe(opts)
|
2021-03-04 17:40:28 -05:00
|
|
|
await reifyFinish(this.npm, arb)
|
|
|
|
}
|
2015-10-09 23:13:57 -07:00
|
|
|
}
|
2012-08-21 15:29:03 -07:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
module.exports = Dedupe
|