Skip to content

Commit

Permalink
fix(core): build failure caused by read-only files (#10195)
Browse files Browse the repository at this point in the history
* fix(core): build failure caused by read-only files

* test: fix fixtures/build-readonly-file

* other:  format code
  • Loading branch information
1574242600 authored Feb 23, 2024
1 parent 7fab7fd commit 903eace
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-flowers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fix build failure caused by read-only files under /public (in the presence of client-side JS).
1 change: 1 addition & 0 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ async function clientBuild(
...viteConfig.build,
emptyOutDir: false,
outDir: fileURLToPath(out),
copyPublicDir: ssr,
rollupOptions: {
...viteConfig.build?.rollupOptions,
input: Array.from(input),
Expand Down
51 changes: 51 additions & 0 deletions packages/astro/test/build-readonly-file.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/build-readonly-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/build-readonly-file",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
---
<script>
console.log('test');
</script>
6 changes: 6 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 903eace

Please sign in to comment.