Skip to content
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

fix(cli): verbose and stats verbose flag (rebase) #1466

Closed
wants to merge 11 commits into from
19 changes: 11 additions & 8 deletions packages/webpack-cli/__tests__/StatsGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ const StatsGroup = require('../lib/groups/StatsGroup');

describe('StatsGroup', function () {
{
StatsGroup.validOptions().map((option) => {
StatsGroup.validOptions().validArrayString.map((option) => {
it(`should handle ${option} option`, () => {
const statsGroup = new StatsGroup([
{
stats: option,
},
]);

const statsGroup = new StatsGroup([{ stats: `${option}` }]);
const result = statsGroup.run();
expect(result.outputOptions.stats).toEqual(option);
});
});
StatsGroup.validOptions().validArrayObject.map((option) => {
let stats = option.stats ? option.stats : null;
it(`should handle verbose true with stats ${stats} option`, () => {
const statsGroup = new StatsGroup(option);
const result = statsGroup.run();
expect(result.options.stats).toEqual(option);
expect(result.outputOptions.stats).toEqual('verbose');
});
});
}
Expand Down
19 changes: 10 additions & 9 deletions packages/webpack-cli/lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const logger = require('../utils/logger');
*/
class StatsGroup extends GroupHelper {
static validOptions() {
return ['none', 'errors-only', 'minimal', 'normal', 'detailed', 'verbose', 'errors-warnings'];
const validArrayString = ['none', 'errors-only', 'minimal', 'normal', 'detailed', 'verbose', 'errors-warnings'];
const validArrayObject = validArrayString.map((e) => {
return { verbose: true, stats: `${e}` };
});
validArrayObject.push({ verbose: true });
return { validArrayString, validArrayObject };
}

constructor(options) {
Expand All @@ -15,19 +20,15 @@ class StatsGroup extends GroupHelper {
resolveOptions() {
if (this.args.verbose && this.args.stats) {
logger.warn('Conflict between "verbose" and "stats" options. Using verbose.');
this.opts.option.stats = {
verbose: true,
};
this.opts.outputOptions.stats = 'verbose';
} else {
if (this.args.verbose) {
this.opts.option.stats = {
verbose: true,
};
} else if (!StatsGroup.validOptions().includes(this.args.stats)) {
this.opts.outputOptions.stats = 'verbose';
} else if (!StatsGroup.validOptions().validArrayString.includes(this.args.stats)) {
logger.warn(`'${this.args.stats}' is invalid value for stats. Using 'normal' option for stats`);
this.opts.options.stats = 'normal';
} else {
this.opts.options.stats = this.args.stats;
this.opts.outputOptions.stats = this.args.stats;
}
}
if (this.args.json) {
Expand Down
13 changes: 6 additions & 7 deletions packages/webpack-cli/lib/utils/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Compiler {
this.output = new CompilerOutput();
this.compilerOptions = {};
}
setUpHookForCompilation(compilation, outputOptions, options) {
setUpHookForCompilation(compilation, outputOptions, options, idx) {
const { ProgressPlugin } = webpack;
let progressPluginExists;
if (options.plugins) {
Expand All @@ -34,7 +34,7 @@ class Compiler {
process.stdout.write(`) ${percent}% : `);
process.stdout.write(`${cyanBright(msg)}`);
if (percent === 100) {
process.stdout.write(`${cyanBright('Complilation completed\n')}`);
process.stdout.write(`\n${cyanBright('Compilation completed\n')}`);
}
}
};
Expand All @@ -53,10 +53,9 @@ class Compiler {
}
}
});

if (outputOptions.infoVerbosity === 'verbose') {
if (outputOptions.stats === 'verbose') {
const resolveCompilationName = (compilation) => {
return compilation.name ? compilation.name : '';
return compilation.name ? compilation.name : `${idx + 1}`;
};
if (outputOptions.watch) {
compilation.hooks.watchRun.tap('WebpackCLI', (compilation) => {
Expand All @@ -78,7 +77,7 @@ class Compiler {
}

generateOutput(outputOptions, stats) {
this.output.generateRawOutput(stats, this.compilerOptions);
this.output.generateRawOutput(stats, outputOptions);
process.stdout.write('\n');
if (outputOptions.watch) {
logger.info('watching files for updates...');
Expand Down Expand Up @@ -165,7 +164,7 @@ class Compiler {

if (this.compiler.compilers) {
this.compiler.compilers.forEach((comp, idx) => {
this.setUpHookForCompilation(comp, outputOptions, options[idx]);
this.setUpHookForCompilation(comp, outputOptions, options[idx], idx);
});
} else {
this.setUpHookForCompilation(this.compiler, outputOptions, options);
Expand Down
15 changes: 8 additions & 7 deletions packages/webpack-cli/lib/utils/GroupHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ class GroupHelper {
}

arrayToObject(arr) {
if (!arr) {
return;
if (Array.isArray(arr)) {
aman29271 marked this conversation as resolved.
Show resolved Hide resolved
return arr.reduce((result, currentItem) => {
const key = Object.keys(currentItem)[0];
result[this.hyphenToUpperCase(key)] = currentItem[key];
return result;
}, {});
}
return arr.reduce((result, currentItem) => {
const key = Object.keys(currentItem)[0];
result[this.hyphenToUpperCase(key)] = currentItem[key];
return result;
}, {});
if (!arr) return;
return arr;
}

// TODO: to re implement
Expand Down