webpack 5.110.2 → 5.111.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.
- package/README.md +5 -2
- package/lib/APIPlugin.js +23 -7
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/Compilation.js +321 -303
- package/lib/Compiler.js +209 -46
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ContextModule.js +17 -81
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DotenvPlugin.js +41 -13
- package/lib/ExternalModule.js +41 -14
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +45 -21
- package/lib/FlagDependencyUsagePlugin.js +8 -2
- package/lib/HotModuleReplacementPlugin.js +53 -7
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +16 -7
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +58 -32
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +794 -477
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetGenerator.js +25 -8
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/config/browserslistTargetHandler.js +19 -0
- package/lib/config/defaults.js +110 -64
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/css/CssGenerator.js +8 -0
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +94 -36
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +7 -6
- package/lib/css/CssParser.js +144 -11
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +11 -3
- package/lib/css/data.js +2814 -678
- package/lib/css/syntax.js +4082 -248
- package/lib/debug/ProfilingPlugin.js +4 -0
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/CssIcssExportDependency.js +7 -1
- package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
- package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +171 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +62 -2
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +59 -15
- package/lib/dependencies/ImportParserPlugin.js +24 -14
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/WorkerDependency.js +1 -2
- package/lib/dependencies/WorkletDependency.js +1 -2
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/html/HtmlGenerator.js +11 -5
- package/lib/html/HtmlModulesPlugin.js +360 -84
- package/lib/html/HtmlParser.js +13 -6
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +121 -7
- package/lib/html/htmlMinify.js +84 -113
- package/lib/html/syntax.js +1067 -569
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +3 -0
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +52 -22
- package/lib/javascript/JavascriptParser.js +1255 -728
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1494 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +8696 -5225
- package/lib/library/ModuleLibraryPlugin.js +116 -5
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/ConcatenatedModule.js +133 -25
- package/lib/optimize/ConstExportsPlugin.js +50 -39
- package/lib/optimize/InlineExports.js +20 -123
- package/lib/optimize/MangleExportsPlugin.js +10 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
- package/lib/optimize/RealContentHashPlugin.js +68 -9
- package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/CacheEffectivenessPlugin.js +4 -3
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +7 -3
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +105 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +9 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +338 -217
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/serialization/FileMiddleware.js +15 -2
- package/lib/serialization/ObjectMiddleware.js +138 -106
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/SourceProcessor.js +76 -69
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/conventions.js +5 -1
- package/lib/util/fs.js +27 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +22 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1440 -331
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -107,21 +107,6 @@ Technically any value can be used.
|
|
|
107
107
|
* @property {(context: ObjectDeserializerContext<EXPECTED_ANY>) => EXPECTED_ANY} deserialize
|
|
108
108
|
*/
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
* Updates set size using the provided set.
|
|
112
|
-
* @template T
|
|
113
|
-
* @param {Set<T>} set set
|
|
114
|
-
* @param {number} size count of items to keep
|
|
115
|
-
*/
|
|
116
|
-
const setSetSize = (set, size) => {
|
|
117
|
-
let i = 0;
|
|
118
|
-
for (const item of set) {
|
|
119
|
-
if (i++ >= size) {
|
|
120
|
-
set.delete(item);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
110
|
/**
|
|
126
111
|
* Updates map size using the provided map.
|
|
127
112
|
* @template K, X
|
|
@@ -149,6 +134,9 @@ const toHash = (buffer, hashFunction) => {
|
|
|
149
134
|
return hash.digest("latin1");
|
|
150
135
|
};
|
|
151
136
|
|
|
137
|
+
/** Marks an object whose children are still being written; never a real position. */
|
|
138
|
+
const IN_PROGRESS = -1;
|
|
139
|
+
|
|
152
140
|
const ESCAPE = null;
|
|
153
141
|
const ESCAPE_ESCAPE_VALUE = null;
|
|
154
142
|
const ESCAPE_END_OBJECT = true;
|
|
@@ -463,16 +451,22 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
463
451
|
let currentPosTypeLookup = 0;
|
|
464
452
|
/** @type {Map<SerializerConfigWithSerializer, number>} */
|
|
465
453
|
let objectTypeLookup = new Map();
|
|
466
|
-
/**
|
|
467
|
-
|
|
454
|
+
/**
|
|
455
|
+
* One-entry cache in front of `objectTypeLookup`, since runs of one class are common.
|
|
456
|
+
* @type {SerializerConfigWithSerializer | undefined}
|
|
457
|
+
*/
|
|
458
|
+
let lastConfig;
|
|
459
|
+
/** @type {number} */
|
|
460
|
+
let lastConfigIndex = 0;
|
|
461
|
+
/** @type {ComplexSerializableType[]} */
|
|
462
|
+
const cycleStack = [];
|
|
468
463
|
/**
|
|
469
464
|
* Returns stack.
|
|
470
465
|
* @param {ComplexSerializableType} item item to stack
|
|
471
466
|
* @returns {string} stack
|
|
472
467
|
*/
|
|
473
468
|
const stackToString = (item) => {
|
|
474
|
-
const arr = [...cycleStack];
|
|
475
|
-
arr.push(item);
|
|
469
|
+
const arr = [...cycleStack, item];
|
|
476
470
|
return arr
|
|
477
471
|
.map((item) => {
|
|
478
472
|
if (typeof item === "string") {
|
|
@@ -528,63 +522,35 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
528
522
|
};
|
|
529
523
|
/** @type {undefined | WeakSet<Error>} */
|
|
530
524
|
let hasDebugInfoAttached;
|
|
531
|
-
/**
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
throw err;
|
|
549
|
-
}
|
|
550
|
-
return ctx;
|
|
551
|
-
},
|
|
552
|
-
setCircularReference(ref) {
|
|
553
|
-
addReferenceable(ref);
|
|
554
|
-
},
|
|
555
|
-
snapshot() {
|
|
556
|
-
return {
|
|
557
|
-
length: result.length,
|
|
558
|
-
cycleStackSize: cycleStack.size,
|
|
559
|
-
referenceableSize: referenceable.size,
|
|
560
|
-
currentPos,
|
|
561
|
-
objectTypeLookupSize: objectTypeLookup.size,
|
|
562
|
-
currentPosTypeLookup
|
|
563
|
-
};
|
|
564
|
-
},
|
|
565
|
-
rollback(snapshot) {
|
|
566
|
-
result.length = snapshot.length;
|
|
567
|
-
setSetSize(cycleStack, snapshot.cycleStackSize);
|
|
568
|
-
setMapSize(referenceable, snapshot.referenceableSize);
|
|
569
|
-
currentPos = snapshot.currentPos;
|
|
570
|
-
setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
|
|
571
|
-
currentPosTypeLookup = snapshot.currentPosTypeLookup;
|
|
572
|
-
},
|
|
573
|
-
...context
|
|
525
|
+
/**
|
|
526
|
+
* Appends the path from the root to `item`, once per error.
|
|
527
|
+
* @param {Error} err error thrown while writing `item`
|
|
528
|
+
* @param {ComplexSerializableType} item item being written
|
|
529
|
+
* @returns {Error} err
|
|
530
|
+
*/
|
|
531
|
+
const attachSerializationPath = (err, item) => {
|
|
532
|
+
if (hasDebugInfoAttached === undefined) {
|
|
533
|
+
hasDebugInfoAttached = new WeakSet();
|
|
534
|
+
}
|
|
535
|
+
if (!hasDebugInfoAttached.has(err)) {
|
|
536
|
+
err.message += `\nwhile serializing ${stackToString(item)}`;
|
|
537
|
+
hasDebugInfoAttached.add(err);
|
|
538
|
+
}
|
|
539
|
+
return err;
|
|
574
540
|
};
|
|
575
|
-
this.extendContext(ctx);
|
|
576
541
|
// Dispatched on `typeof` first: two thirds of the items are numbers,
|
|
577
542
|
// booleans and `undefined`, and only 3% are buffers.
|
|
578
543
|
/**
|
|
579
|
-
*
|
|
544
|
+
* Writes one item into the output; the context is returned so writes chain.
|
|
580
545
|
* @param {ComplexSerializableType} item item to serialize
|
|
546
|
+
* @returns {ObjectSerializerContext<EXPECTED_ANY>} context
|
|
581
547
|
*/
|
|
582
548
|
const process = (item) => {
|
|
583
549
|
switch (typeof item) {
|
|
584
550
|
case "number":
|
|
585
551
|
case "boolean":
|
|
586
552
|
result.push(item);
|
|
587
|
-
return;
|
|
553
|
+
return ctx;
|
|
588
554
|
case "string": {
|
|
589
555
|
if (item.length > 1) {
|
|
590
556
|
// short strings are shorter when not emitting a reference (this saves 1 byte per empty string)
|
|
@@ -602,10 +568,10 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
602
568
|
) {
|
|
603
569
|
// A back-reference is `null` + the offset.
|
|
604
570
|
result.push(ESCAPE, offset);
|
|
605
|
-
return;
|
|
571
|
+
return ctx;
|
|
606
572
|
}
|
|
607
573
|
}
|
|
608
|
-
|
|
574
|
+
referenceable.set(item, currentPos++);
|
|
609
575
|
}
|
|
610
576
|
|
|
611
577
|
if (item.length > 102400 && context.logger) {
|
|
@@ -617,87 +583,115 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
617
583
|
}
|
|
618
584
|
|
|
619
585
|
result.push(item);
|
|
620
|
-
return;
|
|
586
|
+
return ctx;
|
|
621
587
|
}
|
|
622
588
|
case "undefined":
|
|
623
589
|
result.push(ESCAPE, ESCAPE_UNDEFINED);
|
|
624
|
-
return;
|
|
590
|
+
return ctx;
|
|
625
591
|
case "object": {
|
|
626
592
|
// ESCAPE is null, so this covers null too
|
|
627
593
|
if (item === ESCAPE) {
|
|
628
594
|
result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
|
|
629
|
-
return;
|
|
595
|
+
return ctx;
|
|
630
596
|
}
|
|
631
597
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
598
|
+
// buffers and objects share one reference table, so a single
|
|
599
|
+
// lookup answers both before the costlier buffer test
|
|
600
|
+
const ref = referenceable.get(item);
|
|
601
|
+
if (ref !== undefined) {
|
|
602
|
+
if (ref === IN_PROGRESS) {
|
|
603
|
+
throw attachSerializationPath(
|
|
604
|
+
new Error(
|
|
605
|
+
"This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize."
|
|
606
|
+
),
|
|
607
|
+
item
|
|
608
|
+
);
|
|
638
609
|
}
|
|
610
|
+
result.push(ESCAPE, ref - currentPos);
|
|
611
|
+
return ctx;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (Buffer.isBuffer(item)) {
|
|
639
615
|
const alreadyUsedBuffer = dedupeBuffer(item);
|
|
640
616
|
if (alreadyUsedBuffer !== item) {
|
|
641
617
|
const ref = referenceable.get(alreadyUsedBuffer);
|
|
642
618
|
if (ref !== undefined) {
|
|
643
619
|
referenceable.set(item, ref);
|
|
644
620
|
result.push(ESCAPE, ref - currentPos);
|
|
645
|
-
return;
|
|
621
|
+
return ctx;
|
|
646
622
|
}
|
|
647
623
|
item = alreadyUsedBuffer;
|
|
648
624
|
}
|
|
649
|
-
|
|
625
|
+
referenceable.set(item, currentPos++);
|
|
650
626
|
|
|
651
627
|
result.push(/** @type {Buffer} */ (item));
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// check if we can emit a reference
|
|
656
|
-
const ref = referenceable.get(item);
|
|
657
|
-
if (ref !== undefined) {
|
|
658
|
-
result.push(ESCAPE, ref - currentPos);
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
if (cycleStack.has(item)) {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize."
|
|
665
|
-
);
|
|
628
|
+
return ctx;
|
|
666
629
|
}
|
|
667
630
|
|
|
668
631
|
// Keyed by the registration itself: one per class, so it stands in for
|
|
669
632
|
// `${request}/${name}` without building that string per object.
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
633
|
+
const proto = Object.getPrototypeOf(item);
|
|
634
|
+
const registered = serializers.get(
|
|
635
|
+
proto === null ? null : proto.constructor
|
|
673
636
|
);
|
|
637
|
+
/** @type {SerializerConfigWithSerializer} */
|
|
638
|
+
let config;
|
|
639
|
+
if (registered !== undefined && registered.serializer !== undefined) {
|
|
640
|
+
config = /** @type {SerializerConfigWithSerializer} */ (registered);
|
|
641
|
+
} else {
|
|
642
|
+
try {
|
|
643
|
+
// re-resolved so the miss reports which class is unregistered
|
|
644
|
+
config = ObjectMiddleware.getSerializerFor(
|
|
645
|
+
/** @type {Constructor} */
|
|
646
|
+
(item)
|
|
647
|
+
);
|
|
648
|
+
} catch (err) {
|
|
649
|
+
if (err === NOT_SERIALIZABLE) throw err;
|
|
650
|
+
throw attachSerializationPath(/** @type {Error} */ (err), item);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
674
653
|
const { request, name, serializer } = config;
|
|
675
|
-
const lastIndex =
|
|
654
|
+
const lastIndex =
|
|
655
|
+
config === lastConfig
|
|
656
|
+
? lastConfigIndex
|
|
657
|
+
: objectTypeLookup.get(config);
|
|
676
658
|
|
|
677
659
|
if (lastIndex === undefined) {
|
|
678
|
-
|
|
660
|
+
lastConfigIndex = currentPosTypeLookup++;
|
|
661
|
+
objectTypeLookup.set(config, lastConfigIndex);
|
|
679
662
|
|
|
680
663
|
result.push(ESCAPE, request, name);
|
|
681
664
|
} else {
|
|
665
|
+
lastConfigIndex = lastIndex;
|
|
682
666
|
result.push(ESCAPE, currentPosTypeLookup - lastIndex);
|
|
683
667
|
}
|
|
668
|
+
lastConfig = config;
|
|
684
669
|
|
|
685
|
-
|
|
670
|
+
referenceable.set(item, IN_PROGRESS);
|
|
671
|
+
cycleStack.push(item);
|
|
686
672
|
|
|
687
673
|
try {
|
|
688
674
|
serializer.serialize(item, ctx);
|
|
689
|
-
}
|
|
690
|
-
cycleStack.
|
|
675
|
+
} catch (err) {
|
|
676
|
+
cycleStack.pop();
|
|
677
|
+
if (err !== NOT_SERIALIZABLE) {
|
|
678
|
+
attachSerializationPath(/** @type {Error} */ (err), item);
|
|
679
|
+
}
|
|
680
|
+
throw err;
|
|
691
681
|
}
|
|
682
|
+
cycleStack.pop();
|
|
692
683
|
|
|
693
684
|
result.push(ESCAPE, ESCAPE_END_OBJECT);
|
|
694
685
|
|
|
695
|
-
|
|
696
|
-
return;
|
|
686
|
+
referenceable.set(item, currentPos++);
|
|
687
|
+
return ctx;
|
|
697
688
|
}
|
|
698
689
|
case "function": {
|
|
699
690
|
if (!SerializerMiddleware.isLazy(item)) {
|
|
700
|
-
throw
|
|
691
|
+
throw attachSerializationPath(
|
|
692
|
+
new Error(`Unexpected function ${item}`),
|
|
693
|
+
item
|
|
694
|
+
);
|
|
701
695
|
}
|
|
702
696
|
|
|
703
697
|
/** @type {SerializedType | undefined} */
|
|
@@ -708,10 +702,10 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
708
702
|
if (typeof serializedData === "function") {
|
|
709
703
|
result.push(serializedData);
|
|
710
704
|
} else {
|
|
711
|
-
throw new Error("Not implemented");
|
|
705
|
+
throw attachSerializationPath(new Error("Not implemented"), item);
|
|
712
706
|
}
|
|
713
707
|
} else if (SerializerMiddleware.isLazy(item, this)) {
|
|
714
|
-
throw new Error("Not implemented");
|
|
708
|
+
throw attachSerializationPath(new Error("Not implemented"), item);
|
|
715
709
|
} else {
|
|
716
710
|
const data =
|
|
717
711
|
/** @type {() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>} */
|
|
@@ -723,12 +717,50 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
723
717
|
SerializerMiddleware.setLazySerializedValue(item, data);
|
|
724
718
|
result.push(data);
|
|
725
719
|
}
|
|
726
|
-
return;
|
|
720
|
+
return ctx;
|
|
727
721
|
}
|
|
728
722
|
default:
|
|
729
723
|
result.push(item);
|
|
730
724
|
}
|
|
725
|
+
return ctx;
|
|
731
726
|
};
|
|
727
|
+
/** @type {ObjectSerializerContext<EXPECTED_ANY>} */
|
|
728
|
+
let ctx = {
|
|
729
|
+
write: process,
|
|
730
|
+
setCircularReference(ref) {
|
|
731
|
+
addReferenceable(ref);
|
|
732
|
+
},
|
|
733
|
+
snapshot() {
|
|
734
|
+
return {
|
|
735
|
+
length: result.length,
|
|
736
|
+
cycleStackSize: cycleStack.length,
|
|
737
|
+
referenceableSize: referenceable.size,
|
|
738
|
+
currentPos,
|
|
739
|
+
objectTypeLookupSize: objectTypeLookup.size,
|
|
740
|
+
currentPosTypeLookup
|
|
741
|
+
};
|
|
742
|
+
},
|
|
743
|
+
rollback(snapshot) {
|
|
744
|
+
result.length = snapshot.length;
|
|
745
|
+
cycleStack.length = snapshot.cycleStackSize;
|
|
746
|
+
// a `setCircularReference` since the snapshot replaced a marker on an
|
|
747
|
+
// item already keyed here, which `setMapSize` cannot undo
|
|
748
|
+
for (let i = 0; i < cycleStack.length; i++) {
|
|
749
|
+
const item = /** @type {ReferenceableItem} */ (cycleStack[i]);
|
|
750
|
+
const ref = referenceable.get(item);
|
|
751
|
+
if (ref !== undefined && ref >= snapshot.currentPos) {
|
|
752
|
+
referenceable.set(item, IN_PROGRESS);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
setMapSize(referenceable, snapshot.referenceableSize);
|
|
756
|
+
currentPos = snapshot.currentPos;
|
|
757
|
+
setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
|
|
758
|
+
lastConfig = undefined;
|
|
759
|
+
currentPosTypeLookup = snapshot.currentPosTypeLookup;
|
|
760
|
+
},
|
|
761
|
+
...context
|
|
762
|
+
};
|
|
763
|
+
this.extendContext(ctx);
|
|
732
764
|
|
|
733
765
|
try {
|
|
734
766
|
for (const item of data) {
|
|
@@ -15,6 +15,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
|
|
|
15
15
|
const ConsumeSharedModule = require("./ConsumeSharedModule");
|
|
16
16
|
const ConsumeSharedRuntimeModule = require("./ConsumeSharedRuntimeModule");
|
|
17
17
|
const ProvideForSharedDependency = require("./ProvideForSharedDependency");
|
|
18
|
+
const { addDeclaredShared } = require("./declaredShared");
|
|
18
19
|
const { resolveMatchedConfigs } = require("./resolveMatchedConfigs");
|
|
19
20
|
const {
|
|
20
21
|
getDescriptionFile,
|
|
@@ -137,6 +138,17 @@ class ConsumeSharedPlugin {
|
|
|
137
138
|
normalModuleFactory
|
|
138
139
|
);
|
|
139
140
|
|
|
141
|
+
// A key ending in a slash shares everything under it, and the
|
|
142
|
+
// modules then carry the remainder appended to the share key.
|
|
143
|
+
addDeclaredShared(
|
|
144
|
+
compilation,
|
|
145
|
+
consumes.map(([key, config]) => ({
|
|
146
|
+
name: key,
|
|
147
|
+
shareKey: config.shareKey,
|
|
148
|
+
prefix: key.endsWith("/")
|
|
149
|
+
}))
|
|
150
|
+
);
|
|
151
|
+
|
|
140
152
|
/** @typedef {Map<string, ConsumeOptions>} Consumes */
|
|
141
153
|
|
|
142
154
|
/** @type {Consumes} */
|
|
@@ -33,6 +33,17 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
|
33
33
|
this._runtimeRequirements = runtimeRequirements;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* The `[handlerMap, key]` pairs this module installs onto a chunk handler map
|
|
38
|
+
* such as `__webpack_require__.f`, or `null` where it cannot name them.
|
|
39
|
+
* @returns {[string, string][] | null} installed chunk handlers (do not mutate)
|
|
40
|
+
*/
|
|
41
|
+
getInstalledChunkHandlers() {
|
|
42
|
+
return this._runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
|
|
43
|
+
? [[RuntimeGlobals.ensureChunkHandlers, "consumes"]]
|
|
44
|
+
: [];
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
/**
|
|
37
48
|
* Generates runtime code for this runtime module.
|
|
38
49
|
* @returns {string | null} runtime code
|
|
@@ -23,6 +23,15 @@ class ShareRuntimeModule extends RuntimeModule {
|
|
|
23
23
|
super("sharing");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The `[handlerMap, key]` pairs this module installs onto a chunk handler map
|
|
28
|
+
* such as `__webpack_require__.f`, or `null` where it cannot name them.
|
|
29
|
+
* @returns {[string, string][] | null} installed chunk handlers (do not mutate)
|
|
30
|
+
*/
|
|
31
|
+
getInstalledChunkHandlers() {
|
|
32
|
+
return RuntimeModule.NO_CHUNK_HANDLERS;
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
/**
|
|
27
36
|
* Generates runtime code for this runtime module.
|
|
28
37
|
* @returns {string | null} runtime code
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
/** @import Compilation from "../Compilation" */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {object} SharedDeclaration
|
|
12
|
+
* @property {string} name the config key, as the config spells it
|
|
13
|
+
* @property {string} shareKey the key the modules created for it carry
|
|
14
|
+
* @property {boolean} prefix whether it shares everything under the key
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @type {WeakMap<Compilation, SharedDeclaration[]>} */
|
|
18
|
+
const DECLARED_SHARED = new WeakMap();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What this build declared as shared, one entry per config key, since several
|
|
22
|
+
* may name one share key. `performance.unusedConfig` matches modules on the
|
|
23
|
+
* share key and reports the config key.
|
|
24
|
+
* @param {Compilation} compilation the compilation
|
|
25
|
+
* @returns {SharedDeclaration[] | undefined} the declarations, when any were made
|
|
26
|
+
*/
|
|
27
|
+
const getDeclaredShared = (compilation) => DECLARED_SHARED.get(compilation);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Records declarations, appending when a build applies the plugin more than
|
|
31
|
+
* once, as `ModuleFederationPlugin` and `SharePlugin` do.
|
|
32
|
+
* @param {Compilation} compilation the compilation
|
|
33
|
+
* @param {SharedDeclaration[]} declarations what this application declared
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
36
|
+
const addDeclaredShared = (compilation, declarations) => {
|
|
37
|
+
const declared = DECLARED_SHARED.get(compilation);
|
|
38
|
+
|
|
39
|
+
if (declared === undefined) {
|
|
40
|
+
DECLARED_SHARED.set(compilation, [...declarations]);
|
|
41
|
+
} else {
|
|
42
|
+
for (const declaration of declarations) declared.push(declaration);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports.addDeclaredShared = addDeclaredShared;
|
|
47
|
+
module.exports.getDeclaredShared = getDeclaredShared;
|
|
@@ -1340,9 +1340,11 @@ const SIMPLE_EXTRACTORS = {
|
|
|
1340
1340
|
const warnings = module.getWarnings();
|
|
1341
1341
|
const warningsCount =
|
|
1342
1342
|
warnings !== undefined ? countIterable(warnings) : 0;
|
|
1343
|
-
const { cacheable,
|
|
1343
|
+
const { cacheable, diagnostics } = /** @type {BuildInfo} */ (
|
|
1344
1344
|
module.buildInfo
|
|
1345
1345
|
);
|
|
1346
|
+
const notCacheableReasons =
|
|
1347
|
+
diagnostics === undefined ? undefined : diagnostics.notCacheableReasons;
|
|
1346
1348
|
const preOrderIndex = /** @type {number} */ (
|
|
1347
1349
|
moduleGraph.getPreOrderIndex(module)
|
|
1348
1350
|
);
|
|
@@ -460,6 +460,8 @@ const ASSET_SIMPLE_PRINTERS = {
|
|
|
460
460
|
javascriptModule ? formatFlag("javascript module") : undefined,
|
|
461
461
|
"asset.info.sourceFilename": (sourceFilename, { formatFlag }) =>
|
|
462
462
|
sourceFilename ? formatFlag(`from: ${sourceFilename}`) : undefined,
|
|
463
|
+
"asset.info.copied": (copied, { green, formatFlag }) =>
|
|
464
|
+
copied ? green(formatFlag("copied")) : undefined,
|
|
463
465
|
"asset.info.development": (development, { green, formatFlag }) =>
|
|
464
466
|
development ? green(formatFlag("dev")) : undefined,
|
|
465
467
|
"asset.info.hotModuleReplacement": (
|
|
@@ -1045,6 +1047,7 @@ const PREFERRED_ORDERS = {
|
|
|
1045
1047
|
"asset.info": [
|
|
1046
1048
|
"immutable",
|
|
1047
1049
|
"sourceFilename",
|
|
1050
|
+
"copied",
|
|
1048
1051
|
"javascriptModule",
|
|
1049
1052
|
"development",
|
|
1050
1053
|
"hotModuleReplacement"
|
package/lib/util/ArrayQueue.js
CHANGED
|
@@ -90,11 +90,11 @@ class ArrayQueue {
|
|
|
90
90
|
[Symbol.iterator]() {
|
|
91
91
|
return {
|
|
92
92
|
next: () => {
|
|
93
|
-
|
|
94
|
-
if (
|
|
93
|
+
// length, not truthiness: a queued `0`/`false`/`undefined` is a value
|
|
94
|
+
if (this.length > 0) {
|
|
95
95
|
return {
|
|
96
96
|
done: false,
|
|
97
|
-
value:
|
|
97
|
+
value: /** @type {T} */ (this.dequeue())
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
return {
|