From a730b5ca5f931baf77bc8f958a03201f9164a4a8 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:26:26 +0000 Subject: [PATCH] try awaiting spawn on windows --- packages/io/src/io.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/io/src/io.ts b/packages/io/src/io.ts index a6c31ab6..8efe4632 100644 --- a/packages/io/src/io.ts +++ b/packages/io/src/io.ts @@ -128,15 +128,28 @@ export async function rmRF(inputPath: string): Promise { } try { const cmdPath = ioUtil.getCmdPath() - if (await ioUtil.isDirectory(inputPath, true)) { - await exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { - env: {inputPath} + + const p = new Promise(async (resolve, reject) => { + setTimeout(() => { + resolve("timeout") + }, 500) + + let result = null; + if (await ioUtil.isDirectory(inputPath, true)) { + result = childProcess.spawn(cmdPath, ['/s', '/c', '"rd /s /q "%inputPath%""'], { + env: {inputPath} + }) + } else { + result = childProcess.spawn('cmdPath', ['/s', '/c', '"del /f /a "%inputPath%""'], { + env: {inputPath} + }) + } + + result.on('close', (code) => { + resolve(code) }) - } else { - await exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { - env: {inputPath} - }) - } + }) + await p } catch (err) { // if you try to delete a file that doesn't exist, desired result is achieved // other errors are valid