@a.incantalupo/web-tools 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit/lighthouse.js +8 -5
- package/dist/refs/images.js +17 -2
- package/package.json +20 -5
package/dist/audit/lighthouse.js
CHANGED
|
@@ -16,11 +16,14 @@ const METRICS = {
|
|
|
16
16
|
speedIndexMs: "speed-index",
|
|
17
17
|
ttfbMs: "server-response-time",
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The LCP element, from Lighthouse 13's "LCP breakdown" insight: a list whose items are
|
|
21
|
+
* the subparts table and the element's node (`type: "node"`).
|
|
22
|
+
*/
|
|
20
23
|
function lcpElementOf(details) {
|
|
21
|
-
const
|
|
22
|
-
[];
|
|
23
|
-
const node =
|
|
24
|
+
const items = details
|
|
25
|
+
?.items ?? [];
|
|
26
|
+
const node = items.find((i) => i?.type === "node");
|
|
24
27
|
if (!node?.selector && !node?.snippet)
|
|
25
28
|
return null;
|
|
26
29
|
const snippet = (node.snippet ?? "").replace(/\s+/g, " ");
|
|
@@ -148,7 +151,7 @@ export async function runLighthouse(urls, outDir, times = 1) {
|
|
|
148
151
|
error: lhr.runtimeError?.message ?? metricError ?? null,
|
|
149
152
|
reportFile,
|
|
150
153
|
screenshot,
|
|
151
|
-
lcpElement: lcpElementOf(lhr.audits["
|
|
154
|
+
lcpElement: lcpElementOf(lhr.audits["lcp-breakdown-insight"]?.details),
|
|
152
155
|
},
|
|
153
156
|
});
|
|
154
157
|
}
|
package/dist/refs/images.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// warnings as a count; --json: the same as JSON; --full: every finding (the default).
|
|
10
10
|
//
|
|
11
11
|
// Fails (exit 1) on what is always wrong: an image that didn't load, or a lazy-loaded
|
|
12
|
-
// largest image (LCP). Warns on what is usually wrong: a file much larger than its slot,
|
|
12
|
+
// largest image (LCP) that the page doesn't preload for that screen. Warns on what is usually wrong: a file much larger than its slot,
|
|
13
13
|
// a photo stretched past its pixels, images over the budget (KB) before any scroll.
|
|
14
14
|
import { chromium } from "playwright-core";
|
|
15
15
|
import { homedir } from "node:os";
|
|
@@ -72,9 +72,24 @@ for (const url of urls) {
|
|
|
72
72
|
new PerformanceObserver((list) => {
|
|
73
73
|
const entry = list.getEntries().at(-1);
|
|
74
74
|
const el = entry?.element;
|
|
75
|
+
// A lazy image the page preloads for this screen is fetched from the head
|
|
76
|
+
// on, not late: a first row that is on screen only from two columns up
|
|
77
|
+
// (lazy for phones, `<link rel="preload" media="(min-width: ...)">`).
|
|
78
|
+
const preloaded = (img) => [
|
|
79
|
+
...document.querySelectorAll('link[rel="preload"][as="image"]'),
|
|
80
|
+
].some((link) => (!link.media || matchMedia(link.media).matches) &&
|
|
81
|
+
[
|
|
82
|
+
link.getAttribute("href") ?? "",
|
|
83
|
+
...(link.getAttribute("imagesrcset") ?? "")
|
|
84
|
+
.split(",")
|
|
85
|
+
.map((candidate) => candidate.trim().split(/\s+/)[0]),
|
|
86
|
+
].some((file) => file !== "" &&
|
|
87
|
+
new URL(file, location.href).href === img.currentSrc));
|
|
75
88
|
done(el
|
|
76
89
|
? {
|
|
77
|
-
lazy: el instanceof HTMLImageElement &&
|
|
90
|
+
lazy: el instanceof HTMLImageElement &&
|
|
91
|
+
el.loading === "lazy" &&
|
|
92
|
+
!preloaded(el),
|
|
78
93
|
what: el instanceof HTMLImageElement
|
|
79
94
|
? `image ${(entry?.url ?? "").split("/").pop()}`
|
|
80
95
|
: `text <${el.tagName.toLowerCase()}>`,
|
package/package.json
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a.incantalupo/web-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Checks and captures for any website: readability and contrast, screenshots, style snapshots and diffs, glyph and image checks, a site audit with niche profiles, your own signed-in browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"stack-tools": "dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./audit": {
|
|
15
|
+
"types": "./dist/audit/index.d.ts",
|
|
16
|
+
"default": "./dist/audit/index.js"
|
|
17
|
+
}
|
|
12
18
|
},
|
|
13
|
-
"files": [
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
14
23
|
"license": "MIT",
|
|
24
|
+
"engines": { "node": ">=22.19" },
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Alessandro-Incantalupo/web-stack-kb.git",
|
|
28
|
+
"directory": "tools/web-tools"
|
|
29
|
+
},
|
|
15
30
|
"scripts": {
|
|
16
31
|
"build": "rm -rf dist && tsc -p tsconfig.json && chmod +x dist/cli.js",
|
|
17
32
|
"check": "tsc -p tsconfig.json --noEmit",
|
|
@@ -20,7 +35,7 @@
|
|
|
20
35
|
"dependencies": {
|
|
21
36
|
"cheerio": "^1.1.0",
|
|
22
37
|
"chrome-launcher": "^1.2.0",
|
|
23
|
-
"lighthouse": "^
|
|
38
|
+
"lighthouse": "^13.6.0",
|
|
24
39
|
"playwright-core": "1.56.1"
|
|
25
40
|
},
|
|
26
41
|
"devDependencies": {
|