@konvert7/klint 0.12.0 → 0.12.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 (2) hide show
  1. package/core/runner.ts +31 -8
  2. package/package.json +1 -1
package/core/runner.ts CHANGED
@@ -31,7 +31,12 @@ function walk(dir: string, root: string, excludes: string[] = []): string[] {
31
31
  const full = join(dir, entry.name);
32
32
  const rel = relative(root, full).replaceAll("\\", "/");
33
33
  if (entry.isDirectory()) {
34
- if (excludes.some((pattern) => matchPattern(rel, pattern))) continue;
34
+ if (
35
+ excludes.some(
36
+ (pattern) => matchPattern(rel, pattern) || matchPattern(`${rel}/`, pattern)
37
+ )
38
+ )
39
+ continue;
35
40
  out.push(...walk(full, root, excludes));
36
41
  } else if (/\.(tsx?|jsx?|mts|cts)$/.test(entry.name))
37
42
  out.push(full.replaceAll("\\", "/"));
@@ -66,18 +71,36 @@ function matchPattern(relPath: string, pattern: string): boolean {
66
71
  const norm = relPath.replaceAll("\\", "/");
67
72
  const p = pattern.replaceAll("\\", "/");
68
73
  if (p === "." || p === "**") return true;
69
- if (p.endsWith("/**")) return norm.startsWith(`${p.slice(0, -3)}/`);
70
74
  if (!p.includes("*")) return norm === p || norm.startsWith(`${p}/`);
71
75
  return globToRegExp(p).test(norm);
72
76
  }
73
77
 
74
78
  function globToRegExp(pattern: string): RegExp {
75
- const escaped = pattern
76
- .replace(/[.+?^${}()|[\]\\]/g, "\\$&")
77
- .replaceAll("**/", "(?:.*/)?")
78
- .replaceAll("**", ".*")
79
- .replaceAll("*", "[^/]*");
80
- return new RegExp(`^${escaped}$`);
79
+ let source = "";
80
+ for (let i = 0; i < pattern.length; i++) {
81
+ const char = pattern[i];
82
+ const next = pattern[i + 1];
83
+
84
+ if (char === "*" && next === "*") {
85
+ const after = pattern[i + 2];
86
+ if (after === "/") {
87
+ source += "(?:.*/)?";
88
+ i += 2;
89
+ } else {
90
+ source += ".*";
91
+ i++;
92
+ }
93
+ continue;
94
+ }
95
+
96
+ if (char === "*") {
97
+ source += "[^/]*";
98
+ continue;
99
+ }
100
+
101
+ source += /[.+?^${}()|[\]\\]/.test(char) ? `\\${char}` : char;
102
+ }
103
+ return new RegExp(`^${source}$`);
81
104
  }
82
105
 
83
106
  function applyPatterns(files: string[], patterns: string[], root: string): string[] {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konvert7/klint",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Architecture-as-Code linter for TypeScript. Enforce layer boundaries, import rules, and singleton patterns in YAML.",
5
5
  "type": "module",
6
6
  "bin": {