Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1874 race condition #3561

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/jest-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"jest-util": "^20.0.1",
"json-stable-stringify": "^1.0.1",
"micromatch": "^2.3.11",
"proper-lockfile": "^2.0.1",
"strip-bom": "3.0.0",
"yargs": "^7.0.2"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-runtime/src/ScriptTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const path = require('path');
const vm = require('vm');
const {createDirectory} = require('jest-util');
const fs = require('graceful-fs');
const lockfile = require('proper-lockfile');
const {getCacheFilePath} = require('jest-haste-map');
const stableStringify = require('json-stable-stringify');
const slash = require('slash');
Expand Down Expand Up @@ -342,15 +343,21 @@ const stripShebang = content => {
};

const writeCacheFile = (cachePath: Path, fileData: string) => {
let release;
try {
release = lockfile.lockSync(cachePath, {realpath: false});
fs.writeFileSync(cachePath, fileData, 'utf8');
release();
} catch (e) {
e.message =
'jest: failed to cache transform results in: ' +
cachePath +
'\nFailure message: ' +
e.message;
removeFile(cachePath);
if (release) {
release();
}
throw e;
}
};
Expand Down
11 changes: 11 additions & 0 deletions packages/jest-runtime/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,13 @@ private@^0.1.6:
version "0.1.7"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1"

proper-lockfile@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-2.0.1.tgz#159fb06193d32003f4b3691dd2ec1a634aa80d1d"
dependencies:
graceful-fs "^4.1.2"
retry "^0.10.0"

randomatic@^1.1.3:
version "1.1.6"
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.6.tgz#110dcabff397e9dcff7c0789ccc0a49adf1ec5bb"
Expand Down Expand Up @@ -713,6 +720,10 @@ require-main-filename@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"

retry@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4"

"semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
Expand Down