vite-doctor 0.0.1-alpha.1 → 0.0.1

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 (42) hide show
  1. package/dist/cli-main-DCJWk1En.mjs +175 -0
  2. package/dist/cli-main-DZtwLzMZ.d.mts +4 -0
  3. package/dist/cli.d.mts +1 -3
  4. package/dist/cli.mjs +3 -141
  5. package/dist/config-D5OZt0fD-B9Flpubz.d.mts +39 -0
  6. package/dist/doctor-Bwq3I7XL.mjs +6334 -0
  7. package/dist/index.d.mts +2 -25
  8. package/dist/index.mjs +2 -2
  9. package/dist/nuxt-cli.d.mts +2 -0
  10. package/dist/nuxt-cli.mjs +9 -0
  11. package/dist/nuxt.d.mts +8 -453
  12. package/dist/nuxt.mjs +36 -8566
  13. package/dist/plugin-_P7sALMl.mjs +77 -0
  14. package/dist/plugin-vLTZiLbe.d.mts +23 -0
  15. package/dist/plugin.d.mts +2 -20
  16. package/dist/plugin.mjs +1 -44
  17. package/dist/primitives-DdFGPkcF-ByGjY1Ra.d.mts +556 -0
  18. package/dist/rules-DFU2Qgly.mjs +5581 -0
  19. package/dist/rules.d.mts +41 -0
  20. package/dist/rules.mjs +2 -0
  21. package/package.json +32 -23
  22. package/dist/_format-B2HI7dfh.mjs +0 -21
  23. package/dist/chunk-Vs_PY4HZ.mjs +0 -37
  24. package/dist/dist-8lLfIOP2.mjs +0 -500
  25. package/dist/doctor-_N6Ivxkm.mjs +0 -37
  26. package/dist/jiti-CKNfQMe-.mjs +0 -5460
  27. package/dist/jiti-R7_DrxGt.mjs +0 -3
  28. package/dist/json5-6m_qGRPT.mjs +0 -775
  29. package/dist/jsonc-BE4T3qGL.mjs +0 -399
  30. package/dist/jsonc-CLHNv_ud.mjs +0 -2
  31. package/dist/main-DLCb8JN7.mjs +0 -272
  32. package/dist/nypm-B42YpMR7.mjs +0 -671
  33. package/dist/nypm-V_7qwBzU.mjs +0 -2
  34. package/dist/ohash-DJf_Wz36.mjs +0 -183
  35. package/dist/prompt-BtRxIZzP.mjs +0 -847
  36. package/dist/rolldown-runtime-DRLVd5Gq.mjs +0 -13
  37. package/dist/rules-C0Oyy6lY-ClEeab_k.mjs +0 -167037
  38. package/dist/src-CuYgaMvh.mjs +0 -1173
  39. package/dist/src-DrZYBMKC.mjs +0 -63
  40. package/dist/tar-C2j71EuP.mjs +0 -2933
  41. package/dist/toml-DQFyLJNX.mjs +0 -644
  42. package/dist/yaml-BXFm6QiY.mjs +0 -1065
@@ -0,0 +1,175 @@
1
+ import { A as explainRule, C as cleanCache, D as createRulesReport, T as createReport } from "./rules-DFU2Qgly.mjs";
2
+ import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-Bwq3I7XL.mjs";
3
+ import { resolve } from "pathe";
4
+ import { statSync } from "node:fs";
5
+ import { cac } from "cac";
6
+ import { consola } from "consola";
7
+ //#region ../core/dist/internal/cli.mjs
8
+ function parseDoctorArgs(args) {
9
+ const options = {};
10
+ let path = ".";
11
+ for (let index = 0; index < args.length; index++) {
12
+ const arg = args[index];
13
+ if (arg === "--changed") options.changed = true;
14
+ else if (arg === "--types") options.types = true;
15
+ else if (arg === "--threads") options.threads = Number(args[++index]);
16
+ else if (arg === "--coverage") options.coverage = args[++index];
17
+ else if (arg === "--runtime-evidence") options.runtimeEvidence = args[++index];
18
+ else if (arg === "--analyses") options.analyses = args[++index];
19
+ else if (arg === "--emit-graph") options.emitGraph = true;
20
+ else if (arg === "--confidence-min") options.confidenceMin = args[++index];
21
+ else if (arg === "--structural-review") options.structuralReview = true;
22
+ else if (arg === "--no-types") options.types = false;
23
+ else if (arg === "--profile") options.profile = true;
24
+ else if (arg === "--new-only") options.newOnly = true;
25
+ else if (arg === "--update-baseline") options.updateBaseline = true;
26
+ else if (arg === "--cache") options.cache = true;
27
+ else if (arg === "--no-cache") options.cache = false;
28
+ else if (arg === "--fix") options.fix = true;
29
+ else if (arg === "--unsafe-fix") options.unsafeFix = true;
30
+ else if (arg === "--max-warnings") options.maxWarnings = Number(args[++index]);
31
+ else if (arg === "--framework") options.framework = args[++index];
32
+ else if (arg === "--rules") options.rules = args[++index];
33
+ else if (arg === "--severity") options.severity = args[++index];
34
+ else if (arg === "--extends") options.extends = parseExtends(args[++index]);
35
+ else if (arg === "--since") options.since = args[++index];
36
+ else if (arg === "--baseline") options.baseline = args[++index];
37
+ else if (arg === "--format") options.format = args[++index];
38
+ else if (!arg.startsWith("-")) path = arg;
39
+ }
40
+ return {
41
+ options,
42
+ path
43
+ };
44
+ }
45
+ function applyDoctorOptions(options, flags) {
46
+ if (flags.changed) options.changed = true;
47
+ if (flags.types) options.types = true;
48
+ if (flags.threads) options.threads = Number(flags.threads);
49
+ options.coverage = stringFlag(flags.coverage) ?? options.coverage;
50
+ options.runtimeEvidence = stringFlag(flags.runtimeEvidence) ?? options.runtimeEvidence;
51
+ options.analyses = stringFlag(flags.analyses) ?? options.analyses;
52
+ if (flags.emitGraph) options.emitGraph = true;
53
+ options.confidenceMin = stringFlag(flags.confidenceMin) ?? options.confidenceMin;
54
+ if (flags.structuralReview) options.structuralReview = true;
55
+ if (flags.types === false) options.types = false;
56
+ if (flags.profile) options.profile = true;
57
+ if (flags.newOnly) options.newOnly = true;
58
+ if (flags.updateBaseline) options.updateBaseline = true;
59
+ if (flags.cache) options.cache = true;
60
+ if (flags.cache === false) options.cache = false;
61
+ if (flags.fix) options.fix = true;
62
+ if (flags.unsafeFix) options.unsafeFix = true;
63
+ if (flags.maxWarnings !== void 0) options.maxWarnings = Number(flags.maxWarnings);
64
+ options.framework = stringFlag(flags.framework) ?? options.framework;
65
+ options.rules = stringFlag(flags.rules) ?? options.rules;
66
+ options.severity = stringFlag(flags.severity) ?? options.severity;
67
+ options.extends = parseExtendsFlag(flags.extends) ?? options.extends;
68
+ options.since = stringFlag(flags.since) ?? options.since;
69
+ options.baseline = stringFlag(flags.baseline) ?? options.baseline;
70
+ options.format = stringFlag(flags.format) ?? options.format;
71
+ }
72
+ function parseExtends(value) {
73
+ if (!value || value === "auto") return "auto";
74
+ return value.split(",").map((item) => item.trim()).filter(Boolean);
75
+ }
76
+ function parseExtendsFlag(value) {
77
+ return typeof value === "string" ? parseExtends(value) : void 0;
78
+ }
79
+ function stringFlag(value) {
80
+ return typeof value === "string" ? value : void 0;
81
+ }
82
+ function normalizeDoctorCommand(args, commands) {
83
+ const first = args.find((arg) => !arg.startsWith("-"));
84
+ if (!first) return ["scan", ...args];
85
+ if (commands.has(first)) return args;
86
+ return ["scan", ...args];
87
+ }
88
+ //#endregion
89
+ //#region src/cli-main.ts
90
+ const commands = new Set([
91
+ "scan",
92
+ "check",
93
+ "rules",
94
+ "explain",
95
+ "cache"
96
+ ]);
97
+ const removedCommands = new Set(["run", "ci"]);
98
+ async function main(args = process.argv.slice(2), cwd = process.cwd()) {
99
+ if (args.includes("--version") || args.includes("-v")) {
100
+ process.stdout.write(`${viteDoctorVersion}\n`);
101
+ return 0;
102
+ }
103
+ if (removedCommands.has(args[0] ?? "")) {
104
+ errorHuman(`vite-doctor ${args[0]} was removed. Use your package manager scripts directly.`);
105
+ return 1;
106
+ }
107
+ let exitCode = 0;
108
+ const cli = cac("vite-doctor");
109
+ addScanCommand(cli, "scan", cwd, (code) => exitCode = code);
110
+ addScanCommand(cli, "check", cwd, (code) => exitCode = code);
111
+ cli.command("rules", "List available Doctor rules.").option("--format <format>", "Machine output: json or sarif.").option("--framework <framework>", "Framework override.").action(async (options) => {
112
+ const runOptions = {};
113
+ applyDoctorOptions(runOptions, options);
114
+ process.stdout.write(createRulesReport(await viteDoctorRulePacks(runOptions), runOptions.format));
115
+ });
116
+ 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) => {
117
+ const runOptions = {};
118
+ applyDoctorOptions(runOptions, options);
119
+ process.stdout.write(explainRule(await viteDoctorRulePacks(runOptions), rule, runOptions.format));
120
+ });
121
+ cli.command("cache <action>", "Manage Doctor cache.").action((action) => {
122
+ if (action === "clean") {
123
+ cleanCache(cwd);
124
+ consola.log("Doctor cache cleaned");
125
+ return;
126
+ }
127
+ consola.error(`Unknown cache command: ${action}`);
128
+ exitCode = 1;
129
+ });
130
+ cli.help();
131
+ try {
132
+ cli.parse([
133
+ "node",
134
+ "vite-doctor",
135
+ ...normalizeDoctorCommand(args, commands)
136
+ ], { run: false });
137
+ const result = await cli.runMatchedCommand();
138
+ if (typeof result === "number") exitCode = result;
139
+ return exitCode;
140
+ } catch (error) {
141
+ consola.error(error instanceof Error ? error.message : String(error));
142
+ return 1;
143
+ }
144
+ }
145
+ function addScanCommand(cli, name, cwd, setExitCode) {
146
+ 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) => {
147
+ const parsed = parseDoctorArgs([path]);
148
+ applyDoctorOptions(parsed.options, options);
149
+ if (options.config || options.trustedConfig) {
150
+ errorHuman("Executable config loading was removed from vite-doctor. Use built-in framework auto-activation or @vue-doctor/core/config for trusted config files.");
151
+ setExitCode(1);
152
+ return;
153
+ }
154
+ setExitCode(await runScan(parsed.path, parsed.options, cwd));
155
+ });
156
+ }
157
+ async function runScan(path, options, cwd) {
158
+ const root = resolve(cwd, path);
159
+ if (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
160
+ errorHuman(`No readable directory found at ${root}`);
161
+ return 1;
162
+ }
163
+ const result = await runViteDoctor({
164
+ ...options,
165
+ root
166
+ });
167
+ process.stdout.write(createReport(result, options.format));
168
+ return shouldFailDoctorRun(result, options.maxWarnings) ? 1 : 0;
169
+ }
170
+ function errorHuman(message) {
171
+ consola.error(message);
172
+ if (process.env.VITEST_WORKER_ID) console.error(message);
173
+ }
174
+ //#endregion
175
+ export { main as t };
@@ -0,0 +1,4 @@
1
+ //#region src/cli-main.d.ts
2
+ declare function main(args?: string[], cwd?: string): Promise<number>;
3
+ //#endregion
4
+ export { main as t };
package/dist/cli.d.mts CHANGED
@@ -1,4 +1,2 @@
1
- //#region src/cli.d.ts
2
- declare function main(args?: string[], cwd?: string): Promise<number>;
3
- //#endregion
1
+ import { t as main } from "./cli-main-DZtwLzMZ.mjs";
4
2
  export { main };
