Skip to content

Commit

Permalink
Resolves #4825 (#4841)
Browse files Browse the repository at this point in the history
* Resolves #4825

* Add changeset

* Update late-cups-jam.md

* Update late-cups-jam.md
  • Loading branch information
rishi-raj-jain committed Sep 22, 2022
1 parent 3389f0c commit 4b09226
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-cups-jam.md
@@ -0,0 +1,5 @@
---
'astro': patch
---

copy assets even if outDir is out of process.cwd()
12 changes: 7 additions & 5 deletions packages/astro/src/core/build/static-build.ts
Expand Up @@ -242,11 +242,6 @@ async function clientBuild(

async function cleanSsrOutput(opts: StaticBuildOptions) {
const out = getOutDirWithinCwd(opts.settings.config.outDir);
// Clean out directly if the outDir is outside of root
if (out.toString() !== opts.settings.config.outDir.toString()) {
await fs.promises.rm(out, { recursive: true });
return;
}
// The SSR output is all .mjs files, the client output is not.
const files = await glob('**/*.mjs', {
cwd: fileURLToPath(out),
Expand All @@ -257,6 +252,13 @@ async function cleanSsrOutput(opts: StaticBuildOptions) {
await fs.promises.rm(url);
})
);
// Clean out directly if the outDir is outside of root
if (out.toString() !== opts.settings.config.outDir.toString()) {
// Copy assets before cleaning directory if outside root
copyFiles(out, opts.settings.config.outDir);
await fs.promises.rm(out, { recursive: true });
return;
}
}

async function copyFiles(fromFolder: URL, toFolder: URL) {
Expand Down

0 comments on commit 4b09226

Please sign in to comment.