-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
730 additions
and
688 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
// 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') | ||
class Dedupe { | ||
constructor (npm) { | ||
this.npm = npm | ||
} | ||
|
||
const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb) | ||
get usage () { | ||
return usageUtil('dedupe', 'npm dedupe') | ||
} | ||
|
||
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 | ||
exec (args, cb) { | ||
this.dedupe(args).then(() => cb()).catch(cb) | ||
} | ||
|
||
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) | ||
async dedupe (args) { | ||
if (this.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) || this.npm.flatOptions.dryRun | ||
const where = this.npm.prefix | ||
const arb = new Arborist({ | ||
...this.npm.flatOptions, | ||
path: where, | ||
dryRun, | ||
}) | ||
await arb.dedupe(this.npm.flatOptions) | ||
await reifyFinish(arb) | ||
} | ||
} | ||
|
||
module.exports = Object.assign(cmd, { usage }) | ||
module.exports = Dedupe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.