@svelte-vitals/vite 0.21.0 → 0.22.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 +79 -6
- package/package.json +4 -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,13 @@ 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
|
+
resolveKitPathsBase
|
|
84
|
+
} from "@svelte-vitals/core";
|
|
72
85
|
async function exists(path) {
|
|
73
86
|
try {
|
|
74
87
|
await access(path);
|
|
@@ -88,17 +101,33 @@ async function robotsRefsSitemap(cwd) {
|
|
|
88
101
|
return void 0;
|
|
89
102
|
}
|
|
90
103
|
}
|
|
104
|
+
async function readFirstConfig(cwd, files) {
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const path = join2(cwd, file);
|
|
107
|
+
if (!await exists(path)) continue;
|
|
108
|
+
try {
|
|
109
|
+
return { file, source: await readFile2(path, "utf8") };
|
|
110
|
+
} catch {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
91
116
|
async function collectRenderedProject(cwd, htmlLang) {
|
|
92
|
-
const [hasRobotsTxt, hasSitemap] = await Promise.all([
|
|
117
|
+
const [hasRobotsTxt, hasSitemap, viteConfig, svelteConfig] = await Promise.all([
|
|
93
118
|
existsAny(cwd, ROBOTS_SOURCE_PATHS),
|
|
94
|
-
existsAny(cwd, SITEMAP_SOURCE_PATHS)
|
|
119
|
+
existsAny(cwd, SITEMAP_SOURCE_PATHS),
|
|
120
|
+
readFirstConfig(cwd, VITE_CONFIG_FILES),
|
|
121
|
+
readFirstConfig(cwd, SVELTE_CONFIG_FILES)
|
|
95
122
|
]);
|
|
96
123
|
const robotsReferencesSitemap = await robotsRefsSitemap(cwd);
|
|
124
|
+
const kitPathsBase = resolveKitPathsBase(viteConfig, svelteConfig);
|
|
97
125
|
return {
|
|
98
126
|
hasRobotsTxt,
|
|
99
127
|
hasSitemap,
|
|
100
128
|
htmlLang,
|
|
101
|
-
...robotsReferencesSitemap !== void 0 ? { robotsReferencesSitemap } : {}
|
|
129
|
+
...robotsReferencesSitemap !== void 0 ? { robotsReferencesSitemap } : {},
|
|
130
|
+
...kitPathsBase ? { kitPathsBase } : {}
|
|
102
131
|
};
|
|
103
132
|
}
|
|
104
133
|
|
|
@@ -510,7 +539,51 @@ function isRelevant(file, root) {
|
|
|
510
539
|
return segments[0] === "src" || segments[0] === "static";
|
|
511
540
|
}
|
|
512
541
|
var DEFAULT_PRERENDER_DIR = ".svelte-kit/output/prerendered/pages";
|
|
542
|
+
function validateRulesOption(rules) {
|
|
543
|
+
if (!rules) return;
|
|
544
|
+
const unknown = findUnknownRuleIds(Object.keys(rules));
|
|
545
|
+
if (unknown.length > 0) {
|
|
546
|
+
throw new Error(
|
|
547
|
+
`svelte-vitals: invalid \`rules\` option \u2014 unknown rule id(s): ${unknown.join(", ")}. Known rule ids: ${knownRuleIds().join(", ")}`
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
const errors = [];
|
|
551
|
+
for (const [id, setting] of Object.entries(rules)) {
|
|
552
|
+
errors.push(...validateRuleSetting(`rules.${id}`, id, setting, ruleOptionsSpec(id), { allowOptions: true }));
|
|
553
|
+
}
|
|
554
|
+
if (errors.length > 0) throw new Error(`svelte-vitals: invalid \`rules\` option \u2014 ${errors.join(" ")}`);
|
|
555
|
+
}
|
|
556
|
+
function validateOverridesOption(overrides, rules) {
|
|
557
|
+
if (!overrides) return;
|
|
558
|
+
const rulesLayerKnown = rules !== void 0;
|
|
559
|
+
const baseConfig = { ...defaultConfig, rules: rules ?? {} };
|
|
560
|
+
const errors = [];
|
|
561
|
+
overrides.forEach((entry, i) => {
|
|
562
|
+
const entryRules = entry.rules ?? {};
|
|
563
|
+
const nonCategoryKeys = Object.keys(entryRules).filter((k) => !CATEGORIES2.includes(k));
|
|
564
|
+
const unknown = findUnknownRuleIds(nonCategoryKeys);
|
|
565
|
+
if (unknown.length > 0) {
|
|
566
|
+
throw new Error(
|
|
567
|
+
`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(", ")}`
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
for (const [key, setting] of Object.entries(entryRules)) {
|
|
571
|
+
const isCategory = CATEGORIES2.includes(key);
|
|
572
|
+
const baseline = isCategory ? void 0 : resolveRuleOptions(key, ruleOptionsSpec(key), baseConfig);
|
|
573
|
+
errors.push(
|
|
574
|
+
...validateRuleSetting(`overrides[${i}].rules.${key}`, key, setting, ruleOptionsSpec(key), {
|
|
575
|
+
allowOptions: !isCategory,
|
|
576
|
+
...baseline !== void 0 ? { baseline } : {},
|
|
577
|
+
skipRangeCheck: !rulesLayerKnown || shouldSkipRangeCheck(overrides, i, key, setting)
|
|
578
|
+
})
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
if (errors.length > 0) throw new Error(`svelte-vitals: invalid \`overrides\` option \u2014 ${errors.join(" ")}`);
|
|
583
|
+
}
|
|
513
584
|
function svelteVitals(options = {}) {
|
|
585
|
+
validateRulesOption(options.rules);
|
|
586
|
+
validateOverridesOption(options.overrides, options.rules);
|
|
514
587
|
let root = options.cwd ?? process.cwd();
|
|
515
588
|
let minifyFlag;
|
|
516
589
|
const buildPlugin = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svelte-vitals/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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/core": "0.
|
|
46
|
-
"svelte-vitals": "0.
|
|
45
|
+
"@svelte-vitals/core": "0.30.0",
|
|
46
|
+
"svelte-vitals": "0.34.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@sveltejs/kit": "^2.70.1",
|
|
@@ -58,7 +58,7 @@
|
|
|
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": {
|