Skip to content

Commit

Permalink
Adapter related changes for IntegrationData (#377)
Browse files Browse the repository at this point in the history
* chore: port adapter related changes from astro #11864

* chore: bump version

* chore: bump

* fix: types

* fix

* fix: tests

* fix: locals

* Update expected image endpoint

---------

Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Matthew Phillips <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent f952649 commit bea4ad2
Show file tree
Hide file tree
Showing 26 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions packages/integrations/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"web-vitals": "^3.5.2"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"astro": "^5.0.0-alpha.6",
"astro": "^5.0.0-alpha.8",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/vercel/src/lib/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nodePath from 'node:path';
import { appendForwardSlash, removeLeadingForwardSlash } from '@astrojs/internal-helpers/path';
import type { AstroConfig, RouteData, RoutePart } from 'astro';
import type { AstroConfig, IntegrationRouteData, RoutePart } from 'astro';

const pathJoin = nodePath.posix.join;

Expand Down Expand Up @@ -85,7 +85,7 @@ function getReplacePattern(segments: RoutePart[][]) {
return result;
}

function getRedirectLocation(route: RouteData, config: AstroConfig): string {
function getRedirectLocation(route: IntegrationRouteData, config: AstroConfig): string {
if (route.redirectRoute) {
const pattern = getReplacePattern(route.redirectRoute.segments);
const path = config.trailingSlash === 'always' ? appendForwardSlash(pattern) : pattern;
Expand All @@ -99,7 +99,7 @@ function getRedirectLocation(route: RouteData, config: AstroConfig): string {
}
}

function getRedirectStatus(route: RouteData): number {
function getRedirectStatus(route: IntegrationRouteData): number {
if (typeof route.redirect === 'object') {
return route.redirect.status;
}
Expand All @@ -116,7 +116,7 @@ export function escapeRegex(content: string) {
return `^/${getMatchPattern(segments)}$`;
}

export function getRedirects(routes: RouteData[], config: AstroConfig): VercelRoute[] {
export function getRedirects(routes: IntegrationRouteData[], config: AstroConfig): VercelRoute[] {
// biome-ignore lint/style/useConst: <explanation>
let redirects: VercelRoute[] = [];

Expand Down
7 changes: 4 additions & 3 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
AstroConfig,
AstroIntegration,
AstroIntegrationLogger,
RouteData,
IntegrationRouteData,
} from 'astro';
import { AstroError } from 'astro/errors';
import glob from 'fast-glob';
Expand Down Expand Up @@ -193,7 +193,7 @@ export default function vercelServerless({
let _config: AstroConfig;
let _buildTempFolder: URL;
let _serverEntry: string;
let _entryPoints: Map<RouteData, URL>;
let _entryPoints: Map<IntegrationRouteData, URL>;
let _middlewareEntryPoint: URL | undefined;
// Extra files to be merged with `includeFiles` during build
const extraFilesToInclude: URL[] = [];
Expand Down Expand Up @@ -314,7 +314,8 @@ export default function vercelServerless({

// Multiple entrypoint support
if (_entryPoints.size) {
const getRouteFuncName = (route: RouteData) => route.component.replace('src/pages/', '');
const getRouteFuncName = (route: IntegrationRouteData) =>
route.component.replace('src/pages/', '');

const getFallbackFuncName = (entryFile: URL) =>
basename(entryFile.toString())
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/serverless/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default async function middleware(request, context) {
request,
params: {}
});
ctx.locals = { vercel: { edge: context }, ...${handlerTemplateCall} };
Object.assign(ctx.locals, { vercel: { edge: context }, ...${handlerTemplateCall} });
const { origin } = new URL(request.url);
const next = async () => {
const { vercel, ...locals } = ctx.locals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from 'astro/config';

export default defineConfig({
output: "server",
adapter: vercel(),
experimental: {
serverIslands: true,
}
adapter: vercel()
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "^5.0.0-alpha.6"
"astro": "^5.0.0-alpha.8"
}
}
2 changes: 1 addition & 1 deletion packages/integrations/vercel/test/isr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ISR', () => {
dest: '/_isr?x_astro_path=$0',
},
{
src: '^\\/_image$',
src: '^\\/_image\\/?$',
dest: '_render',
},
]);
Expand Down

0 comments on commit bea4ad2

Please sign in to comment.