webpack 5.108.4 → 5.109.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/lib/APIPlugin.js +48 -29
- package/lib/CacheFacade.js +8 -0
- package/lib/ChunkGroup.js +1 -0
- package/lib/CompatibilityPlugin.js +31 -29
- package/lib/Compilation.js +49 -4
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextModule.js +239 -6
- package/lib/ContextModuleFactory.js +139 -14
- package/lib/DefinePlugin.js +396 -101
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +107 -5
- package/lib/ExternalModuleFactoryPlugin.js +20 -1
- package/lib/FileSystemInfo.js +130 -74
- package/lib/HotModuleReplacementPlugin.js +18 -15
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +2 -2
- package/lib/ModuleTypeConstants.js +8 -1
- package/lib/MultiCompiler.js +13 -2
- package/lib/MultiWatching.js +1 -0
- package/lib/NodeStuffPlugin.js +51 -33
- package/lib/NormalModule.js +169 -401
- package/lib/NormalModuleFactory.js +76 -2
- package/lib/ProgressPlugin.js +211 -119
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RuntimeGlobals.js +47 -0
- package/lib/RuntimePlugin.js +33 -0
- package/lib/RuntimeTemplate.js +304 -16
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +24 -19
- package/lib/asset/AssetGenerator.js +110 -28
- package/lib/asset/AssetModulesPlugin.js +92 -2
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/cache/PackFileCacheStrategy.js +9 -3
- package/lib/config/browserslistTargetHandler.js +40 -0
- package/lib/config/defaults.js +219 -29
- package/lib/config/normalization.js +26 -0
- package/lib/config/target.js +9 -1
- package/lib/css/CssGenerator.js +40 -31
- package/lib/css/CssLoadingRuntimeModule.js +5 -1
- package/lib/css/CssModulesPlugin.js +13 -0
- package/lib/css/CssParser.js +594 -263
- package/lib/css/syntax.js +875 -462
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
- package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
- package/lib/dependencies/CommonJsExportsDependency.js +47 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/CommonJsRequireDependency.js +26 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
- package/lib/dependencies/CssIcssExportDependency.js +162 -71
- package/lib/dependencies/CssUrlDependency.js +35 -4
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
- package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
- package/lib/dependencies/HarmonyImportDependency.js +12 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
- package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/HtmlEntryDependency.js +797 -172
- package/lib/dependencies/HtmlSourceDependency.js +26 -0
- package/lib/dependencies/ImportDependency.js +43 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
- package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaPlugin.js +532 -180
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +80 -17
- package/lib/dependencies/ImportPhase.js +10 -8
- package/lib/dependencies/LoaderPlugin.js +5 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
- package/lib/dependencies/SystemPlugin.js +2 -4
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLDependency.js +141 -21
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
- package/lib/dependencies/WorkerDependency.js +86 -18
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/errors/ModuleParseError.js +39 -22
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
- package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
- package/lib/hmr/lazyCompilationBackend.js +32 -8
- package/lib/html/HtmlGenerator.js +887 -15
- package/lib/html/HtmlModule.js +2 -2
- package/lib/html/HtmlModulesPlugin.js +610 -166
- package/lib/html/HtmlParser.js +603 -247
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +1264 -661
- package/lib/ids/IdHelpers.js +1 -1
- package/lib/index.js +6 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +366 -48
- package/lib/javascript/JavascriptGenerator.js +197 -49
- package/lib/javascript/JavascriptModulesPlugin.js +178 -24
- package/lib/javascript/JavascriptParser.js +701 -355
- package/lib/javascript/JavascriptParserHelpers.js +3 -6
- package/lib/javascript/syntax.js +4380 -0
- package/lib/library/ModuleLibraryPlugin.js +38 -1
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +19 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +14 -0
- package/lib/optimize/ConcatenatedModule.js +120 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
- package/lib/optimize/InnerGraphPlugin.js +50 -30
- package/lib/optimize/ModuleConcatenationPlugin.js +69 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
- package/lib/prefetch/ResourceHintPlugin.js +663 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/RuleSetCompiler.js +114 -0
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
- package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
- package/lib/schemes/HttpUriPlugin.js +40 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -2
- package/lib/serialization/FileMiddleware.js +29 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +32 -3
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -2
- package/lib/stats/StatsFactory.js +15 -8
- package/lib/url/URLParserPlugin.js +66 -13
- package/lib/util/AsyncQueue.js +122 -72
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/StackedMap.js +122 -48
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/concatenate.js +40 -14
- package/lib/util/createHooksRegistry.js +13 -5
- package/lib/util/dataURL.js +2 -2
- package/lib/util/deterministicGrouping.js +7 -5
- package/lib/util/formatSize.js +6 -2
- package/lib/util/globUtils.js +710 -0
- package/lib/util/identifier.js +23 -6
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +88 -71
- package/lib/util/magicComment.js +121 -25
- package/lib/util/numberHash.js +2 -2
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
- package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
- package/lib/web/FetchCompileWasmPlugin.js +14 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
- package/lib/webpack.js +65 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
- package/module.d.ts +21 -0
- package/package.json +13 -12
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +759 -36
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +17 -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/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1213 -96
|
@@ -41,6 +41,7 @@ const NAMED_PRESETS = {
|
|
|
41
41
|
relatedAssets: true,
|
|
42
42
|
entrypoints: true,
|
|
43
43
|
chunkGroups: true,
|
|
44
|
+
chunkGroupResourceHints: true,
|
|
44
45
|
ids: true,
|
|
45
46
|
modules: false,
|
|
46
47
|
chunks: true,
|
|
@@ -210,6 +211,7 @@ const DEFAULTS = {
|
|
|
210
211
|
chunkGroups: OFF_FOR_TO_STRING,
|
|
211
212
|
chunkGroupAuxiliary: OFF_FOR_TO_STRING,
|
|
212
213
|
chunkGroupChildren: OFF_FOR_TO_STRING,
|
|
214
|
+
chunkGroupResourceHints: OFF_FOR_TO_STRING,
|
|
213
215
|
chunkGroupMaxAssets: (o, { forToString }) => (forToString ? 5 : Infinity),
|
|
214
216
|
chunks: OFF_FOR_TO_STRING,
|
|
215
217
|
chunkRelations: OFF_FOR_TO_STRING,
|
|
@@ -508,8 +508,18 @@ const MODULE_SIMPLE_PRINTERS = {
|
|
|
508
508
|
"module.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
|
|
509
509
|
"module.depth": (depth, { formatFlag }) =>
|
|
510
510
|
depth !== null ? formatFlag(`depth ${depth}`) : undefined,
|
|
511
|
-
"module.cacheable": (cacheable, { formatFlag, red }) =>
|
|
512
|
-
cacheable === false
|
|
511
|
+
"module.cacheable": (cacheable, { formatFlag, red, module }) =>
|
|
512
|
+
cacheable === false
|
|
513
|
+
? red(
|
|
514
|
+
formatFlag(
|
|
515
|
+
module.notCacheableReasons && module.notCacheableReasons.length > 0
|
|
516
|
+
? `not cacheable: ${module.notCacheableReasons.join(", ")}`
|
|
517
|
+
: "not cacheable"
|
|
518
|
+
)
|
|
519
|
+
)
|
|
520
|
+
: undefined,
|
|
521
|
+
// rendered as part of the "module.cacheable" flag
|
|
522
|
+
"module.notCacheableReasons": () => undefined,
|
|
513
523
|
"module.orphan": (orphan, { formatFlag, yellow }) =>
|
|
514
524
|
orphan ? yellow(formatFlag("orphan")) : undefined,
|
|
515
525
|
// "module.runtime": (runtime, { formatFlag, yellow }) =>
|
|
@@ -310,23 +310,30 @@ class StatsFactory {
|
|
|
310
310
|
false
|
|
311
311
|
);
|
|
312
312
|
|
|
313
|
-
//
|
|
313
|
+
// reuse one item context; create() spreads it synchronously, so mutating
|
|
314
|
+
// `_index`/the name key between items is safe and skips a per-item spread
|
|
315
|
+
/** @type {StatsFactoryContext} */
|
|
316
|
+
const itemContext = { ...context };
|
|
317
|
+
const itemNameType = `${type}[]`;
|
|
318
|
+
/** @type {string | void} */
|
|
319
|
+
let prevItemName;
|
|
314
320
|
let resultItems = items2.map((item, i) => {
|
|
315
|
-
|
|
316
|
-
const itemContext = {
|
|
317
|
-
...context,
|
|
318
|
-
_index: i
|
|
319
|
-
};
|
|
321
|
+
itemContext._index = i;
|
|
320
322
|
|
|
321
323
|
// run getItemName
|
|
322
324
|
const itemName = this._forEachLevel(
|
|
323
325
|
this.hooks.getItemName,
|
|
324
326
|
this._caches.getItemName,
|
|
325
|
-
|
|
327
|
+
itemNameType,
|
|
326
328
|
(h) => h.call(item, itemContext)
|
|
327
329
|
);
|
|
330
|
+
// drop a previous item's name key before adding this one's
|
|
331
|
+
if (prevItemName !== undefined && prevItemName !== itemName) {
|
|
332
|
+
delete itemContext[prevItemName];
|
|
333
|
+
}
|
|
328
334
|
if (itemName) itemContext[itemName] = item;
|
|
329
|
-
|
|
335
|
+
prevItemName = itemName;
|
|
336
|
+
const innerType = itemName ? `${type}[].${itemName}` : itemNameType;
|
|
330
337
|
|
|
331
338
|
// run getItemFactory
|
|
332
339
|
const itemFactory =
|
|
@@ -9,6 +9,9 @@ const { pathToFileURL } = require("url");
|
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const ConstDependency = require("../dependencies/ConstDependency");
|
|
11
11
|
const ContextDependencyHelpers = require("../dependencies/ContextDependencyHelpers");
|
|
12
|
+
const {
|
|
13
|
+
isImportMetaFieldEnabled
|
|
14
|
+
} = require("../dependencies/ImportMetaPlugin");
|
|
12
15
|
const URLContextDependency = require("../dependencies/URLContextDependency");
|
|
13
16
|
const URLDependency = require("../dependencies/URLDependency");
|
|
14
17
|
const CommentCompilationWarning = require("../errors/CommentCompilationWarning");
|
|
@@ -16,6 +19,7 @@ const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning")
|
|
|
16
19
|
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
|
17
20
|
const { approve } = require("../javascript/JavascriptParserHelpers");
|
|
18
21
|
const { getInnerGraphUtils } = require("../optimize/InnerGraph");
|
|
22
|
+
const ResourceHintPlugin = require("../prefetch/ResourceHintPlugin");
|
|
19
23
|
|
|
20
24
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
|
21
25
|
/** @typedef {import("estree").NewExpression} NewExpressionNode */
|
|
@@ -78,7 +82,7 @@ const keepNewURL = (parser, expr) => {
|
|
|
78
82
|
/** @type {Range} */ (arg2.range),
|
|
79
83
|
[RuntimeGlobals.baseURI]
|
|
80
84
|
);
|
|
81
|
-
dep.loc =
|
|
85
|
+
dep.loc = parser.getLocation(expr);
|
|
82
86
|
parser.state.module.addPresentationalDependency(dep);
|
|
83
87
|
};
|
|
84
88
|
|
|
@@ -89,9 +93,10 @@ const getEvaluatedExprCache = new WeakMap();
|
|
|
89
93
|
* Gets evaluated expr.
|
|
90
94
|
* @param {NewExpressionNode} expr expression
|
|
91
95
|
* @param {JavascriptParser} parser parser parser
|
|
96
|
+
* @param {boolean} importMetaUrlEnabled true when import.meta.url should be handled
|
|
92
97
|
* @returns {BasicEvaluatedExpression | undefined} basic evaluated expression
|
|
93
98
|
*/
|
|
94
|
-
const getEvaluatedExpr = (expr, parser) => {
|
|
99
|
+
const getEvaluatedExpr = (expr, parser, importMetaUrlEnabled) => {
|
|
95
100
|
let result = getEvaluatedExprCache.get(expr);
|
|
96
101
|
if (result !== undefined) return result;
|
|
97
102
|
|
|
@@ -107,7 +112,9 @@ const getEvaluatedExpr = (expr, parser) => {
|
|
|
107
112
|
if (arg2.type !== "MemberExpression" || arg1.type === "SpreadElement") {
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
|
-
if (!isMetaUrl(parser, arg2))
|
|
115
|
+
if (!importMetaUrlEnabled || !isMetaUrl(parser, arg2)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
111
118
|
|
|
112
119
|
return parser.evaluateExpression(arg1);
|
|
113
120
|
};
|
|
@@ -118,6 +125,13 @@ const getEvaluatedExpr = (expr, parser) => {
|
|
|
118
125
|
return result;
|
|
119
126
|
};
|
|
120
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {object} ResolvedResourceHints
|
|
130
|
+
* @property {boolean=} prefetch project-wide prefetch default
|
|
131
|
+
* @property {boolean=} preload project-wide preload default
|
|
132
|
+
* @property {("low" | "high" | "auto" | false)=} fetchPriority project-wide fetchPriority default
|
|
133
|
+
*/
|
|
134
|
+
|
|
121
135
|
class URLParserPlugin {
|
|
122
136
|
/**
|
|
123
137
|
* Creates an instance of URLParserPlugin.
|
|
@@ -135,10 +149,18 @@ class URLParserPlugin {
|
|
|
135
149
|
*/
|
|
136
150
|
apply(parser) {
|
|
137
151
|
const relative = this.options.url === "relative";
|
|
152
|
+
const importMetaUrlEnabled = isImportMetaFieldEnabled(
|
|
153
|
+
this.options.importMeta,
|
|
154
|
+
"url"
|
|
155
|
+
);
|
|
138
156
|
|
|
139
157
|
parser.hooks.canRename.for("URL").tap(PLUGIN_NAME, approve);
|
|
140
158
|
parser.hooks.evaluateNewExpression.for("URL").tap(PLUGIN_NAME, (expr) => {
|
|
141
|
-
const evaluatedExpr = getEvaluatedExpr(
|
|
159
|
+
const evaluatedExpr = getEvaluatedExpr(
|
|
160
|
+
expr,
|
|
161
|
+
parser,
|
|
162
|
+
importMetaUrlEnabled
|
|
163
|
+
);
|
|
142
164
|
const request = evaluatedExpr && evaluatedExpr.asString();
|
|
143
165
|
|
|
144
166
|
if (!request) return;
|
|
@@ -159,7 +181,7 @@ class URLParserPlugin {
|
|
|
159
181
|
parser.state.module.addWarning(
|
|
160
182
|
new CommentCompilationWarning(
|
|
161
183
|
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
|
162
|
-
|
|
184
|
+
parser.getLocation(comment)
|
|
163
185
|
)
|
|
164
186
|
);
|
|
165
187
|
}
|
|
@@ -170,7 +192,7 @@ class URLParserPlugin {
|
|
|
170
192
|
parser.state.module.addWarning(
|
|
171
193
|
new UnsupportedFeatureWarning(
|
|
172
194
|
`\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
|
|
173
|
-
|
|
195
|
+
parser.getLocation(expr)
|
|
174
196
|
)
|
|
175
197
|
);
|
|
176
198
|
return;
|
|
@@ -179,7 +201,11 @@ class URLParserPlugin {
|
|
|
179
201
|
|
|
180
202
|
const [, arg2] = expr.arguments;
|
|
181
203
|
|
|
182
|
-
if (
|
|
204
|
+
if (
|
|
205
|
+
arg2.type !== "MemberExpression" ||
|
|
206
|
+
!importMetaUrlEnabled ||
|
|
207
|
+
!isMetaUrl(parser, arg2)
|
|
208
|
+
) {
|
|
183
209
|
return;
|
|
184
210
|
}
|
|
185
211
|
|
|
@@ -189,7 +215,11 @@ class URLParserPlugin {
|
|
|
189
215
|
}
|
|
190
216
|
}
|
|
191
217
|
|
|
192
|
-
const evaluatedExpr = getEvaluatedExpr(
|
|
218
|
+
const evaluatedExpr = getEvaluatedExpr(
|
|
219
|
+
expr,
|
|
220
|
+
parser,
|
|
221
|
+
importMetaUrlEnabled
|
|
222
|
+
);
|
|
193
223
|
if (!evaluatedExpr) return;
|
|
194
224
|
|
|
195
225
|
/** @type {string | undefined} */
|
|
@@ -213,8 +243,27 @@ class URLParserPlugin {
|
|
|
213
243
|
/** @type {Range} */ (expr.range),
|
|
214
244
|
relative
|
|
215
245
|
);
|
|
216
|
-
dep.loc =
|
|
246
|
+
dep.loc = parser.getLocation(expr);
|
|
247
|
+
// `parser.javascript.urlHints` provides project-wide defaults
|
|
248
|
+
// (resolved per-request, with `test` / `include` / `exclude`
|
|
249
|
+
// matching); a per-URL magic comment for the same hint wins
|
|
250
|
+
// when both are set.
|
|
251
|
+
ResourceHintPlugin.applyResourceHints(
|
|
252
|
+
dep,
|
|
253
|
+
this.options.urlHints,
|
|
254
|
+
request,
|
|
255
|
+
importOptions,
|
|
256
|
+
parser.state.module,
|
|
257
|
+
parser.getLocation(expr)
|
|
258
|
+
);
|
|
217
259
|
parser.state.current.addDependency(dep);
|
|
260
|
+
// For ESM module output the template embeds the asset's resolved
|
|
261
|
+
// filename, so the asset must be code-generated first. Only added in
|
|
262
|
+
// that mode — a code-gen dependency on an asset that a later watch
|
|
263
|
+
// rebuild leaves unaffected can otherwise deadlock the scheduler.
|
|
264
|
+
if (parser.state.compilation.options.output.module) {
|
|
265
|
+
parser.state.module.addCodeGenerationDependency(dep);
|
|
266
|
+
}
|
|
218
267
|
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
219
268
|
parser.state,
|
|
220
269
|
(e) => (dep.usedByExports = e)
|
|
@@ -239,7 +288,7 @@ class URLParserPlugin {
|
|
|
239
288
|
parser.state.module.addWarning(
|
|
240
289
|
new UnsupportedFeatureWarning(
|
|
241
290
|
`\`webpackInclude\` expected a regular expression, but received: ${importOptions.webpackInclude}.`,
|
|
242
|
-
|
|
291
|
+
parser.getLocation(expr)
|
|
243
292
|
)
|
|
244
293
|
);
|
|
245
294
|
} else {
|
|
@@ -254,7 +303,7 @@ class URLParserPlugin {
|
|
|
254
303
|
parser.state.module.addWarning(
|
|
255
304
|
new UnsupportedFeatureWarning(
|
|
256
305
|
`\`webpackExclude\` expected a regular expression, but received: ${importOptions.webpackExclude}.`,
|
|
257
|
-
|
|
306
|
+
parser.getLocation(expr)
|
|
258
307
|
)
|
|
259
308
|
);
|
|
260
309
|
} else {
|
|
@@ -278,7 +327,7 @@ class URLParserPlugin {
|
|
|
278
327
|
parser
|
|
279
328
|
);
|
|
280
329
|
if (!dep) return;
|
|
281
|
-
dep.loc =
|
|
330
|
+
dep.loc = parser.getLocation(expr);
|
|
282
331
|
dep.optional = Boolean(parser.scope.inTry);
|
|
283
332
|
parser.state.current.addDependency(dep);
|
|
284
333
|
return true;
|
|
@@ -290,7 +339,11 @@ class URLParserPlugin {
|
|
|
290
339
|
const calleeInfo = parser.getFreeInfoFromVariable(callee.name);
|
|
291
340
|
if (!calleeInfo || calleeInfo.name !== "URL") return;
|
|
292
341
|
|
|
293
|
-
const evaluatedExpr = getEvaluatedExpr(
|
|
342
|
+
const evaluatedExpr = getEvaluatedExpr(
|
|
343
|
+
expr,
|
|
344
|
+
parser,
|
|
345
|
+
importMetaUrlEnabled
|
|
346
|
+
);
|
|
294
347
|
const request = evaluatedExpr && evaluatedExpr.asString();
|
|
295
348
|
|
|
296
349
|
if (request) return true;
|
package/lib/util/AsyncQueue.js
CHANGED
|
@@ -159,6 +159,11 @@ class AsyncQueue {
|
|
|
159
159
|
*/
|
|
160
160
|
add(item, callback) {
|
|
161
161
|
if (this._stopped) return callback(new WebpackError("Queue was stopped"));
|
|
162
|
+
// skip async hook dispatch when unused — this runs per module × queue
|
|
163
|
+
if (!this.hooks.beforeAdd.isUsed()) {
|
|
164
|
+
this._add(item, callback);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
162
167
|
this.hooks.beforeAdd.callAsync(item, (err) => {
|
|
163
168
|
if (err) {
|
|
164
169
|
callback(
|
|
@@ -166,42 +171,52 @@ class AsyncQueue {
|
|
|
166
171
|
);
|
|
167
172
|
return;
|
|
168
173
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
this._add(item, callback);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Processes the provided item, after the beforeAdd hook.
|
|
180
|
+
* @param {T} item an item
|
|
181
|
+
* @param {Callback<R>} callback callback function
|
|
182
|
+
* @returns {void}
|
|
183
|
+
*/
|
|
184
|
+
_add(item, callback) {
|
|
185
|
+
const key = this._getKey(item);
|
|
186
|
+
const entry = this._entries.get(key);
|
|
187
|
+
if (entry !== undefined) {
|
|
188
|
+
if (entry.state === DONE_STATE) {
|
|
189
|
+
if (inHandleResult++ > 3) {
|
|
190
|
+
process.nextTick(() => callback(entry.error, entry.result));
|
|
181
191
|
} else {
|
|
182
|
-
entry.
|
|
192
|
+
callback(entry.error, entry.result);
|
|
183
193
|
}
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this._stopped) {
|
|
188
|
-
this.hooks.added.call(item);
|
|
189
|
-
this._root._activeTasks++;
|
|
190
|
-
process.nextTick(() =>
|
|
191
|
-
this._handleResult(newEntry, new WebpackError("Queue was stopped"))
|
|
192
|
-
);
|
|
194
|
+
inHandleResult--;
|
|
195
|
+
} else if (entry.callbacks === undefined) {
|
|
196
|
+
entry.callbacks = [callback];
|
|
193
197
|
} else {
|
|
194
|
-
|
|
195
|
-
this._queued.enqueue(newEntry);
|
|
196
|
-
const root = this._root;
|
|
197
|
-
root._needProcessing = true;
|
|
198
|
-
if (root._willEnsureProcessing === false) {
|
|
199
|
-
root._willEnsureProcessing = true;
|
|
200
|
-
setImmediate(root._ensureProcessing);
|
|
201
|
-
}
|
|
202
|
-
this.hooks.added.call(item);
|
|
198
|
+
entry.callbacks.push(callback);
|
|
203
199
|
}
|
|
204
|
-
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const newEntry = new AsyncQueueEntry(item, callback);
|
|
203
|
+
if (this._stopped) {
|
|
204
|
+
this.hooks.added.call(item);
|
|
205
|
+
this._root._activeTasks++;
|
|
206
|
+
process.nextTick(() =>
|
|
207
|
+
this._handleResult(newEntry, new WebpackError("Queue was stopped"))
|
|
208
|
+
);
|
|
209
|
+
} else {
|
|
210
|
+
this._entries.set(key, newEntry);
|
|
211
|
+
this._queued.enqueue(newEntry);
|
|
212
|
+
const root = this._root;
|
|
213
|
+
root._needProcessing = true;
|
|
214
|
+
if (root._willEnsureProcessing === false) {
|
|
215
|
+
root._willEnsureProcessing = true;
|
|
216
|
+
setImmediate(root._ensureProcessing);
|
|
217
|
+
}
|
|
218
|
+
this.hooks.added.call(item);
|
|
219
|
+
}
|
|
205
220
|
}
|
|
206
221
|
|
|
207
222
|
/**
|
|
@@ -357,6 +372,11 @@ class AsyncQueue {
|
|
|
357
372
|
* @returns {void}
|
|
358
373
|
*/
|
|
359
374
|
_startProcessing(entry) {
|
|
375
|
+
// skip async hook dispatch when unused — this runs per module × queue
|
|
376
|
+
if (!this.hooks.beforeStart.isUsed()) {
|
|
377
|
+
this._startProcessing2(entry);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
360
380
|
this.hooks.beforeStart.callAsync(entry.item, (err) => {
|
|
361
381
|
if (err) {
|
|
362
382
|
this._handleResult(
|
|
@@ -365,20 +385,29 @@ class AsyncQueue {
|
|
|
365
385
|
);
|
|
366
386
|
return;
|
|
367
387
|
}
|
|
368
|
-
|
|
369
|
-
try {
|
|
370
|
-
this._processor(entry.item, (e, r) => {
|
|
371
|
-
inCallback = true;
|
|
372
|
-
this._handleResult(entry, e, r);
|
|
373
|
-
});
|
|
374
|
-
} catch (err) {
|
|
375
|
-
if (inCallback) throw err;
|
|
376
|
-
this._handleResult(entry, /** @type {WebpackError} */ (err), null);
|
|
377
|
-
}
|
|
378
|
-
this.hooks.started.call(entry.item);
|
|
388
|
+
this._startProcessing2(entry);
|
|
379
389
|
});
|
|
380
390
|
}
|
|
381
391
|
|
|
392
|
+
/**
|
|
393
|
+
* Processes the provided entry, after the beforeStart hook.
|
|
394
|
+
* @param {AsyncQueueEntry<T, K, R>} entry the entry
|
|
395
|
+
* @returns {void}
|
|
396
|
+
*/
|
|
397
|
+
_startProcessing2(entry) {
|
|
398
|
+
let inCallback = false;
|
|
399
|
+
try {
|
|
400
|
+
this._processor(entry.item, (e, r) => {
|
|
401
|
+
inCallback = true;
|
|
402
|
+
this._handleResult(entry, e, r);
|
|
403
|
+
});
|
|
404
|
+
} catch (err) {
|
|
405
|
+
if (inCallback) throw err;
|
|
406
|
+
this._handleResult(entry, /** @type {WebpackError} */ (err), null);
|
|
407
|
+
}
|
|
408
|
+
this.hooks.started.call(entry.item);
|
|
409
|
+
}
|
|
410
|
+
|
|
382
411
|
/**
|
|
383
412
|
* Processes the provided entry.
|
|
384
413
|
* @param {AsyncQueueEntry<T, K, R>} entry the entry
|
|
@@ -387,45 +416,66 @@ class AsyncQueue {
|
|
|
387
416
|
* @returns {void}
|
|
388
417
|
*/
|
|
389
418
|
_handleResult(entry, err, result) {
|
|
419
|
+
// skip async hook dispatch when unused — this runs per module × queue
|
|
420
|
+
if (!this.hooks.result.isUsed()) {
|
|
421
|
+
this._handleResult2(entry, err, result);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
390
424
|
this.hooks.result.callAsync(entry.item, err, result, (hookError) => {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
425
|
+
this._handleResult2(
|
|
426
|
+
entry,
|
|
427
|
+
hookError
|
|
428
|
+
? makeWebpackError(
|
|
429
|
+
hookError,
|
|
430
|
+
`AsyncQueue(${this._name}).hooks.result`
|
|
431
|
+
)
|
|
432
|
+
: err,
|
|
433
|
+
result
|
|
434
|
+
);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
402
437
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Finalizes the provided entry, after the result hook.
|
|
440
|
+
* @param {AsyncQueueEntry<T, K, R>} entry the entry
|
|
441
|
+
* @param {(WebpackError | null)=} error error, if any
|
|
442
|
+
* @param {(R | null)=} result result, if any
|
|
443
|
+
* @returns {void}
|
|
444
|
+
*/
|
|
445
|
+
_handleResult2(entry, error, result) {
|
|
446
|
+
const callback = /** @type {Callback<R>} */ (entry.callback);
|
|
447
|
+
const callbacks = entry.callbacks;
|
|
448
|
+
entry.state = DONE_STATE;
|
|
449
|
+
entry.callback = undefined;
|
|
450
|
+
entry.callbacks = undefined;
|
|
451
|
+
entry.result = result;
|
|
452
|
+
entry.error = error;
|
|
409
453
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
} else {
|
|
454
|
+
const root = this._root;
|
|
455
|
+
root._activeTasks--;
|
|
456
|
+
if (root._willEnsureProcessing === false && root._needProcessing) {
|
|
457
|
+
root._willEnsureProcessing = true;
|
|
458
|
+
setImmediate(root._ensureProcessing);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (inHandleResult++ > 3) {
|
|
462
|
+
process.nextTick(() => {
|
|
420
463
|
callback(error, result);
|
|
421
464
|
if (callbacks !== undefined) {
|
|
422
465
|
for (const callback of callbacks) {
|
|
423
466
|
callback(error, result);
|
|
424
467
|
}
|
|
425
468
|
}
|
|
469
|
+
});
|
|
470
|
+
} else {
|
|
471
|
+
callback(error, result);
|
|
472
|
+
if (callbacks !== undefined) {
|
|
473
|
+
for (const callback of callbacks) {
|
|
474
|
+
callback(error, result);
|
|
475
|
+
}
|
|
426
476
|
}
|
|
427
|
-
|
|
428
|
-
|
|
477
|
+
}
|
|
478
|
+
inHandleResult--;
|
|
429
479
|
}
|
|
430
480
|
|
|
431
481
|
clear() {
|
package/lib/util/SetHelpers.js
CHANGED
|
@@ -41,7 +41,7 @@ const intersect = (sets) => {
|
|
|
41
41
|
* @template T
|
|
42
42
|
* @param {Set<T>} bigSet a Set which contains the original elements to compare against
|
|
43
43
|
* @param {Set<T>} smallSet the set whose elements might be contained inside of bigSet
|
|
44
|
-
* @returns {boolean} returns true if
|
|
44
|
+
* @returns {boolean} returns true if bigSet contains all elements inside of smallSet
|
|
45
45
|
*/
|
|
46
46
|
const isSubset = (bigSet, smallSet) => {
|
|
47
47
|
if (bigSet.size < smallSet.size) return false;
|