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

Commit

Permalink
fix(vercel): copy static assets after all integrations (#508)
Browse files Browse the repository at this point in the history
* fix(vercel): copy static assets after all integrations

* Format

* Fix logic

* Format
  • Loading branch information
ascorbic authored Jan 20, 2025
1 parent ce66003 commit af69a12
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 6 deletions.
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.

0 comments on commit af69a12

Please sign in to comment.