From 7a1bd12ecf92013fe26835918ff76e94ee7cbd40 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 4 Apr 2020 20:43:39 +0530 Subject: [PATCH] feat(webpack-cli): add alias for version docs: add alias for version --- packages/webpack-cli/README.md | 2 +- packages/webpack-cli/lib/bootstrap.js | 2 +- packages/webpack-cli/lib/utils/cli-flags.js | 1 + test/version/version-multi-args.test.js | 2 +- test/version/version-single-arg.test.js | 6 ++++++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/webpack-cli/README.md b/packages/webpack-cli/README.md index 8cb633924c5..299ab326652 100644 --- a/packages/webpack-cli/README.md +++ b/packages/webpack-cli/README.md @@ -56,7 +56,7 @@ Options -p, --prod Run production build --mode string Defines the mode to pass to webpack --no-mode Sets mode="none" which disables any default behavior - --version Get current version + -v, --version Get current version --node-args string[] NodeJS flags --stats type It instructs webpack on how to treat the stats --verbose It tells webpack to output all the information diff --git a/packages/webpack-cli/lib/bootstrap.js b/packages/webpack-cli/lib/bootstrap.js index 461f61b581d..2b569fc6437 100644 --- a/packages/webpack-cli/lib/bootstrap.js +++ b/packages/webpack-cli/lib/bootstrap.js @@ -45,7 +45,7 @@ const resolveNegatedArgs = (args) => { async function runCLI(cli, commandIsUsed) { let args; const helpFlagExists = isFlagPresent(process.argv, 'help'); - const versionFlagExists = isFlagPresent(process.argv, 'version'); + const versionFlagExists = isFlagPresent(process.argv, 'version') || isFlagPresent(process.argv, '-v'); if (helpFlagExists) { cli.runHelp(process.argv); diff --git a/packages/webpack-cli/lib/utils/cli-flags.js b/packages/webpack-cli/lib/utils/cli-flags.js index 39d6e7cb229..1201d5324f4 100644 --- a/packages/webpack-cli/lib/utils/cli-flags.js +++ b/packages/webpack-cli/lib/utils/cli-flags.js @@ -254,6 +254,7 @@ module.exports = { { name: 'version', usage: '--version', + alias: 'v', type: Boolean, group: BASIC_GROUP, description: 'Get current version', diff --git a/test/version/version-multi-args.test.js b/test/version/version-multi-args.test.js index b5c60007592..9d304191cc9 100644 --- a/test/version/version-multi-args.test.js +++ b/test/version/version-multi-args.test.js @@ -11,7 +11,7 @@ describe('version flag with multiple arguments', () => { }); it('outputs version with multiple commands', () => { - const { stdout, stderr } = run(__dirname, ['version', 'create']); + const { stdout, stderr } = run(__dirname, ['version', 'init']); expect(stdout).toContain(pkgJSON.version); expect(stderr).toHaveLength(0); }); diff --git a/test/version/version-single-arg.test.js b/test/version/version-single-arg.test.js index 1da3012ec1d..7fe652e37d5 100644 --- a/test/version/version-single-arg.test.js +++ b/test/version/version-single-arg.test.js @@ -15,4 +15,10 @@ describe('single version flag', () => { expect(stdout).toContain(pkgJSON.version); expect(stderr).toHaveLength(0); }); + + it('outputs versions with alias syntax', () => { + const { stdout, stderr } = run(__dirname, ['-v']); + expect(stdout).toContain(pkgJSON.version); + expect(stderr).toHaveLength(0); + }); });