webpack 5.99.9 → 5.100.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/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +11 -4
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +34 -20
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RawModule.js +14 -0
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +3 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +17 -9
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +6 -3
- package/lib/stats/StatsPrinter.js +6 -7
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +95 -58
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1243 -409
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
const InitFragment = require("./InitFragment");
|
|
9
9
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
10
10
|
const Template = require("./Template");
|
|
11
|
+
const {
|
|
12
|
+
getMakeDeferredNamespaceModeFromExportsType,
|
|
13
|
+
getOptimizedDeferredModule
|
|
14
|
+
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
11
15
|
const { equals } = require("./util/ArrayHelpers");
|
|
12
16
|
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
13
17
|
const propertyAccess = require("./util/propertyAccess");
|
|
@@ -51,9 +55,7 @@ Module has these incoming connections: ${Array.from(
|
|
|
51
55
|
`\n - ${
|
|
52
56
|
connection.originModule && connection.originModule.identifier()
|
|
53
57
|
} ${connection.dependency && connection.dependency.type} ${
|
|
54
|
-
(connection.explanations &&
|
|
55
|
-
Array.from(connection.explanations).join(", ")) ||
|
|
56
|
-
""
|
|
58
|
+
(connection.explanations && [...connection.explanations].join(", ")) || ""
|
|
57
59
|
}`
|
|
58
60
|
).join("")}`;
|
|
59
61
|
|
|
@@ -72,8 +74,9 @@ function getGlobalObject(definition) {
|
|
|
72
74
|
// call expression
|
|
73
75
|
// expression in parentheses
|
|
74
76
|
/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
|
|
75
|
-
)
|
|
77
|
+
) {
|
|
76
78
|
return trimmed;
|
|
79
|
+
}
|
|
77
80
|
|
|
78
81
|
return `Object(${trimmed})`;
|
|
79
82
|
}
|
|
@@ -216,8 +219,9 @@ class RuntimeTemplate {
|
|
|
216
219
|
lastWasExpr = isExpr;
|
|
217
220
|
}
|
|
218
221
|
if (lastWasExpr) concatenationCost -= 3;
|
|
219
|
-
if (typeof args[0] !== "string" && typeof args[1] === "string")
|
|
222
|
+
if (typeof args[0] !== "string" && typeof args[1] === "string") {
|
|
220
223
|
concatenationCost -= 3;
|
|
224
|
+
}
|
|
221
225
|
|
|
222
226
|
if (concatenationCost <= templateCost) return this._es5Concatenation(args);
|
|
223
227
|
|
|
@@ -770,8 +774,8 @@ class RuntimeTemplate {
|
|
|
770
774
|
);
|
|
771
775
|
runtimeRequirements.add(RuntimeGlobals.runtimeId);
|
|
772
776
|
return compileBooleanMatcher.fromLists(
|
|
773
|
-
|
|
774
|
-
|
|
777
|
+
[...positiveRuntimeIds],
|
|
778
|
+
[...negativeRuntimeIds]
|
|
775
779
|
)(RuntimeGlobals.runtimeId);
|
|
776
780
|
}
|
|
777
781
|
|
|
@@ -779,22 +783,26 @@ class RuntimeTemplate {
|
|
|
779
783
|
* @param {object} options options object
|
|
780
784
|
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
|
781
785
|
* @param {Module} options.module the module
|
|
786
|
+
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
782
787
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
783
788
|
* @param {string} options.request the request that should be printed as comment
|
|
784
789
|
* @param {string} options.importVar name of the import variable
|
|
785
790
|
* @param {Module} options.originModule module in which the statement is emitted
|
|
786
791
|
* @param {boolean=} options.weak true, if this is a weak dependency
|
|
787
792
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
793
|
+
* @param {boolean=} options.defer if set, the module will be deferred
|
|
788
794
|
* @returns {[string, string]} the import statement and the compat statement
|
|
789
795
|
*/
|
|
790
796
|
importStatement({
|
|
791
797
|
update,
|
|
792
798
|
module,
|
|
799
|
+
moduleGraph,
|
|
793
800
|
chunkGraph,
|
|
794
801
|
request,
|
|
795
802
|
importVar,
|
|
796
803
|
originModule,
|
|
797
804
|
weak,
|
|
805
|
+
defer,
|
|
798
806
|
runtimeRequirements
|
|
799
807
|
}) {
|
|
800
808
|
if (!module) {
|
|
@@ -805,6 +813,29 @@ class RuntimeTemplate {
|
|
|
805
813
|
""
|
|
806
814
|
];
|
|
807
815
|
}
|
|
816
|
+
|
|
817
|
+
/** @type {Set<Module>} */
|
|
818
|
+
const innerAsyncDependencies = new Set();
|
|
819
|
+
defer = defer && (module.buildMeta ? !module.buildMeta.async : true);
|
|
820
|
+
|
|
821
|
+
if (this.compilation.options.experiments.deferImport && defer) {
|
|
822
|
+
const seen = new Set();
|
|
823
|
+
(function gatherInnerAsyncDependencies(mod) {
|
|
824
|
+
if (!moduleGraph.isAsync(mod) || seen.has(mod)) return;
|
|
825
|
+
seen.add(mod);
|
|
826
|
+
if (mod.buildMeta && mod.buildMeta.async) {
|
|
827
|
+
innerAsyncDependencies.add(mod);
|
|
828
|
+
} else {
|
|
829
|
+
for (const dep of mod.dependencies) {
|
|
830
|
+
const module = moduleGraph.getModule(dep);
|
|
831
|
+
if (module) {
|
|
832
|
+
gatherInnerAsyncDependencies(module);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
})(module);
|
|
837
|
+
}
|
|
838
|
+
|
|
808
839
|
if (chunkGraph.getModuleId(module) === null) {
|
|
809
840
|
if (weak) {
|
|
810
841
|
// only weak referenced modules don't get an id
|
|
@@ -840,9 +871,19 @@ class RuntimeTemplate {
|
|
|
840
871
|
(originModule.buildMeta).strictHarmonyModule
|
|
841
872
|
);
|
|
842
873
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
843
|
-
|
|
874
|
+
let importContent;
|
|
875
|
+
if (defer) {
|
|
876
|
+
importContent = `/* deferred harmony import */ ${optDeclaration}${importVar} = ${getOptimizedDeferredModule(
|
|
877
|
+
this,
|
|
878
|
+
exportsType,
|
|
879
|
+
moduleId,
|
|
880
|
+
Array.from(innerAsyncDependencies, mod => chunkGraph.getModuleId(mod))
|
|
881
|
+
)};\n`;
|
|
882
|
+
} else {
|
|
883
|
+
importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`;
|
|
884
|
+
}
|
|
844
885
|
|
|
845
|
-
if (exportsType === "dynamic") {
|
|
886
|
+
if (exportsType === "dynamic" && !defer) {
|
|
846
887
|
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
|
847
888
|
return [
|
|
848
889
|
importContent,
|
|
@@ -856,6 +897,7 @@ class RuntimeTemplate {
|
|
|
856
897
|
* @template GenerateContext
|
|
857
898
|
* @param {object} options options
|
|
858
899
|
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
900
|
+
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
859
901
|
* @param {Module} options.module the module
|
|
860
902
|
* @param {string} options.request the request
|
|
861
903
|
* @param {string | string[]} options.exportName the export name
|
|
@@ -868,10 +910,12 @@ class RuntimeTemplate {
|
|
|
868
910
|
* @param {InitFragment<GenerateContext>[]} options.initFragments init fragments will be added here
|
|
869
911
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
|
870
912
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
913
|
+
* @param {boolean=} options.defer if true, the module will be deferred.
|
|
871
914
|
* @returns {string} expression
|
|
872
915
|
*/
|
|
873
916
|
exportFromImport({
|
|
874
917
|
moduleGraph,
|
|
918
|
+
chunkGraph,
|
|
875
919
|
module,
|
|
876
920
|
request,
|
|
877
921
|
exportName,
|
|
@@ -883,13 +927,16 @@ class RuntimeTemplate {
|
|
|
883
927
|
importVar,
|
|
884
928
|
initFragments,
|
|
885
929
|
runtime,
|
|
886
|
-
runtimeRequirements
|
|
930
|
+
runtimeRequirements,
|
|
931
|
+
defer
|
|
887
932
|
}) {
|
|
888
933
|
if (!module) {
|
|
889
934
|
return this.missingModule({
|
|
890
935
|
request
|
|
891
936
|
});
|
|
892
937
|
}
|
|
938
|
+
|
|
939
|
+
defer = defer && (module.buildMeta ? !module.buildMeta.async : true);
|
|
893
940
|
if (!Array.isArray(exportName)) {
|
|
894
941
|
exportName = exportName ? [exportName] : [];
|
|
895
942
|
}
|
|
@@ -900,7 +947,21 @@ class RuntimeTemplate {
|
|
|
900
947
|
);
|
|
901
948
|
|
|
902
949
|
if (defaultInterop) {
|
|
950
|
+
// when the defaultInterop is used (when a ESM imports a CJS module),
|
|
903
951
|
if (exportName.length > 0 && exportName[0] === "default") {
|
|
952
|
+
if (defer && exportsType !== "namespace") {
|
|
953
|
+
const access = `${importVar}.a${propertyAccess(exportName, 1)}`;
|
|
954
|
+
if (isCall || asiSafe === undefined) {
|
|
955
|
+
return access;
|
|
956
|
+
}
|
|
957
|
+
return asiSafe ? `(${access})` : `;(${access})`;
|
|
958
|
+
}
|
|
959
|
+
// accessing the .default property is same thing as `require()` the module.
|
|
960
|
+
|
|
961
|
+
// For example:
|
|
962
|
+
// import mod from "cjs"; mod.default.x;
|
|
963
|
+
// is translated to
|
|
964
|
+
// var mod = require("cjs"); mod.x;
|
|
904
965
|
switch (exportsType) {
|
|
905
966
|
case "dynamic":
|
|
906
967
|
if (isCall) {
|
|
@@ -918,7 +979,11 @@ class RuntimeTemplate {
|
|
|
918
979
|
break;
|
|
919
980
|
}
|
|
920
981
|
} else if (exportName.length > 0) {
|
|
982
|
+
// the property used is not .default.
|
|
983
|
+
// For example:
|
|
984
|
+
// import * as ns from "cjs"; cjs.prop;
|
|
921
985
|
if (exportsType === "default-only") {
|
|
986
|
+
// in the strictest case, it is a runtime error (e.g. NodeJS behavior of CJS-ESM interop).
|
|
922
987
|
return `/* non-default import from non-esm module */undefined${propertyAccess(
|
|
923
988
|
exportName,
|
|
924
989
|
1
|
|
@@ -929,10 +994,17 @@ class RuntimeTemplate {
|
|
|
929
994
|
) {
|
|
930
995
|
return "/* __esModule */true";
|
|
931
996
|
}
|
|
997
|
+
} else if (defer) {
|
|
998
|
+
// now exportName.length is 0
|
|
999
|
+
// fall through to the end of this function, create the namespace there.
|
|
932
1000
|
} else if (
|
|
933
1001
|
exportsType === "default-only" ||
|
|
934
1002
|
exportsType === "default-with-named"
|
|
935
1003
|
) {
|
|
1004
|
+
// now exportName.length is 0, which means the namespace object is used in an unknown way
|
|
1005
|
+
// for example:
|
|
1006
|
+
// import * as ns from "cjs"; console.log(ns);
|
|
1007
|
+
// we will need to createFakeNamespaceObject that simulates ES Module namespace object
|
|
936
1008
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
937
1009
|
initFragments.push(
|
|
938
1010
|
new InitFragment(
|
|
@@ -952,6 +1024,8 @@ class RuntimeTemplate {
|
|
|
952
1024
|
|
|
953
1025
|
if (exportName.length > 0) {
|
|
954
1026
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
1027
|
+
// in some case the exported item is renamed (get this by getUsedName). for example,
|
|
1028
|
+
// x.default might be emitted as x.Z (default is renamed to Z)
|
|
955
1029
|
const used = exportsInfo.getUsedName(exportName, runtime);
|
|
956
1030
|
if (!used) {
|
|
957
1031
|
const comment = Template.toNormalComment(
|
|
@@ -962,7 +1036,9 @@ class RuntimeTemplate {
|
|
|
962
1036
|
const comment = equals(used, exportName)
|
|
963
1037
|
? ""
|
|
964
1038
|
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
|
965
|
-
const access = `${importVar}${
|
|
1039
|
+
const access = `${importVar}${
|
|
1040
|
+
defer ? ".a" : ""
|
|
1041
|
+
}${comment}${propertyAccess(used)}`;
|
|
966
1042
|
if (isCall && callContext === false) {
|
|
967
1043
|
return asiSafe
|
|
968
1044
|
? `(0,${access})`
|
|
@@ -972,6 +1048,30 @@ class RuntimeTemplate {
|
|
|
972
1048
|
}
|
|
973
1049
|
return access;
|
|
974
1050
|
}
|
|
1051
|
+
if (defer) {
|
|
1052
|
+
initFragments.push(
|
|
1053
|
+
new InitFragment(
|
|
1054
|
+
`var ${importVar}_deferred_namespace_cache;\n`,
|
|
1055
|
+
InitFragment.STAGE_CONSTANTS,
|
|
1056
|
+
-1,
|
|
1057
|
+
`${importVar}_deferred_namespace_cache`
|
|
1058
|
+
)
|
|
1059
|
+
);
|
|
1060
|
+
|
|
1061
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1062
|
+
const id = chunkGraph.getModuleId(module);
|
|
1063
|
+
const type = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
1064
|
+
const init = `${
|
|
1065
|
+
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1066
|
+
}(${JSON.stringify(id)}, ${type})`;
|
|
1067
|
+
|
|
1068
|
+
return `/*#__PURE__*/ ${
|
|
1069
|
+
asiSafe ? "" : asiSafe === false ? ";" : "Object"
|
|
1070
|
+
}(${importVar}_deferred_namespace_cache || (${importVar}_deferred_namespace_cache = ${init}))`;
|
|
1071
|
+
}
|
|
1072
|
+
// if we hit here, the importVar is either
|
|
1073
|
+
// - already a ES module namespace object
|
|
1074
|
+
// - or imported by a way that does not need interop.
|
|
975
1075
|
return importVar;
|
|
976
1076
|
}
|
|
977
1077
|
|
|
@@ -10,6 +10,8 @@ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|
|
10
10
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
|
11
11
|
/** @typedef {import("./Compilation")} Compilation */
|
|
12
12
|
|
|
13
|
+
const PLUGIN_NAME = "SourceMapDevToolModuleOptionsPlugin";
|
|
14
|
+
|
|
13
15
|
class SourceMapDevToolModuleOptionsPlugin {
|
|
14
16
|
/**
|
|
15
17
|
* @param {SourceMapDevToolPluginOptions} options options
|
|
@@ -25,34 +27,22 @@ class SourceMapDevToolModuleOptionsPlugin {
|
|
|
25
27
|
apply(compilation) {
|
|
26
28
|
const options = this.options;
|
|
27
29
|
if (options.module !== false) {
|
|
28
|
-
compilation.hooks.buildModule.tap(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
compilation.hooks.runtimeModule.tap(
|
|
35
|
-
"SourceMapDevToolModuleOptionsPlugin",
|
|
36
|
-
module => {
|
|
37
|
-
module.useSourceMap = true;
|
|
38
|
-
}
|
|
39
|
-
);
|
|
30
|
+
compilation.hooks.buildModule.tap(PLUGIN_NAME, module => {
|
|
31
|
+
module.useSourceMap = true;
|
|
32
|
+
});
|
|
33
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, module => {
|
|
34
|
+
module.useSourceMap = true;
|
|
35
|
+
});
|
|
40
36
|
} else {
|
|
41
|
-
compilation.hooks.buildModule.tap(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
compilation.hooks.runtimeModule.tap(
|
|
48
|
-
"SourceMapDevToolModuleOptionsPlugin",
|
|
49
|
-
module => {
|
|
50
|
-
module.useSimpleSourceMap = true;
|
|
51
|
-
}
|
|
52
|
-
);
|
|
37
|
+
compilation.hooks.buildModule.tap(PLUGIN_NAME, module => {
|
|
38
|
+
module.useSimpleSourceMap = true;
|
|
39
|
+
});
|
|
40
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, module => {
|
|
41
|
+
module.useSimpleSourceMap = true;
|
|
42
|
+
});
|
|
53
43
|
}
|
|
54
44
|
JavascriptModulesPlugin.getCompilationHooks(compilation).useSourceMap.tap(
|
|
55
|
-
|
|
45
|
+
PLUGIN_NAME,
|
|
56
46
|
() => true
|
|
57
47
|
);
|
|
58
48
|
}
|
|
@@ -13,7 +13,7 @@ const ProgressPlugin = require("./ProgressPlugin");
|
|
|
13
13
|
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
|
14
14
|
const createSchemaValidation = require("./util/create-schema-validation");
|
|
15
15
|
const createHash = require("./util/createHash");
|
|
16
|
-
const {
|
|
16
|
+
const { dirname, relative } = require("./util/fs");
|
|
17
17
|
const generateDebugId = require("./util/generateDebugId");
|
|
18
18
|
const { makePathsAbsolute } = require("./util/identifier");
|
|
19
19
|
|
|
@@ -28,12 +28,12 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
|
28
28
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
|
29
29
|
/** @typedef {import("./Compiler")} Compiler */
|
|
30
30
|
/** @typedef {import("./Module")} Module */
|
|
31
|
-
/** @typedef {import("./NormalModule").
|
|
31
|
+
/** @typedef {import("./NormalModule").RawSourceMap} RawSourceMap */
|
|
32
32
|
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
33
33
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
|
34
34
|
|
|
35
35
|
const validate = createSchemaValidation(
|
|
36
|
-
require("../schemas/plugins/SourceMapDevToolPlugin.check
|
|
36
|
+
require("../schemas/plugins/SourceMapDevToolPlugin.check"),
|
|
37
37
|
() => require("../schemas/plugins/SourceMapDevToolPlugin.json"),
|
|
38
38
|
{
|
|
39
39
|
name: "SourceMap DevTool Plugin",
|
|
@@ -47,7 +47,7 @@ const validate = createSchemaValidation(
|
|
|
47
47
|
* @property {(string | Module)[]} modules
|
|
48
48
|
* @property {string} source
|
|
49
49
|
* @property {string} file
|
|
50
|
-
* @property {
|
|
50
|
+
* @property {RawSourceMap} sourceMap
|
|
51
51
|
* @property {ItemCacheFacade} cacheItem cache item
|
|
52
52
|
*/
|
|
53
53
|
|
|
@@ -95,17 +95,17 @@ const getTaskForFile = (
|
|
|
95
95
|
cacheItem
|
|
96
96
|
) => {
|
|
97
97
|
let source;
|
|
98
|
-
/** @type {
|
|
98
|
+
/** @type {RawSourceMap} */
|
|
99
99
|
let sourceMap;
|
|
100
100
|
/**
|
|
101
101
|
* Check if asset can build source map
|
|
102
102
|
*/
|
|
103
103
|
if (asset.sourceAndMap) {
|
|
104
104
|
const sourceAndMap = asset.sourceAndMap(options);
|
|
105
|
-
sourceMap = /** @type {
|
|
105
|
+
sourceMap = /** @type {RawSourceMap} */ (sourceAndMap.map);
|
|
106
106
|
source = sourceAndMap.source;
|
|
107
107
|
} else {
|
|
108
|
-
sourceMap = /** @type {
|
|
108
|
+
sourceMap = /** @type {RawSourceMap} */ (asset.map(options));
|
|
109
109
|
source = asset.source();
|
|
110
110
|
}
|
|
111
111
|
if (!sourceMap || typeof source !== "string") return;
|
|
@@ -270,8 +270,9 @@ class SourceMapDevToolPlugin {
|
|
|
270
270
|
/**
|
|
271
271
|
* Add file to chunk, if not presented there
|
|
272
272
|
*/
|
|
273
|
-
if (cachedFile !== file && chunk !== undefined)
|
|
273
|
+
if (cachedFile !== file && chunk !== undefined) {
|
|
274
274
|
chunk.auxiliaryFiles.add(cachedFile);
|
|
275
|
+
}
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
reportProgress(
|
|
@@ -362,13 +363,13 @@ class SourceMapDevToolPlugin {
|
|
|
362
363
|
* all modules in defined order (longest identifier first)
|
|
363
364
|
* @type {Array<string | Module>}
|
|
364
365
|
*/
|
|
365
|
-
const allModules =
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
366
|
+
const allModules = [...moduleToSourceNameMapping.keys()].sort(
|
|
367
|
+
(a, b) => {
|
|
368
|
+
const ai = typeof a === "string" ? a : a.identifier();
|
|
369
|
+
const bi = typeof b === "string" ? b : b.identifier();
|
|
370
|
+
return ai.length - bi.length;
|
|
371
|
+
}
|
|
372
|
+
);
|
|
372
373
|
|
|
373
374
|
// find modules with conflicting source names
|
|
374
375
|
for (let idx = 0; idx < allModules.length; idx++) {
|
|
@@ -548,8 +549,9 @@ class SourceMapDevToolPlugin {
|
|
|
548
549
|
sourceMapAsset,
|
|
549
550
|
sourceMapAssetInfo
|
|
550
551
|
);
|
|
551
|
-
if (chunk !== undefined)
|
|
552
|
+
if (chunk !== undefined) {
|
|
552
553
|
chunk.auxiliaryFiles.add(sourceMapFile);
|
|
554
|
+
}
|
|
553
555
|
} else {
|
|
554
556
|
if (currentSourceMappingURLComment === false) {
|
|
555
557
|
throw new Error(
|
|
@@ -573,7 +575,7 @@ class SourceMapDevToolPlugin {
|
|
|
573
575
|
() =>
|
|
574
576
|
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
|
575
577
|
sourceMapString,
|
|
576
|
-
"
|
|
578
|
+
"utf8"
|
|
577
579
|
).toString("base64")}`
|
|
578
580
|
)
|
|
579
581
|
);
|
package/lib/Template.js
CHANGED
|
@@ -410,7 +410,7 @@ class Template {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
module.exports = Template;
|
|
413
|
-
module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
|
|
414
|
-
NUMBER_OF_IDENTIFIER_START_CHARS;
|
|
415
413
|
module.exports.NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
|
|
416
414
|
NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS;
|
|
415
|
+
module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
|
|
416
|
+
NUMBER_OF_IDENTIFIER_START_CHARS;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const mime = require("mime-types");
|
|
9
8
|
const { basename, extname } = require("path");
|
|
10
9
|
const util = require("util");
|
|
10
|
+
const mime = require("mime-types");
|
|
11
11
|
const Chunk = require("./Chunk");
|
|
12
12
|
const Module = require("./Module");
|
|
13
13
|
const { parseResource } = require("./util/identifier");
|
|
@@ -9,6 +9,8 @@ const WebpackError = require("./WebpackError");
|
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("./Compiler")} Compiler */
|
|
11
11
|
|
|
12
|
+
const PLUGIN_NAME = "WarnDeprecatedOptionPlugin";
|
|
13
|
+
|
|
12
14
|
class WarnDeprecatedOptionPlugin {
|
|
13
15
|
/**
|
|
14
16
|
* Create an instance of the plugin
|
|
@@ -28,14 +30,11 @@ class WarnDeprecatedOptionPlugin {
|
|
|
28
30
|
* @returns {void}
|
|
29
31
|
*/
|
|
30
32
|
apply(compiler) {
|
|
31
|
-
compiler.hooks.thisCompilation.tap(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
33
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
34
|
+
compilation.warnings.push(
|
|
35
|
+
new DeprecatedOptionWarning(this.option, this.value, this.suggestion)
|
|
36
|
+
);
|
|
37
|
+
});
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
package/lib/WatchIgnorePlugin.js
CHANGED
|
@@ -15,8 +15,9 @@ const createSchemaValidation = require("./util/create-schema-validation");
|
|
|
15
15
|
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
|
16
16
|
/** @typedef {import("./util/fs").WatchMethod} WatchMethod */
|
|
17
17
|
/** @typedef {import("./util/fs").Watcher} Watcher */
|
|
18
|
+
|
|
18
19
|
const validate = createSchemaValidation(
|
|
19
|
-
require("../schemas/plugins/WatchIgnorePlugin.check
|
|
20
|
+
require("../schemas/plugins/WatchIgnorePlugin.check"),
|
|
20
21
|
() => require("../schemas/plugins/WatchIgnorePlugin.json"),
|
|
21
22
|
{
|
|
22
23
|
name: "Watch Ignore Plugin",
|
|
@@ -38,8 +39,8 @@ class IgnoringWatchFileSystem {
|
|
|
38
39
|
|
|
39
40
|
/** @type {WatchMethod} */
|
|
40
41
|
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
|
41
|
-
files =
|
|
42
|
-
dirs =
|
|
42
|
+
files = [...files];
|
|
43
|
+
dirs = [...dirs];
|
|
43
44
|
/**
|
|
44
45
|
* @param {string} path path to check
|
|
45
46
|
* @returns {boolean} true, if path is ignored
|