Skip to content

Commit

Permalink
chore: update webpack (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 6, 2021
1 parent 1adc5aa commit f9dadef
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 38 deletions.
12 changes: 10 additions & 2 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Options:
--config-name <value...> Name of the configuration to use.
-m, --merge Merge two or more configurations using 'webpack-merge'.
--env <value...> Environment passed to the configuration when it is a function.
--node-env <value> Sets process.env.NODE_ENV to the specified value
-h, --hot Enables Hot Module Replacement
--no-hot Disables Hot Module Replacement.
--analyze It invokes webpack-bundle-analyzer plugin to get bundle information.
Expand Down Expand Up @@ -52,6 +53,9 @@ Options:
--experiments-lazy-compilation-client <value> A custom client.
--experiments-lazy-compilation-entries Enable/disable lazy compilation for entries.
--no-experiments-lazy-compilation-entries Negative 'experiments-lazy-compilation-entries' option.
--experiments-lazy-compilation-imports Enable/disable lazy compilation for import() modules.
--no-experiments-lazy-compilation-imports Negative 'experiments-lazy-compilation-imports' option.
--experiments-lazy-compilation-test <value> Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.
--experiments-output-module Allow output javascript files as module source type.
--no-experiments-output-module Negative 'experiments-output-module' option.
--experiments-sync-web-assembly Support WebAssembly as synchronous EcmaScript Module (outdated).
Expand Down Expand Up @@ -428,6 +432,11 @@ Options:
--output-chunk-load-timeout <value> Number of milliseconds before chunk request expires.
--output-chunk-loading <value> The method of loading chunks (methods included by default are 'jsonp' (web), 'importScripts' (WebWorker), 'require' (sync node.js), 'async-node' (async node.js), but others might be added by plugins).
--output-chunk-loading-global <value> The global variable used by webpack for loading of chunks.
--output-clean Clean the output directory before emit.
--no-output-clean Negative 'output-clean' option.
--output-clean-dry Log the assets that should be removed instead of deleting them.
--no-output-clean-dry Negative 'output-clean-dry' option.
--output-clean-keep <value> Keep these assets.
--output-compare-before-emit Check if to be emitted file already exists and have the same content before writing to output filesystem.
--no-output-compare-before-emit Negative 'output-compare-before-emit' option.
--output-cross-origin-loading <value> This option enables cross-origin loading of chunks.
Expand Down Expand Up @@ -686,8 +695,7 @@ Options:
--stats-entrypoints <value> Display the entry points with the corresponding bundles.
--stats-env Add --env information.
--no-stats-env Negative 'stats-env' option.
--stats-error-details Add details to errors (like resolving log).
--no-stats-error-details Negative 'stats-error-details' option.
--stats-error-details <value> Add details to errors (like resolving log).
--stats-error-stack Add internal stack trace to errors.
--no-stats-error-stack Negative 'stats-error-stack' option.
--stats-errors Add errors.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"ts-jest": "^26.4.3",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack": "^5.18.0",
"webpack": "^5.21.1",
"webpack-bundle-analyzer": "^4.3.0",
"webpack-dev-server": "^3.11.1",
"yeoman-test": "^2.7.0"
Expand Down
4 changes: 3 additions & 1 deletion test/build-errors/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../utils/test-utils');
const { readFile } = require('fs');
const { resolve } = require('path');
Expand All @@ -10,7 +12,7 @@ describe('errors', () => {
expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stdout).toMatch(/ERROR/);
expect(stdout).toMatch(/Error: Can't resolve/);
expect(stripAnsi(stdout)).toMatch(/Error: Can't resolve/);
});

it('should output JSON with the "json" flag', () => {
Expand Down
4 changes: 3 additions & 1 deletion test/build-warnings/warnings.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../utils/test-utils');
const { existsSync, readFile } = require('fs');
const { resolve } = require('path');
Expand All @@ -10,7 +12,7 @@ describe('warnings', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toMatch(/WARNING/);
expect(stdout).toMatch(/Error: Can't resolve/);
expect(stripAnsi(stdout)).toMatch(/Error: Can't resolve/);
});

it('should output JSON with the "json" flag', () => {
Expand Down
36 changes: 17 additions & 19 deletions test/colors/colors.test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
'use strict';

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

describe('colors related tests', () => {
it('should output by default', () => {
const { exitCode, stderr, stdout } = run(__dirname, [], true, [], { FORCE_COLOR: true });
const { exitCode, stderr, stdout } = run(__dirname, [], { env: { FORCE_COLOR: true } });

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from flags', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose'], true, [], { FORCE_COLOR: true });
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose'], { env: { FORCE_COLOR: true } });

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from flags and from configuration', () => {
const { exitCode, stderr, stdout } = run(
__dirname,
['--stats=verbose', `--config=${resolve(__dirname, './no-stats.webpack.config.js')}`],
true,
[],
{ FORCE_COLOR: true },
{ env: { FORCE_COLOR: true } },
);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from flags and from configuration #2', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js'], true, [], {
FORCE_COLOR: true,
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js'], {
env: { FORCE_COLOR: true },
});

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should disable colored output with --no-color', () => {
Expand All @@ -68,30 +66,30 @@ describe('colors related tests', () => {
});

it('should work with the "stats" option from the configuration', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-string.webpack.config.js'], true, [], { FORCE_COLOR: true });
const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-string.webpack.config.js'], { env: { FORCE_COLOR: true } });

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from the configuration #1', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-boolean.webpack.config.js'], true, [], { FORCE_COLOR: true });
const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-boolean.webpack.config.js'], { env: { FORCE_COLOR: true } });

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from the configuration #2', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--config=no-stats.webpack.config.js'], true, [], { FORCE_COLOR: true });
const { exitCode, stderr, stdout } = run(__dirname, ['--config=no-stats.webpack.config.js'], { env: { FORCE_COLOR: true } });

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from the configuration #3', () => {
Expand All @@ -100,7 +98,7 @@ describe('colors related tests', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option from the configuration #4', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/core-flags/context-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { resolve } = require('path');
const { run, isWindows } = require('../utils/test-utils');

Expand All @@ -23,6 +24,6 @@ describe('--context flag', () => {

expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`Module not found: Error: Can't resolve './src/main.js'`);
expect(stripAnsi(stdout)).toContain(`Module not found: Error: Can't resolve './src/main.js'`);
});
});
2 changes: 2 additions & 0 deletions test/core-flags/output-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('output config related flag', () => {

if (property.includes('environment-')) {
property = property.split('environment-')[1];
} else if (property.includes('clean-')) {
property = property.split('clean-')[1];
}

const propName = hyphenToUpperCase(property);
Expand Down
2 changes: 1 addition & 1 deletion test/core-flags/stats-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('stats config related flag', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('log');
} else if (flag.name === 'stats-entrypoints') {
} else if (flag.name === 'stats-entrypoints' || flag.name === 'stats-error-details') {
const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'auto']);

expect(exitCode).toBe(0);
Expand Down
4 changes: 3 additions & 1 deletion test/defaults/output-defaults.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { existsSync } = require('fs');
const { resolve } = require('path');
const { run } = require('../utils/test-utils');
Expand All @@ -10,7 +12,7 @@ describe('output flag defaults', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
// Should print warning about config fallback
expect(stdout).toContain('option has not been set, webpack will fallback to');
expect(stripAnsi(stdout)).toContain('option has not been set, webpack will fallback to');

expect(existsSync(resolve(__dirname, './binary/main.js'))).toBeTruthy();
});
Expand Down
3 changes: 2 additions & 1 deletion test/entry/defaults-empty/entry-single-arg.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../../utils/test-utils');

describe('single entry flag empty project', () => {
Expand All @@ -8,6 +9,6 @@ describe('single entry flag empty project', () => {

expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`not found: Error: Can't resolve`);
expect(stripAnsi(stdout)).toContain(`not found: Error: Can't resolve`);
});
});
3 changes: 2 additions & 1 deletion test/entry/flag-entry/entry-with-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../../utils/test-utils');
const { existsSync, readFile } = require('fs');
const { resolve } = require('path');
Expand Down Expand Up @@ -39,6 +40,6 @@ describe('entry flag', () => {

expect(exitCode).toEqual(1);
expect(stderr).toBeFalsy();
expect(stdout).toContain("Module not found: Error: Can't resolve");
expect(stripAnsi(stdout)).toContain("Module not found: Error: Can't resolve");
});
});
8 changes: 6 additions & 2 deletions test/mode/mode-single-arg/mode-single-arg.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

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

describe('mode flags', () => {
Expand All @@ -8,8 +9,11 @@ describe('mode flags', () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toContain(`mode: 'production'`);
expect(stdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`);

const pureStdout = stripAnsi(stdout);

expect(pureStdout).not.toContain(`mode: 'production'`);
expect(pureStdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`);
});

it('should load a development config when --mode=development is passed', () => {
Expand Down
5 changes: 4 additions & 1 deletion test/prefetch/prefetch.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

const fs = require('fs');
const { join } = require('path');
const stripAnsi = require('strip-ansi');
const { run } = require('../utils/test-utils');
const rimraf = require('rimraf');

Expand All @@ -26,7 +29,7 @@ describe('prefetch', () => {
expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
// Should contain the error message
expect(stdout).toContain(`Error: Can't resolve './src/somefile.js'`);
expect(stripAnsi(stdout)).toContain(`Error: Can't resolve './src/somefile.js'`);
});

it('should log error when flag value is not supplied', () => {
Expand Down
5 changes: 4 additions & 1 deletion test/zero-config/entry-absent/zero-config.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../../utils/test-utils');

describe('Zero Config tests', () => {
Expand All @@ -7,6 +10,6 @@ describe('Zero Config tests', () => {
expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
// Entry file is absent, should log the Error from the compiler
expect(stdout).toContain("Error: Can't resolve './src'");
expect(stripAnsi(stdout)).toContain("Error: Can't resolve './src'");
});
});
9 changes: 4 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11074,10 +11074,10 @@ webpack-sources@^2.1.1:
source-list-map "^2.0.1"
source-map "^0.6.1"

webpack@^5.18.0:
version "5.19.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.19.0.tgz#1a5fee84dd63557e68336b0774ac4a1c81aa2c73"
integrity sha512-egX19vAQ8fZ4cVYtA9Y941eqJtcZAK68mQq87MMv+GTXKZOc3TpKBBxdGX+HXUYlquPxiluNsJ1VHvwwklW7CQ==
webpack@^5.21.1:
version "5.21.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.21.1.tgz#a5a13965187deeaa674a0ecea219b61060a2c38f"
integrity sha512-H/fjQiDETEZDKoZm/LhvDBxOIKf9rfOdqb2pKTHRvBFMIRtwAwYlPCgBd0gc5xiDG5DqkxAiFZgAF/4H41wMuQ==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.46"
Expand All @@ -11097,7 +11097,6 @@ webpack@^5.18.0:
loader-runner "^4.2.0"
mime-types "^2.1.27"
neo-async "^2.6.2"
pkg-dir "^5.0.0"
schema-utils "^3.0.0"
tapable "^2.1.1"
terser-webpack-plugin "^5.1.1"
Expand Down

0 comments on commit f9dadef

Please sign in to comment.