Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2020-05-05 02:17:58 +0300
committerisaacs <i@izs.me>2020-05-08 04:19:20 +0300
commit59d937387d510d3f5b09390d601d53ab66a63d37 (patch)
tree1b8903aef7b82e678ba3397799220f28d37a832b /lib/prune.js
parent873665e2c7f400c5de1962135f2510acc304b599 (diff)
Consistent output for most reify() commands
This adds a 'reify-output.js' util, which can be passed any Arborist object after it reifies a tree. Consistent output is printed in all cases, showing the number of packages added/removed/changed, packages needing funding, and a minimal (but always actionable and relevant) audit summary. The only code using the Installer class now is in lib/outdated.js, which is has a pending update coming soon. Prune and dedupe commands are awaiting top-level Arborist methods, so that they can be similarly tightened up. (For now, this commit just has them fail with a 'coming soon' message.) The last piece holding the 'install/*.js' code in this repo is that it is used in 'ls', 'fund', 'shrinkwrap', and the error-message util.
Diffstat (limited to 'lib/prune.js')
-rw-r--r--lib/prune.js75
1 files changed, 13 insertions, 62 deletions
diff --git a/lib/prune.js b/lib/prune.js
index 62c9a9225..6e1cd9318 100644
--- a/lib/prune.js
+++ b/lib/prune.js
@@ -1,69 +1,20 @@
-// XXX replace this with @npmcli/arborist
// prune extraneous packages.
+const util = require('util')
+const Arborist = require('@npmcli/arborist')
+const rimraf = util.promisify(require('rimraf'))
+const reifyOutput = require('./utils/reify-output.js')
+const usageUtil = require('./utils/usage.js')
-module.exports = prune
-module.exports.Pruner = Pruner
+const usage = usageUtil('prune',
+ 'npm prune [[<@scope>/]<pkg>...] [--production]')
-prune.usage = 'npm prune [[<@scope>/]<pkg>...] [--production]'
+const completion = require('./utils/completion/installed-deep.js')
-var npm = require('./npm.js')
-var log = require('npmlog')
-var util = require('util')
-var moduleName = require('./utils/module-name.js')
-var Installer = require('./install.js').Installer
-var isExtraneous = require('./install/is-extraneous.js')
-var isOnlyDev = require('./install/is-only-dev.js')
-var removeDeps = require('./install/deps.js').removeDeps
-var loadExtraneous = require('./install/deps.js').loadExtraneous
-var chain = require('slide').chain
-var computeMetadata = require('./install/deps.js').computeMetadata
+const cmd = (args, cb) => prune(args).then(() => cb()).catch(cb)
-prune.completion = require('./utils/completion/installed-deep.js')
-
-function prune (args, cb) {
- var dryrun = !!npm.config.get('dry-run')
- new Pruner('.', dryrun, args).run(cb)
-}
-
-function Pruner (where, dryrun, args) {
- Installer.call(this, where, dryrun, args)
- this.autoPrune = true
-}
-util.inherits(Pruner, class {}) // Installer)
-
-Pruner.prototype.loadAllDepsIntoIdealTree = function (cb) {
- log.silly('uninstall', 'loadAllDepsIntoIdealTree')
-
- var cg = this.progress['loadIdealTree:loadAllDepsIntoIdealTree']
- var steps = []
-
- computeMetadata(this.idealTree)
- var self = this
- var excludeDev = npm.config.get('production') || /^prod(uction)?$/.test(npm.config.get('only'))
- function shouldPrune (child) {
- if (isExtraneous(child)) return true
- if (!excludeDev) return false
- return isOnlyDev(child)
- }
- function getModuleName (child) {
- // wrapping because moduleName doesn't like extra args and we're called
- // from map.
- return moduleName(child)
- }
- function matchesArg (name) {
- return self.args.length === 0 || self.args.indexOf(name) !== -1
- }
- function nameObj (name) {
- return {name: name}
- }
- var toPrune = this.idealTree.children.filter(shouldPrune).map(getModuleName).filter(matchesArg).map(nameObj)
-
- steps.push(
- [removeDeps, toPrune, this.idealTree, null],
- [loadExtraneous, this.idealTree, cg.newGroup('loadExtraneous')])
- chain(steps, cb)
+const prune = async args => {
+ require('npmlog').warn('coming soon!')
+ throw new Error('not yet implemented')
}
-Pruner.prototype.runPreinstallTopLevelLifecycles = function (cb) { cb() }
-Pruner.prototype.runPostinstallTopLevelLifecycles = function (cb) { cb() }
-Pruner.prototype.saveToDependencies = function (cb) { cb() }
+module.exports = Object.assign(cmd, { usage, completion })