@svelte-vitals/vite 0.9.2 → 0.10.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/index.js +39 -6
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
// src/plugin.ts
|
|
6
6
|
import { existsSync } from "fs";
|
|
7
7
|
import { writeFile, mkdir } from "fs/promises";
|
|
8
|
-
import { join as
|
|
8
|
+
import { join as join4, isAbsolute, dirname } from "path";
|
|
9
9
|
import { defineConfig as defineConfig2 } from "@svelte-vitals/core";
|
|
10
10
|
|
|
11
11
|
// src/analyze.ts
|
|
@@ -97,6 +97,37 @@ async function collectRenderedProject(cwd, htmlLang) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
// src/providers/source/components.ts
|
|
101
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
102
|
+
import { join as join3 } from "path";
|
|
103
|
+
import { glob as glob2 } from "tinyglobby";
|
|
104
|
+
import { parseComponentFacts } from "@svelte-vitals/core";
|
|
105
|
+
async function collectComponentFacts(root) {
|
|
106
|
+
const files = await glob2("src/**/*.svelte", { cwd: root, dot: false });
|
|
107
|
+
return Promise.all(
|
|
108
|
+
files.sort().map(async (rel) => {
|
|
109
|
+
try {
|
|
110
|
+
const source = await readFile3(join3(root, rel), "utf8");
|
|
111
|
+
return { file: rel, ...parseComponentFacts(source, rel) };
|
|
112
|
+
} catch {
|
|
113
|
+
return {
|
|
114
|
+
file: rel,
|
|
115
|
+
eachBlocks: [],
|
|
116
|
+
effects: [],
|
|
117
|
+
htmlTags: [],
|
|
118
|
+
javascriptUrls: [],
|
|
119
|
+
loc: 0,
|
|
120
|
+
propCount: 0,
|
|
121
|
+
imports: [],
|
|
122
|
+
namespaceImports: [],
|
|
123
|
+
constableStates: [],
|
|
124
|
+
suppressions: []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
100
131
|
// src/version.ts
|
|
101
132
|
import { readFileSync } from "fs";
|
|
102
133
|
function readPackageVersion() {
|
|
@@ -118,14 +149,16 @@ async function analyze(prerenderPagesDir, cwd, options) {
|
|
|
118
149
|
});
|
|
119
150
|
const { heads, headings, images, htmlLang } = await collectRenderedHeads(prerenderPagesDir);
|
|
120
151
|
const project = await collectRenderedProject(cwd, htmlLang);
|
|
152
|
+
const components = await collectComponentFacts(cwd);
|
|
121
153
|
const results = applyRuleSeverities(
|
|
122
|
-
await runRules(selectRules(allRules, config), { heads, headings, images, project, config }),
|
|
154
|
+
await runRules(selectRules(allRules, config), { heads, headings, images, project, components, config }),
|
|
123
155
|
config
|
|
124
156
|
);
|
|
125
157
|
const { score } = computeScore(results, config);
|
|
126
158
|
const summary = summarize(results, config);
|
|
127
159
|
const failed = hasFailureAtOrAbove(summary, config.failOn);
|
|
128
|
-
const coverageNote = `Analyzed ${heads.length} prerendered route(s). SSR/dynamic routes are not covered \u2014 run \`npx svelte-vitals\` for those
|
|
160
|
+
const coverageNote = `Analyzed ${heads.length} prerendered route(s). SSR/dynamic routes are not covered \u2014 run \`npx svelte-vitals\` for those.
|
|
161
|
+
Scanned ${components.length} component(s) under src/ for Correctness/Security/Architecture/Bundle findings.`;
|
|
129
162
|
const consoleReport = formatConsoleReport(results, config, { mode: "rendered / plugin" }) + "\n" + coverageNote + "\n";
|
|
130
163
|
const jsonReport = formatJsonReport(results, config, { version: readPackageVersion() });
|
|
131
164
|
return {
|
|
@@ -254,8 +287,8 @@ function svelteVitals(options = {}) {
|
|
|
254
287
|
if (!options.cwd) root = config.root;
|
|
255
288
|
},
|
|
256
289
|
async closeBundle() {
|
|
257
|
-
const pagesDir = options.prerenderDir ? options.prerenderDir :
|
|
258
|
-
const resolved = isAbsolute(pagesDir) ? pagesDir :
|
|
290
|
+
const pagesDir = options.prerenderDir ? options.prerenderDir : join4(root, DEFAULT_PRERENDER_DIR);
|
|
291
|
+
const resolved = isAbsolute(pagesDir) ? pagesDir : join4(root, pagesDir);
|
|
259
292
|
if (!existsSync(resolved)) return;
|
|
260
293
|
let result;
|
|
261
294
|
try {
|
|
@@ -270,7 +303,7 @@ function svelteVitals(options = {}) {
|
|
|
270
303
|
console.log(out);
|
|
271
304
|
}
|
|
272
305
|
if (options.outFile) {
|
|
273
|
-
const outPath = isAbsolute(options.outFile) ? options.outFile :
|
|
306
|
+
const outPath = isAbsolute(options.outFile) ? options.outFile : join4(root, options.outFile);
|
|
274
307
|
await mkdir(dirname(outPath), { recursive: true });
|
|
275
308
|
await writeFile(outPath, result.jsonReport);
|
|
276
309
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svelte-vitals/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Vite/SvelteKit plugin for svelte-vitals — analyzes prerendered HTML during vite build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"esm-env": "^1.2.2",
|
|
43
|
-
"node-html-parser": "^
|
|
43
|
+
"node-html-parser": "^8.0.4",
|
|
44
44
|
"tinyglobby": "^0.2.17",
|
|
45
|
-
"@svelte-vitals/core": "0.
|
|
45
|
+
"@svelte-vitals/core": "0.19.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@sveltejs/kit": "^2.
|
|
49
|
-
"vite": "^8.1.
|
|
48
|
+
"@sveltejs/kit": "^2.69.0",
|
|
49
|
+
"vite": "^8.1.3"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"@sveltejs/kit": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@sveltejs/kit": "^2.
|
|
58
|
-
"@types/node": "^24.
|
|
59
|
-
"svelte": "^5.56.
|
|
60
|
-
"vite": "^8.1.
|
|
57
|
+
"@sveltejs/kit": "^2.69.0",
|
|
58
|
+
"@types/node": "^24.13.2",
|
|
59
|
+
"svelte": "^5.56.4",
|
|
60
|
+
"vite": "^8.1.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsup",
|