diff --git a/test/test-fs-wrapper.js b/test/test-fs-wrapper.js index cfafbbd88..ed02d5756 100644 --- a/test/test-fs-wrapper.js +++ b/test/test-fs-wrapper.js @@ -270,10 +270,11 @@ async function runTests() { }); await asyncTest('copy creates parent directories for dest', async () => { - const src = path.join(TMP, 'copy-file-src.txt'); + const src = path.join(TMP, 'copy-mkdir-src.txt'); + nativeFs.writeFileSync(src, 'copy mkdir'); const dest = path.join(TMP, 'copy-deep', 'nested', 'dest.txt'); await fs.copy(src, dest); - assertEqual(nativeFs.readFileSync(dest, 'utf8'), 'copy file', 'copy with mkdir content mismatch'); + assertEqual(nativeFs.readFileSync(dest, 'utf8'), 'copy mkdir', 'copy with mkdir content mismatch'); }); await asyncTest('copy copies a directory recursively', async () => { diff --git a/tools/cli/lib/fs.js b/tools/cli/lib/fs.js index f449560a3..4e6dcfa70 100644 --- a/tools/cli/lib/fs.js +++ b/tools/cli/lib/fs.js @@ -115,7 +115,10 @@ module.exports.copy = async function copy(src, dest, options = {}) { try { await fsp.access(dest); return; // dest exists, skip - } catch { + } catch (error) { + if (error && error.code !== 'ENOENT' && error.code !== 'ENOTDIR') { + throw error; + } // dest doesn't exist, proceed } }