svelte-vitals 0.6.0 → 0.7.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/bin.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  knownRuleIds,
7
7
  readPackageVersion,
8
8
  run
9
- } from "./chunk-LWN65ZOR.js";
9
+ } from "./chunk-DVIKLRTP.js";
10
10
 
11
11
  // src/bin.ts
12
12
  import mri from "mri";
@@ -471,6 +471,105 @@ async function collectRoutes(rt, cwd, config = defaultConfig) {
471
471
  };
472
472
  }
473
473
 
474
+ // src/providers/source/a11y.ts
475
+ import { compile } from "svelte/compiler";
476
+ import { defaultConfig as defaultConfig2 } from "@svelte-vitals/core";
477
+
478
+ // src/rules-config.ts
479
+ import { allRules } from "@svelte-vitals/core";
480
+ var KNOWN_IDS = new Set(allRules.map((r) => r.id));
481
+ var A11Y_CODE_PREFIX = "a11y_";
482
+ var A11Y_CATEGORY_KEY = "a11y_category";
483
+ function findUnknownRuleIds(ids) {
484
+ return [
485
+ ...new Set(ids.filter((id) => !KNOWN_IDS.has(id) && !(id.startsWith(A11Y_CODE_PREFIX) && id !== A11Y_CATEGORY_KEY)))
486
+ ];
487
+ }
488
+ function knownRuleIds() {
489
+ return [...KNOWN_IDS].sort();
490
+ }
491
+ function buildRulesConfig(allow, ignore) {
492
+ const rules = {};
493
+ if (allow.length > 0) {
494
+ for (const r of allRules) if (!allow.includes(r.id)) rules[r.id] = "off";
495
+ if (!allow.some((id) => id.startsWith(A11Y_CODE_PREFIX))) rules[A11Y_CATEGORY_KEY] = "off";
496
+ }
497
+ for (const id of ignore) rules[id] = "off";
498
+ return rules;
499
+ }
500
+
501
+ // src/providers/source/a11y.ts
502
+ function firstLine(message) {
503
+ return message.split("\n")[0] ?? message;
504
+ }
505
+ function fileA11y(source, rel) {
506
+ let warnings;
507
+ try {
508
+ ({ warnings } = compile(source, { generate: false, filename: rel }));
509
+ } catch {
510
+ return { ok: false, warnings: [] };
511
+ }
512
+ const out = [];
513
+ for (const w of warnings) {
514
+ if (w.code.startsWith(A11Y_CODE_PREFIX)) {
515
+ out.push({
516
+ code: w.code,
517
+ message: firstLine(w.message),
518
+ line: w.start?.line ?? 0
519
+ });
520
+ }
521
+ }
522
+ return { ok: true, warnings: out };
523
+ }
524
+ async function collectA11y(rt, cwd, config = defaultConfig2) {
525
+ if (config.rules[A11Y_CATEGORY_KEY] === "off") return [];
526
+ const pages = await enumerateRoutePages(rt, cwd);
527
+ const cache = /* @__PURE__ */ new Map();
528
+ const results = [];
529
+ for (const page of pages) {
530
+ const files = await chainFiles(rt, cwd, page);
531
+ const route = deriveRoute(page);
532
+ const fails = [];
533
+ let compiledAll = true;
534
+ for (const { rel } of files) {
535
+ let entry = cache.get(rel);
536
+ if (!entry) {
537
+ const source = await rt.readFile(rt.join(cwd, rel));
538
+ entry = fileA11y(source, rel);
539
+ cache.set(rel, entry);
540
+ }
541
+ if (!entry.ok) compiledAll = false;
542
+ for (const w of entry.warnings) {
543
+ if (config.rules[w.code] === "off") continue;
544
+ fails.push({
545
+ id: w.code,
546
+ category: "a11y",
547
+ severity: "warning",
548
+ detection: { presence: "none", value: "absent" },
549
+ route,
550
+ location: rel,
551
+ ...w.line > 0 ? { line: w.line } : {},
552
+ message: w.message,
553
+ docsUrl: `https://svelte.dev/e/${w.code}`
554
+ });
555
+ }
556
+ }
557
+ if (fails.length > 0) {
558
+ results.push(...fails);
559
+ } else if (compiledAll) {
560
+ results.push({
561
+ id: "a11y",
562
+ category: "a11y",
563
+ severity: "warning",
564
+ detection: { presence: "own", value: "static" },
565
+ route,
566
+ message: "Accessibility"
567
+ });
568
+ }
569
+ }
570
+ return results;
571
+ }
572
+
474
573
  // src/version.ts
