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

Commit af69a12

Browse files
authored
fix(vercel): copy static assets after all integrations (#508)
* fix(vercel): copy static assets after all integrations * Format * Fix logic * Format
1 parent ce66003 commit af69a12

File tree

8 files changed

+142
-6
lines changed

8 files changed

+142
-6
lines changed

.changeset/fluffy-icons-beg.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 static assets generated by integrations from being deployed

packages/vercel/src/index.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ export default function vercelAdapter({
215215
format: 'directory',
216216
redirects: false,
217217
},
218+
integrations: [
219+
{
220+
name: 'astro:copy-vercel-output',
221+
hooks: {
222+
'astro:build:done': async () => {
223+
if (_buildOutput === 'static') {
224+
cpSync(_config.outDir, new URL('./.vercel/output/static/', _config.root), {
225+
recursive: true,
226+
});
227+
}
228+
},
229+
},
230+
},
231+
],
218232
vite: {
219233
ssr: {
220234
external: ['@vercel/nft'],
@@ -308,13 +322,13 @@ export default function vercelAdapter({
308322
if (existsSync(staticDir)) {
309323
emptyDir(staticDir);
310324
}
311-
mkdirSync(new URL('./.vercel/output/static/', _config.root), { recursive: true });
325+
mkdirSync(new URL('./.vercel/output/static/', _config.root), {
326+
recursive: true,
327+
});
312328

313-
if (_buildOutput === 'static' && staticDir) {
314-
cpSync(_config.outDir, new URL('./.vercel/output/static/', _config.root), {
315-
recursive: true,
316-
});
317-
} else {
329+
mkdirSync(new URL('./.vercel/output/server/', _config.root));
330+
331+
if (_buildOutput !== 'static') {
318332
cpSync(_config.build.client, new URL('./.vercel/output/static/', _config.root), {
319333
recursive: true,
320334
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import vercel from '@astrojs/vercel';
2+
import { defineConfig } from 'astro/config';
3+
4+
import sitemap from '@astrojs/sitemap';
5+
6+
export default defineConfig({
7+
site: 'https://example.com',
8+
adapter: vercel({}),
9+
integrations: [sitemap()]
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@test/astro-vercel-integration-assets",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"@astrojs/sitemap": "^3.2.1",
7+
"@astrojs/vercel": "workspace:*",
8+
"astro": "^5.1.6"
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>One</title>
4+
</head>
5+
<body>
6+
<h1>One</h1>
7+
</body>
8+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Two</title>
4+
</head>
5+
<body>
6+
<h1>Two</h1>
7+
</body>
8+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from 'node:assert/strict';
2+
import { before, describe, it } from 'node:test';
3+
import { loadFixture } from './test-utils.js';
4+
5+
describe('Assets generated by integrations', () => {
6+
/** @type {import('./test-utils.js').Fixture} */
7+
let fixture;
8+
9+
before(async () => {
10+
fixture = await loadFixture({
11+
root: './fixtures/integration-assets/',
12+
});
13+
await fixture.build();
14+
});
15+
16+
it('moves static assets generated by integrations to the correct location', async () => {
17+
const sitemap = await fixture.readFile('../.vercel/output/static/sitemap-index.xml');
18+
assert(sitemap.includes('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
19+
});
20+
});

pnpm-lock.yaml

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)