webpack 5.38.0 → 5.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +10 -10
- package/bin/webpack.js +20 -5
- package/lib/AsyncDependencyToInitialChunkError.js +0 -2
- package/lib/CaseSensitiveModulesWarning.js +0 -2
- package/lib/Chunk.js +6 -2
- package/lib/ChunkRenderError.js +0 -2
- package/lib/CodeGenerationError.js +0 -2
- package/lib/CommentCompilationWarning.js +0 -2
- package/lib/Compilation.js +43 -28
- package/lib/ConcurrentCompilationError.js +0 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextModuleFactory.js +3 -1
- package/lib/DllReferencePlugin.js +0 -2
- package/lib/ExportsInfo.js +1 -0
- package/lib/HarmonyLinkingError.js +0 -2
- package/lib/HookWebpackError.js +0 -1
- package/lib/InvalidDependenciesModuleWarning.js +0 -2
- package/lib/ModuleBuildError.js +0 -2
- package/lib/ModuleDependencyError.js +0 -2
- package/lib/ModuleDependencyWarning.js +0 -2
- package/lib/ModuleError.js +0 -2
- package/lib/ModuleNotFoundError.js +0 -2
- package/lib/ModuleParseError.js +0 -2
- package/lib/ModuleRestoreError.js +0 -2
- package/lib/ModuleStoreError.js +0 -2
- package/lib/ModuleWarning.js +0 -2
- package/lib/NoModeWarning.js +0 -2
- package/lib/NormalModule.js +0 -2
- package/lib/UnsupportedFeatureWarning.js +0 -2
- package/lib/WarnDeprecatedOptionPlugin.js +0 -2
- package/lib/WebpackError.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +4 -1
- package/lib/cli.js +1 -1
- package/lib/config/normalization.js +1 -0
- package/lib/dependencies/ContextElementDependency.js +6 -1
- package/lib/dependencies/CriticalDependencyWarning.js +0 -2
- package/lib/dependencies/ImportParserPlugin.js +1 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +0 -2
- package/lib/dependencies/SystemPlugin.js +0 -2
- package/lib/errors/BuildCycleError.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +3 -1
- package/lib/javascript/JavascriptParser.js +10 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/InnerGraphPlugin.js +33 -2
- package/lib/performance/AssetsOverSizeLimitWarning.js +0 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +0 -2
- package/lib/performance/NoAsyncChunksWarning.js +0 -2
- package/lib/serialization/PlainObjectSerializer.js +17 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +26 -4
- package/lib/util/ArrayQueue.js +8 -0
- package/lib/util/AsyncQueue.js +9 -0
- package/lib/util/LazySet.js +26 -17
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +0 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +0 -2
- package/package.json +4 -4
- package/types.d.ts +17 -11
package/README.md
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
</a>
|
41
41
|
<h1>webpack</h1>
|
42
42
|
<p>
|
43
|
-
|
43
|
+
Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
|
44
44
|
</p>
|
45
45
|
</div>
|
46
46
|
|
@@ -77,7 +77,7 @@ yarn add webpack --dev
|
|
77
77
|
|
78
78
|
<h2 align="center">Introduction</h2>
|
79
79
|
|
80
|
-
|
80
|
+
Webpack is a bundler for modules. The main purpose is to bundle JavaScript
|
81
81
|
files for usage in a browser, yet it is also capable of transforming, bundling,
|
82
82
|
or packaging just about any resource or asset.
|
83
83
|
|
@@ -95,14 +95,14 @@ Check out webpack's quick [**Get Started**](https://webpack.js.org/guides/gettin
|
|
95
95
|
|
96
96
|
### Browser Compatibility
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
Webpack supports all browsers that are [ES5-compliant](https://kangax.github.io/compat-table/es5/) (IE8 and below are not supported).
|
99
|
+
Webpack also needs `Promise` for `import()` and `require.ensure()`. If you want to support older browsers, you will need to [load a polyfill](https://webpack.js.org/guides/shimming/) before using these expressions.
|
100
100
|
|
101
101
|
<h2 align="center">Concepts</h2>
|
102
102
|
|
103
103
|
### [Plugins](https://webpack.js.org/plugins/)
|
104
104
|
|
105
|
-
|
105
|
+
Webpack has a [rich plugin
|
106
106
|
interface](https://webpack.js.org/plugins/). Most of the features
|
107
107
|
within webpack itself use this plugin interface. This makes webpack very
|
108
108
|
**flexible**.
|
@@ -129,7 +129,7 @@ within webpack itself use this plugin interface. This makes webpack very
|
|
129
129
|
|
130
130
|
### [Loaders](https://webpack.js.org/loaders/)
|
131
131
|
|
132
|
-
|
132
|
+
Webpack enables the use of loaders to preprocess files. This allows you to bundle
|
133
133
|
**any static resource** way beyond JavaScript. You can easily [write your own
|
134
134
|
loaders](https://webpack.js.org/api/loaders/) using Node.js.
|
135
135
|
|
@@ -249,23 +249,23 @@ or are automatically applied via regex from your webpack configuration.
|
|
249
249
|
|
250
250
|
### Performance
|
251
251
|
|
252
|
-
|
252
|
+
Webpack uses async I/O and has multiple caching levels. This makes webpack fast
|
253
253
|
and incredibly **fast** on incremental compilations.
|
254
254
|
|
255
255
|
### Module Formats
|
256
256
|
|
257
|
-
|
257
|
+
Webpack supports ES2015+, CommonJS and AMD modules **out of the box**. It performs clever static
|
258
258
|
analysis on the AST of your code. It even has an evaluation engine to evaluate
|
259
259
|
simple expressions. This allows you to **support most existing libraries** out of the box.
|
260
260
|
|
261
261
|
### [Code Splitting](https://webpack.js.org/guides/code-splitting/)
|
262
262
|
|
263
|
-
|
263
|
+
Webpack allows you to split your codebase into multiple chunks. Chunks are
|
264
264
|
loaded asynchronously at runtime. This reduces the initial loading time.
|
265
265
|
|
266
266
|
### [Optimizations](https://webpack.js.org/guides/production-build/)
|
267
267
|
|
268
|
-
|
268
|
+
Webpack can do many optimizations to **reduce the output size of your
|
269
269
|
JavaScript** by deduplicating frequently used modules, minifying, and giving
|
270
270
|
you full control of what is loaded initially and what is loaded at runtime
|
271
271
|
through code splitting. It can also make your code chunks **cache
|
package/bin/webpack.js
CHANGED
@@ -32,13 +32,28 @@ const runCommand = (command, args) => {
|
|
32
32
|
* @returns {boolean} is the package installed?
|
33
33
|
*/
|
34
34
|
const isInstalled = packageName => {
|
35
|
-
|
36
|
-
require.resolve(packageName);
|
37
|
-
|
35
|
+
if (process.versions.pnp) {
|
38
36
|
return true;
|
39
|
-
} catch (err) {
|
40
|
-
return false;
|
41
37
|
}
|
38
|
+
|
39
|
+
const path = require("path");
|
40
|
+
const fs = require("graceful-fs");
|
41
|
+
|
42
|
+
let dir = __dirname;
|
43
|
+
|
44
|
+
do {
|
45
|
+
try {
|
46
|
+
if (
|
47
|
+
fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()
|
48
|
+
) {
|
49
|
+
return true;
|
50
|
+
}
|
51
|
+
} catch (_error) {
|
52
|
+
// Nothing
|
53
|
+
}
|
54
|
+
} while (dir !== (dir = path.dirname(dir)));
|
55
|
+
|
56
|
+
return false;
|
42
57
|
};
|
43
58
|
|
44
59
|
/**
|
package/lib/Chunk.js
CHANGED
@@ -598,8 +598,12 @@ class Chunk {
|
|
598
598
|
*/
|
599
599
|
getAllInitialChunks() {
|
600
600
|
const chunks = new Set();
|
601
|
-
|
602
|
-
|
601
|
+
const queue = new Set(this.groupsIterable);
|
602
|
+
for (const group of queue) {
|
603
|
+
if (group.isInitial()) {
|
604
|
+
for (const c of group.chunks) chunks.add(c);
|
605
|
+
for (const g of group.childrenIterable) queue.add(g);
|
606
|
+
}
|
603
607
|
}
|
604
608
|
return chunks;
|
605
609
|
}
|
package/lib/ChunkRenderError.js
CHANGED
package/lib/Compilation.js
CHANGED
@@ -337,6 +337,31 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
|
|
337
337
|
"DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK"
|
338
338
|
);
|
339
339
|
|
340
|
+
// TODO webpack 6: remove
|
341
|
+
const defineRemovedModuleTemplates = moduleTemplates => {
|
342
|
+
Object.defineProperties(moduleTemplates, {
|
343
|
+
asset: {
|
344
|
+
enumerable: false,
|
345
|
+
configurable: false,
|
346
|
+
get: () => {
|
347
|
+
throw new WebpackError(
|
348
|
+
"Compilation.moduleTemplates.asset has been removed"
|
349
|
+
);
|
350
|
+
}
|
351
|
+
},
|
352
|
+
webassembly: {
|
353
|
+
enumerable: false,
|
354
|
+
configurable: false,
|
355
|
+
get: () => {
|
356
|
+
throw new WebpackError(
|
357
|
+
"Compilation.moduleTemplates.webassembly has been removed"
|
358
|
+
);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
});
|
362
|
+
moduleTemplates = undefined;
|
363
|
+
};
|
364
|
+
|
340
365
|
const byId = compareSelect(
|
341
366
|
/**
|
342
367
|
* @param {Chunk} c chunk
|
@@ -861,26 +886,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
861
886
|
this.moduleTemplates = {
|
862
887
|
javascript: new ModuleTemplate(this.runtimeTemplate, this)
|
863
888
|
};
|
864
|
-
|
865
|
-
asset: {
|
866
|
-
enumerable: false,
|
867
|
-
configurable: false,
|
868
|
-
get() {
|
869
|
-
throw new WebpackError(
|
870
|
-
"Compilation.moduleTemplates.asset has been removed"
|
871
|
-
);
|
872
|
-
}
|
873
|
-
},
|
874
|
-
webassembly: {
|
875
|
-
enumerable: false,
|
876
|
-
configurable: false,
|
877
|
-
get() {
|
878
|
-
throw new WebpackError(
|
879
|
-
"Compilation.moduleTemplates.webassembly has been removed"
|
880
|
-
);
|
881
|
-
}
|
882
|
-
}
|
883
|
-
});
|
889
|
+
defineRemovedModuleTemplates(this.moduleTemplates);
|
884
890
|
|
885
891
|
this.moduleGraph = new ModuleGraph();
|
886
892
|
/** @type {ChunkGraph} */
|
@@ -1999,6 +2005,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1999
2005
|
}
|
2000
2006
|
|
2001
2007
|
finish(callback) {
|
2008
|
+
this.factorizeQueue.clear();
|
2002
2009
|
if (this.profile) {
|
2003
2010
|
this.logger.time("finish module profiles");
|
2004
2011
|
const ParallelismFactorCalculator = require("./util/ParallelismFactorCalculator");
|
@@ -2233,6 +2240,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2233
2240
|
* @returns {void}
|
2234
2241
|
*/
|
2235
2242
|
seal(callback) {
|
2243
|
+
const finalCallback = err => {
|
2244
|
+
this.factorizeQueue.clear();
|
2245
|
+
this.buildQueue.clear();
|
2246
|
+
this.rebuildQueue.clear();
|
2247
|
+
this.processDependenciesQueue.clear();
|
2248
|
+
this.addModuleQueue.clear();
|
2249
|
+
return callback(err);
|
2250
|
+
};
|
2236
2251
|
const chunkGraph = new ChunkGraph(this.moduleGraph);
|
2237
2252
|
this.chunkGraph = chunkGraph;
|
2238
2253
|
|
@@ -2397,7 +2412,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2397
2412
|
|
2398
2413
|
this.hooks.optimizeTree.callAsync(this.chunks, this.modules, err => {
|
2399
2414
|
if (err) {
|
2400
|
-
return
|
2415
|
+
return finalCallback(
|
2401
2416
|
makeWebpackError(err, "Compilation.hooks.optimizeTree")
|
2402
2417
|
);
|
2403
2418
|
}
|
@@ -2409,7 +2424,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2409
2424
|
this.modules,
|
2410
2425
|
err => {
|
2411
2426
|
if (err) {
|
2412
|
-
return
|
2427
|
+
return finalCallback(
|
2413
2428
|
makeWebpackError(err, "Compilation.hooks.optimizeChunkModules")
|
2414
2429
|
);
|
2415
2430
|
}
|
@@ -2452,7 +2467,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2452
2467
|
this.hooks.beforeCodeGeneration.call();
|
2453
2468
|
this.codeGeneration(err => {
|
2454
2469
|
if (err) {
|
2455
|
-
return
|
2470
|
+
return finalCallback(err);
|
2456
2471
|
}
|
2457
2472
|
this.hooks.afterCodeGeneration.call();
|
2458
2473
|
this.logger.timeEnd("code generation");
|
@@ -2471,7 +2486,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2471
2486
|
|
2472
2487
|
this._runCodeGenerationJobs(codeGenerationJobs, err => {
|
2473
2488
|
if (err) {
|
2474
|
-
return
|
2489
|
+
return finalCallback(err);
|
2475
2490
|
}
|
2476
2491
|
|
2477
2492
|
if (shouldRecord) {
|
@@ -2491,7 +2506,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2491
2506
|
this.logger.time("process assets");
|
2492
2507
|
this.hooks.processAssets.callAsync(this.assets, err => {
|
2493
2508
|
if (err) {
|
2494
|
-
return
|
2509
|
+
return finalCallback(
|
2495
2510
|
makeWebpackError(err, "Compilation.hooks.processAssets")
|
2496
2511
|
);
|
2497
2512
|
}
|
@@ -2517,12 +2532,12 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2517
2532
|
}
|
2518
2533
|
return this.hooks.afterSeal.callAsync(err => {
|
2519
2534
|
if (err) {
|
2520
|
-
return
|
2535
|
+
return finalCallback(
|
2521
2536
|
makeWebpackError(err, "Compilation.hooks.afterSeal")
|
2522
2537
|
);
|
2523
2538
|
}
|
2524
2539
|
this.fileSystemInfo.logStatistics();
|
2525
|
-
|
2540
|
+
finalCallback();
|
2526
2541
|
});
|
2527
2542
|
});
|
2528
2543
|
};
|
@@ -2533,7 +2548,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2533
2548
|
this.createChunkAssets(err => {
|
2534
2549
|
this.logger.timeEnd("create chunk assets");
|
2535
2550
|
if (err) {
|
2536
|
-
return
|
2551
|
+
return finalCallback(err);
|
2537
2552
|
}
|
2538
2553
|
cont();
|
2539
2554
|
});
|
@@ -14,7 +14,5 @@ module.exports = class ConcurrentCompilationError extends WebpackError {
|
|
14
14
|
this.name = "ConcurrentCompilationError";
|
15
15
|
this.message =
|
16
16
|
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.";
|
17
|
-
|
18
|
-
Error.captureStackTrace(this, this.constructor);
|
19
17
|
}
|
20
18
|
};
|
package/lib/ContextModule.js
CHANGED
@@ -54,6 +54,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
54
54
|
* @property {RegExp=} include
|
55
55
|
* @property {RegExp=} exclude
|
56
56
|
* @property {RawChunkGroupOptions=} groupOptions
|
57
|
+
* @property {string=} typePrefix
|
57
58
|
* @property {string=} category
|
58
59
|
* @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
|
59
60
|
*/
|
@@ -577,7 +578,7 @@ class ContextModule extends Module {
|
|
577
578
|
fakeMapDataExpression = "fakeMap[id]"
|
578
579
|
) {
|
579
580
|
if (typeof fakeMap === "number") {
|
580
|
-
return `return ${this.getReturn(fakeMap)};`;
|
581
|
+
return `return ${this.getReturn(fakeMap, asyncModule)};`;
|
581
582
|
}
|
582
583
|
return `return ${
|
583
584
|
RuntimeGlobals.createFakeNamespaceObject
|
@@ -273,7 +273,8 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
273
273
|
include,
|
274
274
|
exclude,
|
275
275
|
referencedExports,
|
276
|
-
category
|
276
|
+
category,
|
277
|
+
typePrefix
|
277
278
|
} = options;
|
278
279
|
if (!regExp || !resource) return callback(null, []);
|
279
280
|
|
@@ -346,6 +347,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
346
347
|
const dep = new ContextElementDependency(
|
347
348
|
obj.request + resourceQuery + resourceFragment,
|
348
349
|
obj.request,
|
350
|
+
typePrefix,
|
349
351
|
category,
|
350
352
|
referencedExports
|
351
353
|
);
|
package/lib/ExportsInfo.js
CHANGED
package/lib/HookWebpackError.js
CHANGED
package/lib/ModuleBuildError.js
CHANGED
@@ -30,8 +30,6 @@ class ModuleDependencyError extends WebpackError {
|
|
30
30
|
/** error is not (de)serialized, so it might be undefined after deserialization */
|
31
31
|
this.error = err;
|
32
32
|
|
33
|
-
Error.captureStackTrace(this, this.constructor);
|
34
|
-
|
35
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
36
34
|
this.stack =
|
37
35
|
err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
|
@@ -30,8 +30,6 @@ class ModuleDependencyWarning extends WebpackError {
|
|
30
30
|
/** error is not (de)serialized, so it might be undefined after deserialization */
|
31
31
|
this.error = err;
|
32
32
|
|
33
|
-
Error.captureStackTrace(this, this.constructor);
|
34
|
-
|
35
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
36
34
|
this.stack =
|
37
35
|
err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
|
package/lib/ModuleError.js
CHANGED
package/lib/ModuleParseError.js
CHANGED
package/lib/ModuleStoreError.js
CHANGED
package/lib/ModuleWarning.js
CHANGED
package/lib/NoModeWarning.js
CHANGED
@@ -18,7 +18,5 @@ module.exports = class NoModeWarning extends WebpackError {
|
|
18
18
|
"Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
|
19
19
|
"You can also set it to 'none' to disable any default behavior. " +
|
20
20
|
"Learn more: https://webpack.js.org/configuration/mode/";
|
21
|
-
|
22
|
-
Error.captureStackTrace(this, this.constructor);
|
23
21
|
}
|
24
22
|
};
|
package/lib/NormalModule.js
CHANGED
package/lib/WebpackError.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
const FileSystemInfo = require("../FileSystemInfo");
|
9
9
|
const ProgressPlugin = require("../ProgressPlugin");
|
10
10
|
const { formatSize } = require("../SizeFormatHelpers");
|
11
|
+
const SerializerMiddleware = require("../serialization/SerializerMiddleware");
|
11
12
|
const LazySet = require("../util/LazySet");
|
12
13
|
const makeSerializable = require("../util/makeSerializable");
|
13
14
|
const memoize = require("../util/memoize");
|
@@ -677,7 +678,7 @@ class PackContent {
|
|
677
678
|
*/
|
678
679
|
constructor(items, usedItems, dataOrFn, logger, lazyName) {
|
679
680
|
this.items = items;
|
680
|
-
/** @type {function(): PackContentItems |
|
681
|
+
/** @type {function(): Promise<PackContentItems> | PackContentItems } */
|
681
682
|
this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
|
682
683
|
/** @type {Map<string, any>} */
|
683
684
|
this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
|
@@ -715,6 +716,7 @@ class PackContent {
|
|
715
716
|
this.logger.timeEnd(timeMessage);
|
716
717
|
}
|
717
718
|
this.content = map;
|
719
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
718
720
|
return map.get(identifier);
|
719
721
|
});
|
720
722
|
} else {
|
@@ -723,6 +725,7 @@ class PackContent {
|
|
723
725
|
this.logger.timeEnd(timeMessage);
|
724
726
|
}
|
725
727
|
this.content = map;
|
728
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
726
729
|
return map.get(identifier);
|
727
730
|
}
|
728
731
|
}
|
package/lib/cli.js
CHANGED
@@ -148,7 +148,7 @@ const getArguments = (schema = webpackSchema) => {
|
|
148
148
|
{
|
149
149
|
type: "reset",
|
150
150
|
multiple: false,
|
151
|
-
description: `Clear all items provided in configuration. ${description}`,
|
151
|
+
description: `Clear all items provided in '${schemaPath}' configuration. ${description}`,
|
152
152
|
path: schemaPath
|
153
153
|
}
|
154
154
|
],
|
@@ -129,6 +129,7 @@ const getNormalizedWebpackOptions = config => {
|
|
129
129
|
case "filesystem":
|
130
130
|
return {
|
131
131
|
type: "filesystem",
|
132
|
+
allowCollectingMemory: cache.allowCollectingMemory,
|
132
133
|
maxMemoryGenerations: cache.maxMemoryGenerations,
|
133
134
|
maxAge: cache.maxAge,
|
134
135
|
profile: cache.profile,
|
@@ -14,9 +14,10 @@ const ModuleDependency = require("./ModuleDependency");
|
|
14
14
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
15
15
|
|
16
16
|
class ContextElementDependency extends ModuleDependency {
|
17
|
-
constructor(request, userRequest, category, referencedExports) {
|
17
|
+
constructor(request, userRequest, typePrefix, category, referencedExports) {
|
18
18
|
super(request);
|
19
19
|
this.referencedExports = referencedExports;
|
20
|
+
this._typePrefix = typePrefix;
|
20
21
|
this._category = category;
|
21
22
|
|
22
23
|
if (userRequest) {
|
@@ -25,6 +26,10 @@ class ContextElementDependency extends ModuleDependency {
|
|
25
26
|
}
|
26
27
|
|
27
28
|
get type() {
|
29
|
+
if (this._typePrefix) {
|
30
|
+
return `${this._typePrefix} context element`;
|
31
|
+
}
|
32
|
+
|
28
33
|
return "context element";
|
29
34
|
}
|
30
35
|
|
@@ -350,7 +350,9 @@ class LazyCompilationPlugin {
|
|
350
350
|
resolveData.dependencies.every(
|
351
351
|
dep =>
|
352
352
|
IGNORED_DEPENDENCY_TYPES.has(dep.type) ||
|
353
|
-
(this.imports &&
|
353
|
+
(this.imports &&
|
354
|
+
(dep.type === "import()" ||
|
355
|
+
dep.type === "import() context element")) ||
|
354
356
|
(this.entries && dep.type === "entry")
|
355
357
|
) &&
|
356
358
|
!/webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client/.test(
|
@@ -175,11 +175,18 @@ class JavascriptParser extends Parser {
|
|
175
175
|
/** @type {SyncBailHook<[IfStatementNode], boolean | void>} */
|
176
176
|
statementIf: new SyncBailHook(["statement"]),
|
177
177
|
/** @type {SyncBailHook<[ExpressionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
178
|
-
classExtendsExpression: new SyncBailHook([
|
178
|
+
classExtendsExpression: new SyncBailHook([
|
179
|
+
"expression",
|
180
|
+
"classDefinition"
|
181
|
+
]),
|
179
182
|
/** @type {SyncBailHook<[MethodDefinitionNode | PropertyDefinitionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
180
|
-
classBodyElement: new SyncBailHook(["element", "
|
183
|
+
classBodyElement: new SyncBailHook(["element", "classDefinition"]),
|
181
184
|
/** @type {SyncBailHook<[ExpressionNode, MethodDefinitionNode | PropertyDefinitionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
182
|
-
classBodyValue: new SyncBailHook([
|
185
|
+
classBodyValue: new SyncBailHook([
|
186
|
+
"expression",
|
187
|
+
"element",
|
188
|
+
"classDefinition"
|
189
|
+
]),
|
183
190
|
/** @type {HookMap<SyncBailHook<[LabeledStatementNode], boolean | void>>} */
|
184
191
|
label: new HookMap(() => new SyncBailHook(["statement"])),
|
185
192
|
/** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
|
@@ -238,12 +238,25 @@ class InnerGraphPlugin {
|
|
238
238
|
}
|
239
239
|
);
|
240
240
|
|
241
|
+
parser.hooks.classBodyElement.tap(
|
242
|
+
"InnerGraphPlugin",
|
243
|
+
(element, classDefinition) => {
|
244
|
+
if (!InnerGraph.isEnabled(parser.state)) return;
|
245
|
+
if (parser.scope.topLevelScope === true) {
|
246
|
+
const fn = classWithTopLevelSymbol.get(classDefinition);
|
247
|
+
if (fn) {
|
248
|
+
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
);
|
253
|
+
|
241
254
|
parser.hooks.classBodyValue.tap(
|
242
255
|
"InnerGraphPlugin",
|
243
|
-
(expression, element,
|
256
|
+
(expression, element, classDefinition) => {
|
244
257
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
245
258
|
if (parser.scope.topLevelScope === true) {
|
246
|
-
const fn = classWithTopLevelSymbol.get(
|
259
|
+
const fn = classWithTopLevelSymbol.get(classDefinition);
|
247
260
|
if (fn) {
|
248
261
|
if (
|
249
262
|
!element.static ||
|
@@ -253,6 +266,24 @@ class InnerGraphPlugin {
|
|
253
266
|
)
|
254
267
|
) {
|
255
268
|
InnerGraph.setTopLevelSymbol(parser.state, fn);
|
269
|
+
if (element.type !== "MethodDefinition" && element.static) {
|
270
|
+
InnerGraph.onUsage(parser.state, usedByExports => {
|
271
|
+
switch (usedByExports) {
|
272
|
+
case undefined:
|
273
|
+
case true:
|
274
|
+
return;
|
275
|
+
default: {
|
276
|
+
const dep = new PureExpressionDependency(
|
277
|
+
expression.range
|
278
|
+
);
|
279
|
+
dep.loc = expression.loc;
|
280
|
+
dep.usedByExports = usedByExports;
|
281
|
+
parser.state.module.addDependency(dep);
|
282
|
+
break;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
});
|
286
|
+
}
|
256
287
|
} else {
|
257
288
|
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
258
289
|
}
|
@@ -7,19 +7,21 @@
|
|
7
7
|
const cache = new WeakMap();
|
8
8
|
|
9
9
|
class ObjectStructure {
|
10
|
-
constructor(
|
11
|
-
this.keys =
|
12
|
-
this.children =
|
10
|
+
constructor() {
|
11
|
+
this.keys = undefined;
|
12
|
+
this.children = undefined;
|
13
13
|
}
|
14
14
|
|
15
|
-
getKeys() {
|
15
|
+
getKeys(keys) {
|
16
|
+
if (this.keys === undefined) this.keys = keys;
|
16
17
|
return this.keys;
|
17
18
|
}
|
18
19
|
|
19
20
|
key(key) {
|
21
|
+
if (this.children === undefined) this.children = new Map();
|
20
22
|
const child = this.children.get(key);
|
21
23
|
if (child !== undefined) return child;
|
22
|
-
const newChild = new ObjectStructure(
|
24
|
+
const newChild = new ObjectStructure();
|
23
25
|
this.children.set(key, newChild);
|
24
26
|
return newChild;
|
25
27
|
}
|
@@ -28,20 +30,27 @@ class ObjectStructure {
|
|
28
30
|
const getCachedKeys = (keys, cacheAssoc) => {
|
29
31
|
let root = cache.get(cacheAssoc);
|
30
32
|
if (root === undefined) {
|
31
|
-
root = new ObjectStructure(
|
33
|
+
root = new ObjectStructure();
|
32
34
|
cache.set(cacheAssoc, root);
|
33
35
|
}
|
34
36
|
let current = root;
|
35
37
|
for (const key of keys) {
|
36
38
|
current = current.key(key);
|
37
39
|
}
|
38
|
-
return current.getKeys();
|
40
|
+
return current.getKeys(keys);
|
39
41
|
};
|
40
42
|
|
41
43
|
class PlainObjectSerializer {
|
42
44
|
serialize(obj, { write }) {
|
43
45
|
const keys = Object.keys(obj);
|
44
|
-
if (keys.length >
|
46
|
+
if (keys.length > 128) {
|
47
|
+
// Objects with so many keys are unlikely to share structure
|
48
|
+
// with other objects
|
49
|
+
write(keys);
|
50
|
+
for (const key of keys) {
|
51
|
+
write(obj[key]);
|
52
|
+
}
|
53
|
+
} else if (keys.length > 1) {
|
45
54
|
write(getCachedKeys(keys, write));
|
46
55
|
for (const key of keys) {
|
47
56
|
write(obj[key]);
|
@@ -15,7 +15,7 @@ class Serializer {
|
|
15
15
|
const ctx = { ...context, ...this.context };
|
16
16
|
let current = obj;
|
17
17
|
for (const middleware of this.serializeMiddlewares) {
|
18
|
-
if (current
|
18
|
+
if (current && typeof current.then === "function") {
|
19
19
|
current = current.then(
|
20
20
|
data => data && middleware.serialize(data, context)
|
21
21
|
);
|
@@ -35,7 +35,7 @@ class Serializer {
|
|
35
35
|
/** @type {any} */
|
36
36
|
let current = value;
|
37
37
|
for (const middleware of this.deserializeMiddlewares) {
|
38
|
-
if (current
|
38
|
+
if (current && typeof current.then === "function") {
|
39
39
|
current = current.then(data => middleware.deserialize(data, context));
|
40
40
|
} else {
|
41
41
|
current = middleware.deserialize(current, ctx);
|
@@ -100,9 +100,10 @@ class SerializerMiddleware {
|
|
100
100
|
static serializeLazy(lazy, serialize) {
|
101
101
|
const fn = memoize(() => {
|
102
102
|
const r = lazy();
|
103
|
-
if (r
|
104
|
-
|
105
|
-
|
103
|
+
if (r && typeof r.then === "function") {
|
104
|
+
return r.then(data => data && serialize(data));
|
105
|
+
}
|
106
|
+
return serialize(r);
|
106
107
|
});
|
107
108
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
108
109
|
/** @type {any} */ (fn).options = /** @type {any} */ (lazy).options;
|
@@ -118,7 +119,9 @@ class SerializerMiddleware {
|
|
118
119
|
static deserializeLazy(lazy, deserialize) {
|
119
120
|
const fn = memoize(() => {
|
120
121
|
const r = lazy();
|
121
|
-
if (r
|
122
|
+
if (r && typeof r.then === "function") {
|
123
|
+
return r.then(data => deserialize(data));
|
124
|
+
}
|
122
125
|
return deserialize(r);
|
123
126
|
});
|
124
127
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
@@ -126,6 +129,25 @@ class SerializerMiddleware {
|
|
126
129
|
fn[LAZY_SERIALIZED_VALUE] = lazy;
|
127
130
|
return fn;
|
128
131
|
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @param {function(): Promise<any> | any} lazy lazy function
|
135
|
+
* @returns {function(): Promise<any> | any} new lazy
|
136
|
+
*/
|
137
|
+
static unMemoizeLazy(lazy) {
|
138
|
+
if (!SerializerMiddleware.isLazy(lazy)) return lazy;
|
139
|
+
const fn = () => {
|
140
|
+
throw new Error(
|
141
|
+
"A lazy value that has been unmemorized can't be called again"
|
142
|
+
);
|
143
|
+
};
|
144
|
+
fn[LAZY_SERIALIZED_VALUE] = SerializerMiddleware.unMemoizeLazy(
|
145
|
+
lazy[LAZY_SERIALIZED_VALUE]
|
146
|
+
);
|
147
|
+
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
148
|
+
fn.options = /** @type {any} */ (lazy).options;
|
149
|
+
return fn;
|
150
|
+
}
|
129
151
|
}
|
130
152
|
|
131
153
|
module.exports = SerializerMiddleware;
|
package/lib/util/ArrayQueue.js
CHANGED
@@ -27,6 +27,14 @@ class ArrayQueue {
|
|
27
27
|
return this._list.length + this._listReversed.length;
|
28
28
|
}
|
29
29
|
|
30
|
+
/**
|
31
|
+
* Empties the queue.
|
32
|
+
*/
|
33
|
+
clear() {
|
34
|
+
this._list.length = 0;
|
35
|
+
this._listReversed.length = 0;
|
36
|
+
}
|
37
|
+
|
30
38
|
/**
|
31
39
|
* Appends the specified element to this queue.
|
32
40
|
* @param {T} item The element to add.
|
package/lib/util/AsyncQueue.js
CHANGED
@@ -359,6 +359,15 @@ class AsyncQueue {
|
|
359
359
|
inHandleResult--;
|
360
360
|
});
|
361
361
|
}
|
362
|
+
|
363
|
+
clear() {
|
364
|
+
this._entries.clear();
|
365
|
+
this._queued.clear();
|
366
|
+
this._activeTasks = 0;
|
367
|
+
this._willEnsureProcessing = false;
|
368
|
+
this._needProcessing = false;
|
369
|
+
this._stopped = false;
|
370
|
+
}
|
362
371
|
}
|
363
372
|
|
364
373
|
module.exports = AsyncQueue;
|
package/lib/util/LazySet.js
CHANGED
@@ -24,21 +24,17 @@ const merge = (targetSet, toMerge) => {
|
|
24
24
|
/**
|
25
25
|
* @template T
|
26
26
|
* @param {Set<Iterable<T>>} targetSet set where iterables should be added
|
27
|
-
* @param {Array<
|
27
|
+
* @param {Array<LazySet<T>>} toDeepMerge lazy sets to be flattened
|
28
28
|
* @returns {void}
|
29
29
|
*/
|
30
30
|
const flatten = (targetSet, toDeepMerge) => {
|
31
31
|
for (const set of toDeepMerge) {
|
32
|
-
if (set
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
targetSet.add(mergedSet);
|
37
|
-
}
|
38
|
-
flatten(targetSet, set._toDeepMerge);
|
32
|
+
if (set._set.size > 0) targetSet.add(set._set);
|
33
|
+
if (set._needMerge) {
|
34
|
+
for (const mergedSet of set._toMerge) {
|
35
|
+
targetSet.add(mergedSet);
|
39
36
|
}
|
40
|
-
|
41
|
-
targetSet.add(set);
|
37
|
+
flatten(targetSet, set._toDeepMerge);
|
42
38
|
}
|
43
39
|
}
|
44
40
|
};
|
@@ -58,7 +54,7 @@ class LazySet {
|
|
58
54
|
this._set = new Set(iterable);
|
59
55
|
/** @type {Set<Iterable<T>>} */
|
60
56
|
this._toMerge = new Set();
|
61
|
-
/** @type {Array<
|
57
|
+
/** @type {Array<LazySet<T>>} */
|
62
58
|
this._toDeepMerge = [];
|
63
59
|
this._needMerge = false;
|
64
60
|
this._deopt = false;
|
@@ -76,6 +72,14 @@ class LazySet {
|
|
76
72
|
this._needMerge = false;
|
77
73
|
}
|
78
74
|
|
75
|
+
_isEmpty() {
|
76
|
+
return (
|
77
|
+
this._set.size === 0 &&
|
78
|
+
this._toMerge.size === 0 &&
|
79
|
+
this._toDeepMerge.length === 0
|
80
|
+
);
|
81
|
+
}
|
82
|
+
|
79
83
|
get size() {
|
80
84
|
if (this._needMerge) this._merge();
|
81
85
|
return this._set.size;
|
@@ -101,13 +105,18 @@ class LazySet {
|
|
101
105
|
_set.add(item);
|
102
106
|
}
|
103
107
|
} else {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
this.
|
109
|
-
|
108
|
+
if (iterable instanceof LazySet) {
|
109
|
+
if (iterable._isEmpty()) return this;
|
110
|
+
this._toDeepMerge.push(iterable);
|
111
|
+
this._needMerge = true;
|
112
|
+
if (this._toDeepMerge.length > 100000) {
|
113
|
+
this._flatten();
|
114
|
+
}
|
115
|
+
} else {
|
116
|
+
this._toMerge.add(iterable);
|
117
|
+
this._needMerge = true;
|
110
118
|
}
|
119
|
+
if (this._toMerge.size > 100000) this._merge();
|
111
120
|
}
|
112
121
|
return this;
|
113
122
|
}
|
@@ -291,7 +291,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
291
291
|
"var promise;",
|
292
292
|
this.supportsStreaming
|
293
293
|
? Template.asString([
|
294
|
-
"if(importObject
|
294
|
+
"if(importObject && typeof importObject.then === 'function' && typeof WebAssembly.compileStreaming === 'function') {",
|
295
295
|
Template.indent([
|
296
296
|
"promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {",
|
297
297
|
Template.indent([
|
@@ -309,7 +309,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
309
309
|
])
|
310
310
|
])
|
311
311
|
: Template.asString([
|
312
|
-
"if(importObject
|
312
|
+
"if(importObject && typeof importObject.then === 'function') {",
|
313
313
|
Template.indent([
|
314
314
|
"var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });",
|
315
315
|
"promise = Promise.all([",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.40.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"browserslist": "^4.14.5",
|
15
15
|
"chrome-trace-event": "^1.0.2",
|
16
16
|
"enhanced-resolve": "^5.8.0",
|
17
|
-
"es-module-lexer": "^0.
|
17
|
+
"es-module-lexer": "^0.6.0",
|
18
18
|
"eslint-scope": "5.1.1",
|
19
19
|
"events": "^3.2.0",
|
20
20
|
"glob-to-regexp": "^0.4.1",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"neo-async": "^2.6.2",
|
26
26
|
"schema-utils": "^3.0.0",
|
27
27
|
"tapable": "^2.1.1",
|
28
|
-
"terser-webpack-plugin": "^5.1.
|
28
|
+
"terser-webpack-plugin": "^5.1.3",
|
29
29
|
"watchpack": "^2.2.0",
|
30
30
|
"webpack-sources": "^2.3.0"
|
31
31
|
},
|
@@ -91,7 +91,7 @@
|
|
91
91
|
"simple-git": "^2.17.0",
|
92
92
|
"strip-ansi": "^6.0.0",
|
93
93
|
"style-loader": "^2.0.0",
|
94
|
-
"terser": "^5.
|
94
|
+
"terser": "^5.7.0",
|
95
95
|
"toml": "^3.0.0",
|
96
96
|
"tooling": "webpack/tooling#v1.19.0",
|
97
97
|
"ts-loader": "^8.0.2",
|
package/types.d.ts
CHANGED
@@ -358,6 +358,7 @@ declare abstract class AsyncQueue<T, K, R> {
|
|
358
358
|
isProcessing(item: T): boolean;
|
359
359
|
isQueued(item: T): boolean;
|
360
360
|
isDone(item: T): boolean;
|
361
|
+
clear(): void;
|
361
362
|
}
|
362
363
|
declare class AsyncWebAssemblyModulesPlugin {
|
363
364
|
constructor(options?: any);
|
@@ -2375,6 +2376,7 @@ declare interface ContextModuleOptions {
|
|
2375
2376
|
include?: RegExp;
|
2376
2377
|
exclude?: RegExp;
|
2377
2378
|
groupOptions?: RawChunkGroupOptions;
|
2379
|
+
typePrefix?: string;
|
2378
2380
|
category?: string;
|
2379
2381
|
|
2380
2382
|
/**
|
@@ -5793,11 +5795,13 @@ type LoaderContext<OptionsType> = NormalModuleLoaderContext<OptionsType> &
|
|
5793
5795
|
LoaderRunnerLoaderContext<OptionsType> &
|
5794
5796
|
LoaderPluginLoaderContext &
|
5795
5797
|
HotModuleReplacementPluginLoaderContext;
|
5796
|
-
type LoaderDefinition<
|
5797
|
-
|
5798
|
-
|
5799
|
-
|
5800
|
-
|
5798
|
+
type LoaderDefinition<
|
5799
|
+
OptionsType = {},
|
5800
|
+
ContextAdditions = {}
|
5801
|
+
> = LoaderDefinitionFunction<OptionsType, ContextAdditions> & {
|
5802
|
+
raw?: false;
|
5803
|
+
pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>;
|
5804
|
+
};
|
5801
5805
|
declare interface LoaderDefinitionFunction<
|
5802
5806
|
OptionsType = {},
|
5803
5807
|
ContextAdditions = {}
|
@@ -7202,7 +7206,7 @@ declare interface NormalModuleLoaderContext<OptionsType> {
|
|
7202
7206
|
};
|
7203
7207
|
emitFile(
|
7204
7208
|
name: string,
|
7205
|
-
content: string,
|
7209
|
+
content: string | Buffer,
|
7206
7210
|
sourceMap?: string,
|
7207
7211
|
assetInfo?: AssetInfo
|
7208
7212
|
): void;
|
@@ -8660,11 +8664,13 @@ declare interface RawChunkGroupOptions {
|
|
8660
8664
|
preloadOrder?: number;
|
8661
8665
|
prefetchOrder?: number;
|
8662
8666
|
}
|
8663
|
-
type RawLoaderDefinition<
|
8664
|
-
|
8665
|
-
|
8666
|
-
|
8667
|
-
|
8667
|
+
type RawLoaderDefinition<
|
8668
|
+
OptionsType = {},
|
8669
|
+
ContextAdditions = {}
|
8670
|
+
> = RawLoaderDefinitionFunction<OptionsType, ContextAdditions> & {
|
8671
|
+
raw: true;
|
8672
|
+
pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>;
|
8673
|
+
};
|
8668
8674
|
declare interface RawLoaderDefinitionFunction<
|
8669
8675
|
OptionsType = {},
|
8670
8676
|
ContextAdditions = {}
|