diff options
author | Gar <gar+gh@danger.computer> | 2021-02-25 02:54:50 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-05 00:05:08 +0300 |
commit | 4a5dd3a5a200b3f4f7b47168497d8e03dca3a2ca (patch) | |
tree | d34a1ea229b719c3cfbdce85899ceaf67b43e7ab /lib/find-dupes.js | |
parent | b33c760cea7fe2696d35b5530abc1b455980fef1 (diff) |
fix(npm) pass npm context everywhere
Instead of files randomly requiring the npm singleton,
we pass it where it needs to go so that tests don't need
to do so much require mocking everywhere
PR-URL: https://github.com/npm/cli/pull/2772
Credit: @wraithgar
Close: #2772
Reviewed-by: @ruyadorno
Diffstat (limited to 'lib/find-dupes.js')
-rw-r--r-- | lib/find-dupes.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/find-dupes.js b/lib/find-dupes.js index 19e7ea6a7..5061be9cc 100644 --- a/lib/find-dupes.js +++ b/lib/find-dupes.js @@ -1,8 +1,19 @@ // dedupe duplicated packages, or find them in the tree -const dedupe = require('./dedupe.js') const usageUtil = require('./utils/usage.js') -const usage = usageUtil('find-dupes', 'npm find-dupes') -const cmd = (args, cb) => dedupe({ dryRun: true }, cb) +class FindDupes { + constructor (npm) { + this.npm = npm + } -module.exports = Object.assign(cmd, { usage }) + /* istanbul ignore next - see test/lib/load-all-commands.js */ + get usage () { + return usageUtil('find-dupes', 'npm find-dupes') + } + + exec (args, cb) { + this.npm.config.set('dry-run', true) + this.npm.commands.dedupe([], cb) + } +} +module.exports = FindDupes |