Skip to content

Commit 7b0fbd7

Browse files
SteveALeeNate Moore
and
Nate Moore
authored
Fix SSR static build public file copying. fixes #3016 (#3037)
* Fix SSR static build public file copying * chore: update lockfile * remove dirname and use URL constructor * Cleanup test and actually test what it says it tests Co-authored-by: Nate Moore <[email protected]>
1 parent a9ecefb commit 7b0fbd7

File tree

8 files changed

+48
-5
lines changed

8 files changed

+48
-5
lines changed

.changeset/metal-grapes-tickle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix SSR static build public files copying

packages/astro/src/core/build/static-build.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,14 @@ async function copyFiles(fromFolder: URL, toFolder: URL) {
253253
cwd: fileURLToPath(fromFolder),
254254
});
255255

256-
// Make the directory
257-
await fs.promises.mkdir(toFolder, { recursive: true });
258-
259256
await Promise.all(
260257
files.map(async (filename) => {
261258
const from = new URL(filename, fromFolder);
262259
const to = new URL(filename, toFolder);
263-
return fs.promises.copyFile(from, to);
264-
})
260+
const lastFolder = new URL('./', to)
261+
return fs.promises.mkdir(lastFolder, {recursive: true})
262+
.then(()=>fs.promises.copyFile(from, to) )
263+
})
265264
);
266265
}
267266

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from 'astro/config';
2+
import nodejs from '@astrojs/node';
3+
4+
export default defineConfig({
5+
adapter: nodejs(),
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@test/static-build",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"@astrojs/node": "workspace:*",
6+
"@test/static-build-pkg": "workspace:*",
7+
"astro": "workspace:*"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test asset
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test asset

packages/astro/test/static-build.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,15 @@ describe('Static build', () => {
168168
expect(found).to.equal(true, 'Found the log message');
169169
});
170170
});
171+
172+
describe('Static build SSR', () => {
173+
174+
it('Copies public files', async () => {
175+
const fixture = await loadFixture({
176+
root: './fixtures/static build SSR/',
177+
});
178+
await fixture.build()
179+
const asset = await fixture.readFile('/client/nested/asset2.txt');
180+
});
181+
182+
});

pnpm-lock.yaml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)