webpack 5.92.1 → 5.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/bin/webpack.js +6 -7
- package/hot/log.js +1 -2
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +4 -3
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +12 -6
- package/lib/Cache.js +8 -10
- package/lib/CacheFacade.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +5 -7
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +58 -36
- package/lib/ChunkGroup.js +2 -3
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +10 -11
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/Compilation.js +223 -191
- package/lib/Compiler.js +81 -82
- package/lib/ConcatenationScope.js +3 -6
- package/lib/ConditionalInitFragment.js +6 -7
- package/lib/ConstPlugin.js +7 -15
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +36 -21
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +76 -69
- package/lib/DelegatedModule.js +7 -3
- package/lib/DelegatedModuleFactoryPlugin.js +36 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +0 -1
- package/lib/Dependency.js +10 -14
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllModuleFactory.js +1 -0
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +30 -15
- package/lib/EntryPlugin.js +1 -3
- package/lib/EnvironmentPlugin.js +5 -2
- package/lib/ErrorHelpers.js +11 -12
- package/lib/EvalDevToolModulePlugin.js +10 -12
- package/lib/EvalSourceMapDevToolPlugin.js +15 -13
- package/lib/ExportsInfo.js +185 -120
- package/lib/ExternalModule.js +104 -64
- package/lib/ExternalModuleFactoryPlugin.js +23 -10
- package/lib/FileSystemInfo.js +791 -422
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
- package/lib/FlagDependencyExportsPlugin.js +12 -11
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +2 -5
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +8 -10
- package/lib/HotModuleReplacementPlugin.js +78 -64
- package/lib/IgnoreErrorModuleFactory.js +3 -3
- package/lib/IgnorePlugin.js +1 -3
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +2 -3
- package/lib/LibManifestPlugin.js +4 -3
- package/lib/MainTemplate.js +72 -19
- package/lib/Module.js +25 -9
- package/lib/ModuleBuildError.js +4 -11
- package/lib/ModuleDependencyError.js +5 -5
- package/lib/ModuleDependencyWarning.js +5 -5
- package/lib/ModuleError.js +1 -5
- package/lib/ModuleFilenameHelpers.js +29 -46
- package/lib/ModuleGraph.js +7 -6
- package/lib/ModuleGraphConnection.js +6 -6
- package/lib/ModuleInfoHeaderPlugin.js +82 -30
- package/lib/ModuleParseError.js +8 -9
- package/lib/ModuleRestoreError.js +1 -1
- package/lib/ModuleStoreError.js +1 -1
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +21 -22
- package/lib/ModuleWarning.js +1 -5
- package/lib/MultiCompiler.js +24 -26
- package/lib/MultiStats.js +73 -31
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +132 -70
- package/lib/NormalModuleFactory.js +53 -49
- package/lib/OptimizationStages.js +3 -3
- package/lib/ProgressPlugin.js +9 -9
- package/lib/ProvidePlugin.js +4 -4
- package/lib/RuntimeGlobals.js +71 -70
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +24 -12
- package/lib/RuntimeTemplate.js +40 -44
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolPlugin.js +42 -34
- package/lib/Stats.js +5 -11
- package/lib/Template.js +18 -24
- package/lib/TemplatedPathPlugin.js +12 -10
- package/lib/UseStrictPlugin.js +8 -1
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +89 -62
- package/lib/asset/AssetGenerator.js +107 -42
- package/lib/asset/AssetModulesPlugin.js +29 -23
- package/lib/asset/AssetSourceGenerator.js +2 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
- package/lib/buildChunkGraph.js +14 -19
- package/lib/cache/IdleFileCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +51 -50
- package/lib/cache/ResolverCachePlugin.js +6 -6
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +148 -104
- package/lib/config/browserslistTargetHandler.js +16 -13
- package/lib/config/defaults.js +31 -28
- package/lib/config/normalization.js +335 -344
- package/lib/config/target.js +42 -52
- package/lib/container/ContainerEntryModule.js +2 -2
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +11 -8
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +39 -40
- package/lib/css/CssGenerator.js +11 -14
- package/lib/css/CssLoadingRuntimeModule.js +10 -10
- package/lib/css/CssModulesPlugin.js +127 -47
- package/lib/css/CssParser.js +20 -18
- package/lib/css/walkCssTokens.js +80 -95
- package/lib/debug/ProfilingPlugin.js +19 -20
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
- package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
- package/lib/dependencies/CommonJsExportsDependency.js +0 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
- package/lib/dependencies/ConstDependency.js +1 -1
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +72 -9
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +68 -21
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +4 -5
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/ExportsInfoDependency.js +1 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
- package/lib/dependencies/HarmonyExports.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +41 -16
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +11 -13
- package/lib/dependencies/ImportParserPlugin.js +39 -44
- package/lib/dependencies/JsonExportsDependency.js +22 -18
- package/lib/dependencies/LoaderPlugin.js +47 -36
- package/lib/dependencies/LocalModule.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
- package/lib/dependencies/ProvidedDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +6 -6
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLDependency.js +3 -3
- package/lib/dependencies/URLPlugin.js +66 -12
- package/lib/dependencies/WorkerPlugin.js +25 -24
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +11 -12
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
- package/lib/hmr/LazyCompilationPlugin.js +27 -12
- package/lib/hmr/lazyCompilationBackend.js +64 -40
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -1
- package/lib/ids/IdHelpers.js +29 -39
- package/lib/ids/SyncModuleIdsPlugin.js +7 -2
- package/lib/index.js +1 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +6 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -11
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +97 -70
- package/lib/javascript/JavascriptParser.js +179 -200
- package/lib/javascript/JavascriptParserHelpers.js +20 -21
- package/lib/javascript/StartupHelpers.js +41 -13
- package/lib/json/JsonGenerator.js +7 -13
- package/lib/json/JsonModulesPlugin.js +1 -4
- package/lib/json/JsonParser.js +5 -3
- package/lib/library/AmdLibraryPlugin.js +12 -16
- package/lib/library/AssignLibraryPlugin.js +9 -11
- package/lib/library/EnableLibraryPlugin.js +25 -15
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +144 -0
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +66 -92
- package/lib/logging/Logger.js +32 -4
- package/lib/logging/createConsoleLogger.js +12 -13
- package/lib/logging/runtime.js +7 -8
- package/lib/logging/truncateArgs.js +5 -8
- package/lib/node/NodeWatchFileSystem.js +3 -18
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/nodeConsole.js +22 -22
- package/lib/optimize/AggressiveMergingPlugin.js +2 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
- package/lib/optimize/ConcatenatedModule.js +144 -61
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
- package/lib/optimize/InnerGraph.js +17 -17
- package/lib/optimize/InnerGraphPlugin.js +8 -7
- package/lib/optimize/LimitChunkCountPlugin.js +2 -3
- package/lib/optimize/MangleExportsPlugin.js +1 -0
- package/lib/optimize/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -78
- package/lib/optimize/RealContentHashPlugin.js +7 -10
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
- package/lib/optimize/SplitChunksPlugin.js +34 -30
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/rules/BasicEffectRulePlugin.js +3 -1
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
- package/lib/rules/RuleSetCompiler.js +41 -22
- package/lib/rules/UseEffectRulePlugin.js +36 -32
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
- package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +241 -126
- package/lib/serialization/BinaryMiddleware.js +44 -28
- package/lib/serialization/DateObjectSerializer.js +1 -0
- package/lib/serialization/ErrorObjectSerializer.js +2 -0
- package/lib/serialization/FileMiddleware.js +154 -106
- package/lib/serialization/MapObjectSerializer.js +2 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
- package/lib/serialization/ObjectMiddleware.js +52 -56
- package/lib/serialization/PlainObjectSerializer.js +32 -6
- package/lib/serialization/RegExpObjectSerializer.js +1 -0
- package/lib/serialization/Serializer.js +4 -5
- package/lib/serialization/SerializerMiddleware.js +6 -6
- package/lib/serialization/SetObjectSerializer.js +2 -1
- package/lib/sharing/ConsumeSharedModule.js +19 -14
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +108 -141
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +15 -27
- package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
- package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
- package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
- package/lib/stats/StatsFactory.js +127 -56
- package/lib/stats/StatsPrinter.js +75 -44
- package/lib/util/ArrayHelpers.js +8 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +31 -12
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +1 -0
- package/lib/util/MapHelpers.js +1 -3
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Queue.js +1 -1
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +4 -3
- package/lib/util/StackedCacheMap.js +4 -6
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +0 -5
- package/lib/util/TupleQueue.js +1 -1
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +7 -7
- package/lib/util/WeakTupleMap.js +19 -21
- package/lib/util/binarySearchBounds.js +5 -12
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +21 -19
- package/lib/util/comparators.js +57 -52
- package/lib/util/compileBooleanMatcher.js +3 -6
- package/lib/util/conventions.js +10 -13
- package/lib/util/createHash.js +9 -6
- package/lib/util/deprecation.js +22 -12
- package/lib/util/deterministicGrouping.js +19 -26
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +31 -31
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +7 -7
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +81 -59
- package/lib/util/memoize.js +8 -10
- package/lib/util/mergeScope.js +6 -9
- package/lib/util/nonNumericOnlyHash.js +2 -2
- package/lib/util/numberHash.js +1 -6
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/propertyAccess.js +2 -5
- package/lib/util/propertyName.js +1 -3
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +103 -113
- package/lib/util/semver.js +29 -27
- package/lib/util/serialization.js +16 -1
- package/lib/util/smartGrouping.js +5 -5
- package/lib/util/source.js +1 -1
- package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +17 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/types.d.ts +682 -347
package/lib/RuntimeTemplate.js
CHANGED
@@ -34,27 +34,28 @@ const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
34
34
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
35
35
|
* @returns {string} error message
|
36
36
|
*/
|
37
|
-
const noModuleIdErrorMessage = (
|
38
|
-
|
37
|
+
const noModuleIdErrorMessage = (
|
38
|
+
module,
|
39
|
+
chunkGraph
|
40
|
+
) => `Module ${module.identifier()} has no id assigned.
|
39
41
|
This should not happen.
|
40
42
|
It's in these chunks: ${
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
Array.from(
|
44
|
+
chunkGraph.getModuleChunksIterable(module),
|
45
|
+
c => c.name || c.id || c.debugId
|
46
|
+
).join(", ") || "none"
|
47
|
+
} (If module is in no chunk this indicates a bug in some chunk/module optimization logic)
|
46
48
|
Module has these incoming connections: ${Array.from(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
};
|
49
|
+
chunkGraph.moduleGraph.getIncomingConnections(module),
|
50
|
+
connection =>
|
51
|
+
`\n - ${
|
52
|
+
connection.originModule && connection.originModule.identifier()
|
53
|
+
} ${connection.dependency && connection.dependency.type} ${
|
54
|
+
(connection.explanations &&
|
55
|
+
Array.from(connection.explanations).join(", ")) ||
|
56
|
+
""
|
57
|
+
}`
|
58
|
+
).join("")}`;
|
58
59
|
|
59
60
|
/**
|
60
61
|
* @param {string | undefined} definition global object definition
|
@@ -66,11 +67,11 @@ function getGlobalObject(definition) {
|
|
66
67
|
|
67
68
|
if (
|
68
69
|
// identifier, we do not need real identifier regarding ECMAScript/Unicode
|
69
|
-
|
70
|
+
/^[_\p{L}][_0-9\p{L}]*$/iu.test(trimmed) ||
|
70
71
|
// iife
|
71
72
|
// call expression
|
72
73
|
// expression in parentheses
|
73
|
-
|
74
|
+
/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
|
74
75
|
)
|
75
76
|
return trimmed;
|
76
77
|
|
@@ -335,10 +336,9 @@ class RuntimeTemplate {
|
|
335
336
|
}
|
336
337
|
if (!content) return "";
|
337
338
|
if (this.outputOptions.pathinfo) {
|
338
|
-
return Template.toComment(content)
|
339
|
-
} else {
|
340
|
-
return Template.toNormalComment(content) + " ";
|
339
|
+
return `${Template.toComment(content)} `;
|
341
340
|
}
|
341
|
+
return `${Template.toNormalComment(content)} `;
|
342
342
|
}
|
343
343
|
|
344
344
|
/**
|
@@ -412,11 +412,10 @@ class RuntimeTemplate {
|
|
412
412
|
: JSON.stringify(
|
413
413
|
`Module '${moduleId}' is not available (weak dependency)`
|
414
414
|
);
|
415
|
-
const comment = request ? Template.toNormalComment(request)
|
416
|
-
const errorStatements =
|
417
|
-
|
418
|
-
|
419
|
-
"e.code = 'MODULE_NOT_FOUND'; throw e;";
|
415
|
+
const comment = request ? `${Template.toNormalComment(request)} ` : "";
|
416
|
+
const errorStatements = `var e = new Error(${errorMessage}); ${
|
417
|
+
comment
|
418
|
+
}e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
420
419
|
switch (type) {
|
421
420
|
case "statements":
|
422
421
|
return errorStatements;
|
@@ -778,7 +777,6 @@ class RuntimeTemplate {
|
|
778
777
|
}
|
779
778
|
|
780
779
|
/**
|
781
|
-
*
|
782
780
|
* @param {object} options options object
|
783
781
|
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
784
782
|
* @param {Module} options.module the module
|
@@ -907,13 +905,13 @@ class RuntimeTemplate {
|
|
907
905
|
case "dynamic":
|
908
906
|
if (isCall) {
|
909
907
|
return `${importVar}_default()${propertyAccess(exportName, 1)}`;
|
910
|
-
} else {
|
911
|
-
return asiSafe
|
912
|
-
? `(${importVar}_default()${propertyAccess(exportName, 1)})`
|
913
|
-
: asiSafe === false
|
914
|
-
? `;(${importVar}_default()${propertyAccess(exportName, 1)})`
|
915
|
-
: `${importVar}_default.a${propertyAccess(exportName, 1)}`;
|
916
908
|
}
|
909
|
+
return asiSafe
|
910
|
+
? `(${importVar}_default()${propertyAccess(exportName, 1)})`
|
911
|
+
: asiSafe === false
|
912
|
+
? `;(${importVar}_default()${propertyAccess(exportName, 1)})`
|
913
|
+
: `${importVar}_default.a${propertyAccess(exportName, 1)}`;
|
914
|
+
|
917
915
|
case "default-only":
|
918
916
|
case "default-with-named":
|
919
917
|
exportName = exportName.slice(1);
|
@@ -921,10 +919,10 @@ class RuntimeTemplate {
|
|
921
919
|
}
|
922
920
|
} else if (exportName.length > 0) {
|
923
921
|
if (exportsType === "default-only") {
|
924
|
-
return (
|
925
|
-
|
926
|
-
|
927
|
-
)
|
922
|
+
return `/* non-default import from non-esm module */undefined${propertyAccess(
|
923
|
+
exportName,
|
924
|
+
1
|
925
|
+
)}`;
|
928
926
|
} else if (
|
929
927
|
exportsType !== "namespace" &&
|
930
928
|
exportName[0] === "__esModule"
|
@@ -963,7 +961,7 @@ class RuntimeTemplate {
|
|
963
961
|
}
|
964
962
|
const comment = equals(used, exportName)
|
965
963
|
? ""
|
966
|
-
: Template.toNormalComment(propertyAccess(exportName))
|
964
|
+
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
967
965
|
const access = `${importVar}${comment}${propertyAccess(used)}`;
|
968
966
|
if (isCall && callContext === false) {
|
969
967
|
return asiSafe
|
@@ -973,9 +971,8 @@ class RuntimeTemplate {
|
|
973
971
|
: `/*#__PURE__*/Object(${access})`;
|
974
972
|
}
|
975
973
|
return access;
|
976
|
-
} else {
|
977
|
-
return importVar;
|
978
974
|
}
|
975
|
+
return importVar;
|
979
976
|
}
|
980
977
|
|
981
978
|
/**
|
@@ -1040,9 +1037,8 @@ class RuntimeTemplate {
|
|
1040
1037
|
return `Promise.all(${comment.trim()}[${chunks
|
1041
1038
|
.map(requireChunkId)
|
1042
1039
|
.join(", ")}])`;
|
1043
|
-
} else {
|
1044
|
-
return `Promise.resolve(${comment.trim()})`;
|
1045
1040
|
}
|
1041
|
+
return `Promise.resolve(${comment.trim()})`;
|
1046
1042
|
}
|
1047
1043
|
|
1048
1044
|
/**
|
package/lib/SizeFormatHelpers.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
* @param {number} size the size in bytes
|
10
10
|
* @returns {string} the formatted size
|
11
11
|
*/
|
12
|
-
exports.formatSize = size => {
|
12
|
+
module.exports.formatSize = size => {
|
13
13
|
if (typeof size !== "number" || Number.isNaN(size) === true) {
|
14
14
|
return "unknown size";
|
15
15
|
}
|
@@ -21,7 +21,5 @@ exports.formatSize = size => {
|
|
21
21
|
const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
|
22
22
|
const index = Math.floor(Math.log(size) / Math.log(1024));
|
23
23
|
|
24
|
-
return `${
|
25
|
-
abbreviations[index]
|
26
|
-
}`;
|
24
|
+
return `${Number((size / 1024 ** index).toPrecision(3))} ${abbreviations[index]}`;
|
27
25
|
};
|
@@ -24,11 +24,12 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
24
24
|
/** @typedef {import("./Chunk")} Chunk */
|
25
25
|
/** @typedef {import("./Compilation").Asset} Asset */
|
26
26
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
27
|
-
/** @typedef {import("./Compilation").PathData} PathData */
|
28
27
|
/** @typedef {import("./Compiler")} Compiler */
|
29
28
|
/** @typedef {import("./Module")} Module */
|
30
29
|
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
30
|
+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
31
31
|
/** @typedef {import("./util/Hash")} Hash */
|
32
|
+
/** @typedef {import("./util/createHash").Algorithm} Algorithm */
|
32
33
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
33
34
|
|
34
35
|
const validate = createSchemaValidation(
|
@@ -63,7 +64,6 @@ const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/;
|
|
63
64
|
* For when `test` or `exec` is called on them
|
64
65
|
* @param {RegExp} regexp Stateful Regular Expression to be reset
|
65
66
|
* @returns {void}
|
66
|
-
*
|
67
67
|
*/
|
68
68
|
const resetRegexpState = regexp => {
|
69
69
|
regexp.lastIndex = -1;
|
@@ -74,9 +74,7 @@ const resetRegexpState = regexp => {
|
|
74
74
|
* @param {string} str String to quote
|
75
75
|
* @returns {string} Escaped string
|
76
76
|
*/
|
77
|
-
const quoteMeta = str =>
|
78
|
-
return str.replace(METACHARACTERS_REGEXP, "\\$&");
|
79
|
-
};
|
77
|
+
const quoteMeta = str => str.replace(METACHARACTERS_REGEXP, "\\$&");
|
80
78
|
|
81
79
|
/**
|
82
80
|
* Creating {@link SourceMapTask} for given file
|
@@ -111,7 +109,7 @@ const getTaskForFile = (
|
|
111
109
|
source = asset.source();
|
112
110
|
}
|
113
111
|
if (!sourceMap || typeof source !== "string") return;
|
114
|
-
const context = compilation.options.context;
|
112
|
+
const context = /** @type {string} */ (compilation.options.context);
|
115
113
|
const root = compilation.compiler.root;
|
116
114
|
const cachedAbsolutify = makePathsAbsolute.bindContextCache(context, root);
|
117
115
|
const modules = sourceMap.sources.map(source => {
|
@@ -140,13 +138,13 @@ class SourceMapDevToolPlugin {
|
|
140
138
|
constructor(options = {}) {
|
141
139
|
validate(options);
|
142
140
|
|
143
|
-
/** @type {string | false} */
|
144
|
-
|
145
|
-
/** @type {string | false | (function(PathData, AssetInfo=): string)}} */
|
141
|
+
this.sourceMapFilename = /** @type {string | false} */ (options.filename);
|
142
|
+
/** @type {false | TemplatePath}} */
|
146
143
|
this.sourceMappingURLComment =
|
147
144
|
options.append === false
|
148
145
|
? false
|
149
|
-
:
|
146
|
+
: // eslint-disable-next-line no-useless-concat
|
147
|
+
options.append || "\n//# source" + "MappingURL=[url]";
|
150
148
|
/** @type {string | Function} */
|
151
149
|
this.moduleFilenameTemplate =
|
152
150
|
options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]";
|
@@ -223,7 +221,7 @@ class SourceMapDevToolPlugin {
|
|
223
221
|
}
|
224
222
|
}
|
225
223
|
|
226
|
-
reportProgress(0
|
224
|
+
reportProgress(0);
|
227
225
|
/** @type {SourceMapTask[]} */
|
228
226
|
const tasks = [];
|
229
227
|
let fileIndex = 0;
|
@@ -312,14 +310,23 @@ class SourceMapDevToolPlugin {
|
|
312
310
|
|
313
311
|
for (let idx = 0; idx < modules.length; idx++) {
|
314
312
|
const module = modules[idx];
|
313
|
+
|
314
|
+
if (
|
315
|
+
typeof module === "string" &&
|
316
|
+
/^(data|https?):/.test(module)
|
317
|
+
) {
|
318
|
+
moduleToSourceNameMapping.set(module, module);
|
319
|
+
continue;
|
320
|
+
}
|
321
|
+
|
315
322
|
if (!moduleToSourceNameMapping.get(module)) {
|
316
323
|
moduleToSourceNameMapping.set(
|
317
324
|
module,
|
318
325
|
ModuleFilenameHelpers.createFilename(
|
319
326
|
module,
|
320
327
|
{
|
321
|
-
moduleFilenameTemplate
|
322
|
-
namespace
|
328
|
+
moduleFilenameTemplate,
|
329
|
+
namespace
|
323
330
|
},
|
324
331
|
{
|
325
332
|
requestShortener,
|
@@ -383,7 +390,7 @@ class SourceMapDevToolPlugin {
|
|
383
390
|
module,
|
384
391
|
{
|
385
392
|
moduleFilenameTemplate: fallbackModuleFilenameTemplate,
|
386
|
-
namespace
|
393
|
+
namespace
|
387
394
|
},
|
388
395
|
{
|
389
396
|
requestShortener,
|
@@ -429,7 +436,7 @@ class SourceMapDevToolPlugin {
|
|
429
436
|
const moduleFilenames = modules.map(m =>
|
430
437
|
moduleToSourceNameMapping.get(m)
|
431
438
|
);
|
432
|
-
sourceMap.sources = moduleFilenames;
|
439
|
+
sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
|
433
440
|
if (options.noSources) {
|
434
441
|
sourceMap.sourcesContent = undefined;
|
435
442
|
}
|
@@ -444,21 +451,18 @@ class SourceMapDevToolPlugin {
|
|
444
451
|
// If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
|
445
452
|
if (usesContentHash && task.assetInfo.contenthash) {
|
446
453
|
const contenthash = task.assetInfo.contenthash;
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
} else {
|
451
|
-
pattern = quoteMeta(contenthash);
|
452
|
-
}
|
454
|
+
const pattern = Array.isArray(contenthash)
|
455
|
+
? contenthash.map(quoteMeta).join("|")
|
456
|
+
: quoteMeta(contenthash);
|
453
457
|
sourceMap.file = sourceMap.file.replace(
|
454
458
|
new RegExp(pattern, "g"),
|
455
459
|
m => "x".repeat(m.length)
|
456
460
|
);
|
457
461
|
}
|
458
462
|
|
459
|
-
/** @type {
|
463
|
+
/** @type {false | TemplatePath} */
|
460
464
|
let currentSourceMappingURLComment = sourceMappingURLComment;
|
461
|
-
|
465
|
+
const cssExtensionDetected =
|
462
466
|
CSS_EXTENSION_DETECT_REGEXP.test(file);
|
463
467
|
resetRegexpState(CSS_EXTENSION_DETECT_REGEXP);
|
464
468
|
if (
|
@@ -474,13 +478,17 @@ class SourceMapDevToolPlugin {
|
|
474
478
|
}
|
475
479
|
const sourceMapString = JSON.stringify(sourceMap);
|
476
480
|
if (sourceMapFilename) {
|
477
|
-
|
481
|
+
const filename = file;
|
478
482
|
const sourceMapContentHash =
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
483
|
+
/** @type {string} */
|
484
|
+
(
|
485
|
+
usesContentHash &&
|
486
|
+
createHash(
|
487
|
+
/** @type {Algorithm} */
|
488
|
+
(compilation.outputOptions.hashFunction)
|
489
|
+
)
|
490
|
+
.update(sourceMapString)
|
491
|
+
.digest("hex")
|
484
492
|
);
|
485
493
|
const pathParams = {
|
486
494
|
chunk,
|
@@ -511,10 +519,10 @@ class SourceMapDevToolPlugin {
|
|
511
519
|
// Add source map url to compilation asset, if currentSourceMappingURLComment is set
|
512
520
|
asset = new ConcatSource(
|
513
521
|
asset,
|
514
|
-
compilation.getPath(
|
515
|
-
|
516
|
-
|
517
|
-
)
|
522
|
+
compilation.getPath(currentSourceMappingURLComment, {
|
523
|
+
url: sourceMapUrl,
|
524
|
+
...pathParams
|
525
|
+
})
|
518
526
|
);
|
519
527
|
}
|
520
528
|
const assetInfo = {
|
@@ -584,7 +592,7 @@ class SourceMapDevToolPlugin {
|
|
584
592
|
});
|
585
593
|
},
|
586
594
|
err => {
|
587
|
-
reportProgress(1
|
595
|
+
reportProgress(1);
|
588
596
|
callback(err);
|
589
597
|
}
|
590
598
|
);
|
package/lib/Stats.js
CHANGED
@@ -55,13 +55,11 @@ class Stats {
|
|
55
55
|
* @returns {StatsCompilation} json output
|
56
56
|
*/
|
57
57
|
toJson(options) {
|
58
|
-
|
58
|
+
const normalizedOptions = this.compilation.createStatsOptions(options, {
|
59
59
|
forToString: false
|
60
60
|
});
|
61
61
|
|
62
|
-
const statsFactory = this.compilation.createStatsFactory(
|
63
|
-
/** @type {NormalizedStatsOptions} */ (options)
|
64
|
-
);
|
62
|
+
const statsFactory = this.compilation.createStatsFactory(normalizedOptions);
|
65
63
|
|
66
64
|
return statsFactory.create("compilation", this.compilation, {
|
67
65
|
compilation: this.compilation
|
@@ -73,16 +71,12 @@ class Stats {
|
|
73
71
|
* @returns {string} string output
|
74
72
|
*/
|
75
73
|
toString(options) {
|
76
|
-
|
74
|
+
const normalizedOptions = this.compilation.createStatsOptions(options, {
|
77
75
|
forToString: true
|
78
76
|
});
|
79
77
|
|
80
|
-
const statsFactory = this.compilation.createStatsFactory(
|
81
|
-
|
82
|
-
);
|
83
|
-
const statsPrinter = this.compilation.createStatsPrinter(
|
84
|
-
/** @type {NormalizedStatsOptions} */ (options)
|
85
|
-
);
|
78
|
+
const statsFactory = this.compilation.createStatsFactory(normalizedOptions);
|
79
|
+
const statsPrinter = this.compilation.createStatsPrinter(normalizedOptions);
|
86
80
|
|
87
81
|
const data = statsFactory.create("compilation", this.compilation, {
|
88
82
|
compilation: this.compilation
|
package/lib/Template.js
CHANGED
@@ -13,6 +13,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
|
|
13
13
|
/** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
|
14
14
|
/** @typedef {import("./Chunk")} Chunk */
|
15
15
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
16
|
+
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
16
17
|
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
17
18
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
18
19
|
/** @typedef {import("./Compilation").PathData} PathData */
|
@@ -22,6 +23,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
|
|
22
23
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
23
24
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
24
25
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
26
|
+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
25
27
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
26
28
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
27
29
|
|
@@ -59,7 +61,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
59
61
|
/**
|
60
62
|
* @typedef {object} RenderManifestEntryTemplated
|
61
63
|
* @property {function(): Source} render
|
62
|
-
* @property {
|
64
|
+
* @property {TemplatePath} filenameTemplate
|
63
65
|
* @property {PathData=} pathOptions
|
64
66
|
* @property {AssetInfo=} info
|
65
67
|
* @property {string} identifier
|
@@ -88,7 +90,6 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
88
90
|
|
89
91
|
class Template {
|
90
92
|
/**
|
91
|
-
*
|
92
93
|
* @param {Function} fn a runtime function (.runtime.js) "template"
|
93
94
|
* @returns {string} the updated and normalized function string
|
94
95
|
*/
|
@@ -110,8 +111,8 @@ class Template {
|
|
110
111
|
.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_$1")
|
111
112
|
.replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
|
112
113
|
}
|
114
|
+
|
113
115
|
/**
|
114
|
-
*
|
115
116
|
* @param {string} str string to be converted to commented in bundle code
|
116
117
|
* @returns {string} returns a commented version of string
|
117
118
|
*/
|
@@ -121,7 +122,6 @@ class Template {
|
|
121
122
|
}
|
122
123
|
|
123
124
|
/**
|
124
|
-
*
|
125
125
|
* @param {string} str string to be converted to "normal comment"
|
126
126
|
* @returns {string} returns a commented version of string
|
127
127
|
*/
|
@@ -211,23 +211,20 @@ class Template {
|
|
211
211
|
}
|
212
212
|
|
213
213
|
/**
|
214
|
-
*
|
215
214
|
* @param {string | string[]} s string to convert to identity
|
216
215
|
* @returns {string} converted identity
|
217
216
|
*/
|
218
217
|
static indent(s) {
|
219
218
|
if (Array.isArray(s)) {
|
220
219
|
return s.map(Template.indent).join("\n");
|
221
|
-
} else {
|
222
|
-
const str = s.trimEnd();
|
223
|
-
if (!str) return "";
|
224
|
-
const ind = str[0] === "\n" ? "" : "\t";
|
225
|
-
return ind + str.replace(/\n([^\n])/g, "\n\t$1");
|
226
220
|
}
|
221
|
+
const str = s.trimEnd();
|
222
|
+
if (!str) return "";
|
223
|
+
const ind = str[0] === "\n" ? "" : "\t";
|
224
|
+
return ind + str.replace(/\n([^\n])/g, "\n\t$1");
|
227
225
|
}
|
228
226
|
|
229
227
|
/**
|
230
|
-
*
|
231
228
|
* @param {string|string[]} s string to create prefix for
|
232
229
|
* @param {string} prefix prefix to compose
|
233
230
|
* @returns {string} returns new prefix string
|
@@ -236,11 +233,10 @@ class Template {
|
|
236
233
|
const str = Template.asString(s).trim();
|
237
234
|
if (!str) return "";
|
238
235
|
const ind = str[0] === "\n" ? "" : prefix;
|
239
|
-
return ind + str.replace(/\n([^\n])/g,
|
236
|
+
return ind + str.replace(/\n([^\n])/g, `\n${prefix}$1`);
|
240
237
|
}
|
241
238
|
|
242
239
|
/**
|
243
|
-
*
|
244
240
|
* @param {string|string[]} str string or string collection
|
245
241
|
* @returns {string} returns a single string from array
|
246
242
|
*/
|
@@ -270,7 +266,7 @@ class Template {
|
|
270
266
|
if (maxId < moduleId) maxId = moduleId;
|
271
267
|
if (minId > moduleId) minId = moduleId;
|
272
268
|
}
|
273
|
-
if (minId < 16 + (
|
269
|
+
if (minId < 16 + String(minId).length) {
|
274
270
|
// add minId x ',' instead of 'Array(minId).concat(…)'
|
275
271
|
minId = 0;
|
276
272
|
}
|
@@ -288,23 +284,21 @@ class Template {
|
|
288
284
|
/**
|
289
285
|
* @param {ChunkRenderContext} renderContext render context
|
290
286
|
* @param {Module[]} modules modules to render (should be ordered by identifier)
|
291
|
-
* @param {function(Module): Source} renderModule function to render a module
|
287
|
+
* @param {function(Module): Source | null} renderModule function to render a module
|
292
288
|
* @param {string=} prefix applying prefix strings
|
293
289
|
* @returns {Source | null} rendered chunk modules in a Source object or null if no modules
|
294
290
|
*/
|
295
291
|
static renderChunkModules(renderContext, modules, renderModule, prefix = "") {
|
296
292
|
const { chunkGraph } = renderContext;
|
297
|
-
|
293
|
+
const source = new ConcatSource();
|
298
294
|
if (modules.length === 0) {
|
299
295
|
return null;
|
300
296
|
}
|
301
297
|
/** @type {{id: string|number, source: Source|string}[]} */
|
302
|
-
const allModules = modules.map(module => {
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
};
|
307
|
-
});
|
298
|
+
const allModules = modules.map(module => ({
|
299
|
+
id: /** @type {ModuleId} */ (chunkGraph.getModuleId(module)),
|
300
|
+
source: renderModule(module) || "false"
|
301
|
+
}));
|
308
302
|
const bounds = Template.getModulesArrayBounds(allModules);
|
309
303
|
if (bounds) {
|
310
304
|
// Render a spare array
|
@@ -330,7 +324,7 @@ class Template {
|
|
330
324
|
source.add(module.source);
|
331
325
|
}
|
332
326
|
}
|
333
|
-
source.add(
|
327
|
+
source.add(`\n${prefix}]`);
|
334
328
|
if (minId !== 0) {
|
335
329
|
source.add(")");
|
336
330
|
}
|
@@ -379,7 +373,7 @@ class Template {
|
|
379
373
|
runtimeSource = codeGenResult.sources.get("runtime");
|
380
374
|
}
|
381
375
|
if (runtimeSource) {
|
382
|
-
source.add(Template.toNormalComment(module.identifier())
|
376
|
+
source.add(`${Template.toNormalComment(module.identifier())}\n`);
|
383
377
|
if (!module.shouldIsolate()) {
|
384
378
|
source.add(runtimeSource);
|
385
379
|
source.add("\n\n");
|
@@ -13,6 +13,7 @@ const Module = require("./Module");
|
|
13
13
|
const { parseResource } = require("./util/identifier");
|
14
14
|
|
15
15
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
16
|
+
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
16
17
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
17
18
|
/** @typedef {import("./Compilation").PathData} PathData */
|
18
19
|
/** @typedef {import("./Compiler")} Compiler */
|
@@ -55,7 +56,7 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
|
|
55
56
|
/** @type {ReplacerFunction} */
|
56
57
|
const fn = (match, arg, input) => {
|
57
58
|
let result;
|
58
|
-
const length = arg && parseInt(arg, 10);
|
59
|
+
const length = arg && Number.parseInt(arg, 10);
|
59
60
|
|
60
61
|
if (length && handler) {
|
61
62
|
result = handler(length);
|
@@ -101,9 +102,9 @@ const replacer = (value, allowEmpty) => {
|
|
101
102
|
}
|
102
103
|
|
103
104
|
return "";
|
104
|
-
} else {
|
105
|
-
return `${value}`;
|
106
105
|
}
|
106
|
+
|
107
|
+
return `${value}`;
|
107
108
|
};
|
108
109
|
|
109
110
|
return fn;
|
@@ -129,8 +130,10 @@ const deprecated = (fn, message, code) => {
|
|
129
130
|
};
|
130
131
|
};
|
131
132
|
|
133
|
+
/** @typedef {string | function(PathData, AssetInfo=): string} TemplatePath */
|
134
|
+
|
132
135
|
/**
|
133
|
-
* @param {
|
136
|
+
* @param {TemplatePath} path the raw path
|
134
137
|
* @param {PathData} data context data
|
135
138
|
* @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
|
136
139
|
* @returns {string} the interpolated path
|
@@ -155,7 +158,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
155
158
|
// [ext] - .js
|
156
159
|
if (typeof data.filename === "string") {
|
157
160
|
// check that filename is data uri
|
158
|
-
|
161
|
+
const match = data.filename.match(/^data:([^;,]+)/);
|
159
162
|
if (match) {
|
160
163
|
const ext = mime.extension(match[1]);
|
161
164
|
const emptyReplacer = replacer("", true);
|
@@ -292,17 +295,16 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
292
295
|
const idReplacer = replacer(() =>
|
293
296
|
prepareId(
|
294
297
|
module instanceof Module
|
295
|
-
? /** @type {
|
298
|
+
? /** @type {ModuleId} */
|
299
|
+
(/** @type {ChunkGraph} */ (chunkGraph).getModuleId(module))
|
296
300
|
: module.id
|
297
301
|
)
|
298
302
|
);
|
299
303
|
const moduleHashReplacer = hashLength(
|
300
304
|
replacer(() =>
|
301
305
|
module instanceof Module
|
302
|
-
? /** @type {ChunkGraph} */
|
303
|
-
|
304
|
-
data.runtime
|
305
|
-
)
|
306
|
+
? /** @type {ChunkGraph} */
|
307
|
+
(chunkGraph).getRenderedModuleHash(module, data.runtime)
|
306
308
|
: module.hash
|
307
309
|
),
|
308
310
|
"hashWithLength" in module ? module.hashWithLength : undefined,
|
package/lib/UseStrictPlugin.js
CHANGED
@@ -12,6 +12,7 @@ const {
|
|
12
12
|
} = require("./ModuleTypeConstants");
|
13
13
|
const ConstDependency = require("./dependencies/ConstDependency");
|
14
14
|
|
15
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
15
16
|
/** @typedef {import("./Compiler")} Compiler */
|
16
17
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
17
18
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
@@ -32,8 +33,9 @@ class UseStrictPlugin {
|
|
32
33
|
(compilation, { normalModuleFactory }) => {
|
33
34
|
/**
|
34
35
|
* @param {JavascriptParser} parser the parser
|
36
|
+
* @param {JavascriptParserOptions} parserOptions the javascript parser options
|
35
37
|
*/
|
36
|
-
const handler = parser => {
|
38
|
+
const handler = (parser, parserOptions) => {
|
37
39
|
parser.hooks.program.tap(PLUGIN_NAME, ast => {
|
38
40
|
const firstNode = ast.body[0];
|
39
41
|
if (
|
@@ -54,6 +56,11 @@ class UseStrictPlugin {
|
|
54
56
|
/** @type {BuildInfo} */
|
55
57
|
(parser.state.module.buildInfo).strict = true;
|
56
58
|
}
|
59
|
+
if (parserOptions.overrideStrict) {
|
60
|
+
/** @type {BuildInfo} */
|
61
|
+
(parser.state.module.buildInfo).strict =
|
62
|
+
parserOptions.overrideStrict === "strict";
|
63
|
+
}
|
57
64
|
});
|
58
65
|
};
|
59
66
|
|
@@ -42,7 +42,6 @@ class WarnDeprecatedOptionPlugin {
|
|
42
42
|
class DeprecatedOptionWarning extends WebpackError {
|
43
43
|
/**
|
44
44
|
* Create an instance deprecated option warning
|
45
|
-
*
|
46
45
|
* @param {string} option the target option
|
47
46
|
* @param {string | number} value the deprecated option value
|
48
47
|
* @param {string} suggestion the suggestion replacement
|