From f3bfd47424dfa32a0fc2cddbbf32de35a9363f9f Mon Sep 17 00:00:00 2001 From: Damian Pieczynski Date: Wed, 4 Nov 2020 19:31:46 +0100 Subject: [PATCH] refactor: move appendProgressPlugin as method, fine-tune logging --- .../lib/plugins/WebpackCLIPlugin.js | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js b/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js index 4aeeb63d91e..e84c624413e 100644 --- a/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js @@ -3,34 +3,6 @@ const webpack = packageExists('webpack') ? require('webpack') : undefined; const { getStatsOptions } = require('../utils/stats-options'); const { PluginName } = require('../utils/name'); -const appendProgressPlugin = (compiler, progress) => { - const { ProgressPlugin } = compiler.webpack || webpack; - - const logger = compiler.getInfrastructureLogger(PluginName); - - const compilers = compiler.compilers || [compiler]; - - for (const compiler of compilers) { - let progressPluginExists; - - if (compiler.options.plugins) { - progressPluginExists = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); - } - - if (!progressPluginExists) { - if (typeof progress === 'string' && progress !== 'profile') { - logger.error(`'${progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`); - - process.exit(2); - } - - const isProfile = progress === 'profile'; - - new ProgressPlugin({ profile: isProfile }).apply(compiler); - } - } -}; - class WebpackCLIPlugin { constructor(options) { this.options = options; @@ -42,12 +14,12 @@ class WebpackCLIPlugin { const { progress } = this.options; if (progress) { - appendProgressPlugin(compiler, progress); + this.appendProgressPlugin(compiler, progress); } const logger = compiler.getInfrastructureLogger(PluginName); - const resolveName = (obj) => (obj.name ? `${obj.name}: ` : ''); + const resolveName = (obj) => (obj.name ? `${obj.name} ` : ''); const done = (stats) => { const printStats = (childCompiler, childStats) => { @@ -60,7 +32,7 @@ class WebpackCLIPlugin { ...statusOptions(false), }; - const statsString = childStats.toString(statsOptions); + const statsString = resolveName(childCompiler) + 'output:\n' + childStats.toString(statsOptions); if (statsString.length) { if (childStats.hasErrors()) { @@ -109,6 +81,34 @@ class WebpackCLIPlugin { }); compiler.hooks.done.tap(PluginName, done); } + + appendProgressPlugin(compiler, progress) { + const { ProgressPlugin } = compiler.webpack || webpack; + + const logger = compiler.getInfrastructureLogger(PluginName); + + const compilers = compiler.compilers || [compiler]; + + for (const compiler of compilers) { + let progressPluginExists; + + if (compiler.options.plugins) { + progressPluginExists = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); + } + + if (!progressPluginExists) { + if (typeof progress === 'string' && progress !== 'profile') { + logger.error(`'${progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`); + + process.exit(2); + } + + const isProfile = progress === 'profile'; + + new ProgressPlugin({ profile: isProfile }).apply(compiler); + } + } + } } module.exports = WebpackCLIPlugin;