@svelte-vitals/vite 0.6.0 → 0.8.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/chunk-VMCOBS2U.js +104 -0
- package/dist/hooks/index.js +6 -3
- package/dist/index.js +12 -5
- package/package.json +2 -2
- package/dist/chunk-GISWUGBL.js +0 -54
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/providers/rendered/parse-html.ts
|
|
2
|
+
import { parse, HTMLElement } from "node-html-parser";
|
|
3
|
+
function attrValue(v) {
|
|
4
|
+
return v !== void 0 && v.trim().length > 0 ? "static" : "absent";
|
|
5
|
+
}
|
|
6
|
+
function parseHtmlHead(html) {
|
|
7
|
+
const root = parse(html);
|
|
8
|
+
const head = root.querySelector("head") ?? root;
|
|
9
|
+
const tags = [];
|
|
10
|
+
const title = head.querySelector("title");
|
|
11
|
+
if (title) {
|
|
12
|
+
const text = title.text;
|
|
13
|
+
tags.push({
|
|
14
|
+
kind: "title",
|
|
15
|
+
presence: "own",
|
|
16
|
+
value: attrValue(text),
|
|
17
|
+
...text && text.trim().length > 0 ? { text } : {}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
for (const meta of head.querySelectorAll("meta")) {
|
|
21
|
+
const name = meta.getAttribute("name");
|
|
22
|
+
const property = meta.getAttribute("property");
|
|
23
|
+
const charset = meta.getAttribute("charset");
|
|
24
|
+
if (charset != null) {
|
|
25
|
+
tags.push({ kind: "meta", name: "charset", presence: "own", value: attrValue(charset) });
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!name && !property) continue;
|
|
29
|
+
const content = name === "robots" ? meta.getAttribute("content") : null;
|
|
30
|
+
const noindex = content != null && /(^|[\s,])(noindex|none)([\s,]|$)/i.test(content);
|
|
31
|
+
const descText = name === "description" ? meta.getAttribute("content") : null;
|
|
32
|
+
tags.push({
|
|
33
|
+
kind: "meta",
|
|
34
|
+
...name ? { name } : {},
|
|
35
|
+
...property ? { property } : {},
|
|
36
|
+
presence: "own",
|
|
37
|
+
value: attrValue(meta.getAttribute("content")),
|
|
38
|
+
...noindex ? { noindex: true } : {},
|
|
39
|
+
...descText && descText.trim().length > 0 ? { text: descText } : {}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
for (const link of head.querySelectorAll("link")) {
|
|
43
|
+
const rel = link.getAttribute("rel");
|
|
44
|
+
if (!rel) continue;
|
|
45
|
+
const asAttr = link.getAttribute("as");
|
|
46
|
+
const hasCrossorigin = link.hasAttribute("crossorigin");
|
|
47
|
+
const hreflang = link.getAttribute("hreflang");
|
|
48
|
+
const href = link.getAttribute("href");
|
|
49
|
+
tags.push({
|
|
50
|
+
kind: "link",
|
|
51
|
+
rel,
|
|
52
|
+
presence: "own",
|
|
53
|
+
value: attrValue(href),
|
|
54
|
+
...asAttr != null ? { hasAs: true, as: asAttr } : {},
|
|
55
|
+
...hasCrossorigin ? { hasCrossorigin: true } : {},
|
|
56
|
+
// Keep a literal empty hreflang="" (present-but-invalid) so SEO026 can flag it.
|
|
57
|
+
...hreflang != null ? { hreflang } : {},
|
|
58
|
+
...href ? { href } : {}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
for (const script of head.querySelectorAll("script")) {
|
|
62
|
+
const type = script.getAttribute("type");
|
|
63
|
+
if (type === "application/ld+json") {
|
|
64
|
+
const raw = script.rawText;
|
|
65
|
+
tags.push({
|
|
66
|
+
kind: "jsonld",
|
|
67
|
+
presence: "own",
|
|
68
|
+
value: attrValue(raw),
|
|
69
|
+
...raw && raw.trim().length > 0 ? { jsonld: raw } : {}
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const src = script.getAttribute("src");
|
|
74
|
+
if (src) {
|
|
75
|
+
const blocking = !script.hasAttribute("defer") && !script.hasAttribute("async") && type !== "module";
|
|
76
|
+
tags.push({
|
|
77
|
+
kind: "script",
|
|
78
|
+
presence: "own",
|
|
79
|
+
value: "static",
|
|
80
|
+
href: src,
|
|
81
|
+
...blocking ? { blocking: true } : {}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const htmlEl = root.querySelector("html");
|
|
86
|
+
const lang = htmlEl?.getAttribute("lang");
|
|
87
|
+
const htmlLang = lang === void 0 || lang === null ? { presence: "none", value: "absent" } : { presence: "own", value: attrValue(lang) };
|
|
88
|
+
const headings = [];
|
|
89
|
+
const collectHeadings = (el) => {
|
|
90
|
+
for (const child of el.childNodes) {
|
|
91
|
+
if (child instanceof HTMLElement) {
|
|
92
|
+
const m = /^h([1-6])$/i.exec(child.rawTagName ?? "");
|
|
93
|
+
if (m) headings.push(Number(m[1]));
|
|
94
|
+
collectHeadings(child);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
collectHeadings(root.querySelector("body") ?? root);
|
|
99
|
+
return { tags, htmlLang, headings };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
parseHtmlHead
|
|
104
|
+
};
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseHtmlHead
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-VMCOBS2U.js";
|
|
4
4
|
|
|
5
5
|
// src/hooks/handle.ts
|
|
6
6
|
import { DEV } from "esm-env";
|
|
@@ -63,10 +63,13 @@ async function postIngest(origin, route, results) {
|
|
|
63
63
|
}
|
|
64
64
|
async function analyzeAndWarn(html, route, origin, rules, config, lastSignature) {
|
|
65
65
|
try {
|
|
66
|
-
const { tags, htmlLang } = parseHtmlHead(html);
|
|
66
|
+
const { tags, htmlLang, headings: levels } = parseHtmlHead(html);
|
|
67
67
|
const head = { route, source: "rendered", tags, file: route };
|
|
68
|
+
const headings = [
|
|
69
|
+
{ route, headings: levels.map((level) => ({ level, line: 0, file: route })) }
|
|
70
|
+
];
|
|
68
71
|
const project = { hasRobotsTxt: true, hasSitemap: true, htmlLang };
|
|
69
|
-
const results = applyRuleSeverities(await runRules(rules, { heads: [head], project, config }), config);
|
|
72
|
+
const results = applyRuleSeverities(await runRules(rules, { heads: [head], headings, project, config }), config);
|
|
70
73
|
const signature = findingSignature(results, config);
|
|
71
74
|
if (lastSignature.get(route) === signature) return;
|
|
72
75
|
lastSignature.set(route, signature);
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseHtmlHead
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VMCOBS2U.js";
|
|
4
4
|
|
|
5
5
|
// src/plugin.ts
|
|
6
6
|
import { existsSync } from "fs";
|
|
@@ -38,17 +38,24 @@ async function collectRenderedHeads(prerenderPagesDir) {
|
|
|
38
38
|
files.map(async (rel) => ({ rel, parsed: parseHtmlHead(await readFile(join(prerenderPagesDir, rel), "utf8")) }))
|
|
39
39
|
);
|
|
40
40
|
const heads = [];
|
|
41
|
+
const headings = [];
|
|
41
42
|
let htmlLang = { presence: "none", value: "absent" };
|
|
42
43
|
for (const { rel, parsed } of parsedFiles) {
|
|
43
44
|
if (htmlLang.presence === "none" && parsed.htmlLang.presence === "own") htmlLang = parsed.htmlLang;
|
|
45
|
+
const route = deriveRouteFromHtmlPath(rel);
|
|
44
46
|
heads.push({
|
|
45
|
-
route
|
|
47
|
+
route,
|
|
46
48
|
source: "rendered",
|
|
47
49
|
tags: parsed.tags,
|
|
48
50
|
file: rel
|
|
49
51
|
});
|
|
52
|
+
headings.push({
|
|
53
|
+
route,
|
|
54
|
+
// Rendered mode does not track source lines (line 0 = unknown); file is the HTML path.
|
|
55
|
+
headings: parsed.headings.map((level) => ({ level, line: 0, file: rel }))
|
|
56
|
+
});
|
|
50
57
|
}
|
|
51
|
-
return { heads, htmlLang };
|
|
58
|
+
return { heads, headings, htmlLang };
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
// src/providers/rendered/project.ts
|
|
@@ -107,10 +114,10 @@ async function analyze(prerenderPagesDir, cwd, options) {
|
|
|
107
114
|
rules: options.rules ?? {},
|
|
108
115
|
failOn: options.failOn ?? "critical"
|
|
109
116
|
});
|
|
110
|
-
const { heads, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
|
|
117
|
+
const { heads, headings, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
|
|
111
118
|
const project = await collectRenderedProject(cwd, htmlLang);
|
|
112
119
|
const results = applyRuleSeverities(
|
|
113
|
-
await runRules(selectRules(allRules, config), { heads, project, config }),
|
|
120
|
+
await runRules(selectRules(allRules, config), { heads, headings, project, config }),
|
|
114
121
|
config
|
|
115
122
|
);
|
|
116
123
|
const { score } = computeScore(results, config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svelte-vitals/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Vite/SvelteKit plugin for svelte-vitals — analyzes prerendered HTML during vite build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"esm-env": "^1.2.2",
|
|
43
43
|
"node-html-parser": "^6.1.13",
|
|
44
44
|
"tinyglobby": "^0.2.17",
|
|
45
|
-
"@svelte-vitals/core": "0.
|
|
45
|
+
"@svelte-vitals/core": "0.15.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": "^2.0.0",
|
package/dist/chunk-GISWUGBL.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// src/providers/rendered/parse-html.ts
|
|
2
|
-
import { parse } from "node-html-parser";
|
|
3
|
-
function attrValue(v) {
|
|
4
|
-
return v !== void 0 && v.trim().length > 0 ? "static" : "absent";
|
|
5
|
-
}
|
|
6
|
-
function parseHtmlHead(html) {
|
|
7
|
-
const root = parse(html);
|
|
8
|
-
const head = root.querySelector("head") ?? root;
|
|
9
|
-
const tags = [];
|
|
10
|
-
const title = head.querySelector("title");
|
|
11
|
-
if (title) tags.push({ kind: "title", presence: "own", value: attrValue(title.text) });
|
|
12
|
-
for (const meta of head.querySelectorAll("meta")) {
|
|
13
|
-
const name = meta.getAttribute("name");
|
|
14
|
-
const property = meta.getAttribute("property");
|
|
15
|
-
if (!name && !property) continue;
|
|
16
|
-
const content = name === "robots" ? meta.getAttribute("content") : null;
|
|
17
|
-
const noindex = content != null && /(^|[\s,])(noindex|none)([\s,]|$)/i.test(content);
|
|
18
|
-
tags.push({
|
|
19
|
-
kind: "meta",
|
|
20
|
-
...name ? { name } : {},
|
|
21
|
-
...property ? { property } : {},
|
|
22
|
-
presence: "own",
|
|
23
|
-
value: attrValue(meta.getAttribute("content")),
|
|
24
|
-
...noindex ? { noindex: true } : {}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
for (const link of head.querySelectorAll("link")) {
|
|
28
|
-
const rel = link.getAttribute("rel");
|
|
29
|
-
if (!rel) continue;
|
|
30
|
-
const asAttr = link.getAttribute("as");
|
|
31
|
-
const hasCrossorigin = link.hasAttribute("crossorigin");
|
|
32
|
-
tags.push({
|
|
33
|
-
kind: "link",
|
|
34
|
-
rel,
|
|
35
|
-
presence: "own",
|
|
36
|
-
value: attrValue(link.getAttribute("href")),
|
|
37
|
-
...asAttr != null ? { hasAs: true, as: asAttr } : {},
|
|
38
|
-
...hasCrossorigin ? { hasCrossorigin: true } : {}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
for (const script of head.querySelectorAll("script")) {
|
|
42
|
-
if (script.getAttribute("type") === "application/ld+json") {
|
|
43
|
-
tags.push({ kind: "jsonld", presence: "own", value: attrValue(script.text) });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const htmlEl = root.querySelector("html");
|
|
47
|
-
const lang = htmlEl?.getAttribute("lang");
|
|
48
|
-
const htmlLang = lang === void 0 || lang === null ? { presence: "none", value: "absent" } : { presence: "own", value: attrValue(lang) };
|
|
49
|
-
return { tags, htmlLang };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export {
|
|
53
|
-
parseHtmlHead
|
|
54
|
-
};
|