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 <nate@skypack.dev>
This commit is contained in:
Steve Lee 2022-04-11 02:23:17 +01:00 committed by GitHub
parent a9ecefb8ac
commit 7b0fbd731e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix SSR static build public files copying

View file

@ -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) )
})
);
}

View file

@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import nodejs from '@astrojs/node';
export default defineConfig({
adapter: nodejs(),
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/static-build",
"version": "0.0.0",
"dependencies": {
"@astrojs/node": "workspace:*",
"@test/static-build-pkg": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1 @@
test asset

View file

@ -0,0 +1 @@
test asset

View file

@ -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');
});
});

View file

@ -1102,6 +1102,16 @@ importers:
'@test/static-build-pkg': link:pkg
astro: link:../../..
packages/astro/test/fixtures/static build SSR:
specifiers:
'@astrojs/node': workspace:*
'@test/static-build-pkg': workspace:*
astro: workspace:*
dependencies:
'@astrojs/node': link:../../../../integrations/node
'@test/static-build-pkg': link:../static build/pkg
astro: link:../../..
packages/astro/test/fixtures/static build/pkg:
specifiers: {}