Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
throw an error when trying to dedupe in global mode
PR-URL: #2716
Credit: @nlf
Close: #2716
Reviewed-by: @ljharb, @wraithgar
  • Loading branch information
nlf committed Feb 18, 2021
1 parent 00afa31 commit 69e0c4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/dedupe.js
Expand Up @@ -10,6 +10,12 @@ 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({
Expand Down
15 changes: 15 additions & 0 deletions test/lib/dedupe.js
@@ -1,6 +1,21 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('should throw in global mode', (t) => {
const dedupe = requireInject('../../lib/dedupe.js', {
'../../lib/npm.js': {
flatOptions: {
global: true,
},
},
})

dedupe([], er => {
t.match(er, { code: 'EDEDUPEGLOBAL' }, 'throws EDEDUPEGLOBAL')
t.end()
})
})

test('should remove dupes using Arborist', (t) => {
const dedupe = requireInject('../../lib/dedupe.js', {
'../../lib/npm.js': {
Expand Down

0 comments on commit 69e0c4e

Please sign in to comment.