From 21b9b2e42dffde0e47e0f397e7b2fee7a1f16064 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 30 May 2018 10:35:08 -0700 Subject: [PATCH] Avoid a race condition in CLI directory creation. (#8082) --- packages/babel-cli/src/babel/dir.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 5ae00b440b..867f4c55b5 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -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; } }