@vercel/speed-insights 1.3.1 → 2.0.0
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/dist/astro/component.ts +1 -2
- package/dist/astro/index.astro +25 -10
- package/dist/index.d.mts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +58 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -31
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.d.mts +5 -5
- package/dist/next/index.d.ts +5 -5
- package/dist/next/index.js +84 -38
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +84 -38
- package/dist/next/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +5 -2
- package/dist/nuxt/index.d.ts +5 -2
- package/dist/nuxt/index.js +30 -182
- package/dist/nuxt/index.js.map +1 -1
- package/dist/nuxt/index.mjs +26 -171
- package/dist/nuxt/index.mjs.map +1 -1
- package/dist/nuxt/runtime/index.d.mts +40 -0
- package/dist/nuxt/runtime/index.d.ts +40 -0
- package/dist/nuxt/runtime/index.js +278 -0
- package/dist/nuxt/runtime/index.js.map +1 -0
- package/dist/nuxt/runtime/index.mjs +250 -0
- package/dist/nuxt/runtime/index.mjs.map +1 -0
- package/dist/react/index.d.mts +6 -5
- package/dist/react/index.d.ts +6 -5
- package/dist/react/index.js +76 -37
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +76 -37
- package/dist/react/index.mjs.map +1 -1
- package/dist/remix/index.d.mts +5 -5
- package/dist/remix/index.d.ts +5 -5
- package/dist/remix/index.js +86 -41
- package/dist/remix/index.js.map +1 -1
- package/dist/remix/index.mjs +86 -41
- package/dist/remix/index.mjs.map +1 -1
- package/dist/sveltekit/index.d.mts +6 -6
- package/dist/sveltekit/index.d.ts +6 -6
- package/dist/sveltekit/index.js +77 -43
- package/dist/sveltekit/index.js.map +1 -1
- package/dist/sveltekit/index.mjs +77 -43
- package/dist/sveltekit/index.mjs.map +1 -1
- package/dist/vue/index.d.mts +36 -1
- package/dist/vue/index.d.ts +36 -1
- package/dist/vue/index.js +75 -36
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +75 -36
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +16 -6
- package/tsup.config.js +17 -2
- package/.eslintrc.cjs +0 -7
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/nuxt/runtime/index.ts
|
|
21
|
+
var runtime_exports = {};
|
|
22
|
+
__export(runtime_exports, {
|
|
23
|
+
SpeedInsights: () => SpeedInsights,
|
|
24
|
+
injectSpeedInsights: () => injectSpeedInsights2
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
27
|
+
var import_app = require("nuxt/app");
|
|
28
|
+
|
|
29
|
+
// src/queue.ts
|
|
30
|
+
var initQueue = () => {
|
|
31
|
+
if (window.si) return;
|
|
32
|
+
window.si = function a(...params) {
|
|
33
|
+
window.siq = window.siq || [];
|
|
34
|
+
window.siq.push(params);
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// package.json
|
|
39
|
+
var name = "@vercel/speed-insights";
|
|
40
|
+
var version = "2.0.0";
|
|
41
|
+
|
|
42
|
+
// src/utils.ts
|
|
43
|
+
function isBrowser() {
|
|
44
|
+
return typeof window !== "undefined";
|
|
45
|
+
}
|
|
46
|
+
function detectEnvironment() {
|
|
47
|
+
try {
|
|
48
|
+
const env = process.env.NODE_ENV;
|
|
49
|
+
if (env === "development" || env === "test") {
|
|
50
|
+
return "development";
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
return "production";
|
|
55
|
+
}
|
|
56
|
+
function isDevelopment() {
|
|
57
|
+
return detectEnvironment() === "development";
|
|
58
|
+
}
|
|
59
|
+
function computeRoute(pathname, pathParams) {
|
|
60
|
+
if (!pathname || !pathParams) {
|
|
61
|
+
return pathname;
|
|
62
|
+
}
|
|
63
|
+
let result = pathname;
|
|
64
|
+
try {
|
|
65
|
+
const entries = Object.entries(pathParams);
|
|
66
|
+
for (const [key, value] of entries) {
|
|
67
|
+
if (!Array.isArray(value)) {
|
|
68
|
+
const matcher = turnValueToRegExp(value);
|
|
69
|
+
if (matcher.test(result)) {
|
|
70
|
+
result = result.replace(matcher, `/[${key}]`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const [key, value] of entries) {
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
const matcher = turnValueToRegExp(value.join("/"));
|
|
77
|
+
if (matcher.test(result)) {
|
|
78
|
+
result = result.replace(matcher, `/[...${key}]`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
} catch {
|
|
84
|
+
return pathname;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function turnValueToRegExp(value) {
|
|
88
|
+
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
89
|
+
}
|
|
90
|
+
function escapeRegExp(string) {
|
|
91
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
92
|
+
}
|
|
93
|
+
function getScriptSrc(props) {
|
|
94
|
+
if (props.scriptSrc) {
|
|
95
|
+
return makeAbsolute(props.scriptSrc);
|
|
96
|
+
}
|
|
97
|
+
if (isDevelopment()) {
|
|
98
|
+
return "https://va.vercel-scripts.com/v1/speed-insights/script.debug.js";
|
|
99
|
+
}
|
|
100
|
+
if (props.dsn) {
|
|
101
|
+
return "https://va.vercel-scripts.com/v1/speed-insights/script.js";
|
|
102
|
+
}
|
|
103
|
+
if (props.basePath) {
|
|
104
|
+
return makeAbsolute(`${props.basePath}/speed-insights/script.js`);
|
|
105
|
+
}
|
|
106
|
+
return "/_vercel/speed-insights/script.js";
|
|
107
|
+
}
|
|
108
|
+
function loadProps(explicitProps, confString) {
|
|
109
|
+
var _a;
|
|
110
|
+
let props = explicitProps;
|
|
111
|
+
if (confString) {
|
|
112
|
+
try {
|
|
113
|
+
props = {
|
|
114
|
+
...(_a = JSON.parse(confString)) == null ? void 0 : _a.speedInsights,
|
|
115
|
+
...explicitProps
|
|
116
|
+
};
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const dataset = {
|
|
121
|
+
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
|
122
|
+
sdkv: version
|
|
123
|
+
};
|
|
124
|
+
if (props.sampleRate) {
|
|
125
|
+
dataset.sampleRate = props.sampleRate.toString();
|
|
126
|
+
}
|
|
127
|
+
if (props.route) {
|
|
128
|
+
dataset.route = props.route;
|
|
129
|
+
}
|
|
130
|
+
if (isDevelopment() && props.debug === false) {
|
|
131
|
+
dataset.debug = "false";
|
|
132
|
+
}
|
|
133
|
+
if (props.dsn) {
|
|
134
|
+
dataset.dsn = props.dsn;
|
|
135
|
+
}
|
|
136
|
+
if (props.endpoint) {
|
|
137
|
+
dataset.endpoint = makeAbsolute(props.endpoint);
|
|
138
|
+
} else if (props.basePath) {
|
|
139
|
+
dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
src: getScriptSrc(props),
|
|
143
|
+
beforeSend: props.beforeSend,
|
|
144
|
+
dataset
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function makeAbsolute(url) {
|
|
148
|
+
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/generic.ts
|
|
152
|
+
function injectSpeedInsights(props = {}, confString) {
|
|
153
|
+
var _a;
|
|
154
|
+
if (!isBrowser() || props.route === null) return null;
|
|
155
|
+
initQueue();
|
|
156
|
+
const { beforeSend, src, dataset } = loadProps(props, confString);
|
|
157
|
+
if (document.head.querySelector(`script[src*="${src}"]`)) return null;
|
|
158
|
+
if (beforeSend) {
|
|
159
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
160
|
+
}
|
|
161
|
+
const script = document.createElement("script");
|
|
162
|
+
script.src = src;
|
|
163
|
+
script.defer = true;
|
|
164
|
+
for (const [key, value] of Object.entries(dataset)) {
|
|
165
|
+
script.dataset[key] = value;
|
|
166
|
+
}
|
|
167
|
+
script.onerror = () => {
|
|
168
|
+
console.log(
|
|
169
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
document.head.appendChild(script);
|
|
173
|
+
return {
|
|
174
|
+
setRoute: (route) => {
|
|
175
|
+
script.dataset.route = route ?? void 0;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/vue/create-component.ts
|
|
181
|
+
var import_vue = require("vue");
|
|
182
|
+
var import_vue_router = require("vue-router");
|
|
183
|
+
|
|
184
|
+
// src/vue/utils.ts
|
|
185
|
+
var import_meta = {};
|
|
186
|
+
function getBasePath() {
|
|
187
|
+
try {
|
|
188
|
+
return import_meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function getConfigString() {
|
|
193
|
+
try {
|
|
194
|
+
return import_meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/vue/create-component.ts
|
|
200
|
+
function createComponent(framework = "vue") {
|
|
201
|
+
return (0, import_vue.defineComponent)({
|
|
202
|
+
props: [
|
|
203
|
+
"dsn",
|
|
204
|
+
"sampleRate",
|
|
205
|
+
"beforeSend",
|
|
206
|
+
"debug",
|
|
207
|
+
"scriptSrc",
|
|
208
|
+
"endpoint"
|
|
209
|
+
],
|
|
210
|
+
setup(props) {
|
|
211
|
+
const route = (0, import_vue_router.useRoute)();
|
|
212
|
+
const configure = injectSpeedInsights(
|
|
213
|
+
{
|
|
214
|
+
...Object.fromEntries(
|
|
215
|
+
// trim out undefined values to avoid overriding config values
|
|
216
|
+
Object.entries(props).filter(([_, v]) => v !== void 0)
|
|
217
|
+
),
|
|
218
|
+
framework,
|
|
219
|
+
basePath: getBasePath()
|
|
220
|
+
},
|
|
221
|
+
getConfigString()
|
|
222
|
+
);
|
|
223
|
+
if (route && configure) {
|
|
224
|
+
const changeRoute = () => {
|
|
225
|
+
configure.setRoute(computeRoute(route.path, route.params));
|
|
226
|
+
};
|
|
227
|
+
changeRoute();
|
|
228
|
+
(0, import_vue.watch)(route, changeRoute);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
// Vue component must have a render function, or a template.
|
|
232
|
+
render() {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/nuxt/runtime/utils.ts
|
|
239
|
+
var import_meta2 = {};
|
|
240
|
+
function getBasePath2() {
|
|
241
|
+
try {
|
|
242
|
+
return import_meta2.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
243
|
+
} catch {
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function getConfigString2() {
|
|
247
|
+
try {
|
|
248
|
+
return import_meta2.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
249
|
+
} catch {
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/nuxt/runtime/index.ts
|
|
254
|
+
var SpeedInsights = createComponent("nuxt");
|
|
255
|
+
function injectSpeedInsights2(props = {}) {
|
|
256
|
+
if (isBrowser()) {
|
|
257
|
+
const router = (0, import_app.useRouter)();
|
|
258
|
+
const route = (0, import_app.useRoute)();
|
|
259
|
+
const speedInsights = injectSpeedInsights(
|
|
260
|
+
{
|
|
261
|
+
...props,
|
|
262
|
+
route: computeRoute(route.path, route.params),
|
|
263
|
+
framework: "nuxt",
|
|
264
|
+
basePath: getBasePath2()
|
|
265
|
+
},
|
|
266
|
+
getConfigString2()
|
|
267
|
+
);
|
|
268
|
+
router.afterEach((to) => {
|
|
269
|
+
speedInsights == null ? void 0 : speedInsights.setRoute(computeRoute(to.path, to.params));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
274
|
+
0 && (module.exports = {
|
|
275
|
+
SpeedInsights,
|
|
276
|
+
injectSpeedInsights
|
|
277
|
+
});
|
|
278
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/nuxt/runtime/index.ts","../../../src/queue.ts","../../../package.json","../../../src/utils.ts","../../../src/generic.ts","../../../src/vue/create-component.ts","../../../src/vue/utils.ts","../../../src/nuxt/runtime/utils.ts"],"sourcesContent":["import { useRoute, useRouter } from 'nuxt/app';\nimport {\n type BeforeSendMiddleware,\n injectSpeedInsights as inject,\n} from '../../generic';\nimport type { SpeedInsightsProps } from '../../types';\nimport { computeRoute, isBrowser } from '../../utils';\nimport { createComponent } from '../../vue/create-component';\nimport { getBasePath, getConfigString } from './utils';\n\nexport const SpeedInsights = createComponent('nuxt');\nexport type { SpeedInsightsProps, BeforeSendMiddleware };\n\n// Export the injectSpeedInsights script with automatic tracking on page changes\nfunction injectSpeedInsights(\n props: Omit<SpeedInsightsProps, 'framework'> = {},\n): void {\n if (isBrowser()) {\n const router = useRouter();\n const route = useRoute();\n\n const speedInsights = inject(\n {\n ...props,\n route: computeRoute(route.path, route.params),\n framework: 'nuxt',\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n // On navigation to a new page\n router.afterEach((to) => {\n speedInsights?.setRoute(computeRoute(to.path, to.params));\n });\n }\n}\n\nexport { injectSpeedInsights };\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 || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\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\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\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 \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport 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 {\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 try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\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 * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { injectSpeedInsights, type SpeedInsightsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: [\n 'dsn',\n 'sampleRate',\n 'beforeSend',\n 'debug',\n 'scriptSrc',\n 'endpoint',\n ],\n setup(props: Omit<SpeedInsightsProps, 'framework'>) {\n const route = useRoute();\n const configure = injectSpeedInsights(\n {\n ...Object.fromEntries(\n // trim out undefined values to avoid overriding config values\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n framework,\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n if (route && configure) {\n const changeRoute = (): void => {\n configure.setRoute(computeRoute(route.path, route.params));\n };\n\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\n },\n });\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERV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qDAAe,SAAS,aAAa,GAAG,MAAM,GAAG,MAAM;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":["injectSpeedInsights","import_meta","getBasePath","getConfigString","injectSpeedInsights","getBasePath","getConfigString"]}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// src/nuxt/runtime/index.ts
|
|
2
|
+
import { useRoute as useRoute2, useRouter } from "nuxt/app";
|
|
3
|
+
|
|
4
|
+
// src/queue.ts
|
|
5
|
+
var initQueue = () => {
|
|
6
|
+
if (window.si) return;
|
|
7
|
+
window.si = function a(...params) {
|
|
8
|
+
window.siq = window.siq || [];
|
|
9
|
+
window.siq.push(params);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var name = "@vercel/speed-insights";
|
|
15
|
+
var version = "2.0.0";
|
|
16
|
+
|
|
17
|
+
// src/utils.ts
|
|
18
|
+
function isBrowser() {
|
|
19
|
+
return typeof window !== "undefined";
|
|
20
|
+
}
|
|
21
|
+
function detectEnvironment() {
|
|
22
|
+
try {
|
|
23
|
+
const env = process.env.NODE_ENV;
|
|
24
|
+
if (env === "development" || env === "test") {
|
|
25
|
+
return "development";
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
return "production";
|
|
30
|
+
}
|
|
31
|
+
function isDevelopment() {
|
|
32
|
+
return detectEnvironment() === "development";
|
|
33
|
+
}
|
|
34
|
+
function computeRoute(pathname, pathParams) {
|
|
35
|
+
if (!pathname || !pathParams) {
|
|
36
|
+
return pathname;
|
|
37
|
+
}
|
|
38
|
+
let result = pathname;
|
|
39
|
+
try {
|
|
40
|
+
const entries = Object.entries(pathParams);
|
|
41
|
+
for (const [key, value] of entries) {
|
|
42
|
+
if (!Array.isArray(value)) {
|
|
43
|
+
const matcher = turnValueToRegExp(value);
|
|
44
|
+
if (matcher.test(result)) {
|
|
45
|
+
result = result.replace(matcher, `/[${key}]`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [key, value] of entries) {
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
const matcher = turnValueToRegExp(value.join("/"));
|
|
52
|
+
if (matcher.test(result)) {
|
|
53
|
+
result = result.replace(matcher, `/[...${key}]`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
} catch {
|
|
59
|
+
return pathname;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function turnValueToRegExp(value) {
|
|
63
|
+
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
64
|
+
}
|
|
65
|
+
function escapeRegExp(string) {
|
|
66
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
67
|
+
}
|
|
68
|
+
function getScriptSrc(props) {
|
|
69
|
+
if (props.scriptSrc) {
|
|
70
|
+
return makeAbsolute(props.scriptSrc);
|
|
71
|
+
}
|
|
72
|
+
if (isDevelopment()) {
|
|
73
|
+
return "https://va.vercel-scripts.com/v1/speed-insights/script.debug.js";
|
|
74
|
+
}
|
|
75
|
+
if (props.dsn) {
|
|
76
|
+
return "https://va.vercel-scripts.com/v1/speed-insights/script.js";
|
|
77
|
+
}
|
|
78
|
+
if (props.basePath) {
|
|
79
|
+
return makeAbsolute(`${props.basePath}/speed-insights/script.js`);
|
|
80
|
+
}
|
|
81
|
+
return "/_vercel/speed-insights/script.js";
|
|
82
|
+
}
|
|
83
|
+
function loadProps(explicitProps, confString) {
|
|
84
|
+
var _a;
|
|
85
|
+
let props = explicitProps;
|
|
86
|
+
if (confString) {
|
|
87
|
+
try {
|
|
88
|
+
props = {
|
|
89
|
+
...(_a = JSON.parse(confString)) == null ? void 0 : _a.speedInsights,
|
|
90
|
+
...explicitProps
|
|
91
|
+
};
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const dataset = {
|
|
96
|
+
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
|
97
|
+
sdkv: version
|
|
98
|
+
};
|
|
99
|
+
if (props.sampleRate) {
|
|
100
|
+
dataset.sampleRate = props.sampleRate.toString();
|
|
101
|
+
}
|
|
102
|
+
if (props.route) {
|
|
103
|
+
dataset.route = props.route;
|
|
104
|
+
}
|
|
105
|
+
if (isDevelopment() && props.debug === false) {
|
|
106
|
+
dataset.debug = "false";
|
|
107
|
+
}
|
|
108
|
+
if (props.dsn) {
|
|
109
|
+
dataset.dsn = props.dsn;
|
|
110
|
+
}
|
|
111
|
+
if (props.endpoint) {
|
|
112
|
+
dataset.endpoint = makeAbsolute(props.endpoint);
|
|
113
|
+
} else if (props.basePath) {
|
|
114
|
+
dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
src: getScriptSrc(props),
|
|
118
|
+
beforeSend: props.beforeSend,
|
|
119
|
+
dataset
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function makeAbsolute(url) {
|
|
123
|
+
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/generic.ts
|
|
127
|
+
function injectSpeedInsights(props = {}, confString) {
|
|
128
|
+
var _a;
|
|
129
|
+
if (!isBrowser() || props.route === null) return null;
|
|
130
|
+
initQueue();
|
|
131
|
+
const { beforeSend, src, dataset } = loadProps(props, confString);
|
|
132
|
+
if (document.head.querySelector(`script[src*="${src}"]`)) return null;
|
|
133
|
+
if (beforeSend) {
|
|
134
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
135
|
+
}
|
|
136
|
+
const script = document.createElement("script");
|
|
137
|
+
script.src = src;
|
|
138
|
+
script.defer = true;
|
|
139
|
+
for (const [key, value] of Object.entries(dataset)) {
|
|
140
|
+
script.dataset[key] = value;
|
|
141
|
+
}
|
|
142
|
+
script.onerror = () => {
|
|
143
|
+
console.log(
|
|
144
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
document.head.appendChild(script);
|
|
148
|
+
return {
|
|
149
|
+
setRoute: (route) => {
|
|
150
|
+
script.dataset.route = route ?? void 0;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/vue/create-component.ts
|
|
156
|
+
import { defineComponent, watch } from "vue";
|
|
157
|
+
import { useRoute } from "vue-router";
|
|
158
|
+
|
|
159
|
+
// src/vue/utils.ts
|
|
160
|
+
function getBasePath() {
|
|
161
|
+
try {
|
|
162
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getConfigString() {
|
|
167
|
+
try {
|
|
168
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/vue/create-component.ts
|
|
174
|
+
function createComponent(framework = "vue") {
|
|
175
|
+
return defineComponent({
|
|
176
|
+
props: [
|
|
177
|
+
"dsn",
|
|
178
|
+
"sampleRate",
|
|
179
|
+
"beforeSend",
|
|
180
|
+
"debug",
|
|
181
|
+
"scriptSrc",
|
|
182
|
+
"endpoint"
|
|
183
|
+
],
|
|
184
|
+
setup(props) {
|
|
185
|
+
const route = useRoute();
|
|
186
|
+
const configure = injectSpeedInsights(
|
|
187
|
+
{
|
|
188
|
+
...Object.fromEntries(
|
|
189
|
+
// trim out undefined values to avoid overriding config values
|
|
190
|
+
Object.entries(props).filter(([_, v]) => v !== void 0)
|
|
191
|
+
),
|
|
192
|
+
framework,
|
|
193
|
+
basePath: getBasePath()
|
|
194
|
+
},
|
|
195
|
+
getConfigString()
|
|
196
|
+
);
|
|
197
|
+
if (route && configure) {
|
|
198
|
+
const changeRoute = () => {
|
|
199
|
+
configure.setRoute(computeRoute(route.path, route.params));
|
|
200
|
+
};
|
|
201
|
+
changeRoute();
|
|
202
|
+
watch(route, changeRoute);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
// Vue component must have a render function, or a template.
|
|
206
|
+
render() {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/nuxt/runtime/utils.ts
|
|
213
|
+
function getBasePath2() {
|
|
214
|
+
try {
|
|
215
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getConfigString2() {
|
|
220
|
+
try {
|
|
221
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/nuxt/runtime/index.ts
|
|
227
|
+
var SpeedInsights = createComponent("nuxt");
|
|
228
|
+
function injectSpeedInsights2(props = {}) {
|
|
229
|
+
if (isBrowser()) {
|
|
230
|
+
const router = useRouter();
|
|
231
|
+
const route = useRoute2();
|
|
232
|
+
const speedInsights = injectSpeedInsights(
|
|
233
|
+
{
|
|
234
|
+
...props,
|
|
235
|
+
route: computeRoute(route.path, route.params),
|
|
236
|
+
framework: "nuxt",
|
|
237
|
+
basePath: getBasePath2()
|
|
238
|
+
},
|
|
239
|
+
getConfigString2()
|
|
240
|
+
);
|
|
241
|
+
router.afterEach((to) => {
|
|
242
|
+
speedInsights == null ? void 0 : speedInsights.setRoute(computeRoute(to.path, to.params));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export {
|
|
247
|
+
SpeedInsights,
|
|
248
|
+
injectSpeedInsights2 as injectSpeedInsights
|
|
249
|
+
};
|
|
250
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/nuxt/runtime/index.ts","../../../src/queue.ts","../../../package.json","../../../src/utils.ts","../../../src/generic.ts","../../../src/vue/create-component.ts","../../../src/vue/utils.ts","../../../src/nuxt/runtime/utils.ts"],"sourcesContent":["import { useRoute, useRouter } from 'nuxt/app';\nimport {\n type BeforeSendMiddleware,\n injectSpeedInsights as inject,\n} from '../../generic';\nimport type { SpeedInsightsProps } from '../../types';\nimport { computeRoute, isBrowser } from '../../utils';\nimport { createComponent } from '../../vue/create-component';\nimport { getBasePath, getConfigString } from './utils';\n\nexport const SpeedInsights = createComponent('nuxt');\nexport type { SpeedInsightsProps, BeforeSendMiddleware };\n\n// Export the injectSpeedInsights script with automatic tracking on page changes\nfunction injectSpeedInsights(\n props: Omit<SpeedInsightsProps, 'framework'> = {},\n): void {\n if (isBrowser()) {\n const router = useRouter();\n const route = useRoute();\n\n const speedInsights = inject(\n {\n ...props,\n route: computeRoute(route.path, route.params),\n framework: 'nuxt',\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n // On navigation to a new page\n router.afterEach((to) => {\n speedInsights?.setRoute(computeRoute(to.path, to.params));\n });\n }\n}\n\nexport { injectSpeedInsights };\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 || [];\n window.siq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"2.0.0\",\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\": \"Apache-2.0\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./sveltekit\": {\n \"types\": \"./dist/sveltekit/index.d.ts\",\n \"svelte\": \"./dist/sveltekit/index.mjs\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\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 \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@remix-run/react\": \"^2.14.0\",\n \"@sveltejs/kit\": \"^2.8.1\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.1\",\n \"@types/react\": \"^18.3.12\",\n \"copyfiles\": \"^2.4.1\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"^14.0.4\",\n \"react\": \"^18.3.1\",\n \"react-dom\": \"^18.3.1\",\n \"svelte\": \"^5.2.7\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\n \"vue\": \"^3.5.13\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"nuxt\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\n\nexport 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 {\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 try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(\n props: SpeedInsightsProps & { basePath?: string },\n): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js';\n }\n if (props.dsn) {\n return 'https://va.vercel-scripts.com/v1/speed-insights/script.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/speed-insights/script.js`);\n }\n return '/_vercel/speed-insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectSpeedInsightsProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)\n ?.speedInsights as Partial<SpeedInsightsProps>),\n ...explicitProps,\n };\n } catch {\n // Invalid JSON, use only explicit props\n }\n }\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n\n if (props.sampleRate) {\n dataset.sampleRate = props.sampleRate.toString();\n }\n if (props.route) {\n dataset.route = props.route;\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n\n if (props.endpoint) {\n dataset.endpoint = makeAbsolute(props.endpoint);\n } else if (props.basePath) {\n // backward compatibility\n dataset.endpoint = makeAbsolute(`${props.basePath}/speed-insights/vitals`);\n }\n\n return {\n src: getScriptSrc(props),\n beforeSend: props.beforeSend,\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n BeforeSend,\n InjectSpeedInsightsProps,\n SpeedInsightsProps,\n} from './types';\nimport { computeRoute, isBrowser, loadProps } from './utils';\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 * @param [props.sampleRate] - When setting to 0.5, 50% of the events will be sent to Vercel Speed Insights. Defaults to `1`.\n * @param [props.route] - The dynamic route of the page.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [confString] - an optional JSON string (InjectSpeedInsightsProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction injectSpeedInsights(\n props: InjectSpeedInsightsProps = {},\n confString?: string,\n): {\n setRoute: (route: string | null) => void;\n} | null {\n // When route is null, it means that pages router is not ready yet. Will resolve soon\n if (!isBrowser() || props.route === null) return null;\n\n initQueue();\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return null;\n\n if (beforeSend) {\n window.si?.('beforeSend', beforeSend);\n }\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n // Apply all dataset attributes from loadProps\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n\n script.onerror = (): void => {\n console.log(\n `[Vercel Speed Insights] Failed to load script from ${src}. Please check if any content blockers are enabled and try again.`,\n );\n };\n\n document.head.appendChild(script);\n\n return {\n setRoute: (route: string | null): void => {\n script.dataset.route = route ?? undefined;\n },\n };\n}\n\nexport { injectSpeedInsights, computeRoute };\nexport type { SpeedInsightsProps, BeforeSend as BeforeSendMiddleware };\n\nexport default {\n injectSpeedInsights,\n computeRoute,\n};\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { injectSpeedInsights, type SpeedInsightsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: [\n 'dsn',\n 'sampleRate',\n 'beforeSend',\n 'debug',\n 'scriptSrc',\n 'endpoint',\n ],\n setup(props: Omit<SpeedInsightsProps, 'framework'>) {\n const route = useRoute();\n const configure = injectSpeedInsights(\n {\n ...Object.fromEntries(\n // trim out undefined values to avoid overriding config values\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n framework,\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n if (route && configure) {\n const changeRoute = (): void => {\n configure.setRoute(computeRoute(route.path, route.params));\n };\n\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\n },\n });\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";AAAA,SAAS,YAAAA,WAAU,iBAAiB;;;ACA7B,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,WAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACKN,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,QAAQ;AAAA,EAER;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;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,cAAM,UAAU,kBAAkB,KAAK;AACvC,YAAI,QAAQ,KAAK,MAAM,GAAG;AACxB,mBAAS,OAAO,QAAQ,SAAS,KAAK,GAAG,GAAG;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,eAAW,CAAC,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GAAG;AAAA,QACH,OAAO,aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,QAC5C,WAAW;AAAA,QACX,UAAUC,aAAY;AAAA,MACxB;AAAA,MACAC,iBAAgB;AAAA,IAClB;AAEA,WAAO,UAAU,CAAC,OAAO;AACvB,qDAAe,SAAS,aAAa,GAAG,MAAM,GAAG,MAAM;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":["useRoute","getBasePath","getConfigString","injectSpeedInsights","useRoute","getBasePath","getConfigString"]}
|
package/dist/react/index.d.mts
CHANGED
|
@@ -2,20 +2,20 @@ interface SpeedInsightsProps {
|
|
|
2
2
|
dsn?: string;
|
|
3
3
|
sampleRate?: number;
|
|
4
4
|
route?: string | null;
|
|
5
|
-
beforeSend?:
|
|
5
|
+
beforeSend?: BeforeSend;
|
|
6
6
|
debug?: boolean;
|
|
7
7
|
scriptSrc?: string;
|
|
8
8
|
endpoint?: string;
|
|
9
9
|
}
|
|
10
10
|
type EventTypes = 'vital';
|
|
11
|
-
interface
|
|
11
|
+
interface BeforeSendEvent {
|
|
12
12
|
type: EventTypes;
|
|
13
13
|
url: string;
|
|
14
14
|
route?: string;
|
|
15
15
|
}
|
|
16
|
-
type
|
|
16
|
+
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null | undefined | false;
|
|
17
17
|
interface Functions {
|
|
18
|
-
beforeSend?:
|
|
18
|
+
beforeSend?: BeforeSend;
|
|
19
19
|
}
|
|
20
20
|
interface SpeedInsights$1<T extends keyof Functions = keyof Functions> {
|
|
21
21
|
queue: [T, Functions[T]][];
|
|
@@ -29,7 +29,7 @@ declare global {
|
|
|
29
29
|
siq?: SpeedInsights$1['queue'];
|
|
30
30
|
sil?: boolean;
|
|
31
31
|
/** used by Astro component only */
|
|
32
|
-
speedInsightsBeforeSend?:
|
|
32
|
+
speedInsightsBeforeSend?: BeforeSend;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -38,6 +38,7 @@ declare function computeRoute(pathname: string | null, pathParams: Record<string
|
|
|
38
38
|
declare function SpeedInsights(props: SpeedInsightsProps & {
|
|
39
39
|
framework?: string;
|
|
40
40
|
basePath?: string;
|
|
41
|
+
configString?: string;
|
|
41
42
|
}): JSX.Element | null;
|
|
42
43
|
|
|
43
44
|
export { SpeedInsights, computeRoute };
|