package/dist/cli.mjs CHANGED
@@ -1,147 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { i as planCi } from "./src-DrZYBMKC.mjs";
3
- import { _ as createReport, r as cleanCache, v as createRulesReport, y as explainRule } from "./rules-C0Oyy6lY-ClEeab_k.mjs";
4
- import { n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-_N6Ivxkm.mjs";
5
- import { statSync } from "node:fs";
6
- import { spawn } from "node:child_process";
2
+ import { t as main } from "./cli-main-DCJWk1En.mjs";
3
+ import { realpathSync } from "node:fs";
7
4
  import { fileURLToPath } from "node:url";
8
- import { resolve } from "pathe";
9
5
  //#region src/cli.ts
10
- async function main(args = process.argv.slice(2), cwd = process.cwd()) {
11
- const dryRun = args.includes("--dry-run");
12
- const firstPositional = args.find((arg) => !arg.startsWith("-"));
13
- const command = firstPositional ? isCommand(firstPositional) ? firstPositional : "scan" : "run";
14
- if (args.includes("--help") || args.includes("-h")) {
15
- printHelp();
16
- return 0;
17
- }
18
- if (command === "rules") {
19
- const { options } = parseRunArgs(args.filter((arg) => arg !== command));
20
- process.stdout.write(createRulesReport(viteDoctorRulePacks(), options.format));
21
- return 0;
22
- }
23
- if (command === "explain") {
24
- const rest = args.filter((arg) => arg !== command);
25
- const ruleId = rest.find((arg) => !arg.startsWith("-")) ?? "";
26
- const { options } = parseRunArgs(rest.filter((arg) => arg !== ruleId));
27
- process.stdout.write(explainRule(viteDoctorRulePacks(), ruleId, options.format));
28
- return 0;
29
- }
30
- if (command === "cache" && args.includes("clean")) {
31
- cleanCache(cwd);
32
- console.log("Doctor cache cleaned");
33
- return 0;
34
- }
35
- if (command === "scan" || command === "check") {
36
- const { path, options } = parseRunArgs(args.filter((arg) => arg !== command));
37
- const root = resolve(cwd, path);
38
- if (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
39
- console.error(`No readable directory found at ${root}`);
40
- return 1;
41
- }
42
- const result = await runViteDoctor({
43
- ...options,
44
- root
45
- });
46
- process.stdout.write(createReport(result, options.format));
47
- return shouldFailDoctorRun(result, options.maxWarnings) ? 1 : 0;
48
- }
49
- if (command !== "run" && command !== "ci") {
50
- console.error(`Unknown command: ${command}`);
51
- return 1;
52
- }
53
- let plan;
54
- try {
55
- plan = planCi(cwd);
56
- } catch (error) {
57
- console.error(error instanceof Error ? error.message : String(error));
58
- return 1;
59
- }
60
- console.log(`Package manager: ${plan.packageManager}`);
61
- console.log("Commands:");
62
- for (const item of plan.commands) console.log(`- ${item.display}`);
63
- if (dryRun) return 0;
64
- for (const item of plan.commands) {
65
- const exitCode = await runCommand(item, cwd);
66
- if (exitCode !== 0) return exitCode;
67
- }
68
- return 0;
69
- }
70
- function printHelp() {
71
- console.log(`vite-doctor
72
-
73
- Usage:
74
- vite-doctor [run] [--dry-run]
75
- vite-doctor [path]
76
- vite-doctor scan [path]
77
- vite-doctor check [path]
78
- vite-doctor rules [--format json]
79
-
80
- Runs the project's existing scripts with the detected package manager by default.`);
81
- }
82
- function parseRunArgs(args) {
83
- const options = {};
84
- let path = ".";
85
- for (let index = 0; index < args.length; index++) {
86
- const arg = args[index];
87
- if (arg === "--trusted-config" || arg === "--config") options.config = true;
88
- else if (arg === "--changed") options.changed = true;
89
- else if (arg === "--types") options.types = true;
90
- else if (arg === "--threads") options.threads = Number(args[++index]);
91
- else if (arg === "--analyses") options.analyses = args[++index];
92
- else if (arg === "--profile") options.profile = true;
93
- else if (arg === "--new-only") options.newOnly = true;
94
- else if (arg === "--cache") options.cache = true;
95
- else if (arg === "--no-cache") options.cache = false;
96
- else if (arg === "--fix") options.fix = true;
97
- else if (arg === "--unsafe-fix") options.unsafeFix = true;
98
- else if (arg === "--max-warnings") options.maxWarnings = Number(args[++index]);
99
- else if (arg === "--framework") options.framework = args[++index];
100
- else if (arg === "--rules") options.rules = args[++index];
101
- else if (arg === "--severity") options.severity = args[++index];
102
- else if (arg === "--preset") options.preset = args[++index];
103
- else if (arg === "--since") options.since = args[++index];
104
- else if (arg === "--baseline") options.baseline = args[++index];
105
- else if (arg === "--format") options.format = args[++index];
106
- else if (!arg.startsWith("-")) path = arg;
107
- }
108
- return {
109
- path,
110
- options
111
- };
112
- }
113
- function isCommand(value) {
114
- return [
115
- "run",
116
- "ci",
117
- "rules",
118
- "explain",
119
- "cache",
120
- "scan",
121
- "check"
122
- ].includes(value);
123
- }
124
- function runCommand(item, cwd) {
125
- return new Promise((resolve) => {
126
- const child = spawn(item.command, item.args, {
127
- cwd,
128
- stdio: "inherit"
129
- });
130
- child.on("error", (error) => {
131
- console.error(`Failed to run ${item.display}: ${error.message}`);
132
- resolve(1);
133
- });
134
- child.on("close", (code, signal) => {
135
- if (signal) {
136
- console.error(`${item.display} exited from signal ${signal}`);
137
- resolve(1);
138
- return;
139
- }
140
- resolve(code ?? 1);
141
- });
142
- });
143
- }
144
6
  const currentFile = fileURLToPath(import.meta.url);
145
- if (process.argv[1] === currentFile) process.exitCode = await main();
7
+ if (process.argv[1] && realpathSync(process.argv[1]) === currentFile) process.exitCode = await main();
146
8
  //#endregion
147
9
  export { main };
@@ -0,0 +1,39 @@
1
+ import { i as DoctorSerializableConfig, n as DoctorFramework, t as DoctorExtension } from "./primitives-DdFGPkcF-ByGjY1Ra.mjs";
2
+
3
+ //#region ../core/dist/config-D5OZt0fD.d.mts
4
+ //#region src/config.d.ts
5
+ interface DoctorConfig extends DoctorSerializableConfig {
6
+ extensions?: DoctorExtension[];
7
+ }
8
+ interface DoctorRunOptions {
9
+ root?: string;
10
+ /** Already-loaded Doctor config. */
11
+ config?: DoctorConfig;
12
+ framework?: "auto" | DoctorFramework;
13
+ extends?: "auto" | string[];
14
+ changed?: boolean;
15
+ since?: string;
16
+ format?: string;
17
+ baseline?: string;
18
+ updateBaseline?: boolean;
19
+ newOnly?: boolean;
20
+ severity?: "error" | "warn" | "info";
21
+ rules?: string;
22
+ types?: boolean;
23
+ threads?: number;
24
+ coverage?: string;
25
+ runtimeEvidence?: string;
26
+ analyses?: string;
27
+ emitGraph?: boolean;
28
+ confidenceMin?: string;
29
+ structuralReview?: boolean;
30
+ profile?: boolean;
31
+ cache?: boolean;
32
+ fix?: boolean;
33
+ unsafeFix?: boolean;
34
+ scoreOnly?: boolean;
35
+ maxWarnings?: number;
36
+ extensions?: DoctorExtension[];
37
+ }
38
+ //#endregion
39
+ export { DoctorRunOptions as n, DoctorConfig as t };