0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix(core): build failure caused by read-only files (#10195)

* fix(core): build failure caused by read-only files

* test: fix fixtures/build-readonly-file

* other:  format code
This commit is contained in:
Nworm 2024-02-23 19:36:53 +08:00 committed by GitHub
parent 7fab7fd8c6
commit 903eace233
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fix build failure caused by read-only files under /public (in the presence of client-side JS).

View file

@ -309,6 +309,7 @@ async function clientBuild(
...viteConfig.build,
emptyOutDir: false,
outDir: fileURLToPath(out),
copyPublicDir: ssr,
rollupOptions: {
...viteConfig.build?.rollupOptions,
input: Array.from(input),

View file

@ -0,0 +1,51 @@
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'url';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
describe('When a read-only file exists in /public (static)', () => {
let fixture;
let testFilePath;
before(async () => {
fixture = await loadFixture({
root: './fixtures/build-readonly-file/',
});
testFilePath = fileURLToPath(fixture.config.publicDir) + 'test.txt';
fs.chmodSync(testFilePath, 0o444);
});
it('Gets successfully build', async () => {
await fixture.build();
});
after(() => {
fs.chmodSync(testFilePath, 0o666);
fixture.clean();
});
});
describe('When a read-only file exists in /public (server)', () => {
let fixture;
let testFilePath;
before(async () => {
fixture = await loadFixture({
root: './fixtures/build-readonly-file/',
adapter: testAdapter(),
});
testFilePath = fileURLToPath(fixture.config.publicDir) + 'test.txt';
fs.chmodSync(testFilePath, 0o444);
});
it('Gets successfully build', async () => {
await fixture.build();
});
after(() => {
fs.chmodSync(testFilePath, 0o666);
fixture.clean();
});
});

View file

@ -0,0 +1,8 @@
{
"name": "@test/build-readonly-file",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1 @@
test

View file

@ -0,0 +1,5 @@
---
---
<script>
console.log('test');
</script>

View file

@ -2327,6 +2327,12 @@ importers:
specifier: ^10.19.2
version: 10.19.3
packages/astro/test/fixtures/build-readonly-file:
dependencies:
astro:
specifier: workspace:*
version: link:../../..
packages/astro/test/fixtures/client-address:
dependencies:
astro: