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

feat: add flag to force start finish log #2566

Merged
merged 4 commits into from Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/webpack-cli/lib/plugins/CLIPlugin.js
Expand Up @@ -40,14 +40,20 @@ class CLIPlugin {
setupHelpfulOutput(compiler) {
const pluginName = 'webpack-cli';
const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : '');
const logCompilation = (message) => {
if (process.env.WEBPACK_CLI_START_FINISH_FORCE_LOG) {
process.stderr.write(message);
} else {
this.logger.log(message);
}
};

const { configPath } = this.options;

compiler.hooks.run.tap(pluginName, () => {
const name = getCompilationName();

this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);

logCompilation(`Compiler${name ? ` ${name}` : ''} starting... `);
if (configPath) {
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
}
Expand All @@ -62,7 +68,7 @@ class CLIPlugin {

const name = getCompilationName();

this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);
logCompilation(`Compiler${name ? ` ${name}` : ''} starting... `);

if (configPath) {
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
Expand All @@ -79,8 +85,7 @@ class CLIPlugin {
(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => {
const name = getCompilationName();

this.logger.log(`Compiler${name ? ` ${name}` : ''} finished`);

logCompilation(`Compiler${name ? ` ${name}` : ''} finished`);
process.nextTick(() => {
if (compiler.watchMode) {
this.logger.log(`Compiler${name ? `${name}` : ''} is watching files for updates...`);
Expand Down
1 change: 1 addition & 0 deletions test/build/start-finish-force-log/src/index.js
@@ -0,0 +1 @@
console.log("Itadori Yuuji")
@@ -0,0 +1,50 @@
'use strict';

const { run, runWatch, isWebpack5 } = require('../../utils/test-utils');

describe('start finish force log', () => {
it('start finish force log when env is set', () => {
const { exitCode, stderr, stdout } = run(__dirname, [], {
env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true },
});
expect(exitCode).toBe(0);
expect(stderr).toContain('Compiler starting...');
expect(stderr).toContain('Compiler finished');
const output = isWebpack5 ? 'compiled successfully' : 'main.js';
expect(stdout).toContain(output);
});

it('should show name of the config', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--name', 'log config'], {
env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true },
});
expect(exitCode).toBe(0);
expect(stderr).toContain("Compiler 'log config' starting...");
expect(stderr).toContain("Compiler 'log config' finished");
const output = isWebpack5 ? 'compiled successfully' : 'main.js';
expect(stdout).toContain(output);
});

it('should work with watch', async () => {
const { stderr, stdout } = await runWatch(__dirname, ['watch'], {
env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true },
});
expect(stderr).toContain('Compiler starting...');
expect(stderr).toContain('Compiler finished');
const output = isWebpack5 ? 'compiled successfully' : 'main.js';
expect(stdout).toContain(output);
});

it('should work with multi compiler', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './webpack.config.array.js'], {
env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true },
});
expect(exitCode).toBe(0);
expect(stderr).toContain("Compiler 'Gojou' starting...");
expect(stderr).toContain("Compiler 'Satoru' starting...");
expect(stderr).toContain("Compiler 'Gojou' finished");
expect(stderr).toContain("Compiler 'Satoru' finished");
const output = isWebpack5 ? 'compiled successfully' : 'main.js';
expect(stdout).toContain(output);
});
});
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions test/build/start-finish-force-log/webpack.config.array.js
@@ -0,0 +1,10 @@
module.exports = [
{
name: 'Gojou',
mode: 'development',
},
{
name: 'Satoru',
mode: 'development',
},
];
3 changes: 3 additions & 0 deletions test/build/start-finish-force-log/webpack.config.js
@@ -0,0 +1,3 @@
module.exports = {
mode: 'development',
};