Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No assets folder when outDir outside cwd #4841

Merged
merged 8 commits into from Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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