summaryrefslogtreecommitdiff
path: root/packages/integrations/vercel/src
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2024-09-19 21:13:44 +0800
committerGravatar GitHub <noreply@github.com> 2024-09-19 21:13:44 +0800
commit997fd33c291cec374f2bc969c0919b422e5dcbd3 (patch)
treeb8f03aa661515e5eb8f9ab2132381ba56649ae8a /packages/integrations/vercel/src
parent7a4d252a17584afa08db199b692fd29cf38d8b55 (diff)
downloadastro-997fd33c291cec374f2bc969c0919b422e5dcbd3.tar.gz
astro-997fd33c291cec374f2bc969c0919b422e5dcbd3.tar.zst
astro-997fd33c291cec374f2bc969c0919b422e5dcbd3.zip
Remove vercel speedInsights option (#384)
Diffstat (limited to 'packages/integrations/vercel/src')
-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
4 files changed, 0 insertions, 135 deletions
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,