vite-doctor 0.0.6 → 0.0.8
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/README.md +33 -1
- package/dist/cli.mjs +244 -93
- package/dist/{config-BUjI8Z-S.d.mts → config-BF-tCiTu.d.mts} +3 -3
- package/dist/{config-cx1PzoSm.mjs → config-BX26IYzh.mjs} +2 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/{core-BFSgtrql.mjs → core-DLeqgOx5.mjs} +674 -121
- package/dist/{doctor-6AYPdd9f.mjs → doctor-CwNKe5uB.mjs} +13 -8
- package/dist/index-B6nzQEFO.d.mts +3 -0
- package/dist/{index-Dt29Fkqo.d.mts → index-BJU56z7q.d.mts} +1 -1
- package/dist/index-DgRcIdSA.d.mts +1 -0
- package/dist/index-Dw9aENZG.d.mts +29 -0
- package/dist/{index-CuZnkOun.d.mts → index-vpjcMmhA.d.mts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{module-uWErbEZU.d.mts → module-DWXrUl_H.d.mts} +3 -3
- package/dist/nitro-aRdLgPkY.mjs +2 -0
- package/dist/nuxt.d.mts +1 -1
- package/dist/{plugin-DF-TEW82.mjs → plugin-BCCA3oXP.mjs} +2 -2
- package/dist/{plugin-Cbc4OqZF.d.mts → plugin-BKNEtcVs.d.mts} +4 -4
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.mjs +1 -1
- package/dist/{primitives-BKt7lsYN.d.mts → primitives-3i5qmm5e.d.mts} +17 -2
- package/dist/rule-packs/nitro/index.d.mts +2 -2
- package/dist/rule-packs/nitro/index.mjs +2 -2
- package/dist/rule-packs/nitro/rules.d.mts +1 -1
- package/dist/rule-packs/nitro/rules.mjs +1 -1
- package/dist/rule-packs/nuxt/index.d.mts +2 -2
- package/dist/rule-packs/nuxt/module.d.mts +2 -2
- package/dist/rule-packs/nuxt/rules/index.d.mts +4 -4
- package/dist/rule-packs/nuxt/rules/index.mjs +2 -2
- package/dist/rule-packs/typescript/index.d.mts +2 -0
- package/dist/rule-packs/typescript/index.mjs +3 -0
- package/dist/rule-packs/typescript/rules/index.d.mts +2 -0
- package/dist/rule-packs/typescript/rules/index.mjs +2 -0
- package/dist/rule-packs/vite/index.d.mts +1 -1
- package/dist/rule-packs/vite/index.mjs +1 -1
- package/dist/rule-packs/vite/rules/index.d.mts +1 -1
- package/dist/rule-packs/vite/rules/index.mjs +1 -1
- package/dist/rule-packs/vue/index.d.mts +1 -1
- package/dist/rule-packs/vue/index.mjs +1 -1
- package/dist/rule-packs/vue/rules.d.mts +1 -1
- package/dist/rule-packs/vue/rules.mjs +1 -1
- package/dist/{rules-BTFofRie.mjs → rules-22ICiQaK.mjs} +289 -277
- package/dist/{rules-Dfp82SAy.mjs → rules-BKTr-IUz.mjs} +2 -1
- package/dist/rules-BkrZ1R0E.mjs +2 -0
- package/dist/{rules-DYysUGLM.mjs → rules-Bq9PexjC.mjs} +1 -1
- package/dist/{rules-BFAxpIuo.mjs → rules-Cc1_NZ7P.mjs} +1 -1
- package/dist/rules-D3X57pir.mjs +634 -0
- package/dist/{rules-CKaNAD2c.d.mts → rules-htM7saRv.d.mts} +1 -1
- package/dist/rules.d.mts +1 -1
- package/dist/rules.mjs +2 -2
- package/dist/typescript-Br-J4sLq.mjs +2 -0
- package/docs/skills/doctor/SKILL.md +52 -0
- package/package.json +7 -1
- package/dist/index-BhX8IsSY.d.mts +0 -3
- package/dist/index-D9d8HxE4.d.mts +0 -1
- package/dist/nitro-BVeI5VWP.mjs +0 -2
- package/dist/rules-CHyYwZV9.mjs +0 -2
package/README.md
CHANGED
|
@@ -32,6 +32,24 @@ pnpm dlx vite-doctor . --rules nuxt/fetch/no-raw-fetch-in-setup
|
|
|
32
32
|
pnpm dlx vite-doctor . --framework nitro
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
`--changed` analyzes complete changed files for framework context, then reports only Diagnostics owned by staged, unstaged, or untracked lines:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm dlx vite-doctor . --changed
|
|
39
|
+
pnpm dlx vite-doctor . --since origin/main
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Doctor recognizes coding-agent runtimes through Vercel's agent catalog and returns a compact agent report when output is non-interactive. An explicit format always wins:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm dlx vite-doctor . --format text
|
|
46
|
+
pnpm dlx vite-doctor . --format agent
|
|
47
|
+
pnpm dlx vite-doctor . --format json
|
|
48
|
+
pnpm dlx vite-doctor . --format sarif
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Agent reports use relative locations and include remediation, Diagnostic Reference URLs, and command templates for explanation, focused verification, and the full rerun.
|
|
52
|
+
|
|
35
53
|
For Nuxt projects, install Vite Doctor and run it through Nuxt:
|
|
36
54
|
|
|
37
55
|
```bash
|
|
@@ -53,7 +71,17 @@ The migration report stages source changes that are safe on the installed runtim
|
|
|
53
71
|
|
|
54
72
|
## Configuration
|
|
55
73
|
|
|
56
|
-
|
|
74
|
+
Doctor automatically loads declarative `doctor.config.json` without executing project code:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"rules": {
|
|
79
|
+
"vite/define/no-secret-define": "error"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Executable config remains explicit because loading it runs project code:
|
|
57
85
|
|
|
58
86
|
```ts
|
|
59
87
|
// doctor.config.ts
|
|
@@ -66,6 +94,10 @@ export default defineDoctorConfig({
|
|
|
66
94
|
});
|
|
67
95
|
```
|
|
68
96
|
|
|
97
|
+
```bash
|
|
98
|
+
pnpm dlx vite-doctor . --config doctor.config.ts
|
|
99
|
+
```
|
|
100
|
+
|
|
69
101
|
Plugin surfaces accept the same policy through host config:
|
|
70
102
|
|
|
71
103
|
```ts
|
package/dist/cli.mjs
CHANGED
|
@@ -1,53 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { a as reportStatus, d as detectProject, i as explainRule, l as cleanCache, n as createReport, r as createRulesReport, u as evaluateRuleApplicability } from "./core-DLeqgOx5.mjs";
|
|
3
|
+
import { n as loadDoctorConfig } from "./config-BX26IYzh.mjs";
|
|
4
|
+
import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-CwNKe5uB.mjs";
|
|
4
5
|
import { relative, resolve } from "pathe";
|
|
5
|
-
import { realpathSync, statSync } from "node:fs";
|
|
6
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { cac } from "cac";
|
|
8
9
|
import { consola } from "consola";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
else if (arg === "--rules") options.rules = args[++index];
|
|
35
|
-
else if (arg === "--severity") options.severity = args[++index];
|
|
36
|
-
else if (arg === "--extends") options.extends = parseExtends(args[++index]);
|
|
37
|
-
else if (arg === "--since") options.since = args[++index];
|
|
38
|
-
else if (arg === "--baseline") options.baseline = args[++index];
|
|
39
|
-
else if (arg === "--format") options.format = args[++index];
|
|
40
|
-
else if (!arg.startsWith("-")) path = arg;
|
|
41
|
-
}
|
|
10
|
+
import { determineAgent } from "detect-agent";
|
|
11
|
+
import { isCI } from "std-env";
|
|
12
|
+
//#region src/core/internal/agent-runtime.ts
|
|
13
|
+
const currentRuntime = {
|
|
14
|
+
ci: isCI,
|
|
15
|
+
tty: process.stdout?.isTTY === true,
|
|
16
|
+
determineAgent
|
|
17
|
+
};
|
|
18
|
+
async function selectDoctorPresentation(explicitFormat, runtime = currentRuntime) {
|
|
19
|
+
if (explicitFormat) return {
|
|
20
|
+
format: explicitFormat,
|
|
21
|
+
automatic: false
|
|
22
|
+
};
|
|
23
|
+
if (runtime.ci || runtime.tty) return {
|
|
24
|
+
format: "text",
|
|
25
|
+
automatic: false
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
const result = await runtime.determineAgent();
|
|
29
|
+
if (result.isAgent) return {
|
|
30
|
+
format: "agent",
|
|
31
|
+
detectedAgent: result.agent.name,
|
|
32
|
+
automatic: true
|
|
33
|
+
};
|
|
34
|
+
} catch {}
|
|
42
35
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
format: "text",
|
|
37
|
+
automatic: false
|
|
45
38
|
};
|
|
46
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/core/internal/cli.ts
|
|
47
42
|
function applyDoctorOptions(options, flags) {
|
|
48
43
|
if (flags.changed) options.changed = true;
|
|
49
44
|
if (flags.types) options.types = true;
|
|
50
|
-
if (flags.threads) options.threads = Number(flags.threads);
|
|
51
45
|
options.coverage = stringFlag(flags.coverage) ?? options.coverage;
|
|
52
46
|
options.runtimeEvidence = stringFlag(flags.runtimeEvidence) ?? options.runtimeEvidence;
|
|
53
47
|
options.analyses = stringFlag(flags.analyses) ?? options.analyses;
|
|
@@ -81,12 +75,6 @@ function parseExtendsFlag(value) {
|
|
|
81
75
|
function stringFlag(value) {
|
|
82
76
|
return typeof value === "string" ? value : void 0;
|
|
83
77
|
}
|
|
84
|
-
function normalizeDoctorCommand(args, commands) {
|
|
85
|
-
const first = args.find((arg) => !arg.startsWith("-"));
|
|
86
|
-
if (!first) return ["scan", ...args];
|
|
87
|
-
if (commands.has(first)) return args;
|
|
88
|
-
return ["scan", ...args];
|
|
89
|
-
}
|
|
90
78
|
//#endregion
|
|
91
79
|
//#region src/migration.ts
|
|
92
80
|
async function createMigrationReport(root, requestedTargets = []) {
|
|
@@ -171,6 +159,11 @@ async function createMigrationReport(root, requestedTargets = []) {
|
|
|
171
159
|
}
|
|
172
160
|
function formatMigrationReport(report, format = "text") {
|
|
173
161
|
if (format === "json") return `${JSON.stringify(report, null, 2)}\n`;
|
|
162
|
+
if (format === "agent") return `${JSON.stringify({
|
|
163
|
+
schema: "vite-doctor.migration/v1",
|
|
164
|
+
status: report.summary.diagnostics || report.summary.dependencyChanges ? "findings" : "clean",
|
|
165
|
+
...report
|
|
166
|
+
})}\n`;
|
|
174
167
|
const lines = [
|
|
175
168
|
`Migration target: ${report.target.requested.join(", ")} (${report.target.source})`,
|
|
176
169
|
`Workspace: ${report.root}`,
|
|
@@ -278,48 +271,97 @@ function major(version) {
|
|
|
278
271
|
}
|
|
279
272
|
//#endregion
|
|
280
273
|
//#region src/cli-main.ts
|
|
281
|
-
const
|
|
274
|
+
const removedCommands = /* @__PURE__ */ new Set([
|
|
275
|
+
"run",
|
|
276
|
+
"ci",
|
|
282
277
|
"scan",
|
|
283
|
-
"check"
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
"
|
|
287
|
-
"
|
|
278
|
+
"check"
|
|
279
|
+
]);
|
|
280
|
+
const reportFormats = /* @__PURE__ */ new Set([
|
|
281
|
+
"text",
|
|
282
|
+
"json",
|
|
283
|
+
"sarif",
|
|
284
|
+
"agent"
|
|
285
|
+
]);
|
|
286
|
+
const metadataFormats = /* @__PURE__ */ new Set([
|
|
287
|
+
"text",
|
|
288
|
+
"json",
|
|
289
|
+
"agent"
|
|
288
290
|
]);
|
|
289
|
-
const
|
|
291
|
+
const frameworks = /* @__PURE__ */ new Set([
|
|
292
|
+
"auto",
|
|
293
|
+
"vite",
|
|
294
|
+
"vue",
|
|
295
|
+
"nitro",
|
|
296
|
+
"nuxt"
|
|
297
|
+
]);
|
|
298
|
+
const severities = /* @__PURE__ */ new Set([
|
|
299
|
+
"error",
|
|
300
|
+
"warn",
|
|
301
|
+
"info"
|
|
302
|
+
]);
|
|
303
|
+
const analyses = /* @__PURE__ */ new Set([
|
|
304
|
+
"dead-code",
|
|
305
|
+
"graph",
|
|
306
|
+
"dupes",
|
|
307
|
+
"health"
|
|
308
|
+
]);
|
|
309
|
+
var CliConfigError = class extends Error {
|
|
310
|
+
constructor(file, message) {
|
|
311
|
+
super(message);
|
|
312
|
+
this.file = file;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
290
315
|
async function main(args = process.argv.slice(2), cwd = process.cwd()) {
|
|
291
316
|
if (args.includes("--version") || args.includes("-v")) {
|
|
292
317
|
process.stdout.write(`${viteDoctorVersion}\n`);
|
|
293
318
|
return 0;
|
|
294
319
|
}
|
|
295
320
|
if (removedCommands.has(args[0] ?? "")) {
|
|
296
|
-
|
|
297
|
-
|
|
321
|
+
const command = args[0];
|
|
322
|
+
await writeCliError(`vite-doctor ${command} was removed. Use ${command === "scan" || command === "check" ? "vite-doctor [path]" : "your package manager scripts"}.`, await requestedPresentation(args));
|
|
323
|
+
return 2;
|
|
298
324
|
}
|
|
299
325
|
let exitCode = 0;
|
|
300
326
|
const cli = cac("vite-doctor");
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
327
|
+
addDoctorRunCommand(cli, cwd, (code) => exitCode = code);
|
|
328
|
+
cli.command("migrate [path]", "Evaluate source against a future runtime graph.").option("--to <target>", "Explicit target such as nuxt@5 or nitro@3.").option("--format <format>", "Output: text, json, or agent.").action(async (path = ".", options) => {
|
|
329
|
+
const format = await presentationFormat(options.format, metadataFormats);
|
|
304
330
|
const root = resolve(cwd, path);
|
|
305
|
-
if (!
|
|
306
|
-
|
|
307
|
-
exitCode =
|
|
331
|
+
if (!isDirectory(root)) {
|
|
332
|
+
await writeCliError(`No readable directory found at ${root}`, format);
|
|
333
|
+
exitCode = 2;
|
|
308
334
|
return;
|
|
309
335
|
}
|
|
310
336
|
const report = await createMigrationReport(root, options.to ? [options.to] : []);
|
|
311
|
-
process.stdout.write(formatMigrationReport(report,
|
|
337
|
+
process.stdout.write(formatMigrationReport(report, format));
|
|
312
338
|
exitCode = report.summary.errors > 0 ? 1 : 0;
|
|
313
339
|
});
|
|
314
|
-
cli.command("rules", "List available Doctor rules.").option("--format <format>", "
|
|
315
|
-
const
|
|
340
|
+
cli.command("rules", "List available Doctor rules.").option("--format <format>", "Output: text, json, or agent.").option("--framework <framework>", "Framework override.").action(async (options) => {
|
|
341
|
+
const format = await presentationFormat(options.format, metadataFormats);
|
|
342
|
+
const runOptions = {
|
|
343
|
+
root: cwd,
|
|
344
|
+
format
|
|
345
|
+
};
|
|
316
346
|
applyDoctorOptions(runOptions, options);
|
|
317
|
-
|
|
347
|
+
validateCliRunOptions(runOptions);
|
|
348
|
+
process.stdout.write(createRulesReport(await viteDoctorRulePacks(runOptions), format));
|
|
318
349
|
});
|
|
319
|
-
cli.command("explain <
|
|
320
|
-
const
|
|
350
|
+
cli.command("explain <diagnostic>", "Explain a Doctor Diagnostic Code or Rule.").option("--format <format>", "Output: text, json, or agent.").option("--framework <framework>", "Framework override.").action(async (diagnostic, options) => {
|
|
351
|
+
const format = await presentationFormat(options.format, metadataFormats);
|
|
352
|
+
const runOptions = {
|
|
353
|
+
root: cwd,
|
|
354
|
+
format
|
|
355
|
+
};
|
|
321
356
|
applyDoctorOptions(runOptions, options);
|
|
322
|
-
|
|
357
|
+
validateCliRunOptions(runOptions);
|
|
358
|
+
const report = explainRule(await viteDoctorRulePacks(runOptions), diagnostic, format);
|
|
359
|
+
if (!report) {
|
|
360
|
+
await writeCliError(`Unknown Diagnostic Code or Rule: ${diagnostic}`, format);
|
|
361
|
+
exitCode = 2;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
process.stdout.write(report);
|
|
323
365
|
});
|
|
324
366
|
cli.command("cache <action>", "Manage Doctor cache.").action((action) => {
|
|
325
367
|
if (action === "clean") {
|
|
@@ -327,52 +369,161 @@ async function main(args = process.argv.slice(2), cwd = process.cwd()) {
|
|
|
327
369
|
consola.log("Doctor cache cleaned");
|
|
328
370
|
return;
|
|
329
371
|
}
|
|
330
|
-
|
|
331
|
-
exitCode = 1;
|
|
372
|
+
throw new Error(`Unknown cache action: ${action}`);
|
|
332
373
|
});
|
|
333
374
|
cli.help();
|
|
334
375
|
try {
|
|
335
376
|
cli.parse([
|
|
336
377
|
"node",
|
|
337
378
|
"vite-doctor",
|
|
338
|
-
...
|
|
379
|
+
...args
|
|
339
380
|
], { run: false });
|
|
340
381
|
const result = await cli.runMatchedCommand();
|
|
341
382
|
if (typeof result === "number") exitCode = result;
|
|
342
383
|
return exitCode;
|
|
343
384
|
} catch (error) {
|
|
344
|
-
|
|
345
|
-
|
|
385
|
+
const format = await requestedPresentation(args);
|
|
386
|
+
await writeCliError(error instanceof Error ? error.message : String(error), format, {
|
|
387
|
+
kind: error instanceof CliConfigError ? "config" : "invocation",
|
|
388
|
+
file: error instanceof CliConfigError ? error.file : void 0
|
|
389
|
+
});
|
|
390
|
+
return 2;
|
|
346
391
|
}
|
|
347
392
|
}
|
|
348
|
-
function
|
|
349
|
-
cli.command(
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
setExitCode(
|
|
393
|
+
function addDoctorRunCommand(cli, cwd, setExitCode) {
|
|
394
|
+
cli.command("[path]", "Run Doctor diagnostics.").option("--changed", "Report diagnostics on changed lines.").option("--types", "Enable type-aware rules.").option("--analyses <analyses>", "Comma-separated analyses: dead-code, graph, dupes, or health.").option("--profile", "Include timings.").option("--new-only", "Only report diagnostics absent from the baseline.").option("--cache", "Use the analysis cache.").option("--no-cache", "Disable the analysis cache.").option("--fix", "Apply safe edit plans and verify the result.").option("--unsafe-fix", "Apply unsafe edit plans and verify the result.").option("--max-warnings <count>", "Maximum warnings before failure.").option("--framework <framework>", "Framework override: vite, vue, nitro, or nuxt.").option("--rules <rules>", "Comma-separated Rule selectors.").option("--severity <severity>", "Minimum severity: error, warn, or info.").option("--extends <extends>", "Comma-separated rule-pack presets.").option("--since <ref>", "Report diagnostics on lines changed since a Git ref.").option("--baseline <file>", "Diagnostic baseline file.").option("--format <format>", "Output: text, json, sarif, or agent.").option("--config <path>", "Explicitly load an executable Doctor config.").action(async (path = ".", options) => {
|
|
395
|
+
const format = await presentationFormat(options.format, reportFormats);
|
|
396
|
+
const root = resolve(cwd, path);
|
|
397
|
+
if (!isDirectory(root)) {
|
|
398
|
+
await writeCliError(`No readable directory found at ${root}`, format);
|
|
399
|
+
setExitCode(2);
|
|
355
400
|
return;
|
|
356
401
|
}
|
|
357
|
-
|
|
402
|
+
const runOptions = {
|
|
403
|
+
root,
|
|
404
|
+
format
|
|
405
|
+
};
|
|
406
|
+
applyDoctorOptions(runOptions, options);
|
|
407
|
+
validateCliRunOptions(runOptions);
|
|
408
|
+
const explicitConfig = stringFlag(options.config);
|
|
409
|
+
const configFile = cliConfigFile(root, explicitConfig);
|
|
410
|
+
runOptions.config = await loadCliConfig(root, explicitConfig);
|
|
411
|
+
try {
|
|
412
|
+
setExitCode(await runDoctorCommand(runOptions, format));
|
|
413
|
+
} catch (error) {
|
|
414
|
+
if (configFile && isLoadedConfigValidationError(error, runOptions)) throw createCliConfigError(configFile, error);
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
358
417
|
});
|
|
359
418
|
}
|
|
360
|
-
async function
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return 1;
|
|
365
|
-
}
|
|
366
|
-
const result = await runViteDoctor({
|
|
367
|
-
...options,
|
|
368
|
-
root
|
|
369
|
-
});
|
|
370
|
-
process.stdout.write(createReport(result, options.format));
|
|
419
|
+
async function runDoctorCommand(options, format) {
|
|
420
|
+
const result = await runViteDoctor(options);
|
|
421
|
+
process.stdout.write(createReport(result, format));
|
|
422
|
+
if (reportStatus(result) === "incomplete") return 3;
|
|
371
423
|
return shouldFailDoctorRun(result, options.maxWarnings) ? 1 : 0;
|
|
372
424
|
}
|
|
373
|
-
function
|
|
425
|
+
async function loadCliConfig(root, explicitConfig) {
|
|
426
|
+
if (explicitConfig) {
|
|
427
|
+
const configFile = resolve(root, explicitConfig);
|
|
428
|
+
try {
|
|
429
|
+
return await loadDoctorConfig({
|
|
430
|
+
cwd: root,
|
|
431
|
+
configFile
|
|
432
|
+
});
|
|
433
|
+
} catch (error) {
|
|
434
|
+
throw createCliConfigError(configFile, error);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const declarativeConfig = resolve(root, "doctor.config.json");
|
|
438
|
+
if (!existsSync(declarativeConfig)) return void 0;
|
|
439
|
+
try {
|
|
440
|
+
const value = JSON.parse(readFileSync(declarativeConfig, "utf8"));
|
|
441
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("doctor.config.json must contain a JSON object.");
|
|
442
|
+
return value;
|
|
443
|
+
} catch (error) {
|
|
444
|
+
throw createCliConfigError(declarativeConfig, error);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async function presentationFormat(value, supported) {
|
|
448
|
+
const explicit = stringFlag(value);
|
|
449
|
+
if (explicit && !reportFormats.has(explicit)) throw new Error(`Unknown report format ${JSON.stringify(explicit)}. Expected ${[...supported].join(", ")}.`);
|
|
450
|
+
if (explicit && !supported.has(explicit)) throw new Error(`Report format ${JSON.stringify(explicit)} is not available here. Expected ${[...supported].join(", ")}.`);
|
|
451
|
+
return (await selectDoctorPresentation(explicit)).format;
|
|
452
|
+
}
|
|
453
|
+
async function requestedPresentation(args) {
|
|
454
|
+
let explicit;
|
|
455
|
+
for (let index = 0; index < args.length; index++) if (args[index] === "--format") explicit = args[index + 1];
|
|
456
|
+
else if (args[index]?.startsWith("--format=")) explicit = args[index].slice(9);
|
|
457
|
+
if (explicit && reportFormats.has(explicit)) return (await selectDoctorPresentation(explicit)).format;
|
|
458
|
+
return (await selectDoctorPresentation()).format;
|
|
459
|
+
}
|
|
460
|
+
async function writeCliError(message, format, failure = { kind: "invocation" }) {
|
|
461
|
+
if (format === "json" || format === "agent") {
|
|
462
|
+
const indentation = format === "agent" ? void 0 : 2;
|
|
463
|
+
process.stdout.write(`${JSON.stringify({
|
|
464
|
+
schema: format === "agent" ? "vite-doctor.agent/v1" : "vite-doctor.report/v3",
|
|
465
|
+
status: "failed",
|
|
466
|
+
error: {
|
|
467
|
+
kind: failure.kind,
|
|
468
|
+
message,
|
|
469
|
+
file: failure.file
|
|
470
|
+
},
|
|
471
|
+
next: failure.kind === "config" ? {
|
|
472
|
+
action: "fix-config",
|
|
473
|
+
file: failure.file
|
|
474
|
+
} : {
|
|
475
|
+
action: "correct-invocation",
|
|
476
|
+
command: "vite-doctor --help"
|
|
477
|
+
}
|
|
478
|
+
}, null, indentation)}\n`);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (format === "sarif") {
|
|
482
|
+
process.stdout.write(`${JSON.stringify({
|
|
483
|
+
version: "2.1.0",
|
|
484
|
+
runs: [{
|
|
485
|
+
tool: { driver: {
|
|
486
|
+
name: "Vite Doctor",
|
|
487
|
+
semanticVersion: viteDoctorVersion
|
|
488
|
+
} },
|
|
489
|
+
invocations: [{
|
|
490
|
+
executionSuccessful: false,
|
|
491
|
+
toolExecutionNotifications: [{
|
|
492
|
+
level: "error",
|
|
493
|
+
message: { text: message }
|
|
494
|
+
}]
|
|
495
|
+
}],
|
|
496
|
+
results: []
|
|
497
|
+
}]
|
|
498
|
+
})}\n`);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
374
501
|
consola.error(message);
|
|
375
|
-
|
|
502
|
+
}
|
|
503
|
+
function isDirectory(path) {
|
|
504
|
+
return Boolean(statSync(path, { throwIfNoEntry: false })?.isDirectory());
|
|
505
|
+
}
|
|
506
|
+
function validateCliRunOptions(options) {
|
|
507
|
+
if (options.framework && !frameworks.has(options.framework)) throw new Error(`Unknown framework ${JSON.stringify(options.framework)}. Expected ${[...frameworks].join(", ")}.`);
|
|
508
|
+
if (options.severity && !severities.has(options.severity)) throw new Error(`Unknown severity ${JSON.stringify(options.severity)}. Expected ${[...severities].join(", ")}.`);
|
|
509
|
+
if (options.maxWarnings !== void 0 && (!Number.isInteger(options.maxWarnings) || options.maxWarnings < 0)) throw new Error("--max-warnings must be a non-negative integer.");
|
|
510
|
+
const requestedAnalyses = options.analyses?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
511
|
+
if (options.analyses !== void 0 && !requestedAnalyses?.length) throw new Error("--analyses must select at least one analysis.");
|
|
512
|
+
const unknownAnalyses = requestedAnalyses?.filter((item) => !analyses.has(item));
|
|
513
|
+
if (unknownAnalyses?.length) throw new Error(`Unknown analysis ${JSON.stringify(unknownAnalyses[0])}. Expected ${[...analyses].join(", ")}.`);
|
|
514
|
+
}
|
|
515
|
+
function createCliConfigError(file, error) {
|
|
516
|
+
return new CliConfigError(file, `Could not load Doctor config at ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
517
|
+
}
|
|
518
|
+
function cliConfigFile(root, explicitConfig) {
|
|
519
|
+
if (explicitConfig) return resolve(root, explicitConfig);
|
|
520
|
+
const declarativeConfig = resolve(root, "doctor.config.json");
|
|
521
|
+
return existsSync(declarativeConfig) ? declarativeConfig : void 0;
|
|
522
|
+
}
|
|
523
|
+
function isLoadedConfigValidationError(error, options) {
|
|
524
|
+
if (!(error instanceof Error)) return false;
|
|
525
|
+
if (error.name === "DOC0019" || error.name === "DOC0020") return true;
|
|
526
|
+
return options.extends === void 0 && (error.name === "DOC0016" || error.name === "DOC0017" || error.name === "DOC0018");
|
|
376
527
|
}
|
|
377
528
|
//#endregion
|
|
378
529
|
//#region src/cli.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as DoctorSerializableConfig, c as RuntimeTarget, n as DoctorFramework, r as DoctorReportFormat, t as DoctorExtension } from "./primitives-3i5qmm5e.mjs";
|
|
2
2
|
//#region src/core/config.d.ts
|
|
3
3
|
interface DoctorConfig extends DoctorSerializableConfig {
|
|
4
4
|
extensions?: DoctorExtension[];
|
|
@@ -11,14 +11,13 @@ interface DoctorRunOptions {
|
|
|
11
11
|
extends?: "auto" | string[];
|
|
12
12
|
changed?: boolean;
|
|
13
13
|
since?: string;
|
|
14
|
-
format?:
|
|
14
|
+
format?: DoctorReportFormat;
|
|
15
15
|
baseline?: string;
|
|
16
16
|
updateBaseline?: boolean;
|
|
17
17
|
newOnly?: boolean;
|
|
18
18
|
severity?: "error" | "warn" | "info";
|
|
19
19
|
rules?: string;
|
|
20
20
|
types?: boolean;
|
|
21
|
-
threads?: number;
|
|
22
21
|
coverage?: string;
|
|
23
22
|
runtimeEvidence?: string;
|
|
24
23
|
analyses?: string;
|
|
@@ -38,6 +37,7 @@ declare function defineDoctorConfig(config: DoctorConfig): DoctorConfig;
|
|
|
38
37
|
interface LoadDoctorConfigOptions {
|
|
39
38
|
cwd: string;
|
|
40
39
|
defaults?: DoctorConfig;
|
|
40
|
+
configFile?: string;
|
|
41
41
|
}
|
|
42
42
|
declare function loadDoctorConfig(options: LoadDoctorConfigOptions): Promise<DoctorConfig>;
|
|
43
43
|
//#endregion
|
|
@@ -6,7 +6,8 @@ function defineDoctorConfig(config) {
|
|
|
6
6
|
}
|
|
7
7
|
async function loadDoctorConfig(options) {
|
|
8
8
|
const result = await loadConfig({
|
|
9
|
-
configFile: "doctor.config",
|
|
9
|
+
configFile: options.configFile ?? "doctor.config",
|
|
10
|
+
configFileRequired: Boolean(options.configFile),
|
|
10
11
|
cwd: options.cwd,
|
|
11
12
|
dotenv: false,
|
|
12
13
|
globalRc: false,
|
package/dist/config.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as loadDoctorConfig, i as defineDoctorConfig, n as DoctorRunOptions, r as LoadDoctorConfigOptions, t as DoctorConfig } from "./config-
|
|
1
|
+
import { a as loadDoctorConfig, i as defineDoctorConfig, n as DoctorRunOptions, r as LoadDoctorConfigOptions, t as DoctorConfig } from "./config-BF-tCiTu.mjs";
|
|
2
2
|
export { type DoctorConfig, type DoctorRunOptions, type LoadDoctorConfigOptions, defineDoctorConfig, loadDoctorConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as loadDoctorConfig, t as defineDoctorConfig } from "./config-
|
|
1
|
+
import { n as loadDoctorConfig, t as defineDoctorConfig } from "./config-BX26IYzh.mjs";
|
|
2
2
|
export { defineDoctorConfig, loadDoctorConfig };
|