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: display used config path when logging level=log #2397

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions packages/webpack-cli/__tests__/applyCLIPlugin.test.js
Expand Up @@ -5,7 +5,7 @@ const applyCLIPlugin = new webpackCLI().applyCLIPlugin;

describe('CLIPluginResolver', () => {
it('should add CLI plugin to single compiler object', async () => {
const result = await applyCLIPlugin({ options: {} }, { hot: true, prefetch: true });
const result = await applyCLIPlugin({ options: {}, path: new WeakMap() }, { hot: true, prefetch: true });
expect(result.options.plugins[0] instanceof CLIPlugin).toBeTruthy();
expect(result.options.plugins[0].options).toEqual({
configPath: undefined,
Expand All @@ -18,7 +18,7 @@ describe('CLIPluginResolver', () => {
});

it('should add CLI plugin to multi compiler object', async () => {
const result = await applyCLIPlugin({ options: [{}, {}] }, { hot: true, prefetch: true });
const result = await applyCLIPlugin({ options: [{}, {}], path: new WeakMap() }, { hot: true, prefetch: true });
expect(result.options[0].plugins[0] instanceof CLIPlugin).toBeTruthy();
expect(result.options[1].plugins[0] instanceof CLIPlugin).toBeTruthy();
expect(result.options).toEqual([
Expand Down
9 changes: 9 additions & 0 deletions packages/webpack-cli/lib/plugins/CLIPlugin.js
Expand Up @@ -41,7 +41,12 @@ class CLIPlugin {
const pluginName = 'webpack-cli';
const getCompilationName = () => (compiler.name ? ` '${compiler.name}'` : '');

const { configPath } = this.options;

compiler.hooks.run.tap(pluginName, () => {
if (configPath) {
this.logger.log(`Using config ${configPath}`);
}
this.logger.log(`Compilation${getCompilationName()} starting...`);
});

Expand All @@ -52,6 +57,10 @@ class CLIPlugin {
this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}

if (configPath) {
this.logger.log(`Using config ${configPath}`);
}

this.logger.log(`Compilation${getCompilationName()} starting...`);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -1631,7 +1631,7 @@ class WebpackCLI {

configOptions.plugins.unshift(
new CLIPlugin({
configPath: config.path,
configPath: config.path.get(configOptions),
helpfulOutput: !cliOptions.json,
hot: cliOptions.hot,
progress: cliOptions.progress,
Expand Down
14 changes: 12 additions & 2 deletions test/build/basic/basic.test.js
@@ -1,6 +1,6 @@
'use strict';

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

describe('bundle command', () => {
it('should work without command (default command)', async () => {
Expand Down Expand Up @@ -140,4 +140,14 @@ describe('bundle command', () => {
expect(stderr).toContain("Run 'webpack --help' to see available commands and options");
expect(stdout).toBeFalsy();
});

it('should log supplied config when logging level is log', () => {
if (isWebpack5) {
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './entry.config.js', '--infrastructure-logging-level', 'log']);
expect(exitCode).toBe(0);
const configPath = resolve(__dirname, './entry.config.js');
expect(stderr).toContain(`Using config ${configPath}`);
expect(stdout).toBeFalsy();
}
});
});
12 changes: 12 additions & 0 deletions test/core-flags/infrastructure-logging.test.js
@@ -1,6 +1,7 @@
'use strict';

const { run } = require('../utils/test-utils');
const { resolve } = require('path');

describe('infrastructure logging related flag', () => {
it('should set infrastructureLogging.debug properly', () => {
Expand All @@ -27,4 +28,15 @@ describe('infrastructure logging related flag', () => {
expect(stderr).toContain("Compilation 'compiler' finished");
expect(stdout).toContain(`level: 'log'`);
});

it('should log used default config when level is log', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--infrastructure-logging-level', 'log']);

expect(exitCode).toBe(0);
const configPath = resolve(__dirname, './webpack.config.js');
expect(stderr).toContain("Compilation 'compiler' starting...");
expect(stderr).toContain(`Using config ${configPath}`);
expect(stderr).toContain("Compilation 'compiler' finished");
expect(stdout).toContain(`level: 'log'`);
});
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
});
15 changes: 15 additions & 0 deletions test/serve/basic/serve-basic.test.js
Expand Up @@ -329,4 +329,19 @@ describe('basic serve usage', () => {
expect(stderr).toContain("Error: Unknown option '--unknown-flag'");
expect(stdout).toBeFalsy();
});

it('should log used supplied config with serve', async () => {
if (isWebpack5) {
const { stderr, stdout } = await runServe(__dirname, [
'--config',
'webpack.config.js',
'--infrastructure-logging-level',
'log',
]);

const configPath = path.resolve(__dirname, './webpack.cache.config.js');
expect(stderr).toContain(`Using config ${configPath}`);
expect(stdout).toBeFalsy();
}
});
});
16 changes: 16 additions & 0 deletions test/watch/basic/basic.test.js
Expand Up @@ -176,4 +176,20 @@ describe('basic', () => {
expect(stderr).toContain("Run 'webpack --help' to see available commands and options");
expect(stdout).toBeFalsy();
});

it('should log supplied config with watch', async () => {
if (isWebpack5) {
const { stderr, stdout } = await run(__dirname, [
'watch',
'--config',
'watch.config.js',
'--infrastructure-logging-level',
'log',
]);

const configPath = resolve(__dirname, './watch.config.js');
expect(stderr).toContain(`Using config ${configPath}`);
expect(stdout).toBeFalsy();
}
});
});