Skip to content

Commit

Permalink
feat: respect the infrastructureLogging.level option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Nov 28, 2020
1 parent eae913b commit 10c544b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/webpack-cli/lib/plugins/CLIPlugin.js
@@ -1,6 +1,5 @@
const packageExists = require('../utils/package-exists');
const webpack = packageExists('webpack') ? require('webpack') : undefined;
const logger = require('../utils/logger');

class CLIPlugin {
constructor(options) {
Expand Down Expand Up @@ -37,11 +36,6 @@ class CLIPlugin {
const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin));

if (!progressPlugin) {
if (typeof this.options.progress === 'string' && this.options.progress !== 'profile') {
logger.error(`'${this.options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`);
process.exit(2);
}

new ProgressPlugin({ profile: this.options.progress === 'profile' }).apply(compiler);
}
}
Expand All @@ -51,37 +45,40 @@ class CLIPlugin {
const getCompilationName = (compilation) => (compilation.name ? ` '${compilation.name}'` : '');

compiler.hooks.run.tap(pluginName, (compiler) => {
logger.success(`Compilation${getCompilationName(compiler)} starting...`);
this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
});

compiler.hooks.watchRun.tap(pluginName, (compiler) => {
const { bail, watch } = compiler.options;

if (bail && watch) {
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}

logger.success(`Compilation${getCompilationName(compiler)} starting...`);
this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
});

compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => {
const date = new Date(changeTime * 1000);

logger.log(`File '${filename}' was modified, changed time is ${date} (timestamp is ${changeTime})`);
this.logger.info(`File '${filename}' was modified`);
this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
});

(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, (stats) => {
logger.success(`Compilation${getCompilationName(stats.compilation)} finished`);
this.logger.info(`Compilation${getCompilationName(stats.compilation)} finished`);

process.nextTick(() => {
if (compiler.watchMode) {
logger.success(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
this.logger.info(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
}
});
});
}

apply(compiler) {
this.logger = compiler.getInfrastructureLogger('webpack-cli');

if (this.options.progress && this.options.helpfulOutput) {
this.setupProgressPlugin(compiler);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -219,6 +219,11 @@ class WebpackCLI {
}
}

if (typeof args.progress === 'string' && args.progress !== 'profile') {
logger.error(`'${this.options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`);
process.exit(2);
}

if (Object.keys(args).length === 0 && !process.env.NODE_ENV) {
return config;
}
Expand Down

0 comments on commit 10c544b

Please sign in to comment.