Skip to content

chore: upgrade commander to v7 #6242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 21 additions & 45 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ program
.option('-x, --proxy <proxyUrl>', 'Use specified proxy when creating project')
.option('-b, --bare', 'Scaffold project without beginner instructions')
.option('--skipGetStarted', 'Skip displaying "Get started" instructions')
.action((name, cmd) => {
const options = cleanArgs(cmd)

.action((name, options) => {
if (minimist(process.argv.slice(3))._.length > 1) {
console.log(chalk.yellow('\n Info: You provided more than one argument. The first one will be used as the app\'s name, the rest are ignored.'))
}
Expand Down Expand Up @@ -97,8 +95,8 @@ program
.option('--rules', 'list all module rule names')
.option('--plugins', 'list all plugin names')
.option('-v --verbose', 'Show full function definitions in output')
.action((paths, cmd) => {
require('../lib/inspect')(paths, cleanArgs(cmd))
.action((paths, options) => {
require('../lib/inspect')(paths, options)
})

program
Expand All @@ -124,9 +122,9 @@ program
.option('-D, --dev', 'Run in dev mode')
.option('--quiet', `Don't output starting messages`)
.option('--headless', `Don't open browser on start and output port`)
.action((cmd) => {
.action((options) => {
checkNodeVersion('>=8.6', 'vue ui')
require('../lib/ui')(cleanArgs(cmd))
require('../lib/ui')(options)
})

program
Expand All @@ -146,16 +144,16 @@ program
.option('-d, --delete <path>', 'delete option from config')
.option('-e, --edit', 'open config with default editor')
.option('--json', 'outputs JSON result only')
.action((value, cmd) => {
require('../lib/config')(value, cleanArgs(cmd))
.action((value, options) => {
require('../lib/config')(value, options)
})

program
.command('outdated')
.description('(experimental) check for outdated vue cli service / plugins')
.option('--next', 'Also check for alpha / beta / rc versions when upgrading')
.action((cmd) => {
require('../lib/outdated')(cleanArgs(cmd))
.action((options) => {
require('../lib/outdated')(options)
})

program
Expand All @@ -166,17 +164,16 @@ program
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies')
.option('--all', 'Upgrade all plugins')
.option('--next', 'Also check for alpha / beta / rc versions when upgrading')
.action((packageName, cmd) => {
require('../lib/upgrade')(packageName, cleanArgs(cmd))
.action((packageName, options) => {
require('../lib/upgrade')(packageName, options)
})

program
.command('migrate [plugin-name]')
.description('(experimental) run migrator for an already-installed cli plugin')
// TODO: use `requiredOption` after upgrading to commander 4.x
.option('-f, --from <version>', 'The base version for the migrator to migrate from')
.action((packageName, cmd) => {
require('../lib/migrate')(packageName, cleanArgs(cmd))
.requiredOption('-f, --from <version>', 'The base version for the migrator to migrate from')
.action((packageName, options) => {
require('../lib/migrate')(packageName, options)
})

program
Expand All @@ -201,15 +198,13 @@ program
})

// output help information on unknown commands
program
.arguments('<command>')
.action((cmd) => {
program.outputHelp()
console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`))
console.log()
suggestCommands(cmd)
process.exitCode = 1
})
program.on('command:*', ([cmd]) => {
program.outputHelp()
console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`))
console.log()
suggestCommands(cmd)
process.exitCode = 1
})

// add some useful info on help
program.on('--help', () => {
Expand Down Expand Up @@ -259,22 +254,3 @@ function suggestCommands (unknownCommand) {
console.log(` ` + chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`))
}
}

function camelize (str) {
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : '')
}

// commander passes the Command object itself as options,
// extract only actual options into a fresh object.
function cleanArgs (cmd) {
const args = {}
cmd.options.forEach(o => {
const key = camelize(o.long.replace(/^--/, ''))
// if an option is not present and Command has a method with the same name
// it should not be copied
if (typeof cmd[key] !== 'function' && typeof cmd[key] !== 'undefined') {
args[key] = cmd[key]
}
})
return args
}
5 changes: 0 additions & 5 deletions packages/@vue/cli/lib/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ async function runMigrator (context, plugin, pkg = getPkg(context)) {
}

async function migrate (pluginId, { from }, context = process.cwd()) {
// TODO: remove this after upgrading to commander 4.x
if (!from) {
throw new Error(`Required option 'from' not specified`)
}

const pluginName = resolvePluginId(pluginId)
const pluginMigrator = loadModule(`${pluginName}/migrator`, context)
if (!pluginMigrator) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@vue/cli-ui-addon-webpack": "^5.0.0-alpha.3",
"@vue/cli-ui-addon-widgets": "^5.0.0-alpha.3",
"boxen": "^4.1.0",
"commander": "^2.20.0",
"commander": "^7.0.0",
"debug": "^4.1.0",
"deepmerge": "^4.2.2",
"download-git-repo": "^3.0.2",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7579,6 +7579,11 @@ commander@^6.2.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==

commander@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-7.0.0.tgz#3e2bbfd8bb6724760980988fb5b22b7ee6b71ab2"
integrity sha512-ovx/7NkTrnPuIV8sqk/GjUIIM1+iUQeqA3ye2VNpq9sVoiZsooObWlQy+OPWGI17GDaEoybuAGJm6U8yC077BA==

commander@~2.19.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
Expand Down