Skip to content

Commit a905ea3

Browse files
committed
fix discussions
1 parent 4830503 commit a905ea3

9 files changed

Lines changed: 162 additions & 3 deletions

File tree

lib/dependencies/ExportsInfoDependency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
5050
const exportsInfo = moduleGraph.getExportsInfo(module);
5151
const exportInfo = exportsInfo.getExportInfo(exportName);
5252
if (exportInfo) return exportInfo.canMangle;
53-
return exportsInfo.otherExportsInfo.canMangleProvide;
53+
return exportsInfo.otherExportsInfo.canMangle;
5454
}
5555
case "used":
5656
return (

test/TestCases.template.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ const deprecationTracking = require("./helpers/deprecationTracking");
1212
const captureStdio = require("./helpers/captureStdio");
1313
const asModule = require("./helpers/asModule");
1414

15+
const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => {
16+
if (config.run < 2) return;
17+
const match =
18+
/^\[webpack\.cache\.PackFileCacheStrategy\] Pack got invalid because of write to:(.+)$/.exec(
19+
log
20+
);
21+
if (match) {
22+
return `Pack got invalid because of write to: ${match[1].trim()}`;
23+
}
24+
};
25+
1526
const casesPath = path.join(__dirname, "cases");
1627
let categories = fs.readdirSync(casesPath);
1728
categories = categories.map(cat => {
@@ -23,7 +34,53 @@ categories = categories.map(cat => {
2334
};
2435
});
2536

37+
const createLogger = appendTarget => {
38+
return {
39+
log: l => appendTarget.push(l),
40+
debug: l => appendTarget.push(l),
41+
trace: l => appendTarget.push(l),
42+
info: l => appendTarget.push(l),
43+
warn: console.warn.bind(console),
44+
error: console.error.bind(console),
45+
logTime: () => {},
46+
group: () => {},
47+
groupCollapsed: () => {},
48+
groupEnd: () => {},
49+
profile: () => {},
50+
profileEnd: () => {},
51+
clear: () => {},
52+
status: () => {}
53+
};
54+
};
55+
56+
const returnLogError = (logs, errorsFilter, config) => {
57+
for (const log of logs) {
58+
for (const filter of errorsFilter) {
59+
const result = filter(log, config);
60+
if (result) {
61+
return new Error(result);
62+
}
63+
}
64+
}
65+
};
66+
2667
const describeCases = config => {
68+
let allowErrorsMap;
69+
if (config.infrastructureLogErrors) {
70+
allowErrorsMap = new Map();
71+
if (config.infrastructureLogErrors.allowList) {
72+
for (const { category, test } of config.infrastructureLogErrors
73+
.allowList) {
74+
let byCategory = allowErrorsMap.get(category);
75+
if (!byCategory) {
76+
byCategory = new Set();
77+
allowErrorsMap.set(category, byCategory);
78+
}
79+
byCategory.add(test);
80+
}
81+
}
82+
}
83+
2784
describe(config.name, () => {
2885
let stderr;
2986
beforeEach(() => {
@@ -49,6 +106,13 @@ const describeCases = config => {
49106
return true;
50107
})
51108
.forEach(testName => {
109+
let infraStructureLog = [];
110+
const inAllowErrorsList = () => {
111+
const byCategory = allowErrorsMap.get(category.name);
112+
if (!byCategory) return false;
113+
return byCategory.has(testName);
114+
};
115+
52116
describe(testName, () => {
53117
const testDirectory = path.join(
54118
casesPath,
@@ -187,6 +251,10 @@ const describeCases = config => {
187251
topLevelAwait: true,
188252
backCompat: false,
189253
...(config.module ? { outputModule: true } : {})
254+
},
255+
infrastructureLogging: config.cache && {
256+
debug: true,
257+
console: createLogger(infraStructureLog)
190258
}
191259
};
192260
const cleanups = [];
@@ -207,12 +275,28 @@ const describeCases = config => {
207275
options.output.path,
208276
"cache1"
209277
);
278+
infraStructureLog.length = 0;
210279
const deprecationTracker = deprecationTracking.start();
211280
const webpack = require("..");
212281
webpack(options, err => {
213282
deprecationTracker();
214283
options.output.path = oldPath;
215284
if (err) return done(err);
285+
if (config.infrastructureLogErrors) {
286+
if (!inAllowErrorsList()) {
287+
const error = returnLogError(
288+
infraStructureLog,
289+
Array.isArray(config.infrastructureLogErrors.filter)
290+
? config.infrastructureLogErrors.filter
291+
: [config.infrastructureLogErrors.filter],
292+
{
293+
run: 1,
294+
options
295+
}
296+
);
297+
if (error) return done(error);
298+
}
299+
}
216300
done();
217301
});
218302
},
@@ -226,12 +310,28 @@ const describeCases = config => {
226310
options.output.path,
227311
"cache2"
228312
);
313+
infraStructureLog.length = 0;
229314
const deprecationTracker = deprecationTracking.start();
230315
const webpack = require("..");
231316
webpack(options, err => {
232317
deprecationTracker();
233318
options.output.path = oldPath;
234319
if (err) return done(err);
320+
if (config.infrastructureLogErrors) {
321+
if (!inAllowErrorsList()) {
322+
const error = returnLogError(
323+
infraStructureLog,
324+
Array.isArray(config.infrastructureLogErrors.filter)
325+
? config.infrastructureLogErrors.filter
326+
: [config.infrastructureLogErrors.filter],
327+
{
328+
run: 2,
329+
options
330+
}
331+
);
332+
if (error) return done(error);
333+
}
334+
}
235335
done();
236336
});
237337
},
@@ -241,13 +341,29 @@ const describeCases = config => {
241341
it(
242342
testName + " should compile",
243343
done => {
344+
infraStructureLog.length = 0;
244345
const webpack = require("..");
245346
const compiler = webpack(options);
246347
const run = () => {
247348
const deprecationTracker = deprecationTracking.start();
248349
compiler.run((err, stats) => {
249350
const deprecations = deprecationTracker();
250351
if (err) return done(err);
352+
if (config.infrastructureLogErrors) {
353+
if (!inAllowErrorsList()) {
354+
const error = returnLogError(
355+
infraStructureLog,
356+
Array.isArray(config.infrastructureLogErrors.filter)
357+
? config.infrastructureLogErrors.filter
358+
: [config.infrastructureLogErrors.filter],
359+
{
360+
run: 3,
361+
options
362+
}
363+
);
364+
if (error) return done(error);
365+
}
366+
}
251367
compiler.close(err => {
252368
if (err) return done(err);
253369
const statOptions = {
@@ -443,3 +559,6 @@ const describeCases = config => {
443559
};
444560

445561
exports.describeCases = describeCases;
562+
exports.logErrors = {
563+
PERSISTENCE_CACHE_INVALIDATE_ERROR
564+
};

test/TestCasesCachePack.longtest.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
const path = require("path");
2-
const { describeCases } = require("./TestCases.template");
2+
const { describeCases, logErrors } = require("./TestCases.template");
33

44
describe("TestCases", () => {
55
describeCases({
66
name: "cache pack",
7+
infrastructureLogErrors: {
8+
allowList: [
9+
{
10+
// Pack got invalid because of write to: Compilation/modules|/Users/ivankopeykin/Repositories/webpack/test/cases/compile/error-hide-stack/loader.js!
11+
category: "compile",
12+
test: "error-hide-stack"
13+
},
14+
{
15+
// Pack got invalid because of write to: Compilation/modules|json|/Users/ivankopeykin/Repositories/webpack/test/cases/errors/load-module-error/error-loader.js!/Users/ivankopeykin/Repositories/webpack/test/cases/errors/load-module-error/b.json
16+
category: "errors",
17+
test: "load-module-error"
18+
},
19+
{
20+
// Pack got invalid because of write to: Compilation/modules|json|/Users/ivankopeykin/Repositories/webpack/test/cases/json/data/poison
21+
category: "json",
22+
test: "import-assertions-type-json"
23+
},
24+
{
25+
// Pack got invalid because of write to: Compilation/modules|/Users/ivankopeykin/Repositories/webpack/test/cases/loaders/no-string/loader.js!/Users/ivankopeykin/Repositories/webpack/test/cases/loaders/no-string/file.js
26+
category: "loaders",
27+
test: "no-string"
28+
},
29+
{
30+
// Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|/Users/ivankopeykin/Repositories/webpack/test/cases|request=|./large/big-assets/
31+
category: "large",
32+
test: "big-assets"
33+
},
34+
{
35+
// Pack got invalid because of write to: Compilation/modules|/Users/ivankopeykin/Repositories/webpack/test/cases/parsing/context/templates/dump-file.txt
36+
category: "parsing",
37+
test: "context"
38+
}
39+
],
40+
filter: [logErrors.PERSISTENCE_CACHE_INVALIDATE_ERROR]
41+
},
742
cache: {
843
type: "filesystem",
944
buildDependencies: {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
/** @type {import("../../../../").Configuration} */
2-
module.exports = {};
2+
module.exports = {
3+
optimization: {
4+
usedExports: true,
5+
providedExports: true
6+
}
7+
};

0 commit comments

Comments
 (0)