From 113b1319f9e9c90694454bebc9dc12111a441ecf Mon Sep 17 00:00:00 2001 From: Gar Date: Mon, 22 Feb 2021 15:59:21 -0800 Subject: chore(refactor): promisify completion scripts We also removed the "none" script because we handle a missing script just fine. There is no need to put an empty one in PR-URL: https://github.com/npm/cli/pull/2759 Credit: @wraithgar Close: #2759 Reviewed-by: @nlf --- lib/utils/completion/installed-deep.js | 6 +----- lib/utils/completion/installed-shallow.js | 5 ++--- lib/utils/completion/none.js | 2 -- lib/utils/lifecycle-cmd.js | 3 +-- 4 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 lib/utils/completion/none.js (limited to 'lib/utils') diff --git a/lib/utils/completion/installed-deep.js b/lib/utils/completion/installed-deep.js index 793f3b3e9..f464bb9a9 100644 --- a/lib/utils/completion/installed-deep.js +++ b/lib/utils/completion/installed-deep.js @@ -2,7 +2,7 @@ const { resolve } = require('path') const Arborist = require('@npmcli/arborist') const npm = require('../../npm.js') -const readNames = async () => { +const installedDeep = async () => { const { depth, global, @@ -36,8 +36,4 @@ const readNames = async () => { return [...res] } -function installedDeep (opts, cb) { - return readNames().then(res => cb(null, res)).catch(cb) -} - module.exports = installedDeep diff --git a/lib/utils/completion/installed-shallow.js b/lib/utils/completion/installed-shallow.js index e2ff5a302..c9c680e7d 100644 --- a/lib/utils/completion/installed-shallow.js +++ b/lib/utils/completion/installed-shallow.js @@ -4,7 +4,7 @@ const readdir = promisify(require('readdir-scoped-modules')) const names = global => readdir(global ? npm.globalDir : npm.localDir) -const installedShallow = async opts => { +const installedShallow = async (opts) => { const { conf: { argv: { remain } } } = opts if (remain.length > 3) return null @@ -15,5 +15,4 @@ const installedShallow = async opts => { return [...locals, ...globals] } -module.exports = (opts, cb) => - installedShallow(opts).then(list => cb(null, list)).catch(cb) +module.exports = installedShallow diff --git a/lib/utils/completion/none.js b/lib/utils/completion/none.js deleted file mode 100644 index 752400da4..000000000 --- a/lib/utils/completion/none.js +++ /dev/null @@ -1,2 +0,0 @@ -// used for commands where no completion is relevant/possible -module.exports = (opts, cb) => cb(null, []) diff --git a/lib/utils/lifecycle-cmd.js b/lib/utils/lifecycle-cmd.js index 83a712cf4..94b109942 100644 --- a/lib/utils/lifecycle-cmd.js +++ b/lib/utils/lifecycle-cmd.js @@ -2,10 +2,9 @@ // test, start, stop, restart const usageUtil = require('./usage.js') -const completion = require('./completion/none.js') module.exports = (npm, stage) => { const cmd = (args, cb) => npm.commands['run-script']([stage, ...args], cb) const usage = usageUtil(stage, `npm ${stage} [-- ]`) - return Object.assign(cmd, { usage, completion }) + return Object.assign(cmd, { usage }) } -- cgit v1.2.3