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-08-04 08:56:34 +0300
committerisaacs <i@izs.me>2020-08-04 11:03:34 +0300
commit108a4fcb5da23c34690b4767a4c5f7f93ab99c0d (patch)
tree15254742f9e81012fd8d50d6621d9178d2f6977d /lib/bin.js
parent0b63d5078a5858b83dba943720c6d6dfe6eb808f (diff)
refactor and lint commands, make consistent
Still pending test coverage for most of these, but wanted to give them a clean sweep to get the "load-all-commands" tests passing. The following changes are in here: - All commands now have a `completion()` method and a usage string that uses the same `usage` util consistently. - The `silent` argument to many commands has been removed. - All commands use the `cmd = ${cmd}(args).then(() => cb()).catch(cb)` pattern consistently. Full test coverage for all commands is still lacking, and will have to be done prior to the GA v7 release.
Diffstat (limited to 'lib/bin.js')
-rw-r--r--lib/bin.js35
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/bin.js b/lib/bin.js
index c15a7752c..e2b2a31da 100644
--- a/lib/bin.js
+++ b/lib/bin.js
@@ -1,23 +1,16 @@
-module.exports = bin
-
-var npm = require('./npm.js')
-var osenv = require('osenv')
-var output = require('./utils/output.js')
-
-bin.usage = 'npm bin [--global]'
-
-function bin (args, silent, cb) {
- if (typeof cb !== 'function') {
- cb = silent
- silent = false
- }
- var b = npm.bin
- var PATH = osenv.path()
-
- if (!silent) output(b)
- process.nextTick(cb.bind(this, null, b))
-
- if (npm.config.get('global') && PATH.indexOf(b) === -1) {
- process.stderr.write('(not in PATH env variable)\n')
+const osenv = require('osenv')
+const npm = require('./npm.js')
+const output = require('./utils/output.js')
+const usageUtil = require('./utils/usage.js')
+const completion = require('./utils/completion/none.js')
+const cmd = (args, cb) => bin(args).then(() => cb()).catch(cb)
+const usage = usageUtil('bin', 'npm bin [-g]')
+const bin = async (args, cb) => {
+ const b = npm.bin
+ const PATH = osenv.path()
+ output(b)
+ if (npm.flatOptions.global && !PATH.includes(b)) {
+ console.error('(not in PATH env variable)')
}
}
+module.exports = Object.assign(cmd, { usage, completion })