From b9230812ed98d58dd6b2c9fe41f4f5ab7cccf692 Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Wed, 15 May 2024 15:01:47 +1000 Subject: [PATCH] Only remove output directory files, not the directory (#969) --- .changeset/dirty-hounds-try.md | 5 +++++ packages/sku/lib/buildFileUtils.js | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/dirty-hounds-try.md diff --git a/.changeset/dirty-hounds-try.md b/.changeset/dirty-hounds-try.md new file mode 100644 index 000000000..f0631cc0b --- /dev/null +++ b/.changeset/dirty-hounds-try.md @@ -0,0 +1,5 @@ +--- +'sku': patch +--- + +When cleaning the build output directory, only delete files within the directory, rather than the entire directory diff --git a/packages/sku/lib/buildFileUtils.js b/packages/sku/lib/buildFileUtils.js index 0f7400184..c10559288 100644 --- a/packages/sku/lib/buildFileUtils.js +++ b/packages/sku/lib/buildFileUtils.js @@ -8,7 +8,18 @@ const exists = require('./exists'); const copyDirContents = require('./copyDirContents'); const cleanTargetDirectory = async () => { - fs.rm(paths.target, { recursive: true, force: true }); + const files = await new Fdir() + .withBasePath() + .withMaxDepth(1) + .withDirs() + // This glob pattern is used to exclude the target directory itself + .glob(`${paths.target}/*`) + .crawl(paths.target) + .withPromise(); + + for (const file of files) { + await fs.rm(file, { recursive: true, force: true }); + } }; const copyPublicFiles = async () => {