webpack 5.27.2 → 5.28.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/lib/NormalModule.js
CHANGED
@@ -367,6 +367,7 @@ class NormalModule extends Module {
|
|
367
367
|
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
368
368
|
*/
|
369
369
|
_restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
370
|
+
super._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
370
371
|
this.parserOptions = unsafeCacheData.parserOptions;
|
371
372
|
this.parser = normalModuleFactory.getParser(this.type, this.parserOptions);
|
372
373
|
this.generatorOptions = unsafeCacheData.generatorOptions;
|
@@ -15,6 +15,7 @@ const { makePathsRelative } = require("../util/identifier");
|
|
15
15
|
|
16
16
|
/** @typedef {import("webpack-sources").Source} Source */
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
|
18
|
+
/** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
|
18
19
|
/** @typedef {import("../Compilation")} Compilation */
|
19
20
|
/** @typedef {import("../Compiler")} Compiler */
|
20
21
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
@@ -24,6 +25,55 @@ const { makePathsRelative } = require("../util/identifier");
|
|
24
25
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
25
26
|
/** @typedef {import("../util/Hash")} Hash */
|
26
27
|
|
28
|
+
const mergeMaybeArrays = (a, b) => {
|
29
|
+
const set = new Set();
|
30
|
+
if (Array.isArray(a)) for (const item of a) set.add(item);
|
31
|
+
else set.add(a);
|
32
|
+
if (Array.isArray(b)) for (const item of b) set.add(item);
|
33
|
+
else set.add(b);
|
34
|
+
return Array.from(set);
|
35
|
+
};
|
36
|
+
|
37
|
+
const mergeAssetInfo = (a, b) => {
|
38
|
+
const result = { ...a, ...b };
|
39
|
+
for (const key of Object.keys(a)) {
|
40
|
+
if (key in b) {
|
41
|
+
if (a[key] === b[key]) continue;
|
42
|
+
switch (key) {
|
43
|
+
case "fullhash":
|
44
|
+
case "chunkhash":
|
45
|
+
case "modulehash":
|
46
|
+
case "contenthash":
|
47
|
+
result[key] = mergeMaybeArrays(a[key], b[key]);
|
48
|
+
break;
|
49
|
+
case "immutable":
|
50
|
+
case "development":
|
51
|
+
case "hotModuleReplacement":
|
52
|
+
case "javascriptModule ":
|
53
|
+
result[key] = a[key] || b[key];
|
54
|
+
break;
|
55
|
+
case "related":
|
56
|
+
result[key] = mergeRelatedInfo(a[key], b[key]);
|
57
|
+
break;
|
58
|
+
default:
|
59
|
+
throw new Error(`Can't handle conflicting asset info for ${key}`);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return result;
|
64
|
+
};
|
65
|
+
|
66
|
+
const mergeRelatedInfo = (a, b) => {
|
67
|
+
const result = { ...a, ...b };
|
68
|
+
for (const key of Object.keys(a)) {
|
69
|
+
if (key in b) {
|
70
|
+
if (a[key] === b[key]) continue;
|
71
|
+
result[key] = mergeMaybeArrays(a[key], b[key]);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return result;
|
75
|
+
};
|
76
|
+
|
27
77
|
const JS_TYPES = new Set(["javascript"]);
|
28
78
|
const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]);
|
29
79
|
|
@@ -31,12 +81,14 @@ class AssetGenerator extends Generator {
|
|
31
81
|
/**
|
32
82
|
* @param {AssetGeneratorOptions["dataUrl"]=} dataUrlOptions the options for the data url
|
33
83
|
* @param {string=} filename override for output.assetModuleFilename
|
84
|
+
* @param {RawPublicPath=} publicPath override for output.assetModulePublicPath
|
34
85
|
* @param {boolean=} emit generate output asset
|
35
86
|
*/
|
36
|
-
constructor(dataUrlOptions, filename, emit) {
|
87
|
+
constructor(dataUrlOptions, filename, publicPath, emit) {
|
37
88
|
super();
|
38
89
|
this.dataUrlOptions = dataUrlOptions;
|
39
90
|
this.filename = filename;
|
91
|
+
this.publicPath = publicPath;
|
40
92
|
this.emit = emit;
|
41
93
|
}
|
42
94
|
|
@@ -131,9 +183,9 @@ class AssetGenerator extends Generator {
|
|
131
183
|
module.matchResource || module.resource,
|
132
184
|
runtimeTemplate.compilation.compiler.root
|
133
185
|
).replace(/^\.\//, "");
|
134
|
-
|
186
|
+
let {
|
135
187
|
path: filename,
|
136
|
-
info
|
188
|
+
info: assetInfo
|
137
189
|
} = runtimeTemplate.compilation.getAssetPathWithInfo(
|
138
190
|
assetModuleFilename,
|
139
191
|
{
|
@@ -144,11 +196,33 @@ class AssetGenerator extends Generator {
|
|
144
196
|
contentHash
|
145
197
|
}
|
146
198
|
);
|
147
|
-
|
148
|
-
|
199
|
+
let publicPath;
|
200
|
+
if (this.publicPath) {
|
201
|
+
const {
|
202
|
+
path,
|
203
|
+
info
|
204
|
+
} = runtimeTemplate.compilation.getAssetPathWithInfo(
|
205
|
+
this.publicPath,
|
206
|
+
{
|
207
|
+
module,
|
208
|
+
runtime,
|
209
|
+
filename: sourceFilename,
|
210
|
+
chunkGraph,
|
211
|
+
contentHash
|
212
|
+
}
|
213
|
+
);
|
214
|
+
publicPath = JSON.stringify(path);
|
215
|
+
assetInfo = mergeAssetInfo(assetInfo, info);
|
216
|
+
} else {
|
217
|
+
publicPath = RuntimeGlobals.publicPath;
|
218
|
+
runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
|
219
|
+
}
|
220
|
+
assetInfo = {
|
149
221
|
sourceFilename,
|
150
|
-
...
|
222
|
+
...assetInfo
|
151
223
|
};
|
224
|
+
module.buildInfo.filename = filename;
|
225
|
+
module.buildInfo.assetInfo = assetInfo;
|
152
226
|
if (getData) {
|
153
227
|
// Due to code generation caching module.buildInfo.XXX can't used to store such information
|
154
228
|
// It need to be stored in the code generation results instead, where it's cached too
|
@@ -156,15 +230,13 @@ class AssetGenerator extends Generator {
|
|
156
230
|
const data = getData();
|
157
231
|
data.set("fullContentHash", fullHash);
|
158
232
|
data.set("filename", filename);
|
159
|
-
data.set("assetInfo",
|
233
|
+
data.set("assetInfo", assetInfo);
|
160
234
|
}
|
161
235
|
|
162
|
-
runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
|
163
|
-
|
164
236
|
return new RawSource(
|
165
|
-
`${
|
166
|
-
RuntimeGlobals.
|
167
|
-
} + ${JSON.stringify(filename)};`
|
237
|
+
`${
|
238
|
+
RuntimeGlobals.module
|
239
|
+
}.exports = ${publicPath} + ${JSON.stringify(filename)};`
|
168
240
|
);
|
169
241
|
}
|
170
242
|
}
|
@@ -118,8 +118,10 @@ class AssetModulesPlugin {
|
|
118
118
|
}
|
119
119
|
|
120
120
|
let filename = undefined;
|
121
|
+
let publicPath = undefined;
|
121
122
|
if (type !== "asset/inline") {
|
122
123
|
filename = generatorOptions.filename;
|
124
|
+
publicPath = generatorOptions.publicPath;
|
123
125
|
}
|
124
126
|
|
125
127
|
const AssetGenerator = getAssetGenerator();
|
@@ -127,6 +129,7 @@ class AssetModulesPlugin {
|
|
127
129
|
return new AssetGenerator(
|
128
130
|
dataUrl,
|
129
131
|
filename,
|
132
|
+
publicPath,
|
130
133
|
generatorOptions.emit !== false
|
131
134
|
);
|
132
135
|
});
|
@@ -408,16 +408,13 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
408
408
|
};
|
409
409
|
this.extendContext(ctx);
|
410
410
|
const process = item => {
|
411
|
-
// check if we can emit a reference
|
412
|
-
const ref = referenceable.get(item);
|
413
|
-
|
414
|
-
if (ref !== undefined) {
|
415
|
-
result.push(ESCAPE, ref - currentPos);
|
416
|
-
|
417
|
-
return;
|
418
|
-
}
|
419
|
-
|
420
411
|
if (Buffer.isBuffer(item)) {
|
412
|
+
// check if we can emit a reference
|
413
|
+
const ref = referenceable.get(item);
|
414
|
+
if (ref !== undefined) {
|
415
|
+
result.push(ESCAPE, ref - currentPos);
|
416
|
+
return;
|
417
|
+
}
|
421
418
|
const alreadyUsedBuffer = dedupeBuffer(item);
|
422
419
|
if (alreadyUsedBuffer !== item) {
|
423
420
|
const ref = referenceable.get(alreadyUsedBuffer);
|
@@ -431,7 +428,19 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
431
428
|
addReferenceable(item);
|
432
429
|
|
433
430
|
result.push(item);
|
434
|
-
} else if (
|
431
|
+
} else if (item === ESCAPE) {
|
432
|
+
result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
|
433
|
+
} else if (
|
434
|
+
typeof item === "object"
|
435
|
+
// We don't have to check for null as ESCAPE is null and this has been checked before
|
436
|
+
) {
|
437
|
+
// check if we can emit a reference
|
438
|
+
const ref = referenceable.get(item);
|
439
|
+
if (ref !== undefined) {
|
440
|
+
result.push(ESCAPE, ref - currentPos);
|
441
|
+
return;
|
442
|
+
}
|
443
|
+
|
435
444
|
if (cycleStack.has(item)) {
|
436
445
|
throw new Error(`Circular references can't be serialized`);
|
437
446
|
}
|
@@ -464,6 +473,12 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
464
473
|
} else if (typeof item === "string") {
|
465
474
|
if (item.length > 1) {
|
466
475
|
// short strings are shorter when not emitting a reference (this saves 1 byte per empty string)
|
476
|
+
// check if we can emit a reference
|
477
|
+
const ref = referenceable.get(item);
|
478
|
+
if (ref !== undefined) {
|
479
|
+
result.push(ESCAPE, ref - currentPos);
|
480
|
+
return;
|
481
|
+
}
|
467
482
|
addReferenceable(item);
|
468
483
|
}
|
469
484
|
|
@@ -476,8 +491,6 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
476
491
|
}
|
477
492
|
|
478
493
|
result.push(item);
|
479
|
-
} else if (item === ESCAPE) {
|
480
|
-
result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
|
481
494
|
} else if (typeof item === "function") {
|
482
495
|
if (!SerializerMiddleware.isLazy(item))
|
483
496
|
throw new Error("Unexpected function " + item);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.28.0",
|
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",
|
@@ -107,6 +107,9 @@
|
|
107
107
|
},
|
108
108
|
"filename": {
|
109
109
|
"$ref": "#/definitions/FilenameTemplate"
|
110
|
+
},
|
111
|
+
"publicPath": {
|
112
|
+
"$ref": "#/definitions/RawPublicPath"
|
110
113
|
}
|
111
114
|
}
|
112
115
|
},
|
@@ -178,6 +181,9 @@
|
|
178
181
|
},
|
179
182
|
"filename": {
|
180
183
|
"$ref": "#/definitions/FilenameTemplate"
|
184
|
+
},
|
185
|
+
"publicPath": {
|
186
|
+
"$ref": "#/definitions/RawPublicPath"
|
181
187
|
}
|
182
188
|
}
|
183
189
|
},
|
@@ -2912,11 +2918,19 @@
|
|
2912
2918
|
"type": "boolean"
|
2913
2919
|
},
|
2914
2920
|
"PublicPath": {
|
2915
|
-
"description": "The
|
2921
|
+
"description": "The 'publicPath' specifies the public URL address of the output files when referenced in a browser.",
|
2916
2922
|
"anyOf": [
|
2917
2923
|
{
|
2918
2924
|
"enum": ["auto"]
|
2919
2925
|
},
|
2926
|
+
{
|
2927
|
+
"$ref": "#/definitions/RawPublicPath"
|
2928
|
+
}
|
2929
|
+
]
|
2930
|
+
},
|
2931
|
+
"RawPublicPath": {
|
2932
|
+
"description": "The 'publicPath' specifies the public URL address of the output files when referenced in a browser.",
|
2933
|
+
"anyOf": [
|
2920
2934
|
{
|
2921
2935
|
"type": "string"
|
2922
2936
|
},
|
package/types.d.ts
CHANGED
@@ -312,6 +312,11 @@ declare interface AssetResourceGeneratorOptions {
|
|
312
312
|
* Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
|
313
313
|
*/
|
314
314
|
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
|
315
|
+
|
316
|
+
/**
|
317
|
+
* The 'publicPath' specifies the public URL address of the output files when referenced in a browser.
|
318
|
+
*/
|
319
|
+
publicPath?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
|
315
320
|
}
|
316
321
|
declare abstract class AsyncDependenciesBlock extends DependenciesBlock {
|
317
322
|
groupOptions: RawChunkGroupOptions & { name?: string } & {
|
@@ -7388,7 +7393,7 @@ declare interface Output {
|
|
7388
7393
|
pathinfo?: boolean | "verbose";
|
7389
7394
|
|
7390
7395
|
/**
|
7391
|
-
* The
|
7396
|
+
* The 'publicPath' specifies the public URL address of the output files when referenced in a browser.
|
7392
7397
|
*/
|
7393
7398
|
publicPath?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
|
7394
7399
|
|
@@ -7650,7 +7655,7 @@ declare interface OutputNormalized {
|
|
7650
7655
|
pathinfo?: boolean | "verbose";
|
7651
7656
|
|
7652
7657
|
/**
|
7653
|
-
* The
|
7658
|
+
* The 'publicPath' specifies the public URL address of the output files when referenced in a browser.
|
7654
7659
|
*/
|
7655
7660
|
publicPath?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
|
7656
7661
|
|