diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-01 11:38:43 -0500 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-03-02 09:31:29 +0100 |
commit | 993963e2ee1c24dee0f39dbdbb3283272c30679c (patch) | |
tree | 7ad138c8a4b240f948e322eb2bc5c6d7acca32e6 /deps/npm/lib | |
parent | b3f35e2c70c7d1e3ee7b4c3fd74672adceb16c52 (diff) | |
download | node-new-993963e2ee1c24dee0f39dbdbb3283272c30679c.tar.gz |
deps: upgrade npm to 7.6.0
PR-URL: https://github.com/nodejs/node/pull/37559
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Diffstat (limited to 'deps/npm/lib')
57 files changed, 168 insertions, 221 deletions
diff --git a/deps/npm/lib/access.js b/deps/npm/lib/access.js index 8a372d90cb..10b1e21e0c 100644 --- a/deps/npm/lib/access.js +++ b/deps/npm/lib/access.js @@ -59,17 +59,17 @@ const access = async ([cmd, ...args], cb) => { return fn(args, { ...npm.flatOptions }) } -const completion = function (opts, cb) { - var argv = opts.conf.argv.remain +const completion = async (opts) => { + const argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, subcommands) + return subcommands switch (argv[2]) { case 'grant': if (argv.length === 3) - return cb(null, ['read-only', 'read-write']) + return ['read-only', 'read-write'] else - return cb(null, []) + return [] case 'public': case 'restricted': @@ -79,9 +79,9 @@ const completion = function (opts, cb) { case '2fa-required': case '2fa-not-required': case 'revoke': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/adduser.js b/deps/npm/lib/adduser.js index b6c3321745..c68c2b80f8 100644 --- a/deps/npm/lib/adduser.js +++ b/deps/npm/lib/adduser.js @@ -15,8 +15,6 @@ const usage = usageUtil( 'npm adduser [--registry=url] [--scope=@orgname] [--always-auth]' ) -const completion = require('./utils/completion/none.js') - const cmd = (args, cb) => adduser(args).then(() => cb()).catch(cb) const getRegistry = ({ scope, registry }) => { @@ -74,4 +72,4 @@ const adduser = async (args) => { output(message) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/audit.js b/deps/npm/lib/audit.js index cb8ab5b3a4..1b31401b1a 100644 --- a/deps/npm/lib/audit.js +++ b/deps/npm/lib/audit.js @@ -38,17 +38,17 @@ const usage = usageUtil( '[--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]' ) -const completion = (opts, cb) => { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, ['fix']) + return ['fix'] switch (argv[2]) { case 'fix': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/bin.js b/deps/npm/lib/bin.js index 1d776365c2..e627ce22f1 100644 --- a/deps/npm/lib/bin.js +++ b/deps/npm/lib/bin.js @@ -1,7 +1,6 @@ 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 PATH = require('./utils/path.js') const cmd = (args, cb) => bin(args).then(() => cb()).catch(cb) const usage = usageUtil('bin', 'npm bin [-g]') @@ -11,4 +10,4 @@ const bin = async (args, cb) => { if (npm.flatOptions.global && !PATH.includes(b)) console.error('(not in PATH env variable)') } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/bugs.js b/deps/npm/lib/bugs.js index 012f39efbd..09856313ce 100644 --- a/deps/npm/lib/bugs.js +++ b/deps/npm/lib/bugs.js @@ -7,7 +7,6 @@ const npm = require('./npm.js') const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js') const usage = usageUtil('bugs', 'npm bugs [<pkgname>]') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => bugs(args).then(() => cb()).catch(cb) @@ -44,4 +43,4 @@ const getBugs = async pkg => { await openUrl(url, `${mani.name} bug list available at the following URL`) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js index 30d6aef863..7b84353b4a 100644 --- a/deps/npm/lib/cache.js +++ b/deps/npm/lib/cache.js @@ -19,17 +19,17 @@ const usage = usageUtil('cache', '\nnpm cache verify' ) -const completion = (opts, cb) => { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, ['add', 'clean', 'verify']) + return ['add', 'clean', 'verify'] // TODO - eventually... switch (argv[2]) { case 'verify': case 'clean': case 'add': - return cb(null, []) + return [] } } diff --git a/deps/npm/lib/ci.js b/deps/npm/lib/ci.js index 80b9dbb223..51c165acce 100644 --- a/deps/npm/lib/ci.js +++ b/deps/npm/lib/ci.js @@ -11,7 +11,6 @@ const npm = require('./npm.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('ci', 'npm ci') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => ci().then(() => cb()).catch(cb) @@ -76,4 +75,4 @@ const ci = async () => { await reifyFinish(arb) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, {usage}) diff --git a/deps/npm/lib/completion.js b/deps/npm/lib/completion.js index bdea338ff2..b31867d988 100644 --- a/deps/npm/lib/completion.js +++ b/deps/npm/lib/completion.js @@ -28,8 +28,6 @@ // one per line for the shell completion method to consume in IFS=$'\n' mode // as an array. // -// TODO: make all the implementation completion methods promise-returning -// instead of callback-taking. const npm = require('./npm.js') const { types, shorthands } = require('./utils/config.js') @@ -52,9 +50,9 @@ const { promisify } = require('util') const cmd = (args, cb) => compl(args).then(() => cb()).catch(cb) // completion for the completion command -const completion = async (opts, cb) => { +const completion = async (opts) => { if (opts.w > 2) - return cb() + return const { resolve } = require('path') const [bashExists, zshExists] = await Promise.all([ @@ -68,7 +66,7 @@ const completion = async (opts, cb) => { if (bashExists) out.push(['>>', '~/.bashrc']) - cb(null, out) + return out } const compl = async args => { @@ -121,18 +119,16 @@ const compl = async args => { raw: args, } - const wrap = getWrap(opts) - if (partialWords.slice(0, -1).indexOf('--') === -1) { if (word.charAt(0) === '-') - return wrap(configCompl(opts)) + return wrap(opts, configCompl(opts)) if (words[w - 1] && words[w - 1].charAt(0) === '-' && !isFlag(words[w - 1])) { // awaiting a value for a non-bool config. // don't even try to do this for now - return wrap(configValueCompl(opts)) + return wrap(opts, configValueCompl(opts)) } } @@ -146,7 +142,7 @@ const compl = async args => { // check if there's a command already. const cmd = parsed.argv.remain[1] if (!cmd) - return wrap(cmdCompl(opts)) + return wrap(opts, cmdCompl(opts)) Object.keys(parsed).forEach(k => npm.config.set(k, parsed[k])) @@ -155,10 +151,8 @@ const compl = async args => { // otherwise, do nothing const impl = npm.commands[cmd] if (impl && impl.completion) { - // XXX promisify all the cmd.completion functions - return await new Promise((res, rej) => { - impl.completion(opts, (er, comps) => er ? rej(er) : res(wrap(comps))) - }) + const comps = await impl.completion(opts) + return wrap(opts, comps) } } @@ -215,7 +209,7 @@ const escape = w => !/\s+/.test(w) ? w // If any of the items are arrays, then join them with a space. // Ie, returning ['a', 'b c', ['d', 'e']] would allow it to expand // to: 'a', 'b c', or 'd' 'e' -const getWrap = opts => compls => { +const wrap = (opts, compls) => { if (!Array.isArray(compls)) compls = compls ? [compls] : [] diff --git a/deps/npm/lib/config.js b/deps/npm/lib/config.js index b32cf3359d..e4da296de8 100644 --- a/deps/npm/lib/config.js +++ b/deps/npm/lib/config.js @@ -26,7 +26,7 @@ const usage = usageUtil( const cmd = (args, cb) => config(args).then(() => cb()).catch(cb) -const completion = (opts, cb) => { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv[1] !== 'config') argv.unshift('config') @@ -36,7 +36,7 @@ const completion = (opts, cb) => { if (opts.partialWord !== 'l') cmds.push('list') - return cb(null, cmds) + return cmds } const action = argv[2] @@ -44,19 +44,19 @@ const completion = (opts, cb) => { case 'set': // todo: complete with valid values, if possible. if (argv.length > 3) - return cb(null, []) + return [] // fallthrough /* eslint no-fallthrough:0 */ case 'get': case 'delete': case 'rm': - return cb(null, Object.keys(types)) + return Object.keys(types) case 'edit': case 'list': case 'ls': default: - return cb(null, []) + return [] } } diff --git a/deps/npm/lib/dedupe.js b/deps/npm/lib/dedupe.js index 5e455192bc..2211fcac8b 100644 --- a/deps/npm/lib/dedupe.js +++ b/deps/npm/lib/dedupe.js @@ -5,7 +5,6 @@ const usageUtil = require('./utils/usage.js') const reifyFinish = require('./utils/reify-finish.js') const usage = usageUtil('dedupe', 'npm dedupe') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb) @@ -27,4 +26,4 @@ const dedupe = async (args) => { await reifyFinish(arb) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/deprecate.js b/deps/npm/lib/deprecate.js index e049986452..42d099b544 100644 --- a/deps/npm/lib/deprecate.js +++ b/deps/npm/lib/deprecate.js @@ -17,19 +17,17 @@ const usage = usageUtil( 'npm deprecate <pkg>[@<version>] <message>' ) -const completion = (opts, cb) => { +const completion = async (opts) => { if (opts.conf.argv.remain.length > 1) - return cb(null, []) + return [] - return getIdentity(npm.flatOptions).then((username) => { - return libaccess.lsPackages(username, npm.flatOptions).then((packages) => { - return Object.keys(packages) - .filter((name) => packages[name] === 'write' && - (opts.conf.argv.remain.length === 0 || - name.startsWith(opts.conf.argv.remain[0])) - ) - }) - }).then((list) => cb(null, list), (err) => cb(err)) + const username = await getIdentity(npm.flatOptions) + const packages = await libaccess.lsPackages(username, npm.flatOptions) + return Object.keys(packages) + .filter((name) => + packages[name] === 'write' && + (opts.conf.argv.remain.length === 0 || + name.startsWith(opts.conf.argv.remain[0]))) } const cmd = (args, cb) => diff --git a/deps/npm/lib/diff.js b/deps/npm/lib/diff.js index af6760106e..9ef5a78a20 100644 --- a/deps/npm/lib/diff.js +++ b/deps/npm/lib/diff.js @@ -11,7 +11,6 @@ const pickManifest = require('npm-pick-manifest') const npm = require('./npm.js') const usageUtil = require('./utils/usage.js') const output = require('./utils/output.js') -const completion = require('./utils/completion/none.js') const readLocalPkg = require('./utils/read-local-package.js') const usage = usageUtil( @@ -263,4 +262,4 @@ const findVersionsByPackageName = async (specs) => { }) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/dist-tag.js b/deps/npm/lib/dist-tag.js index ae4b33ce86..e958bb7544 100644 --- a/deps/npm/lib/dist-tag.js +++ b/deps/npm/lib/dist-tag.js @@ -16,14 +16,14 @@ const usage = usageUtil( '\nnpm dist-tag ls [<pkg>]' ) -const completion = function (opts, cb) { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, ['add', 'rm', 'ls']) + return ['add', 'rm', 'ls'] switch (argv[2]) { default: - return cb() + return [] } } diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js index b6a3df7f70..fa0adb3d37 100644 --- a/deps/npm/lib/docs.js +++ b/deps/npm/lib/docs.js @@ -7,7 +7,6 @@ const npm = require('./npm.js') const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js') const usage = usageUtil('docs', 'npm docs [<pkgname> [<pkgname> ...]]') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => docs(args).then(() => cb()).catch(cb) @@ -37,4 +36,4 @@ const getDocs = async pkg => { await openUrl(url, `${mani.name} docs available at the following URL`) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/doctor.js b/deps/npm/lib/doctor.js index f42b19fa68..e149aec128 100644 --- a/deps/npm/lib/doctor.js +++ b/deps/npm/lib/doctor.js @@ -4,7 +4,6 @@ const chalk = require('chalk') const ansiTrim = require('./utils/ansi-trim.js') const table = require('text-table') const output = require('./utils/output.js') -const completion = require('./utils/completion/none.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('doctor', 'npm doctor') const { resolve } = require('path') @@ -285,4 +284,4 @@ const doctor = async args => { throw 'Some problems found. See above for recommendations.' } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/exec.js b/deps/npm/lib/exec.js index e90ec0866e..dab65c23a3 100644 --- a/deps/npm/lib/exec.js +++ b/deps/npm/lib/exec.js @@ -21,8 +21,6 @@ const usage = usageUtil('exec', '-c <cmd> --call=<cmd> (may not be mixed with positional arguments)' ) -const completion = require('./utils/completion/installed-shallow.js') - const { promisify } = require('util') const read = promisify(require('read')) @@ -284,4 +282,4 @@ const getHash = packages => .digest('hex') .slice(0, 16) -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/explain.js b/deps/npm/lib/explain.js index 9176f2e6c2..a0a4427bcc 100644 --- a/deps/npm/lib/explain.js +++ b/deps/npm/lib/explain.js @@ -30,7 +30,7 @@ const explain = async (args) => { const expls = [] for (const node of nodes) { - const { extraneous, dev, optional, devOptional, peer } = node + const { extraneous, dev, optional, devOptional, peer, inBundle } = node const expl = node.explain() if (extraneous) expl.extraneous = true @@ -39,6 +39,7 @@ const explain = async (args) => { expl.optional = optional expl.devOptional = devOptional expl.peer = peer + expl.bundled = inBundle } expls.push(expl) } diff --git a/deps/npm/lib/find-dupes.js b/deps/npm/lib/find-dupes.js index 9579163782..19e7ea6a7c 100644 --- a/deps/npm/lib/find-dupes.js +++ b/deps/npm/lib/find-dupes.js @@ -3,7 +3,6 @@ const dedupe = require('./dedupe.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('find-dupes', 'npm find-dupes') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => dedupe({ dryRun: true }, cb) -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/get.js b/deps/npm/lib/get.js index ab2141e357..8a416027d7 100644 --- a/deps/npm/lib/get.js +++ b/deps/npm/lib/get.js @@ -1,4 +1,5 @@ const npm = require('./npm.js') +const config = require('./config.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil( @@ -6,7 +7,7 @@ const usage = usageUtil( 'npm get [<key> ...] (See `npm config`)' ) -const completion = npm.commands.config.completion +const completion = config.completion const cmd = (args, cb) => npm.commands.config(['get'].concat(args), cb) diff --git a/deps/npm/lib/help-search.js b/deps/npm/lib/help-search.js index d2a1818060..b184735048 100644 --- a/deps/npm/lib/help-search.js +++ b/deps/npm/lib/help-search.js @@ -11,7 +11,6 @@ const didYouMean = require('./utils/did-you-mean.js') const { cmdList } = require('./utils/cmd-list.js') const usage = usageUtil('help-search', 'npm help-search <text>') -const completion = require('./utils/completion/none.js') const npmUsage = require('./utils/npm-usage.js') @@ -201,4 +200,4 @@ const formatResults = (args, results) => { return finalOut.trim() } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/help.js b/deps/npm/lib/help.js index f699616654..6f215c76c1 100644 --- a/deps/npm/lib/help.js +++ b/deps/npm/lib/help.js @@ -1,10 +1,24 @@ module.exports = help -help.completion = function (opts, cb) { +help.completion = async (opts) => { if (opts.conf.argv.remain.length > 2) - return cb(null, []) - getSections(cb) + return [] + const g = path.resolve(__dirname, '../man/man[0-9]/*.[0-9]') + const files = await new Promise((resolve, reject) => { + glob(g, function (er, files) { + if (er) + return reject(er) + resolve(files) + }) + }) + + return Object.keys(files.reduce(function (acc, file) { + file = path.basename(file).replace(/\.[0-9]+$/, '') + file = file.replace(/^npm-/, '') + acc[file] = true + return acc + }, { help: true })) } const npmUsage = require('./utils/npm-usage.js') @@ -175,18 +189,3 @@ function htmlMan (man) { } return 'file://' + path.resolve(__dirname, '..', 'docs', 'output', sect, f + '.html') } - -function getSections (cb) { - const g = path.resolve(__dirname, '../man/man[0-9]/*.[0-9]') - glob(g, function (er, files) { - if (er) - return cb(er) - - cb(null, Object.keys(files.reduce(function (acc, file) { - file = path.basename(file).replace(/\.[0-9]+$/, '') - file = file.replace(/^npm-/, '') - acc[file] = true - return acc - }, { help: true }))) - }) -} diff --git a/deps/npm/lib/hook.js b/deps/npm/lib/hook.js index e0e15243e0..7d69ccbf2a 100644 --- a/deps/npm/lib/hook.js +++ b/deps/npm/lib/hook.js @@ -13,8 +13,6 @@ const usage = usageUtil('hook', [ 'npm hook update <id> <url> <secret>', ].join('\n')) -const completion = require('./utils/completion/none.js') - const cmd = (args, cb) => hook(args).then(() => cb()).catch(cb) const hook = async (args) => otplease(npm.flatOptions, opts => { @@ -127,4 +125,4 @@ const hookName = (hook) => { return target } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/init.js b/deps/npm/lib/init.js index 60ea52e167..a029779f89 100644 --- a/deps/npm/lib/init.js +++ b/deps/npm/lib/init.js @@ -3,7 +3,6 @@ const npa = require('npm-package-arg') const npm = require('./npm.js') const usageUtil = require('./utils/usage.js') -const completion = require('./utils/completion/none.js') const output = require('./utils/output.js') const usage = usageUtil( @@ -86,4 +85,4 @@ const init = async args => { }) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js index d4ee7047f7..5f0137db1c 100644 --- a/deps/npm/lib/install.js +++ b/deps/npm/lib/install.js @@ -81,14 +81,14 @@ const usage = usageUtil( '[--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save]' ) -const completion = async (opts, cb) => { +const completion = async (opts) => { const { partialWord } = opts // install can complete to a folder with a package.json, or any package. // if it has a slash, then it's gotta be a folder // if it starts with https?://, then just give up, because it's a url if (/^https?:\/\//.test(partialWord)) { // do not complete to URLs - return cb(null, []) + return [] } if (/\//.test(partialWord)) { @@ -126,19 +126,18 @@ const completion = async (opts, cb) => { const match = matches.filter(el => !el || el.isPackage).pop() if (match) { // Success - only one match and it is a package dir - return cb(null, [match.fullPath]) + return [match.fullPath] } else { // no matches - return cb(null, []) + return [] } } catch (er) { - return cb(null, []) // invalid dir: no matching + return [] // invalid dir: no matching } } // Note: there used to be registry completion here, // but it stopped making sense somewhere around // 50,000 packages on the registry - cb() } module.exports = Object.assign(cmd, { usage, completion }) diff --git a/deps/npm/lib/link.js b/deps/npm/lib/link.js index 84f36ada66..0bb3d87b5e 100644 --- a/deps/npm/lib/link.js +++ b/deps/npm/lib/link.js @@ -1,4 +1,6 @@ -const { readdir } = require('fs') +const fs = require('fs') +const util = require('util') +const readdir = util.promisify(fs.readdir) const { resolve } = require('path') const Arborist = require('@npmcli/arborist') @@ -10,9 +12,10 @@ const npm = require('./npm.js') const usageUtil = require('./utils/usage.js') const reifyFinish = require('./utils/reify-finish.js') -const completion = (opts, cb) => { +const completion = async (opts) => { const dir = npm.globalDir - readdir(dir, (er, files) => cb(er, files.filter(f => !/^[._-]/.test(f)))) + const files = await readdir(dir) + return files.filter(f => !/^[._-]/.test(f)) } const usage = usageUtil( diff --git a/deps/npm/lib/ll.js b/deps/npm/lib/ll.js index ada260e329..1d5a6217da 100644 --- a/deps/npm/lib/ll.js +++ b/deps/npm/lib/ll.js @@ -1,6 +1,9 @@ const { usage, completion } = require('./ls.js') const npm = require('./npm.js') -module.exports = Object.assign((args, cb) => { + +const cmd = (args, cb) => { npm.config.set('long', true) return npm.commands.ls(args, cb) -}, { usage, completion }) +} + +module.exports = Object.assign(cmd, { usage, completion }) diff --git a/deps/npm/lib/logout.js b/deps/npm/lib/logout.js index ba2eb92fee..d2762c1ba3 100644 --- a/deps/npm/lib/logout.js +++ b/deps/npm/lib/logout.js @@ -4,7 +4,6 @@ const getAuth = require('npm-registry-fetch/auth.js') const npmFetch = require('npm-registry-fetch') const npm = require('./npm.js') const usageUtil = require('./utils/usage.js') -const completion = require('./utils/completion/none.js') const usage = usageUtil( 'logout', @@ -42,4 +41,4 @@ const logout = async (args) => { await npm.config.save('user') } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/org.js b/deps/npm/lib/org.js index b7af3f3a30..aa9c97d497 100644 --- a/deps/npm/lib/org.js +++ b/deps/npm/lib/org.js @@ -13,19 +13,19 @@ org.usage = 'npm org rm orgname username\n' + 'npm org ls orgname [<username>]' -org.completion = function (opts, cb) { +org.completion = async (opts) => { var argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, org.subcommands) + return org.subcommands switch (argv[2]) { case 'ls': case 'add': case 'rm': case 'set': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js index f9a3fed8c1..c10f63a12e 100644 --- a/deps/npm/lib/outdated.js +++ b/deps/npm/lib/outdated.js @@ -17,7 +17,6 @@ const ansiTrim = require('./utils/ansi-trim.js') const usage = usageUtil('outdated', 'npm outdated [[<@scope>/]<pkg> ...]' ) -const completion = require('./utils/completion/none.js') function cmd (args, cb) { outdated(args) @@ -287,4 +286,4 @@ function makeJSON (list, opts) { return JSON.stringify(out, null, 2) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/owner.js b/deps/npm/lib/owner.js index 0bfb0a6a54..6dce3ec70f 100644 --- a/deps/npm/lib/owner.js +++ b/deps/npm/lib/owner.js @@ -16,18 +16,16 @@ const usage = usageUtil( '\nnpm owner ls [<@scope>/]<pkg>' ) -const completion = function (opts, cb) { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv.length > 3) - return cb(null, []) + return [] if (argv[1] !== 'owner') argv.unshift('owner') - if (argv.length === 2) { - var subs = ['add', 'rm', 'ls'] - return cb(null, subs) - } + if (argv.length === 2) + return ['add', 'rm', 'ls'] // reaches registry in order to autocomplete rm if (argv[2] === 'rm') { @@ -35,25 +33,16 @@ const completion = function (opts, cb) { ...npm.flatOptions, fullMetadata: true, } - readLocalPkg() - .then(pkgName => { - if (!pkgName) - return null - - const spec = npa(pkgName) - return pacote.packument(spec, opts) - }) - .then(data => { - if (data && data.maintainers && data.maintainers.length) - return data.maintainers.map(m => m.name) - - return [] - }) - .then(owners => { - return cb(null, owners) - }) - } else - cb(null, []) + const pkgName = await readLocalPkg() + if (!pkgName) + return [] + + const spec = npa(pkgName) + const data = await pacote.packument(spec, opts) + if (data && data.maintainers && data.maintainers.length) + return data.maintainers.map(m => m.name) + } + return [] } const UsageError = () => diff --git a/deps/npm/lib/pack.js b/deps/npm/lib/pack.js index 7a5c2edabc..ff906cc2bd 100644 --- a/deps/npm/lib/pack.js +++ b/deps/npm/lib/pack.js @@ -10,7 +10,6 @@ const { getContents, logTar } = require('./utils/tar.js') const writeFile = util.promisify(require('fs').writeFile) const output = require('./utils/output.js') -const completion = require('./utils/completion/none.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('pack', 'npm pack [[<@scope>/]<pkg>...] [--dry-run]') @@ -47,4 +46,4 @@ const pack_ = async (arg, opts) => { return pkgContents } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/ping.js b/deps/npm/lib/ping.js index 7762be6d29..efa2263103 100644 --- a/deps/npm/lib/ping.js +++ b/deps/npm/lib/ping.js @@ -4,7 +4,6 @@ const output = require('./utils/output.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('ping', 'npm ping\nping registry') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => ping(args).then(() => cb()).catch(cb) const pingUtil = require('./utils/ping.js') @@ -25,4 +24,4 @@ const ping = async args => { log.notice('PONG', `${JSON.stringify(details, null, 2)}`) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/prefix.js b/deps/npm/lib/prefix.js index 0a99144734..d108b9d423 100644 --- a/deps/npm/lib/prefix.js +++ b/deps/npm/lib/prefix.js @@ -1,8 +1,7 @@ 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) => prefix(args).then(() => cb()).catch(cb) const usage = usageUtil('prefix', 'npm prefix [-g]') const prefix = async (args, cb) => output(npm.prefix) -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/profile.js b/deps/npm/lib/profile.js index 24f026ce85..3727ac0c8b 100644 --- a/deps/npm/lib/profile.js +++ b/deps/npm/lib/profile.js @@ -20,25 +20,25 @@ const usage = usageUtil( 'npm profile set <key> <value>' ) -const completion = (opts, cb) => { +const completion = async (opts) => { var argv = opts.conf.argv.remain const subcommands = ['enable-2fa', 'disable-2fa', 'get', 'set'] if (!argv[2]) - return cb(null, subcommands) + return subcommands switch (argv[2]) { case 'enable-2fa': case 'enable-tfa': - return cb(null, ['auth-and-writes', 'auth-only']) + return ['auth-and-writes', 'auth-only'] case 'disable-2fa': case 'disable-tfa': case 'get': case 'set': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/prune.js b/deps/npm/lib/prune.js index ea6ed4108a..228fd3eebb 100644 --- a/deps/npm/lib/prune.js +++ b/deps/npm/lib/prune.js @@ -8,7 +8,6 @@ const reifyFinish = require('./utils/reify-finish.js') const usage = usageUtil('prune', 'npm prune [[<@scope>/]<pkg>...] [--production]' ) -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => prune().then(() => cb()).catch(cb) @@ -22,4 +21,4 @@ const prune = async () => { await reifyFinish(arb) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/publish.js b/deps/npm/lib/publish.js index 3e8df0076e..5ec66d42fa 100644 --- a/deps/npm/lib/publish.js +++ b/deps/npm/lib/publish.js @@ -18,7 +18,6 @@ const { getContents, logTar } = require('./utils/tar.js') // defaults and metadata, like git sha's and default scripts and all that. const readJson = util.promisify(require('read-package-json')) -const completion = require('./utils/completion/none.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('publish', 'npm publish [<folder>] [--tag <tag>] [--access <public|restricted>] [--dry-run]' + @@ -137,4 +136,4 @@ const publish_ = async (arg, opts) => { return pkgContents } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/repo.js b/deps/npm/lib/repo.js index 2dc3bcb1b8..e9074dca68 100644 --- a/deps/npm/lib/repo.js +++ b/deps/npm/lib/repo.js @@ -8,7 +8,6 @@ const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js') const { URL } = require('url') const usage = usageUtil('repo', 'npm repo [<pkgname> [<pkgname> ...]]') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => repo(args).then(() => cb()).catch(cb) @@ -69,4 +68,4 @@ const unknownHostedUrl = url => { } } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/root.js b/deps/npm/lib/root.js index 27e357655c..631aef8386 100644 --- a/deps/npm/lib/root.js +++ b/deps/npm/lib/root.js @@ -1,8 +1,7 @@ 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) => root(args).then(() => cb()).catch(cb) const usage = usageUtil('root', 'npm root [-g]') const root = async (args, cb) => output(npm.dir) -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/run-script.js b/deps/npm/lib/run-script.js index 8e24a8a44e..4dfb854cad 100644 --- a/deps/npm/lib/run-script.js +++ b/deps/npm/lib/run-script.js @@ -14,16 +14,14 @@ const usage = usageUtil( 'npm run-script <command> [-- <args>]' ) -const completion = async (opts, cb) => { +const completion = async (opts) => { const argv = opts.conf.argv.remain if (argv.length === 2) { // find the script name const json = resolve(npm.localPrefix, 'package.json') const { scripts = {} } = await readJson(json).catch(er => ({})) - return cb(null, Object.keys(scripts)) + return Object.keys(scripts) } - // otherwise nothing to do, just let the system handle it - return cb() } const cmd = (args, cb) => { diff --git a/deps/npm/lib/search.js b/deps/npm/lib/search.js index a3d806d2f1..3f8fd99fb8 100644 --- a/deps/npm/lib/search.js +++ b/deps/npm/lib/search.js @@ -8,7 +8,6 @@ const packageFilter = require('./search/package-filter.js') 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 usage = usageUtil( 'search', @@ -86,4 +85,4 @@ function prepareExcludes (searchexclude) { .filter(s => s) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/set-script.js b/deps/npm/lib/set-script.js index f655c22107..7bac6eca50 100644 --- a/deps/npm/lib/set-script.js +++ b/deps/npm/lib/set-script.js @@ -3,7 +3,6 @@ const usageUtil = require('./utils/usage.js') const { localPrefix } = require('./npm.js') const fs = require('fs') const usage = usageUtil('set-script', 'npm set-script [<script>] [<command>]') -const completion = require('./utils/completion/none.js') const parseJSON = require('json-parse-even-better-errors') const rpj = require('read-package-json-fast') @@ -50,4 +49,4 @@ const set = async function (args) { log.warn('set-script', `Script "${args[0]}" was overwritten`) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/set.js b/deps/npm/lib/set.js index fd60762932..3d61c1e93e 100644 --- a/deps/npm/lib/set.js +++ b/deps/npm/lib/set.js @@ -1,14 +1,14 @@ +const npm = require('./npm.js') +const config = require('./config.js') -module.exports = set +const usage = 'npm set <key>=<value> [<key>=<value> ...] (See `npm config`)' -set.usage = 'npm set <key>=<value> [<key>=<value> ...] (See `npm config`)' +const completion = config.completion -var npm = require('./npm.js') - -set.completion = npm.commands.config.completion - -function set (args, cb) { +const cmd = (args, cb) => { if (!args.length) - return cb(set.usage) + return cb(usage) npm.commands.config(['set'].concat(args), cb) } + +module.exports = Object.assign(cmd, { usage, completion }) diff --git a/deps/npm/lib/shrinkwrap.js b/deps/npm/lib/shrinkwrap.js index f1146206db..8768f35b5f 100644 --- a/deps/npm/lib/shrinkwrap.js +++ b/deps/npm/lib/shrinkwrap.js @@ -6,7 +6,6 @@ const Arborist = require('@npmcli/arborist') const log = require('npmlog') const npm = require('./npm.js') -const completion = require('./utils/completion/none.js') const usageUtil = require('./utils/usage.js') const usage = usageUtil('shrinkwrap', 'npm shrinkwrap') @@ -50,4 +49,4 @@ const shrinkwrap = async () => { log.notice('', 'npm-shrinkwrap.json up to date') } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/star.js b/deps/npm/lib/star.js index b3e72d7da3..c02fdeed89 100644 --- a/deps/npm/lib/star.js +++ b/deps/npm/lib/star.js @@ -6,7 +6,6 @@ const npm = require('./npm.js') const output = require('./utils/output.js') const usageUtil = require('./utils/usage.js') const getIdentity = require('./utils/get-identity') -const completion = require('./utils/completion/none.js') const usage = usageUtil( 'star', @@ -72,4 +71,4 @@ const star = async args => { } } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/stars.js b/deps/npm/lib/stars.js index c09ca6003e..d1c2b73fb1 100644 --- a/deps/npm/lib/stars.js +++ b/deps/npm/lib/stars.js @@ -5,7 +5,6 @@ const npm = require('./npm.js') const output = require('./utils/output.js') const getIdentity = require('./utils/get-identity.js') const usageUtil = require('./utils/usage.js') -const completion = require('./utils/completion/none.js') const usage = usageUtil('stars', 'npm stars [<user>]') @@ -33,4 +32,4 @@ const stars_ = async ([user = getIdentity(npm.flatOptions)]) => { output(row.value) } -module.exports = Object.assign(cmd, { usage, completion }) +module.exports = Object.assign(cmd, { usage }) diff --git a/deps/npm/lib/team.js b/deps/npm/lib/team.js index 5e88011cfe..24e8360b64 100644 --- a/deps/npm/lib/team.js +++ b/deps/npm/lib/team.js @@ -17,10 +17,10 @@ const usage = usageUtil( 'npm team ls <scope>|<scope:team>\n' ) -const completion = (opts, cb) => { +const completion = async (opts) => { const { conf: { argv: { remain: argv } } } = opts if (argv.length === 2) - return cb(null, subcommands) + return subcommands switch (argv[2]) { case 'ls': @@ -28,9 +28,9 @@ const completion = (opts, cb) => { case 'destroy': case 'add': case 'rm': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/token.js b/deps/npm/lib/token.js index b737b5ffbc..1e78584c77 100644 --- a/deps/npm/lib/token.js +++ b/deps/npm/lib/token.js @@ -30,18 +30,18 @@ const InvalidCIDRError = (msg) => token.subcommands = ['list', 'revoke', 'create'] -token.completion = function (opts, cb) { +token.completion = async (opts) => { var argv = opts.conf.argv.remain if (argv.length === 2) - return cb(null, token.subcommands) + return token.subcommands switch (argv[2]) { case 'list': case 'revoke': case 'create': - return cb(null, []) + return [] default: - return cb(new Error(argv[2] + ' not recognized')) + throw new Error(argv[2] + ' not recognized') } } diff --git a/deps/npm/lib/unpublish.js b/deps/npm/lib/unpublish.js index 528208c396..bb931682b4 100644 --- a/deps/npm/lib/unpublish.js +++ b/deps/npm/lib/unpublish.js @@ -17,11 +17,7 @@ const usage = usageUtil('unpublish', 'npm unpublish [<@scope>/]<pkg>[@<version>] const cmd = (args, cb) => unpublish(args).then(() => cb()).catch(cb) -const completion = (args, cb) => completionFn(args) - .then((res) => cb(null, res)) - .catch(cb) - -const completionFn = async (args) => { +const completion = async (args) => { const { partialWord, conf } = args if (conf.argv.remain.length >= 3) diff --git a/deps/npm/lib/unstar.js b/deps/npm/lib/unstar.js index 5dea5bcab0..554bd60bc9 100644 --- a/deps/npm/lib/unstar.js +++ b/deps/npm/lib/unstar.js @@ -1,4 +1,4 @@ -const { usage, completion } = require('./star.js') +const { usage } = require('./star.js') const npm = require('./npm.js') const unstar = (args, cb) => { @@ -6,4 +6,4 @@ const unstar = (args, cb) => { return npm.commands.star(args, cb) } -module.exports = Object.assign(unstar, { usage, completion }) +module.exports = Object.assign(unstar, { usage }) diff --git a/deps/npm/lib/utils/completion/installed-deep.js b/deps/npm/lib/utils/completion/installed-deep.js index 793f3b3e9a..f464bb9a9d 100644 --- a/deps/npm/lib/utils/completion/installed-deep.js +++ b/deps/npm/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/deps/npm/lib/utils/completion/installed-shallow.js b/deps/npm/lib/utils/completion/installed-shallow.js index e2ff5a3025..c9c680e7dd 100644 --- a/deps/npm/lib/utils/completion/installed-shallow.js +++ b/deps/npm/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/deps/npm/lib/utils/completion/none.js b/deps/npm/lib/utils/completion/none.js deleted file mode 100644 index 752400da46..0000000000 --- a/deps/npm/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/deps/npm/lib/utils/explain-dep.js b/deps/npm/lib/utils/explain-dep.js index ed69a02c14..213493c654 100644 --- a/deps/npm/lib/utils/explain-dep.js +++ b/deps/npm/lib/utils/explain-dep.js @@ -6,6 +6,7 @@ const nocolor = { yellow: s => s, cyan: s => s, magenta: s => s, + blue: s => s, } const explainNode = (node, depth, color) => @@ -13,11 +14,12 @@ const explainNode = (node, depth, color) => explainDependents(node, depth, color) const colorType = (type, color) => { - const { red, yellow, cyan, magenta } = color ? chalk : nocolor + const { red, yellow, cyan, magenta, blue } = color ? chalk : nocolor const style = type === 'extraneous' ? red : type === 'dev' ? yellow : type === 'optional' ? cyan : type === 'peer' ? magenta + : type === 'bundled' ? blue : /* istanbul ignore next */ s => s return style(type) } @@ -31,6 +33,7 @@ const printNode = (node, color) => { dev, optional, peer, + bundled, } = node const { bold, dim } = color ? chalk : nocolor const extra = [] @@ -46,6 +49,9 @@ const printNode = (node, color) => { if (peer) extra.push(' ' + bold(colorType('peer', color))) + if (bundled) + extra.push(' ' + bold(colorType('bundled', color))) + return `${bold(name)}@${bold(version)}${extra.join('')}` + (location ? dim(`\n${location}`) : '') } diff --git a/deps/npm/lib/utils/lifecycle-cmd.js b/deps/npm/lib/utils/lifecycle-cmd.js index 83a712cf40..94b109942a 100644 --- a/deps/npm/lib/utils/lifecycle-cmd.js +++ b/deps/npm/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} [-- <args>]`) - return Object.assign(cmd, { usage, completion }) + return Object.assign(cmd, { usage }) } diff --git a/deps/npm/lib/version.js b/deps/npm/lib/version.js index 3a46efae19..9d87b2f2c9 100644 --- a/deps/npm/lib/version.js +++ b/deps/npm/lib/version.js @@ -3,13 +3,12 @@ const npm = require('./npm.js') const output = require('./utils/output.js') const usageUtil = require('./utils/usage.js') -const completion = (opts, cb) => { - const none = require('./utils/completion/none.js') +const completion = async (opts) => { const { conf: { argv: { remain } } } = opts if (remain.length > 2) - return none(opts, cb) + return [] - return cb(null, [ + return [ 'major', 'minor', 'patch', @@ -18,7 +17,7 @@ const completion = (opts, cb) => { 'prepatch', 'prerelease', 'from-git', - ]) + ] } const usage = usageUtil('version', diff --git a/deps/npm/lib/view.js b/deps/npm/lib/view.js index bc9a13d85d..d6d79d35c5 100644 --- a/deps/npm/lib/view.js +++ b/deps/npm/lib/view.js @@ -26,11 +26,11 @@ const usage = usageUtil( const cmd = (args, cb) => view(args).then(() => cb()).catch(cb) -const completion = async (opts, cb) => { +const completion = async (opts) => { if (opts.conf.argv.remain.length <= 2) { // There used to be registry completion here, but it stopped // making sense somewhere around 50,000 packages on the registry - return cb() + return } // have the package, get the fields const config = { ...npm.flatOptions, fullMetadata: true, preferOnline: true } @@ -39,8 +39,8 @@ const completion = async (opts, cb) => { const pckmnt = await packument(spec, config) const dv = pckmnt.versions[pckmnt['dist-tags'][defaultTag]] pckmnt.versions = Object.keys(pckmnt.versions).sort(semver.compareLoose) - const fields = getFields(pckmnt).concat(getFields(dv)) - return cb(null, fields) + + return getFields(pckmnt).concat(getFields(dv)) function getFields (d, f, pref) { f = f || [] diff --git a/deps/npm/lib/whoami.js b/deps/npm/lib/whoami.js index 8e1c1d0523..bbbc39ccec 100644 --- a/deps/npm/lib/whoami.js +++ b/deps/npm/lib/whoami.js @@ -2,7 +2,6 @@ const npm = require('./npm.js') const output = require('./utils/output.js') const getIdentity = require('./utils/get-identity.js') const usageUtil = require('./utils/usage.js') -const completion = require('./utils/completion/none.js') const cmd = (args, cb) => whoami(args).then(() => cb()).catch(cb) @@ -14,4 +13,4 @@ const whoami = async ([spec]) => { output(opts.json ? JSON.stringify(username) : username) } -module.exports = Object.assign(cmd, { completion, usage }) +module.exports = Object.assign(cmd, { usage }) |