ngcompass 0.1.1-beta → 0.1.2-beta
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/README.md +136 -191
- package/dist/cli.cjs +20 -448
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +18 -438
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +20 -448
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -438
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/cli.cjs
CHANGED
|
@@ -1,450 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// src/commands/exit.ts
|
|
24
|
-
var exitWithError = (s3 = 1) => {
|
|
25
|
-
process.stdout.isTTY && process.stdout.write("\x1B[?25h"), process.exit(s3);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// src/commands/init.ts
|
|
29
|
-
function registerInitCommand(t5, i) {
|
|
30
|
-
t5.command("init").description("Create a starter ngcompass configuration in the current project").option("-f, --force", "Overwrite an existing configuration file").option("--cwd <path>", "Project directory where the configuration will be created", process.cwd()).action(async (t6) => {
|
|
31
|
-
try {
|
|
32
|
-
let i2 = await config.initConfig({
|
|
33
|
-
cwd: t6.cwd,
|
|
34
|
-
force: t6.force
|
|
35
|
-
}), c2 = reporters.getConfigReporter();
|
|
36
|
-
await c2.renderInitResult(i2), i2.success || i2.alreadyExists || exitWithError();
|
|
37
|
-
} catch (r7) {
|
|
38
|
-
console.error(r7 instanceof Error ? r7.message : String(r7)), exitWithError();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
var FRAMES = [
|
|
43
|
-
"\u280B",
|
|
44
|
-
"\u2819",
|
|
45
|
-
"\u2839",
|
|
46
|
-
"\u2838",
|
|
47
|
-
"\u283C",
|
|
48
|
-
"\u2834",
|
|
49
|
-
"\u2826",
|
|
50
|
-
"\u2827",
|
|
51
|
-
"\u2807",
|
|
52
|
-
"\u280F"
|
|
53
|
-
];
|
|
54
|
-
var Spinner = class {
|
|
55
|
-
stream;
|
|
56
|
-
timer = null;
|
|
57
|
-
frameIndex = 0;
|
|
58
|
-
message = "";
|
|
59
|
-
isTTY;
|
|
60
|
-
constructor(t5) {
|
|
61
|
-
this.stream = t5, this.isTTY = !!t5.isTTY;
|
|
62
|
-
}
|
|
63
|
-
start(e6) {
|
|
64
|
-
(this.message = e6, this.frameIndex = 0, this.isTTY) ? (this.stream.write("\x1B[?25l"), this.render(), this.timer = setInterval(() => this.render(), 80)) : this.stream.write(`${r2__default.default.cyan("\u276F")} ${r2__default.default.dim(e6)}
|
|
65
|
-
`);
|
|
66
|
-
}
|
|
67
|
-
writeLine(t5) {
|
|
68
|
-
this.isTTY && this.timer ? (this.stream.write("\r\x1B[K"), this.stream.write(`${t5}
|
|
69
|
-
`), this.render()) : this.stream.write(`${t5}
|
|
70
|
-
`);
|
|
71
|
-
}
|
|
72
|
-
stop() {
|
|
73
|
-
this.timer && (clearInterval(this.timer), this.timer = null), this.isTTY && (this.stream.write("\r\x1B[K"), this.stream.write("\x1B[?25h"));
|
|
74
|
-
}
|
|
75
|
-
render() {
|
|
76
|
-
let e6 = r2__default.default.cyan(FRAMES[this.frameIndex % FRAMES.length]);
|
|
77
|
-
this.frameIndex++, this.stream.write(`\r${e6} ${r2__default.default.dim(this.message)}`);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
function normalizeReporterFormat(e6) {
|
|
81
|
-
return "ui" === e6 ? "html" : e6 ?? "console";
|
|
82
|
-
}
|
|
83
|
-
function formatDuration(e6) {
|
|
84
|
-
return e6 < 1e3 ? `${Math.max(0, Math.round(e6))}ms` : `${(e6 / 1e3).toFixed(1)}s`;
|
|
85
|
-
}
|
|
86
|
-
function registerAnalyzeCommand(t5, l2) {
|
|
87
|
-
t5.command("analyze").description("Analyze your project and report rule violations and architecture risks").option("-p, --profile <name>", "Configuration profile to run").option("--force", "Ignore cached results and re-run all checks").option("--format <fmt>", "Reporter format: console | json | sarif | html | ui").option("--compact", "Use compact, ESLint-style output").option("-q, --quiet", "Show summary counts only, suppress violation details").option("--no-recommendation", "Suppress fix recommendations from output").option("--output <path>", "Output path for UI reports (default: ngcompass-report.html)").option("--rule <id>", "Run only one rule (useful for debugging or focused checks)").option("--max-workers <n>", "Cap the number of worker threads (lower = less memory, e.g. --max-workers 2)").option("--type-aware-chunk-size <n>", "Files per type-aware chunk (default 400; lower = less peak memory)").option("--skip-type-check", "Skip rules that require the TypeScript type checker (fastest, lowest memory)").action(async (t6) => {
|
|
88
|
-
let u2 = performance.now(), p2 = reporters.getReporter(normalizeReporterFormat(t6.format), {
|
|
89
|
-
compact: !!t6.compact,
|
|
90
|
-
outputPath: t6.output,
|
|
91
|
-
quiet: !!t6.quiet,
|
|
92
|
-
noRecommendation: false === t6.recommendation
|
|
93
|
-
}), c2 = l2, m2 = 0;
|
|
94
|
-
try {
|
|
95
|
-
var f2;
|
|
96
|
-
let i, d2, g2 = await loadConfigurationStep(t6, l2, p2);
|
|
97
|
-
if (!g2) {
|
|
98
|
-
m2 = 1;
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
let { config: h2 } = g2;
|
|
102
|
-
c2 = cache.createRuntimeCache(h2, n__default.default.cwd());
|
|
103
|
-
let w2 = (function(e6, r7) {
|
|
104
|
-
if (e6) return normalizeReporterFormat(e6);
|
|
105
|
-
switch (r7) {
|
|
106
|
-
case "json":
|
|
107
|
-
return "json";
|
|
108
|
-
case "sarif":
|
|
109
|
-
return "sarif";
|
|
110
|
-
case "html":
|
|
111
|
-
return "html";
|
|
112
|
-
default:
|
|
113
|
-
return "console";
|
|
114
|
-
}
|
|
115
|
-
})(t6.format, h2.outputFormat);
|
|
116
|
-
p2 = reporters.getReporter(w2, {
|
|
117
|
-
compact: !!t6.compact,
|
|
118
|
-
outputPath: t6.output ?? h2.outputPath,
|
|
119
|
-
quiet: !!t6.quiet,
|
|
120
|
-
noRecommendation: false === t6.recommendation
|
|
121
|
-
});
|
|
122
|
-
let k2 = await discoverFilesStep(h2, t6, c2, p2);
|
|
123
|
-
if (!k2) {
|
|
124
|
-
m2 = 1;
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let y = await resolveRulesStep(h2, t6, p2);
|
|
128
|
-
if (!y) {
|
|
129
|
-
m2 = 1;
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
let $ = await buildPlanStep(k2, y, c2, t6, p2, h2);
|
|
133
|
-
if (!$) {
|
|
134
|
-
m2 = 1;
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
let v = "console" === w2 ? n__default.default.stdout : n__default.default.stderr, C = new Spinner(v);
|
|
138
|
-
C.start("Running analysis...");
|
|
139
|
-
let x = (function(t7, o5, n3) {
|
|
140
|
-
let a3 = /* @__PURE__ */ new Map();
|
|
141
|
-
for (let e6 of t7.tasks.map((e7) => e7.filePath).filter((e7) => "string" == typeof e7 && e7.length > 0)) a3.set(e6, (a3.get(e6) ?? 0) + 1);
|
|
142
|
-
let i2 = /* @__PURE__ */ new Map(), s3 = /* @__PURE__ */ new Set();
|
|
143
|
-
return (t8) => {
|
|
144
|
-
var l3;
|
|
145
|
-
if (s3.has(t8.filePath)) return;
|
|
146
|
-
let u3 = i2.get(t8.filePath), p3 = u3 ? {
|
|
147
|
-
filePath: t8.filePath,
|
|
148
|
-
taskCount: u3.taskCount + t8.taskCount,
|
|
149
|
-
issueCount: u3.issueCount + t8.issueCount,
|
|
150
|
-
errorCount: u3.errorCount + t8.errorCount,
|
|
151
|
-
warningCount: u3.warningCount + t8.warningCount,
|
|
152
|
-
duration: u3.duration + t8.duration
|
|
153
|
-
} : t8;
|
|
154
|
-
i2.set(t8.filePath, p3);
|
|
155
|
-
let c3 = a3.get(t8.filePath) ?? p3.taskCount;
|
|
156
|
-
if (p3.taskCount < c3) return;
|
|
157
|
-
s3.add(t8.filePath);
|
|
158
|
-
let m3 = e2__default.default.relative(n3, t8.filePath) || t8.filePath, f3 = p3.issueCount > 0, d3 = f3 ? r2__default.default.red("\u276F") : r2__default.default.green("\u276F"), g3 = f3 ? r2__default.default.red(formatDuration(p3.duration)) : r2__default.default.green(formatDuration(p3.duration));
|
|
159
|
-
o5(f3 ? `${d3} ${r2__default.default.red(m3)} ${g3} ${r2__default.default.red((l3 = p3.issueCount, `${l3.toLocaleString()} issue${1 === l3 ? "" : "s"}`))}` : `${d3} ${r2__default.default.dim(m3)} ${g3}`);
|
|
160
|
-
};
|
|
161
|
-
})($, (e6) => C.writeLine(e6), n__default.default.cwd()), S = await runAnalysisStep($, c2, t6, p2, k2, h2, void 0, h2.maxWorkers, x);
|
|
162
|
-
if (C.stop(), !S) {
|
|
163
|
-
m2 = 1;
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
let F = performance.now() - u2, P = {
|
|
167
|
-
scannedFiles: (/* @__PURE__ */ new Set([
|
|
168
|
-
...$.tasks.map((e6) => e6.filePath),
|
|
169
|
-
...($.skippedTasks ?? []).map((e6) => e6.filePath)
|
|
170
|
-
])).size,
|
|
171
|
-
discoveredFiles: k2.length,
|
|
172
|
-
totalFiles: S.stats.totalFiles,
|
|
173
|
-
totalTasks: $.tasks.length + ($.skippedTasks?.length ?? 0),
|
|
174
|
-
cachedTasks: $.precomputedAnalysis ? $.tasks.length : void 0,
|
|
175
|
-
totalErrors: S.stats.totalErrors,
|
|
176
|
-
totalWarnings: S.stats.totalWarnings,
|
|
177
|
-
failOnSeverity: h2.failOnSeverity,
|
|
178
|
-
maxWarnings: h2.maxWarnings,
|
|
179
|
-
duration: F
|
|
180
|
-
};
|
|
181
|
-
"console" === w2 && p2.summary(P), p2.parseErrors(S.parseErrors), p2.report(S.results), "console" !== w2 && (p2.step("\u276F Writing report..."), p2.summary(P)), $.precomputedAnalysis || await saveToCacheStep(S.results, c2, t6, p2), f2 = S.stats, i = h2.failOnSeverity ?? "error", d2 = h2.maxWarnings ?? 10, (f2.totalErrors > 0 || "warn" === i && f2.totalWarnings > 0 || f2.totalWarnings > d2) && (m2 = 1);
|
|
182
|
-
} catch (e6) {
|
|
183
|
-
p2.error(e6), m2 = 1;
|
|
184
|
-
} finally {
|
|
185
|
-
c2 && c2 !== l2 && await c2.flush(), 0 !== m2 && exitWithError(m2);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async function loadConfigurationStep(e6, r7, t5) {
|
|
190
|
-
let o5 = performance.now();
|
|
191
|
-
t5.step("\u276F Loading configuration...");
|
|
192
|
-
let a3 = await config.resolveConfig({
|
|
193
|
-
profile: e6.profile,
|
|
194
|
-
cache: r7,
|
|
195
|
-
cwd: n__default.default.cwd()
|
|
196
|
-
});
|
|
197
|
-
if (!a3.report.valid) {
|
|
198
|
-
let e7 = a3.report.issues.map((e8) => {
|
|
199
|
-
let r8 = e8.path?.join(".") || "root";
|
|
200
|
-
return `[${e8.severity.toUpperCase()}] ${r8}: ${e8.message}`;
|
|
201
|
-
});
|
|
202
|
-
return t5.error(Error([
|
|
203
|
-
"Configuration validation failed",
|
|
204
|
-
...e7
|
|
205
|
-
].join("\n"))), null;
|
|
206
|
-
}
|
|
207
|
-
if (!a3.config) return t5.error(Error("No configuration found")), null;
|
|
208
|
-
let i = a3.config.plugins;
|
|
209
|
-
if (i && i.length > 0) {
|
|
210
|
-
t5.step(`\u276F Loading ${i.length} plugin(s)...`);
|
|
211
|
-
let e7 = n__default.default.cwd();
|
|
212
|
-
await config.loadPlugins(i, e7, rules.getGlobalRegistry()), t5.info(`Loaded ${i.length} plugin(s)`);
|
|
213
|
-
}
|
|
214
|
-
return t5.debug(`Config resolve: ${(performance.now() - o5).toFixed(2)}ms`), {
|
|
215
|
-
config: a3.config
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
async function discoverFilesStep(r7, o5, a3, i) {
|
|
219
|
-
let s3 = performance.now();
|
|
220
|
-
i.step("\u276F Discovering files...");
|
|
221
|
-
let l2 = await scanner.scan({
|
|
222
|
-
rootDir: n__default.default.cwd(),
|
|
223
|
-
include: r7.include ?? [
|
|
224
|
-
...common.DEFAULT_INCLUDE_PATTERNS
|
|
225
|
-
],
|
|
226
|
-
exclude: r7.exclude ?? [],
|
|
227
|
-
ignorePatterns: r7.ignorePatterns,
|
|
228
|
-
tsConfigPath: (function(r8, t5) {
|
|
229
|
-
if (!r8?.project) return;
|
|
230
|
-
let o6 = r8.tsconfigRootDir ? e2__default.default.resolve(t5, r8.tsconfigRootDir) : t5;
|
|
231
|
-
return e2__default.default.resolve(o6, r8.project);
|
|
232
|
-
})(r7.parserOptions, n__default.default.cwd()),
|
|
233
|
-
respectGitignore: true,
|
|
234
|
-
debug: o5.debug,
|
|
235
|
-
cache: a3
|
|
236
|
-
});
|
|
237
|
-
return l2.ok ? (i.info(`\u276F Found ${l2.data.files.length} files in ${(performance.now() - s3).toFixed(0)}ms`), i.debug(`File discovery: ${(performance.now() - s3).toFixed(2)}ms`), l2.data.files) : (i.error(Error(`File discovery failed: ${l2.error.message}`)), null);
|
|
238
|
-
}
|
|
239
|
-
async function resolveRulesStep(e6, r7, t5) {
|
|
240
|
-
let o5 = performance.now();
|
|
241
|
-
t5.step("\u276F Loading rules...");
|
|
242
|
-
let n3 = e6;
|
|
243
|
-
r7.rule && (t5.info(`Filtering analysis to single rule: ${r7.rule}`), n3 = {
|
|
244
|
-
...e6,
|
|
245
|
-
rules: {
|
|
246
|
-
[r7.rule]: "error"
|
|
247
|
-
},
|
|
248
|
-
extends: []
|
|
249
|
-
});
|
|
250
|
-
let a3 = await rules.resolveRules(n3);
|
|
251
|
-
if (!a3.ok) return t5.error(Error(`Rule resolution failed: ${a3.error.message}`)), null;
|
|
252
|
-
let i = rules.getEnabledRules(a3.data.rules);
|
|
253
|
-
return t5.info(`\u276F Loaded ${i.size} active rules in ${(performance.now() - o5).toFixed(0)}ms`), t5.debug(`Rule resolution: ${(performance.now() - o5).toFixed(2)}ms`), i;
|
|
254
|
-
}
|
|
255
|
-
async function buildPlanStep(e6, r7, t5, o5, a3, i) {
|
|
256
|
-
let s3 = performance.now();
|
|
257
|
-
a3.step("\u276F Planning analysis...");
|
|
258
|
-
let l2 = await planner.buildExecutionPlan({
|
|
259
|
-
files: e6,
|
|
260
|
-
rules: r7,
|
|
261
|
-
rootDir: n__default.default.cwd(),
|
|
262
|
-
cache: t5,
|
|
263
|
-
debug: o5.debug,
|
|
264
|
-
incremental: o5.force ? {
|
|
265
|
-
forceRerun: true
|
|
266
|
-
} : void 0,
|
|
267
|
-
workerCount: i.maxWorkers,
|
|
268
|
-
overrides: i.overrides
|
|
269
|
-
});
|
|
270
|
-
return l2.ok ? (l2.data.precomputedAnalysis ? a3.info("\u276F Reused cached analysis plan") : a3.info(`\u276F Prepared ${l2.data.tasks.length.toLocaleString()} checks in ${(performance.now() - s3).toFixed(0)}ms`), a3.debug(`Plan build: ${(performance.now() - s3).toFixed(2)}ms`), l2.data) : (a3.error(Error(`Execution plan building failed: ${l2.error.message}`)), null);
|
|
271
|
-
}
|
|
272
|
-
async function runAnalysisStep(e6, r7, t5, o5, a3, i, s3, l2, c2) {
|
|
273
|
-
let m2 = performance.now();
|
|
274
|
-
engine.configureRuleExecutor(rules.executeBatchedNewEngineRules, rules.isNewEngineRule);
|
|
275
|
-
let f2 = t5.maxWorkers ? parseInt(t5.maxWorkers, 10) : void 0, d2 = t5.typeAwareChunkSize ? parseInt(t5.typeAwareChunkSize, 10) : void 0, w2 = await engine.runAnalysis(e6, {
|
|
276
|
-
rootDir: n__default.default.cwd(),
|
|
277
|
-
cache: r7,
|
|
278
|
-
debug: t5.debug,
|
|
279
|
-
files: a3,
|
|
280
|
-
maxWorkers: f2 ?? i?.maxWorkers,
|
|
281
|
-
typeAwareChunkSize: d2,
|
|
282
|
-
skipTypeCheck: t5.skipTypeCheck,
|
|
283
|
-
parserOptions: i?.parserOptions,
|
|
284
|
-
onProgress: s3,
|
|
285
|
-
onFileProgress: c2
|
|
286
|
-
});
|
|
287
|
-
return w2.ok ? (o5.debug(`Execution: ${(performance.now() - m2).toFixed(2)}ms`), w2.data) : (o5.error(Error(`Analysis failed: ${w2.error.message}`)), null);
|
|
288
|
-
}
|
|
289
|
-
async function saveToCacheStep(e6, r7, t5, o5) {
|
|
290
|
-
if (!r7) return;
|
|
291
|
-
let n3 = performance.now(), a3 = [];
|
|
292
|
-
for (let r8 of e6) r8.taskId && a3.push([
|
|
293
|
-
r8.taskId,
|
|
294
|
-
r8
|
|
295
|
-
]);
|
|
296
|
-
a3.length > 0 && (await r7.results.setMany(a3), t5.debug && o5.debug(`Saved ${a3.length} results to cache (${(performance.now() - n3).toFixed(2)}ms)`));
|
|
297
|
-
}
|
|
298
|
-
function registerConfigCommand(i, t5) {
|
|
299
|
-
i.command("config").description("Inspect and validate ngcompass configuration").command("health").description("Run semantic validation checks for the active configuration").option("-p, --profile <name>", "Configuration profile to validate").action(async (i2) => {
|
|
300
|
-
try {
|
|
301
|
-
let a3 = await config.validateConfig({
|
|
302
|
-
cache: i2.cache ? t5 : void 0,
|
|
303
|
-
profile: i2.profile
|
|
304
|
-
}), n3 = reporters.getConfigReporter();
|
|
305
|
-
await n3.renderHealthReport(a3.report), a3.report.valid || exitWithError();
|
|
306
|
-
} catch (r7) {
|
|
307
|
-
let o5 = r7 instanceof Error ? r7.message : String(r7);
|
|
308
|
-
console.error(`Error: ${o5}`), exitWithError();
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function registerCacheCommand(e6, a3) {
|
|
313
|
-
let c2 = e6.command("cache").description("Inspect and manage analysis cache data");
|
|
314
|
-
c2.command("clear").description("Clear cached data for one cache type or all cache types").option("-p, --profile <name>", "Configuration profile used to resolve cache settings").option("--type <type>", "Cache type to clear: ast | config | results | all", "all").action(async (e7) => {
|
|
315
|
-
let c3 = reporters.getCacheReporter();
|
|
316
|
-
n__default.default.stdout.write(r2__default.default.dim(" \u203A Clearing cache...\n"));
|
|
317
|
-
let l2 = e7.type, n3 = [
|
|
318
|
-
"ast",
|
|
319
|
-
"config",
|
|
320
|
-
"results",
|
|
321
|
-
"all"
|
|
322
|
-
];
|
|
323
|
-
n3.includes(l2) || (console.error(r2__default.default.red(`Invalid cache type: ${l2}. Must be one of: ${n3.join(", ")}`)), exitWithError());
|
|
324
|
-
try {
|
|
325
|
-
let o5 = await resolveRuntimeCache(a3, {
|
|
326
|
-
profile: e7.profile,
|
|
327
|
-
allowDisabled: true
|
|
328
|
-
});
|
|
329
|
-
"all" === l2 ? await o5.clear() : await o5.clearType(l2), c3.renderClearResult(l2);
|
|
330
|
-
} catch (e8) {
|
|
331
|
-
console.error(r2__default.default.red("Error clearing cache:"), e8), exitWithError();
|
|
332
|
-
}
|
|
333
|
-
}), c2.command("info").description("Show cache status, size, and usage details").option("-p, --profile <name>", "Configuration profile used to resolve cache settings").action(async (e7) => {
|
|
334
|
-
let t5 = reporters.getCacheReporter();
|
|
335
|
-
try {
|
|
336
|
-
let o5 = await resolveRuntimeCache(a3, {
|
|
337
|
-
profile: e7.profile,
|
|
338
|
-
allowDisabled: true
|
|
339
|
-
}), r7 = await o5.getInfo();
|
|
340
|
-
t5.renderCacheInfo(r7);
|
|
341
|
-
} catch (e8) {
|
|
342
|
-
console.error(r2__default.default.red("Error getting cache info:"), e8), exitWithError();
|
|
343
|
-
}
|
|
344
|
-
}), c2.command("path").description("Print the resolved cache directory path").option("-p, --profile <name>", "Configuration profile used to resolve cache settings").action(async (e7) => {
|
|
345
|
-
let o5 = await resolveRuntimeCache(a3, {
|
|
346
|
-
profile: e7.profile,
|
|
347
|
-
allowDisabled: true
|
|
348
|
-
});
|
|
349
|
-
n__default.default.stdout.write(`${o5.getCachePath()}
|
|
350
|
-
`);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
async function resolveRuntimeCache(o5, r7 = {}) {
|
|
354
|
-
let i = r7.cwd ?? n__default.default.cwd();
|
|
355
|
-
try {
|
|
356
|
-
let t5 = await config.resolveConfig({
|
|
357
|
-
profile: r7.profile,
|
|
358
|
-
cache: o5,
|
|
359
|
-
cwd: i
|
|
360
|
-
});
|
|
361
|
-
if (!t5.report.valid || !t5.config) return o5;
|
|
362
|
-
return cache.createRuntimeCache(t5.config, i, {
|
|
363
|
-
allowDisabled: r7.allowDisabled
|
|
364
|
-
}) ?? o5;
|
|
365
|
-
} catch {
|
|
366
|
-
return o5;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function registerRulesCommand(i) {
|
|
370
|
-
i.command("rules [ruleName]").description("Browse available rules or inspect details for a specific rule").option("--preset <name>", "Filter by preset: recommended, strict, performance, reactivity, or all").action((i2, l2) => {
|
|
371
|
-
l2.preset && !rules.isBuiltinPreset(l2.preset) && (console.error(r2__default.default.red(`Unknown preset: "${l2.preset}".`)), console.error(r2__default.default.dim("Available presets: recommended, strict, all, performance, reactivity")), exitWithError());
|
|
372
|
-
let n3 = rules.getRuleListEntries(), m2 = reporters.getRulesReporter({
|
|
373
|
-
preset: l2.preset
|
|
374
|
-
});
|
|
375
|
-
if (i2) {
|
|
376
|
-
let e6 = n3.find((e7) => e7.name === i2);
|
|
377
|
-
if (!e6) {
|
|
378
|
-
console.error(r2__default.default.red(`Rule "${i2}" not found.`)), console.error(r2__default.default.dim("Run `ngcompass rules` to list available rules.")), exitWithError();
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
m2.renderSingleRule(e6);
|
|
382
|
-
} else m2.render(n3);
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// src/commands/index.ts
|
|
387
|
-
function registerCommands(s3, f2) {
|
|
388
|
-
registerInitCommand(s3), registerAnalyzeCommand(s3, f2), registerConfigCommand(s3, f2), registerCacheCommand(s3, f2), registerRulesCommand(s3);
|
|
389
|
-
}
|
|
390
|
-
var restoreCursor = () => {
|
|
391
|
-
process.stdout.isTTY && process.stdout.write("\x1B[?25h");
|
|
392
|
-
};
|
|
393
|
-
var shutdownInProgress = false;
|
|
394
|
-
var gracefulShutdown = async (r7, o5) => {
|
|
395
|
-
if (!shutdownInProgress) {
|
|
396
|
-
if (shutdownInProgress = true, restoreCursor(), r7) try {
|
|
397
|
-
let o6 = new Promise((r8) => setTimeout(r8, 1e4).unref());
|
|
398
|
-
await Promise.race([
|
|
399
|
-
r7.flush(),
|
|
400
|
-
o6
|
|
401
|
-
]);
|
|
402
|
-
} catch {
|
|
403
|
-
}
|
|
404
|
-
process.exit(o5);
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
async function run() {
|
|
408
|
-
let a3 = new commander.Command();
|
|
409
|
-
a3.name("ngcompass").description("Static analysis and architecture insights for Angular codebases.").version(common.PACKAGE_VERSION, "-V, --version", "Display ngcompass version").option("--debug", "Enable detailed debug logs across all modules").addHelpText("after", "\nExamples:\n $ ngcompass init\n $ ngcompass analyze --profile strict\n $ ngcompass cache info\n").hook("preAction", async (r7, o5) => {
|
|
410
|
-
r7.opts().debug && common.enableDebug("debug", "all");
|
|
411
|
-
let n3 = o5.opts();
|
|
412
|
-
if ("json" !== n3.format && "sarif" !== n3.format && "html" !== n3.format && "ui" !== n3.format) {
|
|
413
|
-
let { default: r8 } = await import('picocolors'), e6 = o5.parent, n4 = e6 && "ngcompass" !== e6.name() ? e6.name() : o5.name(), t5 = process.cwd();
|
|
414
|
-
process.stdout.write(`
|
|
415
|
-
${r8.dim(">")} ${r8.dim(`ngcompass@${common.PACKAGE_VERSION}`)} ${r8.dim(n4)} ${r8.dim(t5)}
|
|
416
|
-
${r8.dim(">")} ${r8.dim("ngcompass")} ${r8.dim("run")}
|
|
417
|
-
|
|
418
|
-
${r8.bgCyan(r8.white(r8.bold(` ${n4.toUpperCase()} `)))} ${r8.cyan(common.PACKAGE_VERSION)} ${r8.dim(t5)}
|
|
419
|
-
|
|
420
|
-
`);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
let c2 = cache.createCacheContext();
|
|
424
|
-
process.on("SIGINT", () => void gracefulShutdown(c2, 130)), process.on("SIGTERM", () => void gracefulShutdown(c2, 143)), process.on("uncaughtException", (r7) => {
|
|
425
|
-
restoreCursor(), console.error(`
|
|
426
|
-
[ngcompass] Unexpected error: ${r7.message}`), gracefulShutdown(c2, 1);
|
|
427
|
-
}), process.on("unhandledRejection", (r7) => {
|
|
428
|
-
restoreCursor();
|
|
429
|
-
let o5 = r7 instanceof Error ? r7.message : String(r7);
|
|
430
|
-
console.error(`
|
|
431
|
-
[ngcompass] Unhandled promise rejection: ${o5}`), gracefulShutdown(c2, 1);
|
|
432
|
-
});
|
|
433
|
-
try {
|
|
434
|
-
if (rules.registerAllBuiltinRules(), registerCommands(a3, c2), !process.argv.slice(2).length) return void a3.outputHelp();
|
|
435
|
-
await a3.parseAsync(process.argv), await c2.flush(), process.exit(0);
|
|
436
|
-
} catch (o5) {
|
|
437
|
-
restoreCursor();
|
|
438
|
-
let r7 = o5 instanceof Error ? o5.message : String(o5);
|
|
439
|
-
console.error(`[ngcompass] Fatal error: ${r7}`), await gracefulShutdown(c2, 1);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
run().catch((r7) => {
|
|
443
|
-
restoreCursor();
|
|
444
|
-
let o5 = r7 instanceof Error ? r7.message : String(r7);
|
|
445
|
-
console.error(`[ngcompass] Fatal error: ${o5}`), process.exit(1);
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
exports.run = run;
|
|
449
|
-
//# sourceMappingURL=cli.cjs.map
|
|
2
|
+
'use strict';var commander=require('commander'),reporters=require('@ngcompass/reporters'),config=require('@ngcompass/config'),D=require('path'),C=require('picocolors'),common=require('@ngcompass/common'),f=require('process'),cache=require('@ngcompass/cache'),rules=require('@ngcompass/rules'),engine=require('@ngcompass/engine'),planner=require('@ngcompass/planner'),scanner=require('@ngcompass/scanner');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var D__default=/*#__PURE__*/_interopDefault(D);var C__default=/*#__PURE__*/_interopDefault(C);var f__default=/*#__PURE__*/_interopDefault(f);var c=(o=1)=>{process.stdout.isTTY&&process.stdout.write("\x1B[?25h"),process.exit(o);};function G(o,r){o.command("init").description("Create a starter ngcompass configuration in the current project").option("-f, --force","Overwrite an existing configuration file").option("--cwd <path>","Project directory where the configuration will be created",process.cwd()).action(async e=>{try{let i=await config.initConfig({cwd:e.cwd,force:e.force});await reporters.getConfigReporter().renderInitResult(i),i.success||i.alreadyExists||c();}catch(i){console.error(i instanceof Error?i.message:String(i)),c();}});}var _=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],S=class{stream;timer=null;frameIndex=0;message="";isTTY;constructor(r){this.stream=r,this.isTTY=!!r.isTTY;}start(r){this.message=r,this.frameIndex=0,this.isTTY?(this.stream.write("\x1B[?25l"),this.render(),this.timer=setInterval(()=>this.render(),80)):this.stream.write(`${C__default.default.cyan("\u276F")} ${C__default.default.dim(r)}
|
|
3
|
+
`);}writeLine(r){this.isTTY&&this.timer?(this.stream.write("\r\x1B[K"),this.stream.write(`${r}
|
|
4
|
+
`),this.render()):this.stream.write(`${r}
|
|
5
|
+
`);}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.isTTY&&(this.stream.write("\r\x1B[K"),this.stream.write("\x1B[?25h"));}render(){let r=C__default.default.cyan(_[this.frameIndex%_.length]);this.frameIndex++,this.stream.write(`\r${r} ${C__default.default.dim(this.message)}`);}};function K(o){return o==="ui"?"html":o??"console"}function V(o){return o<1e3?`${Math.max(0,Math.round(o))}ms`:`${(o/1e3).toFixed(1)}s`}function J(o,r){o.command("analyze").description("Analyze your project and report rule violations and architecture risks").option("-p, --profile <name>","Configuration profile to run").option("--force","Ignore cached results and re-run all checks").option("--format <fmt>","Reporter format: console | json | sarif | html | ui").option("--compact","Use compact, ESLint-style output").option("-q, --quiet","Show summary counts only, suppress violation details").option("--no-recommendation","Suppress fix recommendations from output").option("--output <path>","Output path for UI reports (default: ngcompass-report.html)").option("--rule <id>","Run only one rule (useful for debugging or focused checks)").option("--max-workers <n>","Cap the number of worker threads (lower = less memory, e.g. --max-workers 2)").option("--type-aware-chunk-size <n>","Files per type-aware chunk (default 400; lower = less peak memory)").option("--skip-type-check","Skip rules that require the TypeScript type checker (fastest, lowest memory)").action(async e=>{let i=performance.now(),n=reporters.getReporter(K(e.format),{compact:!!e.compact,outputPath:e.output,quiet:!!e.quiet,noRecommendation:e.recommendation===false}),t=r,a=0;try{var s;let p,k,E=await ke(e,r,n);if(!E){a=1;return}let{config:m}=E;t=cache.createRuntimeCache(m,f__default.default.cwd());let g=(function(d,I){if(d)return K(d);switch(I){case "json":return "json";case "sarif":return "sarif";case "html":return "html";default:return "console"}})(e.format,m.outputFormat);n=reporters.getReporter(g,{compact:!!e.compact,outputPath:e.output??m.outputPath,quiet:!!e.quiet,noRecommendation:e.recommendation===!1});let R=await Ee(m,e,t,n);if(!R){a=1;return}let B=await Re(m,e,n);if(!B){a=1;return}let u=await be(R,B,t,e,n,m);if(!u){a=1;return}let oe=g==="console"?f__default.default.stdout:f__default.default.stderr,F=new S(oe);F.start("Running analysis...");let ie=(function(d,I,ae){let A=new Map;for(let l of d.tasks.map(w=>w.filePath).filter(w=>typeof w=="string"&&w.length>0))A.set(l,(A.get(l)??0)+1);let U=new Map,M=new Set;return l=>{var w;if(M.has(l.filePath))return;let x=U.get(l.filePath),y=x?{filePath:l.filePath,taskCount:x.taskCount+l.taskCount,issueCount:x.issueCount+l.issueCount,errorCount:x.errorCount+l.errorCount,warningCount:x.warningCount+l.warningCount,duration:x.duration+l.duration}:l;U.set(l.filePath,y);let se=A.get(l.filePath)??y.taskCount;if(y.taskCount<se)return;M.add(l.filePath);let N=D__default.default.relative(ae,l.filePath)||l.filePath,W=y.issueCount>0,Y=W?C__default.default.red("\u276F"):C__default.default.green("\u276F"),q=W?C__default.default.red(V(y.duration)):C__default.default.green(V(y.duration));I(W?`${Y} ${C__default.default.red(N)} ${q} ${C__default.default.red((w=y.issueCount,`${w.toLocaleString()} issue${w===1?"":"s"}`))}`:`${Y} ${C__default.default.dim(N)} ${q}`);}})(u,d=>F.writeLine(d),f__default.default.cwd()),h=await Se(u,t,e,n,R,m,void 0,m.maxWorkers,ie);if(F.stop(),!h){a=1;return}let ne=performance.now()-i,O={scannedFiles:new Set([...u.tasks.map(d=>d.filePath),...(u.skippedTasks??[]).map(d=>d.filePath)]).size,discoveredFiles:R.length,totalFiles:h.stats.totalFiles,totalTasks:u.tasks.length+(u.skippedTasks?.length??0),cachedTasks:u.precomputedAnalysis?u.tasks.length:void 0,totalErrors:h.stats.totalErrors,totalWarnings:h.stats.totalWarnings,failOnSeverity:m.failOnSeverity,maxWarnings:m.maxWarnings,duration:ne};g==="console"&&n.summary(O),n.parseErrors(h.parseErrors),n.report(h.results),g!=="console"&&(n.step("\u276F Writing report..."),n.summary(O)),u.precomputedAnalysis||await Pe(h.results,t,e,n),s=h.stats,p=m.failOnSeverity??"error",k=m.maxWarnings??10,(s.totalErrors>0||p==="warn"&&s.totalWarnings>0||s.totalWarnings>k)&&(a=1);}catch(p){n.error(p),a=1;}finally{t&&t!==r&&await t.flush(),a!==0&&c(a);}});}async function ke(o,r,e){let i=performance.now();e.step("\u276F Loading configuration...");let n=await config.resolveConfig({profile:o.profile,cache:r,cwd:f__default.default.cwd()});if(!n.report.valid){let a=n.report.issues.map(s=>{let p=s.path?.join(".")||"root";return `[${s.severity.toUpperCase()}] ${p}: ${s.message}`});return e.error(Error(["Configuration validation failed",...a].join(`
|
|
6
|
+
`))),null}if(!n.config)return e.error(Error("No configuration found")),null;let t=n.config.plugins;if(t&&t.length>0){e.step(`\u276F Loading ${t.length} plugin(s)...`);let a=f__default.default.cwd();await config.loadPlugins(t,a,rules.getGlobalRegistry()),e.info(`Loaded ${t.length} plugin(s)`);}return e.debug(`Config resolve: ${(performance.now()-i).toFixed(2)}ms`),{config:n.config}}async function Ee(o,r,e,i){let n=performance.now();i.step("\u276F Discovering files...");let t=await scanner.scan({rootDir:f__default.default.cwd(),include:o.include??[...common.DEFAULT_INCLUDE_PATTERNS],exclude:o.exclude??[],ignorePatterns:o.ignorePatterns,tsConfigPath:(function(a,s){if(!a?.project)return;let p=a.tsconfigRootDir?D__default.default.resolve(s,a.tsconfigRootDir):s;return D__default.default.resolve(p,a.project)})(o.parserOptions,f__default.default.cwd()),respectGitignore:true,debug:r.debug,cache:e});return t.ok?(i.info(`\u276F Found ${t.data.files.length} files in ${(performance.now()-n).toFixed(0)}ms`),i.debug(`File discovery: ${(performance.now()-n).toFixed(2)}ms`),t.data.files):(i.error(Error(`File discovery failed: ${t.error.message}`)),null)}async function Re(o,r,e){let i=performance.now();e.step("\u276F Loading rules...");let n=o;r.rule&&(e.info(`Filtering analysis to single rule: ${r.rule}`),n={...o,rules:{[r.rule]:"error"},extends:[]});let t=await rules.resolveRules(n);if(!t.ok)return e.error(Error(`Rule resolution failed: ${t.error.message}`)),null;let a=rules.getEnabledRules(t.data.rules);return e.info(`\u276F Loaded ${a.size} active rules in ${(performance.now()-i).toFixed(0)}ms`),e.debug(`Rule resolution: ${(performance.now()-i).toFixed(2)}ms`),a}async function be(o,r,e,i,n,t){let a=performance.now();n.step("\u276F Planning analysis...");let s=await planner.buildExecutionPlan({files:o,rules:r,rootDir:f__default.default.cwd(),cache:e,debug:i.debug,incremental:i.force?{forceRerun:true}:void 0,workerCount:t.maxWorkers,overrides:t.overrides});return s.ok?(s.data.precomputedAnalysis?n.info("\u276F Reused cached analysis plan"):n.info(`\u276F Prepared ${s.data.tasks.length.toLocaleString()} checks in ${(performance.now()-a).toFixed(0)}ms`),n.debug(`Plan build: ${(performance.now()-a).toFixed(2)}ms`),s.data):(n.error(Error(`Execution plan building failed: ${s.error.message}`)),null)}async function Se(o,r,e,i,n,t,a,s,p){let k=performance.now();engine.configureRuleExecutor(rules.executeBatchedNewEngineRules,rules.isNewEngineRule);let E=e.maxWorkers?parseInt(e.maxWorkers,10):void 0,m=e.typeAwareChunkSize?parseInt(e.typeAwareChunkSize,10):void 0,g=await engine.runAnalysis(o,{rootDir:f__default.default.cwd(),cache:r,debug:e.debug,files:n,maxWorkers:E??t?.maxWorkers,typeAwareChunkSize:m,skipTypeCheck:e.skipTypeCheck,parserOptions:t?.parserOptions,onProgress:a,onFileProgress:p});return g.ok?(i.debug(`Execution: ${(performance.now()-k).toFixed(2)}ms`),g.data):(i.error(Error(`Analysis failed: ${g.error.message}`)),null)}async function Pe(o,r,e,i){if(!r)return;let n=performance.now(),t=[];for(let a of o)a.taskId&&t.push([a.taskId,a]);t.length>0&&(await r.results.setMany(t),e.debug&&i.debug(`Saved ${t.length} results to cache (${(performance.now()-n).toFixed(2)}ms)`));}function Q(o,r){o.command("config").description("Inspect and validate ngcompass configuration").command("health").description("Run semantic validation checks for the active configuration").option("-p, --profile <name>","Configuration profile to validate").action(async e=>{try{let i=await config.validateConfig({cache:e.cache?r:void 0,profile:e.profile});await reporters.getConfigReporter().renderHealthReport(i.report),i.report.valid||c();}catch(i){let n=i instanceof Error?i.message:String(i);console.error(`Error: ${n}`),c();}});}function Z(o,r){let e=o.command("cache").description("Inspect and manage analysis cache data");e.command("clear").description("Clear cached data for one cache type or all cache types").option("-p, --profile <name>","Configuration profile used to resolve cache settings").option("--type <type>","Cache type to clear: ast | config | results | all","all").action(async i=>{let n=reporters.getCacheReporter();f__default.default.stdout.write(C__default.default.dim(` \u203A Clearing cache...
|
|
7
|
+
`));let t=i.type,a=["ast","config","results","all"];a.includes(t)||(console.error(C__default.default.red(`Invalid cache type: ${t}. Must be one of: ${a.join(", ")}`)),c());try{let s=await j(r,{profile:i.profile,allowDisabled:!0});t==="all"?await s.clear():await s.clearType(t),n.renderClearResult(t);}catch(s){console.error(C__default.default.red("Error clearing cache:"),s),c();}}),e.command("info").description("Show cache status, size, and usage details").option("-p, --profile <name>","Configuration profile used to resolve cache settings").action(async i=>{let n=reporters.getCacheReporter();try{let t=await j(r,{profile:i.profile,allowDisabled:!0}),a=await t.getInfo();n.renderCacheInfo(a);}catch(t){console.error(C__default.default.red("Error getting cache info:"),t),c();}}),e.command("path").description("Print the resolved cache directory path").option("-p, --profile <name>","Configuration profile used to resolve cache settings").action(async i=>{let n=await j(r,{profile:i.profile,allowDisabled:true});f__default.default.stdout.write(`${n.getCachePath()}
|
|
8
|
+
`);});}async function j(o,r={}){let e=r.cwd??f__default.default.cwd();try{let i=await config.resolveConfig({profile:r.profile,cache:o,cwd:e});return !i.report.valid||!i.config?o:cache.createRuntimeCache(i.config,e,{allowDisabled:r.allowDisabled})??o}catch{return o}}function ee(o){o.command("rules [ruleName]").description("Browse available rules or inspect details for a specific rule").option("--preset <name>","Filter by preset: recommended, strict, performance, reactivity, or all").action((r,e)=>{e.preset&&!rules.isBuiltinPreset(e.preset)&&(console.error(C__default.default.red(`Unknown preset: "${e.preset}".`)),console.error(C__default.default.dim("Available presets: recommended, strict, all, performance, reactivity")),c());let i=rules.getRuleListEntries(),n=reporters.getRulesReporter({preset:e.preset});if(r){let t=i.find(a=>a.name===r);if(!t){console.error(C__default.default.red(`Rule "${r}" not found.`)),console.error(C__default.default.dim("Run `ngcompass rules` to list available rules.")),c();return}n.renderSingleRule(t);}else n.render(i);});}function re(o,r){G(o),J(o,r),Q(o,r),Z(o,r),ee(o);}var v=()=>{process.stdout.isTTY&&process.stdout.write("\x1B[?25h");},te=false,$=async(o,r)=>{if(!te){if(te=true,v(),o)try{let e=new Promise(i=>setTimeout(i,1e4).unref());await Promise.race([o.flush(),e]);}catch{}process.exit(r);}};async function Ue(){let o=new commander.Command;o.name("ngcompass").description("Static analysis and architecture insights for Angular codebases.").version(common.PACKAGE_VERSION,"-V, --version","Display ngcompass version").option("--debug","Enable detailed debug logs across all modules").addHelpText("after",`
|
|
9
|
+
Examples:
|
|
10
|
+
$ ngcompass init
|
|
11
|
+
$ ngcompass analyze --profile strict
|
|
12
|
+
$ ngcompass cache info
|
|
13
|
+
`).hook("preAction",async(e,i)=>{e.opts().debug&&common.enableDebug("debug","all");let n=i.opts();if(n.format!=="json"&&n.format!=="sarif"&&n.format!=="html"&&n.format!=="ui"){let{default:t}=await import('picocolors'),a=i.parent,s=a&&a.name()!=="ngcompass"?a.name():i.name(),p=process.cwd();process.stdout.write(`
|
|
14
|
+
${t.dim(">")} ${t.dim(`ngcompass@${common.PACKAGE_VERSION}`)} ${t.dim(s)} ${t.dim(p)}
|
|
15
|
+
${t.dim(">")} ${t.dim("ngcompass")} ${t.dim("run")}
|
|
16
|
+
|
|
17
|
+
${t.bgCyan(t.white(t.bold(` ${s.toUpperCase()} `)))} ${t.cyan(common.PACKAGE_VERSION)} ${t.dim(p)}
|
|
18
|
+
|
|
19
|
+
`);}});let r=cache.createCacheContext();process.on("SIGINT",()=>{$(r,130);}),process.on("SIGTERM",()=>{$(r,143);}),process.on("uncaughtException",e=>{v(),console.error(`
|
|
20
|
+
[ngcompass] Unexpected error: ${e.message}`),$(r,1);}),process.on("unhandledRejection",e=>{v();let i=e instanceof Error?e.message:String(e);console.error(`
|
|
21
|
+
[ngcompass] Unhandled promise rejection: ${i}`),$(r,1);});try{if(rules.registerAllBuiltinRules(),re(o,r),!process.argv.slice(2).length)return void o.outputHelp();await o.parseAsync(process.argv),await r.flush(),process.exit(0);}catch(e){v();let i=e instanceof Error?e.message:String(e);console.error(`[ngcompass] Fatal error: ${i}`),await $(r,1);}}Ue().catch(o=>{v();let r=o instanceof Error?o.message:String(o);console.error(`[ngcompass] Fatal error: ${r}`),process.exit(1);});exports.run=Ue;//# sourceMappingURL=cli.cjs.map
|
|
450
22
|
//# sourceMappingURL=cli.cjs.map
|