Skip to content

Commit

Permalink
Fix SSR static build public file copying. fixes #3016 (#3037)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
SteveALee and Nate Moore authored Apr 11, 2022
1 parent a9ecefb commit 7b0fbd7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-grapes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix SSR static build public files copying
9 changes: 4 additions & 5 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,14 @@ async function copyFiles(fromFolder: URL, toFolder: URL) {
cwd: fileURLToPath(fromFolder),
});

// Make the directory
await fs.promises.mkdir(toFolder, { recursive: true });

await Promise.all(
files.map(async (filename) => {
const from = new URL(filename, fromFolder);
const to = new URL(filename, toFolder);
return fs.promises.copyFile(from, to);
})
const lastFolder = new URL('./', to)
return fs.promises.mkdir(lastFolder, {recursive: true})
.then(()=>fs.promises.copyFile(from, to) )
})
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import nodejs from '@astrojs/node';

export default defineConfig({
adapter: nodejs(),
});
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/static build SSR/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/static-build",
"version": "0.0.0",
"dependencies": {
"@astrojs/node": "workspace:*",
"@test/static-build-pkg": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test asset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test asset
12 changes: 12 additions & 0 deletions packages/astro/test/static-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ describe('Static build', () => {
expect(found).to.equal(true, 'Found the log message');
});
});

describe('Static build SSR', () => {

it('Copies public files', async () => {
const fixture = await loadFixture({
root: './fixtures/static build SSR/',
});
await fixture.build()
const asset = await fixture.readFile('/client/nested/asset2.txt');
});

});
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b0fbd7

Please sign in to comment.