svelte-vitals 0.5.1 → 0.5.2
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 +67 -39
- package/dist/{chunk-RI6LBHFR.js → chunk-LQPB2WAL.js} +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -6,10 +6,71 @@ import {
|
|
|
6
6
|
knownRuleIds,
|
|
7
7
|
readPackageVersion,
|
|
8
8
|
run
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LQPB2WAL.js";
|
|
10
10
|
|
|
11
11
|
// src/bin.ts
|
|
12
12
|
import mri from "mri";
|
|
13
|
+
|
|
14
|
+
// src/resolve-args.ts
|
|
15
|
+
var toList = (v) => typeof v === "string" ? v.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
16
|
+
function resolveArgs(argv) {
|
|
17
|
+
const warnings = [];
|
|
18
|
+
const errors = [];
|
|
19
|
+
const positional = argv._[0];
|
|
20
|
+
const metaComponents = typeof argv["meta-components"] === "string" ? argv["meta-components"].split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
21
|
+
const treatRaw = argv["treat-dynamic-as"];
|
|
22
|
+
const treatDynamicAs = treatRaw === "warn" || treatRaw === "fail" || treatRaw === "pass" ? treatRaw : void 0;
|
|
23
|
+
if (typeof treatRaw === "string" && treatDynamicAs === void 0) {
|
|
24
|
+
warnings.push(
|
|
25
|
+
`svelte-vitals: unknown --treat-dynamic-as '${treatRaw}'; expected pass|warn|fail. Defaulting to 'pass'.`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
const route = typeof argv.route === "string" ? argv.route : void 0;
|
|
29
|
+
const allow = toList(argv.rules);
|
|
30
|
+
const ignore = toList(argv.ignore);
|
|
31
|
+
const unknown = findUnknownRuleIds([...allow, ...ignore]);
|
|
32
|
+
if (unknown.length > 0) {
|
|
33
|
+
errors.push(`svelte-vitals: unknown rule id(s) in --rules/--ignore: ${unknown.join(", ")}`);
|
|
34
|
+
errors.push(`Known rule ids: ${knownRuleIds().join(", ")}`);
|
|
35
|
+
}
|
|
36
|
+
let reporter;
|
|
37
|
+
if (argv.json) {
|
|
38
|
+
reporter = "json";
|
|
39
|
+
} else if (typeof argv.reporter === "string") {
|
|
40
|
+
if (!isReporterName(argv.reporter)) {
|
|
41
|
+
errors.push(
|
|
42
|
+
`svelte-vitals: unknown reporter '${argv.reporter}'. Valid values: console, json, agent, sarif, github.`
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
reporter = argv.reporter;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const failOnRaw = argv["fail-on"];
|
|
49
|
+
const failOnValid = failOnRaw === "warning" || failOnRaw === "info" || failOnRaw === "critical";
|
|
50
|
+
if (typeof failOnRaw === "string" && !failOnValid) {
|
|
51
|
+
warnings.push(
|
|
52
|
+
`svelte-vitals: unknown --fail-on '${failOnRaw}'; expected critical|warning|info. No threshold applied.`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const failOn = argv["fail-on-warning"] ? "warning" : failOnValid ? failOnRaw : void 0;
|
|
56
|
+
if (errors.length > 0) return { options: null, warnings, errors };
|
|
57
|
+
return {
|
|
58
|
+
options: {
|
|
59
|
+
cwd: positional ?? process.cwd(),
|
|
60
|
+
metaComponents,
|
|
61
|
+
treatDynamicAs,
|
|
62
|
+
route,
|
|
63
|
+
reporter,
|
|
64
|
+
byRoute: Boolean(argv["by-route"]),
|
|
65
|
+
failOn,
|
|
66
|
+
rules: buildRulesConfig(allow, ignore)
|
|
67
|
+
},
|
|
68
|
+
warnings,
|
|
69
|
+
errors
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/bin.ts
|
|
13
74
|
var HELP = `svelte-vitals \u2014 a SvelteKit SEO checker (static mode)
|
|
14
75
|
|
|
15
76
|
Usage:
|
|
@@ -48,44 +109,11 @@ async function main() {
|
|
|
48
109
|
console.log(VERSION);
|
|
49
110
|
process.exit(0);
|
|
50
111
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const toList = (v) => typeof v === "string" ? v.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
57
|
-
const allow = toList(argv.rules);
|
|
58
|
-
const ignore = toList(argv.ignore);
|
|
59
|
-
const unknown = findUnknownRuleIds([...allow, ...ignore]);
|
|
60
|
-
if (unknown.length > 0) {
|
|
61
|
-
console.error(`svelte-vitals: unknown rule id(s) in --rules/--ignore: ${unknown.join(", ")}`);
|
|
62
|
-
console.error(`Known rule ids: ${knownRuleIds().join(", ")}`);
|
|
63
|
-
process.exit(2);
|
|
64
|
-
}
|
|
65
|
-
let reporter;
|
|
66
|
-
if (argv.json) {
|
|
67
|
-
reporter = "json";
|
|
68
|
-
} else if (typeof argv.reporter === "string") {
|
|
69
|
-
if (!isReporterName(argv.reporter)) {
|
|
70
|
-
console.error(
|
|
71
|
-
`svelte-vitals: unknown reporter '${argv.reporter}'. Valid values: console, json, agent, sarif, github.`
|
|
72
|
-
);
|
|
73
|
-
process.exit(2);
|
|
74
|
-
}
|
|
75
|
-
reporter = argv.reporter;
|
|
76
|
-
}
|
|
77
|
-
const failOnRaw = argv["fail-on"];
|
|
78
|
-
const failOn = argv["fail-on-warning"] ? "warning" : failOnRaw === "warning" || failOnRaw === "info" || failOnRaw === "critical" ? failOnRaw : void 0;
|
|
79
|
-
const code = await run({
|
|
80
|
-
cwd: positional ?? process.cwd(),
|
|
81
|
-
metaComponents,
|
|
82
|
-
treatDynamicAs,
|
|
83
|
-
route,
|
|
84
|
-
reporter,
|
|
85
|
-
byRoute: Boolean(argv["by-route"]),
|
|
86
|
-
failOn,
|
|
87
|
-
rules: buildRulesConfig(allow, ignore)
|
|
88
|
-
});
|
|
112
|
+
const { options, warnings, errors } = resolveArgs(argv);
|
|
113
|
+
for (const w of warnings) console.error(w);
|
|
114
|
+
for (const e of errors) console.error(e);
|
|
115
|
+
if (!options) process.exit(2);
|
|
116
|
+
const code = await run(options);
|
|
89
117
|
process.exit(code);
|
|
90
118
|
}
|
|
91
119
|
void main();
|
|
@@ -114,7 +114,7 @@ function addImportsFromProgram(program, map) {
|
|
|
114
114
|
if (spec.type === "ImportDefaultSpecifier") {
|
|
115
115
|
map.set(local, { source, imported: "default" });
|
|
116
116
|
} else if (spec.type === "ImportSpecifier") {
|
|
117
|
-
map.set(local, { source, imported: spec.imported?.name ?? local });
|
|
117
|
+
map.set(local, { source, imported: spec.imported?.name ?? spec.imported?.value ?? local });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED