@svelte-vitals/vite 0.14.0 → 0.15.1

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { TreatDynamicAs, RuleSetting, Severity } from '@svelte-vitals/core';
2
+ import { TreatDynamicAs, RuleSetting, Severity, Category } from '@svelte-vitals/core';
3
3
 
4
4
  interface SvelteVitalsOptions {
5
5
  /** Project root (defaults to the Vite config root / cwd). */
@@ -9,6 +9,8 @@ interface SvelteVitalsOptions {
9
9
  rules?: Record<string, RuleSetting>;
10
10
  /** Minimum severity that fails the build (default: 'critical'). */
11
11
  failOn?: Severity;
12
+ /** Per-category weights for the combined Health score shown in the JSON/console report (flag > config file > default 1 each). */
13
+ weights?: Partial<Record<Category, number>>;
12
14
  /** Report output (default: 'console'). */
13
15
  report?: 'console' | 'json' | false;
14
16
  /** Write the JSON report to this path. */
package/dist/index.js CHANGED
@@ -7,8 +7,9 @@ import {
7
7
  // src/plugin.ts
8
8
  import { existsSync } from "fs";
9
9
  import { writeFile, mkdir } from "fs/promises";
10
- import { join as join4, isAbsolute, dirname, relative, basename, sep } from "path";
10
+ import { join as join4, isAbsolute, dirname, relative as relative2, basename, sep as sep2 } from "path";
11
11
  import { defineConfig as defineConfig2 } from "@svelte-vitals/core";
12
+ import { loadConfigFile as loadConfigFile2 } from "svelte-vitals";
12
13
 
13
14
  // src/analyze.ts
14
15
  import {
@@ -23,6 +24,7 @@ import {
23
24
  formatJsonReport,
24
25
  defineConfig
25
26
  } from "@svelte-vitals/core";
27
+ import { loadConfigFile } from "svelte-vitals";
26
28
 
27
29
  // src/providers/rendered/collect.ts
28
30
  import { readFile } from "fs/promises";
@@ -143,11 +145,16 @@ function readCoreVersion() {
143
145
 
144
146
  // src/analyze.ts
145
147
  async function analyze(prerenderPagesDir, cwd, options) {
148
+ const loaded = await loadConfigFile(cwd);
149
+ const fileConfig = loaded?.config;
150
+ const warnings = loaded?.warnings ?? [];
151
+ const weights = options.weights ?? fileConfig?.weights;
146
152
  const config = defineConfig({
147
- treatDynamicAs: options.treatDynamicAs ?? "pass",
148
- metaComponents: options.metaComponents ?? [],
149
- rules: options.rules ?? {},
150
- failOn: options.failOn ?? "critical"
153
+ treatDynamicAs: options.treatDynamicAs ?? fileConfig?.treatDynamicAs ?? "pass",
154
+ metaComponents: options.metaComponents ?? fileConfig?.metaComponents ?? [],
155
+ rules: options.rules ?? fileConfig?.rules ?? {},
156
+ failOn: options.failOn ?? fileConfig?.failOn ?? "critical",
157
+ ...weights !== void 0 ? { weights } : {}
151
158
  });
152
159
  const { heads, headings, images, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
153
160
  const project = await collectRenderedProject(cwd, htmlLang);
@@ -171,7 +178,8 @@ Scanned ${components.length} component(s) under src/ for Correctness/Security/Ar
171
178
  jsonReport,
172
179
  routeCount: heads.length,
173
180
  failed,
174
- failOn: config.failOn
181
+ failOn: config.failOn,
182
+ warnings
175
183
  };
176
184
  }
177
185
 
@@ -921,9 +929,11 @@ function createStore() {
921
929
  }
922
930
 
923
931
  // src/ui/analysis.ts
932
+ import { relative, sep } from "path";
924
933
  function createAnalysisRunner(opts) {
925
934
  const debounceMs = opts.debounceMs ?? 500;
926
935
  let cachedAnalyze = opts.analyze;
936
+ const parseCache = /* @__PURE__ */ new Map();
927
937
  let stopped = false;
928
938
  let running = false;
929
939
  let pending = false;
@@ -946,7 +956,8 @@ function createAnalysisRunner(opts) {
946
956
  treatDynamicAs: opts.treatDynamicAs,
947
957
  metaComponents: opts.metaComponents,
948
958
  rules: opts.rules,
949
- failOn: opts.failOn
959
+ failOn: opts.failOn,
960
+ parseCache
950
961
  });
951
962
  if (!stopped) opts.onResults(results);
952
963
  } catch (err) {
@@ -965,8 +976,10 @@ function createAnalysisRunner(opts) {
965
976
  if (stopped) return;
966
977
  void runOnce();
967
978
  },
968
- notifyChange() {
979
+ notifyChange(file) {
969
980
  if (stopped) return;
981
+ const rel = relative(opts.root, file).split(sep).join("/");
982
+ parseCache.delete(rel);
970
983
  if (timer !== void 0) clearTimeout(timer);
971
984
  timer = setTimeout(() => {
972
985
  timer = void 0;
@@ -996,9 +1009,9 @@ var CONFIG_BASENAMES = /* @__PURE__ */ new Set([
996
1009
  ]);
997
1010
  var IGNORED_SEGMENTS = /* @__PURE__ */ new Set(["node_modules", ".svelte-kit", "build", "dist"]);
998
1011
  function isRelevant(file, root) {
999
- const rel = relative(root, file);
1012
+ const rel = relative2(root, file);
1000
1013
  if (rel === "" || rel.startsWith("..")) return false;
1001
- const segments = rel.split(sep);
1014
+ const segments = rel.split(sep2);
1002
1015
  if (segments.some((s) => IGNORED_SEGMENTS.has(s))) return false;
1003
1016
  if (CONFIG_BASENAMES.has(basename(file))) return true;
1004
1017
  return segments[0] === "src" || segments[0] === "static";
@@ -1024,6 +1037,7 @@ function svelteVitals(options = {}) {
1024
1037
  console.warn(`svelte-vitals: skipped \u2014 analysis failed: ${err instanceof Error ? err.message : String(err)}`);
1025
1038
  return;
1026
1039
  }
1040
+ for (const w of result.warnings) console.warn(`svelte-vitals: ${w}`);
1027
1041
  if (result.routeCount === 0) return;
1028
1042
  if (options.report !== false) {
1029
1043
  const out = options.report === "json" ? result.jsonReport : result.consoleReport;
@@ -1043,16 +1057,21 @@ function svelteVitals(options = {}) {
1043
1057
  const uiPlugin = {
1044
1058
  name: "svelte-vitals:ui",
1045
1059
  apply: "serve",
1046
- configureServer(server) {
1060
+ async configureServer(server) {
1047
1061
  process.env.SVELTE_VITALS_UI = "1";
1062
+ const uiRoot = options.cwd ?? server.config.root;
1063
+ const loaded = await loadConfigFile2(uiRoot);
1064
+ const fileConfig = loaded?.config;
1065
+ for (const w of loaded?.warnings ?? []) console.warn(`svelte-vitals: ${w}`);
1066
+ const weights = options.weights ?? fileConfig?.weights;
1048
1067
  const config = defineConfig2({
1049
- treatDynamicAs: options.treatDynamicAs ?? "pass",
1050
- metaComponents: options.metaComponents ?? [],
1051
- rules: options.rules ?? {},
1052
- failOn: options.failOn ?? "critical"
1068
+ treatDynamicAs: options.treatDynamicAs ?? fileConfig?.treatDynamicAs ?? "pass",
1069
+ metaComponents: options.metaComponents ?? fileConfig?.metaComponents ?? [],
1070
+ rules: options.rules ?? fileConfig?.rules ?? {},
1071
+ failOn: options.failOn ?? fileConfig?.failOn ?? "critical",
1072
+ ...weights !== void 0 ? { weights } : {}
1053
1073
  });
1054
1074
  const store = createStore();
1055
- const uiRoot = options.cwd ?? server.config.root;
1056
1075
  const runner = createAnalysisRunner({
1057
1076
  root: uiRoot,
1058
1077
  treatDynamicAs: options.treatDynamicAs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-vitals/vite",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "description": "Vite/SvelteKit plugin for svelte-vitals — analyzes prerendered HTML during vite build.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,8 +42,8 @@
42
42
  "esm-env": "^1.2.2",
43
43
  "node-html-parser": "^9.0.0",
44
44
  "tinyglobby": "^0.2.17",
45
- "@svelte-vitals/core": "0.23.0",
46
- "svelte-vitals": "0.24.0"
45
+ "@svelte-vitals/core": "0.24.0",
46
+ "svelte-vitals": "0.26.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@sveltejs/kit": "^2.69.2",
@@ -57,6 +57,7 @@
57
57
  "devDependencies": {
58
58
  "@sveltejs/kit": "^2.69.2",
59
59
  "@types/node": "^24.13.3",
60
+ "jsdom": "^29.1.1",
60
61
  "svelte": "^5.56.4",
61
62
  "vite": "^8.1.4"
62
63
  },