diff options
author | claudiahdz <cghr1990@gmail.com> | 2020-06-05 01:21:33 +0300 |
---|---|---|
committer | claudiahdz <cghr1990@gmail.com> | 2020-06-06 01:20:15 +0300 |
commit | 56d458ebc47dc0e5b3e3b699ac7e939f00e0be50 (patch) | |
tree | df7ace9dbbb569e60b151f8c5aa9196d0e8d6cd2 /lib | |
parent | 05e76efe4d4ce6f3ee218a3f501c356036aae57a (diff) |
feat: use Arborist for dedupe and prune
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dedupe.js | 21 | ||||
-rw-r--r-- | lib/prune.js | 27 |
2 files changed, 29 insertions, 19 deletions
diff --git a/lib/dedupe.js b/lib/dedupe.js index 6e696e5ca..51947c792 100644 --- a/lib/dedupe.js +++ b/lib/dedupe.js @@ -1,19 +1,24 @@ // dedupe duplicated packages, or find them in the tree -const util = require('util') +const npm = require('./npm.js') const Arborist = require('@npmcli/arborist') -const rimraf = util.promisify(require('rimraf')) -const reifyOutput = require('./utils/reify-output.js') const usageUtil = require('./utils/usage.js') +const reifyOutput = require('./utils/reify-output.js') const usage = usageUtil('dedupe', 'npm dedupe') - const completion = (cb) => cb(null, []) -const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb) +const cmd = (args, cb) => dedupe().then(() => cb()).catch(cb) -const dedupe = async args => { - require('npmlog').warn('coming soon!') - throw new Error('not yet implemented') +const dedupe = async () => { + const { dryRun } = npm.flatOptions + const where = npm.prefix + const arb = new Arborist({ + ...npm.flatOptions, + path: where, + dryRun + }) + await arb.dedupe() + reifyOutput(arb) } module.exports = Object.assign(cmd, { usage, completion }) diff --git a/lib/prune.js b/lib/prune.js index 6e1cd9318..e675df30d 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -1,20 +1,25 @@ -// prune extraneous packages. -const util = require('util') +// prune extraneous packages +const npm = require('./npm.js') const Arborist = require('@npmcli/arborist') -const rimraf = util.promisify(require('rimraf')) -const reifyOutput = require('./utils/reify-output.js') const usageUtil = require('./utils/usage.js') -const usage = usageUtil('prune', - 'npm prune [[<@scope>/]<pkg>...] [--production]') +const reifyOutput = require('./utils/reify-output.js') -const completion = require('./utils/completion/installed-deep.js') +const usage = usageUtil('prune', + 'npm prune [[<@scope>/]<pkg>...] [--production]' +) +const completion = (cb) => cb(null, []) -const cmd = (args, cb) => prune(args).then(() => cb()).catch(cb) +const cmd = (args, cb) => prune().then(() => cb()).catch(cb) -const prune = async args => { - require('npmlog').warn('coming soon!') - throw new Error('not yet implemented') +const prune = async () => { + const where = npm.prefix + const arb = new Arborist({ + ...npm.flatOptions, + path: where + }) + await arb.prune() + reifyOutput(arb) } module.exports = Object.assign(cmd, { usage, completion }) |