webpack 5.111.0 → 5.111.1
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/lib/APIPlugin.js +3 -4
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +16 -35
- package/lib/Compiler.js +4 -5
- package/lib/ConstPlugin.js +16 -132
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +24 -28
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +20 -16
- package/lib/ExternalModule.js +6 -8
- package/lib/FlagDependencyExportsPlugin.js +8 -13
- package/lib/FlagDependencyUsagePlugin.js +9 -13
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +2 -0
- package/lib/IgnorePlugin.js +1 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +3 -3
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +6 -16
- package/lib/NormalModule.js +96 -44
- package/lib/RuntimeTemplate.js +33 -43
- package/lib/SourceMapDevToolPlugin.js +53 -103
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +25 -16
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +3 -18
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +2 -8
- package/lib/config/defaults.js +52 -78
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/target.js +3 -4
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +37 -34
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +19 -11
- package/lib/css/CssParser.js +18 -20
- package/lib/css/cssMinify.js +32 -29
- package/lib/css/data.js +797 -288
- package/lib/css/syntax.js +2250 -934
- package/lib/debug/ProfilingPlugin.js +3 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +10 -11
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -5
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +6 -8
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +11 -20
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyExportExpressionDependency.js +3 -4
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyExportInitFragment.js +26 -19
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +7 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +103 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +16 -2
- package/lib/dependencies/HtmlEntryDependency.js +74 -102
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +8 -10
- package/lib/dependencies/ImportParserPlugin.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
- package/lib/dependencies/WorkerDependency.js +6 -5
- package/lib/dependencies/WorkletDependency.js +6 -9
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +61 -82
- package/lib/html/HtmlModulesPlugin.js +88 -139
- package/lib/html/HtmlParser.js +97 -141
- package/lib/html/data.js +21 -0
- package/lib/html/htmlMinify.js +10 -11
- package/lib/html/syntax.js +883 -993
- package/lib/index.js +46 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModulesPlugin.js +21 -48
- package/lib/javascript/JavascriptParser.js +721 -178
- package/lib/javascript/parser.js +6 -0
- package/lib/javascript/syntax.js +420 -92
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +64 -136
- package/lib/loaders/LoaderRunner.js +137 -9
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +81 -100
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +3 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -19
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +3 -4
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -8
- package/lib/prefetch/ResourceHintPlugin.js +17 -21
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +7 -10
- package/lib/runtime/AsyncModuleRuntimeModule.js +3 -5
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/runtime/GlobalRuntimeModule.js +2 -4
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +55 -85
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +16 -16
- package/lib/serialization/ObjectMiddleware.js +30 -33
- package/lib/stats/DefaultStatsFactoryPlugin.js +3 -4
- package/lib/typescript/TypeScriptPlugin.js +2 -3
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +15 -22
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/globUtils.js +1 -1
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/internalSerializables.js +1 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/package.json +30 -23
- package/types.d.ts +299 -280
|
@@ -259,7 +259,13 @@ class JsonGenerator extends Generator {
|
|
|
259
259
|
* @returns {Source | null} generated code
|
|
260
260
|
*/
|
|
261
261
|
generateError(error, module, generateContext) {
|
|
262
|
-
return new RawSource(
|
|
262
|
+
return new RawSource(
|
|
263
|
+
Generator.throwBuildErrorCode(
|
|
264
|
+
error,
|
|
265
|
+
undefined,
|
|
266
|
+
generateContext.runtimeTemplate.requestShortener
|
|
267
|
+
)
|
|
268
|
+
);
|
|
263
269
|
}
|
|
264
270
|
|
|
265
271
|
/**
|
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
SAFE_IDENTIFIER,
|
|
25
25
|
propertyAccess
|
|
26
26
|
} = require("../util/property");
|
|
27
|
-
const { getEntryRuntime
|
|
27
|
+
const { getEntryRuntime } = require("../util/runtime");
|
|
28
28
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
29
29
|
|
|
30
30
|
/** @import { Source } from "webpack-sources" */
|
|
@@ -39,7 +39,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
39
39
|
/** @import Compilation from "../Compilation" */
|
|
40
40
|
/** @import Compiler from "../Compiler" */
|
|
41
41
|
/** @import ModuleGraph from "../ModuleGraph" */
|
|
42
|
-
/** @import Module
|
|
42
|
+
/** @import Module from "../Module" */
|
|
43
43
|
/**
|
|
44
44
|
* @import {
|
|
45
45
|
* StartupRenderContext,
|
|
@@ -171,73 +171,33 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
171
171
|
super.apply(compiler);
|
|
172
172
|
|
|
173
173
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
174
|
-
const { onDemandExportsGeneration } =
|
|
175
|
-
ConcatenatedModule.getCompilationHooks(compilation);
|
|
176
174
|
const javascriptHooks =
|
|
177
175
|
JavascriptModulesPlugin.getCompilationHooks(compilation);
|
|
178
|
-
onDemandExportsGeneration.tap(
|
|
179
|
-
PLUGIN_NAME,
|
|
180
|
-
(module, runtimes, source, finalName) => {
|
|
181
|
-
/** @type {BuildMeta} */
|
|
182
|
-
const buildMeta = module.buildMeta || (module.buildMeta = {});
|
|
183
|
-
|
|
184
|
-
/** @type {BuildMeta["exportsSourceByRuntime"]} */
|
|
185
|
-
const exportsSourceByRuntime =
|
|
186
|
-
buildMeta.exportsSourceByRuntime ||
|
|
187
|
-
(buildMeta.exportsSourceByRuntime = new Map());
|
|
188
|
-
|
|
189
|
-
/** @type {BuildMeta["exportsFinalNameByRuntime"]} */
|
|
190
|
-
const exportsFinalNameByRuntime =
|
|
191
|
-
buildMeta.exportsFinalNameByRuntime ||
|
|
192
|
-
(buildMeta.exportsFinalNameByRuntime = new Map());
|
|
193
|
-
|
|
194
|
-
for (const runtime of runtimes) {
|
|
195
|
-
const key = getRuntimeKey(runtime);
|
|
196
|
-
exportsSourceByRuntime.set(key, source);
|
|
197
|
-
exportsFinalNameByRuntime.set(key, finalName);
|
|
198
|
-
}
|
|
199
176
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
buildMeta.exportsBindingSourceByRuntime ||
|
|
219
|
-
(buildMeta.exportsBindingSourceByRuntime = new Map());
|
|
220
|
-
bindings.set(key, source);
|
|
221
|
-
} else {
|
|
222
|
-
const sources =
|
|
223
|
-
buildMeta.exportsSourceByRuntime ||
|
|
224
|
-
(buildMeta.exportsSourceByRuntime = new Map());
|
|
225
|
-
// The `__esModule` marker and the definitions both land here, so
|
|
226
|
-
// keep whichever arrived first rather than replacing it.
|
|
227
|
-
const before = sources.get(key);
|
|
228
|
-
sources.set(key, before ? `${before}${source}` : source);
|
|
177
|
+
compilation.hooks.beforeCodeGeneration.tap(PLUGIN_NAME, () => {
|
|
178
|
+
const entries = libraryEntryModules.get(compilation);
|
|
179
|
+
if (entries === undefined) return;
|
|
180
|
+
const { moduleGraph } = compilation;
|
|
181
|
+
for (const { dependencies } of compilation.entries.values()) {
|
|
182
|
+
for (const dep of dependencies) {
|
|
183
|
+
const module = dep && moduleGraph.getModule(dep);
|
|
184
|
+
if (!module) continue;
|
|
185
|
+
const root =
|
|
186
|
+
module instanceof ConcatenatedModule ? module.rootModule : module;
|
|
187
|
+
if (!entries.has(root)) continue;
|
|
188
|
+
if (
|
|
189
|
+
root === module &&
|
|
190
|
+
!definesOnlyNativeExports(module, moduleGraph)
|
|
191
|
+
) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
moduleGraph.getMeta(module).onDemandExports = true;
|
|
229
195
|
}
|
|
230
|
-
return true;
|
|
231
196
|
}
|
|
232
|
-
);
|
|
197
|
+
});
|
|
233
198
|
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
// module is wrapped in an IIFE/factory. When the entry is
|
|
237
|
-
// inlined directly, the stashed source — and the
|
|
238
|
-
// `definePropertyGetters` / `requireScope` runtime helpers it
|
|
239
|
-
// pulled in — never make it into the output. Drop those helpers
|
|
240
|
-
// from the chunk's set so the bundle stays clean.
|
|
199
|
+
// The stashed exports source is re-emitted only where the entry is wrapped;
|
|
200
|
+
// inlined directly, the helpers it pulled in have no reader and can go.
|
|
241
201
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
|
242
202
|
PLUGIN_NAME,
|
|
243
203
|
(chunk, set, { chunkGraph, codeGenerationResults }) => {
|
|
@@ -255,22 +215,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
255
215
|
if (javascriptHooks.inlineInRuntimeBailout.isUsed()) return;
|
|
256
216
|
|
|
257
217
|
const [module] = chunkGraph.getChunkEntryModulesIterable(chunk);
|
|
258
|
-
const runtimeKey = getRuntimeKey(chunk.runtime);
|
|
259
|
-
const buildMeta = module.buildMeta;
|
|
260
|
-
const takenOver =
|
|
261
|
-
(buildMeta &&
|
|
262
|
-
buildMeta.exportsSourceByRuntime &&
|
|
263
|
-
buildMeta.exportsSourceByRuntime.has(runtimeKey)) ||
|
|
264
|
-
(buildMeta &&
|
|
265
|
-
buildMeta.exportsBindingSourceByRuntime &&
|
|
266
|
-
buildMeta.exportsBindingSourceByRuntime.has(runtimeKey));
|
|
267
|
-
if (!takenOver) return;
|
|
268
218
|
const codeGenResult = codeGenerationResults.get(
|
|
269
219
|
module,
|
|
270
220
|
chunk.runtime
|
|
271
221
|
);
|
|
272
|
-
const
|
|
273
|
-
|
|
222
|
+
const { data } = codeGenResult;
|
|
223
|
+
const takenOver =
|
|
224
|
+
data !== undefined &&
|
|
225
|
+
(data.has("exportsSource") || data.has("exportsBindingSource"));
|
|
226
|
+
if (!takenOver) return;
|
|
227
|
+
const jsSource = codeGenResult.sources.get("javascript");
|
|
274
228
|
if (
|
|
275
229
|
jsSource &&
|
|
276
230
|
String(jsSource.source()).includes(`${RuntimeGlobals.require}.`)
|
|
@@ -608,19 +562,13 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
608
562
|
]
|
|
609
563
|
: moduleGraph.getExportsInfo(module).orderedExports;
|
|
610
564
|
|
|
611
|
-
const
|
|
612
|
-
(module.buildMeta &&
|
|
613
|
-
module.buildMeta.exportsFinalNameByRuntime &&
|
|
614
|
-
module.buildMeta.exportsFinalNameByRuntime.get(
|
|
615
|
-
getRuntimeKey(chunk.runtime)
|
|
616
|
-
)) ||
|
|
617
|
-
{};
|
|
565
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
|
618
566
|
|
|
619
567
|
const isInlinedEntryWithoutIIFE = inlined && !inlinedInIIFE;
|
|
620
568
|
// Direct export bindings from on-demand concatenation
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
569
|
+
/** @type {Record<string, string>} */
|
|
570
|
+
const definitions =
|
|
571
|
+
(isInlinedEntryWithoutIIFE && data && data.get("exportsFinalName")) || {};
|
|
624
572
|
|
|
625
573
|
/** @type {string[]} */
|
|
626
574
|
const shortHandedExports = [];
|
|
@@ -654,15 +602,12 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
654
602
|
.treatAsCommonJs;
|
|
655
603
|
const skipRenderDefaultExport = Boolean(treatAsCommonJs);
|
|
656
604
|
|
|
657
|
-
// A single
|
|
658
|
-
//
|
|
659
|
-
//
|
|
660
|
-
// `__webpack_exports__.x` into a `const`. Concatenated entries already
|
|
661
|
-
// get direct bindings via `definitions` above.
|
|
605
|
+
// A single inlined entry renders at the top level, so its declarations are
|
|
606
|
+
// bindings that can be exported directly, keeping ESM live bindings rather
|
|
607
|
+
// than snapshotting them into a `const`.
|
|
662
608
|
/** @type {Map<string, string> | undefined} */
|
|
663
609
|
let directBindings;
|
|
664
610
|
if (isInlinedEntryWithoutIIFE && !treatAsCommonJs) {
|
|
665
|
-
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
|
666
611
|
const topLevelDeclarations =
|
|
667
612
|
(data && data.get("topLevelDeclarations")) ||
|
|
668
613
|
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
|
@@ -681,15 +626,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
681
626
|
}
|
|
682
627
|
}
|
|
683
628
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const bindingsTakenOver = Boolean(
|
|
687
|
-
module.buildMeta &&
|
|
688
|
-
module.buildMeta.exportsBindingSourceByRuntime &&
|
|
689
|
-
module.buildMeta.exportsBindingSourceByRuntime.has(
|
|
690
|
-
getRuntimeKey(chunk.runtime)
|
|
691
|
-
)
|
|
692
|
-
);
|
|
629
|
+
const bindingsTakenOver =
|
|
630
|
+
data !== undefined && data.has("exportsBindingSource");
|
|
693
631
|
|
|
694
632
|
const moduleExportsInfo = moduleGraph.getExportsInfo(module);
|
|
695
633
|
|
|
@@ -711,7 +649,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
711
649
|
}
|
|
712
650
|
|
|
713
651
|
// Try to find all known exports of the entry module
|
|
714
|
-
|
|
652
|
+
for (const exportInfo of exportInfos) {
|
|
715
653
|
if (!exportInfo.provided) continue;
|
|
716
654
|
|
|
717
655
|
const originalName = exportInfo.name;
|
|
@@ -719,40 +657,37 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
719
657
|
if (skipRenderDefaultExport && originalName === "default") continue;
|
|
720
658
|
|
|
721
659
|
// Try to find all exports from the reexported modules
|
|
722
|
-
const target = exportInfo.
|
|
723
|
-
|
|
724
|
-
// export
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
}
|
|
660
|
+
const target = exportInfo.getTarget(moduleGraph);
|
|
661
|
+
|
|
662
|
+
// A re-export is provided even when its target lacks the export, and
|
|
663
|
+
// the path can end in a property access, so every name is looked up.
|
|
664
|
+
if (
|
|
665
|
+
target &&
|
|
666
|
+
target.export &&
|
|
667
|
+
target.export[target.export.length - 1] !== "default" &&
|
|
668
|
+
moduleGraph
|
|
669
|
+
.getExportsInfo(target.module)
|
|
670
|
+
.isExportProvided(target.export) === false
|
|
671
|
+
) {
|
|
672
|
+
continue;
|
|
737
673
|
}
|
|
738
674
|
|
|
739
|
-
const externalTarget = exportInfo.getTarget(moduleGraph);
|
|
740
675
|
if (
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
codeGenerationResults.has(
|
|
676
|
+
target &&
|
|
677
|
+
target.module instanceof ExternalModule &&
|
|
678
|
+
target.export &&
|
|
679
|
+
target.export.length === 1 &&
|
|
680
|
+
codeGenerationResults.has(target.module, chunk.runtime)
|
|
746
681
|
) {
|
|
747
682
|
const reexport = codeGenerationResults.getData(
|
|
748
|
-
|
|
683
|
+
target.module,
|
|
749
684
|
chunk.runtime,
|
|
750
685
|
"externalReexport"
|
|
751
686
|
);
|
|
752
687
|
if (reexport) {
|
|
753
688
|
if (!bindingsTakenOver) needExportsDeclaration = true;
|
|
754
689
|
result.add(
|
|
755
|
-
`export { ${toExportName(
|
|
690
|
+
`export { ${toExportName(target.export[0])} as ${toExportName(originalName)} } ${reexport};\n`
|
|
756
691
|
);
|
|
757
692
|
alreadyRenderedExports.add(originalName);
|
|
758
693
|
continue;
|
|
@@ -801,7 +736,6 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
801
736
|
finalName.includes("("))
|
|
802
737
|
) {
|
|
803
738
|
if (exportInfo.isReexport()) {
|
|
804
|
-
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
|
805
739
|
const topLevelDeclarations =
|
|
806
740
|
(data && data.get("topLevelDeclarations")) ||
|
|
807
741
|
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
|
@@ -880,19 +814,13 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
880
814
|
renderModuleContent(
|
|
881
815
|
source,
|
|
882
816
|
module,
|
|
883
|
-
{ factory, inlinedInIIFE, chunk },
|
|
817
|
+
{ factory, inlinedInIIFE, chunk, codeGenerationResults },
|
|
884
818
|
libraryContext
|
|
885
819
|
) {
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
const exportsSource =
|
|
889
|
-
|
|
890
|
-
buildMeta.exportsSourceByRuntime &&
|
|
891
|
-
buildMeta.exportsSourceByRuntime.get(runtimeKey);
|
|
892
|
-
const bindingSource =
|
|
893
|
-
buildMeta &&
|
|
894
|
-
buildMeta.exportsBindingSourceByRuntime &&
|
|
895
|
-
buildMeta.exportsBindingSourceByRuntime.get(runtimeKey);
|
|
820
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
|
821
|
+
if (data === undefined) return source;
|
|
822
|
+
const exportsSource = data.get("exportsSource");
|
|
823
|
+
const bindingSource = data.get("exportsBindingSource");
|
|
896
824
|
|
|
897
825
|
// Re-add the exports source in a factory or IIFE-wrapped startup module; value
|
|
898
826
|
// bindings read the declarations above them, so those go after the body.
|
|
@@ -10,6 +10,9 @@ const { parseResource } = require("../util/identifier");
|
|
|
10
10
|
const { adjustSourceMapForRemovedBOM } = require("../util/removeBOM");
|
|
11
11
|
const loadLoader = require("./loadLoader");
|
|
12
12
|
|
|
13
|
+
/** @import { RawSourceMap } from "webpack-sources" */
|
|
14
|
+
/** @import { Environment } from "../../declarations/WebpackOptions" */
|
|
15
|
+
|
|
13
16
|
// Set on a loader context to have each loader's own run measured. Absent
|
|
14
17
|
// unless something asked for the measurement, and read once per loader.
|
|
15
18
|
const LOADER_TIMING = Symbol("loader timing");
|
|
@@ -44,14 +47,139 @@ const LOADER_TIMING = Symbol("loader timing");
|
|
|
44
47
|
|
|
45
48
|
/** @typedef {(...args: EXPECTED_ANY[]) => void} LoaderCallback */
|
|
46
49
|
|
|
47
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {object} AdditionalDataKnown
|
|
52
|
+
* @property {EXPECTED_OBJECT} webpackAST the AST webpack should parse instead of the source
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/** @typedef {AdditionalDataKnown & Record<string, EXPECTED_ANY>} AdditionalData */
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @callback WebpackLoaderContextCallback
|
|
59
|
+
* @param {undefined | null | Error} err error object
|
|
60
|
+
* @param {(string | Buffer)=} content the loader result
|
|
61
|
+
* @param {(null | string | RawSourceMap)=} sourceMap a source map for the result
|
|
62
|
+
* @param {AdditionalData=} additionalData data passed to the next loader
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {object} LoaderEntry
|
|
68
|
+
* @property {string} request
|
|
69
|
+
* @property {string} path
|
|
70
|
+
* @property {string} query
|
|
71
|
+
* @property {string} fragment
|
|
72
|
+
* @property {EXPECTED_OBJECT | string | undefined} options
|
|
73
|
+
* @property {string} ident
|
|
74
|
+
* @property {EXPECTED_FUNCTION | undefined} normal
|
|
75
|
+
* @property {EXPECTED_FUNCTION | undefined} pitch
|
|
76
|
+
* @property {boolean | undefined} raw
|
|
77
|
+
* @property {EXPECTED_OBJECT | undefined} data
|
|
78
|
+
* @property {boolean} pitchExecuted
|
|
79
|
+
* @property {boolean} normalExecuted
|
|
80
|
+
* @property {("commonjs" | "module")=} type
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The members the runner never lets a loader assign. They carry no
|
|
85
|
+
* documentation, so a type literal loses nothing and keeps `readonly`
|
|
86
|
+
* @template OptionsType
|
|
87
|
+
* @typedef {{ readonly currentRequest: string, readonly data: EXPECTED_ANY, readonly previousRequest: string, readonly query: string | OptionsType, readonly remainingRequest: string, readonly request: string }} LoaderRunnerReadonlyContext
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @template OptionsType
|
|
92
|
+
* @typedef {object} LoaderRunnerMutableContext
|
|
93
|
+
* @property {(context: string) => void} addContextDependency Add a directory as dependency of the loader result.
|
|
94
|
+
* @property {(file: string) => void} addDependency Adds a file as dependency of the loader result in order to make them watchable.
|
|
95
|
+
* For example, html-loader uses this technique as it finds src and src-set attributes.
|
|
96
|
+
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
|
|
97
|
+
* @property {(context: string) => void} addMissingDependency
|
|
98
|
+
* @property {() => WebpackLoaderContextCallback} async Make this loader async.
|
|
99
|
+
* @property {(flag?: boolean) => void} cacheable Make this loader result cacheable. By default it's cacheable.
|
|
100
|
+
* A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
|
|
101
|
+
* This means the loader shouldn't have other dependencies than specified with this.addDependency.
|
|
102
|
+
* Most loaders are deterministic and cacheable.
|
|
103
|
+
* @property {WebpackLoaderContextCallback} callback
|
|
104
|
+
* @property {() => void} clearDependencies Remove all dependencies of the loader result. Even initial dependencies and these of other loaders.
|
|
105
|
+
* @property {string} context The directory of the module. Can be used as context for resolving other stuff.
|
|
106
|
+
* eg '/workspaces/ts-loader/examples/vanilla/src'
|
|
107
|
+
* @property {(file: string) => void} dependency alias of addDependency
|
|
108
|
+
* Adds a file as dependency of the loader result in order to make them watchable.
|
|
109
|
+
* For example, html-loader uses this technique as it finds src and src-set attributes.
|
|
110
|
+
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
|
|
111
|
+
* @property {() => string[]} getContextDependencies
|
|
112
|
+
* @property {() => string[]} getDependencies
|
|
113
|
+
* @property {() => string[]} getMissingDependencies
|
|
114
|
+
* @property {number} loaderIndex The index in the loaders array of the current loader.
|
|
115
|
+
* In the example: in loader1: 0, in loader2: 1
|
|
116
|
+
* @property {LoaderEntry[]} loaders An array of all the loaders. It is writeable in the pitch phase.
|
|
117
|
+
* loaders = [{request: string, path: string, query: string, module: function}]
|
|
118
|
+
* @property {string} resourcePath The resource path.
|
|
119
|
+
* In the example: "/abc/resource.js"
|
|
120
|
+
* @property {string} resourceQuery The resource query string.
|
|
121
|
+
* Example: "?query"
|
|
122
|
+
* @property {string} resourceFragment The resource fragment.
|
|
123
|
+
* Example: "#frag"
|
|
124
|
+
* @property {string} resource The resource inclusive query and fragment.
|
|
125
|
+
* Example: "/abc/resource.js?query#frag"
|
|
126
|
+
* @property {string} target Target of compilation.
|
|
127
|
+
* Example: "web"
|
|
128
|
+
* @property {Environment} environment Tell what kind of ES-features may be used in the generated runtime-code.
|
|
129
|
+
* Example: { arrowFunction: true }
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The properties are added by https://github.com/webpack/loader-runner
|
|
134
|
+
* @template OptionsType
|
|
135
|
+
* @typedef {LoaderRunnerMutableContext<OptionsType> & LoaderRunnerReadonlyContext<OptionsType>} LoaderRunnerLoaderContext
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @template [OptionsType={}]
|
|
140
|
+
* @template [ContextAdditions={}]
|
|
141
|
+
* @typedef {(this: import("../NormalModule").LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: EXPECTED_OBJECT) => string | Buffer | Promise<string | Buffer> | void} PitchLoaderDefinitionFunction
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @template [OptionsType={}]
|
|
146
|
+
* @template [ContextAdditions={}]
|
|
147
|
+
* @typedef {(this: import("../NormalModule").LoaderContext<OptionsType> & ContextAdditions, content: string, sourceMap?: string | RawSourceMap, additionalData?: AdditionalData) => string | Buffer | Promise<string | Buffer> | void} LoaderDefinitionFunction
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @template [OptionsType={}]
|
|
152
|
+
* @template [ContextAdditions={}]
|
|
153
|
+
* @typedef {(this: import("../NormalModule").LoaderContext<OptionsType> & ContextAdditions, content: Buffer, sourceMap?: string | RawSourceMap, additionalData?: AdditionalData) => string | Buffer | Promise<string | Buffer> | void} RawLoaderDefinitionFunction
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @template [OptionsType={}]
|
|
158
|
+
* @template [ContextAdditions={}]
|
|
159
|
+
* @typedef {LoaderDefinitionFunction<OptionsType, ContextAdditions> & { raw?: false, pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions> }} LoaderDefinition
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @template [OptionsType={}]
|
|
164
|
+
* @template [ContextAdditions={}]
|
|
165
|
+
* @typedef {RawLoaderDefinitionFunction<OptionsType, ContextAdditions> & { raw: true, pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions> }} RawLoaderDefinition
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @template [OptionsType={}]
|
|
170
|
+
* @template [ContextAdditions={}]
|
|
171
|
+
* @typedef {object} LoaderModule
|
|
172
|
+
* @property {(RawLoaderDefinitionFunction<OptionsType, ContextAdditions> | LoaderDefinitionFunction<OptionsType, ContextAdditions>)=} default
|
|
173
|
+
* @property {false=} raw
|
|
174
|
+
* @property {PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>=} pitch
|
|
175
|
+
*/
|
|
48
176
|
|
|
49
177
|
/**
|
|
50
178
|
* The loader context as the runner sees and mutates it: the canonical
|
|
51
179
|
* `LoaderRunnerLoaderContext` shape (not re-declared here), with only the fields
|
|
52
180
|
* the runner assigns internally before a loader runs widened to their mutable
|
|
53
181
|
* form (nullable `context`/`callback`/`async`, `LoaderObject` loaders).
|
|
54
|
-
* @typedef {Omit<LoaderRunnerLoaderContext
|
|
182
|
+
* @typedef {Omit<LoaderRunnerLoaderContext<EXPECTED_ANY>, "context" | "callback" | "async" | "loaders"> & { context: string | null, callback: LoaderCallback | null, async: (() => LoaderCallback | undefined) | null, loaders: LoaderObject[] }} LoaderContext
|
|
55
183
|
*/
|
|
56
184
|
|
|
57
185
|
const HASH_ESCAPE_REGEXP = /#/g;
|
|
@@ -575,7 +703,7 @@ function createLoaderContext(base) {
|
|
|
575
703
|
* Marks the request as not cacheable with the given reasons instead of
|
|
576
704
|
* attributing the currently running loader (used by the host when the cause
|
|
577
705
|
* lives outside the loader, e.g. in a child compilation of `importModule`).
|
|
578
|
-
* @param {LoaderRunnerLoaderContext} loaderContext loader context
|
|
706
|
+
* @param {LoaderRunnerLoaderContext<EXPECTED_ANY>} loaderContext loader context
|
|
579
707
|
* @param {string[]} reasons reasons why the request is not cacheable
|
|
580
708
|
* @returns {void}
|
|
581
709
|
*/
|
|
@@ -682,12 +810,12 @@ const ACCESSORS = {
|
|
|
682
810
|
* @returns {void}
|
|
683
811
|
*/
|
|
684
812
|
module.exports.runLoaders = function runLoaders(options, callback) {
|
|
685
|
-
// reuse a context already prepared
|
|
686
|
-
// NormalModule
|
|
687
|
-
// in place. State is intentionally preserved across the handoff, so
|
|
688
|
-
//
|
|
689
|
-
// non-cacheable before the run; a caller re-running on the same context
|
|
690
|
-
// clearDependencies() first to avoid accumulating stale
|
|
813
|
+
// WHY: reuse a context `createLoaderContext` already prepared, from
|
|
814
|
+
// NormalModule say, else augment the caller-provided context, or a fresh
|
|
815
|
+
// object, in place. State is intentionally preserved across the handoff, so a
|
|
816
|
+
// host hook such as `beforeLoaders` can pre-add dependencies or mark the
|
|
817
|
+
// request non-cacheable before the run; a caller re-running on the same context
|
|
818
|
+
// should `clearDependencies()` first, to avoid accumulating stale ones.
|
|
691
819
|
const provided = /** @type {EXPECTED_ANY} */ (options.context);
|
|
692
820
|
const loaderContext =
|
|
693
821
|
provided && provided[LOADER_STATE]
|
|
@@ -147,15 +147,9 @@ class NodeWatchFileSystem {
|
|
|
147
147
|
const directoriesSet =
|
|
148
148
|
directories instanceof Set ? directories : new Set(directories);
|
|
149
149
|
|
|
150
|
-
// Watchpack reports a watched directory
|
|
151
|
-
// `
|
|
152
|
-
//
|
|
153
|
-
// prefix, so it would wipe the stat cache of every file inside the
|
|
154
|
-
// directory even though only file-level events actually invalidate
|
|
155
|
-
// file stats. For directories we explicitly watch, purge only the
|
|
156
|
-
// directory's own entry (`{ exact: true }`, enhanced-resolve >=
|
|
157
|
-
// 5.22.0); file-level events in the same aggregated batch still
|
|
158
|
-
// handle file stats and the parent readdir invalidation.
|
|
150
|
+
// Watchpack reports a watched directory whenever its contents change, and
|
|
151
|
+
// `fs.purge(dir)` matches by prefix, wiping every file's stat cache with it.
|
|
152
|
+
// Only its own entry is purged; the batch's file events carry the rest.
|
|
159
153
|
/**
|
|
160
154
|
* @param {Changes | null | undefined} changes changes set
|
|
161
155
|
* @param {Removals | null | undefined} removals removals set
|
|
@@ -53,11 +53,9 @@ class AggressiveMergingPlugin {
|
|
|
53
53
|
},
|
|
54
54
|
(chunks) => {
|
|
55
55
|
const chunkGraph = compilation.chunkGraph;
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
// `>` keeps the first-encountered best, matching the previous stable
|
|
60
|
-
// descending sort's `[0]`.
|
|
56
|
+
// One pair is merged per pass and the hook re-runs, so the maximum is
|
|
57
|
+
// tracked directly rather than sorting every pair each time. A strict
|
|
58
|
+
// `>` keeps the first best found, as a stable descending sort would.
|
|
61
59
|
/** @type {Chunk | undefined} */
|
|
62
60
|
let bestA;
|
|
63
61
|
/** @type {Chunk | undefined} */
|