diff options
Diffstat (limited to 'packages/integrations/vercel')
16 files changed, 169 insertions, 30 deletions
diff --git a/packages/integrations/vercel/CHANGELOG.md b/packages/integrations/vercel/CHANGELOG.md index 899005dc0..ebc411bcd 100644 --- a/packages/integrations/vercel/CHANGELOG.md +++ b/packages/integrations/vercel/CHANGELOG.md @@ -1,5 +1,81 @@ # @astrojs/vercel +## 4.0.0-beta.0 + +### Major Changes + +- [`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 16. The lowest supported version by Astro and all integrations is now v18.14.1. As a reminder, Node 16 will be deprecated on the 11th September 2023. + +- [`c022a4217`](https://github.com/withastro/astro/commit/c022a4217a805d223c1494e9eda4e48bbf810388) Thanks [@Princesseuh](https://github.com/Princesseuh)! - When using an adapter that supports neither Squoosh or Sharp, Astro will now automatically use an image service that does not support processing, but still provides the other benefits of `astro:assets` such as enforcing `alt`, no CLS etc to users + +- [`3dc1ca2fa`](https://github.com/withastro/astro/commit/3dc1ca2fac8d9965cc5085a5d09e72ed87b4281a) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Reduced the amount of polyfills provided by Astro. Astro will no longer provide (no-op) polyfills for several web apis such as HTMLElement, Image or Document. If you need access to those APIs on the server, we recommend using more proper polyfills available on npm. + +### Minor Changes + +- [`9b4f70a62`](https://github.com/withastro/astro/commit/9b4f70a629f55e461759ba46f68af7097a2e9215) Thanks [@ematipico](https://github.com/ematipico)! - Introduced the concept of feature map. A feature map is a list of features that are built-in in Astro, and an Adapter + can tell Astro if it can support it. + + ```ts + import { AstroIntegration } from './astro'; + + function myIntegration(): AstroIntegration { + return { + name: 'astro-awesome-list', + // new feature map + supportedAstroFeatures: { + hybridOutput: 'experimental', + staticOutput: 'stable', + serverOutput: 'stable', + assets: { + supportKind: 'stable', + isSharpCompatible: false, + isSquooshCompatible: false, + }, + }, + }; + } + ``` + +- [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769) Thanks [@ematipico](https://github.com/ematipico)! - The `build.split` and `build.excludeMiddleware` configuration options are deprecated and have been replaced by options in the adapter config. + + If your config includes the `build.excludeMiddleware` option, replace it with `edgeMiddleware` in your adapter options: + + ```diff + import { defineConfig } from "astro/config"; + import vercel from "@astrojs/vercel/serverless"; + + export default defineConfig({ + build: { + - excludeMiddleware: true + }, + adapter: vercel({ + + edgeMiddleware: true + }), + }); + ``` + + If your config includes the `build.split` option, replace it with `functionPerRoute` in your adapter options: + + ```diff + import { defineConfig } from "astro/config"; + import vercel from "@astrojs/vercel/serverless"; + + export default defineConfig({ + build: { + - split: true + }, + adapter: vercel({ + + functionPerRoute: true + }), + }); + ``` + +### Patch Changes + +- Updated dependencies [[`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81), [`76ddef19c`](https://github.com/withastro/astro/commit/76ddef19ccab6e5f7d3a5740cd41acf10e334b38), [`9b4f70a62`](https://github.com/withastro/astro/commit/9b4f70a629f55e461759ba46f68af7097a2e9215), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`2f951cd40`](https://github.com/withastro/astro/commit/2f951cd403dfcc2c3ca6aae618ae3e1409516e32), [`c022a4217`](https://github.com/withastro/astro/commit/c022a4217a805d223c1494e9eda4e48bbf810388), [`67becaa58`](https://github.com/withastro/astro/commit/67becaa580b8f787df58de66b7008b7098f1209c), [`bc37331d8`](https://github.com/withastro/astro/commit/bc37331d8154e3e95a8df9131e4e014e78a7a9e7), [`dfc2d93e3`](https://github.com/withastro/astro/commit/dfc2d93e3c645995379358fabbdfa9aab99f43d8), [`3dc1ca2fa`](https://github.com/withastro/astro/commit/3dc1ca2fac8d9965cc5085a5d09e72ed87b4281a), [`1be84dfee`](https://github.com/withastro/astro/commit/1be84dfee3ce8e6f5cc624f99aec4e980f6fde37), [`35f01df79`](https://github.com/withastro/astro/commit/35f01df797d23315f2bee2fc3fd795adb0559c58), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`78de801f2`](https://github.com/withastro/astro/commit/78de801f21fd4ca1653950027d953bf08614566b), [`59d6e569f`](https://github.com/withastro/astro/commit/59d6e569f63e175c97e82e94aa7974febfb76f7c), [`7723c4cc9`](https://github.com/withastro/astro/commit/7723c4cc93298c2e6530e55da7afda048f22cf81), [`fb5cd6b56`](https://github.com/withastro/astro/commit/fb5cd6b56dc27a71366ed5e1ab8bfe9b8f96bac5), [`631b9c410`](https://github.com/withastro/astro/commit/631b9c410d5d66fa384674027ba95d69ebb5063f)]: + - astro@3.0.0-beta.0 + - @astrojs/internal-helpers@0.2.0-beta.0 + ## 3.8.0 ### Minor Changes diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index 39451bd41..3c13c8a98 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/vercel", "description": "Deploy your site to Vercel", - "version": "3.8.0", + "version": "4.0.0-beta.0", "type": "module", "author": "withastro", "license": "MIT", @@ -51,17 +51,16 @@ "test:hosted": "mocha --exit --timeout 30000 test/hosted" }, "dependencies": { - "@astrojs/internal-helpers": "^0.1.2", - "@astrojs/webapi": "^2.2.0", + "@astrojs/internal-helpers": "workspace:*", "@vercel/analytics": "^0.1.11", "@vercel/nft": "^0.22.6", - "esbuild": "^0.17.19", + "esbuild": "^0.18.16", "fast-glob": "^3.2.12", "set-cookie-parser": "^2.6.0", "web-vitals": "^3.3.2" }, "peerDependencies": { - "astro": "workspace:^2.10.4" + "astro": "workspace:^3.0.0-beta.0" }, "devDependencies": { "@types/set-cookie-parser": "^2.4.2", diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index b83c9f2b7..b613f502c 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -27,6 +27,16 @@ function getAdapter(): AstroAdapter { name: PACKAGE_NAME, serverEntrypoint: `${PACKAGE_NAME}/entrypoint`, exports: ['default'], + supportedAstroFeatures: { + hybridOutput: 'stable', + staticOutput: 'stable', + serverOutput: 'stable', + assets: { + supportKind: 'stable', + isSharpCompatible: false, + isSquooshCompatible: false, + }, + }, }; } diff --git a/packages/integrations/vercel/src/image/dev-service.ts b/packages/integrations/vercel/src/image/dev-service.ts index 04df9932a..d812efb93 100644 --- a/packages/integrations/vercel/src/image/dev-service.ts +++ b/packages/integrations/vercel/src/image/dev-service.ts @@ -1,5 +1,4 @@ import type { LocalImageService } from 'astro'; -// @ts-expect-error import squooshService from 'astro/assets/services/squoosh'; import { sharedValidateOptions } from './shared'; @@ -14,7 +13,9 @@ const service: LocalImageService = { props.width = inputtedWidth; } - return squooshService.getHTMLAttributes(props, serviceOptions); + return squooshService.getHTMLAttributes + ? squooshService.getHTMLAttributes(props, serviceOptions) + : {}; }, getURL(options) { const fileSrc = typeof options.src === 'string' ? options.src : options.src.src; diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 1a2f9d82a..9a8ead137 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -29,11 +29,31 @@ 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, + }, + supportedAstroFeatures: { + hybridOutput: 'stable', + staticOutput: 'stable', + serverOutput: 'stable', + assets: { + supportKind: 'stable', + isSharpCompatible: true, + isSquooshCompatible: true, + }, + }, }; } @@ -43,6 +63,8 @@ export interface VercelServerlessConfig { analytics?: boolean; imageService?: boolean; imagesConfig?: VercelImageConfig; + edgeMiddleware?: boolean; + functionPerRoute?: boolean; } export default function vercelServerless({ @@ -51,6 +73,8 @@ export default function vercelServerless({ analytics, imageService, imagesConfig, + functionPerRoute = false, + edgeMiddleware = false, }: VercelServerlessConfig = {}): AstroIntegration { let _config: AstroConfig; let buildTempFolder: URL; @@ -112,7 +136,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; diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index 9e3cb1da0..f132d71f3 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -1,14 +1,12 @@ -import { polyfill } from '@astrojs/webapi'; import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; +import { applyPolyfills } from 'astro/app/node'; import type { IncomingMessage, ServerResponse } from 'node:http'; import { ASTRO_LOCALS_HEADER } from './adapter'; import { getRequest, setResponse } from './request-transform'; -polyfill(globalThis, { - exclude: 'window document', -}); +applyPolyfills(); export const createExports = (manifest: SSRManifest) => { const app = new App(manifest); diff --git a/packages/integrations/vercel/test/fixtures/basic/astro.config.mjs b/packages/integrations/vercel/test/fixtures/basic/astro.config.mjs index 664b64d56..6e2e304d9 100644 --- a/packages/integrations/vercel/test/fixtures/basic/astro.config.mjs +++ b/packages/integrations/vercel/test/fixtures/basic/astro.config.mjs @@ -2,5 +2,7 @@ import { defineConfig } from 'astro/config'; import vercel from '@astrojs/vercel/serverless'; export default defineConfig({ - adapter: vercel() + adapter: vercel({ + functionPerRoute: true + }) }); diff --git a/packages/integrations/vercel/test/fixtures/functionPerRoute/astro.config.mjs b/packages/integrations/vercel/test/fixtures/functionPerRoute/astro.config.mjs new file mode 100644 index 000000000..fefc69a83 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/functionPerRoute/astro.config.mjs @@ -0,0 +1,9 @@ +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/serverless'; + +export default defineConfig({ + adapter: vercel({ + functionPerRoute: true + }), + output: "server" +}); diff --git a/packages/integrations/vercel/test/fixtures/functionPerRoute/package.json b/packages/integrations/vercel/test/fixtures/functionPerRoute/package.json new file mode 100644 index 000000000..e33f178bb --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/functionPerRoute/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-vercel-function-per-route", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/vercel": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/one.astro b/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/one.astro new file mode 100644 index 000000000..0c7fb90a7 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/one.astro @@ -0,0 +1,8 @@ +<html> + <head> + <title>One</title> + </head> + <body> + <h1>One</h1> + </body> +</html> diff --git a/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/two.astro b/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/two.astro new file mode 100644 index 000000000..e7ba9910e --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/two.astro @@ -0,0 +1,8 @@ +<html> + <head> + <title>Two</title> + </head> + <body> + <h1>Two</h1> + </body> +</html> diff --git a/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/astro.config.mjs b/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/astro.config.mjs index 321a8bde3..33910b50a 100644 --- a/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/astro.config.mjs +++ b/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/astro.config.mjs @@ -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' -});
\ No newline at end of file +}); diff --git a/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/astro.config.mjs b/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/astro.config.mjs index 321a8bde3..33910b50a 100644 --- a/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/astro.config.mjs +++ b/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/astro.config.mjs @@ -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' -});
\ No newline at end of file +}); diff --git a/packages/integrations/vercel/test/no-output.test.js b/packages/integrations/vercel/test/no-output.test.js index af4d9c2b6..3894ee779 100644 --- a/packages/integrations/vercel/test/no-output.test.js +++ b/packages/integrations/vercel/test/no-output.test.js @@ -19,6 +19,6 @@ describe('Missing output config', () => { error = err; } expect(error).to.not.be.equal(undefined); - expect(error.message).to.include(`output: "server"`); + expect(error.message).to.include('output: "server"'); }); }); diff --git a/packages/integrations/vercel/test/split.test.js b/packages/integrations/vercel/test/split.test.js index 9044954f2..85affb3ff 100644 --- a/packages/integrations/vercel/test/split.test.js +++ b/packages/integrations/vercel/test/split.test.js @@ -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(); }); diff --git a/packages/integrations/vercel/tsconfig.json b/packages/integrations/vercel/tsconfig.json index 64d4ef454..af1b43564 100644 --- a/packages/integrations/vercel/tsconfig.json +++ b/packages/integrations/vercel/tsconfig.json @@ -5,6 +5,6 @@ "allowJs": true, "module": "ES2022", "outDir": "./dist", - "target": "ES2021" + "target": "ES2022" } } |