webpack 5.97.1 → 5.99.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 +345 -392
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +343 -167
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +44 -21
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +21 -39
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +52 -10
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +104 -28
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssLoadingRuntimeModule.js +5 -2
- package/lib/css/CssModulesPlugin.js +41 -9
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +38 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +18 -15
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +49 -27
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +54 -34
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -3
- package/lib/json/JsonParser.js +10 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +90 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +81 -79
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/semver.js +18 -8
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/validateSchema.js +4 -7
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -2
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +27 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/JsonModulesPluginParser.check.js +1 -1
- package/schemas/plugins/JsonModulesPluginParser.json +4 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +888 -583
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -14,46 +14,66 @@ const NullDependency = require("./NullDependency");
|
|
14
14
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
16
|
/** @typedef {import("../json/JsonData")} JsonData */
|
17
|
-
/** @typedef {import("../json/JsonData").
|
17
|
+
/** @typedef {import("../json/JsonData").JsonValue} JsonValue */
|
18
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
19
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
|
22
22
|
/**
|
23
|
-
* @
|
24
|
-
* @
|
23
|
+
* @callback GetExportsFromDataFn
|
24
|
+
* @param {JsonValue} data raw json data
|
25
|
+
* @param {number} [curDepth] current depth
|
26
|
+
* @returns {ExportSpec[] | null} export spec or nothing
|
25
27
|
*/
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @param {number} exportsDepth exportsDepth
|
31
|
+
* @returns {GetExportsFromDataFn} value
|
32
|
+
*/
|
33
|
+
const getExportsWithDepth = exportsDepth =>
|
34
|
+
/** @type {GetExportsFromDataFn} */
|
35
|
+
function getExportsFromData(data, curDepth = 1) {
|
36
|
+
if (curDepth > exportsDepth) {
|
37
|
+
return null;
|
36
38
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
|
40
|
+
if (data && typeof data === "object") {
|
41
|
+
if (Array.isArray(data)) {
|
42
|
+
return data.length < 100
|
43
|
+
? data.map((item, idx) => ({
|
44
|
+
name: `${idx}`,
|
45
|
+
canMangle: true,
|
46
|
+
exports: getExportsFromData(item, curDepth + 1) || undefined
|
47
|
+
}))
|
48
|
+
: null;
|
49
|
+
}
|
50
|
+
|
51
|
+
/** @type {ExportSpec[]} */
|
52
|
+
const exports = [];
|
53
|
+
|
54
|
+
for (const key of Object.keys(data)) {
|
55
|
+
exports.push({
|
56
|
+
name: key,
|
57
|
+
canMangle: true,
|
58
|
+
exports: getExportsFromData(data[key], curDepth + 1) || undefined
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
return exports;
|
44
63
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
};
|
64
|
+
|
65
|
+
return null;
|
66
|
+
};
|
49
67
|
|
50
68
|
class JsonExportsDependency extends NullDependency {
|
51
69
|
/**
|
52
70
|
* @param {JsonData} data json data
|
71
|
+
* @param {number} exportsDepth the depth of json exports to analyze
|
53
72
|
*/
|
54
|
-
constructor(data) {
|
73
|
+
constructor(data, exportsDepth) {
|
55
74
|
super();
|
56
75
|
this.data = data;
|
76
|
+
this.exportsDepth = exportsDepth;
|
57
77
|
}
|
58
78
|
|
59
79
|
get type() {
|
@@ -67,8 +87,8 @@ class JsonExportsDependency extends NullDependency {
|
|
67
87
|
*/
|
68
88
|
getExports(moduleGraph) {
|
69
89
|
return {
|
70
|
-
exports:
|
71
|
-
this.data && /** @type {
|
90
|
+
exports: getExportsWithDepth(this.exportsDepth)(
|
91
|
+
this.data && /** @type {JsonValue} */ (this.data.get())
|
72
92
|
),
|
73
93
|
dependencies: undefined
|
74
94
|
};
|
@@ -90,6 +110,7 @@ class JsonExportsDependency extends NullDependency {
|
|
90
110
|
serialize(context) {
|
91
111
|
const { write } = context;
|
92
112
|
write(this.data);
|
113
|
+
write(this.exportsDepth);
|
93
114
|
super.serialize(context);
|
94
115
|
}
|
95
116
|
|
@@ -99,6 +120,7 @@ class JsonExportsDependency extends NullDependency {
|
|
99
120
|
deserialize(context) {
|
100
121
|
const { read } = context;
|
101
122
|
this.data = read();
|
123
|
+
this.exportsDepth = read();
|
102
124
|
super.deserialize(context);
|
103
125
|
}
|
104
126
|
}
|
@@ -12,6 +12,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
12
12
|
|
13
13
|
/** @typedef {import("../../declarations/LoaderContext").LoaderPluginLoaderContext} LoaderPluginLoaderContext */
|
14
14
|
/** @typedef {import("../Compilation").DepConstructor} DepConstructor */
|
15
|
+
/** @typedef {import("../Compilation").ExecuteModuleExports} ExecuteModuleExports */
|
15
16
|
/** @typedef {import("../Compilation").ExecuteModuleResult} ExecuteModuleResult */
|
16
17
|
/** @typedef {import("../Compiler")} Compiler */
|
17
18
|
/** @typedef {import("../Module")} Module */
|
@@ -20,7 +21,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
20
21
|
/**
|
21
22
|
* @callback ImportModuleCallback
|
22
23
|
* @param {(Error | null)=} err error object
|
23
|
-
* @param {
|
24
|
+
* @param {ExecuteModuleExports=} exports exports of the evaluated module
|
24
25
|
*/
|
25
26
|
|
26
27
|
/**
|
@@ -31,11 +32,6 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
31
32
|
*/
|
32
33
|
|
33
34
|
class LoaderPlugin {
|
34
|
-
/**
|
35
|
-
* @param {object} options options
|
36
|
-
*/
|
37
|
-
constructor(options = {}) {}
|
38
|
-
|
39
35
|
/**
|
40
36
|
* Apply the plugin
|
41
37
|
* @param {Compiler} compiler the compiler instance
|
@@ -150,12 +146,7 @@ class LoaderPlugin {
|
|
150
146
|
for (const d of buildDependencies) {
|
151
147
|
loaderContext.addBuildDependency(d);
|
152
148
|
}
|
153
|
-
return callback(
|
154
|
-
null,
|
155
|
-
source,
|
156
|
-
/** @type {object | null} */ (map),
|
157
|
-
referencedModule
|
158
|
-
);
|
149
|
+
return callback(null, source, map, referencedModule);
|
159
150
|
}
|
160
151
|
);
|
161
152
|
};
|
@@ -271,8 +262,7 @@ class LoaderPlugin {
|
|
271
262
|
);
|
272
263
|
};
|
273
264
|
|
274
|
-
//
|
275
|
-
// @ts-ignore Overloading doesn't work
|
265
|
+
// @ts-expect-error overloading doesn't work
|
276
266
|
loaderContext.importModule = (request, options, callback) => {
|
277
267
|
if (!callback) {
|
278
268
|
return new Promise((resolve, reject) => {
|
@@ -10,10 +10,11 @@ const ContextDependency = require("./ContextDependency");
|
|
10
10
|
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
11
11
|
|
12
12
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
|
13
14
|
|
14
15
|
class RequireContextDependency extends ContextDependency {
|
15
16
|
/**
|
16
|
-
* @param {
|
17
|
+
* @param {ContextDependencyOptions} options options
|
17
18
|
* @param {Range} range range
|
18
19
|
*/
|
19
20
|
constructor(options, range) {
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const RequireContextDependency = require("./RequireContextDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
10
11
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
11
12
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
12
13
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
@@ -22,12 +23,13 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
22
23
|
.tap("RequireContextDependencyParserPlugin", expr => {
|
23
24
|
let regExp = /^\.\/.*$/;
|
24
25
|
let recursive = true;
|
26
|
+
/** @type {ContextMode} */
|
25
27
|
let mode = "sync";
|
26
28
|
switch (expr.arguments.length) {
|
27
29
|
case 4: {
|
28
30
|
const modeExpr = parser.evaluateExpression(expr.arguments[3]);
|
29
31
|
if (!modeExpr.isString()) return;
|
30
|
-
mode = /** @type {
|
32
|
+
mode = /** @type {ContextMode} */ (modeExpr.string);
|
31
33
|
}
|
32
34
|
// falls through
|
33
35
|
case 3: {
|
@@ -47,13 +49,14 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
47
49
|
if (!requestExpr.isString()) return;
|
48
50
|
const dep = new RequireContextDependency(
|
49
51
|
{
|
50
|
-
request: requestExpr.string,
|
52
|
+
request: /** @type {string} */ (requestExpr.string),
|
51
53
|
recursive,
|
52
54
|
regExp,
|
53
55
|
mode,
|
54
56
|
category: "commonjs"
|
55
57
|
},
|
56
|
-
/** @type {Range} */
|
58
|
+
/** @type {Range} */
|
59
|
+
(expr.range)
|
57
60
|
);
|
58
61
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
59
62
|
dep.optional = Boolean(parser.scope.inTry);
|
@@ -8,13 +8,14 @@
|
|
8
8
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("../AsyncDependenciesBlock").GroupOptions} GroupOptions */
|
11
12
|
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
12
13
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
13
14
|
|
14
15
|
class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
|
15
16
|
/**
|
16
|
-
* @param {
|
17
|
-
* @param {DependencyLocation} loc location info
|
17
|
+
* @param {GroupOptions | null} chunkName chunk name
|
18
|
+
* @param {(DependencyLocation | null)=} loc location info
|
18
19
|
*/
|
19
20
|
constructor(chunkName, loc) {
|
20
21
|
super(chunkName, loc, null);
|
@@ -10,6 +10,7 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
|
|
10
10
|
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
11
11
|
const getFunctionExpression = require("./getFunctionExpression");
|
12
12
|
|
13
|
+
/** @typedef {import("../AsyncDependenciesBlock").GroupOptions} GroupOptions */
|
13
14
|
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
14
15
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
15
16
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
@@ -25,6 +26,7 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
25
26
|
parser.hooks.call
|
26
27
|
.for("require.ensure")
|
27
28
|
.tap("RequireEnsureDependenciesBlockParserPlugin", expr => {
|
29
|
+
/** @type {string | GroupOptions | null} */
|
28
30
|
let chunkName = null;
|
29
31
|
let errorExpressionArg = null;
|
30
32
|
let errorExpression = null;
|
@@ -32,7 +34,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
32
34
|
case 4: {
|
33
35
|
const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
|
34
36
|
if (!chunkNameExpr.isString()) return;
|
35
|
-
chunkName =
|
37
|
+
chunkName =
|
38
|
+
/** @type {string} */
|
39
|
+
(chunkNameExpr.string);
|
36
40
|
}
|
37
41
|
// falls through
|
38
42
|
case 3: {
|
@@ -44,7 +48,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
44
48
|
expr.arguments[2]
|
45
49
|
);
|
46
50
|
if (!chunkNameExpr.isString()) return;
|
47
|
-
chunkName =
|
51
|
+
chunkName =
|
52
|
+
/** @type {string} */
|
53
|
+
(chunkNameExpr.string);
|
48
54
|
}
|
49
55
|
}
|
50
56
|
// falls through
|
@@ -70,9 +76,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
70
76
|
}
|
71
77
|
|
72
78
|
const depBlock = new RequireEnsureDependenciesBlock(
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
chunkName,
|
80
|
+
/** @type {DependencyLocation} */
|
81
|
+
(expr.loc)
|
76
82
|
);
|
77
83
|
const errorCallbackExists =
|
78
84
|
expr.arguments.length === 4 ||
|
@@ -19,7 +19,7 @@ class RequireResolveContextDependency extends ContextDependency {
|
|
19
19
|
* @param {ContextDependencyOptions} options options
|
20
20
|
* @param {Range} range range
|
21
21
|
* @param {Range} valueRange value range
|
22
|
-
* @param {
|
22
|
+
* @param {string=} context context
|
23
23
|
*/
|
24
24
|
constructor(options, range, valueRange, context) {
|
25
25
|
super(options, context);
|
@@ -21,7 +21,7 @@ class WebAssemblyExportImportedDependency extends ModuleDependency {
|
|
21
21
|
* @param {string} exportName export name
|
22
22
|
* @param {string} request request
|
23
23
|
* @param {string} name name
|
24
|
-
* @param {
|
24
|
+
* @param {string} valueType value type
|
25
25
|
*/
|
26
26
|
constructor(exportName, request, name, valueType) {
|
27
27
|
super(request);
|
@@ -30,6 +30,7 @@ class WorkerDependency extends ModuleDependency {
|
|
30
30
|
* @param {Range} range range
|
31
31
|
* @param {object} workerDependencyOptions options
|
32
32
|
* @param {string=} workerDependencyOptions.publicPath public path for the worker
|
33
|
+
* @param {boolean=} workerDependencyOptions.needNewUrl need generate `new URL(...)`
|
33
34
|
*/
|
34
35
|
constructor(request, range, workerDependencyOptions) {
|
35
36
|
super(request);
|
@@ -118,12 +119,14 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
|
|
118
119
|
runtimeRequirements.add(RuntimeGlobals.baseURI);
|
119
120
|
runtimeRequirements.add(RuntimeGlobals.getChunkScriptFilename);
|
120
121
|
|
122
|
+
const workerImportStr = `/* worker import */ ${workerImportBaseUrl} + ${
|
123
|
+
RuntimeGlobals.getChunkScriptFilename
|
124
|
+
}(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`;
|
125
|
+
|
121
126
|
source.replace(
|
122
127
|
dep.range[0],
|
123
128
|
dep.range[1] - 1,
|
124
|
-
|
125
|
-
RuntimeGlobals.getChunkScriptFilename
|
126
|
-
}(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
|
129
|
+
dep.options.needNewUrl ? `new URL(${workerImportStr})` : workerImportStr
|
127
130
|
);
|
128
131
|
}
|
129
132
|
};
|
@@ -27,6 +27,8 @@ const WorkerDependency = require("./WorkerDependency");
|
|
27
27
|
|
28
28
|
/** @typedef {import("estree").CallExpression} CallExpression */
|
29
29
|
/** @typedef {import("estree").Expression} Expression */
|
30
|
+
/** @typedef {import("estree").Identifier} Identifier */
|
31
|
+
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
30
32
|
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
31
33
|
/** @typedef {import("estree").Pattern} Pattern */
|
32
34
|
/** @typedef {import("estree").Property} Property */
|
@@ -117,45 +119,81 @@ class WorkerPlugin {
|
|
117
119
|
/**
|
118
120
|
* @param {JavascriptParser} parser the parser
|
119
121
|
* @param {Expression} expr expression
|
120
|
-
* @returns {[
|
122
|
+
* @returns {[string, [number, number]] | void} parsed
|
121
123
|
*/
|
122
124
|
const parseModuleUrl = (parser, expr) => {
|
123
|
-
if (
|
124
|
-
expr.type !== "NewExpression" ||
|
125
|
-
expr.callee.type === "Super" ||
|
126
|
-
expr.arguments.length !== 2
|
127
|
-
)
|
125
|
+
if (expr.type !== "NewExpression" || expr.callee.type === "Super")
|
128
126
|
return;
|
129
|
-
const [arg1, arg2] = expr.arguments;
|
130
|
-
if (arg1.type === "SpreadElement") return;
|
131
|
-
if (arg2.type === "SpreadElement") return;
|
132
|
-
const callee = parser.evaluateExpression(expr.callee);
|
133
|
-
if (!callee.isIdentifier() || callee.identifier !== "URL") return;
|
134
|
-
const arg2Value = parser.evaluateExpression(arg2);
|
135
127
|
if (
|
136
|
-
|
137
|
-
|
138
|
-
|
128
|
+
expr.arguments.length === 1 &&
|
129
|
+
expr.arguments[0].type === "MemberExpression" &&
|
130
|
+
isMetaUrl(parser, expr.arguments[0])
|
139
131
|
) {
|
140
|
-
|
132
|
+
const arg1 = expr.arguments[0];
|
133
|
+
return [
|
134
|
+
getUrl(parser.state.module),
|
135
|
+
[
|
136
|
+
/** @type {Range} */ (arg1.range)[0],
|
137
|
+
/** @type {Range} */ (arg1.range)[1]
|
138
|
+
]
|
139
|
+
];
|
140
|
+
} else if (expr.arguments.length === 2) {
|
141
|
+
const [arg1, arg2] = expr.arguments;
|
142
|
+
if (arg1.type === "SpreadElement") return;
|
143
|
+
if (arg2.type === "SpreadElement") return;
|
144
|
+
const callee = parser.evaluateExpression(expr.callee);
|
145
|
+
if (!callee.isIdentifier() || callee.identifier !== "URL") return;
|
146
|
+
const arg2Value = parser.evaluateExpression(arg2);
|
147
|
+
if (
|
148
|
+
!arg2Value.isString() ||
|
149
|
+
!(
|
150
|
+
/** @type {string} */ (arg2Value.string).startsWith("file://")
|
151
|
+
) ||
|
152
|
+
arg2Value.string !== getUrl(parser.state.module)
|
153
|
+
) {
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
const arg1Value = parser.evaluateExpression(arg1);
|
157
|
+
if (!arg1Value.isString()) return;
|
158
|
+
return [
|
159
|
+
/** @type {string} */ (arg1Value.string),
|
160
|
+
[
|
161
|
+
/** @type {Range} */ (arg1.range)[0],
|
162
|
+
/** @type {Range} */ (arg2.range)[1]
|
163
|
+
]
|
164
|
+
];
|
141
165
|
}
|
142
|
-
const arg1Value = parser.evaluateExpression(arg1);
|
143
|
-
return [
|
144
|
-
arg1Value,
|
145
|
-
[
|
146
|
-
/** @type {Range} */ (arg1.range)[0],
|
147
|
-
/** @type {Range} */ (arg2.range)[1]
|
148
|
-
]
|
149
|
-
];
|
150
166
|
};
|
151
167
|
|
168
|
+
/**
|
169
|
+
* @param {JavascriptParser} parser the parser
|
170
|
+
* @param {MemberExpression} expr expression
|
171
|
+
* @returns {boolean} is `import.meta.url`
|
172
|
+
*/
|
173
|
+
const isMetaUrl = (parser, expr) => {
|
174
|
+
const chain = parser.extractMemberExpressionChain(expr);
|
175
|
+
|
176
|
+
if (
|
177
|
+
chain.members.length !== 1 ||
|
178
|
+
chain.object.type !== "MetaProperty" ||
|
179
|
+
chain.object.meta.name !== "import" ||
|
180
|
+
chain.object.property.name !== "meta" ||
|
181
|
+
chain.members[0] !== "url"
|
182
|
+
)
|
183
|
+
return false;
|
184
|
+
|
185
|
+
return true;
|
186
|
+
};
|
187
|
+
|
188
|
+
/** @typedef {Record<string, EXPECTED_ANY>} Values */
|
189
|
+
|
152
190
|
/**
|
153
191
|
* @param {JavascriptParser} parser the parser
|
154
192
|
* @param {ObjectExpression} expr expression
|
155
|
-
* @returns {{ expressions: Record<string, Expression | Pattern>, otherElements: (Property | SpreadElement)[], values:
|
193
|
+
* @returns {{ expressions: Record<string, Expression | Pattern>, otherElements: (Property | SpreadElement)[], values: Values, spread: boolean, insertType: "comma" | "single", insertLocation: number }} parsed object
|
156
194
|
*/
|
157
195
|
const parseObjectExpression = (parser, expr) => {
|
158
|
-
/** @type {
|
196
|
+
/** @type {Values} */
|
159
197
|
const values = {};
|
160
198
|
/** @type {Record<string, Expression | Pattern>} */
|
161
199
|
const expressions = {};
|
@@ -174,7 +212,8 @@ class WorkerPlugin {
|
|
174
212
|
expressions[prop.key.name] = prop.value;
|
175
213
|
if (!prop.shorthand && !prop.value.type.endsWith("Pattern")) {
|
176
214
|
const value = parser.evaluateExpression(
|
177
|
-
/** @type {Expression} */
|
215
|
+
/** @type {Expression} */
|
216
|
+
(prop.value)
|
178
217
|
);
|
179
218
|
if (value.isCompileTimeValue())
|
180
219
|
values[prop.key.name] = value.asCompileTimeValue();
|
@@ -217,10 +256,27 @@ class WorkerPlugin {
|
|
217
256
|
const [arg1, arg2] = expr.arguments;
|
218
257
|
if (arg1.type === "SpreadElement") return;
|
219
258
|
if (arg2 && arg2.type === "SpreadElement") return;
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
259
|
+
|
260
|
+
/** @type {string} */
|
261
|
+
let url;
|
262
|
+
/** @type {[number, number]} */
|
263
|
+
let range;
|
264
|
+
/** @type {boolean} */
|
265
|
+
let needNewUrl = false;
|
266
|
+
|
267
|
+
if (arg1.type === "MemberExpression" && isMetaUrl(parser, arg1)) {
|
268
|
+
url = getUrl(parser.state.module);
|
269
|
+
range = [
|
270
|
+
/** @type {Range} */ (arg1.range)[0],
|
271
|
+
/** @type {Range} */ (arg1.range)[1]
|
272
|
+
];
|
273
|
+
needNewUrl = true;
|
274
|
+
} else {
|
275
|
+
const parsedUrl = parseModuleUrl(parser, arg1);
|
276
|
+
if (!parsedUrl) return;
|
277
|
+
[url, range] = parsedUrl;
|
278
|
+
}
|
279
|
+
|
224
280
|
const {
|
225
281
|
expressions,
|
226
282
|
otherElements,
|
@@ -234,7 +290,7 @@ class WorkerPlugin {
|
|
234
290
|
/** @type {Record<string, Expression | Pattern>} */
|
235
291
|
expressions: {},
|
236
292
|
otherElements: [],
|
237
|
-
/** @type {
|
293
|
+
/** @type {Values} */
|
238
294
|
values: {},
|
239
295
|
spread: false,
|
240
296
|
insertType: arg2 ? "spread" : "argument",
|
@@ -342,13 +398,10 @@ class WorkerPlugin {
|
|
342
398
|
}
|
343
399
|
});
|
344
400
|
block.loc = expr.loc;
|
345
|
-
const dep = new WorkerDependency(
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
publicPath: this._workerPublicPath
|
350
|
-
}
|
351
|
-
);
|
401
|
+
const dep = new WorkerDependency(url, range, {
|
402
|
+
publicPath: this._workerPublicPath,
|
403
|
+
needNewUrl
|
404
|
+
});
|
352
405
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
353
406
|
block.addDependency(dep);
|
354
407
|
parser.state.module.addBlock(block);
|
@@ -370,7 +423,7 @@ class WorkerPlugin {
|
|
370
423
|
);
|
371
424
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
372
425
|
parser.state.module.addPresentationalDependency(dep);
|
373
|
-
/** @type {
|
426
|
+
/** @type {EXPECTED_ANY} */
|
374
427
|
(expressions).type = undefined;
|
375
428
|
}
|
376
429
|
} else if (insertType === "comma") {
|
@@ -406,7 +459,13 @@ class WorkerPlugin {
|
|
406
459
|
|
407
460
|
parser.walkExpression(expr.callee);
|
408
461
|
for (const key of Object.keys(expressions)) {
|
409
|
-
if (expressions[key])
|
462
|
+
if (expressions[key]) {
|
463
|
+
if (expressions[key].type.endsWith("Pattern")) continue;
|
464
|
+
parser.walkExpression(
|
465
|
+
/** @type {Expression} */
|
466
|
+
(expressions[key])
|
467
|
+
);
|
468
|
+
}
|
410
469
|
}
|
411
470
|
for (const prop of otherElements) {
|
412
471
|
parser.walkProperty(prop);
|
@@ -151,6 +151,11 @@ class ModuleChunkFormatPlugin {
|
|
151
151
|
let index = 0;
|
152
152
|
for (let i = 0; i < entries.length; i++) {
|
153
153
|
const [module, entrypoint] = entries[i];
|
154
|
+
if (
|
155
|
+
!chunkGraph.getModuleSourceTypes(module).has("javascript")
|
156
|
+
) {
|
157
|
+
continue;
|
158
|
+
}
|
154
159
|
const final = i + 1 === entries.length;
|
155
160
|
const moduleId = chunkGraph.getModuleId(module);
|
156
161
|
const chunks = getAllChunks(
|
@@ -93,7 +93,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
93
93
|
(compilation.outputOptions.environment);
|
94
94
|
const {
|
95
95
|
runtimeTemplate,
|
96
|
-
outputOptions: { importFunctionName, crossOriginLoading }
|
96
|
+
outputOptions: { importFunctionName, crossOriginLoading, charset }
|
97
97
|
} = compilation;
|
98
98
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
99
99
|
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
@@ -261,6 +261,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
261
261
|
linkPrefetch.call(
|
262
262
|
Template.asString([
|
263
263
|
"var link = document.createElement('link');",
|
264
|
+
charset ? "link.charset = 'utf-8';" : "",
|
264
265
|
crossOriginLoading
|
265
266
|
? `link.crossOrigin = ${JSON.stringify(
|
266
267
|
crossOriginLoading
|
@@ -300,7 +301,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
300
301
|
linkPreload.call(
|
301
302
|
Template.asString([
|
302
303
|
"var link = document.createElement('link');",
|
303
|
-
"link.charset = 'utf-8';",
|
304
|
+
charset ? "link.charset = 'utf-8';" : "",
|
304
305
|
`if (${RuntimeGlobals.scriptNonce}) {`,
|
305
306
|
Template.indent(
|
306
307
|
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
@@ -109,6 +109,7 @@ module.exports = function () {
|
|
109
109
|
var appliedUpdate = {};
|
110
110
|
|
111
111
|
var warnUnexpectedRequire = function warnUnexpectedRequire(module) {
|
112
|
+
// eslint-disable-next-line no-console
|
112
113
|
console.warn(
|
113
114
|
"[HMR] unexpected require(" + module.id + ") to disposed module"
|
114
115
|
);
|