diff options
author | Gar <gar+gh@danger.computer> | 2022-03-24 17:18:56 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-03-28 23:21:36 +0300 |
commit | d8dcc02cfd354c1314c45d6530ec926cd138210c (patch) | |
tree | ba3721d4c4f153fe005bf9e08d450d9e2473a9a4 /lib/npm.js | |
parent | a64acc0bf01e4bc68b26ead5b2d5c6db47ef16c2 (diff) |
fix: consolidate command alias code
Diffstat (limited to 'lib/npm.js')
-rw-r--r-- | lib/npm.js | 23 |
1 files changed, 21 insertions, 2 deletions
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 |