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:
authorGar <gar+gh@danger.computer>2022-03-24 17:18:56 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-03-28 23:21:36 +0300
commitd8dcc02cfd354c1314c45d6530ec926cd138210c (patch)
treeba3721d4c4f153fe005bf9e08d450d9e2473a9a4
parenta64acc0bf01e4bc68b26ead5b2d5c6db47ef16c2 (diff)
fix: consolidate command alias code
-rw-r--r--docs/content/commands/npm-install.md2
-rw-r--r--docs/content/commands/npm-search.md2
-rw-r--r--docs/content/commands/npm-uninstall.md2
-rw-r--r--docs/content/commands/npm-view.md2
-rw-r--r--lib/commands/completion.js7
-rw-r--r--lib/npm.js23
-rw-r--r--lib/utils/cmd-list.js158
-rw-r--r--lib/utils/deref-command.js31
-rw-r--r--lib/utils/npm-usage.js2
-rw-r--r--tap-snapshots/test/lib/commands/completion.js.test.cjs136
-rw-r--r--tap-snapshots/test/lib/load-all-commands.js.test.cjs8
-rw-r--r--tap-snapshots/test/lib/utils/cmd-list.js.test.cjs508
-rw-r--r--tap-snapshots/test/lib/utils/npm-usage.js.test.cjs8
-rw-r--r--test/lib/npm.js12
-rw-r--r--test/lib/utils/deref-command.js9
15 files changed, 587 insertions, 323 deletions
diff --git a/docs/content/commands/npm-install.md b/docs/content/commands/npm-install.md
index 06c243f06..328d6fc14 100644
--- a/docs/content/commands/npm-install.md
+++ b/docs/content/commands/npm-install.md
@@ -22,7 +22,7 @@ npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>
-aliases: i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall, add
+aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
```
<!-- automatically generated, do not edit manually -->
diff --git a/docs/content/commands/npm-search.md b/docs/content/commands/npm-search.md
index db6a12baf..340dea968 100644
--- a/docs/content/commands/npm-search.md
+++ b/docs/content/commands/npm-search.md
@@ -13,7 +13,7 @@ description: Search for packages
```bash
npm search [search terms ...]
-aliases: s, se, find
+aliases: find, s, se
```
<!-- automatically generated, do not edit manually -->
diff --git a/docs/content/commands/npm-uninstall.md b/docs/content/commands/npm-uninstall.md
index 8132bf6bc..9316c686d 100644
--- a/docs/content/commands/npm-uninstall.md
+++ b/docs/content/commands/npm-uninstall.md
@@ -13,7 +13,7 @@ description: Remove a package
```bash
npm uninstall [<@scope>/]<pkg>...
-aliases: un, unlink, remove, rm, r
+aliases: unlink, remove, rm, r, un
```
<!-- automatically generated, do not edit manually -->
diff --git a/docs/content/commands/npm-view.md b/docs/content/commands/npm-view.md
index 53ca408a0..b50b4bfb5 100644
--- a/docs/content/commands/npm-view.md
+++ b/docs/content/commands/npm-view.md
@@ -13,7 +13,7 @@ description: View registry info
```bash
npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]
-aliases: v, info, show
+aliases: info, show, v
```
<!-- automatically generated, do not edit manually -->
diff --git a/lib/commands/completion.js b/lib/commands/completion.js
index 0317753a1..22f91b0ae 100644
--- a/lib/commands/completion.js
+++ b/lib/commands/completion.js
@@ -30,7 +30,6 @@
//
const { definitions, shorthands } = require('../utils/config/index.js')
-const deref = require('../utils/deref-command.js')
const { aliases, cmdList, plumbing } = require('../utils/cmd-list.js')
const aliasNames = Object.keys(aliases)
const fullList = cmdList.concat(aliasNames).filter(c => !plumbing.includes(c))
@@ -152,7 +151,7 @@ class Completion extends BaseCommand {
// check if there's a command already.
const cmd = parsed.argv.remain[1]
if (!cmd) {
- return this.wrap(opts, cmdCompl(opts))
+ return this.wrap(opts, cmdCompl(opts, this.npm))
}
Object.keys(parsed).forEach(k => this.npm.config.set(k, parsed[k]))
@@ -269,13 +268,13 @@ const isFlag = word => {
// complete against the npm commands
// if they all resolve to the same thing, just return the thing it already is
-const cmdCompl = opts => {
+const cmdCompl = (opts, npm) => {
const matches = fullList.filter(c => c.startsWith(opts.partialWord))
if (!matches.length) {
return matches
}
- const derefs = new Set([...matches.map(c => deref(c))])
+ const derefs = new Set([...matches.map(c => npm.deref(c))])
if (derefs.size === 1) {
return [...derefs]
}
diff --git a/lib/npm.js b/lib/npm.js
index fb4fb8d13..74825c97c 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -11,7 +11,6 @@ const usage = require('./utils/npm-usage.js')
const which = require('which')
const fs = require('@npmcli/fs')
-const deref = require('./utils/deref-command.js')
const LogFile = require('./utils/log-file.js')
const Timers = require('./utils/timers.js')
const Display = require('./utils/display.js')
@@ -19,6 +18,7 @@ const log = require('./utils/log-shim')
const replaceInfo = require('./utils/replace-info.js')
const updateNotifier = require('./utils/update-notifier.js')
const pkg = require('../package.json')
+const cmdList = require('./utils/cmd-list.js')
let warnedNonDashArg = false
const _load = Symbol('_load')
@@ -31,7 +31,6 @@ class Npm extends EventEmitter {
command = null
updateNotification = null
loadErr = null
- deref = deref
argv = []
#loadPromise = null
@@ -61,6 +60,26 @@ class Npm extends EventEmitter {
return this.constructor.version
}
+ deref (c) {
+ if (!c) {
+ return
+ }
+ if (c.match(/[A-Z]/)) {
+ c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase())
+ }
+ if (cmdList.plumbing.indexOf(c) !== -1) {
+ return c
+ }
+ // first deref the abbrev, if there is one
+ // then resolve any aliases
+ // so `npm install-cl` will resolve to `install-clean` then to `ci`
+ let a = cmdList.abbrevs[c]
+ while (cmdList.aliases[a]) {
+ a = cmdList.aliases[a]
+ }
+ return a
+ }
+
// Get an instantiated npm command
// npm.command is already taken as the currently running command, a refactor
// would be needed to change this
diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js
index 1469ebdd6..c1d20186a 100644
--- a/lib/utils/cmd-list.js
+++ b/lib/utils/cmd-list.js
@@ -1,5 +1,23 @@
-// short names for common things
-const shorthands = {
+const abbrev = require('abbrev')
+
+// plumbing should not have any aliases
+const aliases = {
+
+ // aliases
+ login: 'adduser',
+ author: 'owner',
+ home: 'docs',
+ issues: 'bugs',
+ info: 'view',
+ show: 'view',
+ find: 'search',
+ add: 'install',
+ unlink: 'uninstall',
+ remove: 'uninstall',
+ rm: 'uninstall',
+ r: 'uninstall',
+
+ // short names for common things
un: 'uninstall',
rb: 'rebuild',
list: 'ls',
@@ -21,12 +39,11 @@ const shorthands = {
'clean-install-test': 'cit',
x: 'exec',
why: 'explain',
-}
-
-const affordances = {
la: 'll',
verison: 'version',
ic: 'ci',
+
+ // typos
innit: 'init',
// manually abbrev so that install-test doesn't make insta stop working
in: 'install',
@@ -44,105 +61,90 @@ const affordances = {
'dist-tags': 'dist-tag',
upgrade: 'update',
udpate: 'update',
- login: 'adduser',
- 'add-user': 'adduser',
- author: 'owner',
- home: 'docs',
- issues: 'bugs',
- info: 'view',
- show: 'view',
- find: 'search',
- add: 'install',
- unlink: 'uninstall',
- remove: 'uninstall',
- rm: 'uninstall',
- r: 'uninstall',
rum: 'run-script',
sit: 'cit',
urn: 'run-script',
ogr: 'org',
+ 'add-user': 'adduser',
}
// these are filenames in .
+// Keep these sorted so that lib/utils/npm-usage.js outputs in order
const cmdList = [
- 'ci',
- 'install-ci-test',
- 'install',
- 'install-test',
- 'uninstall',
+ 'access',
+ 'adduser',
+ 'audit',
+ 'bin',
+ 'bugs',
'cache',
+ 'ci',
+ 'completion',
'config',
- 'set',
- 'get',
- 'update',
- 'outdated',
- 'prune',
- 'pack',
- 'find-dupes',
'dedupe',
+ 'deprecate',
+ 'diff',
+ 'dist-tag',
+ 'docs',
+ 'doctor',
+ 'edit',
+ 'exec',
+ 'explain',
+ 'explore',
+ 'find-dupes',
+ 'fund',
+ 'get',
+ 'help',
'hook',
-
- 'rebuild',
+ 'init',
+ 'install',
+ 'install-ci-test',
+ 'install-test',
'link',
-
- 'publish',
- 'star',
- 'stars',
- 'unstar',
- 'adduser',
+ 'll',
'login', // This is an alias for `adduser` but it can be confusing
'logout',
- 'unpublish',
- 'owner',
- 'access',
- 'team',
- 'deprecate',
- 'shrinkwrap',
- 'token',
- 'profile',
- 'audit',
- 'fund',
- 'org',
-
- 'help',
'ls',
- 'll',
- 'search',
- 'view',
- 'init',
- 'version',
- 'edit',
- 'explore',
- 'docs',
- 'repo',
- 'bugs',
- 'root',
- 'prefix',
- 'bin',
- 'whoami',
- 'diff',
- 'dist-tag',
+ 'org',
+ 'outdated',
+ 'owner',
+ 'pack',
'ping',
'pkg',
-
- 'test',
- 'stop',
- 'start',
+ 'prefix',
+ 'profile',
+ 'prune',
+ 'publish',
+ 'rebuild',
+ 'repo',
'restart',
+ 'root',
'run-script',
+ 'search',
+ 'set',
'set-script',
- 'completion',
- 'doctor',
- 'exec',
- 'explain',
+ 'shrinkwrap',
+ 'star',
+ 'stars',
+ 'start',
+ 'stop',
+ 'team',
+ 'test',
+ 'token',
+ 'uninstall',
+ 'unpublish',
+ 'unstar',
+ 'update',
+ 'version',
+ 'view',
+ 'whoami',
]
const plumbing = ['birthday', 'help-search']
+const abbrevs = abbrev(cmdList.concat(Object.keys(aliases)))
module.exports = {
- aliases: Object.assign({}, shorthands, affordances),
- shorthands,
- affordances,
+ abbrevs,
+ aliases,
cmdList,
plumbing,
}
diff --git a/lib/utils/deref-command.js b/lib/utils/deref-command.js
deleted file mode 100644
index 0a3c8c90b..000000000
--- a/lib/utils/deref-command.js
+++ /dev/null
@@ -1,31 +0,0 @@
-// de-reference abbreviations and shorthands into canonical command name
-
-const { aliases, cmdList, plumbing } = require('./cmd-list.js')
-const aliasNames = Object.keys(aliases)
-const fullList = cmdList.concat(aliasNames).filter(c => !plumbing.includes(c))
-const abbrev = require('abbrev')
-const abbrevs = abbrev(fullList)
-
-module.exports = c => {
- if (!c || typeof c !== 'string') {
- return ''
- }
-
- if (c.match(/[A-Z]/)) {
- c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase())
- }
-
- if (plumbing.indexOf(c) !== -1) {
- return c
- }
-
- // first deref the abbrev, if there is one
- // then resolve any aliases
- // so `npm install-cl` will resolve to `install-clean` then to `ci`
- let a = abbrevs[c]
- while (aliases[a]) {
- a = aliases[a]
- }
-
- return a || ''
-}
diff --git a/lib/utils/npm-usage.js b/lib/utils/npm-usage.js
index b0c98b2ae..8d31f0155 100644
--- a/lib/utils/npm-usage.js
+++ b/lib/utils/npm-usage.js
@@ -45,7 +45,7 @@ const wrap = (arr) => {
: Math.min(60, Math.max(process.stdout.columns - 16, 24))
let l = 0
- for (const c of arr.sort((a, b) => a < b ? -1 : 1)) {
+ for (const c of arr) {
if (out[l].length + c.length + 2 < line) {
out[l] += ', ' + c
} else {
diff --git a/tap-snapshots/test/lib/commands/completion.js.test.cjs b/tap-snapshots/test/lib/commands/completion.js.test.cjs
index 4fa3a2179..232cfec66 100644
--- a/tap-snapshots/test/lib/commands/completion.js.test.cjs
+++ b/tap-snapshots/test/lib/commands/completion.js.test.cjs
@@ -44,72 +44,84 @@ exports[`test/lib/commands/completion.js TAP completion double dashes escape fro
Array [
Array [
String(
- ci
- install-ci-test
- install
- install-test
- uninstall
+ access
+ adduser
+ audit
+ bin
+ bugs
cache
+ ci
+ completion
config
- set
- get
- update
- outdated
- prune
- pack
- find-dupes
dedupe
+ deprecate
+ diff
+ dist-tag
+ docs
+ doctor
+ edit
+ exec
+ explain
+ explore
+ find-dupes
+ fund
+ get
+ help
hook
- rebuild
+ init
+ install
+ install-ci-test
+ install-test
link
- publish
- star
- stars
- unstar
- adduser
+ ll
login
logout
- unpublish
- owner
- access
- team
- deprecate
- shrinkwrap
- token
- profile
- audit
- fund
- org
- help
ls
- ll
- search
- view
- init
- version
- edit
- explore
- docs
- repo
- bugs
- root
- prefix
- bin
- whoami
- diff
- dist-tag
+ org
+ outdated
+ owner
+ pack
ping
pkg
- test
- stop
- start
+ prefix
+ profile
+ prune
+ publish
+ rebuild
+ repo
restart
+ root
run-script
+ search
+ set
set-script
- completion
- doctor
- exec
- explain
+ shrinkwrap
+ star
+ stars
+ start
+ stop
+ team
+ test
+ token
+ uninstall
+ unpublish
+ unstar
+ update
+ version
+ view
+ whoami
+ login
+ author
+ home
+ issues
+ info
+ show
+ find
+ add
+ unlink
+ remove
+ rm
+ r
un
rb
list
@@ -150,23 +162,11 @@ Array [
dist-tags
upgrade
udpate
- login
- add-user
- author
- home
- issues
- info
- show
- find
- add
- unlink
- remove
- rm
- r
rum
sit
urn
ogr
+ add-user
),
],
]
@@ -198,12 +198,12 @@ exports[`test/lib/commands/completion.js TAP completion multiple command names >
Array [
Array [
String(
- adduser
access
+ adduser
audit
- add-user
author
add
+ add-user
),
],
]
diff --git a/tap-snapshots/test/lib/load-all-commands.js.test.cjs b/tap-snapshots/test/lib/load-all-commands.js.test.cjs
index 550c59613..0ad87b945 100644
--- a/tap-snapshots/test/lib/load-all-commands.js.test.cjs
+++ b/tap-snapshots/test/lib/load-all-commands.js.test.cjs
@@ -426,7 +426,7 @@ Options:
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
-aliases: i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall, add
+aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
Run "npm help install" for more info
`
@@ -784,7 +784,7 @@ Options:
[--no-description] [--searchopts <searchopts>] [--searchexclude <searchexclude>]
[--registry <registry>] [--prefer-online] [--prefer-offline] [--offline]
-aliases: s, se, find
+aliases: find, s, se
Run "npm help search" for more info
`
@@ -924,7 +924,7 @@ Options:
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
-aliases: un, unlink, remove, rm, r
+aliases: unlink, remove, rm, r, un
Run "npm help uninstall" for more info
`
@@ -1002,7 +1002,7 @@ Options:
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
-aliases: v, info, show
+aliases: info, show, v
Run "npm help view" for more info
`
diff --git a/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs b/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs
index e5935846e..9413f8e9a 100644
--- a/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs
+++ b/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs
@@ -7,43 +7,348 @@
'use strict'
exports[`test/lib/utils/cmd-list.js TAP > must match snapshot 1`] = `
Object {
- "affordances": Object {
- "add": "install",
- "add-user": "adduser",
- "author": "owner",
- "dist-tags": "dist-tag",
- "find": "search",
- "hlep": "help",
- "home": "docs",
- "ic": "ci",
- "in": "install",
- "info": "view",
- "innit": "init",
- "ins": "install",
- "inst": "install",
- "insta": "install",
- "instal": "install",
- "install-clean": "ci",
- "isnt": "install",
- "isnta": "install",
- "isntal": "install",
- "isntall": "install",
- "isntall-clean": "ci",
- "issues": "bugs",
- "la": "ll",
- "login": "adduser",
- "ogr": "org",
- "r": "uninstall",
- "remove": "uninstall",
- "rm": "uninstall",
- "rum": "run-script",
- "show": "view",
- "sit": "cit",
- "udpate": "update",
- "unlink": "uninstall",
- "upgrade": "update",
- "urn": "run-script",
- "verison": "version",
+ "abbrevs": Object {
+ "ac": "access",
+ "acc": "access",
+ "acce": "access",
+ "acces": "access",
+ "access": "access",
+ "add": "add",
+ "add-": "add-user",
+ "add-u": "add-user",
+ "add-us": "add-user",
+ "add-use": "add-user",
+ "add-user": "add-user",
+ "addu": "adduser",
+ "addus": "adduser",
+ "adduse": "adduser",
+ "adduser": "adduser",
+ "aud": "audit",
+ "audi": "audit",
+ "audit": "audit",
+ "aut": "author",
+ "auth": "author",
+ "autho": "author",
+ "author": "author",
+ "bi": "bin",
+ "bin": "bin",
+ "bu": "bugs",
+ "bug": "bugs",
+ "bugs": "bugs",
+ "c": "c",
+ "ca": "cache",
+ "cac": "cache",
+ "cach": "cache",
+ "cache": "cache",
+ "ci": "ci",
+ "cit": "cit",
+ "clean-install": "clean-install",
+ "clean-install-": "clean-install-test",
+ "clean-install-t": "clean-install-test",
+ "clean-install-te": "clean-install-test",
+ "clean-install-tes": "clean-install-test",
+ "clean-install-test": "clean-install-test",
+ "com": "completion",
+ "comp": "completion",
+ "compl": "completion",
+ "comple": "completion",
+ "complet": "completion",
+ "completi": "completion",
+ "completio": "completion",
+ "completion": "completion",
+ "con": "config",
+ "conf": "config",
+ "confi": "config",
+ "config": "config",
+ "cr": "create",
+ "cre": "create",
+ "crea": "create",
+ "creat": "create",
+ "create": "create",
+ "dd": "ddp",
+ "ddp": "ddp",
+ "ded": "dedupe",
+ "dedu": "dedupe",
+ "dedup": "dedupe",
+ "dedupe": "dedupe",
+ "dep": "deprecate",
+ "depr": "deprecate",
+ "depre": "deprecate",
+ "deprec": "deprecate",
+ "depreca": "deprecate",
+ "deprecat": "deprecate",
+ "deprecate": "deprecate",
+ "dif": "diff",
+ "diff": "diff",
+ "dist-tag": "dist-tag",
+ "dist-tags": "dist-tags",
+ "docs": "docs",
+ "doct": "doctor",
+ "docto": "doctor",
+ "doctor": "doctor",
+ "ed": "edit",
+ "edi": "edit",
+ "edit": "edit",
+ "exe": "exec",
+ "exec": "exec",
+ "expla": "explain",
+ "explai": "explain",
+ "explain": "explain",
+ "explo": "explore",
+ "explor": "explore",
+ "explore": "explore",
+ "find": "find",
+ "find-": "find-dupes",
+ "find-d": "find-dupes",
+ "find-du": "find-dupes",
+ "find-dup": "find-dupes",
+ "find-dupe": "find-dupes",
+ "find-dupes": "find-dupes",
+ "fu": "fund",
+ "fun": "fund",
+ "fund": "fund",
+ "g": "get",
+ "ge": "get",
+ "get": "get",
+ "he": "help",
+ "hel": "help",
+ "help": "help",
+ "hl": "hlep",
+ "hle": "hlep",
+ "hlep": "hlep",
+ "hom": "home",
+ "home": "home",
+ "hoo": "hook",
+ "hook": "hook",
+ "i": "i",
+ "ic": "ic",
+ "in": "in",
+ "inf": "info",
+ "info": "info",
+ "ini": "init",
+ "init": "init",
+ "inn": "innit",
+ "inni": "innit",
+ "innit": "innit",
+ "ins": "ins",
+ "inst": "inst",
+ "insta": "insta",
+ "instal": "instal",
+ "install": "install",
+ "install-ci": "install-ci-test",
+ "install-ci-": "install-ci-test",
+ "install-ci-t": "install-ci-test",
+ "install-ci-te": "install-ci-test",
+ "install-ci-tes": "install-ci-test",
+ "install-ci-test": "install-ci-test",
+ "install-cl": "install-clean",
+ "install-cle": "install-clean",
+ "install-clea": "install-clean",
+ "install-clean": "install-clean",
+ "install-t": "install-test",
+ "install-te": "install-test",
+ "install-tes": "install-test",
+ "install-test": "install-test",
+ "isnt": "isnt",
+ "isnta": "isnta",
+ "isntal": "isntal",
+ "isntall": "isntall",
+ "isntall-": "isntall-clean",
+ "isntall-c": "isntall-clean",
+ "isntall-cl": "isntall-clean",
+ "isntall-cle": "isntall-clean",
+ "isntall-clea": "isntall-clean",
+ "isntall-clean": "isntall-clean",
+ "iss": "issues",
+ "issu": "issues",
+ "issue": "issues",
+ "issues": "issues",
+ "it": "it",
+ "la": "la",
+ "lin": "link",
+ "link": "link",
+ "lis": "list",
+ "list": "list",
+ "ll": "ll",
+ "ln": "ln",
+ "logi": "login",
+ "login": "login",
+ "logo": "logout",
+ "logou": "logout",
+ "logout": "logout",
+ "ls": "ls",
+ "og": "ogr",
+ "ogr": "ogr",
+ "or": "org",
+ "org": "org",
+ "ou": "outdated",
+ "out": "outdated",
+ "outd": "outdated",
+ "outda": "outdated",
+ "outdat": "outdated",
+ "outdate": "outdated",
+ "outdated": "outdated",
+ "ow": "owner",
+ "own": "owner",
+ "owne": "owner",
+ "owner": "owner",
+ "pa": "pack",
+ "pac": "pack",
+ "pack": "pack",
+ "pi": "ping",
+ "pin": "ping",
+ "ping": "ping",
+ "pk": "pkg",
+ "pkg": "pkg",
+ "pre": "prefix",
+ "pref": "prefix",
+ "prefi": "prefix",
+ "prefix": "prefix",
+ "pro": "profile",
+ "prof": "profile",
+ "profi": "profile",
+ "profil": "profile",
+ "profile": "profile",
+ "pru": "prune",
+ "prun": "prune",
+ "prune": "prune",
+ "pu": "publish",
+ "pub": "publish",
+ "publ": "publish",
+ "publi": "publish",
+ "publis": "publish",
+ "publish": "publish",
+ "r": "r",
+ "rb": "rb",
+ "reb": "rebuild",
+ "rebu": "rebuild",
+ "rebui": "rebuild",
+ "rebuil": "rebuild",
+ "rebuild": "rebuild",
+ "rem": "remove",
+ "remo": "remove",
+ "remov": "remove",
+ "remove": "remove",
+ "rep": "repo",
+ "repo": "repo",
+ "res": "restart",
+ "rest": "restart",
+ "resta": "restart",
+ "restar": "restart",
+ "restart": "restart",
+ "rm": "rm",
+ "ro": "root",
+ "roo": "root",
+ "root": "root",
+ "rum": "rum",
+ "run": "run",
+ "run-": "run-script",
+ "run-s": "run-script",
+ "run-sc": "run-script",
+ "run-scr": "run-script",
+ "run-scri": "run-script",
+ "run-scrip": "run-script",
+ "run-script": "run-script",
+ "s": "s",
+ "se": "se",
+ "sea": "search",
+ "sear": "search",
+ "searc": "search",
+ "search": "search",
+ "set": "set",
+ "set-": "set-script",
+ "set-s": "set-script",
+ "set-sc": "set-script",
+ "set-scr": "set-script",
+ "set-scri": "set-script",
+ "set-scrip": "set-script",
+ "set-script": "set-script",
+ "sho": "show",
+ "show": "show",
+ "shr": "shrinkwrap",
+ "shri": "shrinkwrap",
+ "shrin": "shrinkwrap",
+ "shrink": "shrinkwrap",
+ "shrinkw": "shrinkwrap",
+ "shrinkwr": "shrinkwrap",
+ "shrinkwra": "shrinkwrap",
+ "shrinkwrap": "shrinkwrap",
+ "si": "sit",
+ "sit": "sit",
+ "star": "star",
+ "stars": "stars",
+ "start": "start",
+ "sto": "stop",
+ "stop": "stop",
+ "t": "t",
+ "tea": "team",
+ "team": "team",
+ "tes": "test",
+ "test": "test",
+ "to": "token",
+ "tok": "token",
+ "toke": "token",
+ "token": "token",
+ "ts": "tst",
+ "tst": "tst",
+ "ud": "udpate",
+ "udp": "udpate",
+ "udpa": "udpate",
+ "udpat": "udpate",
+ "udpate": "udpate",
+ "un": "un",
+ "uni": "uninstall",
+ "unin": "uninstall",
+ "unins": "uninstall",
+ "uninst": "uninstall",
+ "uninsta": "uninstall",
+ "uninstal": "uninstall",
+ "uninstall": "uninstall",
+ "unl": "unlink",
+ "unli": "unlink",
+ "unlin": "unlink",
+ "unlink": "unlink",
+ "unp": "unpublish",
+ "unpu": "unpublish",
+ "unpub": "unpublish",
+ "unpubl": "unpublish",
+ "unpubli": "unpublish",
+ "unpublis": "unpublish",
+ "unpublish": "unpublish",
+ "uns": "unstar",
+ "unst": "unstar",
+ "unsta": "unstar",
+ "unstar": "unstar",
+ "up": "up",
+ "upd": "update",
+ "upda": "update",
+ "updat": "update",
+ "update": "update",
+ "upg": "upgrade",
+ "upgr": "upgrade",
+ "upgra": "upgrade",
+ "upgrad": "upgrade",
+ "upgrade": "upgrade",
+ "ur": "urn",
+ "urn": "urn",
+ "v": "v",
+ "veri": "verison",
+ "veris": "verison",
+ "veriso": "verison",
+ "verison": "verison",
+ "vers": "version",
+ "versi": "version",
+ "versio": "version",
+ "version": "version",
+ "vi": "view",
+ "vie": "view",
+ "view": "view",
+ "who": "whoami",
+ "whoa": "whoami",
+ "whoam": "whoami",
+ "whoami": "whoami",
+ "why": "why",
+ "x": "x",
},
"aliases": Object {
"add": "install",
@@ -105,99 +410,76 @@ Object {
"x": "exec",
},
"cmdList": Array [
- "ci",
- "install-ci-test",
- "install",
- "install-test",
- "uninstall",
+ "access",
+ "adduser",
+ "audit",
+ "bin",
+ "bugs",
"cache",
+ "ci",
+ "completion",
"config",
- "set",
- "get",
- "update",
- "outdated",
- "prune",
- "pack",
- "find-dupes",
"dedupe",
+ "deprecate",
+ "diff",
+ "dist-tag",
+ "docs",
+ "doctor",
+ "edit",
+ "exec",
+ "explain",
+ "explore",
+ "find-dupes",
+ "fund",
+ "get",
+ "help",
"hook",
- "rebuild",
+ "init",
+ "install",
+ "install-ci-test",
+ "install-test",
"link",
- "publish",
- "star",
- "stars",
- "unstar",
- "adduser",
+ "ll",
"login",
"logout",
- "unpublish",
- "owner",
- "access",
- "team",
- "deprecate",
- "shrinkwrap",
- "token",
- "profile",
- "audit",
- "fund",
- "org",
- "help",
"ls",
- "ll",
- "search",
- "view",
- "init",
- "version",
- "edit",
- "explore",
- "docs",
- "repo",
- "bugs",
- "root",
- "prefix",
- "bin",
- "whoami",
- "diff",
- "dist-tag",
+ "org",
+ "outdated",
+ "owner",
+ "pack",
"ping",
"pkg",
- "test",
- "stop",
- "start",
+ "prefix",
+ "profile",
+ "prune",
+ "publish",
+ "rebuild",
+ "repo",
"restart",
+ "root",
"run-script",
+ "search",
+ "set",
"set-script",
- "completion",
- "doctor",
- "exec",
- "explain",
+ "shrinkwrap",
+ "star",
+ "stars",
+ "start",
+ "stop",
+ "team",
+ "test",
+ "token",
+ "uninstall",
+ "unpublish",
+ "unstar",
+ "update",
+ "version",
+ "view",
+ "whoami",
],
"plumbing": Array [
"birthday",
"help-search",
],
- "shorthands": Object {
- "c": "config",
- "cit": "install-ci-test",
- "clean-install": "ci",
- "clean-install-test": "cit",
- "create": "init",
- "ddp": "dedupe",
- "i": "install",
- "it": "install-test",
- "list": "ls",
- "ln": "link",
- "rb": "rebuild",
- "run": "run-script",
- "s": "search",
- "se": "search",
- "t": "test",
- "tst": "test",
- "un": "uninstall",
- "up": "update",
- "v": "view",
- "why": "explain",
- "x": "exec",
- },
}
`
diff --git a/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs b/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
index 1f4b0292c..e6afc973a 100644
--- a/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
+++ b/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
@@ -514,7 +514,7 @@ All commands:
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
- aliases: i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall, add
+ aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
Run "npm help install" for more info
@@ -826,7 +826,7 @@ All commands:
[--no-description] [--searchopts <searchopts>] [--searchexclude <searchexclude>]
[--registry <registry>] [--prefer-online] [--prefer-offline] [--offline]
- aliases: s, se, find
+ aliases: find, s, se
Run "npm help search" for more info
@@ -944,7 +944,7 @@ All commands:
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
- aliases: un, unlink, remove, rm, r
+ aliases: unlink, remove, rm, r, un
Run "npm help uninstall" for more info
@@ -1012,7 +1012,7 @@ All commands:
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
- aliases: v, info, show
+ aliases: info, show, v
Run "npm help view" for more info
diff --git a/test/lib/npm.js b/test/lib/npm.js
index 541c1258d..998e96314 100644
--- a/test/lib/npm.js
+++ b/test/lib/npm.js
@@ -548,12 +548,14 @@ t.test('output clears progress and console.logs the message', async t => {
t.end()
})
-t.test('unknown command', async t => {
+t.test('aliases and typos', async t => {
const { npm } = await loadMockNpm(t, { load: false })
- await t.rejects(
- npm.cmd('thisisnotacommand'),
- { code: 'EUNKNOWNCOMMAND' }
- )
+ await t.rejects(npm.cmd('thisisnotacommand'), { code: 'EUNKNOWNCOMMAND' })
+ await t.rejects(npm.cmd(''), { code: 'EUNKNOWNCOMMAND' })
+ await t.rejects(npm.cmd('birt'), { code: 'EUNKNOWNCOMMAND' })
+ await t.resolves(npm.cmd('it'), { name: 'install-test' })
+ await t.resolves(npm.cmd('installTe'), { name: 'install-test' })
+ await t.resolves(npm.cmd('birthday'), { name: 'birthday' })
})
t.test('explicit workspace rejection', async t => {
diff --git a/test/lib/utils/deref-command.js b/test/lib/utils/deref-command.js
deleted file mode 100644
index 474488c58..000000000
--- a/test/lib/utils/deref-command.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const t = require('tap')
-const deref = require('../../../lib/utils/deref-command.js')
-
-t.equal(deref(null), '')
-t.equal(deref(8), '')
-t.equal(deref('it'), 'install-test')
-t.equal(deref('installTe'), 'install-test')
-t.equal(deref('birthday'), 'birthday')
-t.equal(deref('birt'), '')