Skip to content

Commit 0d38e57

Browse files
authored
Merge pull request #15356 from webpack/fix/issues-15177
fix serialization in ContextElementDependency
2 parents 2279c5a + 2ec870f commit 0d38e57

File tree

3 files changed

+162
-3
lines changed

3 files changed

+162
-3
lines changed

lib/dependencies/ContextElementDependency.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ class ContextElementDependency extends ModuleDependency {
5353
}
5454

5555
serialize(context) {
56-
context.write(this.referencedExports);
56+
const { write } = context;
57+
write(this._typePrefix);
58+
write(this._category);
59+
write(this.referencedExports);
5760
super.serialize(context);
5861
}
5962

6063
deserialize(context) {
61-
this.referencedExports = context.read();
64+
const { read } = context;
65+
this._typePrefix = read();
66+
this._category = read();
67+
this.referencedExports = read();
6268
super.deserialize(context);
6369
}
6470
}

test/ConfigCacheTestCases.longtest.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
const { describeCases } = require("./ConfigTestCases.template");
1+
const { describeCases, logErrors } = require("./ConfigTestCases.template");
22

33
describeCases({
44
name: "ConfigCacheTestCases",
5+
infrastructureLogErrors: {
6+
allowList: [
7+
{
8+
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/wasm/missing-wasm-experiment/wasm.wasm
9+
category: "wasm",
10+
test: "missing-wasm-experiment"
11+
},
12+
{
13+
// Pack got invalid because of write to: RealContentHashPlugin|analyse|index.html
14+
category: "process-assets",
15+
test: "html-plugin"
16+
},
17+
{
18+
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/cases/parsing/context/templates/dump-file.txt
19+
category: "parsing",
20+
test: "context"
21+
},
22+
{
23+
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/loaders/options/loader-1.js??ruleSet[1].rules[9]!/home/runner/work/webpack/webpack/test/configCases/loaders/options/error1.js
24+
category: "loaders",
25+
test: "options"
26+
},
27+
{
28+
// Pack got invalid because of write to: TerserWebpackPlugin|bundle0.js
29+
category: "assets",
30+
test: "delete-asset"
31+
},
32+
{
33+
// Pack got invalid because of write to: webpack.HttpUriPlugin|https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md
34+
category: "asset-modules",
35+
test: "http-url"
36+
}
37+
],
38+
filter: [logErrors.PERSISTENCE_CACHE_INVALIDATE_ERROR]
39+
},
540
cache: {
641
type: "filesystem",
742
buildDependencies: {

test/ConfigTestCases.template.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const { parseResource } = require("../lib/util/identifier");
1818
const captureStdio = require("./helpers/captureStdio");
1919
const asModule = require("./helpers/asModule");
2020

21+
const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => {
22+
if (config.run < 2) return;
23+
const match =
24+
/^\[webpack\.cache\.PackFileCacheStrategy\] Pack got invalid because of write to:(.+)$/.exec(
25+
log
26+
);
27+
if (match) {
28+
return `Pack got invalid because of write to: ${match[1].trim()}`;
29+
}
30+
};
31+
2132
const casesPath = path.join(__dirname, "configCases");
2233
const categories = fs.readdirSync(casesPath).map(cat => {
2334
return {
@@ -29,7 +40,53 @@ const categories = fs.readdirSync(casesPath).map(cat => {
2940
};
3041
});
3142

43+
const createLogger = appendTarget => {
44+
return {
45+
log: l => appendTarget.push(l),
46+
debug: l => appendTarget.push(l),
47+
trace: l => appendTarget.push(l),
48+
info: l => appendTarget.push(l),
49+
warn: console.warn.bind(console),
50+
error: console.error.bind(console),
51+
logTime: () => {},
52+
group: () => {},
53+
groupCollapsed: () => {},
54+
groupEnd: () => {},
55+
profile: () => {},
56+
profileEnd: () => {},
57+
clear: () => {},
58+
status: () => {}
59+
};
60+
};
61+
62+
const returnLogError = (logs, errorsFilter, config) => {
63+
for (const log of logs) {
64+
for (const filter of errorsFilter) {
65+
const result = filter(log, config);
66+
if (result) {
67+
return new Error(result);
68+
}
69+
}
70+
}
71+
};
72+
3273
const describeCases = config => {
74+
let allowErrorsMap;
75+
if (config.infrastructureLogErrors) {
76+
allowErrorsMap = new Map();
77+
if (config.infrastructureLogErrors.allowList) {
78+
for (const { category, test } of config.infrastructureLogErrors
79+
.allowList) {
80+
let byCategory = allowErrorsMap.get(category);
81+
if (!byCategory) {
82+
byCategory = new Set();
83+
allowErrorsMap.set(category, byCategory);
84+
}
85+
byCategory.add(test);
86+
}
87+
}
88+
}
89+
3390
describe(config.name, () => {
3491
let stderr;
3592
beforeEach(() => {
@@ -44,6 +101,11 @@ const describeCases = config => {
44101
// eslint-disable-next-line no-loop-func
45102
describe(category.name, () => {
46103
for (const testName of category.tests) {
104+
const inAllowErrorsList = () => {
105+
const byCategory = allowErrorsMap.get(category.name);
106+
if (!byCategory) return false;
107+
return byCategory.has(testName);
108+
};
47109
// eslint-disable-next-line no-loop-func
48110
describe(testName, function () {
49111
const testDirectory = path.join(casesPath, category.name, testName);
@@ -54,6 +116,7 @@ const describeCases = config => {
54116
});
55117
return;
56118
}
119+
const infraStructureLog = [];
57120
const outBaseDir = path.join(__dirname, "js");
58121
const testSubPath = path.join(config.name, category.name, testName);
59122
const outputDirectory = path.join(outBaseDir, testSubPath);
@@ -97,6 +160,10 @@ const describeCases = config => {
97160
name: `config-${idx}`,
98161
...config.cache
99162
};
163+
options.infrastructureLogging = {
164+
debug: true,
165+
console: createLogger(infraStructureLog)
166+
};
100167
}
101168
if (!options.snapshot) options.snapshot = {};
102169
if (!options.snapshot.managedPaths) {
@@ -168,6 +235,7 @@ const describeCases = config => {
168235
it(`${testName} should pre-compile to fill disk cache (1st)`, done => {
169236
rimraf.sync(outputDirectory);
170237
fs.mkdirSync(outputDirectory, { recursive: true });
238+
infraStructureLog.length = 0;
171239
const deprecationTracker = deprecationTracking.start();
172240
require("..")(options, err => {
173241
deprecationTracker();
@@ -180,13 +248,29 @@ const describeCases = config => {
180248
)
181249
);
182250
}
251+
if (config.infrastructureLogErrors) {
252+
if (!inAllowErrorsList()) {
253+
const error = returnLogError(
254+
infraStructureLog,
255+
Array.isArray(config.infrastructureLogErrors.filter)
256+
? config.infrastructureLogErrors.filter
257+
: [config.infrastructureLogErrors.filter],
258+
{
259+
run: 1,
260+
options
261+
}
262+
);
263+
if (error) return done(error);
264+
}
265+
}
183266
if (err) return handleFatalError(err, done);
184267
done();
185268
});
186269
}, 60000);
187270
it(`${testName} should pre-compile to fill disk cache (2nd)`, done => {
188271
rimraf.sync(outputDirectory);
189272
fs.mkdirSync(outputDirectory, { recursive: true });
273+
infraStructureLog.length = 0;
190274
const deprecationTracker = deprecationTracking.start();
191275
require("..")(options, (err, stats) => {
192276
deprecationTracker();
@@ -228,13 +312,29 @@ const describeCases = config => {
228312
);
229313
}
230314
}
315+
if (config.infrastructureLogErrors) {
316+
if (!inAllowErrorsList()) {
317+
const error = returnLogError(
318+
infraStructureLog,
319+
Array.isArray(config.infrastructureLogErrors.filter)
320+
? config.infrastructureLogErrors.filter
321+
: [config.infrastructureLogErrors.filter],
322+
{
323+
run: 2,
324+
options
325+
}
326+
);
327+
if (error) return done(error);
328+
}
329+
}
231330
done();
232331
});
233332
}, 40000);
234333
}
235334
it(`${testName} should compile`, done => {
236335
rimraf.sync(outputDirectory);
237336
fs.mkdirSync(outputDirectory, { recursive: true });
337+
infraStructureLog.length = 0;
238338
const deprecationTracker = deprecationTracking.start();
239339
const onCompiled = (err, stats) => {
240340
const deprecations = deprecationTracker();
@@ -298,6 +398,21 @@ const describeCases = config => {
298398
) {
299399
return;
300400
}
401+
if (config.infrastructureLogErrors) {
402+
if (!inAllowErrorsList()) {
403+
const error = returnLogError(
404+
infraStructureLog,
405+
Array.isArray(config.infrastructureLogErrors.filter)
406+
? config.infrastructureLogErrors.filter
407+
: [config.infrastructureLogErrors.filter],
408+
{
409+
run: 3,
410+
options
411+
}
412+
);
413+
if (error) return done(error);
414+
}
415+
}
301416

302417
let filesCount = 0;
303418

@@ -623,3 +738,6 @@ const describeCases = config => {
623738
};
624739

625740
exports.describeCases = describeCases;
741+
exports.logErrors = {
742+
PERSISTENCE_CACHE_INVALIDATE_ERROR
743+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy