mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
feat: adapter features, deprecate astro configs (#7839)
This commit is contained in:
parent
18a0d229c3
commit
469345aa31
9 changed files with 62 additions and 17 deletions
|
@ -29,11 +29,21 @@ const SUPPORTED_NODE_VERSIONS: Record<
|
|||
18: { status: 'current' },
|
||||
};
|
||||
|
||||
function getAdapter(): AstroAdapter {
|
||||
function getAdapter({
|
||||
edgeMiddleware,
|
||||
functionPerRoute,
|
||||
}: {
|
||||
edgeMiddleware: boolean;
|
||||
functionPerRoute: boolean;
|
||||
}): AstroAdapter {
|
||||
return {
|
||||
name: PACKAGE_NAME,
|
||||
serverEntrypoint: `${PACKAGE_NAME}/entrypoint`,
|
||||
exports: ['default'],
|
||||
adapterFeatures: {
|
||||
edgeMiddleware,
|
||||
functionPerRoute,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -43,6 +53,8 @@ export interface VercelServerlessConfig {
|
|||
analytics?: boolean;
|
||||
imageService?: boolean;
|
||||
imagesConfig?: VercelImageConfig;
|
||||
edgeMiddleware?: boolean;
|
||||
functionPerRoute?: boolean;
|
||||
}
|
||||
|
||||
export default function vercelServerless({
|
||||
|
@ -51,6 +63,8 @@ export default function vercelServerless({
|
|||
analytics,
|
||||
imageService,
|
||||
imagesConfig,
|
||||
functionPerRoute = false,
|
||||
edgeMiddleware = false,
|
||||
}: VercelServerlessConfig = {}): AstroIntegration {
|
||||
let _config: AstroConfig;
|
||||
let buildTempFolder: URL;
|
||||
|
@ -112,7 +126,7 @@ export default function vercelServerless({
|
|||
},
|
||||
'astro:config:done': ({ setAdapter, config }) => {
|
||||
throwIfAssetsNotEnabled(config, imageService);
|
||||
setAdapter(getAdapter());
|
||||
setAdapter(getAdapter({ functionPerRoute, edgeMiddleware }));
|
||||
_config = config;
|
||||
buildTempFolder = config.build.server;
|
||||
serverEntry = config.build.serverEntry;
|
||||
|
|
|
@ -2,5 +2,7 @@ import { defineConfig } from 'astro/config';
|
|||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel()
|
||||
adapter: vercel({
|
||||
functionPerRoute: true
|
||||
})
|
||||
});
|
||||
|
|
9
packages/integrations/vercel/test/fixtures/functionPerRoute/astro.config.mjs
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/functionPerRoute/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel({
|
||||
functionPerRoute: true
|
||||
}),
|
||||
output: "server"
|
||||
});
|
9
packages/integrations/vercel/test/fixtures/functionPerRoute/package.json
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/functionPerRoute/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/astro-vercel-function-per-route",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/vercel": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
8
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/one.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>One</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>One</h1>
|
||||
</body>
|
||||
</html>
|
8
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/two.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/two.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Two</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Two</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -2,9 +2,8 @@ import {defineConfig} from "astro/config";
|
|||
import vercel from "@astrojs/vercel/serverless";
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel(),
|
||||
build: {
|
||||
excludeMiddleware: true
|
||||
},
|
||||
adapter: vercel({
|
||||
edgeMiddleware: true
|
||||
}),
|
||||
output: 'server'
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,9 +2,8 @@ import {defineConfig} from "astro/config";
|
|||
import vercel from "@astrojs/vercel/serverless";
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel(),
|
||||
build: {
|
||||
excludeMiddleware: true
|
||||
},
|
||||
adapter: vercel({
|
||||
edgeMiddleware: true
|
||||
}),
|
||||
output: 'server'
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,11 +7,8 @@ describe('build: split', () => {
|
|||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/basic/',
|
||||
root: './fixtures/functionPerRoute/',
|
||||
output: 'server',
|
||||
build: {
|
||||
split: true,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue