Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit d6974e2

Browse files
committed
fix: use husky v8 properly
1 parent b1a921d commit d6974e2

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run validate

.huskyrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"check-format": "npm run prettier -- --list-different",
1414
"lint": "eslint --ignore-path .gitignore .",
1515
"check-types": "tsc --pretty",
16-
"validate": "npm run check-types && npm run lint && npm run check-format"
16+
"validate": "npm run check-types && npm run lint && npm run check-format",
17+
"prepare": "husky install"
1718
},
1819
"repository": {
1920
"type": "git",
@@ -82,8 +83,8 @@
8283
"eslint-plugin-no-loops": "^0.3.0",
8384
"eslint-plugin-react": "^7.30.1",
8485
"eslint-plugin-react-hooks": "^4.6.0",
85-
"husky": "^8.0.2",
8686
"prettier": "2.6.2",
87-
"vite": "^3.0.2"
87+
"vite": "^3.0.2",
88+
"husky": "^8.0.0"
8889
}
8990
}

src/vitals.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import { CLSMetric } from "web-vitals";
2-
3-
const vitalsUrl = "https://vitals.vercel-analytics.com/v1/vitals";
4-
5-
function getConnectionSpeed() {
6-
// This line makes all of my tools angry, and I can't find any type definitions for this, so I just got them to ignore it.
7-
// prettier-ignore
8-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
9-
// @ts-ignore
10-
return "connection" in navigator && "effectiveType" in navigator["connection"] ? navigator["connection"]["effectiveType"] : "";
11-
}
12-
13-
export function sendToVercelAnalytics(metric: CLSMetric) {
14-
const analyticsId = import.meta.env.VITE_VERCEL_ANALYTICS_ID;
15-
if (!analyticsId) {
16-
return;
17-
}
18-
19-
const body = {
20-
dsn: analyticsId,
21-
id: metric.id,
22-
page: window.location.pathname,
23-
href: window.location.href,
24-
event_name: metric.name,
25-
value: metric.value.toString(),
26-
speed: getConnectionSpeed(),
27-
};
28-
29-
const blob = new Blob([new URLSearchParams(body).toString()], {
30-
// This content type is necessary for `sendBeacon`
31-
type: "application/x-www-form-urlencoded",
32-
});
33-
if (navigator.sendBeacon) {
34-
navigator.sendBeacon(vitalsUrl, blob);
35-
} else
36-
fetch(vitalsUrl, {
37-
body: blob,
38-
method: "POST",
39-
credentials: "omit",
40-
keepalive: true,
41-
});
42-
}
1+
import { CLSMetric } from "web-vitals";
2+
3+
const vitalsUrl = "https://vitals.vercel-analytics.com/v1/vitals";
4+
5+
function getConnectionSpeed() {
6+
// This line makes all of my tools angry, and I can't find any type definitions for this, so I just got them to ignore it.
7+
// prettier-ignore
8+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
9+
// @ts-ignore
10+
return "connection" in navigator && "effectiveType" in navigator["connection"] ? navigator["connection"]["effectiveType"] : "";
11+
}
12+
13+
export function sendToVercelAnalytics(metric: CLSMetric) {
14+
const analyticsId = import.meta.env.VITE_VERCEL_ANALYTICS_ID;
15+
if (!analyticsId) {
16+
return;
17+
}
18+
19+
const body = {
20+
dsn: analyticsId,
21+
id: metric.id,
22+
page: window.location.pathname,
23+
href: window.location.href,
24+
event_name: metric.name,
25+
value: metric.value.toString(),
26+
speed: getConnectionSpeed(),
27+
};
28+
29+
const blob = new Blob([new URLSearchParams(body).toString()], {
30+
// This content type is necessary for `sendBeacon`
31+
type: "application/x-www-form-urlencoded",
32+
});
33+
if (navigator.sendBeacon) {
34+
navigator.sendBeacon(vitalsUrl, blob);
35+
} else
36+
fetch(vitalsUrl, {
37+
body: blob,
38+
method: "POST",
39+
credentials: "omit",
40+
keepalive: true,
41+
});
42+
}

0 commit comments

Comments
 (0)