@svelte-vitals/vite 0.21.1 → 0.23.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 +93 -11
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -8,8 +8,15 @@ import {
|
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
9
|
import { writeFile, mkdir } from "fs/promises";
|
|
10
10
|
import { join as join4, isAbsolute, dirname, relative as relative3, basename, sep as sep2 } from "path";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import {
|
|
12
|
+
CATEGORIES as CATEGORIES2,
|
|
13
|
+
defaultConfig,
|
|
14
|
+
defineConfig as defineConfig2,
|
|
15
|
+
resolveRuleOptions,
|
|
16
|
+
shouldSkipRangeCheck,
|
|
17
|
+
validateRuleSetting
|
|
18
|
+
} from "@svelte-vitals/core";
|
|
19
|
+
import { findUnknownRuleIds, knownRuleIds, loadConfigFile as loadConfigFile2, ruleOptionsSpec } from "svelte-vitals";
|
|
13
20
|
|
|
14
21
|
// src/analyze.ts
|
|
15
22
|
import {
|
|
@@ -68,7 +75,14 @@ async function collectRenderedHeads(prerenderPagesDir) {
|
|
|
68
75
|
// src/providers/rendered/project.ts
|
|
69
76
|
import { access, readFile as readFile2 } from "fs/promises";
|
|
70
77
|
import { join as join2 } from "path";
|
|
71
|
-
import {
|
|
78
|
+
import {
|
|
79
|
+
ROBOTS_SOURCE_PATHS,
|
|
80
|
+
SITEMAP_SOURCE_PATHS,
|
|
81
|
+
SVELTE_CONFIG_FILES,
|
|
82
|
+
VITE_CONFIG_FILES,
|
|
83
|
+
resolveKitAliases,
|
|
84
|
+
resolveKitPathsBase
|
|
85
|
+
} from "@svelte-vitals/core";
|
|
72
86
|
async function exists(path) {
|
|
73
87
|
try {
|
|
74
88
|
await access(path);
|
|
@@ -88,17 +102,35 @@ async function robotsRefsSitemap(cwd) {
|
|
|
88
102
|
return void 0;
|
|
89
103
|
}
|
|
90
104
|
}
|
|
105
|
+
async function readFirstConfig(cwd, files) {
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
const path = join2(cwd, file);
|
|
108
|
+
if (!await exists(path)) continue;
|
|
109
|
+
try {
|
|
110
|
+
return { file, source: await readFile2(path, "utf8") };
|
|
111
|
+
} catch {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
91
117
|
async function collectRenderedProject(cwd, htmlLang) {
|
|
92
|
-
const [hasRobotsTxt, hasSitemap] = await Promise.all([
|
|
118
|
+
const [hasRobotsTxt, hasSitemap, viteConfig, svelteConfig] = await Promise.all([
|
|
93
119
|
existsAny(cwd, ROBOTS_SOURCE_PATHS),
|
|
94
|
-
existsAny(cwd, SITEMAP_SOURCE_PATHS)
|
|
120
|
+
existsAny(cwd, SITEMAP_SOURCE_PATHS),
|
|
121
|
+
readFirstConfig(cwd, VITE_CONFIG_FILES),
|
|
122
|
+
readFirstConfig(cwd, SVELTE_CONFIG_FILES)
|
|
95
123
|
]);
|
|
96
124
|
const robotsReferencesSitemap = await robotsRefsSitemap(cwd);
|
|
125
|
+
const kitPathsBase = resolveKitPathsBase(viteConfig, svelteConfig);
|
|
126
|
+
const kitAliases = resolveKitAliases(viteConfig, svelteConfig);
|
|
97
127
|
return {
|
|
98
128
|
hasRobotsTxt,
|
|
99
129
|
hasSitemap,
|
|
100
130
|
htmlLang,
|
|
101
|
-
...robotsReferencesSitemap !== void 0 ? { robotsReferencesSitemap } : {}
|
|
131
|
+
...robotsReferencesSitemap !== void 0 ? { robotsReferencesSitemap } : {},
|
|
132
|
+
...kitPathsBase ? { kitPathsBase } : {},
|
|
133
|
+
...kitAliases ? { kitAliases } : {}
|
|
102
134
|
};
|
|
103
135
|
}
|
|
104
136
|
|
|
@@ -108,7 +140,8 @@ import { join as join3 } from "path";
|
|
|
108
140
|
import { glob as glob2 } from "tinyglobby";
|
|
109
141
|
import {
|
|
110
142
|
collectComponentFacts as collect,
|
|
111
|
-
collectKitModuleFacts as collectKit
|
|
143
|
+
collectKitModuleFacts as collectKit,
|
|
144
|
+
collectSourceFiles as collectFiles
|
|
112
145
|
} from "@svelte-vitals/core";
|
|
113
146
|
var nodeRuntime = {
|
|
114
147
|
readFile: (path) => readFile3(path, "utf8"),
|
|
@@ -126,8 +159,11 @@ var nodeRuntime = {
|
|
|
126
159
|
function collectComponentFacts(root) {
|
|
127
160
|
return collect(nodeRuntime, root);
|
|
128
161
|
}
|
|
129
|
-
function collectKitModuleFacts(root) {
|
|
130
|
-
return collectKit(nodeRuntime, root);
|
|
162
|
+
function collectKitModuleFacts(root, aliases) {
|
|
163
|
+
return collectKit(nodeRuntime, root, aliases);
|
|
164
|
+
}
|
|
165
|
+
function collectSourceFiles(root) {
|
|
166
|
+
return collectFiles(nodeRuntime, root);
|
|
131
167
|
}
|
|
132
168
|
|
|
133
169
|
// src/version.ts
|
|
@@ -171,7 +207,8 @@ async function analyze(prerenderPagesDir, cwd, options, extraProjectFacts) {
|
|
|
171
207
|
...extraProjectFacts
|
|
172
208
|
};
|
|
173
209
|
const components = await collectComponentFacts(cwd);
|
|
174
|
-
const kitModules = await collectKitModuleFacts(cwd);
|
|
210
|
+
const kitModules = await collectKitModuleFacts(cwd, project.kitAliases);
|
|
211
|
+
const sourceFiles = await collectSourceFiles(cwd);
|
|
175
212
|
const results = applyOverrides(
|
|
176
213
|
applyRuleSeverities(
|
|
177
214
|
await runRules(selectRules(allRules, config), {
|
|
@@ -181,7 +218,8 @@ async function analyze(prerenderPagesDir, cwd, options, extraProjectFacts) {
|
|
|
181
218
|
project,
|
|
182
219
|
components,
|
|
183
220
|
config,
|
|
184
|
-
kitModules
|
|
221
|
+
kitModules,
|
|
222
|
+
sourceFiles
|
|
185
223
|
}),
|
|
186
224
|
config
|
|
187
225
|
),
|
|
@@ -510,7 +548,51 @@ function isRelevant(file, root) {
|
|
|
510
548
|
return segments[0] === "src" || segments[0] === "static";
|
|
511
549
|
}
|
|
512
550
|
var DEFAULT_PRERENDER_DIR = ".svelte-kit/output/prerendered/pages";
|
|
551
|
+
function validateRulesOption(rules) {
|
|
552
|
+
if (!rules) return;
|
|
553
|
+
const unknown = findUnknownRuleIds(Object.keys(rules));
|
|
554
|
+
if (unknown.length > 0) {
|
|
555
|
+
throw new Error(
|
|
556
|
+
`svelte-vitals: invalid \`rules\` option \u2014 unknown rule id(s): ${unknown.join(", ")}. Known rule ids: ${knownRuleIds().join(", ")}`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
const errors = [];
|
|
560
|
+
for (const [id, setting] of Object.entries(rules)) {
|
|
561
|
+
errors.push(...validateRuleSetting(`rules.${id}`, id, setting, ruleOptionsSpec(id), { allowOptions: true }));
|
|
562
|
+
}
|
|
563
|
+
if (errors.length > 0) throw new Error(`svelte-vitals: invalid \`rules\` option \u2014 ${errors.join(" ")}`);
|
|
564
|
+
}
|
|
565
|
+
function validateOverridesOption(overrides, rules) {
|
|
566
|
+
if (!overrides) return;
|
|
567
|
+
const rulesLayerKnown = rules !== void 0;
|
|
568
|
+
const baseConfig = { ...defaultConfig, rules: rules ?? {} };
|
|
569
|
+
const errors = [];
|
|
570
|
+
overrides.forEach((entry, i) => {
|
|
571
|
+
const entryRules = entry.rules ?? {};
|
|
572
|
+
const nonCategoryKeys = Object.keys(entryRules).filter((k) => !CATEGORIES2.includes(k));
|
|
573
|
+
const unknown = findUnknownRuleIds(nonCategoryKeys);
|
|
574
|
+
if (unknown.length > 0) {
|
|
575
|
+
throw new Error(
|
|
576
|
+
`svelte-vitals: invalid \`overrides\` option \u2014 overrides[${i}]: unknown rule id(s) or categories: ${unknown.join(", ")}. Known categories: ${CATEGORIES2.join(", ")}. Known rule ids: ${knownRuleIds().join(", ")}`
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
for (const [key, setting] of Object.entries(entryRules)) {
|
|
580
|
+
const isCategory = CATEGORIES2.includes(key);
|
|
581
|
+
const baseline = isCategory ? void 0 : resolveRuleOptions(key, ruleOptionsSpec(key), baseConfig);
|
|
582
|
+
errors.push(
|
|
583
|
+
...validateRuleSetting(`overrides[${i}].rules.${key}`, key, setting, ruleOptionsSpec(key), {
|
|
584
|
+
allowOptions: !isCategory,
|
|
585
|
+
...baseline !== void 0 ? { baseline } : {},
|
|
586
|
+
skipRangeCheck: !rulesLayerKnown || shouldSkipRangeCheck(overrides, i, key, setting)
|
|
587
|
+
})
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
if (errors.length > 0) throw new Error(`svelte-vitals: invalid \`overrides\` option \u2014 ${errors.join(" ")}`);
|
|
592
|
+
}
|
|
513
593
|
function svelteVitals(options = {}) {
|
|
594
|
+
validateRulesOption(options.rules);
|
|
595
|
+
validateOverridesOption(options.overrides, options.rules);
|
|
514
596
|
let root = options.cwd ?? process.cwd();
|
|
515
597
|
let minifyFlag;
|
|
516
598
|
const buildPlugin = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svelte-vitals/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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,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": "0.
|
|
46
|
-
"@svelte-vitals/core": "0.
|
|
45
|
+
"svelte-vitals": "0.35.0",
|
|
46
|
+
"@svelte-vitals/core": "0.31.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@sveltejs/kit": "^2.70.1",
|
|
@@ -58,11 +58,12 @@
|
|
|
58
58
|
"@sveltejs/kit": "^2.70.1",
|
|
59
59
|
"@types/node": "^24.13.3",
|
|
60
60
|
"jsdom": "^29.1.1",
|
|
61
|
-
"svelte": "^5.56.
|
|
61
|
+
"svelte": "^5.56.8",
|
|
62
62
|
"vite": "^8.1.5"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsup",
|
|
66
|
+
"bench": "node scripts/bench/bench.mjs",
|
|
66
67
|
"typecheck": "tsc --noEmit",
|
|
67
68
|
"test": "vitest run"
|
|
68
69
|
}
|