vite-doctor 0.0.3 → 0.0.5

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 (55) hide show
  1. package/README.md +11 -1
  2. package/dist/cli.mjs +206 -5
  3. package/dist/{config-B96z9mkv.d.mts → config-CXNytHmY.d.mts} +2 -2
  4. package/dist/{config-Dnzvhp-h.mjs → config-cx1PzoSm.mjs} +3 -2
  5. package/dist/config.d.mts +1 -1
  6. package/dist/config.mjs +1 -1
  7. package/dist/{core-WTY_jAiL.mjs → core-DIaW0HIr.mjs} +518 -58
  8. package/dist/{doctor-DfkqNcNR.mjs → doctor-yC2Ke8Ae.mjs} +7 -7
  9. package/dist/{index-CFlFH8Pi.d.mts → index-B8FjkmY1.d.mts} +17 -6
  10. package/dist/index-Benbi54b.d.mts +3 -0
  11. package/dist/{index-BZ2DY0NT.d.mts → index-DxuqP4UF.d.mts} +1 -2
  12. package/dist/index-xAh4vxLh.d.mts +1 -0
  13. package/dist/index.d.mts +2 -2
  14. package/dist/index.mjs +2 -2
  15. package/dist/{module-Cy-5RxgV.mjs → module-DHwkZLxN.mjs} +25 -7
  16. package/dist/{module-D63348VO.d.mts → module-DtYfgazD.d.mts} +3 -2
  17. package/dist/nitro-BRgJaQgL.mjs +2 -0
  18. package/dist/nuxt.d.mts +1 -1
  19. package/dist/nuxt.mjs +1 -1
  20. package/dist/{plugin-CWjUWdmC.d.mts → plugin-Dnhz_kMz.d.mts} +3 -3
  21. package/dist/{plugin-7rCuA-AZ.mjs → plugin-tOk2jSfx.mjs} +2 -2
  22. package/dist/plugin.d.mts +1 -1
  23. package/dist/plugin.mjs +1 -1
  24. package/dist/{primitives-mLCLAmZ3.d.mts → primitives-Nhpqd5ap.d.mts} +49 -2
  25. package/dist/rule-packs/nitro/index.d.mts +3 -2
  26. package/dist/rule-packs/nitro/index.mjs +3 -3
  27. package/dist/rule-packs/nitro/rules.d.mts +2 -2
  28. package/dist/rule-packs/nitro/rules.mjs +2 -2
  29. package/dist/rule-packs/nuxt/index.d.mts +2 -2
  30. package/dist/rule-packs/nuxt/index.mjs +1 -1
  31. package/dist/rule-packs/nuxt/module.d.mts +2 -2
  32. package/dist/rule-packs/nuxt/module.mjs +1 -1
  33. package/dist/rule-packs/nuxt/rules/index.d.mts +4 -2
  34. package/dist/rule-packs/nuxt/rules/index.mjs +2 -2
  35. package/dist/rule-packs/vite/index.d.mts +1 -1
  36. package/dist/rule-packs/vite/index.mjs +1 -1
  37. package/dist/rule-packs/vite/rules/index.d.mts +1 -1
  38. package/dist/rule-packs/vite/rules/index.mjs +1 -1
  39. package/dist/rule-packs/vue/index.d.mts +1 -1
  40. package/dist/rule-packs/vue/index.mjs +1 -1
  41. package/dist/rule-packs/vue/rules.d.mts +1 -1
  42. package/dist/rule-packs/vue/rules.mjs +1 -1
  43. package/dist/{rules-cyFhFs4w.mjs → rules-0AWH0_wP.mjs} +19 -18
  44. package/dist/rules-CPBmmZ0K.mjs +2 -0
  45. package/dist/{rules-M6yUv7EP.mjs → rules-CQY9fsh1.mjs} +97 -23
  46. package/dist/{rules-BDMsIiOi.mjs → rules-Cp2zeuza.mjs} +210 -46
  47. package/dist/{rules-BELxdqAV.d.mts → rules-D66KCcT1.d.mts} +1 -2
  48. package/dist/{rules-DBiaAWeX.mjs → rules-DPvqsm4U.mjs} +15 -14
  49. package/dist/rules.d.mts +1 -1
  50. package/dist/rules.mjs +2 -2
  51. package/package.json +29 -28
  52. package/dist/index-BKZ67WMa.d.mts +0 -1
  53. package/dist/index-BVVgDSdq.d.mts +0 -1
  54. package/dist/nitro-D2XxIgEp.mjs +0 -2
  55. package/dist/rules-BGjZej-N.mjs +0 -2
