@techninja/clearstack 0.4.11 → 0.4.13

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.
@@ -67,8 +67,9 @@ export const FAST_CHECKS = new Set(['lines', 'docs', 'imports', 'i18n', 'tests']
67
67
 
68
68
  /**
69
69
  * Build ext→keys map, merging EXT_DEFAULTS with `watchExts` declared on extension checks.
70
+ * Checks may also declare `watchPaths: string[]` to scope triggers to specific path prefixes.
70
71
  * @param {object[]} checks
71
- * @returns {(ext: string) => string[]}
72
+ * @returns {(ext: string, filepath?: string) => string[]}
72
73
  */
73
74
  export function makeExtMap(checks) {
74
75
  const map = new Map(Object.entries(EXT_DEFAULTS).map(([k, v]) => [k, new Set(v)]));
@@ -79,7 +80,17 @@ export function makeExtMap(checks) {
79
80
  map.get(ext).add(c.key);
80
81
  }
81
82
  }
82
- return (ext) => [...(map.get(ext) ?? [])];
83
+ const pathScoped = checks.filter((c) => c.watchPaths?.length);
84
+ return (ext, filepath) => {
85
+ let keys = [...(map.get(ext) ?? [])];
86
+ if (filepath && pathScoped.length) {
87
+ keys = keys.filter((k) => {
88
+ const c = pathScoped.find((p) => p.key === k);
89
+ return !c || c.watchPaths.some((p) => filepath.startsWith(p));
90
+ });
91
+ }
92
+ return keys;
93
+ };
83
94
  }
84
95
 
85
96
  /**
package/lib/spec-scan.js CHANGED
@@ -37,20 +37,25 @@ export function countFiles(root, extensions, ignoreDirs) {
37
37
  return findFiles(root, extensions, ignoreDirs, root).length;
38
38
  }
39
39
 
40
+ /** @param {string} f @param {string | string[]} pat */
41
+ function matchesPat(f, pat) {
42
+ return Array.isArray(pat) ? pat.some((p) => f.includes(p) || f.endsWith(p)) : f.endsWith(pat);
43
+ }
44
+
40
45
  /**
41
46
  * @param {string} root
42
47
  * @param {string[]} extensions
43
48
  * @param {number} max
44
49
  * @param {string[]} ignoreDirs
45
50
  * @param {string} label
46
- * @param {{ exclude?: string, include?: string, localeMax?: number, quiet?: boolean }} [filter]
51
+ * @param {{ exclude?: string | string[], include?: string | string[], localeMax?: number, quiet?: boolean }} [filter]
47
52
  * @returns {CheckResult & { violations?: LineViolation[] }}
48
53
  */
49
54
  export function checkFileLines(root, extensions, max, ignoreDirs, label, filter) {
50
55
  const start = performance.now();
51
56
  let files = findFiles(root, extensions, ignoreDirs, root);
52
- if (filter?.exclude) files = files.filter((f) => !f.endsWith(filter.exclude));
53
- if (filter?.include) files = files.filter((f) => f.endsWith(filter.include));
57
+ if (filter?.exclude) files = files.filter((f) => !matchesPat(f, filter.exclude));
58
+ if (filter?.include) files = files.filter((f) => matchesPat(f, filter.include));
54
59
  const localeMax = filter?.localeMax || max * 5;
55
60
  const violations = [];
56
61
  for (const file of files) {
@@ -74,13 +79,15 @@ export function checkFileLines(root, extensions, max, ignoreDirs, label, filter)
74
79
  * @param {string} root
75
80
  * @param {string[]} ignoreDirs
76
81
  * @param {string} label
77
- * @param {{ quiet?: boolean }} [opts]
82
+ * @param {{ quiet?: boolean, ignore?: string[] }} [opts]
78
83
  * @returns {CheckResult & { violations?: ImportViolation[] }}
79
84
  */
80
85
  export function checkImports(root, ignoreDirs, label, opts) {
81
86
  const start = performance.now();
87
+ const extraIgnore = opts?.ignore ?? [];
82
88
  const files = findFiles(root, ['.js'], ignoreDirs, root)
83
- .filter((f) => f.startsWith('src/') && !f.includes('vendor/') && !f.includes('api/') && !f.endsWith('.test.js') && !f.endsWith('server.js'));
89
+ .filter((f) => f.startsWith('src/') && !f.includes('vendor/') && !f.includes('api/') && !f.endsWith('.test.js') && !f.endsWith('server.js'))
90
+ .filter((f) => !extraIgnore.some((p) => f.includes(p)));
84
91
  const violations = [];
85
92
  const importRe = /(?:^|\n)\s*import\s.*?from\s+['"](\.\.[^'"]*)['"]/g;
86
93
  for (const file of files) {
@@ -37,7 +37,7 @@ export function setupLifecycle(ctx) {
37
37
 
38
38
  for (const dir of watchDirs) {
39
39
  watch(resolve(projectDir, dir), { recursive: true }, (_event, filename) => {
40
- if (filename) schedule(extname(filename));
40
+ if (filename) schedule(extname(filename), filename);
41
41
  });
42
42
  }
43
43
 
@@ -61,9 +61,9 @@ let fixing = false;
61
61
  /**
62
62
  *
63
63
  */
64
- export function schedule(specRows, ctx, pending, timers, run, checksForExt, ext) {
64
+ export function schedule(specRows, ctx, pending, timers, run, checksForExt, ext, filepath) {
65
65
  if (fixing) return;
66
- for (const k of checksForExt(ext)) {
66
+ for (const k of checksForExt(ext, filepath)) {
67
67
  const row = specRows.find((r) => r.key === k);
68
68
  if (row) row.pass = null;
69
69
  if (FAST_CHECKS.has(k)) pending.fast.add(k);
package/lib/watch.js CHANGED
@@ -62,7 +62,7 @@ export async function startWatch(projectDir) {
62
62
 
63
63
  setupLifecycle({
64
64
  serverRow, specRows, projectDir, watchDirs,
65
- schedule: (ext) => schedule(specRows, ctx, pending, timers, run, checksForExt, ext),
65
+ schedule: (ext, filepath) => schedule(specRows, ctx, pending, timers, run, checksForExt, ext, filepath),
66
66
  renderNote: () => renderNote(rows, lastCheck.value, watchDirs),
67
67
  });
68
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techninja/clearstack",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "type": "module",
5
5
  "description": "A no-build web component framework specification — scaffold, validate, and evolve spec-compliant projects",
6
6
  "bin": {