@vercel/speed-insights 0.0.1-beta.5 → 0.0.1-beta.7
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/index.cjs +113 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.cjs +28 -40
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +28 -40
- package/dist/next/index.js.map +1 -1
- package/dist/remix/index.cjs +15 -37
- package/dist/remix/index.cjs.map +1 -1
- package/dist/remix/index.d.cts +1 -1
- package/dist/remix/index.d.ts +1 -1
- package/dist/remix/index.js +15 -37
- package/dist/remix/index.js.map +1 -1
- package/jest.setup.ts +0 -3
- package/package.json +1 -1
- package/tsup.config.js +7 -7
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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/generic.ts
|
|
21
|
+
var generic_exports = {};
|
|
22
|
+
__export(generic_exports, {
|
|
23
|
+
default: () => generic_default,
|
|
24
|
+
inject: () => inject
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(generic_exports);
|
|
27
|
+
|
|
28
|
+
// package.json
|
|
29
|
+
var name = "@vercel/speed-insights";
|
|
30
|
+
var version = "0.0.1-beta.7";
|
|
31
|
+
|
|
32
|
+
// src/queue.ts
|
|
33
|
+
var initQueue = () => {
|
|
34
|
+
if (window.si)
|
|
35
|
+
return;
|
|
36
|
+
window.si = function a(...params) {
|
|
37
|
+
(window.siq = window.siq || []).push(params);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/utils.ts
|
|
42
|
+
function isBrowser() {
|
|
43
|
+
return typeof window !== "undefined";
|
|
44
|
+
}
|
|
45
|
+
function detectEnvironment() {
|
|
46
|
+
try {
|
|
47
|
+
const env = process.env.NODE_ENV;
|
|
48
|
+
if (env === "development" || env === "test") {
|
|
49
|
+
return "development";
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
}
|
|
53
|
+
return "production";
|
|
54
|
+
}
|
|
55
|
+
function isDevelopment() {
|
|
56
|
+
return detectEnvironment() === "development";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/generic.ts
|
|
60
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
61
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
62
|
+
function inject(props) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (!isBrowser() || props.route === null)
|
|
65
|
+
return null;
|
|
66
|
+
initQueue();
|
|
67
|
+
if (props.beforeSend) {
|
|
68
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
69
|
+
}
|
|
70
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
71
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
72
|
+
return null;
|
|
73
|
+
const script = document.createElement("script");
|
|
74
|
+
script.src = src;
|
|
75
|
+
script.defer = true;
|
|
76
|
+
script.dataset.sdkn = name;
|
|
77
|
+
script.dataset.sdkv = version;
|
|
78
|
+
if (props.sampleRate) {
|
|
79
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
80
|
+
}
|
|
81
|
+
if (props.route) {
|
|
82
|
+
script.dataset.route = props.route;
|
|
83
|
+
}
|
|
84
|
+
if (props.endpoint) {
|
|
85
|
+
script.dataset.endpoint = props.endpoint;
|
|
86
|
+
}
|
|
87
|
+
if (props.token) {
|
|
88
|
+
script.dataset.token = props.token;
|
|
89
|
+
}
|
|
90
|
+
if (isDevelopment() && props.debug === false) {
|
|
91
|
+
script.dataset.debug = "false";
|
|
92
|
+
}
|
|
93
|
+
script.onerror = () => {
|
|
94
|
+
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.";
|
|
95
|
+
console.log(
|
|
96
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
document.head.appendChild(script);
|
|
100
|
+
return {
|
|
101
|
+
setRoute: (route) => {
|
|
102
|
+
script.dataset.route = route;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
var generic_default = {
|
|
107
|
+
inject
|
|
108
|
+
};
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
inject
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../package.json","../src/queue.ts","../src/utils.ts"],"sourcesContent":["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 // 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 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","{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCE,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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,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface SpeedInsightsProps {
|
|
2
|
+
token?: string;
|
|
3
|
+
sampleRate?: number;
|
|
4
|
+
route?: string | null;
|
|
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<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['addAction'];
|
|
27
|
+
/** Queue for speed insights datapoints, before the library is loaded */
|
|
28
|
+
siq?: SpeedInsights['queue'];
|
|
29
|
+
sil?: boolean;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 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).
|
|
35
|
+
* @param [props] - Speed Insights options.
|
|
36
|
+
* @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.
|
|
37
|
+
* @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.
|
|
38
|
+
*/
|
|
39
|
+
declare function inject(props: SpeedInsightsProps): {
|
|
40
|
+
setRoute: (route: string) => void;
|
|
41
|
+
} | null;
|
|
42
|
+
|
|
43
|
+
declare const _default: {
|
|
44
|
+
inject: typeof inject;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { SpeedInsightsProps, _default as default, inject };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface SpeedInsightsProps {
|
|
2
|
+
token?: string;
|
|
3
|
+
sampleRate?: number;
|
|
4
|
+
route?: string | null;
|
|
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<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['addAction'];
|
|
27
|
+
/** Queue for speed insights datapoints, before the library is loaded */
|
|
28
|
+
siq?: SpeedInsights['queue'];
|
|
29
|
+
sil?: boolean;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 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).
|
|
35
|
+
* @param [props] - Speed Insights options.
|
|
36
|
+
* @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.
|
|
37
|
+
* @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.
|
|
38
|
+
*/
|
|
39
|
+
declare function inject(props: SpeedInsightsProps): {
|
|
40
|
+
setRoute: (route: string) => void;
|
|
41
|
+
} | null;
|
|
42
|
+
|
|
43
|
+
declare const _default: {
|
|
44
|
+
inject: typeof inject;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { SpeedInsightsProps, _default as default, inject };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var name = "@vercel/speed-insights";
|
|
3
|
+
var version = "0.0.1-beta.7";
|
|
4
|
+
|
|
5
|
+
// src/queue.ts
|
|
6
|
+
var initQueue = () => {
|
|
7
|
+
if (window.si)
|
|
8
|
+
return;
|
|
9
|
+
window.si = function a(...params) {
|
|
10
|
+
(window.siq = window.siq || []).push(params);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/utils.ts
|
|
15
|
+
function isBrowser() {
|
|
16
|
+
return typeof window !== "undefined";
|
|
17
|
+
}
|
|
18
|
+
function detectEnvironment() {
|
|
19
|
+
try {
|
|
20
|
+
const env = process.env.NODE_ENV;
|
|
21
|
+
if (env === "development" || env === "test") {
|
|
22
|
+
return "development";
|
|
23
|
+
}
|
|
24
|
+
} catch (e) {
|
|
25
|
+
}
|
|
26
|
+
return "production";
|
|
27
|
+
}
|
|
28
|
+
function isDevelopment() {
|
|
29
|
+
return detectEnvironment() === "development";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/generic.ts
|
|
33
|
+
var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.debug.js`;
|
|
34
|
+
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
35
|
+
function inject(props) {
|
|
36
|
+
var _a;
|
|
37
|
+
if (!isBrowser() || props.route === null)
|
|
38
|
+
return null;
|
|
39
|
+
initQueue();
|
|
40
|
+
if (props.beforeSend) {
|
|
41
|
+
(_a = window.si) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
42
|
+
}
|
|
43
|
+
const src = props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : SCRIPT_URL);
|
|
44
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
45
|
+
return null;
|
|
46
|
+
const script = document.createElement("script");
|
|
47
|
+
script.src = src;
|
|
48
|
+
script.defer = true;
|
|
49
|
+
script.dataset.sdkn = name;
|
|
50
|
+
script.dataset.sdkv = version;
|
|
51
|
+
if (props.sampleRate) {
|
|
52
|
+
script.dataset.sampleRate = props.sampleRate.toString();
|
|
53
|
+
}
|
|
54
|
+
if (props.route) {
|
|
55
|
+
script.dataset.route = props.route;
|
|
56
|
+
}
|
|
57
|
+
if (props.endpoint) {
|
|
58
|
+
script.dataset.endpoint = props.endpoint;
|
|
59
|
+
}
|
|
60
|
+
if (props.token) {
|
|
61
|
+
script.dataset.token = props.token;
|
|
62
|
+
}
|
|
63
|
+
if (isDevelopment() && props.debug === false) {
|
|
64
|
+
script.dataset.debug = "false";
|
|
65
|
+
}
|
|
66
|
+
script.onerror = () => {
|
|
67
|
+
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.";
|
|
68
|
+
console.log(
|
|
69
|
+
`[Vercel Speed Insights] Failed to load script from ${src}. ${errorMessage}`
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
document.head.appendChild(script);
|
|
73
|
+
return {
|
|
74
|
+
setRoute: (route) => {
|
|
75
|
+
script.dataset.route = route;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var generic_default = {
|
|
80
|
+
inject
|
|
81
|
+
};
|
|
82
|
+
export {
|
|
83
|
+
generic_default as default,
|
|
84
|
+
inject
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["{\n \"name\": \"@vercel/speed-insights\",\n \"version\": \"0.0.1-beta.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\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 // 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 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"],"mappings":";AACE,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,IA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AAA,IACzB;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AACF;","names":[]}
|
package/dist/next/index.cjs
CHANGED
|
@@ -34,14 +34,14 @@ __export(nextjs_exports, {
|
|
|
34
34
|
SpeedInsights: () => SpeedInsights2
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(nextjs_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
38
38
|
|
|
39
39
|
// src/react/index.tsx
|
|
40
40
|
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.7";
|
|
45
45
|
|
|
46
46
|
// src/queue.ts
|
|
47
47
|
var initQueue = () => {
|
|
@@ -70,40 +70,17 @@ function isDevelopment() {
|
|
|
70
70
|
return detectEnvironment() === "development";
|
|
71
71
|
}
|
|
72
72
|
function computeRoute(pathname, pathParams) {
|
|
73
|
-
if (pathname
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
if (pathname === "" || !pathParams) {
|
|
73
|
+
if (!pathname || !pathParams) {
|
|
77
74
|
return pathname;
|
|
78
75
|
}
|
|
79
76
|
let result = pathname;
|
|
80
77
|
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
expr = key;
|
|
88
|
-
value = valueOrArray;
|
|
89
|
-
}
|
|
90
|
-
if (!value) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
let start = 0;
|
|
94
|
-
while (start !== -1) {
|
|
95
|
-
start = result.indexOf(`/${value}`, start);
|
|
96
|
-
if (start !== -1) {
|
|
97
|
-
const end = start + value.length + 2;
|
|
98
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
99
|
-
result = `${result.substring(
|
|
100
|
-
0,
|
|
101
|
-
start + 1
|
|
102
|
-
)}[${expr}]${result.substring(end)}`;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
start += value.length + 1;
|
|
106
|
-
}
|
|
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}(?=[/?#]|$)`);
|
|
82
|
+
if (matcher.test(result)) {
|
|
83
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
107
84
|
}
|
|
108
85
|
}
|
|
109
86
|
return result;
|
|
@@ -114,7 +91,7 @@ var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.deb
|
|
|
114
91
|
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
115
92
|
function inject(props) {
|
|
116
93
|
var _a;
|
|
117
|
-
if (!isBrowser())
|
|
94
|
+
if (!isBrowser() || props.route === null)
|
|
118
95
|
return null;
|
|
119
96
|
initQueue();
|
|
120
97
|
if (props.beforeSend) {
|
|
@@ -161,11 +138,12 @@ function inject(props) {
|
|
|
161
138
|
function SpeedInsights(props) {
|
|
162
139
|
const setScriptRoute = (0, import_react.useRef)(null);
|
|
163
140
|
(0, import_react.useEffect)(() => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
141
|
+
if (!setScriptRoute.current) {
|
|
142
|
+
const script = inject(props);
|
|
143
|
+
if (script) {
|
|
144
|
+
setScriptRoute.current = script.setRoute;
|
|
145
|
+
}
|
|
146
|
+
} else if (props.route) {
|
|
169
147
|
setScriptRoute.current(props.route);
|
|
170
148
|
}
|
|
171
149
|
}, [props.route]);
|
|
@@ -174,16 +152,26 @@ function SpeedInsights(props) {
|
|
|
174
152
|
|
|
175
153
|
// src/nextjs/utils.ts
|
|
176
154
|
var import_navigation = require("next/navigation");
|
|
155
|
+
var import_react2 = require("react");
|
|
177
156
|
var useRoute = () => {
|
|
178
157
|
const params = (0, import_navigation.useParams)();
|
|
158
|
+
const searchParams = (0, import_navigation.useSearchParams)();
|
|
179
159
|
const path = (0, import_navigation.usePathname)();
|
|
180
|
-
|
|
160
|
+
const finalParams = (0, import_react2.useMemo)(() => {
|
|
161
|
+
if (!params)
|
|
162
|
+
return null;
|
|
163
|
+
if (Object.keys(params).length !== 0) {
|
|
164
|
+
return params;
|
|
165
|
+
}
|
|
166
|
+
return { ...Object.fromEntries(searchParams.entries()) };
|
|
167
|
+
}, [params, searchParams]);
|
|
168
|
+
return computeRoute(path, finalParams);
|
|
181
169
|
};
|
|
182
170
|
|
|
183
171
|
// src/nextjs/index.tsx
|
|
184
172
|
function SpeedInsights2(props) {
|
|
185
173
|
const route = useRoute();
|
|
186
|
-
return /* @__PURE__ */
|
|
174
|
+
return /* @__PURE__ */ import_react3.default.createElement(SpeedInsights, { route, ...props });
|
|
187
175
|
}
|
|
188
176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
189
177
|
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 { 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.5\",\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 === 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","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,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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,GAAG,KAAK,YAAY;AAAA,IAC5E;AAAA,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;;;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"]}
|
|
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 if (!setScriptRoute.current) {\n const script = inject(props);\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n } else if (props.route) {\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.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\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 // 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 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, useSearchParams } from 'next/navigation';\nimport { useMemo } from 'react';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams();\n const path = usePathname();\n\n const finalParams = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be null on pages router\n if (!params) return null;\n if (Object.keys(params).length !== 0) {\n return params;\n }\n // For pages router, we need to use `searchParams` because `params` is an empty object\n return { ...Object.fromEntries(searchParams.entries()) };\n }, [params, searchParams]);\n\n return computeRoute(path, finalParams);\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,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,aAAa;AACjD,QAAI,QAAQ,KAAK,MAAM,GAAG;AACxB,eAAS,OAAO,QAAQ,SAAS,KAAK,IAAI,GAAG;AAAA,IAC/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B,YAAM,SAAS,OAAO,KAAK;AAC3B,UAAI,QAAQ;AACV,uBAAe,UAAU,OAAO;AAAA,MAClC;AAAA,IACF,WAAW,MAAM,OAAO;AACtB,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKlBA,wBAAwD;AACxD,IAAAC,gBAAwB;AAGjB,IAAM,WAAW,MAAqB;AAC3C,QAAM,aAAS,6BAAU;AACzB,QAAM,mBAAe,mCAAgB;AACrC,QAAM,WAAO,+BAAY;AAEzB,QAAM,kBAAc,uBAAQ,MAAM;AAEhC,QAAI,CAAC;AAAQ,aAAO;AACpB,QAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AACpC,aAAO;AAAA,IACT;AAEA,WAAO,EAAE,GAAG,OAAO,YAAY,aAAa,QAAQ,CAAC,EAAE;AAAA,EACzD,GAAG,CAAC,QAAQ,YAAY,CAAC;AAEzB,SAAO,aAAa,MAAM,WAAW;AACvC;;;ANhBO,SAASC,eACd,OACa;AACb,QAAM,QAAQ,SAAS;AAEvB,SAAO,8BAAAC,QAAA,cAAC,iBAAoB,OAAe,GAAG,OAAO;AACvD;","names":["SpeedInsights","import_react","import_react","SpeedInsights","React"]}
|
package/dist/next/index.d.cts
CHANGED
package/dist/next/index.d.ts
CHANGED
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.7";
|
|
12
12
|
|
|
13
13
|
// src/queue.ts
|
|
14
14
|
var initQueue = () => {
|
|
@@ -37,40 +37,17 @@ function isDevelopment() {
|
|
|
37
37
|
return detectEnvironment() === "development";
|
|
38
38
|
}
|
|
39
39
|
function computeRoute(pathname, pathParams) {
|
|
40
|
-
if (pathname
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
if (pathname === "" || !pathParams) {
|
|
40
|
+
if (!pathname || !pathParams) {
|
|
44
41
|
return pathname;
|
|
45
42
|
}
|
|
46
43
|
let result = pathname;
|
|
47
44
|
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expr = key;
|
|
55
|
-
value = valueOrArray;
|
|
56
|
-
}
|
|
57
|
-
if (!value) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
let start = 0;
|
|
61
|
-
while (start !== -1) {
|
|
62
|
-
start = result.indexOf(`/${value}`, start);
|
|
63
|
-
if (start !== -1) {
|
|
64
|
-
const end = start + value.length + 2;
|
|
65
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
66
|
-
result = `${result.substring(
|
|
67
|
-
0,
|
|
68
|
-
start + 1
|
|
69
|
-
)}[${expr}]${result.substring(end)}`;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
start += value.length + 1;
|
|
73
|
-
}
|
|
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}(?=[/?#]|$)`);
|
|
49
|
+
if (matcher.test(result)) {
|
|
50
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
74
51
|
}
|
|
75
52
|
}
|
|
76
53
|
return result;
|
|
@@ -81,7 +58,7 @@ var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.deb
|
|
|
81
58
|
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
82
59
|
function inject(props) {
|
|
83
60
|
var _a;
|
|
84
|
-
if (!isBrowser())
|
|
61
|
+
if (!isBrowser() || props.route === null)
|
|
85
62
|
return null;
|
|
86
63
|
initQueue();
|
|
87
64
|
if (props.beforeSend) {
|
|
@@ -128,11 +105,12 @@ function inject(props) {
|
|
|
128
105
|
function SpeedInsights(props) {
|
|
129
106
|
const setScriptRoute = useRef(null);
|
|
130
107
|
useEffect(() => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
108
|
+
if (!setScriptRoute.current) {
|
|
109
|
+
const script = inject(props);
|
|
110
|
+
if (script) {
|
|
111
|
+
setScriptRoute.current = script.setRoute;
|
|
112
|
+
}
|
|
113
|
+
} else if (props.route) {
|
|
136
114
|
setScriptRoute.current(props.route);
|
|
137
115
|
}
|
|
138
116
|
}, [props.route]);
|
|
@@ -140,17 +118,27 @@ function SpeedInsights(props) {
|
|
|
140
118
|
}
|
|
141
119
|
|
|
142
120
|
// src/nextjs/utils.ts
|
|
143
|
-
import { useParams, usePathname } from "next/navigation";
|
|
121
|
+
import { useParams, usePathname, useSearchParams } from "next/navigation";
|
|
122
|
+
import { useMemo } from "react";
|
|
144
123
|
var useRoute = () => {
|
|
145
124
|
const params = useParams();
|
|
125
|
+
const searchParams = useSearchParams();
|
|
146
126
|
const path = usePathname();
|
|
147
|
-
|
|
127
|
+
const finalParams = useMemo(() => {
|
|
128
|
+
if (!params)
|
|
129
|
+
return null;
|
|
130
|
+
if (Object.keys(params).length !== 0) {
|
|
131
|
+
return params;
|
|
132
|
+
}
|
|
133
|
+
return { ...Object.fromEntries(searchParams.entries()) };
|
|
134
|
+
}, [params, searchParams]);
|
|
135
|
+
return computeRoute(path, finalParams);
|
|
148
136
|
};
|
|
149
137
|
|
|
150
138
|
// src/nextjs/index.tsx
|
|
151
139
|
function SpeedInsights2(props) {
|
|
152
140
|
const route = useRoute();
|
|
153
|
-
return /* @__PURE__ */ React.createElement(SpeedInsights, {
|
|
141
|
+
return /* @__PURE__ */ React.createElement(SpeedInsights, { route, ...props });
|
|
154
142
|
}
|
|
155
143
|
export {
|
|
156
144
|
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 { 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.5\",\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 === 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","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,a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SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","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 if (!setScriptRoute.current) {\n const script = inject(props);\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n } else if (props.route) {\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.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\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 // 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 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, useSearchParams } from 'next/navigation';\nimport { useMemo } from 'react';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): string | null => {\n const params = useParams();\n const searchParams = useSearchParams();\n const path = usePathname();\n\n const finalParams = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be null on pages router\n if (!params) return null;\n if (Object.keys(params).length !== 0) {\n return params;\n }\n // For pages router, we need to use `searchParams` because `params` is an empty object\n return { ...Object.fromEntries(searchParams.entries()) };\n }, [params, searchParams]);\n\n return computeRoute(path, finalParams);\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,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= require("react");
|
|
|
40
40
|
|
|
41
41
|
// package.json
|
|
42
42
|
var name = "@vercel/speed-insights";
|
|
43
|
-
var version = "0.0.1-beta.
|
|
43
|
+
var version = "0.0.1-beta.7";
|
|
44
44
|
|
|
45
45
|
// src/queue.ts
|
|
46
46
|
var initQueue = () => {
|
|
@@ -69,40 +69,17 @@ function isDevelopment() {
|
|
|
69
69
|
return detectEnvironment() === "development";
|
|
70
70
|
}
|
|
71
71
|
function computeRoute(pathname, pathParams) {
|
|
72
|
-
if (pathname
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
if (pathname === "" || !pathParams) {
|
|
72
|
+
if (!pathname || !pathParams) {
|
|
76
73
|
return pathname;
|
|
77
74
|
}
|
|
78
75
|
let result = pathname;
|
|
79
76
|
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
expr = key;
|
|
87
|
-
value = valueOrArray;
|
|
88
|
-
}
|
|
89
|
-
if (!value) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
let start = 0;
|
|
93
|
-
while (start !== -1) {
|
|
94
|
-
start = result.indexOf(`/${value}`, start);
|
|
95
|
-
if (start !== -1) {
|
|
96
|
-
const end = start + value.length + 2;
|
|
97
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
98
|
-
result = `${result.substring(
|
|
99
|
-
0,
|
|
100
|
-
start + 1
|
|
101
|
-
)}[${expr}]${result.substring(end)}`;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
start += value.length + 1;
|
|
105
|
-
}
|
|
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}(?=[/?#]|$)`);
|
|
81
|
+
if (matcher.test(result)) {
|
|
82
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
106
83
|
}
|
|
107
84
|
}
|
|
108
85
|
return result;
|
|
@@ -113,7 +90,7 @@ var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.deb
|
|
|
113
90
|
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
114
91
|
function inject(props) {
|
|
115
92
|
var _a;
|
|
116
|
-
if (!isBrowser())
|
|
93
|
+
if (!isBrowser() || props.route === null)
|
|
117
94
|
return null;
|
|
118
95
|
initQueue();
|
|
119
96
|
if (props.beforeSend) {
|
|
@@ -160,11 +137,12 @@ function inject(props) {
|
|
|
160
137
|
function SpeedInsights(props) {
|
|
161
138
|
const setScriptRoute = (0, import_react.useRef)(null);
|
|
162
139
|
(0, import_react.useEffect)(() => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
140
|
+
if (!setScriptRoute.current) {
|
|
141
|
+
const script = inject(props);
|
|
142
|
+
if (script) {
|
|
143
|
+
setScriptRoute.current = script.setRoute;
|
|
144
|
+
}
|
|
145
|
+
} else if (props.route) {
|
|
168
146
|
setScriptRoute.current(props.route);
|
|
169
147
|
}
|
|
170
148
|
}, [props.route]);
|
package/dist/remix/index.cjs.map
CHANGED
|
@@ -1 +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.5\",\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 === 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","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,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;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A,EACzB;AAEA,SAAO,UAAU,MAAY;AAC3B,UAAM,eAAe,cAAc,IAC/B,+DACA;AAGJ,YAAQ;AAAA,MACN,sDAAsD,GAAG,KAAK,YAAY;AAAA,IAC5E;AAAA,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"]}
|
|
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 if (!setScriptRoute.current) {\n const script = inject(props);\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n } else if (props.route) {\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.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\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 // 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 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,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,aAAa;AACjD,QAAI,QAAQ,KAAK,MAAM,GAAG;AACxB,eAAS,OAAO,QAAQ,SAAS,KAAK,IAAI,GAAG;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;;;ACzCA,IAAM,iBAAiB;AACvB,IAAM,aAAa;AAQnB,SAAS,OAAO,OAEP;AAhBT;AAkBE,MAAI,CA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AAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKnBA,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"]}
|
package/dist/remix/index.d.cts
CHANGED
package/dist/remix/index.d.ts
CHANGED
package/dist/remix/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useEffect, useRef } from "react";
|
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
8
|
var name = "@vercel/speed-insights";
|
|
9
|
-
var version = "0.0.1-beta.
|
|
9
|
+
var version = "0.0.1-beta.7";
|
|
10
10
|
|
|
11
11
|
// src/queue.ts
|
|
12
12
|
var initQueue = () => {
|
|
@@ -35,40 +35,17 @@ function isDevelopment() {
|
|
|
35
35
|
return detectEnvironment() === "development";
|
|
36
36
|
}
|
|
37
37
|
function computeRoute(pathname, pathParams) {
|
|
38
|
-
if (pathname
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
if (pathname === "" || !pathParams) {
|
|
38
|
+
if (!pathname || !pathParams) {
|
|
42
39
|
return pathname;
|
|
43
40
|
}
|
|
44
41
|
let result = pathname;
|
|
45
42
|
for (const [key, valueOrArray] of Object.entries(pathParams)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
expr = key;
|
|
53
|
-
value = valueOrArray;
|
|
54
|
-
}
|
|
55
|
-
if (!value) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
let start = 0;
|
|
59
|
-
while (start !== -1) {
|
|
60
|
-
start = result.indexOf(`/${value}`, start);
|
|
61
|
-
if (start !== -1) {
|
|
62
|
-
const end = start + value.length + 2;
|
|
63
|
-
if (end >= result.length || result[end] === "/" || result[end] === "?" || result[end] === "#") {
|
|
64
|
-
result = `${result.substring(
|
|
65
|
-
0,
|
|
66
|
-
start + 1
|
|
67
|
-
)}[${expr}]${result.substring(end)}`;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
start += value.length + 1;
|
|
71
|
-
}
|
|
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}(?=[/?#]|$)`);
|
|
47
|
+
if (matcher.test(result)) {
|
|
48
|
+
result = result.replace(matcher, `/[${expr}]`);
|
|
72
49
|
}
|
|
73
50
|
}
|
|
74
51
|
return result;
|
|
@@ -79,7 +56,7 @@ var DEV_SCRIPT_URL = `https://va.vercel-scripts.com/v1/speed-insights/script.deb
|
|
|
79
56
|
var SCRIPT_URL = `/_vercel/speed-insights/script.js`;
|
|
80
57
|
function inject(props) {
|
|
81
58
|
var _a;
|
|
82
|
-
if (!isBrowser())
|
|
59
|
+
if (!isBrowser() || props.route === null)
|
|
83
60
|
return null;
|
|
84
61
|
initQueue();
|
|
85
62
|
if (props.beforeSend) {
|
|
@@ -126,11 +103,12 @@ function inject(props) {
|
|
|
126
103
|
function SpeedInsights(props) {
|
|
127
104
|
const setScriptRoute = useRef(null);
|
|
128
105
|
useEffect(() => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
106
|
+
if (!setScriptRoute.current) {
|
|
107
|
+
const script = inject(props);
|
|
108
|
+
if (script) {
|
|
109
|
+
setScriptRoute.current = script.setRoute;
|
|
110
|
+
}
|
|
111
|
+
} else if (props.route) {
|
|
134
112
|
setScriptRoute.current(props.route);
|
|
135
113
|
}
|
|
136
114
|
}, [props.route]);
|
package/dist/remix/index.js.map
CHANGED
|
@@ -1 +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.5\",\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 === 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","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;AACj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AAQ,SAAS;AAEvB,SAAO,oCAAC,iBAAqB,GAAI,SAAS,EAAE,MAAM,GAAK,GAAG,OAAO;AACnE;","names":["SpeedInsights"]}
|
|
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 if (!setScriptRoute.current) {\n const script = inject(props);\n if (script) {\n setScriptRoute.current = script.setRoute;\n }\n } else if (props.route) {\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.7\",\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}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\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 // 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 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,eAA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AAEhC,SAAO;AAAA,IACL,UAAU,CAAC,UAAwB;AACjC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;;;AJjEO,SAAS,cAAc,OAA+C;AAC3E,QAAM,iBAAiB,OAAwC,IAAI;AACnE,YAAU,MAAM;AACd,QAAI,CAAC,eAAe,SAAS;AAC3B,YAAM,SAAS,OAAO,KAAK;AAC3B,UAAI,QAAQ;AACV,uBAAe,UAAU,OAAO;AAAA,MAClC;AAAA,IACF,WAAW,MAAM,OAAO;AACtB,qBAAe,QAAQ,MAAM,KAAK;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,SAAO;AACT;;;AKnBA,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
package/tsup.config.js
CHANGED
|
@@ -10,13 +10,13 @@ const cfg = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export default defineConfig([
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
{
|
|
14
|
+
...cfg,
|
|
15
|
+
entry: {
|
|
16
|
+
index: 'src/generic.ts',
|
|
17
|
+
},
|
|
18
|
+
outDir: 'dist',
|
|
19
|
+
},
|
|
20
20
|
{
|
|
21
21
|
...cfg,
|
|
22
22
|
entry: {
|