ctxloom-pro 1.0.4 → 1.0.6

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.
@@ -1,139 +0,0 @@
1
- // src/rules/types.ts
2
- var RulesConfigError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "RulesConfigError";
6
- }
7
- };
8
-
9
- // src/rules/loadConfig.ts
10
- import fs from "fs/promises";
11
- import path from "path";
12
- import yaml from "js-yaml";
13
- import { z } from "zod";
14
- var RuleSchema = z.object({
15
- name: z.string(),
16
- type: z.literal("no-import"),
17
- from: z.string(),
18
- to: z.string(),
19
- severity: z.enum(["error", "warn"]).optional()
20
- });
21
- var RulesConfigSchema = z.object({
22
- version: z.literal(1),
23
- rules: z.array(RuleSchema).default([])
24
- });
25
- async function loadRulesConfig(rootDir) {
26
- const filePath = path.join(rootDir, ".ctxloom", "rules.yml");
27
- let raw;
28
- try {
29
- raw = await fs.readFile(filePath, "utf-8");
30
- } catch (err) {
31
- if (err.code === "ENOENT") return null;
32
- throw new RulesConfigError(`Failed to read rules config: ${String(err)}`);
33
- }
34
- let parsed;
35
- try {
36
- parsed = yaml.load(raw);
37
- } catch (err) {
38
- throw new RulesConfigError(`Invalid YAML in .ctxloom/rules.yml: ${String(err)}`);
39
- }
40
- const result = RulesConfigSchema.safeParse(parsed);
41
- if (!result.success) {
42
- const messages = result.error.errors.map((e) => ` ${e.path.join(".")}: ${e.message}`).join("\n");
43
- throw new RulesConfigError(`Invalid .ctxloom/rules.yml schema:
44
- ${messages}`);
45
- }
46
- return result.data;
47
- }
48
-
49
- // src/rules/RulesChecker.ts
50
- import picomatch from "picomatch";
51
- var RulesChecker = class {
52
- constructor(graph, config) {
53
- this.graph = graph;
54
- this.config = config;
55
- }
56
- graph;
57
- config;
58
- check() {
59
- const start = Date.now();
60
- const violations = [];
61
- const warnings = [];
62
- const allFiles = this.graph.allFiles();
63
- for (const rule of this.config.rules) {
64
- const fromMatcher = picomatch(rule.from, { dot: true });
65
- const toMatcher = picomatch(rule.to, { dot: true });
66
- const fromFiles = allFiles.filter((f) => fromMatcher(f));
67
- const toFiles = new Set(allFiles.filter((f) => toMatcher(f)));
68
- if (fromFiles.length === 0 || toFiles.size === 0) {
69
- warnings.push(`rule "${rule.name}" matched 0 files on from/to \u2014 check glob`);
70
- continue;
71
- }
72
- const severity = rule.severity ?? "error";
73
- for (const fromFile of fromFiles) {
74
- for (const importedFile of this.graph.getImports(fromFile)) {
75
- if (toFiles.has(importedFile)) {
76
- violations.push({
77
- rule: rule.name,
78
- severity,
79
- fromFile,
80
- toFile: importedFile,
81
- message: `${fromFile} must not import ${importedFile} [${rule.name}]`
82
- });
83
- }
84
- }
85
- }
86
- }
87
- return {
88
- violations,
89
- warnings,
90
- rulesChecked: this.config.rules.length,
91
- filesChecked: allFiles.length,
92
- durationMs: Date.now() - start
93
- };
94
- }
95
- };
96
-
97
- // src/rules/reporter.ts
98
- function formatText(result, limit = 50) {
99
- const lines = [];
100
- if (result.warnings.length > 0) {
101
- for (const w of result.warnings) {
102
- lines.push(` \u26A0 ${w}`);
103
- }
104
- lines.push("");
105
- }
106
- const toShow = limit === 0 ? result.violations : result.violations.slice(0, limit);
107
- const hidden = result.violations.length - toShow.length;
108
- for (const v of toShow) {
109
- const tag = v.severity === "warn" ? "WARN" : "ERROR";
110
- lines.push(` [${tag}] ${v.message}`);
111
- }
112
- if (hidden > 0) {
113
- lines.push(`
114
- ... and ${hidden} more. Run with --json for full output.`);
115
- }
116
- if (result.violations.length === 0) {
117
- lines.push(
118
- `\u2713 ${result.rulesChecked} rules checked, 0 violations. (${result.filesChecked} files, ${result.durationMs}ms)`
119
- );
120
- } else {
121
- lines.push(
122
- `
123
- ${result.violations.length} violation(s) found. (${result.filesChecked} files, ${result.rulesChecked} rules, ${result.durationMs}ms)`
124
- );
125
- }
126
- return lines.join("\n");
127
- }
128
- function formatJson(result) {
129
- return JSON.stringify({ schemaVersion: 1, ...result }, null, 2);
130
- }
131
-
132
- export {
133
- RulesConfigError,
134
- loadRulesConfig,
135
- RulesChecker,
136
- formatText,
137
- formatJson
138
- };
139
- //# sourceMappingURL=chunk-PSLPRDPL.js.map