From b673bc850593d5af25793d0358c00797477fa373 Mon Sep 17 00:00:00 2001 From: Ming-jun Lu <40516784+mingjunlu@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:01:51 +0800 Subject: [PATCH] Fix an issue where `astro build` writes type declaration files to `outDir` (#10861) * Fix an issue where `astro build` also writes type declaration files to `outDir` * Add changeset --- .changeset/curvy-humans-judge.md | 5 +++++ packages/astro/src/core/build/static-build.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/curvy-humans-judge.md diff --git a/.changeset/curvy-humans-judge.md b/.changeset/curvy-humans-judge.md new file mode 100644 index 000000000000..a9768726ce32 --- /dev/null +++ b/.changeset/curvy-humans-judge.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where `astro build` writes type declaration files to `outDir` when it's outside of root directory. diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index cdd24e1c0053..6e8fb0be4421 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -442,6 +442,13 @@ async function cleanServerOutput( // Clean out directly if the outDir is outside of root if (out.toString() !== opts.settings.config.outDir.toString()) { + // Remove .d.ts files + const fileNames = await fs.promises.readdir(out); + await Promise.all( + fileNames + .filter((fileName) => fileName.endsWith('.d.ts')) + .map((fileName) => fs.promises.rm(new URL(fileName, out))) + ); // Copy assets before cleaning directory if outside root await copyFiles(out, opts.settings.config.outDir, true); await fs.promises.rm(out, { recursive: true });