vite-doctor 0.0.7 → 0.0.9

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.
Files changed (64) hide show
  1. package/README.md +39 -13
  2. package/dist/cli.mjs +244 -93
  3. package/dist/{config-GYUYW1FL.d.mts → config-BF-tCiTu.d.mts} +3 -3
  4. package/dist/{config-cx1PzoSm.mjs → config-BX26IYzh.mjs} +2 -1
  5. package/dist/config.d.mts +1 -1
  6. package/dist/config.mjs +1 -1
  7. package/dist/{core-jvU53IG0.mjs → core-DLeqgOx5.mjs} +562 -105
  8. package/dist/{doctor-CPU6PJkE.mjs → doctor-CwNKe5uB.mjs} +9 -9
  9. package/dist/index-B6nzQEFO.d.mts +3 -0
  10. package/dist/{index-ST_3aaT7.d.mts → index-BJU56z7q.d.mts} +1 -1
  11. package/dist/index-DgRcIdSA.d.mts +1 -0
  12. package/dist/{index-BZSYm1ow.d.mts → index-Dw9aENZG.d.mts} +1 -1
  13. package/dist/{index-CC_PA_16.d.mts → index-vpjcMmhA.d.mts} +1 -1
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.mjs +2 -2
  16. package/dist/{module-B-h3EZka.d.mts → module-2_e5b-LZ.d.mts} +6 -9
  17. package/dist/{module--Dgf9XPW.mjs → module-DVHJKJkW.mjs} +13 -8
  18. package/dist/nitro-aRdLgPkY.mjs +2 -0
  19. package/dist/nuxt.d.mts +1 -1
  20. package/dist/nuxt.mjs +1 -1
  21. package/dist/{plugin-BUgSIN2M.mjs → plugin-BCCA3oXP.mjs} +2 -2
  22. package/dist/{plugin-C3bX7b3u.d.mts → plugin-BKNEtcVs.d.mts} +4 -4
  23. package/dist/plugin.d.mts +1 -1
  24. package/dist/plugin.mjs +1 -1
  25. package/dist/{primitives-BB8AakLb.d.mts → primitives-3i5qmm5e.d.mts} +14 -2
  26. package/dist/rule-packs/nitro/index.d.mts +2 -2
  27. package/dist/rule-packs/nitro/index.mjs +2 -2
  28. package/dist/rule-packs/nitro/rules.d.mts +1 -1
  29. package/dist/rule-packs/nitro/rules.mjs +1 -1
  30. package/dist/rule-packs/nuxt/index.d.mts +2 -2
  31. package/dist/rule-packs/nuxt/index.mjs +1 -1
  32. package/dist/rule-packs/nuxt/module.d.mts +2 -2
  33. package/dist/rule-packs/nuxt/module.mjs +1 -1
  34. package/dist/rule-packs/nuxt/rules/index.d.mts +4 -4
  35. package/dist/rule-packs/nuxt/rules/index.mjs +2 -2
  36. package/dist/rule-packs/typescript/index.d.mts +1 -1
  37. package/dist/rule-packs/typescript/index.mjs +2 -2
  38. package/dist/rule-packs/typescript/rules/index.d.mts +1 -1
  39. package/dist/rule-packs/typescript/rules/index.mjs +1 -1
  40. package/dist/rule-packs/vite/index.d.mts +1 -1
  41. package/dist/rule-packs/vite/index.mjs +1 -1
  42. package/dist/rule-packs/vite/rules/index.d.mts +1 -1
  43. package/dist/rule-packs/vite/rules/index.mjs +1 -1
  44. package/dist/rule-packs/vue/index.d.mts +1 -1
  45. package/dist/rule-packs/vue/index.mjs +1 -1
  46. package/dist/rule-packs/vue/rules.d.mts +1 -1
  47. package/dist/rule-packs/vue/rules.mjs +1 -1
  48. package/dist/{rules-B3yMC9sr.mjs → rules-22ICiQaK.mjs} +289 -277
  49. package/dist/{rules-Coo8Oc8h.mjs → rules-BKTr-IUz.mjs} +1 -1
  50. package/dist/rules-BkrZ1R0E.mjs +2 -0
  51. package/dist/{rules-wGXdGC9F.mjs → rules-Bq9PexjC.mjs} +1 -1
  52. package/dist/{rules-DZdYc6nv.mjs → rules-Cc1_NZ7P.mjs} +1 -1
  53. package/dist/{rules-C5pNbGfH.mjs → rules-D3X57pir.mjs} +4 -7
  54. package/dist/{rules-BW08SCmi.d.mts → rules-htM7saRv.d.mts} +1 -1
  55. package/dist/rules.d.mts +1 -1
  56. package/dist/rules.mjs +2 -2
  57. package/dist/typescript-Br-J4sLq.mjs +2 -0
  58. package/docs/skills/doctor/SKILL.md +52 -0
  59. package/package.json +4 -1
  60. package/dist/index-CpbGR6NE.d.mts +0 -3
  61. package/dist/index-tu1l5mxN.d.mts +0 -1
  62. package/dist/nitro-DUjsFYpW.mjs +0 -2
  63. package/dist/rules-BYSi5HL7.mjs +0 -2
  64. package/dist/typescript-BzDAG0C4.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
- Standalone trusted config files can use the full Doctor config shape:
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
@@ -112,18 +144,12 @@ Use the Nuxt module surface for Nuxt-specific configuration:
112
144
  ```ts
113
145
  // nuxt.config.ts
114
146
  export default defineNuxtConfig({
115
- modules: [
116
- [
117
- "vite-doctor/nuxt",
118
- {
119
- config: {
120
- rules: {
121
- "nuxt/routing/prefer-nuxt-useroute": "error",
122
- },
123
- },
124
- },
125
- ],
126
- ],
147
+ modules: ["vite-doctor/nuxt"],
148
+ doctor: {
149
+ rules: {
150
+ "nuxt/routing/prefer-nuxt-useroute": "error",
151
+ },
152
+ },
127
153
  });
128
154
  ```
129
155
 
package/dist/cli.mjs CHANGED
@@ -1,53 +1,47 @@
1
1
  #!/usr/bin/env node
2
- import { c as cleanCache, i as explainRule, l as evaluateRuleApplicability, n as createReport, r as createRulesReport, u as detectProject } from "./core-jvU53IG0.mjs";
3
- import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-CPU6PJkE.mjs";
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
- //#region src/core/internal/cli.ts
10
- function parseDoctorArgs(args) {
11
- const options = {};
12
- let path = ".";
13
- for (let index = 0; index < args.length; index++) {
14
- const arg = args[index];
15
- if (arg === "--changed") options.changed = true;
16
- else if (arg === "--types") options.types = true;
17
- else if (arg === "--threads") options.threads = Number(args[++index]);
18
- else if (arg === "--coverage") options.coverage = args[++index];
19
- else if (arg === "--runtime-evidence") options.runtimeEvidence = args[++index];
20
- else if (arg === "--analyses") options.analyses = args[++index];
21
- else if (arg === "--emit-graph") options.emitGraph = true;
22
- else if (arg === "--confidence-min") options.confidenceMin = args[++index];
23
- else if (arg === "--structural-review") options.structuralReview = true;
24
- else if (arg === "--no-types") options.types = false;
25
- else if (arg === "--profile") options.profile = true;
26
- else if (arg === "--new-only") options.newOnly = true;
27
- else if (arg === "--update-baseline") options.updateBaseline = true;
28
- else if (arg === "--cache") options.cache = true;
29
- else if (arg === "--no-cache") options.cache = false;
30
- else if (arg === "--fix") options.fix = true;
31
- else if (arg === "--unsafe-fix") options.unsafeFix = true;
32
- else if (arg === "--max-warnings") options.maxWarnings = Number(args[++index]);
33
- else if (arg === "--framework") options.framework = args[++index];
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
- options,
44
- path
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 commands = /* @__PURE__ */ new Set([
274
+ const removedCommands = /* @__PURE__ */ new Set([
275
+ "run",
276
+ "ci",
282
277
  "scan",
283
- "check",
284
- "migrate",
285
- "rules",
286
- "explain",
287
- "cache"
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 removedCommands = /* @__PURE__ */ new Set(["run", "ci"]);
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
- errorHuman(`vite-doctor ${args[0]} was removed. Use your package manager scripts directly.`);
297
- return 1;
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
- addScanCommand(cli, "scan", cwd, (code) => exitCode = code);
302
- addScanCommand(cli, "check", cwd, (code) => exitCode = code);
303
- cli.command("migrate [path]", "Evaluate current source against a future runtime graph.").option("--to <target>", "Explicit target such as nuxt@5 or nitro@3.").option("--format <format>", "Machine output: json.").action(async (path = ".", options) => {
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 (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
306
- errorHuman(`No readable directory found at ${root}`);
307
- exitCode = 1;
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, options.format));
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>", "Machine output: json or sarif.").option("--framework <framework>", "Framework override.").action(async (options) => {
315
- const runOptions = { root: cwd };
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
- process.stdout.write(createRulesReport(await viteDoctorRulePacks(runOptions), runOptions.format));
347
+ validateCliRunOptions(runOptions);
348
+ process.stdout.write(createRulesReport(await viteDoctorRulePacks(runOptions), format));
318
349
  });
319
- cli.command("explain <rule>", "Explain a Doctor rule.").option("--format <format>", "Machine output: json or sarif.").option("--framework <framework>", "Framework override.").action(async (rule, options) => {
320
- const runOptions = { root: cwd };
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
- process.stdout.write(explainRule(await viteDoctorRulePacks(runOptions), rule, runOptions.format));
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
- consola.error(`Unknown cache command: ${action}`);
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
- ...normalizeDoctorCommand(args, commands)
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
- consola.error(error instanceof Error ? error.message : String(error));
345
- return 1;
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 addScanCommand(cli, name, cwd, setExitCode) {
349
- cli.command(`${name} [path]`, `Run ${name} diagnostics.`).option("--changed", "Only scan changed files.").option("--types", "Enable type-aware checks.").option("--threads <threads>", "Thread count.").option("--analyses <analyses>", "Analyses to run.").option("--profile", "Include timings.").option("--new-only", "Only report new diagnostics.").option("--cache", "Use cache.").option("--no-cache", "Disable cache.").option("--fix", "Apply safe fixes.").option("--unsafe-fix", "Apply unsafe fixes.").option("--max-warnings <count>", "Maximum warnings.").option("--framework <framework>", "Framework override.").option("--rules <rules>", "Rule selector.").option("--severity <severity>", "Minimum severity.").option("--extends <extends>", "Comma-separated rule-pack presets.").option("--since <ref>", "Git base ref.").option("--baseline <file>", "Baseline file.").option("--format <format>", "Machine output: json or sarif.").option("--config", "Unsupported in vite-doctor.").option("--trusted-config", "Unsupported in vite-doctor.").action(async (path = ".", options) => {
350
- const parsed = parseDoctorArgs([path]);
351
- applyDoctorOptions(parsed.options, options);
352
- if (options.config || options.trustedConfig) {
353
- errorHuman("Executable config loading was removed from vite-doctor. Use built-in framework auto-activation or vite-doctor/config for trusted config files.");
354
- setExitCode(1);
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
- setExitCode(await runScan(parsed.path, parsed.options, cwd));
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 runScan(path, options, cwd) {
361
- const root = resolve(cwd, path);
362
- if (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
363
- errorHuman(`No readable directory found at ${root}`);
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 errorHuman(message) {
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
- if (process.env.VITEST_WORKER_ID) console.error(message);
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 { i as DoctorSerializableConfig, n as DoctorFramework, s as RuntimeTarget, t as DoctorExtension } from "./primitives-BB8AakLb.mjs";
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?: string;
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-GYUYW1FL.mjs";
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-cx1PzoSm.mjs";
1
+ import { n as loadDoctorConfig, t as defineDoctorConfig } from "./config-BX26IYzh.mjs";
2
2
  export { defineDoctorConfig, loadDoctorConfig };