webpack 5.48.0 → 5.51.1
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 +4 -16
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/CompatibilityPlugin.js +21 -4
- package/lib/Compilation.js +8 -3
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +665 -193
- package/lib/HotModuleReplacementPlugin.js +4 -4
- package/lib/Module.js +1 -0
- package/lib/MultiCompiler.js +0 -2
- package/lib/NormalModule.js +51 -20
- package/lib/NormalModuleFactory.js +137 -74
- package/lib/Parser.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +8 -0
- package/lib/asset/AssetModulesPlugin.js +0 -1
- package/lib/config/defaults.js +27 -6
- package/lib/config/normalization.js +6 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
- package/lib/index.js +0 -3
- package/lib/javascript/JavascriptParser.js +2 -0
- package/lib/library/ModuleLibraryPlugin.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -1
- package/lib/optimize/ConcatenatedModule.js +3 -3
- package/lib/optimize/SplitChunksPlugin.js +4 -4
- package/lib/schemes/HttpUriPlugin.js +942 -25
- package/lib/serialization/BinaryMiddleware.js +293 -267
- package/lib/util/fs.js +40 -0
- package/lib/util/identifier.js +26 -8
- package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js} +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -2
- package/lib/web/FetchCompileWasmPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +7 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +43 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
- package/schemas/plugins/schemes/HttpUriPlugin.json +42 -0
- package/types.d.ts +110 -14
- package/lib/schemes/HttpsUriPlugin.js +0 -63
package/lib/util/fs.js
CHANGED
@@ -59,6 +59,7 @@ const path = require("path");
|
|
59
59
|
/** @typedef {function((NodeJS.ErrnoException | null)=, number=): void} NumberCallback */
|
60
60
|
/** @typedef {function((NodeJS.ErrnoException | null)=, IStats=): void} StatsCallback */
|
61
61
|
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
|
62
|
+
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, IStats|string=): void} LstatReadlinkAbsoluteCallback */
|
62
63
|
|
63
64
|
/**
|
64
65
|
* @typedef {Object} Watcher
|
@@ -103,6 +104,7 @@ const path = require("path");
|
|
103
104
|
* @property {function(string, BufferOrStringCallback): void} readlink
|
104
105
|
* @property {function(string, DirentArrayCallback): void} readdir
|
105
106
|
* @property {function(string, StatsCallback): void} stat
|
107
|
+
* @property {function(string, StatsCallback): void=} lstat
|
106
108
|
* @property {(function(string, BufferOrStringCallback): void)=} realpath
|
107
109
|
* @property {(function(string=): void)=} purge
|
108
110
|
* @property {(function(string, string): string)=} join
|
@@ -282,3 +284,41 @@ const readJson = (fs, p, callback) => {
|
|
282
284
|
});
|
283
285
|
};
|
284
286
|
exports.readJson = readJson;
|
287
|
+
|
288
|
+
/**
|
289
|
+
* @param {InputFileSystem} fs a file system
|
290
|
+
* @param {string} p an absolute path
|
291
|
+
* @param {ReadJsonCallback} callback callback
|
292
|
+
* @returns {void}
|
293
|
+
*/
|
294
|
+
const lstatReadlinkAbsolute = (fs, p, callback) => {
|
295
|
+
let i = 3;
|
296
|
+
const doReadLink = () => {
|
297
|
+
fs.readlink(p, (err, target) => {
|
298
|
+
if (err && --i > 0) {
|
299
|
+
// It might was just changed from symlink to file
|
300
|
+
// we retry 2 times to catch this case before throwing the error
|
301
|
+
return doStat();
|
302
|
+
}
|
303
|
+
if (err || !target) return doStat();
|
304
|
+
const value = target.toString();
|
305
|
+
callback(null, join(fs, dirname(fs, p), value));
|
306
|
+
});
|
307
|
+
};
|
308
|
+
const doStat = () => {
|
309
|
+
if ("lstat" in fs) {
|
310
|
+
return fs.lstat(p, (err, stats) => {
|
311
|
+
if (err) return callback(err);
|
312
|
+
if (stats.isSymbolicLink()) {
|
313
|
+
return doReadLink();
|
314
|
+
}
|
315
|
+
callback(null, stats);
|
316
|
+
});
|
317
|
+
} else {
|
318
|
+
return fs.stat(p, callback);
|
319
|
+
}
|
320
|
+
};
|
321
|
+
if ("lstat" in fs) return doStat();
|
322
|
+
doReadLink();
|
323
|
+
};
|
324
|
+
exports.lstatReadlinkAbsolute = lstatReadlinkAbsolute;
|
package/lib/util/identifier.js
CHANGED
@@ -15,6 +15,13 @@ const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
|
|
15
15
|
* @property {Map<string, Map<string, string>>=} relativePaths
|
16
16
|
*/
|
17
17
|
|
18
|
+
const relativePathToRequest = relativePath => {
|
19
|
+
if (relativePath === "") return "./.";
|
20
|
+
if (relativePath === "..") return "../.";
|
21
|
+
if (relativePath.startsWith("../")) return relativePath;
|
22
|
+
return `./${relativePath}`;
|
23
|
+
};
|
24
|
+
|
18
25
|
/**
|
19
26
|
* @param {string} context context for relative path
|
20
27
|
* @param {string} maybeAbsolutePath path to make relative
|
@@ -36,10 +43,7 @@ const absoluteToRequest = (context, maybeAbsolutePath) => {
|
|
36
43
|
querySplitPos === -1
|
37
44
|
? maybeAbsolutePath
|
38
45
|
: maybeAbsolutePath.slice(0, querySplitPos);
|
39
|
-
resource = path.posix.relative(context, resource);
|
40
|
-
if (!resource.startsWith("../")) {
|
41
|
-
resource = "./" + resource;
|
42
|
-
}
|
46
|
+
resource = relativePathToRequest(path.posix.relative(context, resource));
|
43
47
|
return querySplitPos === -1
|
44
48
|
? resource
|
45
49
|
: resource + maybeAbsolutePath.slice(querySplitPos);
|
@@ -53,10 +57,9 @@ const absoluteToRequest = (context, maybeAbsolutePath) => {
|
|
53
57
|
: maybeAbsolutePath.slice(0, querySplitPos);
|
54
58
|
resource = path.win32.relative(context, resource);
|
55
59
|
if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
|
56
|
-
resource =
|
57
|
-
|
58
|
-
|
59
|
-
}
|
60
|
+
resource = relativePathToRequest(
|
61
|
+
resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/")
|
62
|
+
);
|
60
63
|
}
|
61
64
|
return querySplitPos === -1
|
62
65
|
? resource
|
@@ -214,6 +217,21 @@ const _makePathsRelative = (context, identifier) => {
|
|
214
217
|
|
215
218
|
exports.makePathsRelative = makeCacheable(_makePathsRelative);
|
216
219
|
|
220
|
+
/**
|
221
|
+
*
|
222
|
+
* @param {string} context context for relative path
|
223
|
+
* @param {string} identifier identifier for path
|
224
|
+
* @returns {string} a converted relative path
|
225
|
+
*/
|
226
|
+
const _makePathsAbsolute = (context, identifier) => {
|
227
|
+
return identifier
|
228
|
+
.split(SEGMENTS_SPLIT_REGEXP)
|
229
|
+
.map(str => requestToAbsolute(context, str))
|
230
|
+
.join("");
|
231
|
+
};
|
232
|
+
|
233
|
+
exports.makePathsAbsolute = makeCacheable(_makePathsAbsolute);
|
234
|
+
|
217
235
|
/**
|
218
236
|
* @param {string} context absolute context path
|
219
237
|
* @param {string} request any request string may containing absolute paths, query string, etc.
|
package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js}
RENAMED
@@ -9,9 +9,9 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
-
class
|
12
|
+
class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
|
13
13
|
constructor({ generateLoadBinaryCode, supportsStreaming }) {
|
14
|
-
super("wasm
|
14
|
+
super("wasm loading", RuntimeModule.STAGE_NORMAL);
|
15
15
|
this.generateLoadBinaryCode = generateLoadBinaryCode;
|
16
16
|
this.supportsStreaming = supportsStreaming;
|
17
17
|
}
|
@@ -75,4 +75,4 @@ class AsyncWasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
|
78
|
-
module.exports =
|
78
|
+
module.exports = AsyncWasmLoadingRuntimeModule;
|
@@ -189,11 +189,17 @@ const generateImportObject = (
|
|
189
189
|
};
|
190
190
|
|
191
191
|
class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
192
|
-
constructor({
|
192
|
+
constructor({
|
193
|
+
generateLoadBinaryCode,
|
194
|
+
supportsStreaming,
|
195
|
+
mangleImports,
|
196
|
+
runtimeRequirements
|
197
|
+
}) {
|
193
198
|
super("wasm chunk loading", RuntimeModule.STAGE_ATTACH);
|
194
199
|
this.generateLoadBinaryCode = generateLoadBinaryCode;
|
195
200
|
this.supportsStreaming = supportsStreaming;
|
196
201
|
this.mangleImports = mangleImports;
|
202
|
+
this._runtimeRequirements = runtimeRequirements;
|
197
203
|
}
|
198
204
|
|
199
205
|
/**
|
@@ -203,6 +209,9 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
203
209
|
const { chunkGraph, compilation, chunk, mangleImports } = this;
|
204
210
|
const { moduleGraph, outputOptions } = compilation;
|
205
211
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
212
|
+
const withHmr = this._runtimeRequirements.has(
|
213
|
+
RuntimeGlobals.hmrDownloadUpdateHandlers
|
214
|
+
);
|
206
215
|
const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
|
207
216
|
const declarations = [];
|
208
217
|
const importObjects = wasmModules.map(module => {
|
@@ -247,9 +256,16 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
247
256
|
runtime: chunk.runtime
|
248
257
|
}
|
249
258
|
);
|
259
|
+
|
260
|
+
const stateExpression = withHmr
|
261
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_wasm`
|
262
|
+
: undefined;
|
263
|
+
|
250
264
|
return Template.asString([
|
251
265
|
"// object to store loaded and loading wasm modules",
|
252
|
-
|
266
|
+
`var installedWasmModules = ${
|
267
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
268
|
+
}{};`,
|
253
269
|
"",
|
254
270
|
// This function is used to delay reading the installed wasm module promises
|
255
271
|
// by a microtask. Sorting them doesn't help because there are edge cases where
|
@@ -6,7 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
|
-
const
|
9
|
+
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
@@ -48,7 +48,7 @@ class FetchCompileAsyncWasmPlugin {
|
|
48
48
|
set.add(RuntimeGlobals.publicPath);
|
49
49
|
compilation.addRuntimeModule(
|
50
50
|
chunk,
|
51
|
-
new
|
51
|
+
new AsyncWasmLoadingRuntimeModule({
|
52
52
|
generateLoadBinaryCode,
|
53
53
|
supportsStreaming: true
|
54
54
|
})
|
@@ -58,7 +58,8 @@ class FetchCompileWasmPlugin {
|
|
58
58
|
new WasmChunkLoadingRuntimeModule({
|
59
59
|
generateLoadBinaryCode,
|
60
60
|
supportsStreaming: true,
|
61
|
-
mangleImports: this.options.mangleImports
|
61
|
+
mangleImports: this.options.mangleImports,
|
62
|
+
runtimeRequirements: set
|
62
63
|
})
|
63
64
|
);
|
64
65
|
});
|
@@ -98,6 +98,10 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
98
98
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
99
99
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
100
100
|
|
101
|
+
const stateExpression = withHmr
|
102
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_jsonp`
|
103
|
+
: undefined;
|
104
|
+
|
101
105
|
return Template.asString([
|
102
106
|
withBaseURI
|
103
107
|
? Template.asString([
|
@@ -108,7 +112,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
108
112
|
"// object to store loaded and loading chunks",
|
109
113
|
"// undefined = chunk not loaded, null = chunk preloaded/prefetched",
|
110
114
|
"// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
|
111
|
-
|
115
|
+
`var installedChunks = ${
|
116
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
117
|
+
}{`,
|
112
118
|
Template.indent(
|
113
119
|
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join(
|
114
120
|
",\n"
|
@@ -389,16 +395,23 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
389
395
|
'// add "moreModules" to the modules object,',
|
390
396
|
'// then flag all "chunkIds" as loaded and fire callback',
|
391
397
|
"var moduleId, chunkId, i = 0;",
|
392
|
-
|
398
|
+
`if(chunkIds.some(${runtimeTemplate.returningFunction(
|
399
|
+
"installedChunks[id] !== 0",
|
400
|
+
"id"
|
401
|
+
)})) {`,
|
393
402
|
Template.indent([
|
394
|
-
|
395
|
-
Template.indent(
|
396
|
-
|
397
|
-
|
398
|
-
|
403
|
+
"for(moduleId in moreModules) {",
|
404
|
+
Template.indent([
|
405
|
+
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
|
406
|
+
Template.indent(
|
407
|
+
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
408
|
+
),
|
409
|
+
"}"
|
410
|
+
]),
|
411
|
+
"}",
|
412
|
+
"if(runtime) var result = runtime(__webpack_require__);"
|
399
413
|
]),
|
400
414
|
"}",
|
401
|
-
"if(runtime) var result = runtime(__webpack_require__);",
|
402
415
|
"if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);",
|
403
416
|
"for(;i < chunkIds.length; i++) {",
|
404
417
|
Template.indent([
|
@@ -67,6 +67,10 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
67
67
|
false
|
68
68
|
);
|
69
69
|
|
70
|
+
const stateExpression = withHmr
|
71
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_importScripts`
|
72
|
+
: undefined;
|
73
|
+
|
70
74
|
return Template.asString([
|
71
75
|
withBaseURI
|
72
76
|
? Template.asString([
|
@@ -78,7 +82,9 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
78
82
|
"",
|
79
83
|
"// object to store loaded chunks",
|
80
84
|
'// "1" means "already loaded"',
|
81
|
-
|
85
|
+
`var installedChunks = ${
|
86
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
87
|
+
}{`,
|
82
88
|
Template.indent(
|
83
89
|
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 1`).join(
|
84
90
|
",\n"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.51.1",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|