@svelte-vitals/vite 0.7.0 → 0.9.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.
@@ -45,19 +45,22 @@ function parseHtmlHead(html) {
45
45
  const asAttr = link.getAttribute("as");
46
46
  const hasCrossorigin = link.hasAttribute("crossorigin");
47
47
  const hreflang = link.getAttribute("hreflang");
48
+ const href = link.getAttribute("href");
48
49
  tags.push({
49
50
  kind: "link",
50
51
  rel,
51
52
  presence: "own",
52
- value: attrValue(link.getAttribute("href")),
53
+ value: attrValue(href),
53
54
  ...asAttr != null ? { hasAs: true, as: asAttr } : {},
54
55
  ...hasCrossorigin ? { hasCrossorigin: true } : {},
55
56
  // Keep a literal empty hreflang="" (present-but-invalid) so SEO026 can flag it.
56
- ...hreflang != null ? { hreflang } : {}
57
+ ...hreflang != null ? { hreflang } : {},
58
+ ...href ? { href } : {}
57
59
  });
58
60
  }
59
61
  for (const script of head.querySelectorAll("script")) {
60
- if (script.getAttribute("type") === "application/ld+json") {
62
+ const type = script.getAttribute("type");
63
+ if (type === "application/ld+json") {
61
64
  const raw = script.rawText;
62
65
  tags.push({
63
66
  kind: "jsonld",
@@ -65,6 +68,18 @@ function parseHtmlHead(html) {
65
68
  value: attrValue(raw),
66
69
  ...raw && raw.trim().length > 0 ? { jsonld: raw } : {}
67
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
+ });
68
83
  }
69
84
  }
70
85
  const htmlEl = root.querySelector("html");
@@ -81,7 +96,16 @@ function parseHtmlHead(html) {
81
96
  }
82
97
  };
83
98
  collectHeadings(root.querySelector("body") ?? root);
84
- return { tags, htmlLang, headings };
99
+ const images = (root.querySelector("body") ?? root).querySelectorAll("img").map((img) => ({
100
+ hasWidth: img.hasAttribute("width"),
101
+ hasHeight: img.hasAttribute("height"),
102
+ hasLoading: img.hasAttribute("loading"),
103
+ hasAlt: img.hasAttribute("alt"),
104
+ lazy: img.getAttribute("loading") === "lazy",
105
+ hasSrcset: img.hasAttribute("srcset"),
106
+ line: 0
107
+ }));
108
+ return { tags, htmlLang, headings, images };
85
109
  }
86
110
 
87
111
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseHtmlHead
3
- } from "../chunk-MICKONGB.js";
3
+ } from "../chunk-LIC7DE52.js";
4
4
 
5
5
  // src/hooks/handle.ts
6
6
  import { DEV } from "esm-env";
@@ -63,13 +63,17 @@ 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, headings: levels } = parseHtmlHead(html);
66
+ const { tags, htmlLang, headings: levels, images: imgs } = parseHtmlHead(html);
67
67
  const head = { route, source: "rendered", tags, file: route };
68
68
  const headings = [
69
69
  { route, headings: levels.map((level) => ({ level, line: 0, file: route })) }
70
70
  ];
71
+ const images = [{ route, images: imgs.map((img) => ({ ...img, file: route })) }];
71
72
  const project = { hasRobotsTxt: true, hasSitemap: true, htmlLang };
72
- const results = applyRuleSeverities(await runRules(rules, { heads: [head], headings, project, config }), config);
73
+ const results = applyRuleSeverities(
74
+ await runRules(rules, { heads: [head], headings, images, project, config }),
75
+ config
76
+ );
73
77
  const signature = findingSignature(results, config);
74
78
  if (lastSignature.get(route) === signature) return;
75
79
  lastSignature.set(route, signature);
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseHtmlHead
3
- } from "./chunk-MICKONGB.js";
3
+ } from "./chunk-LIC7DE52.js";
4
4
 
5
5
  // src/plugin.ts
6
6
  import { existsSync } from "fs";
@@ -39,6 +39,7 @@ async function collectRenderedHeads(prerenderPagesDir) {
39
39
  );
40
40
  const heads = [];
41
41
  const headings = [];
42
+ const images = [];
42
43
  let htmlLang = { presence: "none", value: "absent" };
43
44
  for (const { rel, parsed } of parsedFiles) {
44
45
  if (htmlLang.presence === "none" && parsed.htmlLang.presence === "own") htmlLang = parsed.htmlLang;
@@ -54,8 +55,9 @@ async function collectRenderedHeads(prerenderPagesDir) {
54
55
  // Rendered mode does not track source lines (line 0 = unknown); file is the HTML path.
55
56
  headings: parsed.headings.map((level) => ({ level, line: 0, file: rel }))
56
57
  });
58
+ images.push({ route, images: parsed.images.map((img) => ({ ...img, file: rel })) });
57
59
  }
58
- return { heads, headings, htmlLang };
60
+ return { heads, headings, images, htmlLang };
59
61
  }
60
62
 
61
63
  // src/providers/rendered/project.ts
@@ -114,10 +116,10 @@ async function analyze(prerenderPagesDir, cwd, options) {
114
116
  rules: options.rules ?? {},
115
117
  failOn: options.failOn ?? "critical"
116
118
  });
117
- const { heads, headings, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
119
+ const { heads, headings, images, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
118
120
  const project = await collectRenderedProject(cwd, htmlLang);
119
121
  const results = applyRuleSeverities(
120
- await runRules(selectRules(allRules, config), { heads, headings, project, config }),
122
+ await runRules(selectRules(allRules, config), { heads, headings, images, project, config }),
121
123
  config
122
124
  );
123
125
  const { score } = computeScore(results, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-vitals/vite",
3
- "version": "0.7.0",
3
+ "version": "0.9.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.14.0"
45
+ "@svelte-vitals/core": "0.16.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": "^2.0.0",