summaryrefslogtreecommitdiff
path: root/packages/integrations
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations')
-rw-r--r--packages/integrations/vercel/package.json4
-rw-r--r--packages/integrations/vercel/src/lib/speed-insights.ts30
-rw-r--r--packages/integrations/vercel/src/serverless/adapter.ts18
-rw-r--r--packages/integrations/vercel/src/speed-insights.ts68
-rw-r--r--packages/integrations/vercel/src/static/adapter.ts19
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/astro.config.mjs10
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/package.json9
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/one.astro8
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/two.astro8
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/astro.config.mjs10
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/package.json9
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/one.astro8
-rw-r--r--packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/two.astro8
-rw-r--r--packages/integrations/vercel/test/speed-insights.test.js47
14 files changed, 1 insertions, 255 deletions
diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json
index bf1ffbfdc..1ffdfffcf 100644
--- a/packages/integrations/vercel/package.json
+++ b/packages/integrations/vercel/package.json
@@ -20,7 +20,6 @@
"./serverless": "./dist/serverless/adapter.js",
"./serverless/entrypoint": "./dist/serverless/entrypoint.js",
"./static": "./dist/static/adapter.js",
- "./speed-insights": "./dist/speed-insights.js",
"./build-image-service": "./dist/image/build-service.js",
"./dev-image-service": "./dist/image/dev-service.js",
"./package.json": "./package.json"
@@ -43,8 +42,7 @@
"@vercel/edge": "^1.1.2",
"@vercel/nft": "^0.27.4",
"esbuild": "^0.21.5",
- "fast-glob": "^3.3.2",
- "web-vitals": "^3.5.2"
+ "fast-glob": "^3.3.2"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.8"
diff --git a/packages/integrations/vercel/src/lib/speed-insights.ts b/packages/integrations/vercel/src/lib/speed-insights.ts
deleted file mode 100644
index 033a705c5..000000000
--- a/packages/integrations/vercel/src/lib/speed-insights.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-export type VercelSpeedInsightsConfig = {
- enabled: boolean;
-};
-
-export function getSpeedInsightsViteConfig(enabled?: boolean) {
- if (enabled) {
- return {
- define: exposeEnv(['VERCEL_ANALYTICS_ID']),
- };
- }
-
- return {};
-}
-
-/**
- * While Vercel adds the `PUBLIC_` prefix for their `VERCEL_` env vars by default, some env vars
- * like `VERCEL_ANALYTICS_ID` aren't, so handle them here so that it works correctly in runtime.
- */
-export function exposeEnv(envs: string[]): Record<string, unknown> {
- const mapped: Record<string, unknown> = {};
-
- // biome-ignore lint/complexity/noForEach: <explanation>
- envs
- .filter((env) => process.env[env])
- .forEach((env) => {
- mapped[`import.meta.env.PUBLIC_${env}`] = JSON.stringify(process.env[env]);
- });
-
- return mapped;
-}
diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts
index d52adf2a8..f7b3e6ebc 100644
--- a/packages/integrations/vercel/src/serverless/adapter.ts
+++ b/packages/integrations/vercel/src/serverless/adapter.ts
@@ -20,10 +20,6 @@ import {
import { copyDependenciesToFunction } from '../lib/nft.js';
import { escapeRegex, getRedirects } from '../lib/redirects.js';
import {
- type VercelSpeedInsightsConfig,
- getSpeedInsightsViteConfig,
-} from '../lib/speed-insights.js';
-import {
type VercelWebAnalyticsConfig,
getInjectableWebAnalyticsContent,
} from '../lib/web-analytics.js';
@@ -101,15 +97,6 @@ export interface VercelServerlessConfig {
/** Configuration for [Vercel Web Analytics](https://vercel.com/docs/concepts/analytics). */
webAnalytics?: VercelWebAnalyticsConfig;
- /**
- * @deprecated This option lets you configure the legacy speed insights API which is now deprecated by Vercel.
- *
- * See [Vercel Speed Insights Quickstart](https://vercel.com/docs/speed-insights/quickstart) for instructions on how to use the library instead.
- *
- * https://vercel.com/docs/speed-insights/quickstart
- */
- speedInsights?: VercelSpeedInsightsConfig;
-
/** Force files to be bundled with your function. This is helpful when you notice missing files. */
includeFiles?: string[];
@@ -168,7 +155,6 @@ interface VercelISRConfig {
export default function vercelServerless({
webAnalytics,
- speedInsights,
includeFiles: _includeFiles = [],
excludeFiles: _excludeFiles = [],
imageService,
@@ -222,9 +208,6 @@ export default function vercelServerless({
})
);
}
- if (command === 'build' && speedInsights?.enabled) {
- injectScript('page', 'import "@astrojs/vercel/speed-insights"');
- }
const vercelConfigPath = new URL('vercel.json', config.root);
if (existsSync(vercelConfigPath)) {
@@ -255,7 +238,6 @@ export default function vercelServerless({
redirects: false,
},
vite: {
- ...getSpeedInsightsViteConfig(speedInsights?.enabled),
ssr: {
external: ['@vercel/nft'],
},
diff --git a/packages/integrations/vercel/src/speed-insights.ts b/packages/integrations/vercel/src/speed-insights.ts
deleted file mode 100644
index 84aadfc7b..000000000
--- a/packages/integrations/vercel/src/speed-insights.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import type { Metric } from 'web-vitals';
-import { onCLS, onFCP, onFID, onLCP, onTTFB } from 'web-vitals';
-
-const SPEED_INSIGHTS_INTAKE = 'https://vitals.vercel-analytics.com/v1/vitals';
-
-type Options = { path: string; analyticsId: string };
-
-const getConnectionSpeed = () => {
- return 'connection' in navigator &&
- // biome-ignore lint/complexity/useLiteralKeys: <explanation>
- navigator['connection'] &&
- // biome-ignore lint/complexity/useLiteralKeys: <explanation>
- 'effectiveType' in (navigator['connection'] as unknown as { effectiveType: string })
- ? // biome-ignore lint/complexity/useLiteralKeys: <explanation>
- (navigator['connection'] as unknown as { effectiveType: string })['effectiveType']
- : '';
-};
-
-const sendToSpeedInsights = (metric: Metric, options: Options) => {
- const body = {
- dsn: options.analyticsId,
- id: metric.id,
- page: options.path,
- href: location.href,
- event_name: metric.name,
- value: metric.value.toString(),
- speed: getConnectionSpeed(),
- };
- const blob = new Blob([new URLSearchParams(body).toString()], {
- type: 'application/x-www-form-urlencoded',
- });
- if (navigator.sendBeacon) {
- navigator.sendBeacon(SPEED_INSIGHTS_INTAKE, blob);
- } else
- fetch(SPEED_INSIGHTS_INTAKE, {
- body: blob,
- method: 'POST',
- credentials: 'omit',
- keepalive: true,
- });
-};
-
-function collectWebVitals() {
- const analyticsId = (import.meta as any).env.PUBLIC_VERCEL_ANALYTICS_ID;
-
- if (!analyticsId) {
- console.error('[Speed Insights] VERCEL_ANALYTICS_ID not found');
- return;
- }
-
- const options: Options = { path: window.location.pathname, analyticsId };
-
- try {
- onFID((metric) => sendToSpeedInsights(metric, options));
- onTTFB((metric) => sendToSpeedInsights(metric, options));
- onLCP((metric) => sendToSpeedInsights(metric, options));
- onCLS((metric) => sendToSpeedInsights(metric, options));
- onFCP((metric) => sendToSpeedInsights(metric, options));
- } catch (err) {
- console.error('[Speed Insights]', err);
- }
-}
-
-const mode = (import.meta as any).env.MODE as 'development' | 'production';
-
-if (mode === 'production') {
- collectWebVitals();
-}
diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts
index 458143215..ebd6fb20e 100644
--- a/packages/integrations/vercel/src/static/adapter.ts
+++ b/packages/integrations/vercel/src/static/adapter.ts
@@ -9,10 +9,6 @@ import {
} from '../image/shared.js';
import { getRedirects } from '../lib/redirects.js';
import {
- type VercelSpeedInsightsConfig,
- getSpeedInsightsViteConfig,
-} from '../lib/speed-insights.js';
-import {
type VercelWebAnalyticsConfig,
getInjectableWebAnalyticsContent,
} from '../lib/web-analytics.js';
@@ -38,14 +34,6 @@ function getAdapter(): AstroAdapter {
export interface VercelStaticConfig {
webAnalytics?: VercelWebAnalyticsConfig;
- /**
- * @deprecated This option lets you configure the legacy speed insights API which is now deprecated by Vercel.
- *
- * See [Vercel Speed Insights Quickstart](https://vercel.com/docs/speed-insights/quickstart) for instructions on how to use the library instead.
- *
- * https://vercel.com/docs/speed-insights/quickstart
- */
- speedInsights?: VercelSpeedInsightsConfig;
imageService?: boolean;
imagesConfig?: VercelImageConfig;
devImageService?: DevImageService;
@@ -53,7 +41,6 @@ export interface VercelStaticConfig {
export default function vercelStatic({
webAnalytics,
- speedInsights,
imageService,
imagesConfig,
devImageService = 'sharp',
@@ -72,9 +59,6 @@ export default function vercelStatic({
})
);
}
- if (command === 'build' && speedInsights?.enabled) {
- injectScript('page', 'import "@astrojs/vercel/speed-insights"');
- }
const outDir = new URL('./.vercel/output/static/', config.root);
updateConfig({
outDir,
@@ -82,9 +66,6 @@ export default function vercelStatic({
format: 'directory',
redirects: false,
},
- vite: {
- ...getSpeedInsightsViteConfig(speedInsights?.enabled),
- },
...getAstroImageConfig(
imageService,
imagesConfig,
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/astro.config.mjs b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/astro.config.mjs
deleted file mode 100644
index 794734f78..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/astro.config.mjs
+++ /dev/null
@@ -1,10 +0,0 @@
-import vercel from '@astrojs/vercel/serverless';
-import { defineConfig } from 'astro/config';
-
-export default defineConfig({
- adapter: vercel({
- speedInsights: {
- enabled: true
- }
- })
-});
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/package.json b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/package.json
deleted file mode 100644
index 4e674fa6d..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "@test/astro-vercel-with-speed-insights-enabled-output-as-server",
- "version": "0.0.0",
- "private": true,
- "dependencies": {
- "@astrojs/vercel": "workspace:*",
- "astro": "^5.0.0-alpha.8"
- }
-}
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/one.astro b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/one.astro
deleted file mode 100644
index 0c7fb90a7..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/one.astro
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
- <head>
- <title>One</title>
- </head>
- <body>
- <h1>One</h1>
- </body>
-</html>
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/two.astro b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/two.astro
deleted file mode 100644
index e7ba9910e..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/src/pages/two.astro
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
- <head>
- <title>Two</title>
- </head>
- <body>
- <h1>Two</h1>
- </body>
-</html>
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/astro.config.mjs b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/astro.config.mjs
deleted file mode 100644
index 589aa3662..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/astro.config.mjs
+++ /dev/null
@@ -1,10 +0,0 @@
-import vercel from '@astrojs/vercel/static';
-import { defineConfig } from 'astro/config';
-
-export default defineConfig({
- adapter: vercel({
- speedInsights: {
- enabled: true
- }
- })
-});
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/package.json b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/package.json
deleted file mode 100644
index fd4b24faa..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "@test/astro-vercel-with-speed-insights-enabled-output-as-static",
- "version": "0.0.0",
- "private": true,
- "dependencies": {
- "@astrojs/vercel": "workspace:*",
- "astro": "^5.0.0-alpha.8"
- }
-}
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/one.astro b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/one.astro
deleted file mode 100644
index 0c7fb90a7..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/one.astro
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
- <head>
- <title>One</title>
- </head>
- <body>
- <h1>One</h1>
- </body>
-</html>
diff --git a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/two.astro b/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/two.astro
deleted file mode 100644
index e7ba9910e..000000000
--- a/packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static/src/pages/two.astro
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
- <head>
- <title>Two</title>
- </head>
- <body>
- <h1>Two</h1>
- </body>
-</html>
diff --git a/packages/integrations/vercel/test/speed-insights.test.js b/packages/integrations/vercel/test/speed-insights.test.js
deleted file mode 100644
index 28ca84cd2..000000000
--- a/packages/integrations/vercel/test/speed-insights.test.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import assert from 'node:assert/strict';
-import { before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
-
-describe('Vercel Speed Insights', () => {
- describe('output: server', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
-
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/with-speed-insights-enabled/output-as-server/',
- output: 'server',
- });
- await fixture.build();
- });
-
- it('ensures that Vercel Speed Insights is present in the bundle', async () => {
- const [page] = await fixture.readdir('../.vercel/output/static/_astro');
-
- const bundle = await fixture.readFile(`../.vercel/output/static/_astro/${page}`);
-
- assert.match(bundle, /VERCEL_ANALYTICS_ID/);
- });
- });
-
- describe('output: static', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
-
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/with-speed-insights-enabled/output-as-static/',
- output: 'static',
- });
- await fixture.build();
- });
-
- it('ensures that Vercel Speed Insights is present in the bundle', async () => {
- const [page] = await fixture.readdir('../.vercel/output/static/_astro');
-
- const bundle = await fixture.readFile(`../.vercel/output/static/_astro/${page}`);
-
- assert.match(bundle, /VERCEL_ANALYTICS_ID/);
- });
- });
-});