vite-doctor 0.0.1-alpha.2 → 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.
- package/dist/cli-main-DCJWk1En.mjs +175 -0
- package/dist/cli-main-DZtwLzMZ.d.mts +4 -0
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +2 -87
- package/dist/config-D5OZt0fD-B9Flpubz.d.mts +39 -0
- package/dist/{rules-DFoclETT.mjs → doctor-Bwq3I7XL.mjs} +2824 -384
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/nuxt-cli.d.mts +2 -0
- package/dist/nuxt-cli.mjs +9 -0
- package/dist/nuxt.d.mts +7 -8
- package/dist/nuxt.mjs +20 -15640
- package/dist/{plugin-BxANflhW.mjs → plugin-_P7sALMl.mjs} +37 -4
- package/dist/plugin-vLTZiLbe.d.mts +23 -0
- package/dist/plugin.d.mts +2 -2
- package/dist/plugin.mjs +1 -1
- package/dist/primitives-DdFGPkcF-ByGjY1Ra.d.mts +556 -0
- package/dist/{dist-BrWLPMO_.mjs → rules-DFU2Qgly.mjs} +2574 -1441
- package/dist/rules.d.mts +2 -371
- package/dist/rules.mjs +1 -1
- package/package.json +21 -27
- package/dist/cli-be9W7NnU.mjs +0 -76
- package/dist/doctor-Bke3eE9Z.mjs +0 -91
- package/dist/plugin-Ch9LazsD.d.mts +0 -19
- package/dist/rules-B-3hPfgr.mjs +0 -934
- package/dist/rules-CX8QGsK4.mjs +0 -2
- package/dist/rules-FTCJ71Xs.mjs +0 -2
- package/dist/rules-WBqh_GLn.mjs +0 -1413
|
@@ -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 };
|
package/dist/cli.d.mts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,93 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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";
|
|
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 { consola } from "consola";
|
|
9
|
-
import { cac } from "cac";
|
|
10
5
|
//#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
6
|
const currentFile = fileURLToPath(import.meta.url);
|
|
92
7
|
if (process.argv[1] && realpathSync(process.argv[1]) === currentFile) process.exitCode = await main();
|
|
93
8
|
//#endregion
|
|
@@ -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 };
|