vite-doctor 0.0.0 → 0.0.1-alpha.2

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.
@@ -0,0 +1,76 @@
1
+ //#region ../core/dist/internal/cli.mjs
2
+ function parseDoctorArgs(args) {
3
+ const options = {};
4
+ let path = ".";
5
+ for (let index = 0; index < args.length; index++) {
6
+ const arg = args[index];
7
+ if (arg === "--changed") options.changed = true;
8
+ else if (arg === "--types") options.types = true;
9
+ else if (arg === "--threads") options.threads = Number(args[++index]);
10
+ else if (arg === "--coverage") options.coverage = args[++index];
11
+ else if (arg === "--runtime-evidence") options.runtimeEvidence = args[++index];
12
+ else if (arg === "--analyses") options.analyses = args[++index];
13
+ else if (arg === "--emit-graph") options.emitGraph = true;
14
+ else if (arg === "--confidence-min") options.confidenceMin = args[++index];
15
+ else if (arg === "--structural-review") options.structuralReview = true;
16
+ else if (arg === "--no-types") options.types = false;
17
+ else if (arg === "--profile") options.profile = true;
18
+ else if (arg === "--new-only") options.newOnly = true;
19
+ else if (arg === "--update-baseline") options.updateBaseline = true;
20
+ else if (arg === "--cache") options.cache = true;
21
+ else if (arg === "--no-cache") options.cache = false;
22
+ else if (arg === "--fix") options.fix = true;
23
+ else if (arg === "--unsafe-fix") options.unsafeFix = true;
24
+ else if (arg === "--max-warnings") options.maxWarnings = Number(args[++index]);
25
+ else if (arg === "--framework") options.framework = args[++index];
26
+ else if (arg === "--rules") options.rules = args[++index];
27
+ else if (arg === "--severity") options.severity = args[++index];
28
+ else if (arg === "--preset") options.preset = args[++index];
29
+ else if (arg === "--since") options.since = args[++index];
30
+ else if (arg === "--baseline") options.baseline = args[++index];
31
+ else if (arg === "--format") options.format = args[++index];
32
+ else if (!arg.startsWith("-")) path = arg;
33
+ }
34
+ return {
35
+ options,
36
+ path
37
+ };
38
+ }
39
+ function applyDoctorOptions(options, flags) {
40
+ if (flags.changed) options.changed = true;
41
+ if (flags.types) options.types = true;
42
+ if (flags.threads) options.threads = Number(flags.threads);
43
+ options.coverage = stringFlag(flags.coverage) ?? options.coverage;
44
+ options.runtimeEvidence = stringFlag(flags.runtimeEvidence) ?? options.runtimeEvidence;
45
+ options.analyses = stringFlag(flags.analyses) ?? options.analyses;
46
+ if (flags.emitGraph) options.emitGraph = true;
47
+ options.confidenceMin = stringFlag(flags.confidenceMin) ?? options.confidenceMin;
48
+ if (flags.structuralReview) options.structuralReview = true;
49
+ if (flags.types === false) options.types = false;
50
+ if (flags.profile) options.profile = true;
51
+ if (flags.newOnly) options.newOnly = true;
52
+ if (flags.updateBaseline) options.updateBaseline = true;
53
+ if (flags.cache) options.cache = true;
54
+ if (flags.cache === false) options.cache = false;
55
+ if (flags.fix) options.fix = true;
56
+ if (flags.unsafeFix) options.unsafeFix = true;
57
+ if (flags.maxWarnings !== void 0) options.maxWarnings = Number(flags.maxWarnings);
58
+ options.framework = stringFlag(flags.framework) ?? options.framework;
59
+ options.rules = stringFlag(flags.rules) ?? options.rules;
60
+ options.severity = stringFlag(flags.severity) ?? options.severity;
61
+ options.preset = stringFlag(flags.preset) ?? options.preset;
62
+ options.since = stringFlag(flags.since) ?? options.since;
63
+ options.baseline = stringFlag(flags.baseline) ?? options.baseline;
64
+ options.format = stringFlag(flags.format) ?? options.format;
65
+ }
66
+ function stringFlag(value) {
67
+ return typeof value === "string" ? value : void 0;
68
+ }
69
+ function normalizeDoctorCommand(args, commands) {
70
+ const first = args.find((arg) => !arg.startsWith("-"));
71
+ if (!first) return ["scan", ...args];
72
+ if (commands.has(first)) return args;
73
+ return ["scan", ...args];
74
+ }
75
+ //#endregion
76
+ export { normalizeDoctorCommand as n, parseDoctorArgs as r, applyDoctorOptions as t };
package/dist/cli.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ //#region src/cli.d.ts
2
+ declare function main(args?: string[], cwd?: string): Promise<number>;
3
+ //#endregion
4
+ export { main };
package/dist/cli.mjs ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ import { a as createReport, o as createRulesReport, s as explainRule, t as cleanCache } from "./dist-BrWLPMO_.mjs";
3
+ import { n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-Bke3eE9Z.mjs";
4
+ import { n as normalizeDoctorCommand, r as parseDoctorArgs, t as applyDoctorOptions } from "./cli-be9W7NnU.mjs";
5
+ import { resolve } from "pathe";
6
+ import { realpathSync, statSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { consola } from "consola";
9
+ import { cac } from "cac";
10
+ //#region src/cli.ts
11
+ const commands = new Set([
12
+ "scan",
13
+ "check",
14
+ "rules",
15
+ "explain",
16
+ "cache"
17
+ ]);
18
+ const removedCommands = new Set(["run", "ci"]);
19
+ async function main(args = process.argv.slice(2), cwd = process.cwd()) {
20
+ if (removedCommands.has(args[0] ?? "")) {
21
+ errorHuman(`vite-doctor ${args[0]} was removed. Use your package manager scripts directly.`);
22
+ return 1;
23
+ }
24
+ let exitCode = 0;
25
+ const cli = cac("vite-doctor");
26
+ addScanCommand(cli, "scan", cwd, (code) => exitCode = code);
27
+ addScanCommand(cli, "check", cwd, (code) => exitCode = code);
28
+ cli.command("rules", "List available Doctor rules.").option("--format <format>", "Output format.").option("--framework <framework>", "Framework override.").action(async (options) => {
29
+ const runOptions = {};
30
+ applyDoctorOptions(runOptions, options);
31
+ process.stdout.write(createRulesReport(await viteDoctorRulePacks(runOptions), runOptions.format));
32
+ });
33
+ cli.command("explain <rule>", "Explain a Doctor rule.").option("--format <format>", "Output format.").option("--framework <framework>", "Framework override.").action(async (rule, options) => {
34
+ const runOptions = {};
35
+ applyDoctorOptions(runOptions, options);
36
+ process.stdout.write(explainRule(await viteDoctorRulePacks(runOptions), rule, runOptions.format));
37
+ });
38
+ cli.command("cache <action>", "Manage Doctor cache.").action((action) => {
39
+ if (action === "clean") {
40
+ cleanCache(cwd);
41
+ consola.log("Doctor cache cleaned");
42
+ return;
43
+ }
44
+ consola.error(`Unknown cache command: ${action}`);
45
+ exitCode = 1;
46
+ });
47
+ cli.help();
48
+ try {
49
+ cli.parse([
50
+ "node",
51
+ "vite-doctor",
52
+ ...normalizeDoctorCommand(args, commands)
53
+ ], { run: false });
54
+ const result = await cli.runMatchedCommand();
55
+ if (typeof result === "number") exitCode = result;
56
+ return exitCode;
57
+ } catch (error) {
58
+ consola.error(error instanceof Error ? error.message : String(error));
59
+ return 1;
60
+ }
61
+ }
62
+ function addScanCommand(cli, name, cwd, setExitCode) {
63
+ 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("--preset <preset>", "Rule preset.").option("--since <ref>", "Git base ref.").option("--baseline <file>", "Baseline file.").option("--format <format>", "Output format.").option("--config", "Unsupported in vite-doctor.").option("--trusted-config", "Unsupported in vite-doctor.").action(async (path = ".", options) => {
64
+ const parsed = parseDoctorArgs([path]);
65
+ applyDoctorOptions(parsed.options, options);
66
+ if (options.config || options.trustedConfig) {
67
+ errorHuman("Executable config loading was removed from vite-doctor. Use vue-doctor, nuxt-doctor, or @vue-doctor/core/config for trusted config files.");
68
+ setExitCode(1);
69
+ return;
70
+ }
71
+ setExitCode(await runScan(parsed.path, parsed.options, cwd));
72
+ });
73
+ }
74
+ async function runScan(path, options, cwd) {
75
+ const root = resolve(cwd, path);
76
+ if (!statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
77
+ errorHuman(`No readable directory found at ${root}`);
78
+ return 1;
79
+ }
80
+ const result = await runViteDoctor({
81
+ ...options,
82
+ root
83
+ });
84
+ process.stdout.write(createReport(result, options.format));
85
+ return shouldFailDoctorRun(result, options.maxWarnings) ? 1 : 0;
86
+ }
87
+ function errorHuman(message) {
88
+ consola.error(message);
89
+ if (process.env.VITEST_WORKER_ID) console.error(message);
90
+ }
91
+ const currentFile = fileURLToPath(import.meta.url);
92
+ if (process.argv[1] && realpathSync(process.argv[1]) === currentFile) process.exitCode = await main();
93
+ //#endregion
94
+ export { main };