webpack 5.61.0 → 5.63.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/lib/Chunk.js +3 -2
- package/lib/Compilation.js +36 -20
- package/lib/Compiler.js +13 -11
- package/lib/FileSystemInfo.js +7 -6
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/RuntimePlugin.js +9 -1
- package/lib/buildChunkGraph.js +25 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/config/defaults.js +18 -10
- package/lib/config/normalization.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +17 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -14
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/hmr/lazyCompilationBackend.js +6 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/deprecation.js +10 -2
- package/lib/util/hash/BatchedHash.js +5 -1
- package/lib/util/hash/wasm-hash.js +1 -1
- package/lib/webpack.js +1 -2
- package/module.d.ts +200 -0
- package/package.json +12 -10
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +45 -21
- package/types.d.ts +33 -13
package/lib/Chunk.js
CHANGED
@@ -63,8 +63,9 @@ let debugId = 1000;
|
|
63
63
|
class Chunk {
|
64
64
|
/**
|
65
65
|
* @param {string=} name of chunk being created, is optional (for subclasses)
|
66
|
+
* @param {boolean} backCompat enable backward-compatibility
|
66
67
|
*/
|
67
|
-
constructor(name) {
|
68
|
+
constructor(name, backCompat = true) {
|
68
69
|
/** @type {number | string | null} */
|
69
70
|
this.id = null;
|
70
71
|
/** @type {(number|string)[] | null} */
|
@@ -84,7 +85,7 @@ class Chunk {
|
|
84
85
|
/** @type {RuntimeSpec} */
|
85
86
|
this.runtime = undefined;
|
86
87
|
/** @type {Set<string>} */
|
87
|
-
this.files = new ChunkFilesSet();
|
88
|
+
this.files = backCompat ? new ChunkFilesSet() : new Set();
|
88
89
|
/** @type {Set<string>} */
|
89
90
|
this.auxiliaryFiles = new Set();
|
90
91
|
/** @type {boolean} */
|
package/lib/Compilation.js
CHANGED
@@ -429,6 +429,8 @@ class Compilation {
|
|
429
429
|
* @param {CompilationParams} params the compilation parameters
|
430
430
|
*/
|
431
431
|
constructor(compiler, params) {
|
432
|
+
this._backCompat = compiler._backCompat;
|
433
|
+
|
432
434
|
const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
|
433
435
|
/** @typedef {{ additionalAssets?: true | Function }} ProcessAssetsAdditionalOptions */
|
434
436
|
/** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
|
@@ -559,6 +561,7 @@ class Compilation {
|
|
559
561
|
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
|
560
562
|
*/
|
561
563
|
const createProcessAssetsHook = (name, stage, getArgs, code) => {
|
564
|
+
if (!this._backCompat && code) return undefined;
|
562
565
|
const errorMessage =
|
563
566
|
reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
564
567
|
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
@@ -983,7 +986,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
983
986
|
this.asyncEntrypoints = [];
|
984
987
|
/** @type {Set<Chunk>} */
|
985
988
|
this.chunks = new Set();
|
986
|
-
arrayToSetDeprecation(this.chunks, "Compilation.chunks");
|
987
989
|
/** @type {ChunkGroup[]} */
|
988
990
|
this.chunkGroups = [];
|
989
991
|
/** @type {Map<string, ChunkGroup>} */
|
@@ -992,7 +994,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
992
994
|
this.namedChunks = new Map();
|
993
995
|
/** @type {Set<Module>} */
|
994
996
|
this.modules = new Set();
|
995
|
-
|
997
|
+
if (this._backCompat) {
|
998
|
+
arrayToSetDeprecation(this.chunks, "Compilation.chunks");
|
999
|
+
arrayToSetDeprecation(this.modules, "Compilation.modules");
|
1000
|
+
}
|
996
1001
|
/** @private @type {Map<string, Module>} */
|
997
1002
|
this._modules = new Map();
|
998
1003
|
this.records = null;
|
@@ -1286,7 +1291,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1286
1291
|
}
|
1287
1292
|
this._modules.set(identifier, module);
|
1288
1293
|
this.modules.add(module);
|
1289
|
-
|
1294
|
+
if (this._backCompat)
|
1295
|
+
ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
|
1290
1296
|
if (currentProfile !== undefined) {
|
1291
1297
|
currentProfile.markIntegrationEnd();
|
1292
1298
|
}
|
@@ -1701,7 +1707,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1701
1707
|
|
1702
1708
|
this._modules.set(module.identifier(), module);
|
1703
1709
|
this.modules.add(module);
|
1704
|
-
|
1710
|
+
if (this._backCompat)
|
1711
|
+
ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
|
1705
1712
|
|
1706
1713
|
this._handleModuleBuildAndDependencies(
|
1707
1714
|
originModule,
|
@@ -2417,9 +2424,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2417
2424
|
let statNew = 0;
|
2418
2425
|
/**
|
2419
2426
|
* @param {Module} module module
|
2420
|
-
* @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
|
2427
|
+
* @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
|
2421
2428
|
*/
|
2422
2429
|
const computeReferences = module => {
|
2430
|
+
const id = chunkGraph.getModuleId(module);
|
2423
2431
|
/** @type {Map<Module, string | number | undefined>} */
|
2424
2432
|
let modules = undefined;
|
2425
2433
|
/** @type {(string | number)[] | undefined} */
|
@@ -2447,16 +2455,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2447
2455
|
queue.push.apply(queue, block.blocks);
|
2448
2456
|
}
|
2449
2457
|
}
|
2450
|
-
return { modules, blocks };
|
2458
|
+
return { id, modules, blocks };
|
2451
2459
|
};
|
2452
2460
|
/**
|
2453
2461
|
* @param {Module} module module
|
2454
2462
|
* @param {Object} references references
|
2463
|
+
* @param {string | number} references.id id
|
2455
2464
|
* @param {Map<Module, string | number>=} references.modules modules
|
2456
2465
|
* @param {(string | number)[]=} references.blocks blocks
|
2457
2466
|
* @returns {boolean} ok?
|
2458
2467
|
*/
|
2459
|
-
const compareReferences = (module, { modules, blocks }) => {
|
2468
|
+
const compareReferences = (module, { id, modules, blocks }) => {
|
2469
|
+
if (id !== chunkGraph.getModuleId(module)) return false;
|
2460
2470
|
if (modules !== undefined) {
|
2461
2471
|
for (const [module, id] of modules) {
|
2462
2472
|
if (chunkGraph.getModuleId(module) !== id) return false;
|
@@ -2482,7 +2492,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2482
2492
|
};
|
2483
2493
|
|
2484
2494
|
for (const [module, memCache] of moduleMemCaches) {
|
2485
|
-
/** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
|
2495
|
+
/** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
|
2486
2496
|
const cache = memCache.get(key);
|
2487
2497
|
if (cache === undefined) {
|
2488
2498
|
const memCache2 = new WeakTupleMap();
|
@@ -2777,8 +2787,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2777
2787
|
);
|
2778
2788
|
this.chunkGraph = chunkGraph;
|
2779
2789
|
|
2780
|
-
|
2781
|
-
|
2790
|
+
if (this._backCompat) {
|
2791
|
+
for (const module of this.modules) {
|
2792
|
+
ChunkGraph.setChunkGraphForModule(module, chunkGraph);
|
2793
|
+
}
|
2782
2794
|
}
|
2783
2795
|
|
2784
2796
|
this.hooks.seal.call();
|
@@ -3045,14 +3057,16 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3045
3057
|
}
|
3046
3058
|
this.hooks.afterProcessAssets.call(this.assets);
|
3047
3059
|
this.logger.timeEnd("process assets");
|
3048
|
-
this.assets =
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3060
|
+
this.assets = this._backCompat
|
3061
|
+
? soonFrozenObjectDeprecation(
|
3062
|
+
this.assets,
|
3063
|
+
"Compilation.assets",
|
3064
|
+
"DEP_WEBPACK_COMPILATION_ASSETS",
|
3065
|
+
`BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
|
3053
3066
|
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
|
3054
3067
|
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
|
3055
|
-
|
3068
|
+
)
|
3069
|
+
: Object.freeze(this.assets);
|
3056
3070
|
|
3057
3071
|
this.summarizeDependencies();
|
3058
3072
|
if (shouldRecord) {
|
@@ -3453,7 +3467,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3453
3467
|
*/
|
3454
3468
|
addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
|
3455
3469
|
// Deprecated ModuleGraph association
|
3456
|
-
|
3470
|
+
if (this._backCompat)
|
3471
|
+
ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
|
3457
3472
|
|
3458
3473
|
// add it to the list
|
3459
3474
|
this.modules.add(module);
|
@@ -3589,9 +3604,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3589
3604
|
return chunk;
|
3590
3605
|
}
|
3591
3606
|
}
|
3592
|
-
const chunk = new Chunk(name);
|
3607
|
+
const chunk = new Chunk(name, this._backCompat);
|
3593
3608
|
this.chunks.add(chunk);
|
3594
|
-
|
3609
|
+
if (this._backCompat)
|
3610
|
+
ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
|
3595
3611
|
if (name) {
|
3596
3612
|
this.namedChunks.set(name, chunk);
|
3597
3613
|
}
|
@@ -4715,7 +4731,7 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4715
4731
|
this.outputOptions;
|
4716
4732
|
const runtimeTemplate = this.runtimeTemplate;
|
4717
4733
|
|
4718
|
-
const chunk = new Chunk("build time chunk");
|
4734
|
+
const chunk = new Chunk("build time chunk", this._backCompat);
|
4719
4735
|
chunk.id = chunk.name;
|
4720
4736
|
chunk.ids = [chunk.id];
|
4721
4737
|
chunk.runtime = runtime;
|
package/lib/Compiler.js
CHANGED
@@ -119,8 +119,9 @@ const includesHash = (filename, hashes) => {
|
|
119
119
|
class Compiler {
|
120
120
|
/**
|
121
121
|
* @param {string} context the compilation path
|
122
|
+
* @param {WebpackOptions} options options
|
122
123
|
*/
|
123
|
-
constructor(context) {
|
124
|
+
constructor(context, options = /** @type {WebpackOptions} */ ({})) {
|
124
125
|
this.hooks = Object.freeze({
|
125
126
|
/** @type {SyncHook<[]>} */
|
126
127
|
initialize: new SyncHook([]),
|
@@ -240,8 +241,7 @@ class Compiler {
|
|
240
241
|
|
241
242
|
this.infrastructureLogger = undefined;
|
242
243
|
|
243
|
-
|
244
|
-
this.options = /** @type {WebpackOptions} */ ({});
|
244
|
+
this.options = options;
|
245
245
|
|
246
246
|
this.context = context;
|
247
247
|
|
@@ -263,6 +263,8 @@ class Compiler {
|
|
263
263
|
/** @type {boolean} */
|
264
264
|
this.watchMode = false;
|
265
265
|
|
266
|
+
this._backCompat = this.options.experiments.backCompat !== false;
|
267
|
+
|
266
268
|
/** @type {Compilation} */
|
267
269
|
this._lastCompilation = undefined;
|
268
270
|
/** @type {NormalModuleFactory} */
|
@@ -963,7 +965,13 @@ ${other}`);
|
|
963
965
|
outputOptions,
|
964
966
|
plugins
|
965
967
|
) {
|
966
|
-
const childCompiler = new Compiler(this.context
|
968
|
+
const childCompiler = new Compiler(this.context, {
|
969
|
+
...this.options,
|
970
|
+
output: {
|
971
|
+
...this.options.output,
|
972
|
+
...outputOptions
|
973
|
+
}
|
974
|
+
});
|
967
975
|
childCompiler.name = compilerName;
|
968
976
|
childCompiler.outputPath = this.outputPath;
|
969
977
|
childCompiler.inputFileSystem = this.inputFileSystem;
|
@@ -976,6 +984,7 @@ ${other}`);
|
|
976
984
|
childCompiler.fsStartTime = this.fsStartTime;
|
977
985
|
childCompiler.cache = this.cache;
|
978
986
|
childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;
|
987
|
+
childCompiler._backCompat = this._backCompat;
|
979
988
|
|
980
989
|
const relativeCompilerName = makePathsRelative(
|
981
990
|
this.context,
|
@@ -991,13 +1000,6 @@ ${other}`);
|
|
991
1000
|
this.records[relativeCompilerName].push((childCompiler.records = {}));
|
992
1001
|
}
|
993
1002
|
|
994
|
-
childCompiler.options = {
|
995
|
-
...this.options,
|
996
|
-
output: {
|
997
|
-
...this.options.output,
|
998
|
-
...outputOptions
|
999
|
-
}
|
1000
|
-
};
|
1001
1003
|
childCompiler.parentCompilation = compilation;
|
1002
1004
|
childCompiler.root = this.root;
|
1003
1005
|
if (Array.isArray(plugins)) {
|
package/lib/FileSystemInfo.js
CHANGED
@@ -692,6 +692,11 @@ class SnapshotOptimization {
|
|
692
692
|
}
|
693
693
|
}
|
694
694
|
|
695
|
+
const parseString = str => {
|
696
|
+
if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
|
697
|
+
return JSON.parse(str);
|
698
|
+
};
|
699
|
+
|
695
700
|
/* istanbul ignore next */
|
696
701
|
/**
|
697
702
|
* @param {number} mtime mtime
|
@@ -1657,17 +1662,13 @@ class FileSystemInfo {
|
|
1657
1662
|
let dependency;
|
1658
1663
|
if (imp.d === -1) {
|
1659
1664
|
// import ... from "..."
|
1660
|
-
dependency =
|
1665
|
+
dependency = parseString(
|
1661
1666
|
source.substring(imp.s - 1, imp.e + 1)
|
1662
1667
|
);
|
1663
1668
|
} else if (imp.d > -1) {
|
1664
1669
|
// import()
|
1665
1670
|
let expr = source.substring(imp.s, imp.e).trim();
|
1666
|
-
|
1667
|
-
expr = `"${expr
|
1668
|
-
.slice(1, -1)
|
1669
|
-
.replace(/"/g, '\\"')}"`;
|
1670
|
-
dependency = JSON.parse(expr);
|
1671
|
+
dependency = parseString(expr);
|
1671
1672
|
} else {
|
1672
1673
|
// e.g. import.meta
|
1673
1674
|
continue;
|
@@ -83,6 +83,7 @@ class HotModuleReplacementPlugin {
|
|
83
83
|
* @returns {void}
|
84
84
|
*/
|
85
85
|
apply(compiler) {
|
86
|
+
const { _backCompat: backCompat } = compiler;
|
86
87
|
if (compiler.options.output.strictModuleErrorHandling === undefined)
|
87
88
|
compiler.options.output.strictModuleErrorHandling = true;
|
88
89
|
const runtimeRequirements = [RuntimeGlobals.module];
|
@@ -597,7 +598,8 @@ class HotModuleReplacementPlugin {
|
|
597
598
|
(newRuntimeModules && newRuntimeModules.length > 0)
|
598
599
|
) {
|
599
600
|
const hotUpdateChunk = new HotUpdateChunk();
|
600
|
-
|
601
|
+
if (backCompat)
|
602
|
+
ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
|
601
603
|
hotUpdateChunk.id = chunkId;
|
602
604
|
hotUpdateChunk.runtime = newRuntime;
|
603
605
|
if (currentChunk) {
|
package/lib/RuntimePlugin.js
CHANGED
@@ -218,7 +218,15 @@ class RuntimePlugin {
|
|
218
218
|
compilation.hooks.runtimeRequirementInTree
|
219
219
|
.for(RuntimeGlobals.systemContext)
|
220
220
|
.tap("RuntimePlugin", chunk => {
|
221
|
-
|
221
|
+
const { outputOptions } = compilation;
|
222
|
+
const { library: globalLibrary } = outputOptions;
|
223
|
+
const entryOptions = chunk.getEntryOptions();
|
224
|
+
const libraryType =
|
225
|
+
entryOptions && entryOptions.library !== undefined
|
226
|
+
? entryOptions.library.type
|
227
|
+
: globalLibrary.type;
|
228
|
+
|
229
|
+
if (libraryType === "system") {
|
222
230
|
compilation.addRuntimeModule(
|
223
231
|
chunk,
|
224
232
|
new SystemContextRuntimeModule()
|
package/lib/buildChunkGraph.js
CHANGED
@@ -50,6 +50,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
50
50
|
* @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
|
51
51
|
* @property {number} preOrderIndex next pre order index
|
52
52
|
* @property {number} postOrderIndex next post order index
|
53
|
+
* @property {boolean} asyncChunkLoading create async chunks
|
53
54
|
*/
|
54
55
|
|
55
56
|
/**
|
@@ -304,7 +305,11 @@ const visitModules = (
|
|
304
305
|
availableSources: undefined,
|
305
306
|
availableChildren: undefined,
|
306
307
|
preOrderIndex: 0,
|
307
|
-
postOrderIndex: 0
|
308
|
+
postOrderIndex: 0,
|
309
|
+
asyncChunkLoading:
|
310
|
+
chunkGroup.options.chunkLoading === false
|
311
|
+
? false
|
312
|
+
: compilation.outputOptions.chunkLoading !== false
|
308
313
|
};
|
309
314
|
chunkGroup.index = nextChunkGroupIndex++;
|
310
315
|
if (chunkGroup.getNumberOfParents() > 0) {
|
@@ -418,7 +423,11 @@ const visitModules = (
|
|
418
423
|
availableSources: undefined,
|
419
424
|
availableChildren: undefined,
|
420
425
|
preOrderIndex: 0,
|
421
|
-
postOrderIndex: 0
|
426
|
+
postOrderIndex: 0,
|
427
|
+
asyncChunkLoading:
|
428
|
+
entryOptions.chunkLoading !== undefined
|
429
|
+
? entryOptions.chunkLoading !== false
|
430
|
+
: chunkGroupInfo.asyncChunkLoading
|
422
431
|
};
|
423
432
|
chunkGroupInfoMap.set(entrypoint, cgi);
|
424
433
|
|
@@ -442,8 +451,18 @@ const visitModules = (
|
|
442
451
|
chunkGroup: entrypoint,
|
443
452
|
chunkGroupInfo: cgi
|
444
453
|
});
|
454
|
+
} else if (!chunkGroupInfo.asyncChunkLoading) {
|
455
|
+
// Just queue the block into the current chunk group
|
456
|
+
queue.push({
|
457
|
+
action: PROCESS_BLOCK,
|
458
|
+
block: b,
|
459
|
+
module: module,
|
460
|
+
chunk,
|
461
|
+
chunkGroup,
|
462
|
+
chunkGroupInfo
|
463
|
+
});
|
445
464
|
} else {
|
446
|
-
cgi = namedChunkGroups.get(chunkName);
|
465
|
+
cgi = chunkName && namedChunkGroups.get(chunkName);
|
447
466
|
if (!cgi) {
|
448
467
|
c = compilation.addChunkInGroup(
|
449
468
|
b.groupOptions || b.chunkName,
|
@@ -464,7 +483,8 @@ const visitModules = (
|
|
464
483
|
availableSources: undefined,
|
465
484
|
availableChildren: undefined,
|
466
485
|
preOrderIndex: 0,
|
467
|
-
postOrderIndex: 0
|
486
|
+
postOrderIndex: 0,
|
487
|
+
asyncChunkLoading: chunkGroupInfo.asyncChunkLoading
|
468
488
|
};
|
469
489
|
allCreatedChunkGroups.add(c);
|
470
490
|
chunkGroupInfoMap.set(c, cgi);
|
@@ -518,7 +538,7 @@ const visitModules = (
|
|
518
538
|
chunkGroup: c,
|
519
539
|
chunkGroupInfo: cgi
|
520
540
|
});
|
521
|
-
} else {
|
541
|
+
} else if (entrypoint !== undefined) {
|
522
542
|
chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
|
523
543
|
}
|
524
544
|
};
|
@@ -782,7 +782,7 @@ class PackContent {
|
|
782
782
|
this.logger.time(timeMessage);
|
783
783
|
}
|
784
784
|
const value = this.lazy();
|
785
|
-
if (
|
785
|
+
if ("then" in value) {
|
786
786
|
return value.then(data => {
|
787
787
|
const map = data.map;
|
788
788
|
if (timeMessage) {
|
@@ -830,7 +830,7 @@ class PackContent {
|
|
830
830
|
this.logger.time(timeMessage);
|
831
831
|
}
|
832
832
|
const value = this.lazy();
|
833
|
-
if (
|
833
|
+
if ("then" in value) {
|
834
834
|
return value.then(data => {
|
835
835
|
if (timeMessage) {
|
836
836
|
this.logger.timeEnd(timeMessage);
|
@@ -918,7 +918,7 @@ class PackContent {
|
|
918
918
|
}
|
919
919
|
const value = this.lazy();
|
920
920
|
this.outdated = false;
|
921
|
-
if (
|
921
|
+
if ("then" in value) {
|
922
922
|
// Move to state B1
|
923
923
|
this.lazy = write(() =>
|
924
924
|
value.then(data => {
|
package/lib/config/defaults.js
CHANGED
@@ -183,7 +183,8 @@ const applyWebpackOptionsDefaults = options => {
|
|
183
183
|
applyModuleDefaults(options.module, {
|
184
184
|
cache,
|
185
185
|
syncWebAssembly: options.experiments.syncWebAssembly,
|
186
|
-
asyncWebAssembly: options.experiments.asyncWebAssembly
|
186
|
+
asyncWebAssembly: options.experiments.asyncWebAssembly,
|
187
|
+
futureDefaults
|
187
188
|
});
|
188
189
|
|
189
190
|
applyOutputDefaults(options.output, {
|
@@ -265,15 +266,15 @@ const applyWebpackOptionsDefaults = options => {
|
|
265
266
|
* @returns {void}
|
266
267
|
*/
|
267
268
|
const applyExperimentsDefaults = (experiments, { production, development }) => {
|
268
|
-
D(experiments, "
|
269
|
+
D(experiments, "futureDefaults", false);
|
270
|
+
D(experiments, "backCompat", !experiments.futureDefaults);
|
271
|
+
D(experiments, "topLevelAwait", experiments.futureDefaults);
|
269
272
|
D(experiments, "syncWebAssembly", false);
|
270
|
-
D(experiments, "asyncWebAssembly",
|
273
|
+
D(experiments, "asyncWebAssembly", experiments.futureDefaults);
|
271
274
|
D(experiments, "outputModule", false);
|
272
|
-
D(experiments, "asset", false);
|
273
275
|
D(experiments, "layers", false);
|
274
276
|
D(experiments, "lazyCompilation", undefined);
|
275
277
|
D(experiments, "buildHttp", undefined);
|
276
|
-
D(experiments, "futureDefaults", false);
|
277
278
|
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
278
279
|
|
279
280
|
if (typeof experiments.buildHttp === "object") {
|
@@ -428,9 +429,14 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
428
429
|
|
429
430
|
/**
|
430
431
|
* @param {JavascriptParserOptions} parserOptions parser options
|
432
|
+
* @param {Object} options options
|
433
|
+
* @param {boolean} options.futureDefaults is future defaults enabled
|
431
434
|
* @returns {void}
|
432
435
|
*/
|
433
|
-
const applyJavascriptParserOptionsDefaults =
|
436
|
+
const applyJavascriptParserOptionsDefaults = (
|
437
|
+
parserOptions,
|
438
|
+
{ futureDefaults }
|
439
|
+
) => {
|
434
440
|
D(parserOptions, "unknownContextRequest", ".");
|
435
441
|
D(parserOptions, "unknownContextRegExp", false);
|
436
442
|
D(parserOptions, "unknownContextRecursive", true);
|
@@ -442,9 +448,8 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
|
|
442
448
|
D(parserOptions, "wrappedContextRegExp", /.*/);
|
443
449
|
D(parserOptions, "wrappedContextRecursive", true);
|
444
450
|
D(parserOptions, "wrappedContextCritical", false);
|
445
|
-
|
446
|
-
D(parserOptions, "strictExportPresence", false);
|
447
451
|
D(parserOptions, "strictThisContextOnImports", false);
|
452
|
+
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
448
453
|
};
|
449
454
|
|
450
455
|
/**
|
@@ -453,11 +458,12 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
|
|
453
458
|
* @param {boolean} options.cache is caching enabled
|
454
459
|
* @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
|
455
460
|
* @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
|
461
|
+
* @param {boolean} options.futureDefaults is future defaults enabled
|
456
462
|
* @returns {void}
|
457
463
|
*/
|
458
464
|
const applyModuleDefaults = (
|
459
465
|
module,
|
460
|
-
{ cache, syncWebAssembly, asyncWebAssembly }
|
466
|
+
{ cache, syncWebAssembly, asyncWebAssembly, futureDefaults }
|
461
467
|
) => {
|
462
468
|
if (cache) {
|
463
469
|
D(module, "unsafeCache", module => {
|
@@ -475,7 +481,9 @@ const applyModuleDefaults = (
|
|
475
481
|
}
|
476
482
|
|
477
483
|
F(module.parser, "javascript", () => ({}));
|
478
|
-
applyJavascriptParserOptionsDefaults(module.parser.javascript
|
484
|
+
applyJavascriptParserOptionsDefaults(module.parser.javascript, {
|
485
|
+
futureDefaults
|
486
|
+
});
|
479
487
|
|
480
488
|
A(module, "defaultRules", () => {
|
481
489
|
const esm = {
|
@@ -229,6 +229,7 @@ const getNormalizedWebpackOptions = config => {
|
|
229
229
|
wrappedContextRegExp: module.wrappedContextRegExp,
|
230
230
|
wrappedContextRecursive: module.wrappedContextRecursive,
|
231
231
|
wrappedContextCritical: module.wrappedContextCritical,
|
232
|
+
// TODO webpack 6 remove
|
232
233
|
strictExportPresence: module.strictExportPresence,
|
233
234
|
strictThisContextOnImports: module.strictThisContextOnImports,
|
234
235
|
...parserOptions
|
@@ -90,7 +90,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
90
90
|
// has array range but no function range
|
91
91
|
if (dep.arrayRange && !dep.functionRange) {
|
92
92
|
const startBlock = `${promise}.then(function() {`;
|
93
|
-
const endBlock = `;})
|
93
|
+
const endBlock = `;})['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
94
94
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
95
95
|
|
96
96
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -103,7 +103,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
103
103
|
// has function range but no array range
|
104
104
|
if (dep.functionRange && !dep.arrayRange) {
|
105
105
|
const startBlock = `${promise}.then((`;
|
106
|
-
const endBlock = `).bind(exports, __webpack_require__, exports, module))
|
106
|
+
const endBlock = `).bind(exports, __webpack_require__, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
107
107
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
108
108
|
|
109
109
|
source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
|
@@ -118,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
118
118
|
const startBlock = `${promise}.then(function() { `;
|
119
119
|
const errorRangeBlock = `}${
|
120
120
|
dep.functionBindThis ? ".bind(this)" : ""
|
121
|
-
})
|
121
|
+
})['catch'](`;
|
122
122
|
const endBlock = `${dep.errorCallbackBindThis ? ".bind(this)" : ""})`;
|
123
123
|
|
124
124
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -150,9 +150,9 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
150
150
|
// has array range, function range, but no errorCallbackRange
|
151
151
|
if (dep.arrayRange && dep.functionRange) {
|
152
152
|
const startBlock = `${promise}.then(function() { `;
|
153
|
-
const endBlock = `}${
|
154
|
-
|
155
|
-
})`;
|
153
|
+
const endBlock = `}${
|
154
|
+
dep.functionBindThis ? ".bind(this)" : ""
|
155
|
+
})['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
156
156
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
157
157
|
|
158
158
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -117,7 +117,11 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
117
117
|
const comment = equals(usedImported, ids)
|
118
118
|
? ""
|
119
119
|
: Template.toNormalComment(propertyAccess(ids)) + " ";
|
120
|
-
|
120
|
+
const access = `${comment}${propertyAccess(usedImported)}`;
|
121
|
+
requireExpr =
|
122
|
+
dep.asiSafe === true
|
123
|
+
? `(${requireExpr}${access})`
|
124
|
+
: `${requireExpr}${access}`;
|
121
125
|
}
|
122
126
|
}
|
123
127
|
source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
|
@@ -10,11 +10,13 @@ const ContextDependency = require("./ContextDependency");
|
|
10
10
|
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
11
11
|
|
12
12
|
class CommonJsRequireContextDependency extends ContextDependency {
|
13
|
-
constructor(options, range, valueRange) {
|
13
|
+
constructor(options, range, valueRange, inShorthand) {
|
14
14
|
super(options);
|
15
15
|
|
16
16
|
this.range = range;
|
17
17
|
this.valueRange = valueRange;
|
18
|
+
// inShorthand must be serialized by subclasses that use it
|
19
|
+
this.inShorthand = inShorthand;
|
18
20
|
}
|
19
21
|
|
20
22
|
get type() {
|
@@ -26,6 +28,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|
26
28
|
|
27
29
|
write(this.range);
|
28
30
|
write(this.valueRange);
|
31
|
+
write(this.inShorthand);
|
29
32
|
|
30
33
|
super.serialize(context);
|
31
34
|
}
|
@@ -35,6 +38,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|
35
38
|
|
36
39
|
this.range = read();
|
37
40
|
this.valueRange = read();
|
41
|
+
this.inShorthand = read();
|
38
42
|
|
39
43
|
super.deserialize(context);
|
40
44
|
}
|
@@ -24,13 +24,16 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template
|
|
24
24
|
{ runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
|
25
25
|
) {
|
26
26
|
const dep = /** @type {ContextDependency} */ (dependency);
|
27
|
-
|
27
|
+
let moduleExports = runtimeTemplate.moduleExports({
|
28
28
|
module: moduleGraph.getModule(dep),
|
29
29
|
chunkGraph,
|
30
30
|
request: dep.request,
|
31
31
|
runtimeRequirements
|
32
32
|
});
|
33
33
|
|
34
|
+
if (dep.inShorthand) {
|
35
|
+
moduleExports = `${dep.inShorthand}: ${moduleExports}`;
|
36
|
+
}
|
34
37
|
if (moduleGraph.getModule(dep)) {
|
35
38
|
if (dep.valueRange) {
|
36
39
|
if (Array.isArray(dep.replaces)) {
|