Skip to content

Commit

Permalink
refactor: replace ternary with or operator where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
piecyk committed Oct 25, 2020
1 parent 928a811 commit 40b202f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js
Expand Up @@ -9,7 +9,7 @@ class WebpackCLIPlugin {
this.options = options;
}
async apply(compiler) {
const compilers = compiler.compilers ? compiler.compilers : [compiler];
const compilers = compiler.compilers || [compiler];

for (const compiler of compilers) {
if (this.options.progress) {
Expand All @@ -27,17 +27,19 @@ class WebpackCLIPlugin {
}
}

const compilationName = (compilation) => (compilation.name ? ` ${compilation.name}` : '');

compiler.hooks.watchRun.tap(PluginName, (compilation) => {
const { bail, watch } = compilation.options;
if (bail && watch) {
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}

logger.success(`Compilation${compilation.name ? `${compilation.name}` : ''} starting...`);
logger.success(`Compilation${compilationName(compilation)} starting...`);
});

compiler.hooks.done.tap(PluginName, (compilation) => {
logger.success(`Compilation${compilation.name ? `${compilation.name}` : ''} finished`);
logger.success(`Compilation${compilationName(compilation)} finished`);

process.nextTick(() => {
if (compiler.watchMode) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -216,7 +216,7 @@ class WebpackCLI extends GroupHelper {
handleError(error) {
// https://github.com/webpack/webpack/blob/master/lib/index.js#L267
// https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90
const ValidationError = webpack.ValidationError ? webpack.ValidationError : webpack.WebpackOptionsValidationError;
const ValidationError = webpack.ValidationError || webpack.WebpackOptionsValidationError;

// In case of schema errors print and exit process
// For webpack@4 and webpack@5
Expand Down

0 comments on commit 40b202f

Please sign in to comment.