@vercel/speed-insights 0.0.1-beta.3 → 0.0.1-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/next/index.cjs +37 -63
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -2
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +37 -63
- package/dist/next/index.js.map +1 -1
- package/dist/remix/index.cjs +166 -0
- package/dist/remix/index.cjs.map +1 -0
- package/dist/remix/index.d.cts +35 -0
- package/dist/remix/index.d.ts +35 -0
- package/dist/remix/index.js +131 -0
- package/dist/remix/index.js.map +1 -0
- package/jest.setup.ts +0 -3
- package/package.json +10 -1
- package/tsup.config.js +8 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<div align="center"><strong>Vercel Speed Insights</strong></div>
|
|
4
4
|
<div align="center">Performance insights for your website</div>
|
package/dist/next/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var import_react = require("react");
|
|
|
41
41
|
|
|
42
42
|
// package.json
|
|
43
43
|
var name = "@vercel/speed-insights";
|
|
44
|
-
var version = "0.0.1-beta.
|
|
44
|
+
var version = "0.0.1-beta.6";
|
|
45
45
|
|
|
46
46
|
// src/queue.ts
|
|
47
47
|
var initQueue = () => {
|
|
@@ -69,11 +69,24 @@ function detectEnvironment() {
|
|
|
69
69
|
function isDevelopment() {
|
|
70
70
|
return detectEnvironment() === "development";
|
|
71
71
|
}
|
|
72
|
+
function computeRoute(pathname, pathParams) {
|
|
73
|
+
if (!pathname || !pathParams) {
|
|
74
|
+
return pathname;
|
|
75
|
+
}
|
|
76
|
+
let result = pathname;
|
|
77
|
+
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
78
|
+
const isValueArray = Array.isArray(valueOrArray);
|
|
79
|
+
const value = isValueArray ? valueOrArray.join("/") : valueOrArray;
|
|
80
|
+
const expr = isValueArray ? `...${key}` : key;
|
|
81
|
+
const matcher = new RegExp(`/${value}(?=[/?#]|$)`, "g");
|
|
82
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
72
86
|
|
|
73
87
|
// src/generic.ts
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var SCRIPT_DEBUG_NAME = "script.debug.js";
|
|
88
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
89
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
77
90
|
function inject(props) {
|
|
78
91
|
var _a;
|
|
79
92
|
if (!isBrowser())
|
|
@@ -82,28 +95,28 @@ function inject(props) {
|
|
|
82
95
|
if (props.beforeSend) {
|
|
83
96
|
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
84
97
|
}
|
|
85
|
-
const src = props.scriptSrc ||
|
|
98
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
86
99
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
87
100
|
return null;
|
|
88
101
|
const script = document.createElement("script");
|
|
89
102
|
script.src = src;
|
|
90
103
|
script.defer = true;
|
|
91
|
-
script.
|
|
92
|
-
script.
|
|
104
|
+
script.dataset.sdkn = name;
|
|
105
|
+
script.dataset.sdkv = version;
|
|
93
106
|
if (props.sampleRate) {
|
|
94
|
-
script.
|
|
107
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
95
108
|
}
|
|
96
|
-
if (props.
|
|
97
|
-
script.
|
|
109
|
+
if (props.route) {
|
|
110
|
+
script.dataset.route = props.route;
|
|
98
111
|
}
|
|
99
112
|
if (props.endpoint) {
|
|
100
|
-
script.
|
|
113
|
+
script.dataset.endpoint = props.endpoint;
|
|
101
114
|
}
|
|
102
115
|
if (props.token) {
|
|
103
|
-
script.
|
|
116
|
+
script.dataset.token = props.token;
|
|
104
117
|
}
|
|
105
118
|
if (isDevelopment() && props.debug === false) {
|
|
106
|
-
script.
|
|
119
|
+
script.dataset.debug = "false";
|
|
107
120
|
}
|
|
108
121
|
script.onerror = () => {
|
|
109
122
|
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.";
|
|
@@ -113,78 +126,39 @@ function inject(props) {
|
|
|
113
126
|
};
|
|
114
127
|
document.head.appendChild(script);
|
|
115
128
|
return {
|
|
116
|
-
|
|
117
|
-
script.dataset.
|
|
129
|
+
setRoute: (route) => {
|
|
130
|
+
script.dataset.route = route;
|
|
118
131
|
}
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
// src/react/index.tsx
|
|
123
136
|
function SpeedInsights(props) {
|
|
124
|
-
const
|
|
137
|
+
const setScriptRoute = (0, import_react.useRef)(null);
|
|
125
138
|
(0, import_react.useEffect)(() => {
|
|
126
139
|
const script = inject(props);
|
|
127
|
-
|
|
140
|
+
setScriptRoute.current = (script == null ? void 0 : script.setRoute) || null;
|
|
128
141
|
}, []);
|
|
129
142
|
(0, import_react.useEffect)(() => {
|
|
130
|
-
if (props.
|
|
131
|
-
|
|
143
|
+
if (props.route && setScriptRoute.current) {
|
|
144
|
+
setScriptRoute.current(props.route);
|
|
132
145
|
}
|
|
133
|
-
}, [props.
|
|
146
|
+
}, [props.route]);
|
|
134
147
|
return null;
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
// src/nextjs/utils.ts
|
|
138
151
|
var import_navigation = require("next/navigation");
|
|
139
|
-
var
|
|
152
|
+
var useRoute = () => {
|
|
140
153
|
const params = (0, import_navigation.useParams)();
|
|
141
154
|
const path = (0, import_navigation.usePathname)();
|
|
142
|
-
return
|
|
155
|
+
return computeRoute(path, params);
|
|
143
156
|
};
|
|
144
|
-
function computePathname(pathname, pathParams) {
|
|
145
|
-
if (pathname === null) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
if (pathname === "" || !pathParams) {
|
|
149
|
-
return pathname;
|
|
150
|
-
}
|
|
151
|
-
let result = pathname;
|
|
152
|
-
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
153
|
-
let value;
|
|
154
|
-
let expr;
|
|
155
|
-
if (Array.isArray(valueOrArray)) {
|
|
156
|
-
expr = `...${key}`;
|
|
157
|
-
value = valueOrArray.join("/");
|
|
158
|
-
} else {
|
|
159
|
-
expr = key;
|
|
160
|
-
value = valueOrArray;
|
|
161
|
-
}
|
|
162
|
-
if (!value) {
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
let start = 0;
|
|
166
|
-
while (start !== -1) {
|
|
167
|
-
start = result.indexOf(`/${value}`, start);
|
|
168
|
-
if (start !== -1) {
|
|
169
|
-
const end = start + value.length + 2;
|
|
170
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
171
|
-
result = `${result.substring(
|
|
172
|
-
0,
|
|
173
|
-
start + 1
|
|
174
|
-
)}[${expr}]${result.substring(end)}`;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
start += value.length + 1;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
157
|
|
|
184
158
|
// src/nextjs/index.tsx
|
|
185
159
|
function SpeedInsights2(props) {
|
|
186
|
-
const
|
|
187
|
-
return /* @__PURE__ */ import_react2.default.createElement(SpeedInsights, { ...
|
|
160
|
+
const route = useRoute();
|
|
161
|
+
return /* @__PURE__ */ import_react2.default.createElement(SpeedInsights, { ...route && { route }, ...props });
|
|
188
162
|
}
|
|
189
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
164
|
0 && (module.exports = {
|
package/dist/next/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useDynamicPath } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'dynamicPath'>,\n): JSX.Element {\n const dynamicPath = useDynamicPath();\n\n return (\n <SpeedInsightsScript {...(dynamicPath && { dynamicPath })} {...props} />\n );\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const scriptDynamicPath = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n scriptDynamicPath.current = script?.setDynamicPath || null;\n }, []);\n\n useEffect(() => {\n if (props.dynamicPath && scriptDynamicPath.current) {\n scriptDynamicPath.current(props.dynamicPath);\n }\n }, [props.dynamicPath]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.3\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst SCRIPT_URL = `/_vercel/speed-insights`;\nconst SCRIPT_PROD_NAME = 'script.js';\nconst SCRIPT_DEBUG_NAME = 'script.debug.js';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setDynamicPath: (path: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc ||\n `${SCRIPT_URL}/${isDevelopment() ? SCRIPT_DEBUG_NAME : SCRIPT_PROD_NAME}`;\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (props.sampleRate) {\n script.setAttribute('data-sample-rate', props.sampleRate.toString());\n }\n if (props.dynamicPath) {\n script.setAttribute('data-dynamic-path', props.dynamicPath);\n }\n if (props.endpoint) {\n script.setAttribute('data-endpoint', props.endpoint);\n }\n if (props.token) {\n script.setAttribute('data-token', props.token);\n }\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setDynamicPath: (path: string): void => {\n script.dataset.dynamicPath = path;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","'use client';\nimport { useParams, usePathname } from 'next/navigation';\n\nexport const useDynamicPath = (): string | null => {\n const params = useParams();\n const path = usePathname();\n\n return computePathname(path, params);\n};\n\n// Refined version from dvoytenko\n// https://github.com/vercel/front/pull/25076\nfunction computePathname(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (pathname === null) {\n return null;\n }\n if (pathname === '' || !pathParams) {\n return pathname;\n }\n let result = pathname;\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n let value: string;\n let expr: string;\n if (Array.isArray(valueOrArray)) {\n // An array-based segment, e.g. \"/[...slugs]\".\n expr = `...${key}`;\n value = valueOrArray.join('/');\n } else {\n // A single dynamic segment, e.g. \"/posts/[pid]\".\n expr = key;\n value = valueOrArray;\n }\n if (!value) {\n continue;\n }\n let start = 0;\n while (start !== -1) {\n start = result.indexOf(`/${value}`, start);\n if (start !== -1) {\n const end = start + value.length + 2;\n if (\n end >= result.length ||\n result[end] === '/' ||\n result[end] === '?' ||\n result[end] === '#'\n ) {\n result = `${result.substring(\n 0,\n start + 1,\n )}[${expr}]${result.substring(end)}`;\n break;\n }\n start += value.length + 1;\n }\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA;AAAA;AAAA,IAAAC,gBAAkB;;;ACClB,mBAAkC;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;;;ACjBA,IAAM,aAAa;AACnB,IAAM,mBAAmB;AACzB,IAAM,oBAAo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,SAASC,eACd,OACa;AACb,QAAM,cAAc,eAAe;AAEnC,SACE,8BAAAC,QAAA,cAAC,iBAAqB,GAAI,eAAe,EAAE,YAAY,GAAK,GAAG,OAAO;AAE1E;","names":["SpeedInsights","import_react","SpeedInsights","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useRoute } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'route'>,\n): JSX.Element {\n const route = useRoute();\n\n return <SpeedInsightsScript {...(route && { route })} {...props} />;\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n setScriptRoute.current = script?.setRoute || null;\n }, []);\n\n useEffect(() => {\n if (props.route && setScriptRoute.current) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.6\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.js\",\n \"import\": \"./dist/remix/index.js\",\n \"require\": \"./dist/remix/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@remix-run/react\": \"^2.0.1\",\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${value}(?=[/?#]|$)`, 'g');\n result = result.replace(matcher, `/[${expr}]`);\n }\n\n return result;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;\nconst SCRIPT_URL = `/_vercel/speed-insights/script.js`;\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setRoute: (route: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn = packageName;\n script.dataset.sdkv = version;\n\n if (props.sampleRate) {\n script.dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n script.dataset.route = props.route;\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.token) {\n script.dataset.token = props.token;\n }\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string): void => {\n script.dataset.route = route;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","'use client';\nimport { useParams, usePathname } from 'next/navigation';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const path = usePathname();\n\n return computeRoute(path, params);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA;AAAA;AAAA,IAAAC,gBAAkB;;;ACClB,mBAAkC;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AAEb,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,Q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S,KAAK,YAAY,MAAM;AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAAwB;AACjC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;;;AJhEO,SAAS,cAAc,OAA+C;AAC3E,QAAM,qBAAiB,qBAAwC,IAAI;AACnE,8BAAU,MAAM;AACd,UAAM,SAAS,OAAO,KAAK;AAE3B,mBAAe,WAAU,iCAAQ,aAAY;AAAA,EAC/C,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,QAAI,MAAM,SAAS,eAAe,SAAS;AACzC,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKnBA,wBAAuC;AAGhC,IAAM,WAAW,MAAqB;AAC3C,QAAM,aAAS,6BAAU;AACzB,QAAM,WAAO,+BAAY;AAEzB,SAAO,aAAa,MAAM,MAAM;AAClC;;;ANJO,SAASC,eACd,OACa;AACb,QAAM,QAAQ,SAAS;AAEvB,SAAO,8BAAAC,QAAA,cAAC,iBAAqB,GAAI,SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","names":["SpeedInsights","import_react","SpeedInsights","React"]}
|
package/dist/next/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
interface SpeedInsightsProps {
|
|
2
2
|
token?: string;
|
|
3
3
|
sampleRate?: number;
|
|
4
|
+
route?: string;
|
|
4
5
|
beforeSend?: BeforeSendMiddleware;
|
|
5
6
|
debug?: boolean;
|
|
6
|
-
dynamicPath?: string;
|
|
7
7
|
scriptSrc?: string;
|
|
8
8
|
endpoint?: string;
|
|
9
9
|
}
|
|
@@ -30,6 +30,6 @@ declare global {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
declare function SpeedInsights(props: Omit<SpeedInsightsProps, '
|
|
33
|
+
declare function SpeedInsights(props: Omit<SpeedInsightsProps, 'route'>): JSX.Element;
|
|
34
34
|
|
|
35
35
|
export { SpeedInsights };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
interface SpeedInsightsProps {
|
|
2
2
|
token?: string;
|
|
3
3
|
sampleRate?: number;
|
|
4
|
+
route?: string;
|
|
4
5
|
beforeSend?: BeforeSendMiddleware;
|
|
5
6
|
debug?: boolean;
|
|
6
|
-
dynamicPath?: string;
|
|
7
7
|
scriptSrc?: string;
|
|
8
8
|
endpoint?: string;
|
|
9
9
|
}
|
|
@@ -30,6 +30,6 @@ declare global {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
declare function SpeedInsights(props: Omit<SpeedInsightsProps, '
|
|
33
|
+
declare function SpeedInsights(props: Omit<SpeedInsightsProps, 'route'>): JSX.Element;
|
|
34
34
|
|
|
35
35
|
export { SpeedInsights };
|
package/dist/next/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { useEffect, useRef } from "react";
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "@vercel/speed-insights";
|
|
11
|
-
var version = "0.0.1-beta.
|
|
11
|
+
var version = "0.0.1-beta.6";
|
|
12
12
|
|
|
13
13
|
// src/queue.ts
|
|
14
14
|
var initQueue = () => {
|
|
@@ -36,11 +36,24 @@ function detectEnvironment() {
|
|
|
36
36
|
function isDevelopment() {
|
|
37
37
|
return detectEnvironment() === "development";
|
|
38
38
|
}
|
|
39
|
+
function computeRoute(pathname, pathParams) {
|
|
40
|
+
if (!pathname || !pathParams) {
|
|
41
|
+
return pathname;
|
|
42
|
+
}
|
|
43
|
+
let result = pathname;
|
|
44
|
+
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
45
|
+
const isValueArray = Array.isArray(valueOrArray);
|
|
46
|
+
const value = isValueArray ? valueOrArray.join("/") : valueOrArray;
|
|
47
|
+
const expr = isValueArray ? `...${key}` : key;
|
|
48
|
+
const matcher = new RegExp(`/${value}(?=[/?#]|$)`, "g");
|
|
49
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
39
53
|
|
|
40
54
|
// src/generic.ts
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var SCRIPT_DEBUG_NAME = "script.debug.js";
|
|
55
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
56
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
44
57
|
function inject(props) {
|
|
45
58
|
var _a;
|
|
46
59
|
if (!isBrowser())
|
|
@@ -49,28 +62,28 @@ function inject(props) {
|
|
|
49
62
|
if (props.beforeSend) {
|
|
50
63
|
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
51
64
|
}
|
|
52
|
-
const src = props.scriptSrc ||
|
|
65
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
53
66
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
54
67
|
return null;
|
|
55
68
|
const script = document.createElement("script");
|
|
56
69
|
script.src = src;
|
|
57
70
|
script.defer = true;
|
|
58
|
-
script.
|
|
59
|
-
script.
|
|
71
|
+
script.dataset.sdkn = name;
|
|
72
|
+
script.dataset.sdkv = version;
|
|
60
73
|
if (props.sampleRate) {
|
|
61
|
-
script.
|
|
74
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
62
75
|
}
|
|
63
|
-
if (props.
|
|
64
|
-
script.
|
|
76
|
+
if (props.route) {
|
|
77
|
+
script.dataset.route = props.route;
|
|
65
78
|
}
|
|
66
79
|
if (props.endpoint) {
|
|
67
|
-
script.
|
|
80
|
+
script.dataset.endpoint = props.endpoint;
|
|
68
81
|
}
|
|
69
82
|
if (props.token) {
|
|
70
|
-
script.
|
|
83
|
+
script.dataset.token = props.token;
|
|
71
84
|
}
|
|
72
85
|
if (isDevelopment() && props.debug === false) {
|
|
73
|
-
script.
|
|
86
|
+
script.dataset.debug = "false";
|
|
74
87
|
}
|
|
75
88
|
script.onerror = () => {
|
|
76
89
|
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.";
|
|
@@ -80,78 +93,39 @@ function inject(props) {
|
|
|
80
93
|
};
|
|
81
94
|
document.head.appendChild(script);
|
|
82
95
|
return {
|
|
83
|
-
|
|
84
|
-
script.dataset.
|
|
96
|
+
setRoute: (route) => {
|
|
97
|
+
script.dataset.route = route;
|
|
85
98
|
}
|
|
86
99
|
};
|
|
87
100
|
}
|
|
88
101
|
|
|
89
102
|
// src/react/index.tsx
|
|
90
103
|
function SpeedInsights(props) {
|
|
91
|
-
const
|
|
104
|
+
const setScriptRoute = useRef(null);
|
|
92
105
|
useEffect(() => {
|
|
93
106
|
const script = inject(props);
|
|
94
|
-
|
|
107
|
+
setScriptRoute.current = (script == null ? void 0 : script.setRoute) || null;
|
|
95
108
|
}, []);
|
|
96
109
|
useEffect(() => {
|
|
97
|
-
if (props.
|
|
98
|
-
|
|
110
|
+
if (props.route && setScriptRoute.current) {
|
|
111
|
+
setScriptRoute.current(props.route);
|
|
99
112
|
}
|
|
100
|
-
}, [props.
|
|
113
|
+
}, [props.route]);
|
|
101
114
|
return null;
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
// src/nextjs/utils.ts
|
|
105
118
|
import { useParams, usePathname } from "next/navigation";
|
|
106
|
-
var
|
|
119
|
+
var useRoute = () => {
|
|
107
120
|
const params = useParams();
|
|
108
121
|
const path = usePathname();
|
|
109
|
-
return
|
|
122
|
+
return computeRoute(path, params);
|
|
110
123
|
};
|
|
111
|
-
function computePathname(pathname, pathParams) {
|
|
112
|
-
if (pathname === null) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
if (pathname === "" || !pathParams) {
|
|
116
|
-
return pathname;
|
|
117
|
-
}
|
|
118
|
-
let result = pathname;
|
|
119
|
-
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
120
|
-
let value;
|
|
121
|
-
let expr;
|
|
122
|
-
if (Array.isArray(valueOrArray)) {
|
|
123
|
-
expr = `...${key}`;
|
|
124
|
-
value = valueOrArray.join("/");
|
|
125
|
-
} else {
|
|
126
|
-
expr = key;
|
|
127
|
-
value = valueOrArray;
|
|
128
|
-
}
|
|
129
|
-
if (!value) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
let start = 0;
|
|
133
|
-
while (start !== -1) {
|
|
134
|
-
start = result.indexOf(`/${value}`, start);
|
|
135
|
-
if (start !== -1) {
|
|
136
|
-
const end = start + value.length + 2;
|
|
137
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
138
|
-
result = `${result.substring(
|
|
139
|
-
0,
|
|
140
|
-
start + 1
|
|
141
|
-
)}[${expr}]${result.substring(end)}`;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
start += value.length + 1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
124
|
|
|
151
125
|
// src/nextjs/index.tsx
|
|
152
126
|
function SpeedInsights2(props) {
|
|
153
|
-
const
|
|
154
|
-
return /* @__PURE__ */ React.createElement(SpeedInsights, { ...
|
|
127
|
+
const route = useRoute();
|
|
128
|
+
return /* @__PURE__ */ React.createElement(SpeedInsights, { ...route && { route }, ...props });
|
|
155
129
|
}
|
|
156
130
|
export {
|
|
157
131
|
SpeedInsights2 as SpeedInsights
|
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useDynamicPath } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'dynamicPath'>,\n): JSX.Element {\n const dynamicPath = useDynamicPath();\n\n return (\n <SpeedInsightsScript {...(dynamicPath && { dynamicPath })} {...props} />\n );\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const scriptDynamicPath = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n scriptDynamicPath.current = script?.setDynamicPath || null;\n }, []);\n\n useEffect(() => {\n if (props.dynamicPath && scriptDynamicPath.current) {\n scriptDynamicPath.current(props.dynamicPath);\n }\n }, [props.dynamicPath]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.3\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst SCRIPT_URL = `/_vercel/speed-insights`;\nconst SCRIPT_PROD_NAME = 'script.js';\nconst SCRIPT_DEBUG_NAME = 'script.debug.js';\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setDynamicPath: (path: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc ||\n `${SCRIPT_URL}/${isDevelopment() ? SCRIPT_DEBUG_NAME : SCRIPT_PROD_NAME}`;\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (props.sampleRate) {\n script.setAttribute('data-sample-rate', props.sampleRate.toString());\n }\n if (props.dynamicPath) {\n script.setAttribute('data-dynamic-path', props.dynamicPath);\n }\n if (props.endpoint) {\n script.setAttribute('data-endpoint', props.endpoint);\n }\n if (props.token) {\n script.setAttribute('data-token', props.token);\n }\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setDynamicPath: (path: string): void => {\n script.dataset.dynamicPath = path;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","'use client';\nimport { useParams, usePathname } from 'next/navigation';\n\nexport const useDynamicPath = (): string | null => {\n const params = useParams();\n const path = usePathname();\n\n return computePathname(path, params);\n};\n\n// Refined version from dvoytenko\n// https://github.com/vercel/front/pull/25076\nfunction computePathname(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (pathname === null) {\n return null;\n }\n if (pathname === '' || !pathParams) {\n return pathname;\n }\n let result = pathname;\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n let value: string;\n let expr: string;\n if (Array.isArray(valueOrArray)) {\n // An array-based segment, e.g. \"/[...slugs]\".\n expr = `...${key}`;\n value = valueOrArray.join('/');\n } else {\n // A single dynamic segment, e.g. \"/posts/[pid]\".\n expr = key;\n value = valueOrArray;\n }\n if (!value) {\n continue;\n }\n let start = 0;\n while (start !== -1) {\n start = result.indexOf(`/${value}`, start);\n if (start !== -1) {\n const end = start + value.length + 2;\n if (\n end >= result.length ||\n result[end] === '/' ||\n result[end] === '?' ||\n result[end] === '#'\n ) {\n result = `${result.substring(\n 0,\n start + 1,\n )}[${expr}]${result.substring(end)}`;\n break;\n }\n start += value.length + 1;\n }\n }\n }\n return result;\n}\n"],"mappings":";;;AAAA,OAAO,WAAW;;;ACClB,SAAS,WAAW,cAAc;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;;;ACjBA,IAAM,aAAa;AACnB,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;AAQ1B,SAAS,OAAO,OAEP;AAjBT;AAkBE,MAAI,CAAC,UAAU;AAAG,WAAO;AAEzB,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AACA,QAAM,MACJ,MAAM,aACN,GAAG,UAAU,IAAI,cA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nBA,SAAS,WAAW,mBAAmB;AAEhC,IAAM,iBAAiB,MAAqB;AACjD,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,YAAY;AAEzB,SAAO,gBAAgB,MAAM,MAAM;AACrC;AAIA,SAAS,gBACP,UACA,YACe;AACf,MAAI,aAAa,MAAM;AACrB,WAAO;AAAA,EACT;AACA,MAAI,aAAa,MAAM,CAAC,YAAY;AAClC,WAAO;AAAA,EACT;AACA,MAAI,SAAS;AACb,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,UAAU,GAAG;AAC5D,QAAI;AACJ,QAAI;AACJ,QAAI,MAAM,QAAQ,YAAY,GAAG;AAE/B,aAAO,MAAM,GAAG;AAChB,cAAQ,aAAa,KAAK,GAAG;AAAA,IAC/B,OAAO;AAEL,aAAO;AACP,cAAQ;AAAA,IACV;AACA,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AACA,QAAI,QAAQ;AACZ,WAAO,UAAU,IAAI;AACnB,cAAQ,OAAO,QAAQ,IAAI,KAAK,IAAI,KAAK;AACzC,UAAI,UAAU,IAAI;AAChB,cAAM,MAAM,QAAQ,MAAM,SAAS;AACnC,YACE,OAAO,OAAO,UACd,OAAO,GAAG,MAAM,OAChB,OAAO,GAAG,MAAM,OAChB,OAAO,GAAG,MAAM,KAChB;AACA,mBAAS,GAAG,OAAO;AAAA,YACjB;AAAA,YACA,QAAQ;AAAA,UACV,CAAC,IAAI,IAAI,IAAI,OAAO,UAAU,GAAG,CAAC;AAClC;AAAA,QACF;AACA,iBAAS,MAAM,SAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;;;ANvDO,SAASA,eACd,OACa;AACb,QAAM,cAAc,eAAe;AAEnC,SACE,oCAAC,iBAAqB,GAAI,eAAe,EAAE,YAAY,GAAK,GAAG,OAAO;AAE1E;","names":["SpeedInsights"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useRoute } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'route'>,\n): JSX.Element {\n const route = useRoute();\n\n return <SpeedInsightsScript {...(route && { route })} {...props} />;\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n setScriptRoute.current = script?.setRoute || null;\n }, []);\n\n useEffect(() => {\n if (props.route && setScriptRoute.current) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.6\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.js\",\n \"import\": \"./dist/remix/index.js\",\n \"require\": \"./dist/remix/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@remix-run/react\": \"^2.0.1\",\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${value}(?=[/?#]|$)`, 'g');\n result = result.replace(matcher, `/[${expr}]`);\n }\n\n return result;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;\nconst SCRIPT_URL = `/_vercel/speed-insights/script.js`;\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setRoute: (route: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn = packageName;\n script.dataset.sdkv = version;\n\n if (props.sampleRate) {\n script.dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n script.dataset.route = props.route;\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.token) {\n script.dataset.token = props.token;\n }\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string): void => {\n script.dataset.route = route;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","'use client';\nimport { useParams, usePathname } from 'next/navigation';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const path = usePathname();\n\n return computeRoute(path, params);\n};\n"],"mappings":";;;AAAA,OAAO,WAAW;;;ACClB,SAAS,WAAW,cAAc;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AAEb,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,UAAU,GAAG;AAC5D,UAAM,eAAe,MAAM,QAAQ,YAAY;AAC/C,UAAM,QAAQ,eAAe,aAAa,KAAK,GAAG,IAAI;AACtD,UAAM,OAAO,eAAe,MAAM,GAAG,KAAK;AAE1C,UAAM,UAAU,IAAI,OAAO,IAAI,KAAK,eAAe,GAAG;AACtD,aAAS,OAAO,QAAQ,SAAS,KAAK,IAAI,GAAG;AAAA,EAC/C;AAEA,SAAO;AACT;;;ACvCA,IAAM,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,YAAU,MAAM;AACd,QAAI,MAAM,SAAS,eAAe,SAAS;AACzC,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKnBA,SAAS,WAAW,mBAAmB;AAGhC,IAAM,WAAW,MAAqB;AAC3C,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,YAAY;AAEzB,SAAO,aAAa,MAAM,MAAM;AAClC;;;ANJO,SAASA,eACd,OACa;AACb,QAAM,QAAQ,SAAS;AAEvB,SAAO,oCAAC,iBAAqB,GAAI,SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","names":["SpeedInsights"]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/remix/index.tsx
|
|
31
|
+
var remix_exports = {};
|
|
32
|
+
__export(remix_exports, {
|
|
33
|
+
SpeedInsights: () => SpeedInsights2
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(remix_exports);
|
|
36
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
37
|
+
|
|
38
|
+
// src/react/index.tsx
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
|
|
41
|
+
// package.json
|
|
42
|
+
var name = "@vercel/speed-insights";
|
|
43
|
+
var version = "0.0.1-beta.6";
|
|
44
|
+
|
|
45
|
+
// src/queue.ts
|
|
46
|
+
var initQueue = () => {
|
|
47
|
+
if (window.si)
|
|
48
|
+
return;
|
|
49
|
+
window.si = function a(...params) {
|
|
50
|
+
(window.siq = window.siq || []).push(params);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/utils.ts
|
|
55
|
+
function isBrowser() {
|
|
56
|
+
return typeof window !== "undefined";
|
|
57
|
+
}
|
|
58
|
+
function detectEnvironment() {
|
|
59
|
+
try {
|
|
60
|
+
const env = process.env.NODE_ENV;
|
|
61
|
+
if (env === "development" || env === "test") {
|
|
62
|
+
return "development";
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
}
|
|
66
|
+
return "production";
|
|
67
|
+
}
|
|
68
|
+
function isDevelopment() {
|
|
69
|
+
return detectEnvironment() === "development";
|
|
70
|
+
}
|
|
71
|
+
function computeRoute(pathname, pathParams) {
|
|
72
|
+
if (!pathname || !pathParams) {
|
|
73
|
+
return pathname;
|
|
74
|
+
}
|
|
75
|
+
let result = pathname;
|
|
76
|
+
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
77
|
+
const isValueArray = Array.isArray(valueOrArray);
|
|
78
|
+
const value = isValueArray ? valueOrArray.join("/") : valueOrArray;
|
|
79
|
+
const expr = isValueArray ? `...${key}` : key;
|
|
80
|
+
const matcher = new RegExp(`/${value}(?=[/?#]|$)`, "g");
|
|
81
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/generic.ts
|
|
87
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
88
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
89
|
+
function inject(props) {
|
|
90
|
+
var _a;
|
|
91
|
+
if (!isBrowser())
|
|
92
|
+
return null;
|
|
93
|
+
initQueue();
|
|
94
|
+
if (props.beforeSend) {
|
|
95
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
96
|
+
}
|
|
97
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
98
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
99
|
+
return null;
|
|
100
|
+
const script = document.createElement("script");
|
|
101
|
+
script.src = src;
|
|
102
|
+
script.defer = true;
|
|
103
|
+
script.dataset.sdkn = name;
|
|
104
|
+
script.dataset.sdkv = version;
|
|
105
|
+
if (props.sampleRate) {
|
|
106
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
107
|
+
}
|
|
108
|
+
if (props.route) {
|
|
109
|
+
script.dataset.route = props.route;
|
|
110
|
+
}
|
|
111
|
+
if (props.endpoint) {
|
|
112
|
+
script.dataset.endpoint = props.endpoint;
|
|
113
|
+
}
|
|
114
|
+
if (props.token) {
|
|
115
|
+
script.dataset.token = props.token;
|
|
116
|
+
}
|
|
117
|
+
if (isDevelopment() && props.debug === false) {
|
|
118
|
+
script.dataset.debug = "false";
|
|
119
|
+
}
|
|
120
|
+
script.onerror = () => {
|
|
121
|
+
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.";
|
|
122
|
+
console.log(
|
|
123
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
document.head.appendChild(script);
|
|
127
|
+
return {
|
|
128
|
+
setRoute: (route) => {
|
|
129
|
+
script.dataset.route = route;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/react/index.tsx
|
|
135
|
+
function SpeedInsights(props) {
|
|
136
|
+
const setScriptRoute = (0, import_react.useRef)(null);
|
|
137
|
+
(0, import_react.useEffect)(() => {
|
|
138
|
+
const script = inject(props);
|
|
139
|
+
setScriptRoute.current = (script == null ? void 0 : script.setRoute) || null;
|
|
140
|
+
}, []);
|
|
141
|
+
(0, import_react.useEffect)(() => {
|
|
142
|
+
if (props.route && setScriptRoute.current) {
|
|
143
|
+
setScriptRoute.current(props.route);
|
|
144
|
+
}
|
|
145
|
+
}, [props.route]);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/remix/utils.ts
|
|
150
|
+
var import_react2 = require("@remix-run/react");
|
|
151
|
+
var useRoute = () => {
|
|
152
|
+
const params = (0, import_react2.useParams)();
|
|
153
|
+
const location = (0, import_react2.useLocation)();
|
|
154
|
+
return computeRoute(location.pathname, params);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/remix/index.tsx
|
|
158
|
+
function SpeedInsights2(props) {
|
|
159
|
+
const route = useRoute();
|
|
160
|
+
return /* @__PURE__ */ import_react3.default.createElement(SpeedInsights, { ...route && { route }, ...props });
|
|
161
|
+
}
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
SpeedInsights
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/remix/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/remix/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useRoute } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'route'>,\n): JSX.Element {\n const route = useRoute();\n\n return <SpeedInsightsScript {...(route && { route })} {...props} />;\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n setScriptRoute.current = script?.setRoute || null;\n }, []);\n\n useEffect(() => {\n if (props.route && setScriptRoute.current) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.6\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.js\",\n \"import\": \"./dist/remix/index.js\",\n \"require\": \"./dist/remix/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@remix-run/react\": \"^2.0.1\",\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${value}(?=[/?#]|$)`, 'g');\n result = result.replace(matcher, `/[${expr}]`);\n }\n\n return result;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;\nconst SCRIPT_URL = `/_vercel/speed-insights/script.js`;\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setRoute: (route: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn = packageName;\n script.dataset.sdkv = version;\n\n if (props.sampleRate) {\n script.dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n script.dataset.route = props.route;\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.token) {\n script.dataset.token = props.token;\n }\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string): void => {\n script.dataset.route = route;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","import { useLocation, useParams } from '@remix-run/react';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const location = useLocation();\n\n return computeRoute(location.pathname, params as never);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA;AAAA;AAAA,IAAAC,gBAAkB;;;ACClB,mBAAkC;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AAEb,aAAW,CAAC,KAAK,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AAA,EACF;AAEA,WAAS,KAAK,YAAY,MAAM;AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAAwB;AACjC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;;;AJhEO,SAAS,cAAc,OAA+C;AAC3E,QAAM,qBAAiB,qBAAwC,IAAI;AACnE,8BAAU,MAAM;AACd,UAAM,SAAS,OAAO,KAAK;AAE3B,mBAAe,WAAU,iCAAQ,aAAY;AAAA,EAC/C,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,QAAI,MAAM,SAAS,eAAe,SAAS;AACzC,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKpBA,IAAAC,gBAAuC;AAGhC,IAAM,WAAW,MAAqB;AAC3C,QAAM,aAAS,yBAAU;AACzB,QAAM,eAAW,2BAAY;AAE7B,SAAO,aAAa,SAAS,UAAU,MAAe;AACxD;;;ANHO,SAASC,eACd,OACa;AACb,QAAM,QAAQ,SAAS;AAEvB,SAAO,8BAAAC,QAAA,cAAC,iBAAqB,GAAI,SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","names":["SpeedInsights","import_react","import_react","SpeedInsights","React"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface SpeedInsightsProps {
|
|
2
|
+
token?: string;
|
|
3
|
+
sampleRate?: number;
|
|
4
|
+
route?: string;
|
|
5
|
+
beforeSend?: BeforeSendMiddleware;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
scriptSrc?: string;
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
}
|
|
10
|
+
type EventTypes = 'vital';
|
|
11
|
+
interface Event {
|
|
12
|
+
type: EventTypes;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
type BeforeSendMiddleware = (data: Event) => Event | null | undefined | false;
|
|
16
|
+
interface Functions {
|
|
17
|
+
beforeSend?: BeforeSendMiddleware;
|
|
18
|
+
}
|
|
19
|
+
interface SpeedInsights$1<T extends keyof Functions = keyof Functions> {
|
|
20
|
+
queue: [T, Functions[T]][];
|
|
21
|
+
addAction: (action: T, data: Functions[T]) => void;
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
/** Base interface to track events */
|
|
26
|
+
si?: SpeedInsights$1['addAction'];
|
|
27
|
+
/** Queue for speed insights datapoints, before the library is loaded */
|
|
28
|
+
siq?: SpeedInsights$1['queue'];
|
|
29
|
+
sil?: boolean;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function SpeedInsights(props: Omit<SpeedInsightsProps, 'route'>): JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { SpeedInsights };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface SpeedInsightsProps {
|
|
2
|
+
token?: string;
|
|
3
|
+
sampleRate?: number;
|
|
4
|
+
route?: string;
|
|
5
|
+
beforeSend?: BeforeSendMiddleware;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
scriptSrc?: string;
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
}
|
|
10
|
+
type EventTypes = 'vital';
|
|
11
|
+
interface Event {
|
|
12
|
+
type: EventTypes;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
type BeforeSendMiddleware = (data: Event) => Event | null | undefined | false;
|
|
16
|
+
interface Functions {
|
|
17
|
+
beforeSend?: BeforeSendMiddleware;
|
|
18
|
+
}
|
|
19
|
+
interface SpeedInsights$1<T extends keyof Functions = keyof Functions> {
|
|
20
|
+
queue: [T, Functions[T]][];
|
|
21
|
+
addAction: (action: T, data: Functions[T]) => void;
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
/** Base interface to track events */
|
|
26
|
+
si?: SpeedInsights$1['addAction'];
|
|
27
|
+
/** Queue for speed insights datapoints, before the library is loaded */
|
|
28
|
+
siq?: SpeedInsights$1['queue'];
|
|
29
|
+
sil?: boolean;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function SpeedInsights(props: Omit<SpeedInsightsProps, 'route'>): JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { SpeedInsights };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/remix/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
// src/react/index.tsx
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
|
|
7
|
+
// package.json
|
|
8
|
+
var name = "@vercel/speed-insights";
|
|
9
|
+
var version = "0.0.1-beta.6";
|
|
10
|
+
|
|
11
|
+
// src/queue.ts
|
|
12
|
+
var initQueue = () => {
|
|
13
|
+
if (window.si)
|
|
14
|
+
return;
|
|
15
|
+
window.si = function a(...params) {
|
|
16
|
+
(window.siq = window.siq || []).push(params);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/utils.ts
|
|
21
|
+
function isBrowser() {
|
|
22
|
+
return typeof window !== "undefined";
|
|
23
|
+
}
|
|
24
|
+
function detectEnvironment() {
|
|
25
|
+
try {
|
|
26
|
+
const env = process.env.NODE_ENV;
|
|
27
|
+
if (env === "development" || env === "test") {
|
|
28
|
+
return "development";
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
}
|
|
32
|
+
return "production";
|
|
33
|
+
}
|
|
34
|
+
function isDevelopment() {
|
|
35
|
+
return detectEnvironment() === "development";
|
|
36
|
+
}
|
|
37
|
+
function computeRoute(pathname, pathParams) {
|
|
38
|
+
if (!pathname || !pathParams) {
|
|
39
|
+
return pathname;
|
|
40
|
+
}
|
|
41
|
+
let result = pathname;
|
|
42
|
+
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
43
|
+
const isValueArray = Array.isArray(valueOrArray);
|
|
44
|
+
const value = isValueArray ? valueOrArray.join("/") : valueOrArray;
|
|
45
|
+
const expr = isValueArray ? `...${key}` : key;
|
|
46
|
+
const matcher = new RegExp(`/${value}(?=[/?#]|$)`, "g");
|
|
47
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/generic.ts
|
|
53
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
54
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
55
|
+
function inject(props) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!isBrowser())
|
|
58
|
+
return null;
|
|
59
|
+
initQueue();
|
|
60
|
+
if (props.beforeSend) {
|
|
61
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
62
|
+
}
|
|
63
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
64
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
65
|
+
return null;
|
|
66
|
+
const script = document.createElement("script");
|
|
67
|
+
script.src = src;
|
|
68
|
+
script.defer = true;
|
|
69
|
+
script.dataset.sdkn = name;
|
|
70
|
+
script.dataset.sdkv = version;
|
|
71
|
+
if (props.sampleRate) {
|
|
72
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
73
|
+
}
|
|
74
|
+
if (props.route) {
|
|
75
|
+
script.dataset.route = props.route;
|
|
76
|
+
}
|
|
77
|
+
if (props.endpoint) {
|
|
78
|
+
script.dataset.endpoint = props.endpoint;
|
|
79
|
+
}
|
|
80
|
+
if (props.token) {
|
|
81
|
+
script.dataset.token = props.token;
|
|
82
|
+
}
|
|
83
|
+
if (isDevelopment() && props.debug === false) {
|
|
84
|
+
script.dataset.debug = "false";
|
|
85
|
+
}
|
|
86
|
+
script.onerror = () => {
|
|
87
|
+
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.";
|
|
88
|
+
console.log(
|
|
89
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
document.head.appendChild(script);
|
|
93
|
+
return {
|
|
94
|
+
setRoute: (route) => {
|
|
95
|
+
script.dataset.route = route;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/react/index.tsx
|
|
101
|
+
function SpeedInsights(props) {
|
|
102
|
+
const setScriptRoute = useRef(null);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const script = inject(props);
|
|
105
|
+
setScriptRoute.current = (script == null ? void 0 : script.setRoute) || null;
|
|
106
|
+
}, []);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (props.route && setScriptRoute.current) {
|
|
109
|
+
setScriptRoute.current(props.route);
|
|
110
|
+
}
|
|
111
|
+
}, [props.route]);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/remix/utils.ts
|
|
116
|
+
import { useLocation, useParams } from "@remix-run/react";
|
|
117
|
+
var useRoute = () => {
|
|
118
|
+
const params = useParams();
|
|
119
|
+
const location = useLocation();
|
|
120
|
+
return computeRoute(location.pathname, params);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/remix/index.tsx
|
|
124
|
+
function SpeedInsights2(props) {
|
|
125
|
+
const route = useRoute();
|
|
126
|
+
return /* @__PURE__ */ React.createElement(SpeedInsights, { ...route && { route }, ...props });
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
SpeedInsights2 as SpeedInsights
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/remix/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/remix/utils.ts"],"sourcesContent":["import React from 'react';\nimport { SpeedInsights as SpeedInsightsScript } from '../react';\nimport type { SpeedInsightsProps } from '../types';\nimport { useRoute } from './utils';\n\nexport function SpeedInsights(\n props: Omit<SpeedInsightsProps, 'route'>,\n): JSX.Element {\n const route = useRoute();\n\n return <SpeedInsightsScript {...(route && { route })} {...props} />;\n}\n","'use client';\nimport { useEffect, useRef } from 'react';\nimport type { SpeedInsightsProps } from '../types';\nimport { inject } from '../generic';\n\nexport function SpeedInsights(props: SpeedInsightsProps): JSX.Element | null {\n const setScriptRoute = useRef<((path: string) => void) | null>(null);\n useEffect(() => {\n const script = inject(props);\n\n setScriptRoute.current = script?.setRoute || null;\n }, []);\n\n useEffect(() => {\n if (props.route && setScriptRoute.current) {\n setScriptRoute.current(props.route);\n }\n }, [props.route]);\n\n return null;\n}\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.6\",\n \"description\": \"Speed Insights is a tool for measuring web performance and providing suggestions for improvement.\",\n \"keywords\": [\n \"speed-insights\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/speed-insights\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MPL-2.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.js\",\n \"import\": \"./dist/next/index.js\",\n \"require\": \"./dist/next/index.cjs\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.js\",\n \"import\": \"./dist/remix/index.js\",\n \"require\": \"./dist/remix/index.cjs\"\n }\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"postinstall\": \"node scripts/postinstall.js\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"devDependencies\": {\n \"@remix-run/react\": \"^2.0.1\",\n \"@swc/core\": \"^1.3.82\",\n \"@swc/jest\": \"^0.2.29\",\n \"@testing-library/jest-dom\": \"^6.1.2\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.4\",\n \"@types/node\": \"^20.5.9\",\n \"@types/react\": \"^18.2.21\",\n \"jest\": \"^29.6.4\",\n \"jest-environment-jsdom\": \"^29.6.4\",\n \"next\": \"^13.4.19\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.2.0\"\n }\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.si) return;\n\n window.si = function a(...params): void {\n (window.siq = window.siq || []).push(params);\n };\n};\n","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function isProduction(): boolean {\n return detectEnvironment() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return detectEnvironment() === 'development';\n}\n\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${value}(?=[/?#]|$)`, 'g');\n result = result.replace(matcher, `/[${expr}]`);\n }\n\n return result;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { SpeedInsightsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nconst DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;\nconst SCRIPT_URL = `/_vercel/speed-insights/script.js`;\n\n/**\n * Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).\n * @param [props] - Speed Insights options.\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n */\nfunction inject(props: SpeedInsightsProps): {\n setRoute: (route: string) => void;\n} | null {\n if (!isBrowser()) return null;\n\n initQueue();\n\n if (props.beforeSend) {\n window.si?.('beforeSend', props.beforeSend);\n }\n const src =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n script.dataset.sdkn = packageName;\n script.dataset.sdkv = version;\n\n if (props.sampleRate) {\n script.dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n script.dataset.route = props.route;\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n }\n if (props.token) {\n script.dataset.token = props.token;\n }\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\n }\n\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Speed Insights for your project and deploy again. See https://vercel.com/docs/speed-insights for more information.';\n\n // eslint-disable-next-line no-console -- Logging is okay here\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string): void => {\n script.dataset.route = route;\n },\n };\n}\n\nexport { inject };\nexport type { SpeedInsightsProps };\n\n// eslint-disable-next-line import/no-default-export -- Allow default export\nexport default {\n inject,\n};\n","import { useLocation, useParams } from '@remix-run/react';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const location = useLocation();\n\n return computeRoute(location.pathname, params as never);\n};\n"],"mappings":";AAAA,OAAO,WAAW;;;ACClB,SAAS,WAAW,cAAc;;;ACAhC,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,SAAO;AACT;AAMO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB,MAAM;AACjC;AAEO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AAEb,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,UAAU,GAAG;AAC5D,UAAM,eAAe,MAAM,QAAQ,YAAY;AAC/C,UAAM,QAAQ,eAAe,aAAa,KAAK,GAAG,IAAI;AACtD,UAAM,OAAO,eAAe,MAAM,GAAG,KAAK;AAE1C,UAAM,UAAU,IAAI,OAAO,IAAI,KAAK,eAAe,GAAG;AACtD,aAAS,OAAO,QAAQ,SAAS,KAAK,IAAI,GAAG;AAAA,EAC/C;AAEA,SAAO;AACT;;;ACvCA,IAAM,iBAAiB;AACvB,IAAM,aAAa;AAQnB,SAAS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Ae,SAAS;AACzC,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKpBA,SAAS,aAAa,iBAAiB;AAGhC,IAAM,WAAW,MAAqB;AAC3C,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAE7B,SAAO,aAAa,SAAS,UAAU,MAAe;AACxD;;;ANHO,SAASA,eACd,OACa;AACb,QAAM,QAAQ,SAAS;AAEvB,SAAO,oCAAC,iBAAqB,GAAI,SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","names":["SpeedInsights"]}
|
package/jest.setup.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/speed-insights",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.6",
|
|
4
4
|
"description": "Speed Insights is a tool for measuring web performance and providing suggestions for improvement.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"speed-insights",
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"browser": "./dist/next/index.js",
|
|
24
24
|
"import": "./dist/next/index.js",
|
|
25
25
|
"require": "./dist/next/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./remix": {
|
|
28
|
+
"browser": "./dist/remix/index.js",
|
|
29
|
+
"import": "./dist/remix/index.js",
|
|
30
|
+
"require": "./dist/remix/index.cjs"
|
|
26
31
|
}
|
|
27
32
|
},
|
|
28
33
|
"main": "dist/index.js",
|
|
@@ -37,10 +42,14 @@
|
|
|
37
42
|
],
|
|
38
43
|
"next": [
|
|
39
44
|
"dist/next/index.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"remix": [
|
|
47
|
+
"dist/remix/index.d.ts"
|
|
40
48
|
]
|
|
41
49
|
}
|
|
42
50
|
},
|
|
43
51
|
"devDependencies": {
|
|
52
|
+
"@remix-run/react": "^2.0.1",
|
|
44
53
|
"@swc/core": "^1.3.82",
|
|
45
54
|
"@swc/jest": "^0.2.29",
|
|
46
55
|
"@testing-library/jest-dom": "^6.1.2",
|