diff --git a/.changeset/curvy-humans-judge.md b/.changeset/curvy-humans-judge.md new file mode 100644 index 0000000000..a9768726ce --- /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 cdd24e1c00..6e8fb0be44 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 });