webpack 5.59.0 → 5.71.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +1 -7
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +10 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +1 -2
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +179 -91
- package/lib/Compiler.js +86 -17
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +89 -44
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +27 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +41 -26
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +77 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +2 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +57 -11
- package/lib/asset/AssetGenerator.js +193 -63
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +36 -6
- package/lib/cache/PackFileCacheStrategy.js +7 -4
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +115 -19
- package/lib/config/normalization.js +9 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +440 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +13 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +82 -48
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +21 -9
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +23 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +254 -29
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -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 +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +628 -179
@@ -128,7 +128,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
128
128
|
loadersPrefix = "";
|
129
129
|
const idx = request.lastIndexOf("!");
|
130
130
|
if (idx >= 0) {
|
131
|
-
let loadersRequest = request.
|
131
|
+
let loadersRequest = request.slice(0, idx + 1);
|
132
132
|
let i;
|
133
133
|
for (
|
134
134
|
i = 0;
|
@@ -138,7 +138,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
138
138
|
loadersPrefix += "!";
|
139
139
|
}
|
140
140
|
loadersRequest = loadersRequest
|
141
|
-
.
|
141
|
+
.slice(i)
|
142
142
|
.replace(/!+$/, "")
|
143
143
|
.replace(/!!+/g, "!");
|
144
144
|
if (loadersRequest === "") {
|
@@ -146,7 +146,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
146
146
|
} else {
|
147
147
|
loaders = loadersRequest.split("!");
|
148
148
|
}
|
149
|
-
resource = request.
|
149
|
+
resource = request.slice(idx + 1);
|
150
150
|
} else {
|
151
151
|
loaders = [];
|
152
152
|
resource = request;
|
@@ -167,6 +167,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
167
167
|
asyncLib.parallel(
|
168
168
|
[
|
169
169
|
callback => {
|
170
|
+
const results = [];
|
171
|
+
const yield_ = obj => results.push(obj);
|
172
|
+
|
170
173
|
contextResolver.resolve(
|
171
174
|
{},
|
172
175
|
context,
|
@@ -174,11 +177,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
174
177
|
{
|
175
178
|
fileDependencies,
|
176
179
|
missingDependencies,
|
177
|
-
contextDependencies
|
180
|
+
contextDependencies,
|
181
|
+
yield: yield_
|
178
182
|
},
|
179
|
-
|
183
|
+
err => {
|
180
184
|
if (err) return callback(err);
|
181
|
-
callback(null,
|
185
|
+
callback(null, results);
|
182
186
|
}
|
183
187
|
);
|
184
188
|
},
|
@@ -213,15 +217,25 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
213
217
|
contextDependencies
|
214
218
|
});
|
215
219
|
}
|
216
|
-
|
220
|
+
let [contextResult, loaderResult] = result;
|
221
|
+
if (contextResult.length > 1) {
|
222
|
+
const first = contextResult[0];
|
223
|
+
contextResult = contextResult.filter(r => r.path);
|
224
|
+
if (contextResult.length === 0) contextResult.push(first);
|
225
|
+
}
|
217
226
|
this.hooks.afterResolve.callAsync(
|
218
227
|
{
|
219
228
|
addon:
|
220
229
|
loadersPrefix +
|
221
|
-
|
222
|
-
(
|
223
|
-
resource:
|
230
|
+
loaderResult.join("!") +
|
231
|
+
(loaderResult.length > 0 ? "!" : ""),
|
232
|
+
resource:
|
233
|
+
contextResult.length > 1
|
234
|
+
? contextResult.map(r => r.path)
|
235
|
+
: contextResult[0].path,
|
224
236
|
resolveDependencies: this.resolveDependencies.bind(this),
|
237
|
+
resourceQuery: contextResult[0].query,
|
238
|
+
resourceFragment: contextResult[0].fragment,
|
225
239
|
...beforeResolveResult
|
226
240
|
},
|
227
241
|
(err, result) => {
|
@@ -278,26 +292,27 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
278
292
|
} = options;
|
279
293
|
if (!regExp || !resource) return callback(null, []);
|
280
294
|
|
281
|
-
const addDirectoryChecked = (directory, visited, callback) => {
|
295
|
+
const addDirectoryChecked = (ctx, directory, visited, callback) => {
|
282
296
|
fs.realpath(directory, (err, realPath) => {
|
283
297
|
if (err) return callback(err);
|
284
298
|
if (visited.has(realPath)) return callback(null, []);
|
285
299
|
let recursionStack;
|
286
300
|
addDirectory(
|
301
|
+
ctx,
|
287
302
|
directory,
|
288
|
-
(dir, callback) => {
|
303
|
+
(_, dir, callback) => {
|
289
304
|
if (recursionStack === undefined) {
|
290
305
|
recursionStack = new Set(visited);
|
291
306
|
recursionStack.add(realPath);
|
292
307
|
}
|
293
|
-
addDirectoryChecked(dir, recursionStack, callback);
|
308
|
+
addDirectoryChecked(ctx, dir, recursionStack, callback);
|
294
309
|
},
|
295
310
|
callback
|
296
311
|
);
|
297
312
|
});
|
298
313
|
};
|
299
314
|
|
300
|
-
const addDirectory = (directory, addSubDirectory, callback) => {
|
315
|
+
const addDirectory = (ctx, directory, addSubDirectory, callback) => {
|
301
316
|
fs.readdir(directory, (err, files) => {
|
302
317
|
if (err) return callback(err);
|
303
318
|
const processedFiles = cmf.hooks.contextModuleFiles.call(
|
@@ -324,16 +339,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
324
339
|
|
325
340
|
if (stat.isDirectory()) {
|
326
341
|
if (!recursive) return callback();
|
327
|
-
addSubDirectory(subResource, callback);
|
342
|
+
addSubDirectory(ctx, subResource, callback);
|
328
343
|
} else if (
|
329
344
|
stat.isFile() &&
|
330
345
|
(!include || subResource.match(include))
|
331
346
|
) {
|
332
347
|
const obj = {
|
333
|
-
context:
|
348
|
+
context: ctx,
|
334
349
|
request:
|
335
|
-
"." +
|
336
|
-
subResource.substr(resource.length).replace(/\\/g, "/")
|
350
|
+
"." + subResource.slice(ctx.length).replace(/\\/g, "/")
|
337
351
|
};
|
338
352
|
|
339
353
|
this.hooks.alternativeRequests.callAsync(
|
@@ -345,11 +359,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
345
359
|
.filter(obj => regExp.test(obj.request))
|
346
360
|
.map(obj => {
|
347
361
|
const dep = new ContextElementDependency(
|
348
|
-
obj.request
|
362
|
+
`${obj.request}${resourceQuery}${resourceFragment}`,
|
349
363
|
obj.request,
|
350
364
|
typePrefix,
|
351
365
|
category,
|
352
|
-
referencedExports
|
366
|
+
referencedExports,
|
367
|
+
obj.context
|
353
368
|
);
|
354
369
|
dep.optional = true;
|
355
370
|
return dep;
|
@@ -382,12 +397,37 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
382
397
|
});
|
383
398
|
};
|
384
399
|
|
385
|
-
|
386
|
-
|
400
|
+
const addSubDirectory = (ctx, dir, callback) =>
|
401
|
+
addDirectory(ctx, dir, addSubDirectory, callback);
|
402
|
+
|
403
|
+
const visitResource = (resource, callback) => {
|
404
|
+
if (typeof fs.realpath === "function") {
|
405
|
+
addDirectoryChecked(resource, resource, new Set(), callback);
|
406
|
+
} else {
|
407
|
+
addDirectory(resource, resource, addSubDirectory, callback);
|
408
|
+
}
|
409
|
+
};
|
410
|
+
|
411
|
+
if (typeof resource === "string") {
|
412
|
+
visitResource(resource, callback);
|
387
413
|
} else {
|
388
|
-
|
389
|
-
|
390
|
-
|
414
|
+
asyncLib.map(resource, visitResource, (err, result) => {
|
415
|
+
if (err) return callback(err);
|
416
|
+
|
417
|
+
// result dependencies should have unique userRequest
|
418
|
+
// ordered by resolve result
|
419
|
+
const temp = new Set();
|
420
|
+
const res = [];
|
421
|
+
for (let i = 0; i < result.length; i++) {
|
422
|
+
const inner = result[i];
|
423
|
+
for (const el of inner) {
|
424
|
+
if (temp.has(el.userRequest)) continue;
|
425
|
+
res.push(el);
|
426
|
+
temp.add(el.userRequest);
|
427
|
+
}
|
428
|
+
}
|
429
|
+
callback(null, res);
|
430
|
+
});
|
391
431
|
}
|
392
432
|
}
|
393
433
|
};
|
package/lib/DelegatedModule.js
CHANGED
@@ -91,7 +91,7 @@ class DelegatedModule extends Module {
|
|
91
91
|
|
92
92
|
/**
|
93
93
|
* @param {NeedBuildContext} context context info
|
94
|
-
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
94
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
95
95
|
* @returns {void}
|
96
96
|
*/
|
97
97
|
needBuild(context, callback) {
|
@@ -29,7 +29,7 @@ class DelegatedModuleFactoryPlugin {
|
|
29
29
|
const [dependency] = data.dependencies;
|
30
30
|
const { request } = dependency;
|
31
31
|
if (request && request.startsWith(`${scope}/`)) {
|
32
|
-
const innerRequest = "." + request.
|
32
|
+
const innerRequest = "." + request.slice(scope.length);
|
33
33
|
let resolved;
|
34
34
|
if (innerRequest in this.options.content) {
|
35
35
|
resolved = this.options.content[innerRequest];
|
package/lib/Dependency.js
CHANGED
@@ -172,6 +172,23 @@ class Dependency {
|
|
172
172
|
this._loc = loc;
|
173
173
|
}
|
174
174
|
|
175
|
+
setLoc(startLine, startColumn, endLine, endColumn) {
|
176
|
+
this._locSL = startLine;
|
177
|
+
this._locSC = startColumn;
|
178
|
+
this._locEL = endLine;
|
179
|
+
this._locEC = endColumn;
|
180
|
+
this._locI = undefined;
|
181
|
+
this._locN = undefined;
|
182
|
+
this._loc = undefined;
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* @returns {string | undefined} a request context
|
187
|
+
*/
|
188
|
+
getContext() {
|
189
|
+
return undefined;
|
190
|
+
}
|
191
|
+
|
175
192
|
/**
|
176
193
|
* @returns {string | null} an identifier to merge equal requests
|
177
194
|
*/
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
9
9
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
10
|
+
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
10
11
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
11
12
|
/** @typedef {import("./Dependency")} Dependency */
|
12
13
|
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
@@ -28,8 +29,16 @@
|
|
28
29
|
* @property {RuntimeSpec} runtime current runtimes, for which code is generated
|
29
30
|
* @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
|
30
31
|
* @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
|
32
|
+
* @property {CodeGenerationResults} codeGenerationResults the code generation results
|
31
33
|
*/
|
32
34
|
|
35
|
+
/**
|
36
|
+
* @typedef {Object} CssDependencyTemplateContextExtras
|
37
|
+
* @property {Map<string, string>} cssExports the css exports
|
38
|
+
*/
|
39
|
+
|
40
|
+
/** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
|
41
|
+
|
33
42
|
class DependencyTemplate {
|
34
43
|
/* istanbul ignore next */
|
35
44
|
/**
|
@@ -57,7 +57,7 @@ class DependencyTemplates {
|
|
57
57
|
}
|
58
58
|
|
59
59
|
clone() {
|
60
|
-
const newInstance = new DependencyTemplates();
|
60
|
+
const newInstance = new DependencyTemplates(this._hashFunction);
|
61
61
|
newInstance._map = new Map(this._map);
|
62
62
|
newInstance._hash = this._hash;
|
63
63
|
return newInstance;
|
package/lib/DllModule.js
CHANGED
@@ -96,7 +96,7 @@ class DllModule extends Module {
|
|
96
96
|
|
97
97
|
/**
|
98
98
|
* @param {NeedBuildContext} context context info
|
99
|
-
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
99
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
100
100
|
* @returns {void}
|
101
101
|
*/
|
102
102
|
needBuild(context, callback) {
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -62,8 +62,10 @@ class EntryOptionPlugin {
|
|
62
62
|
runtime: desc.runtime,
|
63
63
|
layer: desc.layer,
|
64
64
|
dependOn: desc.dependOn,
|
65
|
+
baseUri: desc.baseUri,
|
65
66
|
publicPath: desc.publicPath,
|
66
67
|
chunkLoading: desc.chunkLoading,
|
68
|
+
asyncChunks: desc.asyncChunks,
|
67
69
|
wasmLoading: desc.wasmLoading,
|
68
70
|
library: desc.library
|
69
71
|
};
|
package/lib/ErrorHelpers.js
CHANGED
@@ -43,8 +43,8 @@ exports.cutOffMessage = (stack, message) => {
|
|
43
43
|
if (nextLine === -1) {
|
44
44
|
return stack === message ? "" : stack;
|
45
45
|
} else {
|
46
|
-
const firstLine = stack.
|
47
|
-
return firstLine === message ? stack.
|
46
|
+
const firstLine = stack.slice(0, nextLine);
|
47
|
+
return firstLine === message ? stack.slice(nextLine + 1) : stack;
|
48
48
|
}
|
49
49
|
};
|
50
50
|
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const { ConcatSource, RawSource } = require("webpack-sources");
|
9
9
|
const ExternalModule = require("./ExternalModule");
|
10
10
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
11
|
+
const RuntimeGlobals = require("./RuntimeGlobals");
|
11
12
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
12
13
|
|
13
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -77,7 +78,13 @@ class EvalDevToolModulePlugin {
|
|
77
78
|
.replace(/^\//, "")
|
78
79
|
);
|
79
80
|
const result = new RawSource(
|
80
|
-
`eval(${
|
81
|
+
`eval(${
|
82
|
+
compilation.outputOptions.trustedTypes
|
83
|
+
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
84
|
+
content + footer
|
85
|
+
)})`
|
86
|
+
: JSON.stringify(content + footer)
|
87
|
+
});`
|
81
88
|
);
|
82
89
|
cache.set(source, result);
|
83
90
|
return result;
|
@@ -95,6 +102,14 @@ class EvalDevToolModulePlugin {
|
|
95
102
|
hash.update("EvalDevToolModulePlugin");
|
96
103
|
hash.update("2");
|
97
104
|
});
|
105
|
+
if (compilation.outputOptions.trustedTypes) {
|
106
|
+
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
107
|
+
"EvalDevToolModulePlugin",
|
108
|
+
(module, set, context) => {
|
109
|
+
set.add(RuntimeGlobals.createScript);
|
110
|
+
}
|
111
|
+
);
|
112
|
+
}
|
98
113
|
});
|
99
114
|
}
|
100
115
|
}
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const { ConcatSource, RawSource } = require("webpack-sources");
|
9
9
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
10
10
|
const NormalModule = require("./NormalModule");
|
11
|
+
const RuntimeGlobals = require("./RuntimeGlobals");
|
11
12
|
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
12
13
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
13
14
|
const ConcatenatedModule = require("./optimize/ConcatenatedModule");
|
@@ -165,7 +166,15 @@ class EvalSourceMapDevToolPlugin {
|
|
165
166
|
) + `\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
|
166
167
|
|
167
168
|
return result(
|
168
|
-
new RawSource(
|
169
|
+
new RawSource(
|
170
|
+
`eval(${
|
171
|
+
compilation.outputOptions.trustedTypes
|
172
|
+
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
173
|
+
content + footer
|
174
|
+
)})`
|
175
|
+
: JSON.stringify(content + footer)
|
176
|
+
});`
|
177
|
+
)
|
169
178
|
);
|
170
179
|
}
|
171
180
|
);
|
@@ -181,6 +190,14 @@ class EvalSourceMapDevToolPlugin {
|
|
181
190
|
hash.update("EvalSourceMapDevToolPlugin");
|
182
191
|
hash.update("2");
|
183
192
|
});
|
193
|
+
if (compilation.outputOptions.trustedTypes) {
|
194
|
+
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
195
|
+
"EvalSourceMapDevToolPlugin",
|
196
|
+
(module, set, context) => {
|
197
|
+
set.add(RuntimeGlobals.createScript);
|
198
|
+
}
|
199
|
+
);
|
200
|
+
}
|
184
201
|
}
|
185
202
|
);
|
186
203
|
}
|
package/lib/ExportsInfo.js
CHANGED
@@ -291,15 +291,15 @@ class ExportsInfo {
|
|
291
291
|
}
|
292
292
|
}
|
293
293
|
for (const exportInfo of this._exports.values()) {
|
294
|
+
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
295
|
+
exportInfo.canMangleProvide = false;
|
296
|
+
changed = true;
|
297
|
+
}
|
294
298
|
if (excludeExports && excludeExports.has(exportInfo.name)) continue;
|
295
299
|
if (exportInfo.provided !== true && exportInfo.provided !== null) {
|
296
300
|
exportInfo.provided = null;
|
297
301
|
changed = true;
|
298
302
|
}
|
299
|
-
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
300
|
-
exportInfo.canMangleProvide = false;
|
301
|
-
changed = true;
|
302
|
-
}
|
303
303
|
if (targetKey) {
|
304
304
|
exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
|
305
305
|
}
|
package/lib/ExternalModule.js
CHANGED
@@ -53,6 +53,7 @@ const { register } = require("./util/serialization");
|
|
53
53
|
*/
|
54
54
|
|
55
55
|
const TYPES = new Set(["javascript"]);
|
56
|
+
const CSS_TYPES = new Set(["css-import"]);
|
56
57
|
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
57
58
|
const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
|
58
59
|
const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
|
@@ -392,7 +393,7 @@ class ExternalModule extends Module {
|
|
392
393
|
* @returns {Set<string>} types available (do not mutate)
|
393
394
|
*/
|
394
395
|
getSourceTypes() {
|
395
|
-
return TYPES;
|
396
|
+
return this.externalType === "css-import" ? CSS_TYPES : TYPES;
|
396
397
|
}
|
397
398
|
|
398
399
|
/**
|
@@ -409,7 +410,9 @@ class ExternalModule extends Module {
|
|
409
410
|
* @returns {boolean} true, if the chunk is ok for the module
|
410
411
|
*/
|
411
412
|
chunkCondition(chunk, { chunkGraph }) {
|
412
|
-
return
|
413
|
+
return this.externalType === "css-import"
|
414
|
+
? true
|
415
|
+
: chunkGraph.getNumberOfEntryModules(chunk) > 0;
|
413
416
|
}
|
414
417
|
|
415
418
|
/**
|
@@ -429,7 +432,7 @@ class ExternalModule extends Module {
|
|
429
432
|
|
430
433
|
/**
|
431
434
|
* @param {NeedBuildContext} context context info
|
432
|
-
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
435
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
433
436
|
* @returns {void}
|
434
437
|
*/
|
435
438
|
needBuild(context, callback) {
|
@@ -526,8 +529,14 @@ class ExternalModule extends Module {
|
|
526
529
|
return { request, externalType };
|
527
530
|
}
|
528
531
|
|
529
|
-
_getSourceData(
|
530
|
-
|
532
|
+
_getSourceData(
|
533
|
+
request,
|
534
|
+
externalType,
|
535
|
+
runtimeTemplate,
|
536
|
+
moduleGraph,
|
537
|
+
chunkGraph,
|
538
|
+
runtime
|
539
|
+
) {
|
531
540
|
switch (externalType) {
|
532
541
|
case "this":
|
533
542
|
case "window":
|
@@ -536,11 +545,12 @@ class ExternalModule extends Module {
|
|
536
545
|
case "global":
|
537
546
|
return getSourceForGlobalVariableExternal(
|
538
547
|
request,
|
539
|
-
runtimeTemplate.
|
548
|
+
runtimeTemplate.globalObject
|
540
549
|
);
|
541
550
|
case "commonjs":
|
542
551
|
case "commonjs2":
|
543
552
|
case "commonjs-module":
|
553
|
+
case "commonjs-static":
|
544
554
|
return getSourceForCommonJsExternal(request);
|
545
555
|
case "node-commonjs":
|
546
556
|
return this.buildInfo.module
|
@@ -613,60 +623,90 @@ class ExternalModule extends Module {
|
|
613
623
|
runtime,
|
614
624
|
concatenationScope
|
615
625
|
}) {
|
616
|
-
const
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
626
|
+
const { request, externalType } = this._getRequestAndExternalType();
|
627
|
+
switch (externalType) {
|
628
|
+
case "asset": {
|
629
|
+
const sources = new Map();
|
630
|
+
sources.set(
|
631
|
+
"javascript",
|
632
|
+
new RawSource(`module.exports = ${JSON.stringify(request)};`)
|
633
|
+
);
|
634
|
+
const data = new Map();
|
635
|
+
data.set("url", request);
|
636
|
+
return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
|
637
|
+
}
|
638
|
+
case "css-import": {
|
639
|
+
const sources = new Map();
|
640
|
+
sources.set(
|
641
|
+
"css-import",
|
642
|
+
new RawSource(`@import url(${JSON.stringify(request)});`)
|
643
|
+
);
|
644
|
+
return {
|
645
|
+
sources,
|
646
|
+
runtimeRequirements: EMPTY_RUNTIME_REQUIREMENTS
|
647
|
+
};
|
648
|
+
}
|
649
|
+
default: {
|
650
|
+
const sourceData = this._getSourceData(
|
651
|
+
request,
|
652
|
+
externalType,
|
653
|
+
runtimeTemplate,
|
654
|
+
moduleGraph,
|
655
|
+
chunkGraph,
|
656
|
+
runtime
|
657
|
+
);
|
622
658
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
659
|
+
let sourceString = sourceData.expression;
|
660
|
+
if (sourceData.iife)
|
661
|
+
sourceString = `(function() { return ${sourceString}; }())`;
|
662
|
+
if (concatenationScope) {
|
663
|
+
sourceString = `${
|
664
|
+
runtimeTemplate.supportsConst() ? "const" : "var"
|
665
|
+
} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
|
666
|
+
concatenationScope.registerNamespaceExport(
|
667
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
668
|
+
);
|
669
|
+
} else {
|
670
|
+
sourceString = `module.exports = ${sourceString};`;
|
671
|
+
}
|
672
|
+
if (sourceData.init)
|
673
|
+
sourceString = `${sourceData.init}\n${sourceString}`;
|
637
674
|
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
675
|
+
let data = undefined;
|
676
|
+
if (sourceData.chunkInitFragments) {
|
677
|
+
data = new Map();
|
678
|
+
data.set("chunkInitFragments", sourceData.chunkInitFragments);
|
679
|
+
}
|
643
680
|
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
681
|
+
const sources = new Map();
|
682
|
+
if (this.useSourceMap || this.useSimpleSourceMap) {
|
683
|
+
sources.set(
|
684
|
+
"javascript",
|
685
|
+
new OriginalSource(sourceString, this.identifier())
|
686
|
+
);
|
687
|
+
} else {
|
688
|
+
sources.set("javascript", new RawSource(sourceString));
|
689
|
+
}
|
690
|
+
|
691
|
+
let runtimeRequirements = sourceData.runtimeRequirements;
|
692
|
+
if (!concatenationScope) {
|
693
|
+
if (!runtimeRequirements) {
|
694
|
+
runtimeRequirements = RUNTIME_REQUIREMENTS;
|
695
|
+
} else {
|
696
|
+
const set = new Set(runtimeRequirements);
|
697
|
+
set.add(RuntimeGlobals.module);
|
698
|
+
runtimeRequirements = set;
|
699
|
+
}
|
700
|
+
}
|
653
701
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
set.add(RuntimeGlobals.module);
|
661
|
-
runtimeRequirements = set;
|
702
|
+
return {
|
703
|
+
sources,
|
704
|
+
runtimeRequirements:
|
705
|
+
runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
|
706
|
+
data
|
707
|
+
};
|
662
708
|
}
|
663
709
|
}
|
664
|
-
|
665
|
-
return {
|
666
|
-
sources,
|
667
|
-
runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
|
668
|
-
data
|
669
|
-
};
|
670
710
|
}
|
671
711
|
|
672
712
|
/**
|
@@ -89,8 +89,8 @@ class ExternalModuleFactoryPlugin {
|
|
89
89
|
UNSPECIFIED_EXTERNAL_TYPE_REGEXP.test(externalConfig)
|
90
90
|
) {
|
91
91
|
const idx = externalConfig.indexOf(" ");
|
92
|
-
type = externalConfig.
|
93
|
-
externalConfig = externalConfig.
|
92
|
+
type = externalConfig.slice(0, idx);
|
93
|
+
externalConfig = externalConfig.slice(idx + 1);
|
94
94
|
} else if (
|
95
95
|
Array.isArray(externalConfig) &&
|
96
96
|
externalConfig.length > 0 &&
|
@@ -98,9 +98,9 @@ class ExternalModuleFactoryPlugin {
|
|
98
98
|
) {
|
99
99
|
const firstItem = externalConfig[0];
|
100
100
|
const idx = firstItem.indexOf(" ");
|
101
|
-
type = firstItem.
|
101
|
+
type = firstItem.slice(0, idx);
|
102
102
|
externalConfig = [
|
103
|
-
firstItem.
|
103
|
+
firstItem.slice(idx + 1),
|
104
104
|
...externalConfig.slice(1)
|
105
105
|
];
|
106
106
|
}
|
@@ -117,7 +117,7 @@ class ExternalModuleFactoryPlugin {
|
|
117
117
|
|
118
118
|
/**
|
119
119
|
* @param {Externals} externals externals config
|
120
|
-
* @param {function(Error=, ExternalModule=): void} callback callback
|
120
|
+
* @param {function((Error | null)=, ExternalModule=): void} callback callback
|
121
121
|
* @returns {void}
|
122
122
|
*/
|
123
123
|
const handleExternals = (externals, callback) => {
|