475
574
  import { readFileSync } from "fs";
476
575
  function readPackageVersion() {
@@ -511,24 +610,6 @@ function isAutoDetectedGithub(explicit, env = process.env) {
511
610
  return !explicit && !isReporterName(env.SVELTE_VITALS_REPORTER) && !isAgentEnv(env) && isGithubActionsEnv(env);
512
611
  }
513
612
 
514
- // src/rules-config.ts
515
- import { allRules } from "@svelte-vitals/core";
516
- var KNOWN_IDS = new Set(allRules.map((r) => r.id));
517
- function findUnknownRuleIds(ids) {
518
- return [...new Set(ids.filter((id) => !KNOWN_IDS.has(id)))];
519
- }
520
- function knownRuleIds() {
521
- return [...KNOWN_IDS].sort();
522
- }
523
- function buildRulesConfig(allow, ignore) {
524
- const rules = {};
525
- if (allow.length > 0) {
526
- for (const r of allRules) if (!allow.includes(r.id)) rules[r.id] = "off";
527
- }
528
- for (const id of ignore) rules[id] = "off";
529
- return rules;
530
- }
531
-
532
613
  // src/index.ts
533
614
  function routeMatcher(glob) {
534
615
  if (!glob) return () => true;
@@ -552,7 +633,9 @@ async function analyzeProject(opts = {}) {
552
633
  const images = collected.images.filter((i) => matches(i.route));
553
634
  const project = await collectProjectFacts(rt, cwd);
554
635
  const rules = selectRules(allRules2, config);
555
- const results = applyRuleSeverities(await runRules(rules, { heads, images, project, config }), config);
636
+ const a11y = (await collectA11y(rt, cwd, config)).filter((r) => r.route === void 0 || matches(r.route));
637
+ const ruleResults = await runRules(rules, { heads, images, project, config });
638
+ const results = applyRuleSeverities([...ruleResults, ...a11y], config);
556
639
  return { results, config, version: readPackageVersion() };
557
640
  }
558
641
  async function run(opts = {}) {
@@ -612,11 +695,11 @@ async function run(opts = {}) {
612
695
 
613
696
  export {
614
697
  ProjectError,
615
- readPackageVersion,
616
- isReporterName,
617
698
  findUnknownRuleIds,
618
699
  knownRuleIds,
619
700
  buildRulesConfig,
701
+ readPackageVersion,
702
+ isReporterName,
620
703
  routeMatcher,
621
704
  analyzeProject,
622
705
  run
package/dist/index.d.ts CHANGED
@@ -16,6 +16,10 @@ declare function knownRuleIds(): string[];
16
16
  * (--ignore). An allow-list disables every rule not listed; deny always wins.
17
17
  * Callers should reject unknown ids first (see findUnknownRuleIds) so a typo in
18
18
  * --rules can't silently disable every rule.
19
+ *
20
+ * When the allow-list is non-empty and contains no `a11y_*` entries, the
21
+ * `A11Y_CATEGORY_KEY` sentinel is set to `'off'`; `collectA11y` checks this key
22
+ * to suppress the entire Accessibility category.
19
23
  */
20
24
  declare function buildRulesConfig(allow: string[], ignore: string[]): Record<string, RuleSetting>;
21
25
 
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  knownRuleIds,
7
7
  routeMatcher,
8
8
  run
9
- } from "./chunk-LWN65ZOR.js";
9
+ } from "./chunk-DVIKLRTP.js";
10
10
  export {
11
11
  ProjectError,
12
12
  analyzeProject,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-vitals",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A SvelteKit SEO checker — not a runtime Web Vitals reporter. Static analysis of your routes' head metadata.",
5
5
  "type": "module",
6
6
  "license": "MIT",