From bee76a06b626e1780772d689b4840af1920fb3a1 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 19 Jan 2022 16:07:29 +0800 Subject: [PATCH] fix: fix `--force` feature when targetDir doesn't exist yet --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4097b021..e94d742c 100755 --- a/index.js +++ b/index.js @@ -33,6 +33,10 @@ function canSafelyOverwrite(dir) { } function emptyDir(dir) { + if (!fs.existsSync(dir)) { + return + } + postOrderDirectoryTraverse( dir, (dir) => fs.rmdirSync(dir), @@ -237,7 +241,7 @@ async function init() { const needsCypressCT = needsCypress && !needsVitest const root = path.join(cwd, targetDir) - if (shouldOverwrite) { + if (fs.existsSync(root) && shouldOverwrite) { emptyDir(root) } else if (!fs.existsSync(root)) { fs.mkdirSync(root) -- 2.39.5