Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vercel): copy static assets after all integrations #508

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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/fluffy-icons-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fixes a bug that prevented static assets generated by integrations from being deployed
26 changes: 20 additions & 6 deletions packages/vercel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ export default function vercelAdapter({
format: 'directory',
redirects: false,
},
integrations: [
{
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,
});
}
},
},
},
],
vite: {
ssr: {
external: ['@vercel/nft'],
Expand Down Expand Up @@ -308,13 +322,13 @@ export default function vercelAdapter({
if (existsSync(staticDir)) {
emptyDir(staticDir);
}
mkdirSync(new URL('./.vercel/output/static/', _config.root), { recursive: true });
mkdirSync(new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});

if (_buildOutput === 'static' && staticDir) {
cpSync(_config.outDir, new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});
} else {
mkdirSync(new URL('./.vercel/output/server/', _config.root));

if (_buildOutput !== 'static') {
cpSync(_config.build.client, new URL('./.vercel/output/static/', _config.root), {
recursive: true,
});
Expand Down
10 changes: 10 additions & 0 deletions packages/vercel/test/fixtures/integration-assets/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import vercel from '@astrojs/vercel';
import { defineConfig } from 'astro/config';

import sitemap from '@astrojs/sitemap';

export default defineConfig({
site: 'https://example.com',
adapter: vercel({}),
integrations: [sitemap()]
});
10 changes: 10 additions & 0 deletions packages/vercel/test/fixtures/integration-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@test/astro-vercel-integration-assets",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/sitemap": "^3.2.1",
"@astrojs/vercel": "workspace:*",
"astro": "^5.1.6"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>One</title>
</head>
<body>
<h1>One</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Two</title>
</head>
<body>
<h1>Two</h1>
</body>
</html>
20 changes: 20 additions & 0 deletions packages/vercel/test/integration-assets.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from 'node:assert/strict';
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({
root: './fixtures/integration-assets/',
});
await fixture.build();
});

it('moves static assets generated by integrations to the correct location', async () => {
const sitemap = await fixture.readFile('../.vercel/output/static/sitemap-index.xml');
assert(sitemap.includes('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
});
});
61 changes: 61 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading