Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ const writeCacheFile = (cachePath: Path, fileData: string) => {
try {
writeFileAtomic.sync(cachePath, fileData, {encoding: 'utf8'});
} catch (e) {
if (cacheWriteErrorSafeToIgnore(e, cachePath)) {
return;
}

e.message =
'jest: failed to cache transform results in: ' +
cachePath +
Expand All @@ -412,6 +416,20 @@ const writeCacheFile = (cachePath: Path, fileData: string) => {
}
};

/**
* On Windows, renames are not atomic, leading to EPERM exceptions when two
* processes attempt to rename to the same target file at the same time.
* If the target file exists we can be reasonably sure another process has
* legitimately won a cache write race and ignore the error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention #4444 in the comment so that we'll hopefully come back later and revert this when it's not necessary?

*/
const cacheWriteErrorSafeToIgnore = (e: Error, cachePath: Path) => {
return (
process.platform === 'win32' &&
e.code === 'EPERM' &&
fs.existsSync(cachePath)
);
};

const readCacheFile = (cachePath: Path): ?string => {
if (!fs.existsSync(cachePath)) {
return null;
Expand Down