* Resolves #4825

* Add changeset

* Update late-cups-jam.md

* Update late-cups-jam.md
This commit is contained in:
Rishi Raj Jain 2022-09-23 02:07:49 +05:30 committed by GitHub
parent 3389f0ce91
commit 4b092269c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
copy assets even if outDir is out of process.cwd()

View file

@ -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),
@ -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) {