Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 3fe04eb

Browse files
authored
fix(vercel): handle integration static assets in non-static sites (#516)
* fix: arrange assets for server output too * Changeset * Format
1 parent c61df56 commit 3fe04eb

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

.changeset/loud-snails-float.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/vercel': patch
3+
---
4+
5+
Fixes a bug that prevented integration-generated static assets from being deployed with non-static sites

packages/vercel/src/index.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ export default function vercelAdapter({
220220
name: 'astro:copy-vercel-output',
221221
hooks: {
222222
'astro:build:done': async () => {
223-
if (_buildOutput === 'static') {
224-
cpSync(_config.outDir, new URL('./.vercel/output/static/', _config.root), {
225-
recursive: true,
226-
});
227-
}
223+
logger.info('Copying static files to .vercel/output/static');
224+
const staticDir =
225+
_buildOutput === 'static' ? _config.outDir : _config.build.client;
226+
cpSync(staticDir, new URL('./.vercel/output/static/', _config.root), {
227+
recursive: true,
228+
});
228229
},
229230
},
230231
},
@@ -329,9 +330,6 @@ export default function vercelAdapter({
329330
mkdirSync(new URL('./.vercel/output/server/', _config.root));
330331

331332
if (_buildOutput !== 'static') {
332-
cpSync(_config.build.client, new URL('./.vercel/output/static/', _config.root), {
333-
recursive: true,
334-
});
335333
cpSync(_config.build.server, new URL('./.vercel/output/_functions/', _config.root), {
336334
recursive: true,
337335
});

packages/vercel/test/integration-assets.test.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ import { before, describe, it } from 'node:test';
33
import { loadFixture } from './test-utils.js';
44

55
describe('Assets generated by integrations', () => {
6-
/** @type {import('./test-utils.js').Fixture} */
7-
let fixture;
8-
9-
before(async () => {
10-
fixture = await loadFixture({
6+
it('moves static assets generated by integrations to the correct location: static output', async () => {
7+
const fixture = await loadFixture({
118
root: './fixtures/integration-assets/',
129
});
1310
await fixture.build();
11+
const sitemap = await fixture.readFile('../.vercel/output/static/sitemap-index.xml');
12+
assert(sitemap.includes('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
1413
});
1514

16-
it('moves static assets generated by integrations to the correct location', async () => {
15+
it('moves static assets generated by integrations to the correct location: server output', async () => {
16+
const fixture = await loadFixture({
17+
root: './fixtures/integration-assets/',
18+
output: 'server',
19+
});
20+
await fixture.build();
1721
const sitemap = await fixture.readFile('../.vercel/output/static/sitemap-index.xml');
1822
assert(sitemap.includes('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
1923
});

0 commit comments

Comments
 (0)