webpack 5.107.2 → 5.108.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/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +25 -11
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +2 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +142 -80
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +8 -0
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +3 -5
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +64 -7
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
- package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +22 -6
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +30 -6
- package/lib/html/HtmlGenerator.js +217 -23
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +219 -55
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +285 -158
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +24 -5
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +395 -77
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +10 -5
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +35 -27
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1456 -290
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
package/lib/Compiler.js
CHANGED
|
@@ -28,7 +28,10 @@ const ConcurrentCompilationError = require("./errors/ConcurrentCompilationError"
|
|
|
28
28
|
const WebpackError = require("./errors/WebpackError");
|
|
29
29
|
const { Logger } = require("./logging/Logger");
|
|
30
30
|
const { dirname, join, mkdirp } = require("./util/fs");
|
|
31
|
-
const {
|
|
31
|
+
const {
|
|
32
|
+
WINDOWS_ABS_PATH_REGEXP,
|
|
33
|
+
makePathsRelative
|
|
34
|
+
} = require("./util/identifier");
|
|
32
35
|
const memoize = require("./util/memoize");
|
|
33
36
|
const parseJson = require("./util/parseJson");
|
|
34
37
|
const { isSourceEqual } = require("./util/source");
|
|
@@ -312,21 +315,28 @@ class Compiler {
|
|
|
312
315
|
browser: null,
|
|
313
316
|
webworker: null,
|
|
314
317
|
node: null,
|
|
318
|
+
deno: null,
|
|
319
|
+
bun: null,
|
|
315
320
|
nwjs: null,
|
|
316
|
-
electron: null
|
|
321
|
+
electron: null,
|
|
322
|
+
universal: null
|
|
317
323
|
};
|
|
318
324
|
|
|
319
325
|
this.options = options;
|
|
320
326
|
|
|
327
|
+
/** @type {string} */
|
|
321
328
|
this.context = context;
|
|
322
329
|
|
|
330
|
+
/** @type {RequestShortener} */
|
|
323
331
|
this.requestShortener = new RequestShortener(context, this.root);
|
|
324
332
|
|
|
333
|
+
/** @type {Cache} */
|
|
325
334
|
this.cache = new Cache();
|
|
326
335
|
|
|
327
336
|
/** @type {Map<Module, ModuleMemCachesItem> | undefined} */
|
|
328
337
|
this.moduleMemCaches = undefined;
|
|
329
338
|
|
|
339
|
+
/** @type {string} */
|
|
330
340
|
this.compilerPath = "";
|
|
331
341
|
|
|
332
342
|
/** @type {boolean} */
|
|
@@ -338,6 +348,7 @@ class Compiler {
|
|
|
338
348
|
/** @type {boolean} */
|
|
339
349
|
this.watchMode = false;
|
|
340
350
|
|
|
351
|
+
/** @type {boolean} */
|
|
341
352
|
this._backCompat = this.options.experiments.backCompat !== false;
|
|
342
353
|
|
|
343
354
|
/** @type {Compilation | undefined} */
|
|
@@ -778,6 +789,14 @@ class Compiler {
|
|
|
778
789
|
includesHash(targetFile, info.fullhash));
|
|
779
790
|
}
|
|
780
791
|
|
|
792
|
+
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
|
793
|
+
// A Windows drive-absolute targetFile is written as-is; joining it onto
|
|
794
|
+
// outputPath would produce an invalid path (e.g. C:\out\D:\file). A
|
|
795
|
+
// leading "/" stays relative to outputPath (e.g. entry name "/dir/x").
|
|
796
|
+
const targetPath = WINDOWS_ABS_PATH_REGEXP.test(targetFile)
|
|
797
|
+
? targetFile
|
|
798
|
+
: join(fs, outputPath, targetFile);
|
|
799
|
+
|
|
781
800
|
/**
|
|
782
801
|
* Processes the provided err.
|
|
783
802
|
* @param {Error=} err error
|
|
@@ -785,12 +804,6 @@ class Compiler {
|
|
|
785
804
|
*/
|
|
786
805
|
const writeOut = (err) => {
|
|
787
806
|
if (err) return callback(err);
|
|
788
|
-
const targetPath = join(
|
|
789
|
-
/** @type {OutputFileSystem} */
|
|
790
|
-
(this.outputFileSystem),
|
|
791
|
-
outputPath,
|
|
792
|
-
targetFile
|
|
793
|
-
);
|
|
794
807
|
allTargetPaths.add(targetPath);
|
|
795
808
|
|
|
796
809
|
// check if the target file has already been written by this Compiler
|
|
@@ -1056,8 +1069,7 @@ ${other}`);
|
|
|
1056
1069
|
};
|
|
1057
1070
|
|
|
1058
1071
|
if (/\/|\\/.test(targetFile)) {
|
|
1059
|
-
const
|
|
1060
|
-
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
|
1072
|
+
const dir = dirname(fs, targetPath);
|
|
1061
1073
|
mkdirp(fs, dir, writeOut);
|
|
1062
1074
|
} else {
|
|
1063
1075
|
writeOut();
|
|
@@ -1225,7 +1237,9 @@ ${other}`);
|
|
|
1225
1237
|
} catch (parseErr) {
|
|
1226
1238
|
return callback(
|
|
1227
1239
|
new Error(
|
|
1228
|
-
`Cannot parse records: ${
|
|
1240
|
+
`Cannot parse records: ${
|
|
1241
|
+
/** @type {Error} */ (parseErr).message
|
|
1242
|
+
}`
|
|
1229
1243
|
)
|
|
1230
1244
|
);
|
|
1231
1245
|
}
|
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
/** @typedef {import("./optimize/ConcatenatedModule").ExportName} Ids */
|
|
18
18
|
|
|
19
19
|
const MODULE_REFERENCE_REGEXP =
|
|
20
|
-
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(_deferredImport)?(?:_asiSafe(\d))?__$/;
|
|
20
|
+
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(_deferredImport)?(_mangleableNs)?(?:_asiSafe(\d))?__$/;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Encodes how a concatenated module reference should be interpreted when it is
|
|
@@ -27,6 +27,7 @@ const MODULE_REFERENCE_REGEXP =
|
|
|
27
27
|
* @property {boolean} call true, when this referenced export is called
|
|
28
28
|
* @property {boolean} directImport true, when this referenced export is directly imported (not via property access)
|
|
29
29
|
* @property {boolean} deferredImport true, when this referenced export is deferred
|
|
30
|
+
* @property {boolean} mangleableNamespace true, when a whole-namespace reference may use a decoupled namespace object that keeps the original export names
|
|
30
31
|
* @property {boolean | undefined} asiSafe if the position is ASI safe or unknown
|
|
31
32
|
*/
|
|
32
33
|
|
|
@@ -43,6 +44,7 @@ class ConcatenationScope {
|
|
|
43
44
|
* @param {Set<string>} usedNames all used names
|
|
44
45
|
*/
|
|
45
46
|
constructor(modulesMap, currentModule, usedNames) {
|
|
47
|
+
/** @type {ConcatenatedModuleInfo} */
|
|
46
48
|
this._currentModule = currentModule;
|
|
47
49
|
if (Array.isArray(modulesMap)) {
|
|
48
50
|
/** @type {Map<Module, ConcatenatedModuleInfo>} */
|
|
@@ -52,7 +54,9 @@ class ConcatenationScope {
|
|
|
52
54
|
}
|
|
53
55
|
modulesMap = map;
|
|
54
56
|
}
|
|
57
|
+
/** @type {Set<string>} */
|
|
55
58
|
this.usedNames = usedNames;
|
|
59
|
+
/** @type {Map<Module, ModuleInfo>} */
|
|
56
60
|
this._modulesMap = modulesMap;
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -144,6 +148,7 @@ class ConcatenationScope {
|
|
|
144
148
|
call = false,
|
|
145
149
|
directImport = false,
|
|
146
150
|
deferredImport = false,
|
|
151
|
+
mangleableNamespace = false,
|
|
147
152
|
asiSafe = false
|
|
148
153
|
}
|
|
149
154
|
) {
|
|
@@ -151,6 +156,7 @@ class ConcatenationScope {
|
|
|
151
156
|
const callFlag = call ? "_call" : "";
|
|
152
157
|
const directImportFlag = directImport ? "_directImport" : "";
|
|
153
158
|
const deferredImportFlag = deferredImport ? "_deferredImport" : "";
|
|
159
|
+
const mangleableNamespaceFlag = mangleableNamespace ? "_mangleableNs" : "";
|
|
154
160
|
const asiSafeFlag = asiSafe
|
|
155
161
|
? "_asiSafe1"
|
|
156
162
|
: asiSafe === false
|
|
@@ -160,7 +166,7 @@ class ConcatenationScope {
|
|
|
160
166
|
? Buffer.from(JSON.stringify(ids), "utf8").toString("hex")
|
|
161
167
|
: "ns";
|
|
162
168
|
// a "._" is appended to allow "delete ...", which would cause a SyntaxError in strict mode
|
|
163
|
-
return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${deferredImportFlag}${asiSafeFlag}__._`;
|
|
169
|
+
return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${deferredImportFlag}${mangleableNamespaceFlag}${asiSafeFlag}__._`;
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
/**
|
|
@@ -183,7 +189,7 @@ class ConcatenationScope {
|
|
|
183
189
|
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
|
184
190
|
if (!match) return null;
|
|
185
191
|
const index = Number(match[1]);
|
|
186
|
-
const asiSafe = match[
|
|
192
|
+
const asiSafe = match[7];
|
|
187
193
|
return {
|
|
188
194
|
index,
|
|
189
195
|
ids:
|
|
@@ -193,6 +199,7 @@ class ConcatenationScope {
|
|
|
193
199
|
call: Boolean(match[3]),
|
|
194
200
|
directImport: Boolean(match[4]),
|
|
195
201
|
deferredImport: Boolean(match[5]),
|
|
202
|
+
mangleableNamespace: Boolean(match[6]),
|
|
196
203
|
asiSafe: asiSafe ? asiSafe === "1" : undefined
|
|
197
204
|
};
|
|
198
205
|
}
|
package/lib/ContextModule.js
CHANGED
|
@@ -48,6 +48,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
48
48
|
/** @typedef {import("./Dependency")} Dependency */
|
|
49
49
|
/** @typedef {import("./Dependency").RawReferencedExports} RawReferencedExports */
|
|
50
50
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
|
51
|
+
/** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
|
|
51
52
|
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
|
52
53
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
|
53
54
|
/** @typedef {import("./Module").FileSystemDependencies} FileSystemDependencies */
|
|
@@ -65,8 +66,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
65
66
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
66
67
|
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
|
|
67
68
|
/** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
68
|
-
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
69
|
-
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
69
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext<[string, boolean]>} ObjectDeserializerContext */
|
|
70
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext<[string, boolean]>} ObjectSerializerContext */
|
|
70
71
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
71
72
|
/** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
72
73
|
|
|
@@ -121,6 +122,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
121
122
|
/** @typedef {Record<string, ModuleId>} UserRequestMap */
|
|
122
123
|
/** @typedef {Record<ModuleId, ModuleId[]>} UserRequestsMap */
|
|
123
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Defines the build info properties specific to context modules.
|
|
127
|
+
* @typedef {object} KnownContextModuleBuildInfo
|
|
128
|
+
* @property {(Snapshot | null)=} snapshot
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/** @typedef {BuildInfo & KnownContextModuleBuildInfo} ContextModuleBuildInfo */
|
|
132
|
+
|
|
124
133
|
class ContextModule extends Module {
|
|
125
134
|
/**
|
|
126
135
|
* @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
|
|
@@ -156,10 +165,15 @@ class ContextModule extends Module {
|
|
|
156
165
|
};
|
|
157
166
|
}
|
|
158
167
|
|
|
168
|
+
// Redeclared with the context module specific shape
|
|
169
|
+
/** @type {ContextModuleBuildInfo | undefined} */
|
|
170
|
+
this.buildInfo = undefined;
|
|
171
|
+
|
|
159
172
|
// Info from Factory
|
|
160
173
|
/** @type {ResolveDependencies | undefined} */
|
|
161
174
|
this.resolveDependencies = resolveDependencies;
|
|
162
175
|
if (options && options.resolveOptions !== undefined) {
|
|
176
|
+
/** @type {ResolveOptions | undefined} */
|
|
163
177
|
this.resolveOptions = options.resolveOptions;
|
|
164
178
|
}
|
|
165
179
|
|
|
@@ -167,7 +181,9 @@ class ContextModule extends Module {
|
|
|
167
181
|
throw new Error("options.mode is a required option");
|
|
168
182
|
}
|
|
169
183
|
|
|
184
|
+
/** @type {string} */
|
|
170
185
|
this._identifier = this._createIdentifier();
|
|
186
|
+
/** @type {boolean} */
|
|
171
187
|
this._forceBuild = true;
|
|
172
188
|
}
|
|
173
189
|
|
|
@@ -436,7 +452,7 @@ class ContextModule extends Module {
|
|
|
436
452
|
// build if enforced
|
|
437
453
|
if (this._forceBuild) return callback(null, true);
|
|
438
454
|
|
|
439
|
-
const buildInfo = /** @type {
|
|
455
|
+
const buildInfo = /** @type {ContextModuleBuildInfo} */ (this.buildInfo);
|
|
440
456
|
|
|
441
457
|
// always build when we have no snapshot and context
|
|
442
458
|
if (!buildInfo.snapshot) {
|
|
@@ -464,9 +480,18 @@ class ContextModule extends Module {
|
|
|
464
480
|
exportsType: "default",
|
|
465
481
|
defaultObject: "redirect-warn"
|
|
466
482
|
};
|
|
483
|
+
|
|
484
|
+
// Respect the global module parser `overrideStrict` option
|
|
485
|
+
const overrideStrict =
|
|
486
|
+
options.module.parser &&
|
|
487
|
+
options.module.parser.javascript &&
|
|
488
|
+
options.module.parser.javascript.overrideStrict;
|
|
489
|
+
|
|
467
490
|
this.buildInfo = {
|
|
491
|
+
strict: overrideStrict ? overrideStrict === "strict" : undefined,
|
|
468
492
|
snapshot: undefined
|
|
469
493
|
};
|
|
494
|
+
|
|
470
495
|
this.dependencies.length = 0;
|
|
471
496
|
this.blocks.length = 0;
|
|
472
497
|
const startTime = Date.now();
|
|
@@ -709,11 +734,13 @@ class ContextModule extends Module {
|
|
|
709
734
|
|
|
710
735
|
/**
|
|
711
736
|
* @param {FakeMap | FakeMapType} fakeMap fake map
|
|
737
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
|
712
738
|
* @returns {string} fake map init statement
|
|
713
739
|
*/
|
|
714
|
-
getFakeMapInitStatement(fakeMap) {
|
|
740
|
+
getFakeMapInitStatement(fakeMap, runtimeTemplate) {
|
|
741
|
+
const decl = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
|
|
715
742
|
return typeof fakeMap === "object"
|
|
716
|
-
?
|
|
743
|
+
? `${decl} fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
|
|
717
744
|
: "";
|
|
718
745
|
}
|
|
719
746
|
|
|
@@ -751,11 +778,13 @@ class ContextModule extends Module {
|
|
|
751
778
|
|
|
752
779
|
/**
|
|
753
780
|
* @param {false | UserRequestsMap} asyncDepsMap fake map
|
|
781
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
|
754
782
|
* @returns {string} async deps map init statement
|
|
755
783
|
*/
|
|
756
|
-
getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap) {
|
|
784
|
+
getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap, runtimeTemplate) {
|
|
785
|
+
const decl = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
|
|
757
786
|
return typeof asyncDepsMap === "object"
|
|
758
|
-
?
|
|
787
|
+
? `${decl} asyncDepsMap = ${JSON.stringify(asyncDepsMap, null, "\t")};`
|
|
759
788
|
: "";
|
|
760
789
|
}
|
|
761
790
|
|
|
@@ -805,23 +834,25 @@ class ContextModule extends Module {
|
|
|
805
834
|
* @param {Dependency[]} dependencies dependencies
|
|
806
835
|
* @param {ModuleId} id module id
|
|
807
836
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
837
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
|
808
838
|
* @returns {string} source code
|
|
809
839
|
*/
|
|
810
|
-
getSyncSource(dependencies, id, chunkGraph) {
|
|
840
|
+
getSyncSource(dependencies, id, chunkGraph, runtimeTemplate) {
|
|
811
841
|
const map = this.getUserRequestMap(dependencies, chunkGraph);
|
|
812
842
|
const fakeMap = this.getFakeMap(dependencies, chunkGraph);
|
|
813
843
|
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
|
844
|
+
const cst = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
|
|
814
845
|
|
|
815
|
-
return
|
|
816
|
-
${this.getFakeMapInitStatement(fakeMap)}
|
|
846
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
847
|
+
${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
|
|
817
848
|
|
|
818
849
|
function webpackContext(req) {
|
|
819
|
-
|
|
850
|
+
${cst} id = webpackContextResolve(req);
|
|
820
851
|
return ${returnModuleObject};
|
|
821
852
|
}
|
|
822
853
|
function webpackContextResolve(req) {
|
|
823
854
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
824
|
-
|
|
855
|
+
${cst} e = new Error("Cannot find module '" + req + "'");
|
|
825
856
|
e.code = 'MODULE_NOT_FOUND';
|
|
826
857
|
throw e;
|
|
827
858
|
}
|
|
@@ -839,20 +870,22 @@ webpackContext.id = ${JSON.stringify(id)};`;
|
|
|
839
870
|
* @param {Dependency[]} dependencies dependencies
|
|
840
871
|
* @param {ModuleId} id module id
|
|
841
872
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
873
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
|
842
874
|
* @returns {string} source code
|
|
843
875
|
*/
|
|
844
|
-
getWeakSyncSource(dependencies, id, chunkGraph) {
|
|
876
|
+
getWeakSyncSource(dependencies, id, chunkGraph, runtimeTemplate) {
|
|
845
877
|
const map = this.getUserRequestMap(dependencies, chunkGraph);
|
|
846
878
|
const fakeMap = this.getFakeMap(dependencies, chunkGraph);
|
|
847
879
|
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
|
880
|
+
const cst = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
|
|
848
881
|
|
|
849
|
-
return
|
|
850
|
-
${this.getFakeMapInitStatement(fakeMap)}
|
|
882
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
883
|
+
${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
|
|
851
884
|
|
|
852
885
|
function webpackContext(req) {
|
|
853
|
-
|
|
886
|
+
${cst} id = webpackContextResolve(req);
|
|
854
887
|
if(!${RuntimeGlobals.moduleFactories}[id]) {
|
|
855
|
-
|
|
888
|
+
${cst} e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
|
|
856
889
|
e.code = 'MODULE_NOT_FOUND';
|
|
857
890
|
throw e;
|
|
858
891
|
}
|
|
@@ -860,7 +893,7 @@ function webpackContext(req) {
|
|
|
860
893
|
}
|
|
861
894
|
function webpackContextResolve(req) {
|
|
862
895
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
863
|
-
|
|
896
|
+
${cst} e = new Error("Cannot find module '" + req + "'");
|
|
864
897
|
e.code = 'MODULE_NOT_FOUND';
|
|
865
898
|
throw e;
|
|
866
899
|
}
|
|
@@ -894,10 +927,11 @@ module.exports = webpackContext;`;
|
|
|
894
927
|
true,
|
|
895
928
|
asyncDepsMap ? "asyncDepsMap[id]" : undefined
|
|
896
929
|
);
|
|
930
|
+
const cst = runtimeTemplate.renderConst();
|
|
897
931
|
|
|
898
|
-
return
|
|
899
|
-
${this.getFakeMapInitStatement(fakeMap)}
|
|
900
|
-
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap)}
|
|
932
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
933
|
+
${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
|
|
934
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap, runtimeTemplate)}
|
|
901
935
|
|
|
902
936
|
function webpackAsyncContext(req) {
|
|
903
937
|
return webpackAsyncContextResolve(req).then(${runtimeTemplate.basicFunction(
|
|
@@ -905,7 +939,7 @@ function webpackAsyncContext(req) {
|
|
|
905
939
|
[
|
|
906
940
|
`if(!${RuntimeGlobals.moduleFactories}[id]) {`,
|
|
907
941
|
Template.indent([
|
|
908
|
-
|
|
942
|
+
`${cst} e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");`,
|
|
909
943
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
910
944
|
"throw e;"
|
|
911
945
|
]),
|
|
@@ -920,7 +954,7 @@ function webpackAsyncContextResolve(req) {
|
|
|
920
954
|
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
921
955
|
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
922
956
|
Template.indent([
|
|
923
|
-
|
|
957
|
+
`${cst} e = new Error("Cannot find module '" + req + "'");`,
|
|
924
958
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
925
959
|
"throw e;"
|
|
926
960
|
]),
|
|
@@ -960,9 +994,10 @@ module.exports = webpackAsyncContext;`;
|
|
|
960
994
|
"id"
|
|
961
995
|
);
|
|
962
996
|
|
|
963
|
-
|
|
964
|
-
${
|
|
965
|
-
${this.
|
|
997
|
+
const cst = runtimeTemplate.renderConst();
|
|
998
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
999
|
+
${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
|
|
1000
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap, runtimeTemplate)}
|
|
966
1001
|
|
|
967
1002
|
function webpackAsyncContext(req) {
|
|
968
1003
|
return webpackAsyncContextResolve(req).then(${thenFunction});
|
|
@@ -973,7 +1008,7 @@ function webpackAsyncContextResolve(req) {
|
|
|
973
1008
|
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
974
1009
|
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
975
1010
|
Template.indent([
|
|
976
|
-
|
|
1011
|
+
`${cst} e = new Error("Cannot find module '" + req + "'");`,
|
|
977
1012
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
978
1013
|
"throw e;"
|
|
979
1014
|
]),
|
|
@@ -1027,9 +1062,10 @@ module.exports = webpackAsyncContext;`;
|
|
|
1027
1062
|
"id"
|
|
1028
1063
|
);
|
|
1029
1064
|
|
|
1030
|
-
|
|
1031
|
-
${
|
|
1032
|
-
${this.
|
|
1065
|
+
const cst = runtimeTemplate.renderConst();
|
|
1066
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
1067
|
+
${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
|
|
1068
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap, runtimeTemplate)}
|
|
1033
1069
|
|
|
1034
1070
|
function webpackAsyncContext(req) {
|
|
1035
1071
|
return webpackAsyncContextResolve(req).then(${thenFunction});
|
|
@@ -1038,7 +1074,7 @@ function webpackAsyncContextResolve(req) {
|
|
|
1038
1074
|
return ${promise}.then(${runtimeTemplate.basicFunction("", [
|
|
1039
1075
|
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
1040
1076
|
Template.indent([
|
|
1041
|
-
|
|
1077
|
+
`${cst} e = new Error("Cannot find module '" + req + "'");`,
|
|
1042
1078
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
1043
1079
|
"throw e;"
|
|
1044
1080
|
]),
|
|
@@ -1161,6 +1197,7 @@ module.exports = webpackAsyncContext;`;
|
|
|
1161
1197
|
shortMode ? "invalid" : "ids[1]"
|
|
1162
1198
|
);
|
|
1163
1199
|
|
|
1200
|
+
const cst = runtimeTemplate.renderConst();
|
|
1164
1201
|
const webpackAsyncContext =
|
|
1165
1202
|
requestPrefix === "Promise.resolve()"
|
|
1166
1203
|
? `
|
|
@@ -1168,12 +1205,12 @@ function webpackAsyncContext(req) {
|
|
|
1168
1205
|
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1169
1206
|
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
1170
1207
|
Template.indent([
|
|
1171
|
-
|
|
1208
|
+
`${cst} e = new Error("Cannot find module '" + req + "'");`,
|
|
1172
1209
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
1173
1210
|
"throw e;"
|
|
1174
1211
|
]),
|
|
1175
1212
|
"}",
|
|
1176
|
-
shortMode ?
|
|
1213
|
+
shortMode ? `${cst} id = map[req];` : `${cst} ids = map[req], id = ids[0];`,
|
|
1177
1214
|
`return ${returnModuleObject};`
|
|
1178
1215
|
])});
|
|
1179
1216
|
}`
|
|
@@ -1181,7 +1218,7 @@ function webpackAsyncContext(req) {
|
|
|
1181
1218
|
try {
|
|
1182
1219
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
1183
1220
|
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1184
|
-
|
|
1221
|
+
`${cst} e = new Error("Cannot find module '" + req + "'");`,
|
|
1185
1222
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
1186
1223
|
"throw e;"
|
|
1187
1224
|
])});
|
|
@@ -1190,11 +1227,11 @@ function webpackAsyncContext(req) {
|
|
|
1190
1227
|
return Promise.reject(err);
|
|
1191
1228
|
}
|
|
1192
1229
|
|
|
1193
|
-
|
|
1230
|
+
${cst} ids = map[req], id = ids[0];
|
|
1194
1231
|
return ${requestPrefix}.then(${runtimeTemplate.returningFunction(returnModuleObject)});
|
|
1195
1232
|
}`;
|
|
1196
1233
|
|
|
1197
|
-
return
|
|
1234
|
+
return `${cst} map = ${JSON.stringify(map, null, "\t")};
|
|
1198
1235
|
${webpackAsyncContext}
|
|
1199
1236
|
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
|
|
1200
1237
|
"Object.keys(map)"
|
|
@@ -1210,7 +1247,7 @@ module.exports = webpackAsyncContext;`;
|
|
|
1210
1247
|
*/
|
|
1211
1248
|
getSourceForEmptyContext(id, runtimeTemplate) {
|
|
1212
1249
|
return `function webpackEmptyContext(req) {
|
|
1213
|
-
|
|
1250
|
+
${runtimeTemplate.renderConst()} e = new Error("Cannot find module '" + req + "'");
|
|
1214
1251
|
e.code = 'MODULE_NOT_FOUND';
|
|
1215
1252
|
throw e;
|
|
1216
1253
|
}
|
|
@@ -1230,7 +1267,7 @@ module.exports = webpackEmptyContext;`;
|
|
|
1230
1267
|
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
|
1231
1268
|
// uncaught exception popping up in devtools
|
|
1232
1269
|
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1233
|
-
|
|
1270
|
+
`${runtimeTemplate.renderConst()} e = new Error("Cannot find module '" + req + "'");`,
|
|
1234
1271
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
1235
1272
|
"throw e;"
|
|
1236
1273
|
])});
|
|
@@ -1291,10 +1328,20 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1291
1328
|
this.dependencies &&
|
|
1292
1329
|
this.dependencies.length > 0
|
|
1293
1330
|
) {
|
|
1294
|
-
return this.getWeakSyncSource(
|
|
1331
|
+
return this.getWeakSyncSource(
|
|
1332
|
+
this.dependencies,
|
|
1333
|
+
id,
|
|
1334
|
+
chunkGraph,
|
|
1335
|
+
runtimeTemplate
|
|
1336
|
+
);
|
|
1295
1337
|
}
|
|
1296
1338
|
if (this.dependencies && this.dependencies.length > 0) {
|
|
1297
|
-
return this.getSyncSource(
|
|
1339
|
+
return this.getSyncSource(
|
|
1340
|
+
this.dependencies,
|
|
1341
|
+
id,
|
|
1342
|
+
chunkGraph,
|
|
1343
|
+
runtimeTemplate
|
|
1344
|
+
);
|
|
1298
1345
|
}
|
|
1299
1346
|
return this.getSourceForEmptyContext(id, runtimeTemplate);
|
|
1300
1347
|
}
|
|
@@ -1400,9 +1447,7 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1400
1447
|
* @param {ObjectSerializerContext} context context
|
|
1401
1448
|
*/
|
|
1402
1449
|
serialize(context) {
|
|
1403
|
-
|
|
1404
|
-
write(this._identifier);
|
|
1405
|
-
write(this._forceBuild);
|
|
1450
|
+
context.write(this._identifier).write(this._forceBuild);
|
|
1406
1451
|
super.serialize(context);
|
|
1407
1452
|
}
|
|
1408
1453
|
|
|
@@ -1411,10 +1456,10 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1411
1456
|
* @param {ObjectDeserializerContext} context context
|
|
1412
1457
|
*/
|
|
1413
1458
|
deserialize(context) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
this._forceBuild = read();
|
|
1417
|
-
super.deserialize(
|
|
1459
|
+
this._identifier = context.read();
|
|
1460
|
+
const c1 = context.rest;
|
|
1461
|
+
this._forceBuild = c1.read();
|
|
1462
|
+
super.deserialize(c1.rest);
|
|
1418
1463
|
}
|
|
1419
1464
|
}
|
|
1420
1465
|
|
|
@@ -32,6 +32,7 @@ class ContextReplacementPlugin {
|
|
|
32
32
|
newContentRecursive,
|
|
33
33
|
newContentRegExp
|
|
34
34
|
) {
|
|
35
|
+
/** @type {RegExp} */
|
|
35
36
|
this.resourceRegExp = resourceRegExp;
|
|
36
37
|
|
|
37
38
|
// new webpack.ContextReplacementPlugin(/selector/, (context) => { /* Logic */ });
|
|
@@ -43,6 +44,7 @@ class ContextReplacementPlugin {
|
|
|
43
44
|
typeof newContentResource === "string" &&
|
|
44
45
|
typeof newContentRecursive === "object"
|
|
45
46
|
) {
|
|
47
|
+
/** @type {string | undefined} */
|
|
46
48
|
this.newContentResource = newContentResource;
|
|
47
49
|
/**
|
|
48
50
|
* Stores new content create context map.
|
|
@@ -79,9 +81,11 @@ class ContextReplacementPlugin {
|
|
|
79
81
|
this.newContentResource =
|
|
80
82
|
/** @type {string | undefined} */
|
|
81
83
|
(newContentResource);
|
|
84
|
+
/** @type {boolean | undefined} */
|
|
82
85
|
this.newContentRecursive =
|
|
83
86
|
/** @type {boolean | undefined} */
|
|
84
87
|
(newContentRecursive);
|
|
88
|
+
/** @type {RegExp | undefined} */
|
|
85
89
|
this.newContentRegExp =
|
|
86
90
|
/** @type {RegExp | undefined} */
|
|
87
91
|
(newContentRegExp);
|