mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[snap] patch bug in clearing require cache
Snap currently has a bug in which the require cache is not correctly cleared when running in filter mode (#tests < 2 * #workers). - We're currently clearing all entries in the require cache of worker threads, including `jest-worker` and `snap/dist/...` files - jest-worker seems to `require` these files on every dispatch (i.e. `worker.compile` seems to call `require(`compiler-worker`).compile`)
This commit is contained in:
@@ -11,10 +11,26 @@ import { exists } from "./utils";
|
||||
|
||||
const originalConsoleError = console.error;
|
||||
|
||||
// Subpaths to ignore when clearing the require cache
|
||||
const ignoredRequireSubpaths: Array<string> = [
|
||||
// compiler worker runner files
|
||||
"node_modules/jest-worker",
|
||||
// snap source files
|
||||
"packages/snap",
|
||||
];
|
||||
const ignoredRequirePaths: Set<string> = new Set(
|
||||
Object.keys(require.cache).filter(
|
||||
(path) =>
|
||||
!ignoredRequireSubpaths.every((ignored) => !path.includes(ignored))
|
||||
)
|
||||
);
|
||||
|
||||
let version: number | null = null;
|
||||
export function clearRequireCache() {
|
||||
Object.keys(require.cache).forEach(function (key) {
|
||||
delete require.cache[key];
|
||||
Object.keys(require.cache).forEach(function (path) {
|
||||
if (!ignoredRequirePaths.has(path)) {
|
||||
delete require.cache[path];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user