webpack 5.69.1 → 5.72.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/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/BannerPlugin.js +12 -4
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +93 -6
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +64 -18
- package/lib/Compilation.js +51 -25
- package/lib/Compiler.js +16 -3
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +121 -34
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +7 -0
- package/lib/EntryOptionPlugin.js +1 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/ExportsInfo.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +4 -4
- package/lib/FileSystemInfo.js +8 -0
- package/lib/Generator.js +1 -0
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +3 -3
- package/lib/ModuleHashingError.js +29 -0
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +26 -20
- package/lib/NormalModuleFactory.js +17 -10
- package/lib/ProgressPlugin.js +3 -4
- package/lib/RuntimePlugin.js +18 -0
- package/lib/RuntimeTemplate.js +1 -0
- package/lib/WebpackOptionsApply.js +2 -0
- package/lib/asset/AssetGenerator.js +155 -40
- package/lib/asset/AssetParser.js +1 -0
- package/lib/asset/AssetSourceGenerator.js +31 -6
- package/lib/asset/AssetSourceParser.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +8 -4
- package/lib/cache/ResolverCachePlugin.js +89 -28
- package/lib/config/browserslistTargetHandler.js +3 -5
- package/lib/config/defaults.js +9 -1
- package/lib/config/normalization.js +1 -0
- package/lib/container/RemoteRuntimeModule.js +8 -7
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextElementDependency.js +33 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +127 -43
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -8
- 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/LoaderPlugin.js +2 -0
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +2 -2
- package/lib/ids/IdHelpers.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/JavascriptParser.js +66 -40
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
- package/lib/optimize/ConcatenatedModule.js +2 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +20 -1
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/schemes/HttpUriPlugin.js +44 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/internalSerializables.js +4 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +17 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
- package/module.d.ts +15 -0
- package/package.json +2 -2
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +202 -84
package/lib/ContextModule.js
CHANGED
@@ -19,7 +19,11 @@ const {
|
|
19
19
|
keepOriginalOrder,
|
20
20
|
compareModulesById
|
21
21
|
} = require("./util/comparators");
|
22
|
-
const {
|
22
|
+
const {
|
23
|
+
contextify,
|
24
|
+
parseResource,
|
25
|
+
makePathsRelative
|
26
|
+
} = require("./util/identifier");
|
23
27
|
const makeSerializable = require("./util/makeSerializable");
|
24
28
|
|
25
29
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -61,7 +65,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
61
65
|
|
62
66
|
/**
|
63
67
|
* @typedef {Object} ContextModuleOptionsExtras
|
64
|
-
* @property {string} resource
|
68
|
+
* @property {false|string|string[]} resource
|
65
69
|
* @property {string=} resourceQuery
|
66
70
|
* @property {string=} resourceFragment
|
67
71
|
* @property {TODO} resolveOptions
|
@@ -92,23 +96,36 @@ class ContextModule extends Module {
|
|
92
96
|
* @param {ContextModuleOptions} options options object
|
93
97
|
*/
|
94
98
|
constructor(resolveDependencies, options) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
if (!options || typeof options.resource === "string") {
|
100
|
+
const parsed = parseResource(
|
101
|
+
options ? /** @type {string} */ (options.resource) : ""
|
102
|
+
);
|
103
|
+
const resource = parsed.path;
|
104
|
+
const resourceQuery = (options && options.resourceQuery) || parsed.query;
|
105
|
+
const resourceFragment =
|
106
|
+
(options && options.resourceFragment) || parsed.fragment;
|
107
|
+
|
108
|
+
super("javascript/dynamic", resource);
|
109
|
+
/** @type {ContextModuleOptions} */
|
110
|
+
this.options = {
|
111
|
+
...options,
|
112
|
+
resource,
|
113
|
+
resourceQuery,
|
114
|
+
resourceFragment
|
115
|
+
};
|
116
|
+
} else {
|
117
|
+
super("javascript/dynamic");
|
118
|
+
/** @type {ContextModuleOptions} */
|
119
|
+
this.options = {
|
120
|
+
...options,
|
121
|
+
resource: options.resource,
|
122
|
+
resourceQuery: options.resourceQuery || "",
|
123
|
+
resourceFragment: options.resourceFragment || ""
|
124
|
+
};
|
125
|
+
}
|
102
126
|
|
103
127
|
// Info from Factory
|
104
128
|
this.resolveDependencies = resolveDependencies;
|
105
|
-
/** @type {ContextModuleOptions} */
|
106
|
-
this.options = {
|
107
|
-
...options,
|
108
|
-
resource,
|
109
|
-
resourceQuery,
|
110
|
-
resourceFragment
|
111
|
-
};
|
112
129
|
if (options && options.resolveOptions !== undefined) {
|
113
130
|
this.resolveOptions = options.resolveOptions;
|
114
131
|
}
|
@@ -155,7 +172,12 @@ class ContextModule extends Module {
|
|
155
172
|
}
|
156
173
|
|
157
174
|
_createIdentifier() {
|
158
|
-
let identifier =
|
175
|
+
let identifier =
|
176
|
+
this.context ||
|
177
|
+
(typeof this.options.resource === "string" ||
|
178
|
+
this.options.resource === false
|
179
|
+
? `${this.options.resource}`
|
180
|
+
: this.options.resource.join("|"));
|
159
181
|
if (this.options.resourceQuery) {
|
160
182
|
identifier += `|${this.options.resourceQuery}`;
|
161
183
|
}
|
@@ -220,7 +242,19 @@ class ContextModule extends Module {
|
|
220
242
|
* @returns {string} a user readable identifier of the module
|
221
243
|
*/
|
222
244
|
readableIdentifier(requestShortener) {
|
223
|
-
let identifier
|
245
|
+
let identifier;
|
246
|
+
if (this.context) {
|
247
|
+
identifier = requestShortener.shorten(this.context) + "/";
|
248
|
+
} else if (
|
249
|
+
typeof this.options.resource === "string" ||
|
250
|
+
this.options.resource === false
|
251
|
+
) {
|
252
|
+
identifier = requestShortener.shorten(`${this.options.resource}`) + "/";
|
253
|
+
} else {
|
254
|
+
identifier = this.options.resource
|
255
|
+
.map(r => requestShortener.shorten(r) + "/")
|
256
|
+
.join(" ");
|
257
|
+
}
|
224
258
|
if (this.options.resourceQuery) {
|
225
259
|
identifier += ` ${this.options.resourceQuery}`;
|
226
260
|
}
|
@@ -270,11 +304,30 @@ class ContextModule extends Module {
|
|
270
304
|
* @returns {string | null} an identifier for library inclusion
|
271
305
|
*/
|
272
306
|
libIdent(options) {
|
273
|
-
let identifier
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
307
|
+
let identifier;
|
308
|
+
|
309
|
+
if (this.context) {
|
310
|
+
identifier = contextify(
|
311
|
+
options.context,
|
312
|
+
this.context,
|
313
|
+
options.associatedObjectForCache
|
314
|
+
);
|
315
|
+
} else if (typeof this.options.resource === "string") {
|
316
|
+
identifier = contextify(
|
317
|
+
options.context,
|
318
|
+
this.options.resource,
|
319
|
+
options.associatedObjectForCache
|
320
|
+
);
|
321
|
+
} else if (this.options.resource === false) {
|
322
|
+
identifier = "false";
|
323
|
+
} else {
|
324
|
+
identifier = this.options.resource
|
325
|
+
.map(res =>
|
326
|
+
contextify(options.context, res, options.associatedObjectForCache)
|
327
|
+
)
|
328
|
+
.join(" ");
|
329
|
+
}
|
330
|
+
|
278
331
|
if (this.layer) identifier = `(${this.layer})/${identifier}`;
|
279
332
|
if (this.options.mode) {
|
280
333
|
identifier += ` ${this.options.mode}`;
|
@@ -323,8 +376,9 @@ class ContextModule extends Module {
|
|
323
376
|
// build if enforced
|
324
377
|
if (this._forceBuild) return callback(null, true);
|
325
378
|
|
326
|
-
// always build when we have no snapshot
|
327
|
-
if (!this.buildInfo.snapshot)
|
379
|
+
// always build when we have no snapshot and context
|
380
|
+
if (!this.buildInfo.snapshot)
|
381
|
+
return callback(null, Boolean(this.context || this.options.resource));
|
328
382
|
|
329
383
|
fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
|
330
384
|
callback(err, !valid);
|
@@ -439,10 +493,16 @@ class ContextModule extends Module {
|
|
439
493
|
);
|
440
494
|
return;
|
441
495
|
}
|
496
|
+
if (!this.context && !this.options.resource) return callback();
|
497
|
+
|
442
498
|
compilation.fileSystemInfo.createSnapshot(
|
443
499
|
startTime,
|
444
500
|
null,
|
445
|
-
|
501
|
+
this.context
|
502
|
+
? [this.context]
|
503
|
+
: typeof this.options.resource === "string"
|
504
|
+
? [this.options.resource]
|
505
|
+
: /** @type {string[]} */ (this.options.resource),
|
446
506
|
null,
|
447
507
|
SNAPSHOT_OPTIONS,
|
448
508
|
(err, snapshot) => {
|
@@ -466,7 +526,15 @@ class ContextModule extends Module {
|
|
466
526
|
missingDependencies,
|
467
527
|
buildDependencies
|
468
528
|
) {
|
469
|
-
|
529
|
+
if (this.context) {
|
530
|
+
contextDependencies.add(this.context);
|
531
|
+
} else if (typeof this.options.resource === "string") {
|
532
|
+
contextDependencies.add(this.options.resource);
|
533
|
+
} else if (this.options.resource === false) {
|
534
|
+
return;
|
535
|
+
} else {
|
536
|
+
for (const res of this.options.resource) contextDependencies.add(res);
|
537
|
+
}
|
470
538
|
}
|
471
539
|
|
472
540
|
/**
|
@@ -1002,9 +1070,21 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
1002
1070
|
return this.getSourceForEmptyContext(id, runtimeTemplate);
|
1003
1071
|
}
|
1004
1072
|
|
1005
|
-
|
1073
|
+
/**
|
1074
|
+
* @param {string} sourceString source content
|
1075
|
+
* @param {Compilation=} compilation the compilation
|
1076
|
+
* @returns {Source} generated source
|
1077
|
+
*/
|
1078
|
+
getSource(sourceString, compilation) {
|
1006
1079
|
if (this.useSourceMap || this.useSimpleSourceMap) {
|
1007
|
-
return new OriginalSource(
|
1080
|
+
return new OriginalSource(
|
1081
|
+
sourceString,
|
1082
|
+
`webpack://${makePathsRelative(
|
1083
|
+
(compilation && compilation.compiler.context) || "",
|
1084
|
+
this.identifier(),
|
1085
|
+
compilation && compilation.compiler.root
|
1086
|
+
)}`
|
1087
|
+
);
|
1008
1088
|
}
|
1009
1089
|
return new RawSource(sourceString);
|
1010
1090
|
}
|
@@ -1014,16 +1094,23 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
1014
1094
|
* @returns {CodeGenerationResult} result
|
1015
1095
|
*/
|
1016
1096
|
codeGeneration(context) {
|
1017
|
-
const { chunkGraph } = context;
|
1097
|
+
const { chunkGraph, compilation } = context;
|
1018
1098
|
const sources = new Map();
|
1019
1099
|
sources.set(
|
1020
1100
|
"javascript",
|
1021
|
-
this.getSource(
|
1101
|
+
this.getSource(
|
1102
|
+
this.getSourceString(this.options.mode, context),
|
1103
|
+
compilation
|
1104
|
+
)
|
1022
1105
|
);
|
1023
1106
|
const set = new Set();
|
1024
|
-
const allDeps =
|
1025
|
-
this.dependencies.
|
1026
|
-
|
1107
|
+
const allDeps =
|
1108
|
+
this.dependencies.length > 0
|
1109
|
+
? /** @type {ContextElementDependency[]} */ (this.dependencies).slice()
|
1110
|
+
: [];
|
1111
|
+
for (const block of this.blocks)
|
1112
|
+
for (const dep of block.dependencies)
|
1113
|
+
allDeps.push(/** @type {ContextElementDependency} */ (dep));
|
1027
1114
|
set.add(RuntimeGlobals.module);
|
1028
1115
|
set.add(RuntimeGlobals.hasOwnProperty);
|
1029
1116
|
if (allDeps.length > 0) {
|
@@ -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
|
};
|
@@ -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
@@ -182,6 +182,13 @@ class Dependency {
|
|
182
182
|
this._loc = undefined;
|
183
183
|
}
|
184
184
|
|
185
|
+
/**
|
186
|
+
* @returns {string | undefined} a request context
|
187
|
+
*/
|
188
|
+
getContext() {
|
189
|
+
return undefined;
|
190
|
+
}
|
191
|
+
|
185
192
|
/**
|
186
193
|
* @returns {string | null} an identifier to merge equal requests
|
187
194
|
*/
|
package/lib/EntryOptionPlugin.js
CHANGED
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
|
|
package/lib/ExportsInfo.js
CHANGED
@@ -584,7 +584,7 @@ class ExportsInfo {
|
|
584
584
|
if (info.exportsInfo && name.length > 1) {
|
585
585
|
return info.exportsInfo.isExportProvided(name.slice(1));
|
586
586
|
}
|
587
|
-
return info.provided;
|
587
|
+
return info.provided ? name.length === 1 || undefined : info.provided;
|
588
588
|
}
|
589
589
|
const info = this.getReadOnlyExportInfo(name);
|
590
590
|
return info.provided;
|
@@ -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
|
}
|
package/lib/FileSystemInfo.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { create: createResolver } = require("enhanced-resolve");
|
9
|
+
const nodeModule = require("module");
|
9
10
|
const asyncLib = require("neo-async");
|
10
11
|
const AsyncQueue = require("./util/AsyncQueue");
|
11
12
|
const StackedCacheMap = require("./util/StackedCacheMap");
|
@@ -22,6 +23,8 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|
22
23
|
|
23
24
|
const supportsEsm = +process.versions.modules >= 83;
|
24
25
|
|
26
|
+
const builtinModules = new Set(nodeModule.builtinModules);
|
27
|
+
|
25
28
|
let FS_ACCURACY = 2000;
|
26
29
|
|
27
30
|
const EMPTY_SET = new Set();
|
@@ -1673,6 +1676,11 @@ class FileSystemInfo {
|
|
1673
1676
|
// e.g. import.meta
|
1674
1677
|
continue;
|
1675
1678
|
}
|
1679
|
+
|
1680
|
+
// we should not track Node.js build dependencies
|
1681
|
+
if (dependency.startsWith("node:")) continue;
|
1682
|
+
if (builtinModules.has(dependency)) continue;
|
1683
|
+
|
1676
1684
|
push({
|
1677
1685
|
type: RBDT_RESOLVE_ESM_FILE,
|
1678
1686
|
context,
|
package/lib/Generator.js
CHANGED
package/lib/Module.js
CHANGED
@@ -49,6 +49,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
49
49
|
* @property {string=} type the type of source that should be generated
|
50
50
|
*/
|
51
51
|
|
52
|
+
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
52
53
|
/**
|
53
54
|
* @typedef {Object} CodeGenerationContext
|
54
55
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
@@ -58,6 +59,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
58
59
|
* @property {RuntimeSpec} runtime the runtimes code should be generated for
|
59
60
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
60
61
|
* @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
62
|
+
* @property {Compilation=} compilation the compilation
|
63
|
+
* @property {ReadonlySet<string>=} sourceTypes source types
|
61
64
|
*/
|
62
65
|
|
63
66
|
/**
|
@@ -47,7 +47,7 @@ const getAfter = (strFn, token) => {
|
|
47
47
|
return () => {
|
48
48
|
const str = strFn();
|
49
49
|
const idx = str.indexOf(token);
|
50
|
-
return idx < 0 ? "" : str.
|
50
|
+
return idx < 0 ? "" : str.slice(idx);
|
51
51
|
};
|
52
52
|
};
|
53
53
|
|
@@ -55,7 +55,7 @@ const getBefore = (strFn, token) => {
|
|
55
55
|
return () => {
|
56
56
|
const str = strFn();
|
57
57
|
const idx = str.lastIndexOf(token);
|
58
|
-
return idx < 0 ? "" : str.
|
58
|
+
return idx < 0 ? "" : str.slice(0, idx);
|
59
59
|
};
|
60
60
|
};
|
61
61
|
|
@@ -64,7 +64,7 @@ const getHash = (strFn, hashFunction) => {
|
|
64
64
|
const hash = createHash(hashFunction);
|
65
65
|
hash.update(strFn());
|
66
66
|
const digest = /** @type {string} */ (hash.digest("hex"));
|
67
|
-
return digest.
|
67
|
+
return digest.slice(0, 4);
|
68
68
|
};
|
69
69
|
};
|
70
70
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
|
10
|
+
/** @typedef {import("./Module")} Module */
|
11
|
+
|
12
|
+
class ModuleHashingError extends WebpackError {
|
13
|
+
/**
|
14
|
+
* Create a new ModuleHashingError
|
15
|
+
* @param {Module} module related module
|
16
|
+
* @param {Error} error Original error
|
17
|
+
*/
|
18
|
+
constructor(module, error) {
|
19
|
+
super();
|
20
|
+
|
21
|
+
this.name = "ModuleHashingError";
|
22
|
+
this.error = error;
|
23
|
+
this.message = error.message;
|
24
|
+
this.details = error.stack;
|
25
|
+
this.module = module;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
module.exports = ModuleHashingError;
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -69,6 +69,16 @@ class NodeStuffPlugin {
|
|
69
69
|
);
|
70
70
|
}
|
71
71
|
});
|
72
|
+
parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
|
73
|
+
const dep = new ConstDependency(
|
74
|
+
RuntimeGlobals.global,
|
75
|
+
expr.range,
|
76
|
+
[RuntimeGlobals.global]
|
77
|
+
);
|
78
|
+
dep.loc = expr.loc;
|
79
|
+
parser.state.module.addPresentationalDependency(dep);
|
80
|
+
return false;
|
81
|
+
});
|
72
82
|
}
|
73
83
|
|
74
84
|
const setModuleConstant = (expressionName, fn, warning) => {
|