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

fix(vercel): handle integration static assets in non-static sites #516

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-snails-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fixes a bug that prevented integration-generated static assets from being deployed with non-static sites
14 changes: 6 additions & 8 deletions packages/vercel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ export default function vercelAdapter({
name: 'astro:copy-vercel-output',
hooks: {
'astro:build:done': async () => {
if (_buildOutput === 'static') {
cpSync(_config.outDir, new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});
}
logger.info('Copying static files to .vercel/output/static');
const staticDir =
_buildOutput === 'static' ? _config.outDir : _config.build.client;
cpSync(staticDir, new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});
},
},
},
Expand Down Expand Up @@ -329,9 +330,6 @@ export default function vercelAdapter({
mkdirSync(new URL('./.vercel/output/server/', _config.root));

if (_buildOutput !== 'static') {
cpSync(_config.build.client, new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});
cpSync(_config.build.server, new URL('./.vercel/output/_functions/', _config.root), {
recursive: true,
});
Expand Down
16 changes: 10 additions & 6 deletions packages/vercel/test/integration-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';

describe('Assets generated by integrations', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;

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

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