Skip to content

Commit 92ac637

Browse files
evenstensbergematipico
authored andcommitted
tests: add tests for version, improve conventions (#1026)
* tests: add tests for version * tests: clean up tests
1 parent 6186541 commit 92ac637

33 files changed

+1957
-29638
lines changed

.cz-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ module.exports = {
2626
{ value: "feat", name: "feat: A new feature" },
2727
{ value: "fix", name: "fix: Bugs, typos, etc" },
2828
{ value: "misc", name: "misc: Other formats like tweaks and such" },
29-
{ value: "tests", name: "tests: Tests, jest, binTestCases, etc" },
29+
{ value: "tests", name: "tests: Tests, jest, etc" },
3030
]
3131
};

lib/bootstrap.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const cmdArgs = require('command-line-args');
44

55
require('./utils/process-log');
66

7-
const isHelpFlagPresent = args => args.find(arg => ['help', '--help'].indexOf(arg) !== -1);
8-
7+
const isFlagPresent = (args, flag) => args.find(arg => [flag, `--${flag}`].includes(arg));
98
const normalizeFlags = (args, command) => args.slice(2).filter(arg => arg.indexOf('--') < 0 && arg !== command.name && arg !== command.alias);
109

1110
const isCommandUsed = commands =>
@@ -15,9 +14,16 @@ const isCommandUsed = commands =>
1514

1615
async function runCLI(cli, commandIsUsed) {
1716
let args;
18-
const helpFlagExists = isHelpFlagPresent(process.argv);
17+
const helpFlagExists = isFlagPresent(process.argv, 'help');
18+
const versionFlagExists = isFlagPresent(process.argv, 'version');
19+
1920
if (helpFlagExists) {
20-
await cli.runHelp();
21+
cli.runHelp();
22+
return;
23+
}
24+
25+
else if(versionFlagExists) {
26+
cli.runVersion();
2127
return;
2228
}
2329

lib/groups/help.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class HelpGroup {
1313
process.stdout.write('\n Made with ♥️ by the webpack team \n');
1414
}
1515

16+
outputVersion() {
17+
const pkgLock = require('../../package.json');
18+
const webpack = require('webpack');
19+
process.stdout.write(`\nwebpack-cli ${pkgLock.version}`);
20+
process.stdout.write(`\nwebpack ${webpack.version}\n`);
21+
}
22+
1623
run() {
1724
const b = s => chalk.blue(s);
1825
const l = s => chalk.white(s);

lib/utils/compiler.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function showEmojiConditionally(emoji) {
1212
}
1313

1414
function generateOutput(outputOptions, stats, statsErrors) {
15-
if (outputOptions.version) {
16-
console.log(` 🌏 webpack v.${webpack.version}`);
17-
process.exit(0);
18-
}
1915
const statsObj = stats.toJson(outputOptions);
2016
const { assets, entrypoints, time, builtAt, warnings, outputPath } = statsObj;
2117

lib/webpack-cli.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@ class webpackCLI extends GroupHelper {
107107
}
108108
return require('./commands/external').run(command.name, ...args);
109109
}
110-
async runHelp() {
110+
111+
runHelp() {
111112
const HelpGroup = require('./groups/help');
112113
return new HelpGroup().outputHelp();
113114
}
115+
116+
runVersion() {
117+
const HelpGroup = require('./groups/help');
118+
return new HelpGroup().outputVersion();
119+
}
120+
114121
}
115122

116123
module.exports = webpackCLI;

0 commit comments

Comments
 (0)