webpack 5.98.0 → 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 +7 -3
- 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 +326 -152
- 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 +40 -17
- 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 +13 -13
- 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 +50 -8
- 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 +93 -26
- 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/CssModulesPlugin.js +30 -5
- 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 +8 -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 +17 -14
- 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 +24 -8
- 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/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 +51 -31
- 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 -2
- package/lib/json/JsonParser.js +8 -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 +87 -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/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 +80 -78
- 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/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- 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/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- 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/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -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(
|
@@ -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
|
);
|
@@ -23,14 +23,16 @@ const { registerNotSerializable } = require("../util/serialization");
|
|
23
23
|
/** @typedef {import("../Compilation")} Compilation */
|
24
24
|
/** @typedef {import("../Compiler")} Compiler */
|
25
25
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
26
|
+
/** @typedef {import("../Module").BuildCallback} BuildCallback */
|
26
27
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
27
28
|
/** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
|
28
29
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
29
30
|
/** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
|
31
|
+
/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
|
30
32
|
/** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
|
31
33
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
34
|
+
/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
|
32
35
|
/** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
33
|
-
/** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
34
36
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
35
37
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
36
38
|
/** @typedef {import("../WebpackError")} WebpackError */
|
@@ -42,8 +44,8 @@ const { registerNotSerializable } = require("../util/serialization");
|
|
42
44
|
|
43
45
|
/**
|
44
46
|
* @typedef {object} BackendApi
|
45
|
-
* @property {
|
46
|
-
* @property {
|
47
|
+
* @property {(callback: (err?: (Error | null)) => void) => void} dispose
|
48
|
+
* @property {(module: Module) => ModuleResult} module
|
47
49
|
*/
|
48
50
|
|
49
51
|
const HMR_DEPENDENCY_TYPES = new Set([
|
@@ -54,7 +56,7 @@ const HMR_DEPENDENCY_TYPES = new Set([
|
|
54
56
|
]);
|
55
57
|
|
56
58
|
/**
|
57
|
-
* @param {
|
59
|
+
* @param {Options["test"]} test test option
|
58
60
|
* @param {Module} module the module
|
59
61
|
* @returns {boolean | null | string} true, if the module should be selected
|
60
62
|
*/
|
@@ -169,7 +171,7 @@ class LazyCompilationProxyModule extends Module {
|
|
169
171
|
|
170
172
|
/**
|
171
173
|
* @param {NeedBuildContext} context context info
|
172
|
-
* @param {
|
174
|
+
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
173
175
|
* @returns {void}
|
174
176
|
*/
|
175
177
|
needBuild(context, callback) {
|
@@ -181,7 +183,7 @@ class LazyCompilationProxyModule extends Module {
|
|
181
183
|
* @param {Compilation} compilation the compilation
|
182
184
|
* @param {ResolverWithOptions} resolver the resolver
|
183
185
|
* @param {InputFileSystem} fs the file system
|
184
|
-
* @param {
|
186
|
+
* @param {BuildCallback} callback callback function
|
185
187
|
* @returns {void}
|
186
188
|
*/
|
187
189
|
build(options, compilation, resolver, fs, callback) {
|
@@ -315,13 +317,13 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
315
317
|
|
316
318
|
/**
|
317
319
|
* @param {ModuleFactoryCreateData} data data object
|
318
|
-
* @param {
|
320
|
+
* @param {ModuleFactoryCallback} callback callback
|
319
321
|
* @returns {void}
|
320
322
|
*/
|
321
323
|
create(data, callback) {
|
322
|
-
const dependency =
|
323
|
-
|
324
|
-
|
324
|
+
const dependency =
|
325
|
+
/** @type {LazyCompilationDependency} */
|
326
|
+
(data.dependencies[0]);
|
325
327
|
callback(null, {
|
326
328
|
module: dependency.proxyModule.originalModule
|
327
329
|
});
|
@@ -331,7 +333,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
331
333
|
/**
|
332
334
|
* @callback BackendHandler
|
333
335
|
* @param {Compiler} compiler compiler
|
334
|
-
* @param {
|
336
|
+
* @param {(err: Error | null, backendApi?: BackendApi) => void} callback callback
|
335
337
|
* @returns {void}
|
336
338
|
*/
|
337
339
|
|
@@ -341,13 +343,19 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
341
343
|
* @returns {Promise<BackendApi>} backend
|
342
344
|
*/
|
343
345
|
|
346
|
+
/** @typedef {BackendHandler | PromiseBackendHandler} BackEnd */
|
347
|
+
|
348
|
+
/**
|
349
|
+
* @typedef {object} Options options
|
350
|
+
* @property {BackEnd} backend the backend
|
351
|
+
* @property {boolean=} entries
|
352
|
+
* @property {boolean=} imports
|
353
|
+
* @property {(RegExp | string | ((module: Module) => boolean))=} test additional filter for lazy compiled entrypoint modules
|
354
|
+
*/
|
355
|
+
|
344
356
|
class LazyCompilationPlugin {
|
345
357
|
/**
|
346
|
-
* @param {
|
347
|
-
* @param {BackendHandler | PromiseBackendHandler} options.backend the backend
|
348
|
-
* @param {boolean} options.entries true, when entries are lazy compiled
|
349
|
-
* @param {boolean} options.imports true, when import() modules are lazy compiled
|
350
|
-
* @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules
|
358
|
+
* @param {Options} options options
|
351
359
|
*/
|
352
360
|
constructor({ backend, entries, imports, test }) {
|
353
361
|
this.backend = backend;
|
@@ -386,7 +394,7 @@ class LazyCompilationPlugin {
|
|
386
394
|
(compilation, { normalModuleFactory }) => {
|
387
395
|
normalModuleFactory.hooks.module.tap(
|
388
396
|
"LazyCompilationPlugin",
|
389
|
-
(
|
397
|
+
(module, createData, resolveData) => {
|
390
398
|
if (
|
391
399
|
resolveData.dependencies.every(dep =>
|
392
400
|
HMR_DEPENDENCY_TYPES.has(dep.type)
|
@@ -407,7 +415,7 @@ class LazyCompilationPlugin {
|
|
407
415
|
hmrDep.request
|
408
416
|
)
|
409
417
|
);
|
410
|
-
if (!isReferringToDynamicImport) return;
|
418
|
+
if (!isReferringToDynamicImport) return module;
|
411
419
|
} else if (
|
412
420
|
!resolveData.dependencies.every(
|
413
421
|
dep =>
|
@@ -418,21 +426,21 @@ class LazyCompilationPlugin {
|
|
418
426
|
(this.entries && dep.type === "entry")
|
419
427
|
)
|
420
428
|
)
|
421
|
-
return;
|
429
|
+
return module;
|
422
430
|
if (
|
423
431
|
/webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test(
|
424
432
|
resolveData.request
|
425
433
|
) ||
|
426
|
-
!checkTest(this.test,
|
434
|
+
!checkTest(this.test, module)
|
427
435
|
)
|
428
|
-
return;
|
429
|
-
const moduleInfo = backend.module(
|
430
|
-
if (!moduleInfo) return;
|
436
|
+
return module;
|
437
|
+
const moduleInfo = backend.module(module);
|
438
|
+
if (!moduleInfo) return module;
|
431
439
|
const { client, data, active } = moduleInfo;
|
432
440
|
|
433
441
|
return new LazyCompilationProxyModule(
|
434
442
|
compiler.context,
|
435
|
-
|
443
|
+
module,
|
436
444
|
resolveData.request,
|
437
445
|
client,
|
438
446
|
data,
|
@@ -20,7 +20,7 @@ const {
|
|
20
20
|
/**
|
21
21
|
* @typedef {object} DeterministicModuleIdsPluginOptions
|
22
22
|
* @property {string=} context context relative to which module identifiers are computed
|
23
|
-
* @property {
|
23
|
+
* @property {((module: Module) => boolean)=} test selector function for modules
|
24
24
|
* @property {number=} maxLength maximum id length in digits (used as starting point)
|
25
25
|
* @property {number=} salt hash salt for ids
|
26
26
|
* @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { DEFAULTS } = require("../config/defaults");
|
8
9
|
const {
|
9
10
|
compareModulesByPreOrderIndexOrIdentifier
|
10
11
|
} = require("../util/comparators");
|
@@ -37,7 +38,7 @@ class HashedModuleIdsPlugin {
|
|
37
38
|
/** @type {HashedModuleIdsPluginOptions} */
|
38
39
|
this.options = {
|
39
40
|
context: undefined,
|
40
|
-
hashFunction:
|
41
|
+
hashFunction: DEFAULTS.HASH_FUNCTION,
|
41
42
|
hashDigest: "base64",
|
42
43
|
hashDigestLength: 4,
|
43
44
|
...options
|