package/README.md CHANGED
@@ -22,7 +22,7 @@ Run Vite Doctor from the project root:
22
22
  pnpm dlx vite-doctor .
23
23
  ```
24
24
 
25
- Vite Doctor reads app code, build config, project metadata, and server handlers to catch framework bugs before review. It picks the Nuxt, Vue, Nitro, or Vite diagnostics that fit your project.
25
+ Vite Doctor reads app code, build config, project metadata, and server handlers to catch framework bugs before review. It resolves the installed Nuxt, Nitro, and H3 runtime graph and picks diagnostics that match the versions the framework actually loads.
26
26
 
27
27
  Need a narrower Doctor Run? Select exact presets, one Rule, or a framework override:
28
28
 
@@ -41,6 +41,16 @@ pnpm nuxt doctor
41
41
 
42
42
  Use `--framework` only when Doctor cannot identify the framework automatically.
43
43
 
44
+ Check a migration before changing dependencies:
45
+
46
+ ```bash
47
+ pnpm dlx vite-doctor migrate .
48
+ pnpm dlx vite-doctor migrate . --to nuxt@5 --format json
49
+ pnpm dlx vite-doctor migrate . --to nitro@3
50
+ ```
51
+
52
+ The migration report stages source changes that are safe on the installed runtime, then dependency, configuration, and source changes that must land together, followed by checks that require the target runtime. It does not rewrite the project.
53
+
44
54
  ## Configuration
45
55
 
46
56
  Standalone trusted config files can use the full Doctor config shape:
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { c as cleanCache, i as explainRule, n as createReport, r as createRulesReport } from "./core-WTY_jAiL.mjs";
3
- import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-DfkqNcNR.mjs";
4
- import { resolve } from "pathe";
2
+ import { c as cleanCache, i as explainRule, l as evaluateRuleApplicability, n as createReport, r as createRulesReport, u as detectProject } from "./core-DIaW0HIr.mjs";
3
+ import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-yC2Ke8Ae.mjs";
4
+ import { relative, resolve } from "pathe";
5
5
  import { realpathSync, statSync } from "node:fs";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { cac } from "cac";
@@ -88,15 +88,205 @@ function normalizeDoctorCommand(args, commands) {
88
88
  return ["scan", ...args];
89
89
  }
90
90
  //#endregion
91
+ //#region src/migration.ts
92
+ async function createMigrationReport(root, requestedTargets = []) {
93
+ const current = await detectProject(root);
94
+ const targetSpec = requestedTargets.length ? parseExplicitTargets(requestedTargets) : inferTarget(current);
95
+ validateTargetFramework(current.framework, targetSpec.requested);
96
+ const targetProject = await detectProject(root, current.framework, targetSpec.runtime);
97
+ const packs = await viteDoctorRulePacks({
98
+ root,
99
+ framework: current.framework
100
+ });
101
+ const activated = [];
102
+ const retained = [];
103
+ const migrationRuleIds = [];
104
+ for (const rule of packs.flatMap((pack) => pack.rules)) {
105
+ const currentState = evaluateRuleApplicability(rule, current).state;
106
+ if (evaluateRuleApplicability(rule, targetProject).state !== "active") continue;
107
+ if (currentState === "active") retained.push(rule.meta.id);
108
+ else activated.push(rule.meta.id);
109
+ if (currentState !== "active" || rule.meta.category === "migration" || rule.meta.applicability) migrationRuleIds.push(rule.meta.id);
110
+ }
111
+ const diagnostics = (await runViteDoctor({
112
+ root,
113
+ framework: current.framework,
114
+ runtimeTarget: targetSpec.runtime,
115
+ rules: migrationRuleIds.length ? migrationRuleIds.join(",") : "__doctor_no_rules__",
116
+ cache: false
117
+ })).diagnostics.filter((item) => item.ruleId !== "doctor/inventory/unresolved-runtime").map((item) => migrationDiagnostic(root, item));
118
+ const activatedRules = new Set(activated);
119
+ const sourceDiagnostics = diagnostics.filter((item) => !activatedRules.has(item.ruleId));
120
+ const targetDiagnostics = diagnostics.filter((item) => activatedRules.has(item.ruleId));
121
+ const changes = dependencyChanges(current, targetSpec.requested, targetSpec.runtime);
122
+ return {
123
+ version: viteDoctorVersion,
124
+ reportVersion: 1,
125
+ command: "migrate",
126
+ root,
127
+ framework: current.framework,
128
+ target: targetSpec,
129
+ applicability: {
130
+ activated: activated.sort(),
131
+ retained: retained.sort()
132
+ },
133
+ stages: [
134
+ {
135
+ id: "source",
136
+ title: "Safe source changes before the dependency upgrade",
137
+ diagnostics: sourceDiagnostics
138
+ },
139
+ {
140
+ id: "dependencies",
141
+ title: "Dependency, configuration, and coupled source changes",
142
+ diagnostics: targetDiagnostics,
143
+ changes
144
+ },
145
+ {
146
+ id: "deferred",
147
+ title: "Checks after the target runtime is installed",
148
+ checks: [
149
+ {
150
+ id: "install-target",
151
+ instruction: "Install the target dependency graph with the project package manager."
152
+ },
153
+ {
154
+ id: "rerun-doctor",
155
+ instruction: "Run vite-doctor again without migrate so Doctor verifies the runtime versions that were actually installed."
156
+ },
157
+ {
158
+ id: "run-project-checks",
159
+ instruction: "Run the project's type checks, tests, and production build on the installed target."
160
+ }
161
+ ]
162
+ }
163
+ ],
164
+ summary: {
165
+ diagnostics: diagnostics.length,
166
+ errors: diagnostics.filter((item) => item.severity === "blocker" || item.severity === "error").length,
167
+ warnings: diagnostics.filter((item) => item.severity === "warn").length,
168
+ dependencyChanges: changes.length
169
+ }
170
+ };
171
+ }
172
+ function formatMigrationReport(report, format = "text") {
173
+ if (format === "json") return `${JSON.stringify(report, null, 2)}\n`;
174
+ const lines = [
175
+ `Migration target: ${report.target.requested.join(", ")} (${report.target.source})`,
176
+ `Workspace: ${report.root}`,
177
+ ""
178
+ ];
179
+ for (const stage of report.stages) {
180
+ lines.push(stage.title);
181
+ if (stage.id === "source") {
182
+ if (!stage.diagnostics.length) lines.push(" No source changes detected.");
183
+ for (const diagnostic of stage.diagnostics) {
184
+ const location = diagnostic.range ? `${diagnostic.file}:${diagnostic.range.line}:${diagnostic.range.column}` : diagnostic.file;
185
+ lines.push(` ${diagnostic.code} ${location}`);
186
+ lines.push(` ${diagnostic.why}`);
187
+ lines.push(` Fix: ${diagnostic.fix}`);
188
+ }
189
+ } else if (stage.id === "dependencies") {
190
+ if (!stage.changes.length && !stage.diagnostics.length) lines.push(" No dependency, config, or coupled source changes inferred.");
191
+ for (const change of stage.changes) lines.push(` ${change.instruction}`);
192
+ for (const diagnostic of stage.diagnostics) {
193
+ const location = diagnostic.range ? `${diagnostic.file}:${diagnostic.range.line}:${diagnostic.range.column}` : diagnostic.file;
194
+ lines.push(` ${diagnostic.code} ${location}`);
195
+ lines.push(` ${diagnostic.why}`);
196
+ lines.push(` Fix with the target upgrade: ${diagnostic.fix}`);
197
+ }
198
+ } else for (const check of stage.checks) lines.push(` ${check.instruction}`);
199
+ lines.push("");
200
+ }
201
+ lines.push(`Summary: ${report.summary.diagnostics} diagnostics, ${report.summary.dependencyChanges} dependency/config changes`);
202
+ return `${lines.join("\n")}\n`;
203
+ }
204
+ function inferTarget(project) {
205
+ const nuxt = project.runtimeGraph?.packages.nuxt;
206
+ const nitro = project.runtimeGraph?.packages.nitro;
207
+ if (project.framework === "nuxt" && nuxt?.state === "resolved" && major(nuxt.version) < 5) return targetFromRequested(["nuxt@5"], "inferred");
208
+ if ((project.framework === "nuxt" || project.framework === "nitro") && nitro?.state === "resolved" && major(nitro.version) < 3) return targetFromRequested(["nitro@3"], "inferred");
209
+ throw new Error("Doctor cannot infer one supported next runtime target from the installed graph. Pass --to nuxt@5 or --to nitro@3.");
210
+ }
211
+ function parseExplicitTargets(targets) {
212
+ return targetFromRequested(targets.flatMap((target) => target.split(",")).map((target) => target.trim()).filter(Boolean), "explicit");
213
+ }
214
+ function validateTargetFramework(framework, targets) {
215
+ for (const target of targets) if (!(target === "nuxt@5" ? framework === "nuxt" : target === "nitro@3" && (framework === "nuxt" || framework === "nitro"))) throw new Error(`Migration target ${target} is not supported for ${framework} projects.`);
216
+ }
217
+ function targetFromRequested(requested, source) {
218
+ const runtime = {};
219
+ for (const target of requested) {
220
+ if (target === "nuxt@5") {
221
+ runtime.nuxt = "5.0.0-0";
222
+ runtime.nitro = "3.0.0-0";
223
+ runtime.h3 = "2.0.0-0";
224
+ runtime.nuxtCompatibility = 5;
225
+ continue;
226
+ }
227
+ if (target === "nitro@3") {
228
+ runtime.nitro = "3.0.0-0";
229
+ runtime.h3 = "2.0.0-0";
230
+ continue;
231
+ }
232
+ throw new Error(`Unsupported migration target "${target}". Use nuxt@5 or nitro@3.`);
233
+ }
234
+ if (!requested.length) throw new Error("Migration requires at least one target.");
235
+ return {
236
+ source,
237
+ requested,
238
+ runtime
239
+ };
240
+ }
241
+ function dependencyChanges(project, requested, runtime) {
242
+ const changes = [];
243
+ for (const target of requested) {
244
+ const [runtimeName, targetMajor] = target.split("@");
245
+ const current = project.runtimeGraph?.packages[runtimeName];
246
+ const packageName = runtimeName === "nitro" && current?.name === "nitropack" ? "nitro" : runtimeName;
247
+ changes.push({
248
+ kind: "dependency",
249
+ package: packageName,
250
+ from: current?.version,
251
+ to: `${packageName}@${targetMajor}`,
252
+ instruction: `Update ${current?.name ?? packageName}${current?.version ? ` from ${current.version}` : ""} to ${packageName}@${targetMajor}.`
253
+ });
254
+ }
255
+ if (runtime.nuxtCompatibility === 5 && project.nuxtCompatibility?.version !== 5) {
256
+ const unknownCompatibility = project.nuxtCompatibility?.state === "unknown";
257
+ changes.push({
258
+ kind: "config",
259
+ to: "future.compatibilityVersion: 5",
260
+ instruction: unknownCompatibility ? "Verify that the effective future.compatibilityVersion resolves to 5; Doctor could not prove it from the composed Nuxt config." : "Set future.compatibilityVersion to 5 while preparing the Nuxt upgrade, then resolve the reported compatibility diagnostics."
261
+ });
262
+ }
263
+ return changes;
264
+ }
265
+ function migrationDiagnostic(root, diagnostic) {
266
+ return {
267
+ code: diagnostic.code,
268
+ ruleId: diagnostic.ruleId,
269
+ severity: diagnostic.severity,
270
+ file: relative(root, diagnostic.file),
271
+ range: diagnostic.range,
272
+ why: diagnostic.why,
273
+ fix: diagnostic.suggestion ?? diagnostic.diagnostic.fix ?? "Review this migration diagnostic."
274
+ };
275
+ }
276
+ function major(version) {
277
+ return Number(version?.split(".")[0] ?? NaN);
278
+ }
279
+ //#endregion
91
280
  //#region src/cli-main.ts
92
- const commands = new Set([
281
+ const commands = /* @__PURE__ */ new Set([
93
282
  "scan",
94
283
  "check",
284
+ "migrate",
95
285
  "rules",
96
286
  "explain",
97
287
  "cache"
98
288
  ]);
99
- const removedCommands = new Set(["run", "ci"]);
289
+ const removedCommands = /* @__PURE__ */ new Set(["run", "ci"]);
100
290
  async function main(args = process.argv.slice(2), cwd = process.cwd()) {
101
291
  if (args.includes("--version") || args.includes("-v")) {
102
292
  process.stdout.write(`${viteDoctorVersion}\n`);
@@ -110,6 +300,17 @@ async function main(args = process.argv.slice(2), cwd = process.cwd()) {
110
300
  const cli = cac("vite-doctor");
111
301
  addScanCommand(cli, "scan", cwd, (code) => exitCode = code);
112
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) => {
304
+ const root = resolve(cwd, path);
305
+ if (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
306
+ errorHuman(`No readable directory found at ${root}`);
307
+ exitCode = 1;
308
+ return;
309
+ }
310
+ const report = await createMigrationReport(root, options.to ? [options.to] : []);
311
+ process.stdout.write(formatMigrationReport(report, options.format));
312
+ exitCode = report.summary.errors > 0 ? 1 : 0;
313
+ });
113
314
  cli.command("rules", "List available Doctor rules.").option("--format <format>", "Machine output: json or sarif.").option("--framework <framework>", "Framework override.").action(async (options) => {
114
315
  const runOptions = { root: cwd };
115
316
  applyDoctorOptions(runOptions, options);
@@ -1,5 +1,4 @@
1
- import { i as DoctorSerializableConfig, n as DoctorFramework, t as DoctorExtension } from "./primitives-mLCLAmZ3.mjs";
2
-
1
+ import { i as DoctorSerializableConfig, n as DoctorFramework, s as RuntimeTarget, t as DoctorExtension } from "./primitives-Nhpqd5ap.mjs";
3
2
  //#region src/core/config.d.ts
4
3
  interface DoctorConfig extends DoctorSerializableConfig {
5
4
  extensions?: DoctorExtension[];
@@ -33,6 +32,7 @@ interface DoctorRunOptions {
33
32
  scoreOnly?: boolean;
34
33
  maxWarnings?: number;
35
34
  extensions?: DoctorExtension[];
35
+ runtimeTarget?: RuntimeTarget;
36
36
  }
37
37
  declare function defineDoctorConfig(config: DoctorConfig): DoctorConfig;
38
38
  interface LoadDoctorConfigOptions {
@@ -5,13 +5,14 @@ function defineDoctorConfig(config) {
5
5
  return config;
6
6
  }
7
7
  async function loadDoctorConfig(options) {
8
- return defu((await loadConfig({
8
+ const result = await loadConfig({
9
9
  configFile: "doctor.config",
10
10
  cwd: options.cwd,
11
11
  dotenv: false,
12
12
  globalRc: false,
13
13
  name: "doctor"
14
- })).config ?? {}, options.defaults ?? {});
14
+ });
15
+ return defu(result.config ?? {}, options.defaults ?? {});
15
16
  }
16
17
  //#endregion
17
18
  export { loadDoctorConfig as n, defineDoctorConfig as t };
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-B96z9mkv.mjs";
1
+ import { a as loadDoctorConfig, i as defineDoctorConfig, n as DoctorRunOptions, r as LoadDoctorConfigOptions, t as DoctorConfig } from "./config-CXNytHmY.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-Dnzvhp-h.mjs";
1
+ import { n as loadDoctorConfig, t as defineDoctorConfig } from "./config-cx1PzoSm.mjs";
2
2
  export { defineDoctorConfig, loadDoctorConfig };