Skip to content

Commit

Permalink
fix discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Feb 11, 2022
1 parent 4830503 commit a905ea3
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/dependencies/ExportsInfoDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
const exportsInfo = moduleGraph.getExportsInfo(module);
const exportInfo = exportsInfo.getExportInfo(exportName);
if (exportInfo) return exportInfo.canMangle;
return exportsInfo.otherExportsInfo.canMangleProvide;
return exportsInfo.otherExportsInfo.canMangle;
}
case "used":
return (
Expand Down
119 changes: 119 additions & 0 deletions test/TestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ const deprecationTracking = require("./helpers/deprecationTracking");
const captureStdio = require("./helpers/captureStdio");
const asModule = require("./helpers/asModule");

const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => {
if (config.run < 2) return;
const match =
/^\[webpack\.cache\.PackFileCacheStrategy\] Pack got invalid because of write to:(.+)$/.exec(
log
);
if (match) {
return `Pack got invalid because of write to: ${match[1].trim()}`;
}
};

const casesPath = path.join(__dirname, "cases");
let categories = fs.readdirSync(casesPath);
categories = categories.map(cat => {
Expand All @@ -23,7 +34,53 @@ categories = categories.map(cat => {
};
});

const createLogger = appendTarget => {
return {
log: l => appendTarget.push(l),
debug: l => appendTarget.push(l),
trace: l => appendTarget.push(l),
info: l => appendTarget.push(l),
warn: console.warn.bind(console),
error: console.error.bind(console),
logTime: () => {},
group: () => {},
groupCollapsed: () => {},
groupEnd: () => {},
profile: () => {},
profileEnd: () => {},
clear: () => {},
status: () => {}
};
};

const returnLogError = (logs, errorsFilter, config) => {
for (const log of logs) {
for (const filter of errorsFilter) {
const result = filter(log, config);
if (result) {
return new Error(result);
}
}
}
};

const describeCases = config => {
let allowErrorsMap;
if (config.infrastructureLogErrors) {
allowErrorsMap = new Map();
if (config.infrastructureLogErrors.allowList) {
for (const { category, test } of config.infrastructureLogErrors
.allowList) {
let byCategory = allowErrorsMap.get(category);
if (!byCategory) {
byCategory = new Set();
allowErrorsMap.set(category, byCategory);
}
byCategory.add(test);
}
}
}

describe(config.name, () => {
let stderr;
beforeEach(() => {
Expand All @@ -49,6 +106,13 @@ const describeCases = config => {
return true;
})
.forEach(testName => {
let infraStructureLog = [];
const inAllowErrorsList = () => {
const byCategory = allowErrorsMap.get(category.name);
if (!byCategory) return false;
return byCategory.has(testName);
};

describe(testName, () => {
const testDirectory = path.join(
casesPath,
Expand Down Expand Up @@ -187,6 +251,10 @@ const describeCases = config => {
topLevelAwait: true,
backCompat: false,
...(config.module ? { outputModule: true } : {})
},
infrastructureLogging: config.cache && {
debug: true,
console: createLogger(infraStructureLog)
}
};
const cleanups = [];
Expand All @@ -207,12 +275,28 @@ const describeCases = config => {
options.output.path,
"cache1"
);
infraStructureLog.length = 0;
const deprecationTracker = deprecationTracking.start();
const webpack = require("..");
webpack(options, err => {
deprecationTracker();
options.output.path = oldPath;
if (err) return done(err);
if (config.infrastructureLogErrors) {
if (!inAllowErrorsList()) {
const error = returnLogError(
infraStructureLog,
Array.isArray(config.infrastructureLogErrors.filter)
? config.infrastructureLogErrors.filter
: [config.infrastructureLogErrors.filter],
{
run: 1,
options
}
);
if (error) return done(error);
}
}
done();
});
},
Expand All @@ -226,12 +310,28 @@ const describeCases = config => {
options.output.path,
"cache2"
);
infraStructureLog.length = 0;
const deprecationTracker = deprecationTracking.start();
const webpack = require("..");
webpack(options, err => {
deprecationTracker();
options.output.path = oldPath;
if (err) return done(err);
if (config.infrastructureLogErrors) {
if (!inAllowErrorsList()) {
const error = returnLogError(
infraStructureLog,
Array.isArray(config.infrastructureLogErrors.filter)
? config.infrastructureLogErrors.filter
: [config.infrastructureLogErrors.filter],
{
run: 2,
options
}
);
if (error) return done(error);
}
}
done();
});
},
Expand All @@ -241,13 +341,29 @@ const describeCases = config => {
it(
testName + " should compile",
done => {
infraStructureLog.length = 0;
const webpack = require("..");
const compiler = webpack(options);
const run = () => {
const deprecationTracker = deprecationTracking.start();
compiler.run((err, stats) => {
const deprecations = deprecationTracker();
if (err) return done(err);
if (config.infrastructureLogErrors) {
if (!inAllowErrorsList()) {
const error = returnLogError(
infraStructureLog,
Array.isArray(config.infrastructureLogErrors.filter)
? config.infrastructureLogErrors.filter
: [config.infrastructureLogErrors.filter],
{
run: 3,
options
}
);
if (error) return done(error);
}
}
compiler.close(err => {
if (err) return done(err);
const statOptions = {
Expand Down Expand Up @@ -443,3 +559,6 @@ const describeCases = config => {
};

exports.describeCases = describeCases;
exports.logErrors = {
PERSISTENCE_CACHE_INVALIDATE_ERROR
};
37 changes: 36 additions & 1 deletion test/TestCasesCachePack.longtest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
const path = require("path");
const { describeCases } = require("./TestCases.template");
const { describeCases, logErrors } = require("./TestCases.template");

describe("TestCases", () => {
describeCases({
name: "cache pack",
infrastructureLogErrors: {
allowList: [
{
// Pack got invalid because of write to: Compilation/modules|/Users/ivankopeykin/Repositories/webpack/test/cases/compile/error-hide-stack/loader.js!
category: "compile",
test: "error-hide-stack"
},
{
// 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
category: "errors",
test: "load-module-error"
},
{
// Pack got invalid because of write to: Compilation/modules|json|/Users/ivankopeykin/Repositories/webpack/test/cases/json/data/poison
category: "json",
test: "import-assertions-type-json"
},
{
// 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
category: "loaders",
test: "no-string"
},
{
// Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|/Users/ivankopeykin/Repositories/webpack/test/cases|request=|./large/big-assets/
category: "large",
test: "big-assets"
},
{
// Pack got invalid because of write to: Compilation/modules|/Users/ivankopeykin/Repositories/webpack/test/cases/parsing/context/templates/dump-file.txt
category: "parsing",
test: "context"
}
],
filter: [logErrors.PERSISTENCE_CACHE_INVALIDATE_ERROR]
},
cache: {
type: "filesystem",
buildDependencies: {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion test/configCases/parsing/harmony-reexport/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/** @type {import("../../../../").Configuration} */
module.exports = {};
module.exports = {
optimization: {
usedExports: true,
providedExports: true
}
};

0 comments on commit a905ea3

Please sign in to comment.