Skip to content

Commit

Permalink
fix(vercel): handle integration static assets in non-static sites (#516)
Browse files Browse the repository at this point in the history
* fix: arrange assets for server output too

* Changeset

* Format
  • Loading branch information
ascorbic authored Jan 23, 2025
1 parent c61df56 commit 3fe04eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
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

0 comments on commit 3fe04eb

Please sign in to comment.