diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b2f09b31b78..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,74 +0,0 @@ -dist: trusty -language: node_js - -branches: - only: - - webpack-4 - - main - - next - - dev-1 - -cache: - yarn: true - directories: - - ".jest-cache" - - ".eslintcache" - -stages: - - basic - - advanced - -matrix: - include: - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=basic - stage: basic - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=lintunit - stage: advanced - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration - stage: advanced - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 ALTERNATIVE_SORT=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration - stage: advanced - - os: linux - node_js: "10" - env: - - NODEJS_VERSION=v15.0.0-nightly2020082003293aa3a1 - - YARN_EXTRA_ARGS="--ignore-engines" - - NO_WATCH_TESTS=1 - - JEST="--maxWorkers=2 --cacheDirectory .jest-cache" - - JOB_PART=integration - stage: advanced - fast_finish: true - -before_install: - - | - if [ "$NODEJS_VERSION" != "" ]; - then - mkdir /opt/node - curl --silent "https://nodejs.org/download/nightly/$NODEJS_VERSION/node-$NODEJS_VERSION-linux-x64.tar.gz" | tar -zxf - --directory /opt/node - export PATH="/opt/node/node-$NODEJS_VERSION-linux-x64/bin:$PATH" - node --version - fi - -install: - - yarn --frozen-lockfile $YARN_EXTRA_ARGS - - yarn link --frozen-lockfile $YARN_EXTRA_ARGS || true - - yarn link webpack --frozen-lockfile $YARN_EXTRA_ARGS - -script: yarn travis:$JOB_PART - -after_success: - - cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose - - bash <(curl -s https://codecov.io/bash) -F $JOB_PART -X gcov - - rm -f .jest-cache/haste-map* .jest-cache/perf-cache* - -notifications: - slack: - secure: JduSdKWwbnLCwo7Z4E59SGE+Uw832UwnXzQiKEpg1BV45MYDPRiGltly1tRHmPh9OGjvGx3XSkC2tNGOBLtL4UL2SCkf012x0t7jDutKRfcv/njynl8jk8l+UhPmaWiHXDQAgGiiKdL4RfzPLW3HeVHCOWm0LKMzcarTa8tw+rE= diff --git a/examples/css/README.md b/examples/css/README.md index fb3b35f3464..08b76f663b4 100644 --- a/examples/css/README.md +++ b/examples/css/README.md @@ -208,7 +208,7 @@ module.exports = __webpack_require__.p + "89a353e9c515885abd8e.png"; /******/ var links = document.getElementsByTagName("link"); /******/ for(var i = 0; i < links.length; i++) { /******/ var l = links[i]; -/******/ if(l.href == url || l.getAttribute("href") == url || l.getAttribute("data-webpack") == uniqueName + ":" + key) { link = l; break; } +/******/ if(l.rel == "stylesheet" && (l.href == url || l.getAttribute("href") == url || l.getAttribute("data-webpack") == uniqueName + ":" + key)) { link = l; break; } /******/ } /******/ if(!done) return link; /******/ @@ -233,6 +233,7 @@ module.exports = __webpack_require__.p + "89a353e9c515885abd8e.png"; /******/ link.onerror = onLinkComplete.bind(null, link.onerror); /******/ link.onload = onLinkComplete.bind(null, link.onload); /******/ } else onLinkComplete(undefined, { type: 'load', target: link }); +/******/ /******/ needAttach && document.head.appendChild(link); /******/ return link; /******/ }; @@ -486,12 +487,12 @@ head{--webpack-app-1:_7;} ## Unoptimized ``` -assets by chunk 16.8 KiB (name: main) - asset output.js 16.4 KiB [emitted] (name: main) +assets by chunk 16.9 KiB (name: main) + asset output.js 16.5 KiB [emitted] (name: main) asset output.css 385 bytes [emitted] (name: main) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main) asset 1.output.css 49 bytes [emitted] -Entrypoint main 16.8 KiB (14.6 KiB) = output.js 16.4 KiB output.css 385 bytes 1 auxiliary asset +Entrypoint main 16.9 KiB (14.6 KiB) = output.js 16.5 KiB output.css 385 bytes 1 auxiliary asset chunk (runtime: main) output.js, output.css (main) 218 bytes (javascript) 335 bytes (css) 14.6 KiB (asset) 42 bytes (css-import) 10 KiB (runtime) [entry] [rendered] > ./example.js main runtime modules 10 KiB 9 modules @@ -512,12 +513,12 @@ webpack 5.66.0 compiled successfully ## Production mode ``` -assets by chunk 4.23 KiB (name: main) - asset output.js 3.85 KiB [emitted] [minimized] (name: main) +assets by chunk 4.25 KiB (name: main) + asset output.js 3.87 KiB [emitted] [minimized] (name: main) asset output.css 385 bytes [emitted] (name: main) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main) asset 159.output.css 53 bytes [emitted] -Entrypoint main 4.23 KiB (14.6 KiB) = output.js 3.85 KiB output.css 385 bytes 1 auxiliary asset +Entrypoint main 4.25 KiB (14.6 KiB) = output.js 3.87 KiB output.css 385 bytes 1 auxiliary asset chunk (runtime: main) 159.output.css 23 bytes > ./lazy-style.css ./example.js 4:0-26 ./lazy-style.css 23 bytes [built] [code generated] diff --git a/lib/Cache.js b/lib/Cache.js index 2f553bef93c..e76f8b63b5f 100644 --- a/lib/Cache.js +++ b/lib/Cache.js @@ -21,7 +21,7 @@ const { /** * @template T * @callback CallbackCache - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result * @returns {void} */ diff --git a/lib/CacheFacade.js b/lib/CacheFacade.js index 89c7658b580..9e1d00ec0e4 100644 --- a/lib/CacheFacade.js +++ b/lib/CacheFacade.js @@ -19,7 +19,7 @@ const mergeEtags = require("./cache/mergeEtags"); /** * @template T * @callback CallbackCache - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result * @returns {void} */ @@ -27,7 +27,7 @@ const mergeEtags = require("./cache/mergeEtags"); /** * @template T * @callback CallbackNormalErrorCache - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result * @returns {void} */ diff --git a/lib/CleanPlugin.js b/lib/CleanPlugin.js index e6fbf1d6016..074b90bf450 100644 --- a/lib/CleanPlugin.js +++ b/lib/CleanPlugin.js @@ -45,7 +45,7 @@ const validate = createSchemaValidation( * @param {OutputFileSystem} fs filesystem * @param {string} outputPath output path * @param {Set} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator) - * @param {function(Error=, Set=): void} callback returns the filenames of the assets that shouldn't be there + * @param {function((Error | null)=, Set=): void} callback returns the filenames of the assets that shouldn't be there * @returns {void} */ const getDiffToFs = (fs, outputPath, currentAssets, callback) => { diff --git a/lib/Compilation.js b/lib/Compilation.js index 0e3ed08aa81..b949ce134c2 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -116,34 +116,34 @@ const { isSourceEqual } = require("./util/source"); /** * @callback Callback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @returns {void} */ /** * @callback ModuleCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {Module=} result * @returns {void} */ /** * @callback ModuleFactoryResultCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {ModuleFactoryResult=} result * @returns {void} */ /** * @callback ModuleOrFactoryResultCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {Module | ModuleFactoryResult=} result * @returns {void} */ /** * @callback ExecuteModuleCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {ExecuteModuleResult=} result * @returns {void} */ @@ -1020,7 +1020,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** @type {Map} */ this.dependencyFactories = new Map(); /** @type {DependencyTemplates} */ - this.dependencyTemplates = new DependencyTemplates(); + this.dependencyTemplates = new DependencyTemplates( + this.outputOptions.hashFunction + ); this.childrenCounters = {}; /** @type {Set} */ this.usedChunkIds = null; diff --git a/lib/Compiler.js b/lib/Compiler.js index 2d7ccc1e5a6..f232d8cf4d6 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -58,13 +58,13 @@ const { isSourceEqual } = require("./util/source"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ /** * @callback RunAsChildCallback - * @param {Error=} err + * @param {(Error | null)=} err * @param {Chunk[]=} entries * @param {Compilation=} compilation */ diff --git a/lib/ContextModule.js b/lib/ContextModule.js index a1aca892184..e7170d44b53 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -71,7 +71,7 @@ const makeSerializable = require("./util/makeSerializable"); /** * @callback ResolveDependenciesCallback - * @param {Error=} err + * @param {(Error | null)=} err * @param {ContextElementDependency[]=} dependencies */ @@ -149,12 +149,9 @@ class ContextModule extends Module { this.resolveDependencies = undefined; } - prettyRegExp(regexString) { - // remove the "/" at the front and the beginning - // "/foo/" -> "foo" - return regexString - .substring(1, regexString.length - 1) - .replace(/!/g, "%21"); + _prettyRegExp(regexString, stripSlash = true) { + const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C"); + return stripSlash ? str.substring(1, str.length - 1) : str; } _createIdentifier() { @@ -175,13 +172,19 @@ class ContextModule extends Module { identifier += `|${this.options.addon}`; } if (this.options.regExp) { - identifier += `|${this.options.regExp}`; + identifier += `|${this._prettyRegExp(this.options.regExp, false)}`; } if (this.options.include) { - identifier += `|include: ${this.options.include}`; + identifier += `|include: ${this._prettyRegExp( + this.options.include, + false + )}`; } if (this.options.exclude) { - identifier += `|exclude: ${this.options.exclude}`; + identifier += `|exclude: ${this._prettyRegExp( + this.options.exclude, + false + )}`; } if (this.options.referencedExports) { identifier += `|referencedExports: ${JSON.stringify( @@ -231,13 +234,13 @@ class ContextModule extends Module { identifier += ` ${requestShortener.shorten(this.options.addon)}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; + identifier += ` ${this._prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; + identifier += ` include: ${this._prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; + identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports @@ -272,6 +275,7 @@ class ContextModule extends Module { this.context, options.associatedObjectForCache ); + if (this.layer) identifier = `(${this.layer})/${identifier}`; if (this.options.mode) { identifier += ` ${this.options.mode}`; } @@ -286,13 +290,13 @@ class ContextModule extends Module { )}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; + identifier += ` ${this._prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; + identifier += ` include: ${this._prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; + identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports @@ -312,7 +316,7 @@ class ContextModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild({ fileSystemInfo }, callback) { diff --git a/lib/DelegatedModule.js b/lib/DelegatedModule.js index 98e0ca8f46d..76cb0a48db9 100644 --- a/lib/DelegatedModule.js +++ b/lib/DelegatedModule.js @@ -91,7 +91,7 @@ class DelegatedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/DependencyTemplates.js b/lib/DependencyTemplates.js index 45268e13adb..5f7f30e0273 100644 --- a/lib/DependencyTemplates.js +++ b/lib/DependencyTemplates.js @@ -57,7 +57,7 @@ class DependencyTemplates { } clone() { - const newInstance = new DependencyTemplates(); + const newInstance = new DependencyTemplates(this._hashFunction); newInstance._map = new Map(this._map); newInstance._hash = this._hash; return newInstance; diff --git a/lib/DllModule.js b/lib/DllModule.js index a4321d0d6f1..83b2d95a99a 100644 --- a/lib/DllModule.js +++ b/lib/DllModule.js @@ -96,7 +96,7 @@ class DllModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index cdd236992ff..e6831dbab4e 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -432,7 +432,7 @@ class ExternalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/ExternalModuleFactoryPlugin.js b/lib/ExternalModuleFactoryPlugin.js index 171720dcfa4..92d56470025 100644 --- a/lib/ExternalModuleFactoryPlugin.js +++ b/lib/ExternalModuleFactoryPlugin.js @@ -117,7 +117,7 @@ class ExternalModuleFactoryPlugin { /** * @param {Externals} externals externals config - * @param {function(Error=, ExternalModule=): void} callback callback + * @param {function((Error | null)=, ExternalModule=): void} callback callback * @returns {void} */ const handleExternals = (externals, callback) => { diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index 584476263e3..cfa01bb80e3 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -1185,7 +1185,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ getFileTimestamp(path, callback) { @@ -1196,7 +1196,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ getContextTimestamp(path, callback) { @@ -1217,7 +1217,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ _getUnresolvedContextTimestamp(path, callback) { @@ -1228,7 +1228,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function(WebpackError=, string=): void} callback callback function + * @param {function((WebpackError | null)=, string=): void} callback callback function * @returns {void} */ getFileHash(path, callback) { @@ -1239,7 +1239,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, string=): void} callback callback function + * @param {function((WebpackError | null)=, string=): void} callback callback function * @returns {void} */ getContextHash(path, callback) { @@ -1259,7 +1259,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ContextHash=): void} callback callback function + * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function * @returns {void} */ _getUnresolvedContextHash(path, callback) { @@ -1270,7 +1270,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function + * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function * @returns {void} */ getContextTsh(path, callback) { @@ -1290,7 +1290,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function + * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function * @returns {void} */ _getUnresolvedContextTsh(path, callback) { @@ -1330,7 +1330,7 @@ class FileSystemInfo { /** * @param {string} context context directory * @param {Iterable} deps dependencies - * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function + * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function * @returns {void} */ resolveBuildDependencies(context, deps, callback) { @@ -1798,7 +1798,7 @@ class FileSystemInfo { /** * @param {Map} resolveResults results from resolving - * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way + * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way * @returns {void} */ checkResolveResultsValid(resolveResults, callback) { @@ -1880,7 +1880,7 @@ class FileSystemInfo { * @param {Object} options options object (for future extensions) * @param {boolean=} options.hash should use hash to snapshot * @param {boolean=} options.timestamp should use timestamp to snapshot - * @param {function(WebpackError=, Snapshot=): void} callback callback function + * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function * @returns {void} */ createSnapshot(startTime, files, directories, missing, options, callback) { @@ -2379,7 +2379,7 @@ class FileSystemInfo { /** * @param {Snapshot} snapshot the snapshot made - * @param {function(WebpackError=, boolean=): void} callback callback function + * @param {function((WebpackError | null)=, boolean=): void} callback callback function * @returns {void} */ checkSnapshotValid(snapshot, callback) { @@ -2399,7 +2399,7 @@ class FileSystemInfo { /** * @param {Snapshot} snapshot the snapshot made - * @param {function(WebpackError=, boolean=): void} callback callback function + * @param {function((WebpackError | null)=, boolean=): void} callback callback function * @returns {void} */ _checkSnapshotValidNoCache(snapshot, callback) { @@ -2948,7 +2948,7 @@ class FileSystemInfo { * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory * @param {function(string[], ItemType[]): T} options.reduce called from all context items - * @param {function(Error=, (T)=): void} callback callback + * @param {function((Error | null)=, (T)=): void} callback callback */ _readContext( { @@ -3131,7 +3131,7 @@ class FileSystemInfo { /** * @param {ContextFileSystemInfoEntry} entry entry - * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback + * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback * @returns {void} */ _resolveContextTimestamp(entry, callback) { @@ -3239,7 +3239,7 @@ class FileSystemInfo { /** * @param {ContextHash} entry context hash - * @param {function(Error=, string=): void} callback callback + * @param {function((Error | null)=, string=): void} callback callback * @returns {void} */ _resolveContextHash(entry, callback) { @@ -3395,7 +3395,7 @@ class FileSystemInfo { /** * @param {ContextTimestampAndHash} entry entry - * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback + * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback * @returns {void} */ _resolveContextTsh(entry, callback) { diff --git a/lib/HookWebpackError.js b/lib/HookWebpackError.js index e813d1eac87..dfb5e935899 100644 --- a/lib/HookWebpackError.js +++ b/lib/HookWebpackError.js @@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError; /** * @template T - * @param {function(WebpackError=, T=): void} callback webpack error callback + * @param {function((WebpackError | null)=, T=): void} callback webpack error callback * @param {string} hook name of hook * @returns {Callback} generic callback */ diff --git a/lib/Module.js b/lib/Module.js index e311e58a4bf..a79e620393e 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -691,7 +691,7 @@ class Module extends DependenciesBlock { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index b28cb110dc8..80468380171 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/MultiWatching.js b/lib/MultiWatching.js index 5314569c2c3..2bbd5365a1c 100644 --- a/lib/MultiWatching.js +++ b/lib/MultiWatching.js @@ -13,7 +13,7 @@ const asyncLib = require("neo-async"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 2d8b3736673..1acdd3f3d1e 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -310,7 +310,7 @@ class NormalModule extends Module { } // Info from Build - /** @type {WebpackError=} */ + /** @type {(WebpackError | null)=} */ this.error = null; /** @private @type {Source=} */ this._source = null; @@ -355,11 +355,13 @@ class NormalModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return contextify( + let ident = contextify( options.context, this.userRequest, options.associatedObjectForCache ); + if (this.layer) ident = `(${this.layer})/${ident}`; + return ident; } /** @@ -730,7 +732,7 @@ class NormalModule extends Module { * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system * @param {NormalModuleCompilationHooks} hooks the hooks - * @param {function(WebpackError=): void} callback callback function + * @param {function((WebpackError | null)=): void} callback callback function * @returns {void} */ _doBuild(options, compilation, resolver, fs, hooks, callback) { @@ -1236,7 +1238,7 @@ class NormalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/RawModule.js b/lib/RawModule.js index dc923ce17b2..91342babc31 100644 --- a/lib/RawModule.js +++ b/lib/RawModule.js @@ -74,7 +74,7 @@ class RawModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/RuntimeModule.js b/lib/RuntimeModule.js index c1bd8a9d1d6..9c955d95d09 100644 --- a/lib/RuntimeModule.js +++ b/lib/RuntimeModule.js @@ -78,7 +78,7 @@ class RuntimeModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/Watching.js b/lib/Watching.js index 8cfd357ef55..5051878eb6e 100644 --- a/lib/Watching.js +++ b/lib/Watching.js @@ -15,7 +15,7 @@ const Stats = require("./Stats"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/asset/AssetGenerator.js b/lib/asset/AssetGenerator.js index 16132e2af8a..c1967e9e7a4 100644 --- a/lib/asset/AssetGenerator.js +++ b/lib/asset/AssetGenerator.js @@ -74,6 +74,41 @@ const mergeRelatedInfo = (a, b) => { return result; }; +const encodeDataUri = (encoding, source) => { + let encodedContent; + + switch (encoding) { + case "base64": { + encodedContent = source.buffer().toString("base64"); + break; + } + case false: { + const content = source.source(); + + if (typeof content !== "string") { + encodedContent = content.toString("utf-8"); + } + + encodedContent = encodeURIComponent(encodedContent).replace( + /[!'()*]/g, + character => "%" + character.codePointAt(0).toString(16) + ); + break; + } + default: + throw new Error(`Unsupported encoding '${encoding}'`); + } + + return encodedContent; +}; + +const decodeDataUriContent = (encoding, content) => { + const isBase64 = encoding === "base64"; + return isBase64 + ? Buffer.from(content, "base64") + : Buffer.from(decodeURIComponent(content), "ascii"); +}; + const JS_TYPES = new Set(["javascript"]); const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]); @@ -158,33 +193,18 @@ class AssetGenerator extends Generator { } let encodedContent; + if ( module.resourceResolveData && - module.resourceResolveData.encoding === encoding + module.resourceResolveData.encoding === encoding && + decodeDataUriContent( + module.resourceResolveData.encoding, + module.resourceResolveData.encodedContent + ).equals(originalSource.buffer()) ) { encodedContent = module.resourceResolveData.encodedContent; } else { - switch (encoding) { - case "base64": { - encodedContent = originalSource.buffer().toString("base64"); - break; - } - case false: { - const content = originalSource.source(); - - if (typeof content !== "string") { - encodedContent = content.toString("utf-8"); - } - - encodedContent = encodeURIComponent(encodedContent).replace( - /[!'()*]/g, - character => "%" + character.codePointAt(0).toString(16) - ); - break; - } - default: - throw new Error(`Unsupported encoding '${encoding}'`); - } + encodedContent = encodeDataUri(encoding, originalSource); } encodedSource = `data:${mimeType}${ diff --git a/lib/asset/RawDataUrlModule.js b/lib/asset/RawDataUrlModule.js index 87f5e40ecf8..5d3ab32cecc 100644 --- a/lib/asset/RawDataUrlModule.js +++ b/lib/asset/RawDataUrlModule.js @@ -69,7 +69,7 @@ class RawDataUrlModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/cache/ResolverCachePlugin.js b/lib/cache/ResolverCachePlugin.js index 78d68ed7ad2..a0c0bbccbdb 100644 --- a/lib/cache/ResolverCachePlugin.js +++ b/lib/cache/ResolverCachePlugin.js @@ -106,7 +106,7 @@ class ResolverCachePlugin { * @param {Resolver} resolver the resolver * @param {Object} resolveContext context for resolving meta info * @param {Object} request the request info object - * @param {function(Error=, Object=): void} callback callback function + * @param {function((Error | null)=, Object=): void} callback callback function * @returns {void} */ const doRealResolve = ( diff --git a/lib/cli.js b/lib/cli.js index 5488a7d47ac..7165b3ccc28 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -37,6 +37,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json"); /** * @typedef {Object} ArgumentConfig * @property {string} description + * @property {string} [negatedDescription] * @property {string} path * @property {boolean} multiple * @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type @@ -96,11 +97,42 @@ const getArguments = (schema = webpackSchema) => { */ const getDescription = path => { for (const { schema } of path) { - if (schema.cli && schema.cli.helper) continue; + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.description) return schema.cli.description; + } if (schema.description) return schema.description; } }; + /** + * + * @param {PathItem[]} path path in the schema + * @returns {string | undefined} negative description + */ + const getNegatedDescription = path => { + for (const { schema } of path) { + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.negatedDescription) return schema.cli.negatedDescription; + } + } + }; + + /** + * + * @param {PathItem[]} path path in the schema + * @returns {string | undefined} reset description + */ + const getResetDescription = path => { + for (const { schema } of path) { + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.resetDescription) return schema.cli.resetDescription; + } + } + }; + /** * * @param {any} schemaPart schema @@ -142,13 +174,17 @@ const getArguments = (schema = webpackSchema) => { const addResetFlag = path => { const schemaPath = path[0].path; const name = pathToArgumentName(`${schemaPath}.reset`); - const description = getDescription(path); + const description = + getResetDescription(path) || + `Clear all items provided in '${schemaPath}' configuration. ${getDescription( + path + )}`; flags[name] = { configs: [ { type: "reset", multiple: false, - description: `Clear all items provided in '${schemaPath}' configuration. ${description}`, + description, path: schemaPath } ], @@ -167,6 +203,7 @@ const getArguments = (schema = webpackSchema) => { const argConfigBase = schemaToArgumentConfig(path[0].schema); if (!argConfigBase) return 0; + const negatedDescription = getNegatedDescription(path); const name = pathToArgumentName(path[0].path); /** @type {ArgumentConfig} */ const argConfig = { @@ -176,6 +213,10 @@ const getArguments = (schema = webpackSchema) => { path: path[0].path }; + if (negatedDescription) { + argConfig.negatedDescription = negatedDescription; + } + if (!flags[name]) { flags[name] = { configs: [], diff --git a/lib/config/normalization.js b/lib/config/normalization.js index 507b5460e93..cba7d6b6e54 100644 --- a/lib/config/normalization.js +++ b/lib/config/normalization.js @@ -297,6 +297,8 @@ const getNormalizedWebpackOptions = config => { chunkLoading: output.chunkLoading, chunkLoadingGlobal: output.chunkLoadingGlobal, chunkLoadTimeout: output.chunkLoadTimeout, + cssFilename: output.cssFilename, + cssChunkFilename: output.cssChunkFilename, clean: output.clean, compareBeforeEmit: output.compareBeforeEmit, crossOriginLoading: output.crossOriginLoading, diff --git a/lib/container/ContainerEntryModule.js b/lib/container/ContainerEntryModule.js index d27b767751a..0de4d58c481 100644 --- a/lib/container/ContainerEntryModule.js +++ b/lib/container/ContainerEntryModule.js @@ -79,12 +79,14 @@ class ContainerEntryModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/entry/${this._name}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/entry/${ + this._name + }`; } /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/container/FallbackModule.js b/lib/container/FallbackModule.js index cc51cae27fa..572f6813975 100644 --- a/lib/container/FallbackModule.js +++ b/lib/container/FallbackModule.js @@ -60,9 +60,9 @@ class FallbackModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/fallback/${this.requests[0]}/and ${ - this.requests.length - 1 - } more`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/fallback/${ + this.requests[0] + }/and ${this.requests.length - 1} more`; } /** @@ -76,7 +76,7 @@ class FallbackModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/container/RemoteModule.js b/lib/container/RemoteModule.js index b2bea8e33af..0c399ccfccb 100644 --- a/lib/container/RemoteModule.js +++ b/lib/container/RemoteModule.js @@ -67,12 +67,14 @@ class RemoteModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/remote/${this.request}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${ + this.request + }`; } /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/css/CssLoadingRuntimeModule.js b/lib/css/CssLoadingRuntimeModule.js index a36b0321ff4..a9d52b00a77 100644 --- a/lib/css/CssLoadingRuntimeModule.js +++ b/lib/css/CssLoadingRuntimeModule.js @@ -216,7 +216,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { "for(var i = 0; i < links.length; i++) {", Template.indent([ "var l = links[i];", - `if(${ + `if(l.rel == "stylesheet" && (${ withHmr ? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)' : 'l.href == url || l.getAttribute("href") == url' @@ -224,7 +224,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { uniqueName ? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key' : "" - }) { link = l; break; }` + })) { link = l; break; }` ]), "}", "if(!done) return link;", @@ -253,6 +253,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { "link.onload = onLinkComplete.bind(null, link.onload);" ]), "} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking + withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "", "needAttach && document.head.appendChild(link);", "return link;" ] @@ -433,7 +434,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { ]), "}" ] - )}, true);` + )}, oldTag);` ] )}));` ])});` diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 8f8dcaac814..6d6af9d39c4 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -123,9 +123,7 @@ class Profiler { * @returns {Trace} The trace object */ const createTrace = (fs, outputPath) => { - const trace = new Tracer({ - noStream: true - }); + const trace = new Tracer(); const profiler = new Profiler(inspector); if (/\/|\\/.test(outputPath)) { const dirPath = dirname(fs, outputPath); @@ -173,6 +171,7 @@ const createTrace = (fs, outputPath) => { counter, profiler, end: callback => { + trace.push("]"); // Wait until the write stream finishes. fsStream.on("close", () => { callback(); @@ -242,10 +241,10 @@ class ProfilingPlugin { stage: Infinity }, (stats, callback) => { + if (compiler.watchMode) return callback(); tracer.profiler.stopProfiling().then(parsedResults => { if (parsedResults === undefined) { tracer.profiler.destroy(); - tracer.trace.flush(); tracer.end(callback); return; } @@ -293,7 +292,6 @@ class ProfilingPlugin { }); tracer.profiler.destroy(); - tracer.trace.flush(); tracer.end(callback); }); } @@ -346,11 +344,15 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => { const makeInterceptorFor = (instance, tracer) => hookName => ({ register: ({ name, type, context, fn }) => { - const newFn = makeNewProfiledTapFn(hookName, tracer, { - name, - type, - fn - }); + const newFn = + // Don't tap our own hooks to ensure stream can close cleanly + name === pluginName + ? fn + : makeNewProfiledTapFn(hookName, tracer, { + name, + type, + fn + }); return { name, type, diff --git a/lib/dependencies/CreateScriptUrlDependency.js b/lib/dependencies/CreateScriptUrlDependency.js index 08890144a60..30b39b76d52 100644 --- a/lib/dependencies/CreateScriptUrlDependency.js +++ b/lib/dependencies/CreateScriptUrlDependency.js @@ -25,6 +25,18 @@ class CreateScriptUrlDependency extends NullDependency { get type() { return "create script url"; } + + serialize(context) { + const { write } = context; + write(this.range); + super.serialize(context); + } + + deserialize(context) { + const { read } = context; + this.range = read(); + super.deserialize(context); + } } CreateScriptUrlDependency.Template = class CreateScriptUrlDependencyTemplate extends ( diff --git a/lib/dependencies/LoaderPlugin.js b/lib/dependencies/LoaderPlugin.js index e22fef9fca1..cba0f59ebf2 100644 --- a/lib/dependencies/LoaderPlugin.js +++ b/lib/dependencies/LoaderPlugin.js @@ -16,7 +16,7 @@ const LoaderImportDependency = require("./LoaderImportDependency"); /** * @callback LoadModuleCallback - * @param {Error=} err error object + * @param {(Error | null)=} err error object * @param {string | Buffer=} source source code * @param {object=} map source map * @param {Module=} module loaded module if successful @@ -24,7 +24,7 @@ const LoaderImportDependency = require("./LoaderImportDependency"); /** * @callback ImportModuleCallback - * @param {Error=} err error object + * @param {(Error | null)=} err error object * @param {any=} exports exports of the evaluated module */ diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index 54fdb66e26e..2e3b3d3df08 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -29,6 +29,7 @@ const { registerNotSerializable } = require("../util/serialization"); /** @typedef {import("../RequestShortener")} RequestShortener */ /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */ /** @typedef {import("../WebpackError")} WebpackError */ +/** @typedef {import("../dependencies/HarmonyImportDependency")} HarmonyImportDependency */ /** @typedef {import("../util/Hash")} Hash */ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ @@ -38,7 +39,7 @@ const { registerNotSerializable } = require("../util/serialization"); * @property {function(Module): { client: string, data: string, active: boolean }} module */ -const IGNORED_DEPENDENCY_TYPES = new Set([ +const HMR_DEPENDENCY_TYPES = new Set([ "import.meta.webpackHot.accept", "import.meta.webpackHot.decline", "module.hot.accept", @@ -146,7 +147,7 @@ class LazyCompilationProxyModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -351,32 +352,55 @@ class LazyCompilationPlugin { "LazyCompilationPlugin", (originalModule, createData, resolveData) => { if ( - resolveData.dependencies.every( + resolveData.dependencies.every(dep => + HMR_DEPENDENCY_TYPES.has(dep.type) + ) + ) { + // for HMR only resolving, try to determine if the HMR accept/decline refers to + // an import() or not + const hmrDep = resolveData.dependencies[0]; + const originModule = + compilation.moduleGraph.getParentModule(hmrDep); + const isReferringToDynamicImport = originModule.blocks.some( + block => + block.dependencies.some( + dep => + dep.type === "import()" && + /** @type {HarmonyImportDependency} */ (dep).request === + hmrDep.request + ) + ); + if (!isReferringToDynamicImport) return; + } else if ( + !resolveData.dependencies.every( dep => - IGNORED_DEPENDENCY_TYPES.has(dep.type) || + HMR_DEPENDENCY_TYPES.has(dep.type) || (this.imports && (dep.type === "import()" || dep.type === "import() context element")) || (this.entries && dep.type === "entry") - ) && - !/webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test( + ) + ) + return; + if ( + /webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test( resolveData.request - ) && - checkTest(this.test, originalModule) - ) { - const moduleInfo = backend.module(originalModule); - if (!moduleInfo) return; - const { client, data, active } = moduleInfo; + ) || + !checkTest(this.test, originalModule) + ) + return; + const moduleInfo = backend.module(originalModule); + if (!moduleInfo) return; + const { client, data, active } = moduleInfo; - return new LazyCompilationProxyModule( - compiler.context, - originalModule, - resolveData.request, - client, - data, - active - ); - } + return new LazyCompilationProxyModule( + compiler.context, + originalModule, + resolveData.request, + client, + data, + active + ); } ); compilation.dependencyFactories.set( diff --git a/lib/hmr/lazyCompilationBackend.js b/lib/hmr/lazyCompilationBackend.js index 4120a89c4a7..3f480555998 100644 --- a/lib/hmr/lazyCompilationBackend.js +++ b/lib/hmr/lazyCompilationBackend.js @@ -13,7 +13,7 @@ /** * @callback BackendHandler * @param {Compiler} compiler compiler - * @param {function(Error?, any?): void} callback callback + * @param {function((Error | null)=, any=): void} callback callback * @returns {void} */ diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 36c35a3fbe0..e2c3aa9c27f 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -166,7 +166,7 @@ class Lockfile { /** * @template R * @param {function(function(Error=, R=): void): void} fn function - * @returns {function(function(Error=, R=): void): void} cached function + * @returns {function(function((Error | null)=, R=): void): void} cached function */ const cachedWithoutKey = fn => { let inFlight = false; @@ -201,10 +201,10 @@ const cachedWithoutKey = fn => { * @template R * @param {function(T, function(Error=, R=): void): void} fn function * @param {function(T, function(Error=, R=): void): void=} forceFn function for the second try - * @returns {(function(T, function(Error=, R=): void): void) & { force: function(T, function(Error=, R=): void): void }} cached function + * @returns {(function(T, function((Error | null)=, R=): void): void) & { force: function(T, function((Error | null)=, R=): void): void }} cached function */ const cachedWithKey = (fn, forceFn = fn) => { - /** @typedef {{ result?: R, error?: Error, callbacks?: (function(Error=, R=): void)[], force?: true }} CacheEntry */ + /** @typedef {{ result?: R, error?: Error, callbacks?: (function((Error | null)=, R=): void)[], force?: true }} CacheEntry */ /** @type {Map} */ const cache = new Map(); const resultFn = (arg, callback) => { @@ -358,7 +358,7 @@ class HttpUriPlugin { const getLockfile = cachedWithoutKey( /** - * @param {function(Error=, Lockfile=): void} callback callback + * @param {function((Error | null)=, Lockfile=): void} callback callback * @returns {void} */ callback => { @@ -465,7 +465,7 @@ class HttpUriPlugin { * * @param {string} url URL * @param {string} integrity integrity - * @param {function(Error=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback + * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback */ const resolveContent = (url, integrity, callback) => { const handleResult = (err, result) => { @@ -510,7 +510,7 @@ class HttpUriPlugin { /** * @param {string} url URL * @param {FetchResult} cachedResult result from cache - * @param {function(Error=, FetchResult=): void} callback callback + * @param {function((Error | null)=, FetchResult=): void} callback callback * @returns {void} */ const fetchContentRaw = (url, cachedResult, callback) => { @@ -662,7 +662,7 @@ class HttpUriPlugin { const fetchContent = cachedWithKey( /** * @param {string} url URL - * @param {function(Error=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback + * @param {function((Error | null)=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback * @returns {void} */ (url, callback) => { cache.get(url, null, (err, cachedResult) => { @@ -693,7 +693,7 @@ class HttpUriPlugin { const getInfo = cachedWithKey( /** * @param {string} url the url - * @param {function(Error=, { entry: LockfileEntry, content: Buffer }=): void} callback callback + * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer }=): void} callback callback * @returns {void} */ (url, callback) => { diff --git a/lib/sharing/ConsumeSharedModule.js b/lib/sharing/ConsumeSharedModule.js index 675fa6cf4eb..4a8e83f5900 100644 --- a/lib/sharing/ConsumeSharedModule.js +++ b/lib/sharing/ConsumeSharedModule.js @@ -101,14 +101,16 @@ class ConsumeSharedModule extends Module { */ libIdent(options) { const { shareKey, shareScope, import: request } = this.options; - return `webpack/sharing/consume/${shareScope}/${shareKey}${ + return `${ + this.layer ? `(${this.layer})/` : "" + }webpack/sharing/consume/${shareScope}/${shareKey}${ request ? `/${request}` : "" }`; } /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/sharing/ProvideSharedModule.js b/lib/sharing/ProvideSharedModule.js index bbb71ce39e9..1749ac4c859 100644 --- a/lib/sharing/ProvideSharedModule.js +++ b/lib/sharing/ProvideSharedModule.js @@ -67,12 +67,14 @@ class ProvideSharedModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/sharing/provide/${this._shareScope}/${this._name}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/sharing/provide/${ + this._shareScope + }/${this._name}`; } /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/sharing/utils.js b/lib/sharing/utils.js index 6f89da05385..aefe6f02409 100644 --- a/lib/sharing/utils.js +++ b/lib/sharing/utils.js @@ -22,7 +22,7 @@ exports.isRequiredVersion = str => { * @param {InputFileSystem} fs file system * @param {string} directory directory to start looking into * @param {string[]} descriptionFiles possible description filenames - * @param {function(Error=, {data: object, path: string}=): void} callback callback + * @param {function((Error | null)=, {data: object, path: string}=): void} callback callback */ const getDescriptionFile = (fs, directory, descriptionFiles, callback) => { let i = 0; diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index e55c90cc96c..b99ce1708eb 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -1658,84 +1658,121 @@ const collapse = children => { return newChildren; }; -const spaceLimited = (itemsAndGroups, max) => { +const spaceLimited = ( + itemsAndGroups, + max, + filteredChildrenLineReserved = false +) => { + if (max < 1) { + return { + children: undefined, + filteredChildren: getTotalItems(itemsAndGroups) + }; + } /** @type {any[] | undefined} */ let children = undefined; /** @type {number | undefined} */ let filteredChildren = undefined; // This are the groups, which take 1+ lines each - const groups = itemsAndGroups.filter(c => c.children || c.filteredChildren); + const groups = []; // The sizes of the groups are stored in groupSizes - const groupSizes = groups.map(g => getItemSize(g)); + const groupSizes = []; // This are the items, which take 1 line each - const items = itemsAndGroups.filter(c => !c.children && !c.filteredChildren); + const items = []; // The total of group sizes - let groupsSize = groupSizes.reduce((a, b) => a + b, 0); + let groupsSize = 0; + + for (const itemOrGroup of itemsAndGroups) { + // is item + if (!itemOrGroup.children && !itemOrGroup.filteredChildren) { + items.push(itemOrGroup); + } else { + groups.push(itemOrGroup); + const size = getItemSize(itemOrGroup); + groupSizes.push(size); + groupsSize += size; + } + } + if (groupsSize + items.length <= max) { // The total size in the current state fits into the max // keep all - children = groups.concat(items); - } else if ( - groups.length > 0 && - groups.length + Math.min(1, items.length) < max - ) { - // If each group would take 1 line the total would be below the maximum - // collapse some groups, keep items - while (groupsSize + items.length + (filteredChildren ? 1 : 0) > max) { + children = groups.length > 0 ? groups.concat(items) : items; + } else if (groups.length === 0) { + // slice items to max + // inner space marks that lines for filteredChildren already reserved + const limit = max - (filteredChildrenLineReserved ? 0 : 1); + filteredChildren = items.length - limit; + items.length = limit; + children = items; + } else { + // limit is the size when all groups are collapsed + const limit = + groups.length + + (filteredChildrenLineReserved || items.length === 0 ? 0 : 1); + if (limit < max) { // calculate how much we are over the size limit // this allows to approach the limit faster - // it's always > 1 - const oversize = - items.length + groupsSize + (filteredChildren ? 1 : 0) - max; - // Find the maximum group and process only this one - const maxGroupSize = Math.max(...groupSizes); - if (maxGroupSize < items.length) { - filteredChildren = items.length; - items.length = 0; - continue; - } - for (let i = 0; i < groups.length; i++) { - if (groupSizes[i] === maxGroupSize) { - const group = groups[i]; - // run this algorithm recursively and limit the size of the children to - // current size - oversize / number of groups - // So it should always end up being smaller - const headerSize = !group.children - ? 0 - : group.filteredChildren - ? 2 - : 1; - const limited = spaceLimited( - group.children, - groupSizes[i] - headerSize - oversize / groups.length - ); - groups[i] = { - ...group, - children: limited.children, - filteredChildren: - (group.filteredChildren || 0) + limited.filteredChildren - }; - const newSize = getItemSize(groups[i]); - groupsSize -= groupSizes[i] - newSize; - groupSizes[i] = newSize; - break; + let oversize; + // If each group would take 1 line the total would be below the maximum + // collapse some groups, keep items + while ( + (oversize = + groupsSize + + items.length + + (filteredChildren && !filteredChildrenLineReserved ? 1 : 0) - + max) > 0 + ) { + // Find the maximum group and process only this one + const maxGroupSize = Math.max(...groupSizes); + if (maxGroupSize < items.length) { + filteredChildren = items.length; + items.length = 0; + continue; + } + for (let i = 0; i < groups.length; i++) { + if (groupSizes[i] === maxGroupSize) { + const group = groups[i]; + // run this algorithm recursively and limit the size of the children to + // current size - oversize / number of groups + // So it should always end up being smaller + const headerSize = group.filteredChildren ? 2 : 1; + const limited = spaceLimited( + group.children, + maxGroupSize - + // we should use ceil to always feet in max + Math.ceil(oversize / groups.length) - + // we substitute size of group head + headerSize, + headerSize === 2 + ); + groups[i] = { + ...group, + children: limited.children, + filteredChildren: limited.filteredChildren + ? (group.filteredChildren || 0) + limited.filteredChildren + : group.filteredChildren + }; + const newSize = getItemSize(groups[i]); + groupsSize -= maxGroupSize - newSize; + groupSizes[i] = newSize; + break; + } } } + children = groups.concat(items); + } else if (limit === max) { + // If we have only enough space to show one line per group and one line for the filtered items + // collapse all groups and items + children = collapse(groups); + filteredChildren = items.length; + } else { + // If we have no space + // collapse complete group + filteredChildren = getTotalItems(itemsAndGroups); } - children = groups.concat(items); - } else if ( - groups.length > 0 && - groups.length + Math.min(1, items.length) <= max - ) { - // If we have only enough space to show one line per group and one line for the filtered items - // collapse all groups and items - children = groups.length ? collapse(groups) : undefined; - filteredChildren = items.length; - } else { - // If we have no space - // collapse complete group - filteredChildren = getTotalItems(itemsAndGroups); } + return { children, filteredChildren @@ -1777,6 +1814,9 @@ const reasonGroup = (children, reasons) => { }; }; +const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/; +const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/; + /** @type {Record void>} */ const ASSETS_GROUPERS = { _: (groupConfigs, context, options) => { @@ -1825,10 +1865,10 @@ const ASSETS_GROUPERS = { groupConfigs.push({ getKeys: asset => { const extensionMatch = - groupAssetsByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(asset.name); + groupAssetsByExtension && GROUP_EXTENSION_REGEXP.exec(asset.name); const extension = extensionMatch ? extensionMatch[1] : ""; const pathMatch = - groupAssetsByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(asset.name); + groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name); const path = pathMatch ? pathMatch[1].split(/[/\\]/) : []; const keys = []; if (groupAssetsByPath) { @@ -2025,10 +2065,10 @@ const MODULES_GROUPERS = type => ({ const dataUrl = /^data:[^,;]+/.exec(resource); if (dataUrl) return [dataUrl[0]]; const extensionMatch = - groupModulesByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(resource); + groupModulesByExtension && GROUP_EXTENSION_REGEXP.exec(resource); const extension = extensionMatch ? extensionMatch[1] : ""; const pathMatch = - groupModulesByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(resource); + groupModulesByPath && GROUP_PATH_REGEXP.exec(resource); const path = pathMatch ? pathMatch[1].split(/[/\\]/) : []; const keys = []; if (groupModulesByPath) { diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index 6ef17d3a1cd..d6ce9718154 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -57,6 +57,10 @@ const isValidId = id => { return typeof id === "number" || id; }; +const moreCount = (list, count) => { + return list && list.length > 0 ? `+ ${count}` : `${count}`; +}; + /** @type {Record string | void>} */ const SIMPLE_PRINTERS = { "compilation.summary!": ( @@ -182,13 +186,24 @@ const SIMPLE_PRINTERS = { }, "compilation.assetsByChunkName": () => "", - "compilation.filteredModules": filteredModules => + "compilation.filteredModules": ( + filteredModules, + { compilation: { modules } } + ) => filteredModules > 0 - ? `${filteredModules} ${plural(filteredModules, "module", "modules")}` + ? `${moreCount(modules, filteredModules)} ${plural( + filteredModules, + "module", + "modules" + )}` : undefined, "compilation.filteredAssets": (filteredAssets, { compilation: { assets } }) => filteredAssets > 0 - ? `${filteredAssets} ${plural(filteredAssets, "asset", "assets")}` + ? `${moreCount(assets, filteredAssets)} ${plural( + filteredAssets, + "asset", + "assets" + )}` : undefined, "compilation.logging": (logging, context, printer) => Array.isArray(logging) @@ -281,15 +296,19 @@ const SIMPLE_PRINTERS = { "asset.separator!": () => "\n", "asset.filteredRelated": (filteredRelated, { asset: { related } }) => filteredRelated > 0 - ? `${filteredRelated} related ${plural( + ? `${moreCount(related, filteredRelated)} related ${plural( filteredRelated, "asset", "assets" )}` : undefined, - "asset.filteredChildren": filteredChildren => + "asset.filteredChildren": (filteredChildren, { asset: { children } }) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "asset", "assets")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "asset", + "assets" + )}` : undefined, assetChunk: (id, { formatChunkId }) => formatChunkId(id), @@ -385,21 +404,29 @@ const SIMPLE_PRINTERS = { "module.issuerPath": (issuerPath, { module }) => module.profile ? undefined : "", "module.profile": profile => undefined, - "module.filteredModules": filteredModules => + "module.filteredModules": (filteredModules, { module: { modules } }) => filteredModules > 0 - ? `${filteredModules} nested ${plural( + ? `${moreCount(modules, filteredModules)} nested ${plural( filteredModules, "module", "modules" )}` : undefined, - "module.filteredReasons": filteredReasons => + "module.filteredReasons": (filteredReasons, { module: { reasons } }) => filteredReasons > 0 - ? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}` + ? `${moreCount(reasons, filteredReasons)} ${plural( + filteredReasons, + "reason", + "reasons" + )}` : undefined, - "module.filteredChildren": filteredChildren => + "module.filteredChildren": (filteredChildren, { module: { children } }) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "module", + "modules" + )}` : undefined, "module.separator!": () => "\n", @@ -417,9 +444,16 @@ const SIMPLE_PRINTERS = { "moduleReason.active": (active, { formatFlag }) => active ? undefined : formatFlag("inactive"), "moduleReason.resolvedModule": (module, { magenta }) => magenta(module), - "moduleReason.filteredChildren": filteredChildren => + "moduleReason.filteredChildren": ( + filteredChildren, + { moduleReason: { children } } + ) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "reason", + "reasons" + )}` : undefined, "module.profile.total": (value, { formatTime }) => formatTime(value), @@ -447,10 +481,21 @@ const SIMPLE_PRINTERS = { size ? formatSize(size) : undefined, "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) => size ? `(${formatSize(size)})` : undefined, - "chunkGroup.filteredAssets": n => - n > 0 ? `${n} ${plural(n, "asset", "assets")}` : undefined, - "chunkGroup.filteredAuxiliaryAssets": n => - n > 0 ? `${n} auxiliary ${plural(n, "asset", "assets")}` : undefined, + "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) => + n > 0 + ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}` + : undefined, + "chunkGroup.filteredAuxiliaryAssets": ( + n, + { chunkGroup: { auxiliaryAssets } } + ) => + n > 0 + ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural( + n, + "asset", + "assets" + )}` + : undefined, "chunkGroup.is!": () => "=", "chunkGroupAsset.name": (asset, { green }) => green(asset), "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) => @@ -510,9 +555,9 @@ const SIMPLE_PRINTERS = { "chunk.recorded": (recorded, { formatFlag, green }) => recorded ? green(formatFlag("recorded")) : undefined, "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined), - "chunk.filteredModules": filteredModules => + "chunk.filteredModules": (filteredModules, { chunk: { modules } }) => filteredModules > 0 - ? `${filteredModules} chunk ${plural( + ? `${moreCount(modules, filteredModules)} chunk ${plural( filteredModules, "module", "modules" diff --git a/lib/util/AsyncQueue.js b/lib/util/AsyncQueue.js index 9191b2e6c2b..604337d1cec 100644 --- a/lib/util/AsyncQueue.js +++ b/lib/util/AsyncQueue.js @@ -19,7 +19,7 @@ let inHandleResult = 0; /** * @template T * @callback Callback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result */ diff --git a/package.json b/package.json index b2286d3908d..38ddf25fc9d 100644 --- a/package.json +++ b/package.json @@ -143,13 +143,6 @@ "test:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.{basictest,longtest,test}.js\"", "test:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.basictest.js\"", "test:unit": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\"", - "travis:integration": "yarn cover:integration --ci $JEST", - "travis:basic": "yarn cover:basic --ci $JEST", - "travis:lintunit": "yarn lint && yarn cover:unit --ci $JEST", - "travis:benchmark": "yarn benchmark --ci", - "appveyor:integration": "yarn cover:integration --ci %JEST%", - "appveyor:unit": "yarn cover:unit --ci %JEST%", - "appveyor:benchmark": "yarn benchmark --ci", "build:examples": "cd examples && node buildAll.js", "type-report": "rimraf coverage && yarn cover:types && yarn cover:report && open-cli coverage/lcov-report/index.html", "pretest": "yarn lint", diff --git a/test/Cli.basictest.js b/test/Cli.basictest.js index 7a82fd1bc76..b3ae20301a6 100644 --- a/test/Cli.basictest.js +++ b/test/Cli.basictest.js @@ -5,6 +5,50 @@ describe("Cli", () => { expect(getArguments()).toMatchSnapshot(); }); + it("should generate the correct cli flags with custom schema", () => { + const schema = { + title: "custom CLI options", + type: "object", + additionalProperties: false, + properties: { + "with-reset-description": { + type: "array", + items: { + type: "string" + }, + description: "original description", + cli: { + resetDescription: "custom reset" + } + }, + "with-cli-description": { + type: "string", + description: "original description", + cli: { + description: "description for CLI option" + } + }, + "with-negative-description": { + type: "boolean", + description: "original description", + cli: { + negatedDescription: "custom negative description" + } + }, + "with-both-cli-and-negative-description": { + type: "boolean", + description: "original description", + cli: { + description: "description for CLI option", + negatedDescription: "custom negative description" + } + } + } + }; + + expect(getArguments(schema)).toMatchSnapshot(); + }); + const test = (name, values, config, fn) => { it(`should correctly process arguments for ${name}`, () => { const args = getArguments(); diff --git a/test/ContextModule.unittest.js b/test/ContextModule.unittest.js new file mode 100644 index 00000000000..4d3e691b111 --- /dev/null +++ b/test/ContextModule.unittest.js @@ -0,0 +1,22 @@ +"use strict"; + +const ContextModule = require("../lib/ContextModule"); + +describe("contextModule", () => { + let contextModule; + let request; + beforeEach(() => { + request = "/some/request"; + }); + describe("#identifier", () => { + it("returns an safe identifier for this module", () => { + contextModule = new ContextModule(() => {}, { + type: "javascript/auto", + request, + mode: "lazy", + regExp: /a|b/ + }); + expect(contextModule.identifier()).toContain("/a%7Cb/"); + }); + }); +}); diff --git a/test/README.md b/test/README.md index 240d58b9009..11dd2dcb7e3 100644 --- a/test/README.md +++ b/test/README.md @@ -69,4 +69,4 @@ If you are still nervous or don't quite understand, please submit an issue and t ## Footnotes -1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on Travis to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. +1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. diff --git a/test/WatchTestCases.template.js b/test/WatchTestCases.template.js index a971f3657fd..68dbce53a75 100644 --- a/test/WatchTestCases.template.js +++ b/test/WatchTestCases.template.js @@ -396,7 +396,7 @@ const describeCases = config => { done ) ) { - compiler.close(); + compiler.close(() => {}); return; } compiler.close(done); diff --git a/test/__snapshots__/Cli.basictest.js.snap b/test/__snapshots__/Cli.basictest.js.snap index 5261cf78863..641fe85d824 100644 --- a/test/__snapshots__/Cli.basictest.js.snap +++ b/test/__snapshots__/Cli.basictest.js.snap @@ -8973,3 +8973,75 @@ Object { }, } `; + +exports[`Cli should generate the correct cli flags with custom schema 1`] = ` +Object { + "with-both-cli-and-negative-description": Object { + "configs": Array [ + Object { + "description": "description for CLI option", + "multiple": false, + "negatedDescription": "custom negative description", + "path": "with-both-cli-and-negative-description", + "type": "boolean", + }, + ], + "description": "description for CLI option", + "multiple": false, + "simpleType": "boolean", + }, + "with-cli-description": Object { + "configs": Array [ + Object { + "description": "description for CLI option", + "multiple": false, + "path": "with-cli-description", + "type": "string", + }, + ], + "description": "description for CLI option", + "multiple": false, + "simpleType": "string", + }, + "with-negative-description": Object { + "configs": Array [ + Object { + "description": "original description", + "multiple": false, + "negatedDescription": "custom negative description", + "path": "with-negative-description", + "type": "boolean", + }, + ], + "description": "original description", + "multiple": false, + "simpleType": "boolean", + }, + "with-reset-description": Object { + "configs": Array [ + Object { + "description": "original description", + "multiple": true, + "path": "with-reset-description[]", + "type": "string", + }, + ], + "description": "original description", + "multiple": true, + "simpleType": "string", + }, + "with-reset-description-reset": Object { + "configs": Array [ + Object { + "description": "custom reset", + "multiple": false, + "path": "with-reset-description", + "type": "reset", + }, + ], + "description": "custom reset", + "multiple": false, + "simpleType": "boolean", + }, +} +`; diff --git a/test/__snapshots__/StatsTestCases.basictest.js.snap b/test/__snapshots__/StatsTestCases.basictest.js.snap index f464558b2bf..684cc459206 100644 --- a/test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/test/__snapshots__/StatsTestCases.basictest.js.snap @@ -1363,13 +1363,46 @@ webpack x.x.x compiled successfully in X ms" exports[`StatsTestCases should print correct stats for max-modules 1`] = ` "asset main.js 5.47 KiB [emitted] (name: main) -31 modules +./index.js 181 bytes [built] [code generated] +./a.js?1 33 bytes [built] [code generated] +./a.js?2 33 bytes [built] [code generated] +./a.js?3 33 bytes [built] [code generated] +./a.js?4 33 bytes [built] [code generated] +./a.js?5 33 bytes [built] [code generated] +./a.js?6 33 bytes [built] [code generated] +./a.js?7 33 bytes [built] [code generated] +./a.js?8 33 bytes [built] [code generated] +./a.js?9 33 bytes [built] [code generated] +./a.js?10 33 bytes [built] [code generated] +./c.js?1 33 bytes [built] [code generated] +./c.js?2 33 bytes [built] [code generated] +./c.js?3 33 bytes [built] [code generated] +./c.js?4 33 bytes [built] [code generated] +./c.js?5 33 bytes [built] [code generated] +./c.js?6 33 bytes [built] [code generated] +./c.js?7 33 bytes [built] [code generated] +./c.js?8 33 bytes [built] [code generated] ++ 12 modules webpack x.x.x compiled successfully in X ms" `; exports[`StatsTestCases should print correct stats for max-modules-default 1`] = ` "asset main.js 5.47 KiB [emitted] (name: main) -31 modules +./index.js 181 bytes [built] [code generated] +./a.js?1 33 bytes [built] [code generated] +./a.js?2 33 bytes [built] [code generated] +./a.js?3 33 bytes [built] [code generated] +./a.js?4 33 bytes [built] [code generated] +./a.js?5 33 bytes [built] [code generated] +./a.js?6 33 bytes [built] [code generated] +./a.js?7 33 bytes [built] [code generated] +./a.js?8 33 bytes [built] [code generated] +./a.js?9 33 bytes [built] [code generated] +./a.js?10 33 bytes [built] [code generated] +./c.js?1 33 bytes [built] [code generated] +./c.js?2 33 bytes [built] [code generated] +./c.js?3 33 bytes [built] [code generated] ++ 17 modules webpack x.x.x compiled successfully in X ms" `; @@ -2661,27 +2694,27 @@ exclude1: hidden assets 28.9 KiB 2 assets sourceMap exclude1-main.js.map 12.5 KiB [emitted] [dev] (auxiliary name: main) hidden assets 25 KiB 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset asset exclude1-chunk_js.js 804 bytes [emitted] hidden assets 1.57 KiB 2 assets sourceMap exclude1-chunk_js.js.map 295 bytes [emitted] [dev] hidden assets 590 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset assets by path *.css 144 bytes asset exclude1-chunk_js.css 74 bytes [emitted] hidden assets 148 bytes 2 assets sourceMap exclude1-chunk_js.css.map 197 bytes [emitted] [dev] hidden assets 394 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset asset exclude1-main.css 70 bytes [emitted] (name: main) hidden assets 140 bytes 2 assets sourceMap exclude1-main.css.map 187 bytes [emitted] [dev] (auxiliary name: main) hidden assets 374 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset exclude2: assets by path *.js 15.2 KiB @@ -3089,7 +3122,27 @@ exports[`StatsTestCases should print correct stats for scope-hoisting-bailouts 1 "runtime modules 6.83 KiB 10 modules built modules 615 bytes [built] code generated modules 530 bytes [code generated] - modules by path ./*.js 377 bytes 7 modules + ./index.js 150 bytes [built] [code generated] + Statement (ExpressionStatement) with side effects in source code at 7:0-25 + ModuleConcatenation bailout: Cannot concat with ./cjs.js: Module is not an ECMAScript module + ModuleConcatenation bailout: Cannot concat with ./eval.js: Module uses eval() + ModuleConcatenation bailout: Cannot concat with ./module-id.js: Module uses module.id + ModuleConcatenation bailout: Cannot concat with ./module-loaded.js: Module uses module.loaded + ./entry.js 32 bytes [built] [code generated] + ./cjs.js 59 bytes [built] [code generated] + CommonJS bailout: module.exports is used directly at 3:0-14 + Statement (ExpressionStatement) with side effects in source code at 1:0-26 + ModuleConcatenation bailout: Module is not an ECMAScript module + ./ref-from-cjs.js 45 bytes [built] [code generated] + ./eval.js 35 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-34 + ModuleConcatenation bailout: Module uses eval() + ./module-id.js 26 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-25 + ModuleConcatenation bailout: Module uses module.id + ./module-loaded.js 30 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-29 + ModuleConcatenation bailout: Module uses module.loaded ./concatenated.js + 2 modules 111 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with external \\"external\\": Module external \\"external\\" is not in the same chunk(s) (expected in chunk(s) unnamed chunk(s), module is in chunk(s) index) external \\"external\\" 42 bytes [built] [code generated] @@ -3124,14 +3177,18 @@ Entrypoint second 13.5 KiB = b-vendor.js 419 bytes b-second.js 13.1 KiB runtime modules 15.1 KiB 20 modules cacheable modules 975 bytes code generated modules 857 bytes [code generated] - modules by path ./*.js + 1 modules 459 bytes 3 modules - modules by path ./*.js 106 bytes - ./vendor.js 25 bytes [built] [code generated] - ./lazy_shared.js 56 bytes [built] [code generated] - ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_first.js, ./lazy_second.js - ./common_lazy_shared.js 25 bytes [built] [code generated] ./first.js + 2 modules 292 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) first, module is in chunk(s) vendor) + ./second.js + 1 modules 227 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) second, module is in chunk(s) vendor) + ./vendor.js 25 bytes [built] [code generated] + ./lazy_first.js + 1 modules 116 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_shared.js + ./lazy_shared.js 56 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_first.js, ./lazy_second.js + ./lazy_second.js + 1 modules 116 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_shared.js + ./common_lazy_shared.js 25 bytes [built] [code generated] orphan modules 118 bytes [orphan] ./common2.js 25 bytes [orphan] [built] ./module_first.js 31 bytes [orphan] [built] @@ -3149,16 +3206,7 @@ cacheable modules 823 bytes modules by path ./components/src/ 501 bytes orphan modules 315 bytes [orphan] modules by path ./components/src/CompAB/*.js 164 bytes 2 modules - modules by path ./components/src/CompC/*.js 67 bytes - ./components/src/CompC/CompC.js 33 bytes [orphan] [built] - [module unused] - [inactive] harmony side effect evaluation ./CompC ./components/src/CompC/index.js 1:0-34 - [inactive] harmony export imported specifier ./CompC ./components/src/CompC/index.js 1:0-34 - [inactive] harmony export imported specifier ./CompC ./components/src/index.js 2:0-43 (skipped side-effect-free modules) - ./components/src/CompC/index.js 34 bytes [orphan] [built] - [module unused] - [inactive] harmony side effect evaluation ./CompC ./components/src/index.js 2:0-43 - [inactive] harmony export imported specifier ./CompC ./components/src/index.js 2:0-43 + modules by path ./components/src/CompC/*.js 67 bytes 2 modules ./components/src/index.js 84 bytes [orphan] [built] [module unused] [inactive] from origin ./main.js + 1 modules @@ -3187,20 +3235,21 @@ cacheable modules 823 bytes from origin ./main.js + 1 modules [inactive] harmony side effect evaluation ./utils ./main.js + 1 modules ./components/src/CompAB/CompB.js 1:0-30 harmony import specifier ./utils ./main.js + 1 modules ./components/src/CompAB/CompB.js 5:2-5 - ./main.js + 1 modules 221 bytes [built] [code generated] - [no exports used] - entry ./main.js main - | ./main.js 144 bytes [built] - | [no exports used] - | ./components/src/CompAB/CompB.js 77 bytes [built] - | [only some exports used: default] - | [inactive] from origin ./components/src/CompAB/index.js - | [inactive] harmony side effect evaluation ./CompB ./components/src/CompAB/index.js 2:0-43 - | [inactive] harmony export imported specifier ./CompB ./components/src/CompAB/index.js 2:0-43 - | [inactive] harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40 (skipped side-effect-free modules) - | harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules) - ./foo.js 101 bytes [built] [code generated] - import() ./foo ./main.js + 1 modules ./main.js 6:0-15 + modules by path ./*.js 322 bytes + ./main.js + 1 modules 221 bytes [built] [code generated] + [no exports used] + entry ./main.js main + | ./main.js 144 bytes [built] + | [no exports used] + | ./components/src/CompAB/CompB.js 77 bytes [built] + | [only some exports used: default] + | [inactive] from origin ./components/src/CompAB/index.js + | [inactive] harmony side effect evaluation ./CompB ./components/src/CompAB/index.js 2:0-43 + | [inactive] harmony export imported specifier ./CompB ./components/src/CompAB/index.js 2:0-43 + | [inactive] harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40 (skipped side-effect-free modules) + | harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules) + ./foo.js 101 bytes [built] [code generated] + import() ./foo ./main.js + 1 modules ./main.js 6:0-15 webpack x.x.x compiled successfully in X ms" `; @@ -4110,8 +4159,16 @@ switched: ./index.js 1.19 KiB [built] [code generated] chunk (runtime: main) switched-main-879072e3.js (main-879072e3) 1.68 KiB ={1}= ={59}= ={318}= ={410}= ={520}= ={663}= ={869}= ={997}= [initial] [rendered] > ./ main - modules by path ./subfolder/*.js 1.1 KiB 11 modules - modules by path ./*.js 594 bytes 9 modules + modules by path ./subfolder/*.js 1.1 KiB + ./subfolder/big.js?1 267 bytes [built] [code generated] + ./subfolder/big.js?2 267 bytes [built] [code generated] + ./subfolder/small.js?1 66 bytes [built] [code generated] + + 8 modules + modules by path ./*.js 594 bytes + ./small.js?1 66 bytes [built] [code generated] + ./small.js?2 66 bytes [built] [code generated] + ./small.js?3 66 bytes [built] [code generated] + + 6 modules chunk (runtime: main) switched-main-12217e1d.js (main-12217e1d) 1.57 KiB (javascript) 3.01 KiB (runtime) ={1}= ={59}= ={318}= ={410}= ={520}= ={581}= ={869}= ={997}= [entry] [rendered] > ./ main runtime modules 3.01 KiB 5 modules @@ -4123,13 +4180,13 @@ switched: ./node_modules/small.js?2 66 bytes [built] [code generated] chunk (runtime: main) switched-main-7aeafcb2.js (main-7aeafcb2) 1.62 KiB ={1}= ={59}= ={318}= ={410}= ={520}= ={581}= ={663}= ={869}= [initial] [rendered] > ./ main - modules by path ./inner-module/*.js 594 bytes 9 modules + modules by path ./inner-module/*.js 594 bytes + ./inner-module/small.js?1 66 bytes [built] [code generated] + + 8 modules modules by path ./in-some-directory/*.js 531 bytes ./in-some-directory/big.js?1 267 bytes [built] [code generated] ./in-some-directory/small.js?1 66 bytes [built] [code generated] - ./in-some-directory/small.js?2 66 bytes [built] [code generated] - ./in-some-directory/small.js?3 66 bytes [built] [code generated] - ./in-some-directory/small.js?4 66 bytes [built] [code generated] + + 3 modules modules by path ./*.js 534 bytes ./big.js?1 267 bytes [built] [code generated] ./big.js?2 267 bytes [built] [code generated] diff --git a/test/configCases/asset-modules/data-url/index.js b/test/configCases/asset-modules/data-url/index.js index 2011c18894f..ee46bb5c044 100644 --- a/test/configCases/asset-modules/data-url/index.js +++ b/test/configCases/asset-modules/data-url/index.js @@ -5,6 +5,15 @@ import dataSvg from "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53M const urlSvg = new URL( "data:image/svg;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=" ); +const urlSvg2 = new URL( + "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e", + import.meta.url +); +const helloWorld = new URL("data:text/plain,Hello", import.meta.url); +const helloWorldBase64 = new URL( + "data:text/plain;base64,SGVsbG8=", + import.meta.url +); it("should generate various data-url types", () => { expect(png).toContain("data:image/png;base64,"); @@ -12,4 +21,11 @@ it("should generate various data-url types", () => { expect(jpg).toContain("data:image/jpeg;base64,"); expect(dataSvg).toContain("data:image/svg+xml;base64,"); expect(urlSvg.href).toContain("data:image/svg;base64,"); + expect(urlSvg2.href).toContain( + "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e" + ); + expect(helloWorld.href).toContain("data:text/plain,Hello%2C%20World%21"); + expect(helloWorldBase64.href).toContain( + "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" + ); }); diff --git a/test/configCases/asset-modules/data-url/loader.js b/test/configCases/asset-modules/data-url/loader.js new file mode 100644 index 00000000000..c5048a9c3df --- /dev/null +++ b/test/configCases/asset-modules/data-url/loader.js @@ -0,0 +1,4 @@ +/** @type {import("../../../../").LoaderDefinition<{ f(): any }>} */ +module.exports = function (source) { + return `${source}, World!`; +}; diff --git a/test/configCases/asset-modules/data-url/webpack.config.js b/test/configCases/asset-modules/data-url/webpack.config.js index 19be170b1e7..ab9e619ce2f 100644 --- a/test/configCases/asset-modules/data-url/webpack.config.js +++ b/test/configCases/asset-modules/data-url/webpack.config.js @@ -19,6 +19,11 @@ module.exports = { maxSize: Infinity } } + }, + { + mimetype: "text/plain", + type: "asset/inline", + loader: "./loader" } ] } diff --git a/test/hotCases/lazy-compilation/simple/index.js b/test/hotCases/lazy-compilation/simple/index.js index 1c17e850915..187b2bb4181 100644 --- a/test/hotCases/lazy-compilation/simple/index.js +++ b/test/hotCases/lazy-compilation/simple/index.js @@ -20,9 +20,21 @@ it("should compile to lazy imported module", done => { expect(generation).toBe(1); import("./module").then(result => { expect(result).toHaveProperty("default", 43); - setTimeout(() => { - done(); - }, 1000); + expect(generation).toBe(1); + module.hot.accept("./module", () => { + generation += 10; + }); + NEXT( + require("../../update")(done, true, () => { + import("./module").then(result => { + expect(result).toHaveProperty("default", 44); + expect(generation).toBe(11); + setTimeout(() => { + done(); + }, 1000); + }, done); + }) + ); }, done); }) ); diff --git a/test/hotCases/lazy-compilation/simple/module.js b/test/hotCases/lazy-compilation/simple/module.js index 48e48492637..84c81da2983 100644 --- a/test/hotCases/lazy-compilation/simple/module.js +++ b/test/hotCases/lazy-compilation/simple/module.js @@ -3,3 +3,5 @@ export default 42; export default 42; --- export default 43; +--- +export default 44; diff --git a/test/hotCases/lazy-compilation/unrelated/index.js b/test/hotCases/lazy-compilation/unrelated/index.js new file mode 100644 index 00000000000..9481047251f --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/index.js @@ -0,0 +1,25 @@ +import value from "./module"; + +const neverCalled = () => import("./lazy"); + +it("should compile to lazy imported module", done => { + let generation = 0; + module.hot.accept("./module", () => { + generation++; + }); + expect(value).toBe(42); + expect(generation).toBe(0); + NEXT( + require("../../update")(done, true, () => { + expect(value).toBe(43); + expect(generation).toBe(1); + NEXT( + require("../../update")(done, true, () => { + expect(value).toBe(44); + expect(generation).toBe(2); + done(); + }) + ); + }) + ); +}); diff --git a/test/hotCases/lazy-compilation/unrelated/lazy.js b/test/hotCases/lazy-compilation/unrelated/lazy.js new file mode 100644 index 00000000000..05e08712040 --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/lazy.js @@ -0,0 +1 @@ +export default 123; diff --git a/test/hotCases/lazy-compilation/unrelated/module.js b/test/hotCases/lazy-compilation/unrelated/module.js new file mode 100644 index 00000000000..d099aaa344e --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/module.js @@ -0,0 +1,5 @@ +export default 42; +--- +export default 43; +--- +export default 44; diff --git a/test/hotCases/lazy-compilation/unrelated/webpack.config.js b/test/hotCases/lazy-compilation/unrelated/webpack.config.js new file mode 100644 index 00000000000..aef58ef1aaf --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/webpack.config.js @@ -0,0 +1,10 @@ +"use strict"; + +/** @type {import("../../../../").Configuration} */ +module.exports = { + experiments: { + lazyCompilation: { + entries: false + } + } +}; diff --git a/test/watchCases/plugins/profiling-plugin/0/index.js b/test/watchCases/plugins/profiling-plugin/0/index.js new file mode 100644 index 00000000000..cecdb3b9c59 --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/0/index.js @@ -0,0 +1,3 @@ +it("compiles", function() { + expect(WATCH_STEP).toBe("0"); +}) \ No newline at end of file diff --git a/test/watchCases/plugins/profiling-plugin/1/index.js b/test/watchCases/plugins/profiling-plugin/1/index.js new file mode 100644 index 00000000000..5e1eb9ebdba --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/1/index.js @@ -0,0 +1,3 @@ +it("should not crash on recompile", function() { + expect(WATCH_STEP).toBe("1"); +}) diff --git a/test/watchCases/plugins/profiling-plugin/deprecations.js b/test/watchCases/plugins/profiling-plugin/deprecations.js new file mode 100644 index 00000000000..dee16addc3f --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/deprecations.js @@ -0,0 +1,3 @@ +module.exports = [ + { code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ } +]; diff --git a/test/watchCases/plugins/profiling-plugin/webpack.config.js b/test/watchCases/plugins/profiling-plugin/webpack.config.js new file mode 100644 index 00000000000..3d258a435b9 --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/webpack.config.js @@ -0,0 +1,6 @@ +var webpack = require("../../../../"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + plugins: [new webpack.debug.ProfilingPlugin()] +}; diff --git a/types.d.ts b/types.d.ts index 73c91504c0e..cb6e6ac34bf 100644 --- a/types.d.ts +++ b/types.d.ts @@ -215,6 +215,7 @@ declare interface Argument { } declare interface ArgumentConfig { description: string; + negatedDescription?: string; path: string; multiple: boolean; type: "string" | "number" | "boolean" | "path" | "enum" | "RegExp" | "reset"; @@ -675,16 +676,16 @@ declare interface CallExpressionInfo { getMembers: () => string[]; } declare interface CallbackAsyncQueue { - (err?: WebpackError, result?: T): any; + (err?: null | WebpackError, result?: T): any; } declare interface CallbackCache { - (err?: WebpackError, result?: T): void; + (err?: null | WebpackError, result?: T): void; } declare interface CallbackFunction { - (err?: Error, result?: T): any; + (err?: null | Error, result?: T): any; } declare interface CallbackNormalErrorCache { - (err?: Error, result?: T): void; + (err?: null | Error, result?: T): void; } declare interface CallbackWebpack { (err?: Error, stats?: T): void; @@ -1541,7 +1542,7 @@ declare class Compilation { getLogger(name: string | (() => string)): WebpackLogger; addModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; /** @@ -1559,21 +1560,21 @@ declare class Compilation { */ buildModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; processModuleDependencies( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; processModuleDependenciesNonRecursive(module: Module): void; handleModuleCreation( __0: HandleModuleCreationOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addModuleChain( context: string, dependency: Dependency, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addModuleTree( __0: { @@ -1590,27 +1591,27 @@ declare class Compilation { */ contextInfo?: Partial; }, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addEntry( context: string, entry: Dependency, optionsOrName: string | EntryOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addInclude( context: string, dependency: Dependency, options: EntryOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; rebuildModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; finish(callback?: any): void; unseal(): void; - seal(callback: (err?: WebpackError) => void): void; + seal(callback: (err?: null | WebpackError) => void): void; reportDependencyErrorsAndWarnings( module: Module, blocks: DependenciesBlock[] @@ -1698,7 +1699,7 @@ declare class Compilation { clearAssets(): void; createModuleAssets(): void; getRenderManifest(options: RenderManifestOptions): RenderManifestEntry[]; - createChunkAssets(callback: (err?: WebpackError) => void): void; + createChunkAssets(callback: (err?: null | WebpackError) => void): void; getPath( filename: string | ((arg0: PathData, arg1?: AssetInfo) => string), data?: PathData @@ -1734,17 +1735,20 @@ declare class Compilation { executeModule( module: Module, options: ExecuteModuleOptions, - callback: (err?: WebpackError, result?: ExecuteModuleResult) => void + callback: (err?: null | WebpackError, result?: ExecuteModuleResult) => void ): void; checkConstraints(): void; factorizeModule: { ( options: FactorizeModuleOptions & { factoryResult?: false }, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; ( options: FactorizeModuleOptions & { factoryResult: true }, - callback: (err?: WebpackError, result?: ModuleFactoryResult) => void + callback: ( + err?: null | WebpackError, + result?: ModuleFactoryResult + ) => void ): void; }; @@ -1942,7 +1946,11 @@ declare class Compiler { watch(watchOptions: WatchOptions, handler: CallbackFunction): Watching; run(callback: CallbackFunction): void; runAsChild( - callback: (err?: Error, entries?: Chunk[], compilation?: Compilation) => any + callback: ( + err?: null | Error, + entries?: Chunk[], + compilation?: Compilation + ) => any ): void; purgeInputFileSystem(): void; emitAssets(compilation: Compilation, callback: CallbackFunction): void; @@ -2476,7 +2484,10 @@ declare abstract class ContextModuleFactory extends ModuleFactory { resolveDependencies( fs: InputFileSystem, options: ContextModuleOptions, - callback: (err?: Error, dependencies?: ContextElementDependency[]) => any + callback: ( + err?: null | Error, + dependencies?: ContextElementDependency[] + ) => any ): void; } @@ -4119,40 +4130,43 @@ declare abstract class FileSystemInfo { getFileTimestamp( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: null | FileSystemInfoEntry | "ignore" ) => void ): void; getContextTimestamp( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: null | "ignore" | ResolvedContextFileSystemInfoEntry ) => void ): void; getFileHash( path: string, - callback: (arg0?: WebpackError, arg1?: string) => void + callback: (arg0?: null | WebpackError, arg1?: string) => void ): void; getContextHash( path: string, - callback: (arg0?: WebpackError, arg1?: string) => void + callback: (arg0?: null | WebpackError, arg1?: string) => void ): void; getContextTsh( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: ResolvedContextTimestampAndHash ) => void ): void; resolveBuildDependencies( context: string, deps: Iterable, - callback: (arg0?: Error, arg1?: ResolveBuildDependenciesResult) => void + callback: ( + arg0?: null | Error, + arg1?: ResolveBuildDependenciesResult + ) => void ): void; checkResolveResultsValid( resolveResults: Map, - callback: (arg0?: Error, arg1?: boolean) => void + callback: (arg0?: null | Error, arg1?: boolean) => void ): void; createSnapshot( startTime: number, @@ -4169,12 +4183,12 @@ declare abstract class FileSystemInfo { */ timestamp?: boolean; }, - callback: (arg0?: WebpackError, arg1?: Snapshot) => void + callback: (arg0?: null | WebpackError, arg1?: null | Snapshot) => void ): void; mergeSnapshots(snapshot1: Snapshot, snapshot2: Snapshot): Snapshot; checkSnapshotValid( snapshot: Snapshot, - callback: (arg0?: WebpackError, arg1?: boolean) => void + callback: (arg0?: null | WebpackError, arg1?: boolean) => void ): void; getDeprecatedFileTimestamps(): Map; getDeprecatedContextTimestamps(): Map; @@ -6219,7 +6233,7 @@ declare interface LoaderPluginLoaderContext { importModule( request: string, options: ImportModuleOptions, - callback: (err?: Error, exports?: any) => any + callback: (err?: null | Error, exports?: any) => any ): void; importModule(request: string, options?: ImportModuleOptions): Promise; } @@ -6585,7 +6599,7 @@ declare class Module extends DependenciesBlock { hasReasons(moduleGraph: ModuleGraph, runtime: RuntimeSpec): boolean; needBuild( context: NeedBuildContext, - callback: (arg0?: WebpackError, arg1?: boolean) => void + callback: (arg0?: null | WebpackError, arg1?: boolean) => void ): void; needRebuild( fileTimestamps: Map, @@ -7455,7 +7469,7 @@ declare class NormalModule extends Module { resourceResolveData?: Record; matchResource?: string; loaders: LoaderItem[]; - error?: WebpackError; + error?: null | WebpackError; restoreFromUnsafeCache( unsafeCacheData?: any, normalModuleFactory?: any diff --git a/yarn.lock b/yarn.lock index f43f46453c0..221eb3c21de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -878,9 +878,9 @@ es-module-lexer "*" "@types/eslint-scope@^3.7.0": - version "3.7.2" - resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.2.tgz#11e96a868c67acf65bf6f11d10bb89ea71d5e473" - integrity sha512-TzgYCWoPiTeRg6RQYgtuW7iODtVoKu3RVL72k3WohqhjfaOLK5Mg2T4Tg1o2bSfu0vPkoI48wdQFv5b/Xe04wQ== + version "3.7.3" + resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224" + integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g== dependencies: "@types/eslint" "*" "@types/estree" "*" @@ -925,9 +925,9 @@ "@types/istanbul-lib-report" "*" "@types/jest@^27.0.2": - version "27.0.2" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7" - integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA== + version "27.4.0" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.4.0.tgz#037ab8b872067cae842a320841693080f9cb84ed" + integrity sha512-gHl8XuC1RZ8H2j5sHv/JqsaxXkDDM9iDOgu0Wp8sjs4u/snb2PVehyWXJPr+ORA0RPpgw231mnutWI1+0hgjIQ== dependencies: jest-diff "^27.0.0" pretty-format "^27.0.0" @@ -1228,9 +1228,9 @@ acorn@^7.1.1, acorn@^7.4.0: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.2.4, acorn@^8.4.1: - version "8.6.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895" - integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw== + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== agent-base@6: version "6.0.2" @@ -1560,12 +1560,12 @@ browser-process-hrtime@^1.0.0: integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow== browserslist@^4.14.5, browserslist@^4.16.6: - version "4.18.1" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.18.1.tgz#60d3920f25b6860eb917c6c7b185576f4d8b017f" - integrity sha512-8ScCzdpPwR2wQh8IT82CA2VgDwjHyqMovPBZSNH54+tm4Jk2pCuv90gmAdH6J84OCRWi0b4gMe6O6XPXuJnjgQ== + version "4.19.1" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.1.tgz#4ac0435b35ab655896c31d53018b6dd5e9e4c9a3" + integrity sha512-u2tbbG5PdKRTUoctO3NBD8FQ5HdPh1ZXPHzp1rwaa5jTc+RV9/+RlWiAIKmjRPQF+xbGM9Kklj5bZQFa2s/38A== dependencies: - caniuse-lite "^1.0.30001280" - electron-to-chromium "^1.3.896" + caniuse-lite "^1.0.30001286" + electron-to-chromium "^1.4.17" escalade "^3.1.1" node-releases "^2.0.1" picocolors "^1.0.0" @@ -1628,10 +1628,10 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== -caniuse-lite@^1.0.30001280: - version "1.0.30001280" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001280.tgz#066a506046ba4be34cde5f74a08db7a396718fb7" - integrity sha512-kFXwYvHe5rix25uwueBxC569o53J6TpnGu0BEEn+6Lhl2vsnAumRFWEBhDft1fwyo6m1r4i+RqA4+163FpeFcA== +caniuse-lite@^1.0.30001286: + version "1.0.30001286" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001286.tgz#3e9debad420419618cfdf52dc9b6572b28a8fff6" + integrity sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ== caseless@~0.12.0: version "0.12.0" @@ -1896,9 +1896,9 @@ copy-anything@^2.0.1: is-what "^3.7.1" core-js@^3.6.5: - version "3.19.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.19.1.tgz#f6f173cae23e73a7d88fa23b6e9da329276c6641" - integrity sha512-Tnc7E9iKd/b/ff7GFbhwPVzJzPztGrChB8X8GLqoYGdEOG8IpLnK1xPyo3ZoO3HsK6TodJS58VGPOxA+hLHQMg== + version "3.20.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.20.3.tgz#c710d0a676e684522f3db4ee84e5e18a9d11d69a" + integrity sha512-vVl8j8ph6tRS3B8qir40H7yw7voy17xL0piAjlbBUsH7WIfzoedL/ZOr1OV9FyZQLWXsayOJyV4tnRyXR85/ag== core-util-is@1.0.2, core-util-is@^1.0.2, core-util-is@~1.0.0: version "1.0.2" @@ -2113,9 +2113,9 @@ data-urls@^2.0.0: whatwg-url "^8.0.0" date-fns@^2.15.0: - version "2.27.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.27.0.tgz#e1ff3c3ddbbab8a2eaadbb6106be2929a5a2d92b" - integrity sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q== + version "2.28.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.28.0.tgz#9570d656f5fc13143e50c975a3b6bbeb46cd08b2" + integrity sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw== debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2: version "4.3.2" @@ -2227,10 +2227,10 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" -electron-to-chromium@^1.3.896: - version "1.3.896" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.896.tgz#4a94efe4870b1687eafd5c378198a49da06e8a1b" - integrity sha512-NcGkBVXePiuUrPLV8IxP43n1EOtdg+dudVjrfVEUd/bOqpQUFZ2diL5PPYzbgEhZFEltdXV3AcyKwGnEQ5lhMA== +electron-to-chromium@^1.4.17: + version "1.4.18" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.18.tgz#2fb282213937986a20a653315963070e8321b3f3" + integrity sha512-i7nKjGGBE1+YUIbfLObA1EZPmN7J1ITEllbhusDk+KIk6V6gUxN9PFe36v+Sd+8Cg0k3cgUv9lQhQZalr8rggw== emittery@^0.8.1: version "0.8.1"