8000 feat: respect the `infrastructureLogging.level` option (potential bre… · webpack/webpack-cli@7daccc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7daccc7

Browse files
feat: respect the infrastructureLogging.level option (potential breaking change, logger uses stderr) (#2144)
1 parent b4f3f8b commit 7daccc7

File tree

134 files changed

+1338
-928
lines changed
  • bail
  • build-errors
  • build-warnings
  • cache
  • colors
  • config-format
  • config-lookup
  • config-name
  • config
  • core-flags
  • defaults
  • devtool
  • entry
  • env
  • error
  • help
  • hot
  • info
  • invalid-schema
  • merge
  • mode
  • name
  • no-hot
  • no-stats
  • node
  • optimization
  • output/named-bundles
  • prefetch
  • progress
  • serve
  • stats
  • target
  • unknown
  • utils
  • version
  • watch
  • zero-config
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    134 files changed

    +1338
    -928
    lines changed

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

    Lines changed: 8 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,16 +12,20 @@ describe('Serve', () => {
    1212
    }
    1313

    1414
    it('should run with cli', async () => {
    15-
    const { stdout, stderr } = await runServe([], __dirname);
    15+
    const { stderr, stdout } = await runServe([], __dirname);
    16+
    17+
    expect(stderr).toContain('Compilation starting...');
    18+
    expect(stderr).toContain('Compilation finished');
    1619
    expect(stdout).toContain('main.js');
    1720
    expect(stdout).not.toContain('HotModuleReplacementPlugin');
    18-
    expect(stderr).toHaveLength(0);
    1921
    });
    2022

    2123
    it('should work with flags', async () => {
    22-
    const { stdout, stderr } = await runServe(['--hot'], __dirname);
    24+
    const { stderr, stdout } = await runServe(['--hot'], __dirname);
    25+
    26+
    expect(stderr).toContain('Compilation starting...');
    27+
    expect(stderr).toContain('Compilation finished');
    2328
    expect(stdout).toContain('main.js');
    2429
    expect(stdout).toContain('HotModuleReplacementPlugin');
    25-
    expect(stderr).toHaveLength(0);
    2630
    });
    2731
    });

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

    Lines changed: 9 additions & 12 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,6 +1,5 @@
    11
    const packageExists = require('../utils/package-exists');
    22
    const webpack = packageExists('webpack') ? require('webpack') : undefined;
    3-
    const logger = require('../utils/logger');
    43

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

    3938
    if (!progressPlugin) {
    40-
    if (typeof this.options.progress === 'string' && this.options.progress !== 'profile') {
    41-
    logger.error(`'${this.options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`);
    42-
    process.exit(2);
    43-
    }
    44-
    4539
    new ProgressPlugin({ profile: this.options.progress === 'profile' }).apply(compiler);
    4640
    }
    4741
    }
    @@ -51,37 +45,40 @@ class CLIPlugin {
    5145
    const getCompilationName = (compilation) => (compilation.name ? ` '${compilation.name}'` : '');
    5246

    5347
    compiler.hooks.run.tap(pluginName, (compiler) => {
    54-
    logger.success(`Compilation${getCompilationName(compiler)} starting...`);
    48+
    this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
    5549
    });
    5650

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

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

    64-
    logger.success(`Compilation${getCompilationName(compiler)} starting...`);
    58+
    this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
    6559
    });
    6660

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

    70-
    logger.log(`File '${filename}' was modified, changed time is ${date} (timestamp is ${changeTime})`);
    64+
    this.logger.info(`File '${filename}' was modified`);
    65+
    this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
    7166
    });
    7267

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

    7671
    process.nextTick(() => {
    7772
    if (compiler.watchMode) {
    78-
    logger.success(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
    73+
    this.logger.info(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
    7974
    }
    8075
    });
    8176
    });
    8277
    }
    8378

    8479
    apply(compiler) {
    80+
    this.logger = compiler.getInfrastructureLogger('webpack-cli');
    81+
    8582
    if (this.options.progress && this.options.helpfulOutput) {
    8683
    this.setupProgressPlugin(compiler);
    8784
    }

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

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -219,6 +219,11 @@ class WebpackCLI {
    219219
    }
    220220
    }
    221221

    222+
    if (typeof args.progress === 'string' && args.progress !== 'profile') {
    223+
    logger.error(`'${args.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`);
    224+
    process.exit(2);
    225+
    }
    226+
    222227
    if (Object.keys(args).length === 0 && !process.env.NODE_ENV) {
    223228
    return config;
    224229
    }

    test/analyze/analyze-flag.test.js

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -22,7 +22,8 @@ describe('--analyze flag', () => {
    2222
    const { exitCode, stderr, stdout } = run(__dirname, ['-c', './analyze.config.js', '--analyze']);
    2323

    2424
    expect(exitCode).toBe(0);
    25-
    expect(stderr).toBeFalsy();
    25+
    expect(stderr).toContain('Compilation starting...');
    26+
    expect(stderr).toContain('Compilation finished');
    2627
    expect(stdout).toContain('Webpack Bundle Analyzer saved report to');
    2728
    expect(stdout.match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1);
    2829
    });

    test/bail/bail.test.js

    Lines changed: 29 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,59 +4,84 @@ const { run, runWatch } = require('../utils/test-utils');
    44

    55
    describe('bail and watch warning', () => {
    66
    it('should not log warning in not watch mode', async () => {
    7-
    const { stderr, stdout, exitCode } = await run(__dirname, ['-c', 'bail-webpack.config.js']);
    7+
    const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'bail-webpack.config.js']);
    88

    99
    expect(exitCode).toEqual(0);
    10+
    expect(stderr).toContain('Compilation starting...');
    11+
    expect(stderr).toContain('Compilation finished');
    1012
    expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    1113
    expect(stdout).toBeTruthy();
    1214
    });
    1315

    1416
    it('should not log warning in not watch mode without the "bail" option', async () => {
    15-
    const { stderr, stdout, exitCode } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']);
    17+
    const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']);
    1618

    1719
    expect(exitCode).toEqual(0);
    20+
    expect(stderr).toContain('Compilation starting...');
    21+
    expect(stderr).toContain('Compilation finished');
    1822
    expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    1923
    expect(stdout).toBeTruthy();
    2024
    });
    2125

    2226
    it('should not log warning in not watch mode without the "watch" option', async () => {
    2327
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'watch-webpack.config.js']);
    2428

    29+
    expect(stderr).toContain('Compilation starting...');
    30+
    expect(stderr).toContain('Compilation finished');
    2531
    expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    2632
    expect(stdout).toBeTruthy();
    2733
    });
    2834

    2935
    it('should not log warning without the "bail" option', async () => {
    3036
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']);
    3137

    38+
    expect(stderr).toContain('Compilation starting...');
    39+
    expect(stderr).toContain('Compilation finished');
    3240
    expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    3341
    expect(stdout).toBeTruthy();
    3442
    });
    3543

    3644
    it('should not log warning without the "bail" option', async () => {
    3745
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']);
    3846

    47+
    expect(stderr).toContain('Compilation starting...');
    48+
    expect(stderr).toContain('Compilation finished');
    3949
    expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    4050
    expect(stdout).toBeTruthy();
    4151
    });
    4252

    4353
    it('should log warning in watch mode', async () => {
    4454
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']);
    4555

    56+
    expect(stderr).toContain('Compilation starting...');
    57+
    expect(stderr).toContain('Compilation finished');
    4658
    expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    4759
    expect(stdout).toBeTruthy();
    4860
    });
    4961

    5062
    it('should log warning in watch mode', async () => {
    5163
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']);
    5264

    65+
    expect(stderr).toContain('Compilation starting...');
    66+
    expect(stderr).toContain('Compilation finished');
    5367
    expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    5468
    expect(stdout).toBeTruthy();
    5569
    });
    5670

    5771
    it('should log warning in case of multiple compilers', async () => {
    58-
    const { stderr, stdout } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js']);
    59-
    72+
    const { stderr, stdout } = await runWatch(
    73+
    __dirname,
    74+
    ['-c', 'multi-webpack.config.js'],
    75+
    true,
    76+
    "Compiler 'second' is watching files for updates...",
    77+
    );
    78+
    79+
    expect(stderr).toContain("Compilation 'first' starting...");
    80+
    expect(stderr).toContain("Compilation 'first' finished");
    81+
    expect(stderr).toContain("Compiler 'first' is watching files for updates...");
    82+
    expect(stderr).toContain("Compilation 'second' starting...");
    83+
    expect(stderr).toContain("Compilation 'second' finished");
    84+
    expect(stderr).toContain("Compiler 'second' is watching files for updates...");
    6085
    expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
    6186
    expect(stdout).toBeTruthy();
    6287
    });

    test/build-errors/errors.test.js

    Lines changed: 12 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,18 +5,22 @@ const { resolve } = require('path');
    55

    66
    describe('errors', () => {
    77
    it('should output by default', () => {
    8-
    const { stdout, exitCode } = run(__dirname);
    8+
    const { exitCode, stderr, stdout } = run(__dirname);
    99

    10+
    expect(exitCode).toBe(1);
    11+
    expect(stderr).toContain('Compilation starting...');
    12+
    expect(stderr).toContain('Compilation finished');
    1013
    expect(stdout).toMatch(/ERROR/);
    1114
    expect(stdout).toMatch(/Error: Can't resolve/);
    12-
    expect(exitCode).toBe(1);
    1315
    });
    1416

    1517
    it('should output JSON with the "json" flag', () => {
    16-
    const { stdout, exitCode } = run(__dirname, ['--json']);
    18+
    const { exitCode, stderr, stdout } = run(__dirname, ['--json']);
    1719

    18-
    expect(() => JSON.parse(stdout)).not.toThrow();
    1920
    expect(exitCode).toBe(1);
    21+
    expect(stderr).not.toContain('Compilation starting...');
    22+
    expect(stderr).not.toContain('Compilation finished');
    23+
    expect(() => JSON.parse(stdout)).not.toThrow();
    2024

    2125
    const json = JSON.parse(stdout);
    2226

    @@ -27,10 +31,12 @@ describe('errors', () => {
    2731
    });
    2832

    2933
    it('should store json to a file', (done) => {
    30-
    const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']);
    34+
    const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']);
    3135

    32-
    expect(stdout).toContain('stats are successfully stored as json to stats.json');
    3336
    expect(exitCode).toBe(1);
    37+
    expect(stderr).not.toContain('Compilation starting...');
    38+
    expect(stderr).not.toContain('Compilation finished');
    39+
    expect(stdout).toContain('stats are successfully stored as json to stats.json');
    3440

    3541
    stat(resolve(__dirname, './stats.json'), (err, stats) => {
    3642
    expect(err).toBe(null);

    test/build-warnings/warnings.test.js

    Lines changed: 13 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,18 +5,23 @@ const { resolve } = require('path');
    55

    66
    describe('warnings', () => {
    77
    it('should output by default', () => {
    8-
    const { stdout, exitCode } = run(__dirname);
    8+
    const { exitCode, stderr, stdout } = run(__dirname);
    99

    10+
    expect(exitCode).toBe(0);
    11+
    expect(stderr).toContain('Compilation starting...');
    12+
    expect(stderr).toContain('Compilation finished');
    1013
    expect(stdout).toMatch(/WARNING/);
    1114
    expect(stdout).toMatch(/Error: Can't resolve/);
    12-
    expect(exitCode).toBe(0);
    1315
    });
    1416

    1517
    it('should output JSON with the "json" flag', () => {
    16-
    const { stdout, exitCode } = run(__dirname, ['--json']);
    18+
    const { exitCode, stderr, stdout } = run(__dirname, ['--json']);
    1719

    18-
    expect(() => JSON.parse(stdout)).not.toThrow();
    1920
    expect(exitCode).toBe(0);
    21+
    expect(stderr).not.toContain('Compilation starting...');
    22+
    expect(stderr).not.toContain('Compilation finished');
    23+
    24+
    expect(() => JSON.parse(stdout)).not.toThrow();
    2025

    2126
    const json = JSON.parse(stdout);
    2227

    @@ -27,10 +32,12 @@ describe('warnings', () => {
    2732
    });
    2833

    2934
    it('should store json to a file', (done) => {
    30-
    const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']);
    35+
    const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']);
    3136

    32-
    expect(stdout).toContain('stats are successfully stored as json to stats.json');
    3337
    expect(exitCode).toBe(0);
    38+
    expect(stderr).not.toContain('Compilation starting...');
    39+
    expect(stderr).not.toContain('Compilation finished');
    40+
    expect(stdout).toContain('stats are successfully stored as json to stats.json');
    3441

    3542
    stat(resolve(__dirname, './stats.json'), (err, stats) => {
    3643
    expect(err).toBe(null);

    test/cache/cache.test.js

    Lines changed: 9 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -17,6 +17,8 @@ describe('cache', () => {
    1717
    let { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js', '--cache-name', 'test'], false);
    1818

    1919
    if (isWebpack5) {
    20+
    expect(stderr).toContain('Compilation starting...');
    21+
    expect(stderr).toContain('Compilation finished');
    2022
    expect(stderr).toContain('No pack exists at');
    2123
    expect(stderr).toContain('Stored pack');
    2224
    expect(stdout).toBeTruthy();
    @@ -28,6 +30,8 @@ describe('cache', () => {
    2830

    2931
    if (isWebpack5) {
    3032
    expect(exitCode).toEqual(0);
    33+
    expect(stderr).toContain('Compilation starting...');
    34+
    expect(stderr).toContain('Compilation finished');
    3135
    expect(stderr).toContain('restore cache container');
    3236
    expect(stderr).toContain('restore cache content metadata');
    3337
    expect(stderr).toContain('restore cache content');
    @@ -41,6 +45,9 @@ describe('cache', () => {
    4145
    let { exitCode, stderr, stdout } = run(__dirname, ['--cache-name', 'test-1'], false);
    4246

    4347
    if (isWebpack5) {
    48+
    expect(exitCode).toEqual(0);
    49+
    expect(stderr).toContain('Compilation starting...');
    50+
    expect(stderr).toContain('Compilation finished');
    4451
    expect(stderr).toContain('No pack exists at');
    4552
    expect(stderr).toContain('Stored pack');
    4653
    expect(stdout).toBeTruthy();
    @@ -52,6 +59,8 @@ describe('cache', () => {
    5259

    5360
    if (isWebpack5) {
    5461
    expect(exitCode).toEqual(0);
    62+
    expect(stderr).toContain('Compilation starting...');
    63+
    expect(stderr).toContain('Compilation finished');
    5564
    expect(stderr).toContain('restore cache container');
    5665
    expect(stderr).toContain('restore cache content metadata');
    5766
    expect(stderr).toContain('restore cache content');

    0 commit comments

    Comments
     (0)
    0