Skip to content

Commit

Permalink
Avoid a race condition in CLI directory creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed May 30, 2018
1 parent 2a8ebbe commit 2cbfc34
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/babel-cli/src/babel/dir.js
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 2cbfc34

Please sign in to comment.