Skip to content

Commit f8406e1

Browse files
authored
feat: display used config path when logging level=log (#2431)
1 parent 4f559fe commit f8406e1

File tree

13 files changed

+113
-35
lines changed

13 files changed

+113
-35
lines changed

.github/workflows/nodejs.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ jobs:
3535
node-version: ${{ matrix.node-version }}
3636

3737
- name: Install dependencies
38-
run: |
39-
yarn
40-
yarn bootstrap
41-
42-
- name: Install webpack ${{ matrix.webpack-version }}
43-
run: yarn add -W webpack@${{ matrix.webpack-version }}
38+
run: yarn
4439

4540
- name: Build
4641
run: yarn build
@@ -57,7 +52,7 @@ jobs:
5752
matrix:
5853
os: [ubuntu-latest, windows-latest, macos-latest]
5954
node-version: [10.x, 12.x, 14.x]
60-
webpack-version: [webpack-4, latest]
55+
webpack-version: [4, latest]
6156

6257
steps:
6358
- uses: actions/checkout@v2
@@ -76,27 +71,24 @@ jobs:
7671
path: |
7772
node_modules
7873
*/*/node_modules
79-
key: ${{ runner.os }}-${{ matrix.webpack-version }}-${{ hashFiles('**/yarn.lock', './yarn.lock') }}
74+
key: ${{ runner.os }}-${{ matrix.webpack-version }}-yarn-${{ hashFiles('**/yarn.lock', './yarn.lock') }}
75+
restore-keys: |
76+
${{ runner.os }}-${{ matrix.webpack-version }}-yarn-
8077
8178
- name: Install dependencies
82-
if: steps.cache.outputs.cache-hit != 'true'
83-
run: |
84-
yarn
85-
yarn bootstrap
79+
run: yarn
8680

8781
- name: Install webpack ${{ matrix.webpack-version }}
88-
if: matrix.webpack-version == 'webpack-4'
82+
if: matrix.webpack-version == '4'
8983
run: yarn add -W webpack@${{ matrix.webpack-version }}
9084

91-
- name: Build and Bootstrap
92-
run: |
93-
yarn build:ci
94-
yarn run lerna bootstrap
85+
- name: Prepare environment for tests
86+
run: yarn build:ci
9587

96-
- name: Run Smoketests
88+
- name: Run smoketests
9789
run: yarn test:smoketests
9890

99-
- name: Test and Generate Coverage
91+
- name: Run tests and generate coverage
10092
run: |
10193
yarn prepsuite
10294
yarn test:coverage

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"./packages/*"
2323
],
2424
"scripts": {
25-
"bootstrap": "lerna bootstrap",
2625
"clean": "del-cli \"*.tsbuildinfo\" \"packages/**/*.tsbuildinfo\" \"packages/!(webpack-cli)/lib/!(*.tpl)\" \"**/.yo-rc.json\"",
2726
"prebuild": "yarn clean",
2827
"prebuild:ci": "yarn clean && node ./scripts/setupBuild.js",

packages/webpack-cli/__tests__/applyCLIPlugin.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const applyCLIPlugin = new webpackCLI().applyCLIPlugin;
55

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

2020
it('should add CLI plugin to multi compiler object', async () => {
21-
const result = await applyCLIPlugin({ options: [{}, {}] }, { hot: true, prefetch: true });
21+
const result = await applyCLIPlugin({ options: [{}, {}], path: new WeakMap() }, { hot: true, prefetch: true });
2222
expect(result.options[0].plugins[0] instanceof CLIPlugin).toBeTruthy();
2323
expect(result.options[1].plugins[0] instanceof CLIPlugin).toBeTruthy();
2424
expect(result.options).toEqual([

packages/webpack-cli/lib/plugins/CLIPlugin.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ class CLIPlugin {
3939

4040
setupHelpfulOutput(compiler) {
4141
const pluginName = 'webpack-cli';
42-
const getCompilationName = () => (compiler.name ? ` '${compiler.name}'` : '');
42+
const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : '');
43+
44+
const { configPath } = this.options;
4345

4446
compiler.hooks.run.tap(pluginName, () => {
45-
this.logger.log(`Compilation${getCompilationName()} starting...`);
47+
const name = getCompilationName();
48+
49+
this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);
50+
51+
if (configPath) {
52+
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
53+
}
4654
});
4755

4856
compiler.hooks.watchRun.tap(pluginName, (compiler) => {
@@ -52,7 +60,13 @@ class CLIPlugin {
5260
this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
5361
}
5462

55-
this.logger.log(`Compilation${getCompilationName()} starting...`);
63+
const name = getCompilationName();
64+
65+
this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);
66+
67+
if (configPath) {
68+
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
69+
}
5670
});
5771

5872
compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => {
@@ -63,11 +77,13 @@ class CLIPlugin {
6377
});
6478

6579
(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => {
66-
this.logger.log(`Compilation${getCompilationName()} finished`);
80+
const name = getCompilationName();
81+
82+
this.logger.log(`Compiler${name ? ` ${name}` : ''} finished`);
6783

6884
process.nextTick(() => {
6985
if (compiler.watchMode) {
70-
this.logger.log(`Compiler${getCompilationName()} is watching files for updates...`);
86+
this.logger.log(`Compiler${name ? `${name}` : ''} is watching files for updates...`);
7187
}
7288
});
7389
});

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ class WebpackCLI {
16311631

16321632
configOptions.plugins.unshift(
16331633
new CLIPlugin({
1634-
configPath: config.path,
1634+
configPath: config.path.get(configOptions),
16351635
helpfulOutput: !cliOptions.json,
16361636
hot: cliOptions.hot,
16371637
progress: cliOptions.progress,

test/build/basic/basic.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const stripAnsi = require('strip-ansi');
4+
const { resolve } = require('path');
35
const { run } = require('../../utils/test-utils');
46

57
describe('bundle command', () => {
@@ -140,4 +142,18 @@ describe('bundle command', () => {
140142
expect(stderr).toContain("Run 'webpack --help' to see available commands and options");
141143
expect(stdout).toBeFalsy();
142144
});
145+
146+
it('should log supplied config when logging level is log', () => {
147+
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './log.config.js']);
148+
const configPath = resolve(__dirname, './log.config.js');
149+
150+
expect(exitCode).toBe(0);
151+
152+
const pureStderr = stripAnsi(stderr);
153+
154+
expect(pureStderr).toContain('Compiler starting...');
155+
expect(pureStderr).toContain(`Compiler is using config: '${configPath}'`);
156+
expect(pureStderr).toContain('Compiler finished');
157+
expect(stdout).toBeTruthy();
158+
});
143159
});

test/build/basic/log.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
mode: 'development',
3+
infrastructureLogging: {
4+
level: 'log',
5+
},
6+
};

test/core-flags/infrastructure-logging.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe('infrastructure logging related flag', () => {
2323
const { exitCode, stderr, stdout } = run(__dirname, ['--infrastructure-logging-level', 'log']);
2424

2525
expect(exitCode).toBe(0);
26-
expect(stderr).toContain("Compilation 'compiler' starting...");
27-
expect(stderr).toContain("Compilation 'compiler' finished");
26+
expect(stderr).toContain("Compiler 'compiler' starting...");
27+
expect(stderr).toContain("Compiler 'compiler' finished");
2828
expect(stdout).toContain(`level: 'log'`);
2929
});
3030
});

test/json/json.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
2+
3+
const stripAnsi = require('strip-ansi');
24
const { run } = require('../utils/test-utils');
35
const { existsSync, readFile } = require('fs');
46
const { resolve } = require('path');
@@ -111,8 +113,8 @@ describe('json', () => {
111113
const { exitCode, stderr, stdout } = run(__dirname, ['--json', '--config', 'logging.config.js']);
112114

113115
expect(exitCode).toBe(0);
114-
expect(stderr).toContain('Compilation starting');
115-
expect(stderr).toContain('Compilation finished');
116+
expect(stderr).toContain('Compiler starting...');
117+
expect(stderr).toContain('Compiler finished');
116118
expect(() => JSON.parse(stdout)).not.toThrow();
117119
expect(JSON.parse(stdout)['hash']).toBeDefined();
118120
});
@@ -121,9 +123,12 @@ describe('json', () => {
121123
const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json', '--config', 'logging.config.js']);
122124

123125
expect(exitCode).toBe(0);
124-
expect(stderr).toContain('Compilation starting');
125-
expect(stderr).toContain('Compilation finished');
126-
expect(stderr).toContain(successMessage);
126+
127+
const pureStderr = stripAnsi(stderr);
128+
129+
expect(stderr).toContain('Compiler starting...');
130+
expect(pureStderr).toContain('Compiler finished');
131+
expect(pureStderr).toContain(successMessage);
127132
expect(stdout).toBeFalsy();
128133
expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy();
129134

test/serve/basic/log.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
mode: 'development',
3+
infrastructureLogging: {
4+
level: 'log',
5+
},
6+
};

test/serve/basic/serve-basic.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ describe('basic serve usage', () => {
306306
expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull();
307307
});
308308

309+
it('should log used supplied config with serve', async () => {
310+
const { stderr, stdout } = await runServe(__dirname, ['--config', 'log.config.js', '--port', port]);
311+
const configPath = path.resolve(__dirname, './log.config.js');
312+
313+
expect(stderr).toContain('Compiler starting...');
314+
expect(stderr).toContain(`Compiler is using config: '${configPath}'`);
315+
expect(stderr).toContain('Compiler finished');
316+
expect(stdout).toBeTruthy();
317+
});
318+
309319
it("should log error on using '--watch' flag with serve", async () => {
310320
const { stdout, stderr } = await runServe(testPath, ['--watch']);
311321

test/watch/basic/basic.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,28 @@ describe('basic', () => {
159159
});
160160
});
161161

162+
it('should log supplied config with watch', (done) => {
163+
const proc = runAndGetWatchProc(__dirname, ['watch', '--config', 'log.config.js']);
164+
const configPath = resolve(__dirname, './log.config.js');
165+
166+
let stderr = '';
167+
168+
proc.stderr.on('data', (chunk) => {
169+
const data = stripAnsi(chunk.toString());
170+
171+
stderr += stripAnsi(data);
172+
173+
if (/Compiler finished/.test(data)) {
174+
expect(stderr).toContain('Compiler starting...');
175+
expect(stderr).toContain(`Compiler is using config: '${configPath}'`);
176+
expect(stderr).toContain('Compiler finished');
177+
178+
proc.kill();
179+
done();
180+
}
181+
});
182+
});
183+
162184
it('should recompile upon file change using the `command` option and the `--watch` option and log warning', async () => {
163185
const { exitCode, stderr, stdout } = await run(__dirname, ['watch', '--watch', '--mode', 'development']);
164186

test/watch/basic/log.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
mode: 'development',
3+
infrastructureLogging: {
4+
level: 'log',
5+
},
6+
};

0 commit comments

Comments
 (0)