diff options
author | 2024-09-11 14:26:50 +0200 | |
---|---|---|
committer | 2024-09-11 14:26:50 +0200 | |
commit | 4d6e5601abc0cd9dfa1978b2c089125c740e8e0c (patch) | |
tree | c93f736dc5f9afb40ed0b3856840c730392e5207 /packages/integrations/vercel/src | |
parent | 2ed1753cb46bac703717f201cc71d2ab3f53a4b7 (diff) | |
download | astro-4d6e5601abc0cd9dfa1978b2c089125c740e8e0c.tar.gz astro-4d6e5601abc0cd9dfa1978b2c089125c740e8e0c.tar.zst astro-4d6e5601abc0cd9dfa1978b2c089125c740e8e0c.zip |
feat: remove hybrid (#375)
* feat: remove hybrid
* fix: udpate with new API
* fix: update for latest next changes
* fix: more test-utils fix
* fix: build
* fix: build
* fix: tests
* fix: netlify
* fix: astro env
* fix: use types from AStro
* chore: changeset
Diffstat (limited to 'packages/integrations/vercel/src')
-rw-r--r-- | packages/integrations/vercel/src/lib/prerender.ts | 5 | ||||
-rw-r--r-- | packages/integrations/vercel/src/serverless/adapter.ts | 77 | ||||
-rw-r--r-- | packages/integrations/vercel/src/static/adapter.ts | 6 |
3 files changed, 37 insertions, 51 deletions
diff --git a/packages/integrations/vercel/src/lib/prerender.ts b/packages/integrations/vercel/src/lib/prerender.ts deleted file mode 100644 index f69f3b5d4..000000000 --- a/packages/integrations/vercel/src/lib/prerender.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { AstroConfig } from 'astro'; - -export function isServerLikeOutput(config: AstroConfig) { - return config.output === 'server' || config.output === 'hybrid'; -} diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index a762103f9..b8cf1f2bc 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -84,6 +84,7 @@ function getAdapter({ args: { middlewareSecret, skewProtection }, adapterFeatures: { edgeMiddleware, + buildOutput: 'server', }, supportedAstroFeatures: { hybridOutput: 'stable', @@ -235,10 +236,10 @@ export default function vercelServerless({ if (vercelConfig.trailingSlash === true && config.trailingSlash === 'always') { logger.warn( '\n' + - `\tYour "vercel.json" \`trailingSlash\` configuration (set to \`true\`) will conflict with your Astro \`trailinglSlash\` configuration (set to \`"always"\`).\n` + - // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> - `\tThis would cause infinite redirects under certain conditions and throw an \`ERR_TOO_MANY_REDIRECTS\` error.\n` + - `\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n` + `\tYour "vercel.json" \`trailingSlash\` configuration (set to \`true\`) will conflict with your Astro \`trailinglSlash\` configuration (set to \`"always"\`).\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tThis would cause infinite redirects under certain conditions and throw an \`ERR_TOO_MANY_REDIRECTS\` error.\n` + + `\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n` ); updateConfig({ trailingSlash: 'ignore', @@ -280,12 +281,6 @@ export default function vercelServerless({ _config = config; _buildTempFolder = config.build.server; _serverEntry = config.build.serverEntry; - - if (config.output === 'static') { - throw new AstroError( - '`output: "server"` or `output: "hybrid"` is required to use the serverless adapter.' - ); - } }, 'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => { _entryPoints = new Map( @@ -394,31 +389,31 @@ export default function vercelServerless({ ...routeDefinitions, ...(fourOhFourRoute ? [ - { - src: '/.*', - dest: fourOhFourRoute.prerender - ? '/404.html' - : _middlewareEntryPoint - ? MIDDLEWARE_PATH - : NODE_PATH, - status: 404, - }, - ] + { + src: '/.*', + dest: fourOhFourRoute.prerender + ? '/404.html' + : _middlewareEntryPoint + ? MIDDLEWARE_PATH + : NODE_PATH, + status: 404, + }, + ] : []), ], ...(imageService || imagesConfig ? { - images: imagesConfig - ? { - ...imagesConfig, - domains: [...imagesConfig.domains, ..._config.image.domains], - remotePatterns: [ - ...(imagesConfig.remotePatterns ?? []), - ..._config.image.remotePatterns, - ], - } - : getDefaultImageConfig(_config.image), - } + images: imagesConfig + ? { + ...imagesConfig, + domains: [...imagesConfig.domains, ..._config.image.domains], + remotePatterns: [ + ...(imagesConfig.remotePatterns ?? []), + ..._config.image.remotePatterns, + ], + } + : getDefaultImageConfig(_config.image), + } : {}), }); @@ -451,7 +446,7 @@ class VercelBuilder { readonly logger: AstroIntegrationLogger, readonly maxDuration?: number, readonly runtime = getRuntime(process, logger) - ) { } + ) {} async buildServerlessFolder(entry: URL, functionName: string) { const { config, includeFiles, excludeFiles, logger, NTF_CACHE, runtime, maxDuration } = this; @@ -531,11 +526,11 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru // biome-ignore lint/style/useTemplate: <explanation> // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\n` + - `\tThe local Node.js version (${major}) is not supported by Vercel Serverless Functions.\n` + - // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> - `\tYour project will use Node.js 18 as the runtime instead.\n` + - // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> - `\tConsider switching your local version to 18.\n` + `\tThe local Node.js version (${major}) is not supported by Vercel Serverless Functions.\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tYour project will use Node.js 18 as the runtime instead.\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tConsider switching your local version to 18.\n` ); return 'nodejs18.x'; } @@ -564,10 +559,10 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru // biome-ignore lint/style/useTemplate: <explanation> // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\n` + - `\tYour project is being built for Node.js ${major} as the runtime.\n` + - `\tThis version is deprecated by Vercel Serverless Functions, and scheduled to be disabled on ${removeDate}.\n` + - // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> - `\tConsider upgrading your local version to 18.\n` + `\tYour project is being built for Node.js ${major} as the runtime.\n` + + `\tThis version is deprecated by Vercel Serverless Functions, and scheduled to be disabled on ${removeDate}.\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tConsider upgrading your local version to 18.\n` ); return `nodejs${major}.x`; } diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 92c067114..f3149bdb2 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -7,7 +7,6 @@ import { getAstroImageConfig, getDefaultImageConfig, } from '../image/shared.js'; -import { isServerLikeOutput } from '../lib/prerender.js'; import { getRedirects } from '../lib/redirects.js'; import { type VercelSpeedInsightsConfig, @@ -34,6 +33,7 @@ function getAdapter(): AstroAdapter { envGetSecret: 'unsupported', }, adapterFeatures: { + buildOutput: 'static', edgeMiddleware: false, }, }; @@ -100,10 +100,6 @@ export default function vercelStatic({ 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter()); _config = config; - - if (isServerLikeOutput(config)) { - throw new Error(`${PACKAGE_NAME} should be used with output: 'static'`); - } }, 'astro:build:start': async () => { // Ensure to have `.vercel/output` empty. |