Avoid a race condition in CLI directory creation. (#8082)

This commit is contained in:
Logan Smyth
2018-05-30 10:35:08 -07:00
committed by GitHub
parent 2a8ebbe7ae
commit 21b9b2e42d

View File

@@ -73,8 +73,14 @@ export default async function({ cliOptions, babelOptions }) {
function outputDestFolder(outDir) {
const outDirPath = path.resolve(outDir);
if (!fs.existsSync(outDirPath)) {
try {
fs.mkdirSync(outDirPath);
} catch (err) {
// Testing for the directory and then creating it can lead to race
// conditions if there are multiple processes, so we try to create it
// and bail if it already exists.
if (err.code !== "EEXIST") throw err;
}
}