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
path: root/lib/ci.js
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/ci.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/ci.js')
-rw-r--r--lib/ci.js53
1 files changed, 21 insertions, 32 deletions
diff --git a/lib/ci.js b/lib/ci.js
index e64bca5d6..8823139df 100644
--- a/lib/ci.js
+++ b/lib/ci.js
@@ -1,24 +1,20 @@
-'use strict'
-
const util = require('util')
const Arborist = require('@npmcli/arborist')
const rimraf = util.promisify(require('rimraf'))
+const reifyOutput = require('./utils/reify-output.js')
+const log = require('npmlog')
const npm = require('./npm.js')
const output = require('./utils/output.js')
+const usageUtil = require('./utils/usage.js')
-cmd.usage = 'npm ci'
+const usage = usageUtil('ci', 'npm ci')
-cmd.completion = (cb) => cb(null, [])
+const completion = (cb) => cb(null, [])
-module.exports = cmd
-function cmd(cb) {
- ci()
- .then(() => cb())
- .catch(cb)
-}
+const cmd = (args, cb) => ci().then(() => cb()).catch(cb)
-async function ci () {
+const ci = async () => {
if (npm.flatOptions.global) {
const err = new Error('`npm ci` does not work for global packages')
err.code = 'ECIGLOBAL'
@@ -28,26 +24,19 @@ async function ci () {
const where = npm.prefix
const arb = new Arborist({ ...npm.flatOptions, path: where })
- try {
- await arb.loadVirtual()
- const start = Date.now()
- await rimraf(`${where}/node_modules/`)
- await arb.reify()
- const stop = Date.now()
-
- const time = (stop - start) / 1000
- const pkgCount = arb.diff.children.length
- const added = `added ${pkgCount}`
- output(`${added} packages in ${time}s`)
-
- } catch (err) {
- if (err.message.match(/shrinkwrap/)) {
- const msg = 'The \`npm ci\` command can only install packages with an existing ' +
- 'package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install ' +
- 'with npm@5 or later to generate a package-lock.json file, then try again.'
+ await Promise.all([
+ arb.loadVirtual().catch(er => {
+ log.verbose('loadVirtual', er.stack)
+ const msg =
+ 'The `npm ci` command can only install with an existing package-lock.json or\n' +
+ 'npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or\n' +
+ 'later to generate a package-lock.json file, then try again.'
throw new Error(msg)
- } else {
- throw err
- }
- }
+ }),
+ rimraf(`${where}/node_modules/`)
+ ])
+ await arb.reify()
+ reifyOutput(arb)
}
+
+module.exports = Object.assign(cmd, { completion, usage })