From 903eace233033998811b72e27a54c80d8e59ff37 Mon Sep 17 00:00:00 2001 From: Nworm <35765846+1574242600@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:36:53 +0800 Subject: [PATCH] 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 --- .changeset/nervous-flowers-tell.md | 5 ++ packages/astro/src/core/build/static-build.ts | 1 + .../astro/test/build-readonly-file.test.js | 51 +++++++++++++++++++ .../fixtures/build-readonly-file/package.json | 8 +++ .../build-readonly-file/public/test.txt | 1 + .../build-readonly-file/src/pages/index.astro | 5 ++ pnpm-lock.yaml | 6 +++ 7 files changed, 77 insertions(+) create mode 100644 .changeset/nervous-flowers-tell.md create mode 100644 packages/astro/test/build-readonly-file.test.js create mode 100644 packages/astro/test/fixtures/build-readonly-file/package.json create mode 100644 packages/astro/test/fixtures/build-readonly-file/public/test.txt create mode 100644 packages/astro/test/fixtures/build-readonly-file/src/pages/index.astro diff --git a/.changeset/nervous-flowers-tell.md b/.changeset/nervous-flowers-tell.md new file mode 100644 index 000000000000..d07cdf8adc55 --- /dev/null +++ b/.changeset/nervous-flowers-tell.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fix build failure caused by read-only files under /public (in the presence of client-side JS). diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 3fc40035d653..0b5486d3b729 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -309,6 +309,7 @@ async function clientBuild( ...viteConfig.build, emptyOutDir: false, outDir: fileURLToPath(out), + copyPublicDir: ssr, rollupOptions: { ...viteConfig.build?.rollupOptions, input: Array.from(input), diff --git a/packages/astro/test/build-readonly-file.test.js b/packages/astro/test/build-readonly-file.test.js new file mode 100644 index 000000000000..bf6dd3fa4400 --- /dev/null +++ b/packages/astro/test/build-readonly-file.test.js @@ -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(); + }); +}); diff --git a/packages/astro/test/fixtures/build-readonly-file/package.json b/packages/astro/test/fixtures/build-readonly-file/package.json new file mode 100644 index 000000000000..6ec4bae2ca2e --- /dev/null +++ b/packages/astro/test/fixtures/build-readonly-file/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/build-readonly-file", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/build-readonly-file/public/test.txt b/packages/astro/test/fixtures/build-readonly-file/public/test.txt new file mode 100644 index 000000000000..30d74d258442 --- /dev/null +++ b/packages/astro/test/fixtures/build-readonly-file/public/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/packages/astro/test/fixtures/build-readonly-file/src/pages/index.astro b/packages/astro/test/fixtures/build-readonly-file/src/pages/index.astro new file mode 100644 index 000000000000..56c6ade3b45d --- /dev/null +++ b/packages/astro/test/fixtures/build-readonly-file/src/pages/index.astro @@ -0,0 +1,5 @@ +--- +--- + \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1cd930ed3b79..d36088bc2e69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: