vite-doctor 0.0.2 → 0.0.4

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 (50) hide show
  1. package/README.md +11 -1
  2. package/dist/cli.mjs +204 -3
  3. package/dist/{config-B96z9mkv.d.mts → config-BmPOr4h2.d.mts} +2 -1
  4. package/dist/config.d.mts +1 -1
  5. package/dist/{core-DXS10waH.mjs → core-xDy0T1J2.mjs} +706 -66
  6. package/dist/{doctor-D_fAijfx.mjs → doctor-Bg0UJqwf.mjs} +7 -7
  7. package/dist/{index-BZ2DY0NT.d.mts → index-Cej8hbDn.d.mts} +1 -1
  8. package/dist/{index-oT29pHXX.d.mts → index-DELTN2OW.d.mts} +20 -5
  9. package/dist/index.d.mts +2 -2
  10. package/dist/index.mjs +1 -1
  11. package/dist/{module-Cy-5RxgV.mjs → module-Bhfqw7wj.mjs} +24 -6
  12. package/dist/{module-D63348VO.d.mts → module-DpsQYVY7.d.mts} +2 -2
  13. package/dist/nitro-DP7qe6zn.mjs +2 -0
  14. package/dist/nuxt.d.mts +1 -1
  15. package/dist/nuxt.mjs +1 -1
  16. package/dist/{plugin-QYmdGYMa.mjs → plugin-B-mvNSii.mjs} +2 -2
  17. package/dist/{plugin-CWjUWdmC.d.mts → plugin-BMTLuRfv.d.mts} +2 -2
  18. package/dist/plugin.d.mts +1 -1
  19. package/dist/plugin.mjs +1 -1
  20. package/dist/{primitives-mLCLAmZ3.d.mts → primitives-UOE4-YE8.d.mts} +49 -1
  21. package/dist/rule-packs/nitro/index.d.mts +2 -2
  22. package/dist/rule-packs/nitro/index.mjs +3 -3
  23. package/dist/rule-packs/nitro/rules.d.mts +2 -2
  24. package/dist/rule-packs/nitro/rules.mjs +2 -2
  25. package/dist/rule-packs/nuxt/index.d.mts +2 -2
  26. package/dist/rule-packs/nuxt/index.mjs +1 -1
  27. package/dist/rule-packs/nuxt/module.d.mts +2 -2
  28. package/dist/rule-packs/nuxt/module.mjs +1 -1
  29. package/dist/rule-packs/nuxt/rules/index.d.mts +2 -2
  30. package/dist/rule-packs/nuxt/rules/index.mjs +2 -2
  31. package/dist/rule-packs/vite/index.d.mts +1 -1
  32. package/dist/rule-packs/vite/index.mjs +1 -1
  33. package/dist/rule-packs/vite/rules/index.d.mts +1 -1
  34. package/dist/rule-packs/vite/rules/index.mjs +1 -1
  35. package/dist/rule-packs/vue/index.d.mts +1 -1
  36. package/dist/rule-packs/vue/index.mjs +1 -1
  37. package/dist/rule-packs/vue/rules.d.mts +1 -1
  38. package/dist/rule-packs/vue/rules.mjs +1 -1
  39. package/dist/{rules-TJ8mVfH6.mjs → rules-BY3D2U9g.mjs} +1 -1
  40. package/dist/rules-D233rRrp.mjs +884 -0
  41. package/dist/{rules-BELxdqAV.d.mts → rules-D_ZBKNuF.d.mts} +1 -1
  42. package/dist/rules-DdChlCWs.mjs +2 -0
  43. package/dist/{rules-Wl3xtW3p.mjs → rules-drBDqot9.mjs} +94 -15
  44. package/dist/{rules-CpZKSMoL.mjs → rules-pUteKop1.mjs} +20 -10
  45. package/dist/rules.d.mts +1 -1
  46. package/dist/rules.mjs +2 -2
  47. package/package.json +4 -2
  48. package/dist/nitro-CFxa1y5r.mjs +0 -2
  49. package/dist/rules-8_T4dDGE.mjs +0 -2
  50. package/dist/rules-Ci1PkZG_.mjs +0 -529
@@ -1,14 +1,16 @@
1
1
  import "./config-Dnzvhp-h.mjs";
2
+ import { createRequire } from "node:module";
2
3
  import { dirname, join, relative, resolve } from "pathe";
3
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
4
5
  import { createHash } from "node:crypto";
5
6
  import * as oxcParser from "oxc-parser";
6
7
  import { parseSync } from "oxc-parser";
8
+ import { defineDiagnostics, formatDiagnostic } from "nostics";
7
9
  import { glob } from "node:fs/promises";
10
+ import { satisfies, valid, validRange } from "semver";
8
11
  import { execFile } from "node:child_process";
9
12
  import { matchesGlob } from "node:path";
10
13
  import MagicString from "magic-string";
11
- import { defineDiagnostics, formatDiagnostic } from "nostics";
12
14
  import pc from "picocolors";
13
15
  //#region src/core/internal/script.ts
14
16
  function parseScript(file, source, lang = langFromFile(file)) {
@@ -121,13 +123,63 @@ function sha256$1(input) {
121
123
  return createHash("sha256").update(input).digest("hex");
122
124
  }
123
125
  //#endregion
124
- //#region src/core/primitives.ts
126
+ //#region src/core/internal-diagnostic-handles.ts
127
+ const doctorInternalDiagnostics = defineDiagnostics({ codes: {
128
+ DOC0012: {
129
+ why: (params) => `Duplicate Doctor diagnostic code "${params.code}".`,
130
+ fix: (params) => `Assign a unique Diagnostic Code instead of registering "${params.code}" twice.`
131
+ },
132
+ DOC0013: {
133
+ why: (params) => params.code ? `No Doctor diagnostic handle is registered for rule "${params.ruleId}" and code "${params.code}".` : `No Doctor diagnostic code is registered for rule "${params.ruleId}".`,
134
+ fix: "Register a Diagnostic Code for the rule before it can report diagnostics."
135
+ },
136
+ DOC0014: {
137
+ why: (params) => `Rule "${params.ruleId}" reported a diagnostic without a nostics name/code.`,
138
+ fix: "Report diagnostics through a registered Doctor nostics handle."
139
+ },
140
+ DOC0015: {
141
+ why: (params) => `Rule pack "${params.pack}" must define a non-empty recommended preset.`,
142
+ fix: "Add at least one rule ID to the rule pack recommended preset."
143
+ },
144
+ DOC0016: {
145
+ why: (params) => `Invalid Config Extends entry "${params.entry}". Use "pack/preset".`,
146
+ fix: "Use a rule-pack-qualified preset such as \"vite-doctor/vue/recommended\"."
147
+ },
148
+ DOC0017: {
149
+ why: (params) => `Unknown Rule Pack "${params.pack}" in Config Extends entry "${params.entry}".`,
150
+ fix: "Use an installed Rule Pack name or remove the Config Extends entry."
151
+ },
152
+ DOC0018: {
153
+ why: (params) => `Unknown Preset "${params.preset}" for Rule Pack "${params.pack}" in Config Extends entry "${params.entry}".`,
154
+ fix: "Use a Preset exposed by the selected Rule Pack."
155
+ },
156
+ DOC0019: {
157
+ why: (params) => `Invalid severity for rule "${params.ruleId}": ${params.severity}.`,
158
+ fix: "Use \"blocker\", \"error\", \"warn\", \"info\", or \"off\"."
159
+ },
160
+ DOC0020: {
161
+ why: (params) => `Invalid config for rule "${params.ruleId}".`,
162
+ fix: "Use \"off\", a severity string, or a [severity, options] tuple."
163
+ },
164
+ DOC0021: {
165
+ why: (params) => params.code ? `Diagnostic "${params.code}" for rule "${params.ruleId}" is missing a fix.` : `Rule "${params.ruleId}" reported a diagnostic without a fix.`,
166
+ fix: "Provide actionable nostics fix text for every Doctor diagnostic."
167
+ },
168
+ DOC0022: {
169
+ why: (params) => `Doctor could not resolve the governing runtime graph: ${params.details}`,
170
+ fix: "Install project dependencies and run Doctor from the target project package. For computed Nuxt config, make future.compatibilityVersion statically provable or run pnpm nuxt doctor so the Nuxt integration can record the resolved value."
171
+ }
172
+ } });
173
+ //#endregion
174
+ //#region src/core/diagnostic-constants.ts
125
175
  const DOCTOR_DIAGNOSTICS_DOCS_BASE = "https://vite-doctor.onmax.me/diagnostics";
176
+ //#endregion
177
+ //#region src/core/primitives.ts
126
178
  function createRule(rule) {
127
179
  return rule;
128
180
  }
129
181
  function defineRulePack(pack) {
130
- if (!pack.presets?.recommended?.length) throw new Error(`Rule pack "${pack.name}" must define a non-empty recommended preset.`);
182
+ if (!pack.presets?.recommended?.length) throw doctorInternalDiagnostics.DOC0015({ pack: pack.name });
131
183
  return pack;
132
184
  }
133
185
  function defineDoctorExtension(extension) {
@@ -166,8 +218,346 @@ function normalizeNuxtModuleSources(sources) {
166
218
  }));
167
219
  }
168
220
  //#endregion
221
+ //#region src/core/internal/runtime-graph.ts
222
+ const packageCandidates = {
223
+ nuxt: ["nuxt"],
224
+ nitro: ["nitro", "nitropack"],
225
+ h3: ["h3"],
226
+ vue: ["vue"]
227
+ };
228
+ const acceptedIdentities = {
229
+ nuxt: new Set(["nuxt", "nuxt-nightly"]),
230
+ nitro: new Set([
231
+ "nitro",
232
+ "nitropack",
233
+ "nitro-nightly"
234
+ ]),
235
+ h3: new Set(["h3", "h3-nightly"]),
236
+ vue: new Set(["vue"])
237
+ };
238
+ function resolveRuntimeGraph(root, framework) {
239
+ const rootManifest = join(root, "package.json");
240
+ const packages = {};
241
+ const edges = [];
242
+ if (framework === "nuxt") {
243
+ packages.nuxt = resolveRuntimePackage("nuxt", rootManifest, "project");
244
+ edges.push(edge("project", packages.nuxt));
245
+ packages.nitro = packages.nuxt.state === "resolved" && packages.nuxt.packageJsonPath ? resolveRuntimePackage("nitro", packages.nuxt.packageJsonPath, "nuxt") : blockedRuntime("nitro", "nuxt", packages.nuxt);
246
+ edges.push(edge("nuxt", packages.nitro));
247
+ packages.h3 = packages.nitro.state === "resolved" && packages.nitro.packageJsonPath ? resolveRuntimePackage("h3", packages.nitro.packageJsonPath, "nitro") : blockedRuntime("h3", "nitro", packages.nitro);
248
+ edges.push(edge("nitro", packages.h3));
249
+ packages.vue = resolveRuntimePackage("vue", rootManifest, "project");
250
+ edges.push(edge("project", packages.vue));
251
+ } else if (framework === "nitro") {
252
+ packages.nitro = resolveRuntimePackage("nitro", rootManifest, "project");
253
+ edges.push(edge("project", packages.nitro));
254
+ packages.h3 = packages.nitro.state === "resolved" && packages.nitro.packageJsonPath ? resolveRuntimePackage("h3", packages.nitro.packageJsonPath, "nitro") : blockedRuntime("h3", "nitro", packages.nitro);
255
+ edges.push(edge("nitro", packages.h3));
256
+ } else if (framework === "vue") {
257
+ packages.vue = resolveRuntimePackage("vue", rootManifest, "project");
258
+ edges.push(edge("project", packages.vue));
259
+ }
260
+ return {
261
+ packages,
262
+ edges
263
+ };
264
+ }
265
+ function resolveNuxtCompatibility(root, graph, manifest) {
266
+ if (!graph.packages.nuxt) return void 0;
267
+ const config = readNuxtConfig(root);
268
+ const manifestGeneratedAt = manifest?.generatedAt ? Date.parse(manifest.generatedAt) : NaN;
269
+ const configModifiedAt = config ? configModifiedTime(config.file) : void 0;
270
+ const manifestMatchesConfig = configModifiedAt === void 0 || (Number.isFinite(manifest?.nuxtConfigMtimeMs) ? manifest?.nuxtConfigMtimeMs === configModifiedAt : manifestGeneratedAt >= configModifiedAt);
271
+ if (Number.isFinite(manifestGeneratedAt) && isSupportedNuxtCompatibility(manifest?.compatibilityVersion) && manifestMatchesConfig) return {
272
+ state: "resolved",
273
+ version: manifest.compatibilityVersion,
274
+ provenance: "manifest"
275
+ };
276
+ if (config) {
277
+ const configured = readExportedCompatibilityVersion(config.file, config.text);
278
+ if (configured.state === "resolved") return {
279
+ state: "resolved",
280
+ version: configured.version,
281
+ provenance: "config",
282
+ file: config.file
283
+ };
284
+ if (configured.state === "unknown") return {
285
+ state: "unknown",
286
+ provenance: "config",
287
+ reason: configured.reason,
288
+ file: config.file
289
+ };
290
+ }
291
+ const nuxt = graph.packages.nuxt;
292
+ if (nuxt.state !== "resolved" || !nuxt.version) return {
293
+ state: "unknown",
294
+ provenance: "default",
295
+ reason: "Nuxt compatibility defaults require a resolved Nuxt version."
296
+ };
297
+ return {
298
+ state: "resolved",
299
+ version: Number(nuxt.version.split(".")[0]) >= 5 ? 5 : 4,
300
+ provenance: "default"
301
+ };
302
+ }
303
+ function isSupportedNuxtCompatibility(value) {
304
+ return value === 4 || value === 5;
305
+ }
306
+ function applyRuntimeTarget(graph, compatibility, target) {
307
+ if (!target) return {
308
+ graph,
309
+ compatibility
310
+ };
311
+ const packages = { ...graph.packages };
312
+ for (const runtime of [
313
+ "nuxt",
314
+ "nitro",
315
+ "h3",
316
+ "vue"
317
+ ]) {
318
+ const version = target[runtime];
319
+ if (!version) continue;
320
+ packages[runtime] = {
321
+ runtime,
322
+ state: "resolved",
323
+ requestedName: runtime,
324
+ name: runtime,
325
+ version,
326
+ owner: packages[runtime]?.owner ?? targetOwner(runtime),
327
+ provenance: "target",
328
+ identity: "exact"
329
+ };
330
+ }
331
+ return {
332
+ graph: {
333
+ packages,
334
+ edges: graph.edges.map((item) => ({
335
+ ...item,
336
+ state: packages[item.to]?.state ?? item.state
337
+ }))
338
+ },
339
+ compatibility: target.nuxtCompatibility === void 0 ? compatibility : {
340
+ state: "resolved",
341
+ version: target.nuxtCompatibility,
342
+ provenance: "target"
343
+ }
344
+ };
345
+ }
346
+ function resolveRuntimePackage(runtime, ownerManifest, owner) {
347
+ const ownerPackage = readPackageManifest(ownerManifest);
348
+ const require = createRequire(ownerManifest);
349
+ let lastReason = `No ${runtime} package is resolvable from ${ownerManifest}.`;
350
+ const declaredCandidates = packageCandidates[runtime].filter((name) => packageDeclaration(ownerPackage, name) !== void 0);
351
+ const candidates = declaredCandidates.length ? declaredCandidates : packageCandidates[runtime];
352
+ for (const requestedName of candidates) {
353
+ const declaration = packageDeclaration(ownerPackage, requestedName);
354
+ try {
355
+ const packageJsonPath = resolvePackageJson(require, requestedName);
356
+ const manifest = readPackageManifest(packageJsonPath);
357
+ const name = typeof manifest?.name === "string" ? manifest.name : void 0;
358
+ const version = typeof manifest?.version === "string" ? manifest.version : void 0;
359
+ const identity = packageIdentity(runtime, requestedName, name);
360
+ if (!name || !version || !valid(version)) return unknownRuntime(runtime, requestedName, owner, declaration, {
361
+ name,
362
+ version,
363
+ packageJsonPath,
364
+ reason: `Resolved ${requestedName} has no valid package name and exact semver version.`
365
+ });
366
+ if (identity === "unknown") return unknownRuntime(runtime, requestedName, owner, declaration, {
367
+ name,
368
+ version,
369
+ packageJsonPath,
370
+ reason: `Resolved ${requestedName} to unrecognized package identity ${name}.`
371
+ });
372
+ return {
373
+ runtime,
374
+ state: "resolved",
375
+ requestedName,
376
+ name,
377
+ version,
378
+ packageJsonPath,
379
+ resolvedPath: resolvePackageEntry(require, requestedName),
380
+ owner,
381
+ provenance: "node-resolve",
382
+ declaration,
383
+ identity
384
+ };
385
+ } catch (error) {
386
+ lastReason = error instanceof Error ? error.message : String(error);
387
+ }
388
+ }
389
+ const requestedName = packageCandidates[runtime][0];
390
+ return unknownRuntime(runtime, requestedName, owner, packageDeclaration(ownerPackage, requestedName), { reason: lastReason });
391
+ }
392
+ function resolvePackageJson(require, name) {
393
+ try {
394
+ return require.resolve(`${name}/package.json`);
395
+ } catch {
396
+ const entry = require.resolve(name);
397
+ let current = dirname(entry);
398
+ while (current !== dirname(current)) {
399
+ const candidate = join(current, "package.json");
400
+ if (readPackageManifest(candidate)?.name) return candidate;
401
+ current = dirname(current);
402
+ }
403
+ throw new Error(`Could not locate package.json for ${name} from ${entry}.`);
404
+ }
405
+ }
406
+ function resolvePackageEntry(require, name) {
407
+ try {
408
+ return require.resolve(name);
409
+ } catch {
410
+ return;
411
+ }
412
+ }
413
+ function packageIdentity(runtime, requestedName, actualName) {
414
+ if (!actualName || !acceptedIdentities[runtime].has(actualName)) return "unknown";
415
+ return actualName === requestedName ? "exact" : "alias";
416
+ }
417
+ function packageDeclaration(manifest, name) {
418
+ for (const key of [
419
+ "dependencies",
420
+ "devDependencies",
421
+ "peerDependencies",
422
+ "optionalDependencies"
423
+ ]) {
424
+ const dependencies = manifest?.[key];
425
+ if (dependencies && typeof dependencies === "object") {
426
+ const value = dependencies[name];
427
+ if (typeof value === "string") return value;
428
+ }
429
+ }
430
+ }
431
+ function unknownRuntime(runtime, requestedName, owner, declaration, details) {
432
+ return {
433
+ runtime,
434
+ state: "unknown",
435
+ requestedName,
436
+ owner,
437
+ provenance: "node-resolve",
438
+ declaration,
439
+ identity: details.identity ?? "unknown",
440
+ ...details
441
+ };
442
+ }
443
+ function blockedRuntime(runtime, owner, ownerInstance) {
444
+ return unknownRuntime(runtime, packageCandidates[runtime][0], owner, void 0, { reason: `Cannot resolve ${runtime} because the owning ${ownerInstance.runtime} package is unresolved.` });
445
+ }
446
+ function edge(from, instance) {
447
+ return {
448
+ from,
449
+ to: instance.runtime,
450
+ state: instance.state
451
+ };
452
+ }
453
+ function targetOwner(runtime) {
454
+ if (runtime === "nitro") return "nuxt";
455
+ if (runtime === "h3") return "nitro";
456
+ return "project";
457
+ }
458
+ function readNuxtConfig(root) {
459
+ for (const extension of [
460
+ "ts",
461
+ "mts",
462
+ "js",
463
+ "mjs",
464
+ "cjs",
465
+ "cts"
466
+ ]) {
467
+ const file = join(root, `nuxt.config.${extension}`);
468
+ if (!existsSync(file)) continue;
469
+ try {
470
+ return {
471
+ file,
472
+ text: readFileSync(file, "utf8")
473
+ };
474
+ } catch {
475
+ return null;
476
+ }
477
+ }
478
+ return null;
479
+ }
480
+ function configModifiedTime(file) {
481
+ try {
482
+ return statSync(file).mtimeMs;
483
+ } catch {
484
+ return;
485
+ }
486
+ }
487
+ function readExportedCompatibilityVersion(file, text) {
488
+ const program = parseScript(file, text);
489
+ if (!program) return /\bfuture\s*:[\s\S]{0,200}\bcompatibilityVersion\s*:/.test(text) ? {
490
+ state: "unknown",
491
+ reason: `Doctor found future.compatibilityVersion in ${file} but could not parse the exported Nuxt config safely.`
492
+ } : { state: "absent" };
493
+ const exported = program.body?.find((node) => node.type === "ExportDefaultDeclaration");
494
+ if (!exported) return { state: "absent" };
495
+ let config = unwrapExpression(exported.declaration);
496
+ if (config?.type === "CallExpression" && config.callee?.name === "defineNuxtConfig") config = unwrapExpression(config.arguments?.[0]);
497
+ if (config?.type !== "ObjectExpression") return {
498
+ state: "unknown",
499
+ reason: `The exported Nuxt config in ${file} is computed, so Doctor cannot prove the effective future.compatibilityVersion.`
500
+ };
501
+ const future = objectProperty(config, "future");
502
+ if (future.state === "absent") return future;
503
+ if (future.state === "unknown") return {
504
+ state: "unknown",
505
+ reason: `A spread in the exported Nuxt config at ${file} may define or override future.compatibilityVersion.`
506
+ };
507
+ const futureObject = unwrapExpression(future.value);
508
+ if (futureObject?.type !== "ObjectExpression") return {
509
+ state: "unknown",
510
+ reason: `Nuxt future in ${file} is computed, so Doctor cannot prove the effective compatibilityVersion.`
511
+ };
512
+ const compatibility = objectProperty(futureObject, "compatibilityVersion");
513
+ if (compatibility.state === "absent") return compatibility;
514
+ if (compatibility.state === "unknown") return {
515
+ state: "unknown",
516
+ reason: `A spread in Nuxt future at ${file} may define or override compatibilityVersion.`
517
+ };
518
+ const value = unwrapExpression(compatibility.value);
519
+ return value?.type === "Literal" && (value.value === 4 || value.value === 5) ? {
520
+ state: "resolved",
521
+ version: value.value
522
+ } : {
523
+ state: "unknown",
524
+ reason: `Nuxt future.compatibilityVersion in ${file} is not a static 4 or 5 literal.`
525
+ };
526
+ }
527
+ function unwrapExpression(node) {
528
+ let current = node;
529
+ while (current && [
530
+ "TSAsExpression",
531
+ "TSSatisfiesExpression",
532
+ "ParenthesizedExpression"
533
+ ].includes(current.type)) current = current.expression;
534
+ return current;
535
+ }
536
+ function objectProperty(object, name) {
537
+ let result = { state: "absent" };
538
+ for (const property of object.properties ?? []) {
539
+ if (property.type === "SpreadElement") {
540
+ result = { state: "unknown" };
541
+ continue;
542
+ }
543
+ const key = property.key;
544
+ if ((key?.name ?? key?.value) === name) result = {
545
+ state: "resolved",
546
+ value: property.value
547
+ };
548
+ }
549
+ return result;
550
+ }
551
+ function readPackageManifest(file) {
552
+ try {
553
+ return JSON.parse(readFileSync(resolve(file), "utf8"));
554
+ } catch {
555
+ return null;
556
+ }
557
+ }
558
+ //#endregion
169
559
  //#region src/core/internal/project.ts
170
- async function detectProject(root, requested = "auto") {
560
+ async function detectProject(root, requested = "auto", runtimeTarget) {
171
561
  const packageJson = readJson(join(root, "package.json"));
172
562
  const deps = {
173
563
  ...packageJson?.dependencies,
@@ -182,16 +572,23 @@ async function detectProject(root, requested = "auto") {
182
572
  const ssr = framework === "nuxt" || framework === "nitro" || hasVueSsrEvidence(packageJson, deps);
183
573
  const isMonorepo = existsSync(join(root, "pnpm-workspace.yaml")) || existsSync(join(root, "turbo.json"));
184
574
  const nuxt = framework === "nuxt" ? await detectNuxt(root, nuxtVersion ?? ">=4", deps) : void 0;
575
+ const detectedGraph = resolveRuntimeGraph(root, framework);
576
+ const manifest = framework === "nuxt" ? readJson(join(root, ".nuxt/doctor.manifest.json")) : null;
577
+ const targeted = applyRuntimeTarget(detectedGraph, framework === "nuxt" ? resolveNuxtCompatibility(root, detectedGraph, manifest) : void 0, runtimeTarget);
578
+ const resolvedNuxtVersion = targeted.graph.packages.nuxt?.version;
579
+ const resolvedVueVersion = targeted.graph.packages.vue?.version;
185
580
  return {
186
581
  root: resolve(root),
187
582
  framework,
188
583
  ssr,
189
- vueVersion: cleanVersion(vueVersion),
190
- nuxtVersion: nuxt ? cleanVersion(nuxtVersion ?? nuxt.version) : void 0,
584
+ vueVersion: resolvedVueVersion ?? cleanVersion(vueVersion),
585
+ nuxtVersion: nuxt ? resolvedNuxtVersion ?? cleanVersion(nuxtVersion ?? nuxt.version) : void 0,
191
586
  isMonorepo,
192
587
  packageName: packageJson?.name,
193
588
  tsconfigPath: existsSync(join(root, "tsconfig.json")) ? join(root, "tsconfig.json") : void 0,
194
- nuxt
589
+ nuxt,
590
+ runtimeGraph: targeted.graph,
591
+ nuxtCompatibility: targeted.compatibility
195
592
  };
196
593
  }
197
594
  function hasVueSsrEvidence(packageJson, deps) {
@@ -841,6 +1238,74 @@ function nativeMatch$1(value, pattern) {
841
1238
  return value === pattern || value.includes(pattern);
842
1239
  }
843
1240
  //#endregion
1241
+ //#region src/core/internal/applicability.ts
1242
+ function evaluateRuleApplicability(rule, project) {
1243
+ const requirements = {
1244
+ ...rule.meta.frameworkVersions,
1245
+ ...rule.meta.applicability?.runtimes
1246
+ };
1247
+ const results = Object.entries(requirements).map(([runtime, range]) => evaluateRuntimeRange(project, runtime, range, rule.meta.applicability?.includePrerelease));
1248
+ const compatibilityRange = rule.meta.applicability?.nuxtCompatibility;
1249
+ if (compatibilityRange) results.push(evaluateNuxtCompatibility(project, compatibilityRange));
1250
+ return combineApplicability(results);
1251
+ }
1252
+ function evaluatePackActivation(pack, project) {
1253
+ if (!pack.activation) return active();
1254
+ if (pack.activation.nuxt && project.framework !== "nuxt") return inactive(`Rule Pack ${pack.name} requires a Nuxt project.`);
1255
+ const results = [];
1256
+ if (pack.activation.nuxt) results.push(evaluateRuntimeRange(project, "nuxt", pack.activation.nuxt));
1257
+ if (Boolean(pack.activation.packages?.length || pack.activation.modules?.length)) {
1258
+ const moduleNames = new Set((project.nuxt?.modules ?? []).map((module) => module.name));
1259
+ const matched = pack.activation.packages?.some((name) => moduleNames.has(name)) || pack.activation.modules?.some((name) => moduleNames.has(name));
1260
+ results.push(matched ? active() : inactive(`Rule Pack ${pack.name} package or module activation did not match.`));
1261
+ }
1262
+ return combineApplicability(results);
1263
+ }
1264
+ function evaluateRuntimeRange(project, runtime, range, includePrerelease = false) {
1265
+ if (!validRange(range)) return unknown(`Invalid ${runtime} applicability range ${range}.`);
1266
+ const instance = project.runtimeGraph?.packages[runtime];
1267
+ if (!instance || instance.state !== "resolved" || !instance.version || !valid(instance.version)) return unknown(instance?.reason ?? `The ${runtime} runtime is unresolved.`);
1268
+ return satisfies(instance.version, range, { includePrerelease }) ? active() : inactive(`${runtime} ${instance.version} does not satisfy ${range}.`);
1269
+ }
1270
+ function evaluateNuxtCompatibility(project, range) {
1271
+ if (!validRange(range)) return unknown(`Invalid Nuxt compatibility range ${range}.`);
1272
+ const compatibility = project.nuxtCompatibility;
1273
+ if (compatibility?.state !== "resolved" || compatibility.version === void 0) return unknown(compatibility?.reason ?? "Nuxt compatibility behavior is unresolved.");
1274
+ return satisfies(`${compatibility.version}.0.0`, range) ? active() : inactive(`Nuxt compatibility ${compatibility.version} does not satisfy ${range}.`);
1275
+ }
1276
+ function combineApplicability(results) {
1277
+ if (!results.length) return active();
1278
+ const inactiveResults = results.filter((item) => item.state === "inactive");
1279
+ if (inactiveResults.length) return {
1280
+ state: "inactive",
1281
+ reasons: inactiveResults.flatMap((item) => item.reasons)
1282
+ };
1283
+ const unknownResults = results.filter((item) => item.state === "unknown");
1284
+ if (unknownResults.length) return {
1285
+ state: "unknown",
1286
+ reasons: unknownResults.flatMap((item) => item.reasons)
1287
+ };
1288
+ return active();
1289
+ }
1290
+ function active() {
1291
+ return {
1292
+ state: "active",
1293
+ reasons: []
1294
+ };
1295
+ }
1296
+ function inactive(reason) {
1297
+ return {
1298
+ state: "inactive",
1299
+ reasons: [reason]
1300
+ };
1301
+ }
1302
+ function unknown(reason) {
1303
+ return {
1304
+ state: "unknown",
1305
+ reasons: [reason]
1306
+ };
1307
+ }
1308
+ //#endregion
844
1309
  //#region src/core/internal/scan-session.ts
845
1310
  const DEFAULT_CONFIG = { cache: { dir: ".vite-doctor/cache" } };
846
1311
  var MemoryRuleCache = class {
@@ -894,7 +1359,7 @@ async function createScanSession(options) {
894
1359
  };
895
1360
  markSession(sessionBase, "config", started);
896
1361
  started = performance.now();
897
- const project = await detectProject(root, options.framework ?? "auto");
1362
+ const project = await detectProject(root, options.framework ?? "auto", options.runtimeTarget);
898
1363
  const projectDefaults = project.framework === "nuxt" ? mergeDoctorConfig(DEFAULT_CONFIG, { cache: { dir: ".nuxt/doctor/cache" } }) : DEFAULT_CONFIG;
899
1364
  if (projectDefaults !== DEFAULT_CONFIG || project.nuxt?.doctorConfig) {
900
1365
  config = mergeDoctorConfig(mergeDoctorConfig(projectDefaults, project.nuxt?.doctorConfig), options.config);
@@ -1004,31 +1469,34 @@ async function applyProjectContributions(project, registry) {
1004
1469
  };
1005
1470
  }
1006
1471
  }
1007
- function isActivePack(pack, project) {
1008
- if (!pack.activation) return true;
1009
- if (pack.activation.nuxt && project.framework !== "nuxt") return false;
1010
- if (!Boolean(pack.activation.packages?.length || pack.activation.modules?.length)) return true;
1011
- const moduleNames = new Set((project.nuxt?.modules ?? []).map((module) => module.name));
1012
- return Boolean(pack.activation.packages?.some((name) => moduleNames.has(name)) || pack.activation.modules?.some((name) => moduleNames.has(name)));
1013
- }
1014
1472
  function selectRules(registry, ruleConfigs, options, project) {
1015
1473
  const wanted = options.rules?.split(",").map((item) => item.trim()).filter(Boolean);
1016
1474
  const selectedRules = resolveExtends(registry.packs, options, project);
1017
- return registry.rules.filter((rule) => selectedRules.has(rule.meta.id)).filter((rule) => !rule.meta.requires?.nuxt || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.nitro || project.framework === "nitro" || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.vue || project.framework === "vue" || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.types || options.types).filter((rule) => supportsFrameworkVersion(rule, project)).filter((rule) => !wanted?.length || wanted.some((pattern) => nativeMatch$1(rule.meta.id, pattern))).filter((rule) => resolvedConfig(ruleConfigs, rule.meta.id).enabled);
1475
+ return registry.rules.filter((rule) => selectedRules.has(rule.meta.id)).filter((rule) => !rule.meta.requires?.nuxt || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.nitro || project.framework === "nitro" || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.vue || project.framework === "vue" || project.framework === "nuxt").filter((rule) => !rule.meta.requires?.types || options.types).filter((rule) => !wanted?.length || wanted.some((pattern) => nativeMatch$1(rule.meta.id, pattern))).filter((rule) => resolvedConfig(ruleConfigs, rule.meta.id).enabled).map((rule) => ({
1476
+ rule,
1477
+ applicability: evaluateRuleApplicability(rule, project)
1478
+ })).filter((item) => item.applicability.state === "active").map((item) => item.rule);
1018
1479
  }
1019
1480
  function resolveExtends(packs, options, project) {
1020
1481
  const requested = options.extends ?? options.config?.extends ?? "auto";
1021
- if (requested === "auto") return new Set(packs.filter((pack) => isActivePack(pack, project)).flatMap((pack) => pack.presets.recommended));
1482
+ if (requested === "auto") return new Set(packs.filter((pack) => evaluatePackActivation(pack, project).state === "active").flatMap((pack) => pack.presets.recommended));
1022
1483
  const selected = /* @__PURE__ */ new Set();
1023
1484
  for (const entry of requested) {
1024
1485
  const slash = entry.lastIndexOf("/");
1025
- if (slash === -1) throw new Error(`Invalid extends entry "${entry}". Use "pack/preset".`);
1486
+ if (slash === -1) throw doctorInternalDiagnostics.DOC0016({ entry });
1026
1487
  const packKey = entry.slice(0, slash);
1027
1488
  const presetName = entry.slice(slash + 1);
1028
1489
  const pack = packs.find((item) => rulePackKey(item) === packKey || item.name === packKey);
1029
- if (!pack) throw new Error(`Unknown rule pack in extends entry "${entry}".`);
1490
+ if (!pack) throw doctorInternalDiagnostics.DOC0017({
1491
+ entry,
1492
+ pack: packKey
1493
+ });
1030
1494
  const preset = pack.presets[presetName];
1031
- if (!preset) throw new Error(`Unknown preset in extends entry "${entry}".`);
1495
+ if (!preset) throw doctorInternalDiagnostics.DOC0018({
1496
+ entry,
1497
+ pack: pack.name,
1498
+ preset: presetName
1499
+ });
1032
1500
  for (const ruleId of preset) selected.add(ruleId);
1033
1501
  }
1034
1502
  return selected;
@@ -1052,7 +1520,10 @@ function resolveRuleConfigs(config) {
1052
1520
  }
1053
1521
  if (Array.isArray(value)) {
1054
1522
  const [severity, options] = value;
1055
- if (!isSeverity(severity)) throw new Error(`Invalid severity for rule "${ruleId}": ${String(severity)}`);
1523
+ if (!isSeverity(severity)) throw doctorInternalDiagnostics.DOC0019({
1524
+ ruleId,
1525
+ severity: String(severity)
1526
+ });
1056
1527
  resolved.set(ruleId, {
1057
1528
  enabled: true,
1058
1529
  severity,
@@ -1060,7 +1531,7 @@ function resolveRuleConfigs(config) {
1060
1531
  });
1061
1532
  continue;
1062
1533
  }
1063
- throw new Error(`Invalid config for rule "${ruleId}".`);
1534
+ throw doctorInternalDiagnostics.DOC0020({ ruleId });
1064
1535
  }
1065
1536
  return resolved;
1066
1537
  }
@@ -1073,37 +1544,6 @@ function resolvedConfig(ruleConfigs, ruleId) {
1073
1544
  function isSeverity(value) {
1074
1545
  return value === "blocker" || value === "error" || value === "warn" || value === "info";
1075
1546
  }
1076
- function supportsFrameworkVersion(rule, project) {
1077
- const vue = rule.meta.frameworkVersions?.vue;
1078
- if (vue && !satisfiesVersion(project.vueVersion, vue)) return false;
1079
- const nuxt = rule.meta.frameworkVersions?.nuxt;
1080
- if (nuxt && !project.nuxtVersion) return false;
1081
- if (nuxt && project.nuxtVersion && !satisfiesVersion(project.nuxtVersion, nuxt)) return false;
1082
- return true;
1083
- }
1084
- function satisfiesVersion(version, range) {
1085
- const match = range.trim().match(/^(>=|>|<=|<|=)?\s*(\d+(?:\.\d+){0,2})/);
1086
- if (!match) return true;
1087
- const operator = match[1] ?? "=";
1088
- const comparison = compareVersions(version, match[2]);
1089
- if (operator === ">=") return comparison >= 0;
1090
- if (operator === ">") return comparison > 0;
1091
- if (operator === "<=") return comparison <= 0;
1092
- if (operator === "<") return comparison < 0;
1093
- return comparison === 0;
1094
- }
1095
- function compareVersions(left, right) {
1096
- const leftParts = numericVersionParts(left);
1097
- const rightParts = numericVersionParts(right);
1098
- for (let index = 0; index < 3; index++) {
1099
- const diff = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);
1100
- if (diff) return diff;
1101
- }
1102
- return 0;
1103
- }
1104
- function numericVersionParts(version) {
1105
- return version.replace(/^[^\d]*/, "").split(/[.-]/).slice(0, 3).map((part) => Number.parseInt(part, 10) || 0);
1106
- }
1107
1547
  function createCacheKey(session, phase, input) {
1108
1548
  return `${phase}:${sha256(JSON.stringify({
1109
1549
  version: VERSION,
@@ -1523,7 +1963,7 @@ function createDoctorDiagnosticsHost() {
1523
1963
  defineDiagnostics: defineDoctorDiagnostics,
1524
1964
  register(registry) {
1525
1965
  for (const [code, handle] of Object.entries(registry.diagnostics)) {
1526
- if (logger[code]) throw new Error(`Duplicate Doctor diagnostic code: ${code}`);
1966
+ if (logger[code]) throw doctorInternalDiagnostics.DOC0012({ code });
1527
1967
  logger[code] = handle;
1528
1968
  }
1529
1969
  },
@@ -1531,6 +1971,12 @@ function createDoctorDiagnosticsHost() {
1531
1971
  };
1532
1972
  }
1533
1973
  const doctorDiagnosticsHost = createDoctorDiagnosticsHost();
1974
+ function codeForRuleId(codesByRuleId, ruleId) {
1975
+ return codesByRuleId[ruleId];
1976
+ }
1977
+ function diagnosticForCode(diagnostics, code) {
1978
+ return code ? diagnostics[code] : void 0;
1979
+ }
1534
1980
  function defineDoctorDiagnostics(entries) {
1535
1981
  const codes = Object.fromEntries(entries.map((entry) => [entry.code, {
1536
1982
  why: (params) => params.why,
@@ -1596,6 +2042,60 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
1596
2042
  code: "DOC0011",
1597
2043
  ruleId: "workspace/health/high-fan-out"
1598
2044
  },
2045
+ {
2046
+ code: "DOC0012",
2047
+ ruleId: "doctor/internal/duplicate-diagnostic-code",
2048
+ docs: false
2049
+ },
2050
+ {
2051
+ code: "DOC0013",
2052
+ ruleId: "doctor/internal/missing-diagnostic-code",
2053
+ docs: false
2054
+ },
2055
+ {
2056
+ code: "DOC0014",
2057
+ ruleId: "doctor/internal/missing-diagnostic-name",
2058
+ docs: false
2059
+ },
2060
+ {
2061
+ code: "DOC0015",
2062
+ ruleId: "doctor/rule-pack/missing-recommended-preset",
2063
+ docs: false
2064
+ },
2065
+ {
2066
+ code: "DOC0016",
2067
+ ruleId: "doctor/config/invalid-extends-entry",
2068
+ docs: false
2069
+ },
2070
+ {
2071
+ code: "DOC0017",
2072
+ ruleId: "doctor/config/unknown-rule-pack",
2073
+ docs: false
2074
+ },
2075
+ {
2076
+ code: "DOC0018",
2077
+ ruleId: "doctor/config/unknown-preset",
2078
+ docs: false
2079
+ },
2080
+ {
2081
+ code: "DOC0019",
2082
+ ruleId: "doctor/config/invalid-rule-severity",
2083
+ docs: false
2084
+ },
2085
+ {
2086
+ code: "DOC0020",
2087
+ ruleId: "doctor/config/invalid-rule-config",
2088
+ docs: false
2089
+ },
2090
+ {
2091
+ code: "DOC0021",
2092
+ ruleId: "doctor/internal/missing-diagnostic-fix",
2093
+ docs: false
2094
+ },
2095
+ {
2096
+ code: "DOC0022",
2097
+ ruleId: "doctor/inventory/unresolved-runtime"
2098
+ },
1599
2099
  {
1600
2100
  code: "VUE0001",
1601
2101
  ruleId: "vue/i18n/no-untranslated-text"
@@ -1824,6 +2324,30 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
1824
2324
  code: "NITRO0011",
1825
2325
  ruleId: "nitro/server/prefer-event-fetch"
1826
2326
  },
2327
+ {
2328
+ code: "NITRO0012",
2329
+ ruleId: "nitro/request/prefer-route-method-suffix"
2330
+ },
2331
+ {
2332
+ code: "NITRO0013",
2333
+ ruleId: "nitro/runtime/no-event-runtime-config-in-server"
2334
+ },
2335
+ {
2336
+ code: "NITRO0014",
2337
+ ruleId: "nitro/migration/no-v2-imports"
2338
+ },
2339
+ {
2340
+ code: "NITRO0015",
2341
+ ruleId: "nitro/h3/no-removed-send"
2342
+ },
2343
+ {
2344
+ code: "NITRO0016",
2345
+ ruleId: "nitro/h3/prefer-redirect-response"
2346
+ },
2347
+ {
2348
+ code: "NITRO0017",
2349
+ ruleId: "nitro/h3/prefer-with-base"
2350
+ },
1827
2351
  {
1828
2352
  code: "NUXT0001",
1829
2353
  ruleId: "docus/appconfig/no-unknown-key"
@@ -2111,11 +2635,15 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
2111
2635
  {
2112
2636
  code: "NUXT0072",
2113
2637
  ruleId: "vueuse/prefer-usewindow-size"
2638
+ },
2639
+ {
2640
+ code: "NUXT0073",
2641
+ ruleId: "nuxt/config/no-ignored-compatibility-config"
2114
2642
  }
2115
2643
  ]);
2116
2644
  const allDiagnosticCodesByRuleId = allDoctorDiagnosticRegistry.codesByRuleId;
2117
2645
  doctorDiagnosticsHost.register(allDoctorDiagnosticRegistry);
2118
- const allDiagnostics = doctorDiagnosticsHost.logger;
2646
+ const allDiagnostics = allDoctorDiagnosticRegistry.diagnostics;
2119
2647
  //#endregion
2120
2648
  //#region src/core/internal/diagnostics.ts
2121
2649
  function applyRequestedFixes(session) {
@@ -2197,7 +2725,11 @@ function createDiagnosticFingerprint(root, diagnostic, file) {
2197
2725
  function normalizeDiagnostic(input) {
2198
2726
  const diagnostic = input.diagnostic;
2199
2727
  const code = diagnostic.name;
2200
- if (!code) throw new Error(`Doctor diagnostic is missing a nostics name/code.`);
2728
+ if (!code) throw doctorInternalDiagnostics.DOC0014({ ruleId: input.ruleId });
2729
+ if (!diagnostic.fix) throw doctorInternalDiagnostics.DOC0021({
2730
+ ruleId: input.ruleId,
2731
+ code
2732
+ });
2201
2733
  return {
2202
2734
  ...input,
2203
2735
  diagnostic,
@@ -2210,15 +2742,22 @@ function normalizeDiagnostic(input) {
2210
2742
  };
2211
2743
  }
2212
2744
  function normalizeDiagnosticFromRuleCode(input) {
2213
- const code = input.code ?? allDiagnosticCodesByRuleId[input.ruleId] ?? "DOC9999";
2745
+ const code = input.code ?? codeForRuleId(allDiagnosticCodesByRuleId, input.ruleId) ?? "DOC9999";
2214
2746
  const why = input.why ?? input.message ?? input.diagnostic?.why ?? "Doctor diagnostic";
2215
- const fix = input.suggestion ?? input.diagnostic?.fix ?? input.fix?.message ?? why;
2216
- const diagnostic = input.diagnostic ?? allDiagnostics[code]?.({
2747
+ const fix = input.suggestion ?? input.diagnostic?.fix ?? input.fix?.message;
2748
+ if (!fix) throw doctorInternalDiagnostics.DOC0021({
2749
+ ruleId: input.ruleId,
2750
+ code
2751
+ });
2752
+ const diagnostic = input.diagnostic ?? diagnosticForCode(allDiagnostics, code)?.({
2217
2753
  why,
2218
2754
  fix,
2219
2755
  sources: input.sources
2220
2756
  });
2221
- if (!diagnostic) throw new Error(`No Doctor diagnostic code registered for ${input.ruleId}.`);
2757
+ if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
2758
+ ruleId: input.ruleId,
2759
+ code
2760
+ });
2222
2761
  return {
2223
2762
  ...input,
2224
2763
  diagnostic,
@@ -2252,6 +2791,37 @@ function pushDiagnostic(session, diagnostic) {
2252
2791
  })
2253
2792
  });
2254
2793
  }
2794
+ function reportRuntimeInventoryUnknown(session) {
2795
+ const unresolved = (session.project.framework === "nuxt" ? [
2796
+ "nuxt",
2797
+ "nitro",
2798
+ "h3"
2799
+ ] : session.project.framework === "nitro" ? ["nitro", "h3"] : session.project.framework === "vue" ? ["vue"] : []).map((runtime) => session.project.runtimeGraph?.packages[runtime]).filter((item) => item?.state === "unknown");
2800
+ const details = [...unresolved.map((item) => `${item?.owner} -> ${item?.runtime}: ${item?.reason ?? "unresolved"}`), ...session.project.nuxtCompatibility?.state === "unknown" ? [`Nuxt compatibility: ${session.project.nuxtCompatibility.reason ?? "unresolved"}`] : []];
2801
+ if (!details.length) return;
2802
+ const runtimeFix = "Install project dependencies and run Doctor from the target project package. If the project uses Yarn PnP, run Doctor through Yarn so its loader is active.";
2803
+ const compatibilityFix = "Make the effective future.compatibilityVersion statically provable in nuxt.config, or run pnpm nuxt doctor so the Nuxt integration can record the resolved value.";
2804
+ const compatibilityUnknown = session.project.nuxtCompatibility?.state === "unknown";
2805
+ pushDiagnostic(session, {
2806
+ ruleId: "doctor/inventory/unresolved-runtime",
2807
+ severity: "warn",
2808
+ category: "inventory",
2809
+ file: unresolved.length || !compatibilityUnknown ? resolve(session.root, "package.json") : session.project.nuxtCompatibility?.file ?? resolve(session.root, "package.json"),
2810
+ why: `Doctor could not resolve the governing runtime graph: ${details.join("; ")}`,
2811
+ suggestion: [unresolved.length ? runtimeFix : void 0, compatibilityUnknown ? compatibilityFix : void 0].filter(Boolean).join(" "),
2812
+ evidence: [...unresolved.map((item) => ({
2813
+ kind: "manifest",
2814
+ summary: `${item?.owner} -> ${item?.runtime} is unresolved.`,
2815
+ file: item?.packageJsonPath
2816
+ })), ...session.project.nuxtCompatibility?.state === "unknown" ? [{
2817
+ kind: "manifest",
2818
+ summary: "Nuxt compatibility behavior is unresolved.",
2819
+ file: session.project.nuxtCompatibility?.file ?? session.project.nuxt?.manifestPath
2820
+ }] : []],
2821
+ confidence: "manifest-backed",
2822
+ analysisPhase: "manifest"
2823
+ });
2824
+ }
2255
2825
  function defaultConfidenceForPhase(phase) {
2256
2826
  if (phase === "graph") return "proven";
2257
2827
  if (phase === "type") return "type-backed";
@@ -2491,6 +3061,7 @@ function runDeadCodeRules(session, graph) {
2491
3061
  severity: "error",
2492
3062
  category: "dead-code",
2493
3063
  message: `Import "${item.source}" could not be resolved.`,
3064
+ suggestion: "Fix the import specifier or add the missing source file.",
2494
3065
  file: fact.path,
2495
3066
  range: item.range,
2496
3067
  confidence: "proven",
@@ -2507,6 +3078,7 @@ function runDeadCodeRules(session, graph) {
2507
3078
  severity: "info",
2508
3079
  category: "dead-code",
2509
3080
  message: "File is not reachable from known package, framework, or manifest roots.",
3081
+ suggestion: "Remove the file or import it from a package, framework, or manifest root.",
2510
3082
  file: fact.path,
2511
3083
  confidence: "manifest-backed",
2512
3084
  evidence: [{
@@ -2522,6 +3094,7 @@ function runDeadCodeRules(session, graph) {
2522
3094
  severity: "info",
2523
3095
  category: "dead-code",
2524
3096
  message: `Export "${exp.name}" is not referenced by known imports or framework roots.`,
3097
+ suggestion: `Remove export "${exp.name}" or import it from reachable code.`,
2525
3098
  file: fact.path,
2526
3099
  range: exp.range,
2527
3100
  confidence: exp.kind === "type" ? "type-backed" : "proven",
@@ -2538,6 +3111,7 @@ function runDeadCodeRules(session, graph) {
2538
3111
  severity: "info",
2539
3112
  category: "dead-code",
2540
3113
  message: `Dependency "${dep}" is declared but was not imported by scanned source files.`,
3114
+ suggestion: `Remove "${dep}" from package.json or import it from scanned source code.`,
2541
3115
  file: resolve(session.root, "package.json"),
2542
3116
  confidence: "heuristic-medium",
2543
3117
  evidence: [{
@@ -2551,6 +3125,7 @@ function runDeadCodeRules(session, graph) {
2551
3125
  severity: "warn",
2552
3126
  category: "dead-code",
2553
3127
  message: `Package "${dep}" is imported but is not listed in package.json dependencies.`,
3128
+ suggestion: `Add "${dep}" to package.json dependencies or remove the import.`,
2554
3129
  file: resolve(session.root, "package.json"),
2555
3130
  confidence: "proven",
2556
3131
  evidence: [{
@@ -2568,6 +3143,7 @@ function runCycleAndDuplicateExportRules(session, graph) {
2568
3143
  severity: "warn",
2569
3144
  category: "architecture",
2570
3145
  message: `Circular dependency detected across ${files.length} files.`,
3146
+ suggestion: "Break the cycle by moving shared code into an acyclic module.",
2571
3147
  file: files[0],
2572
3148
  related: files.slice(1).map((file) => ({
2573
3149
  file,
@@ -2589,6 +3165,7 @@ function runCycleAndDuplicateExportRules(session, graph) {
2589
3165
  severity: "warn",
2590
3166
  category: "architecture",
2591
3167
  message: `Export name "${name}" appears in multiple files.`,
3168
+ suggestion: `Rename or consolidate duplicate export "${name}" so imports resolve unambiguously.`,
2592
3169
  file: files[0],
2593
3170
  related: files.slice(1).map((file) => ({
2594
3171
  file,
@@ -2619,6 +3196,7 @@ function runDuplicationRules(session) {
2619
3196
  severity: "info",
2620
3197
  category: "duplication",
2621
3198
  message: `Repeated token window detected in ${files.length} files.`,
3199
+ suggestion: "Extract the repeated code into a shared helper or keep one intentional copy.",
2622
3200
  file: files[0],
2623
3201
  related: files.slice(1).map((file) => ({
2624
3202
  file,
@@ -2641,6 +3219,7 @@ function runHealthRules(session) {
2641
3219
  severity: "warn",
2642
3220
  category: "health",
2643
3221
  message: `File has cyclomatic complexity ${fact.complexity.cyclomatic}.`,
3222
+ suggestion: "Split complex branches into smaller rules, helpers, or modules.",
2644
3223
  file: fact.path,
2645
3224
  confidence: "heuristic-high",
2646
3225
  evidence: [{
@@ -2654,6 +3233,7 @@ function runHealthRules(session) {
2654
3233
  severity: "info",
2655
3234
  category: "health",
2656
3235
  message: `File imports ${fact.imports.length} modules.`,
3236
+ suggestion: "Reduce fan-out by moving cohesive dependencies behind smaller modules.",
2657
3237
  file: fact.path,
2658
3238
  confidence: "heuristic-high",
2659
3239
  evidence: [{
@@ -2918,9 +3498,6 @@ function createRuleContext(session, initialFile, rule, phase = "file") {
2918
3498
  file = nextFile;
2919
3499
  },
2920
3500
  report(diagnostic, metadata) {
2921
- const sources = diagnostic.sources ? [...diagnostic.sources] : rule.meta.docsUrl ? [rule.meta.docsUrl] : void 0;
2922
- if (rule.meta.docsUrl && sources && !sources.includes(rule.meta.docsUrl)) sources.push(rule.meta.docsUrl);
2923
- if (sources?.length) diagnostic.sources = sources;
2924
3501
  const input = normalizeDiagnostic({
2925
3502
  ...metadata,
2926
3503
  diagnostic,
@@ -3046,6 +3623,60 @@ const coreDiagnosticRegistry = defineDoctorDiagnostics([
3046
3623
  {
3047
3624
  code: "DOC0011",
3048
3625
  ruleId: "workspace/health/high-fan-out"
3626
+ },
3627
+ {
3628
+ code: "DOC0012",
3629
+ ruleId: "doctor/internal/duplicate-diagnostic-code",
3630
+ docs: false
3631
+ },
3632
+ {
3633
+ code: "DOC0013",
3634
+ ruleId: "doctor/internal/missing-diagnostic-code",
3635
+ docs: false
3636
+ },
3637
+ {
3638
+ code: "DOC0014",
3639
+ ruleId: "doctor/internal/missing-diagnostic-name",
3640
+ docs: false
3641
+ },
3642
+ {
3643
+ code: "DOC0015",
3644
+ ruleId: "doctor/rule-pack/missing-recommended-preset",
3645
+ docs: false
3646
+ },
3647
+ {
3648
+ code: "DOC0016",
3649
+ ruleId: "doctor/config/invalid-extends-entry",
3650
+ docs: false
3651
+ },
3652
+ {
3653
+ code: "DOC0017",
3654
+ ruleId: "doctor/config/unknown-rule-pack",
3655
+ docs: false
3656
+ },
3657
+ {
3658
+ code: "DOC0018",
3659
+ ruleId: "doctor/config/unknown-preset",
3660
+ docs: false
3661
+ },
3662
+ {
3663
+ code: "DOC0019",
3664
+ ruleId: "doctor/config/invalid-rule-severity",
3665
+ docs: false
3666
+ },
3667
+ {
3668
+ code: "DOC0020",
3669
+ ruleId: "doctor/config/invalid-rule-config",
3670
+ docs: false
3671
+ },
3672
+ {
3673
+ code: "DOC0021",
3674
+ ruleId: "doctor/internal/missing-diagnostic-fix",
3675
+ docs: false
3676
+ },
3677
+ {
3678
+ code: "DOC0022",
3679
+ ruleId: "doctor/inventory/unresolved-runtime"
3049
3680
  }
3050
3681
  ]);
3051
3682
  coreDiagnosticRegistry.diagnostics;
@@ -3056,6 +3687,12 @@ function createTextReport(result) {
3056
3687
  const lines = [];
3057
3688
  lines.push(`Detected: ${frameworkLabel(result)}`);
3058
3689
  lines.push(`Workspace: ${result.root}`);
3690
+ for (const edge of result.project.runtimeGraph?.edges ?? []) {
3691
+ const runtime = result.project.runtimeGraph?.packages[edge.to];
3692
+ const identity = runtime?.state === "resolved" ? `${runtime.name}@${runtime.version}${runtime.packageJsonPath ? ` (${runtime.packageJsonPath})` : ""}` : `unknown${runtime?.reason ? ` (${runtime.reason})` : ""}`;
3693
+ lines.push(`Runtime: ${edge.from} -> ${edge.to} ${identity}`);
3694
+ }
3695
+ if (result.project.nuxtCompatibility) lines.push(`Nuxt compatibility: ${result.project.nuxtCompatibility.state === "resolved" ? result.project.nuxtCompatibility.version : "unknown"} (${result.project.nuxtCompatibility.provenance})`);
3059
3696
  lines.push(`Health score: ${result.score}/100`);
3060
3697
  if (result.project.nuxt?.manifest) {
3061
3698
  const evidence = result.project.nuxt.manifest.evidence;
@@ -3121,7 +3758,9 @@ function createJsonReport(result) {
3121
3758
  suppressedDiagnostics: result.suppressedDiagnostics?.map(serializeDiagnostic),
3122
3759
  timings: result.timings,
3123
3760
  phases: result.phases,
3124
- graph: result.graph
3761
+ graph: result.graph,
3762
+ runtimeGraph: result.project.runtimeGraph,
3763
+ nuxtCompatibility: result.project.nuxtCompatibility
3125
3764
  }, null, 2)}\n`;
3126
3765
  }
3127
3766
  function createSarifReport(result) {
@@ -3247,7 +3886,7 @@ function labelSeverity(severity) {
3247
3886
  return severity === "blocker" ? "Blockers" : severity === "error" ? "Errors" : severity === "warn" ? "Warnings" : "Info";
3248
3887
  }
3249
3888
  function codeListForRule(ruleId) {
3250
- const code = allDiagnosticCodesByRuleId[ruleId];
3889
+ const code = codeForRuleId(allDiagnosticCodesByRuleId, ruleId);
3251
3890
  return code ? [code] : [];
3252
3891
  }
3253
3892
  function indent(value, prefix) {
@@ -3284,6 +3923,7 @@ function serializeDiagnostic(diagnostic) {
3284
3923
  //#region src/core/index.ts
3285
3924
  async function runDoctor(options = {}) {
3286
3925
  const session = await createScanSession(options);
3926
+ reportRuntimeInventoryUnknown(session);
3287
3927
  await runPhase(session, "parseFileFacts", () => parseSourceFiles(session));
3288
3928
  await runPhase(session, "fileRules", () => runFileRules(session));
3289
3929
  await runPhase(session, "manifestRules", () => runManifestRules(session));
@@ -3301,4 +3941,4 @@ async function runDoctor(options = {}) {
3301
3941
  return result;
3302
3942
  }
3303
3943
  //#endregion
3304
- export { defineDoctorDiagnostics as a, defineDoctorExtension as c, explainRule as i, defineRulePack as l, createReport as n, cleanCache as o, createRulesReport as r, createRule as s, runDoctor as t };
3944
+ export { codeForRuleId as a, cleanCache as c, createRule as d, defineDoctorExtension as f, explainRule as i, evaluateRuleApplicability as l, doctorInternalDiagnostics as m, createReport as n, defineDoctorDiagnostics as o, defineRulePack as p, createRulesReport as r, diagnosticForCode as s, runDoctor as t, detectProject as u };