@techninja/clearstack 0.4.6 → 0.4.7
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/lib/watch.js +21 -5
- package/package.json +1 -1
package/lib/watch.js
CHANGED
|
@@ -86,14 +86,19 @@ export async function startWatch(projectDir) {
|
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
const row = toRun[i++];
|
|
89
|
+
row.pass = null;
|
|
90
|
+
row.detail = '';
|
|
91
|
+
render(rows, lastCheck, watchDirs, currentViolations);
|
|
92
|
+
const t0 = Date.now();
|
|
89
93
|
const raw = await row.run({ quiet: true });
|
|
94
|
+
const elapsed = ((Date.now() - t0) / 1000).toFixed(1) + 's';
|
|
90
95
|
row.result = typeof raw === 'boolean' ? { pass: raw } : raw;
|
|
91
96
|
row.pass = row.result.pass;
|
|
92
97
|
row.detail = row.pass
|
|
93
|
-
?
|
|
98
|
+
? `${row.result.detail ?? (row.result.files ? `${row.result.files} files` : '')} (${elapsed})`
|
|
94
99
|
: (row.result.violations?.length
|
|
95
|
-
? `${row.result.violations.length} violation(s)`
|
|
96
|
-
: (() => { const errs = row.result.errors ?? []; const n = errs.filter((l) => /\.(js|ts|css|md)/.test(l)).length || errs.length; return `${n} error(s)`; })());
|
|
100
|
+
? `${row.result.violations.length} violation(s) (${elapsed})`
|
|
101
|
+
: (() => { const errs = row.result.errors ?? []; const n = errs.filter((l) => /\.(js|ts|css|md)/.test(l)).length || errs.length; return `${n} error(s) (${elapsed})`; })());
|
|
97
102
|
// Rebuild violations from all currently-failed rows
|
|
98
103
|
currentViolations = specRows.flatMap((r) => extractViolations(r, projectDir));
|
|
99
104
|
render(rows, lastCheck, watchDirs, currentViolations);
|
|
@@ -116,9 +121,12 @@ export async function startWatch(projectDir) {
|
|
|
116
121
|
*/
|
|
117
122
|
function schedule(ext) {
|
|
118
123
|
for (const k of checksForExt(ext)) {
|
|
124
|
+
const row = specRows.find((r) => r.key === k);
|
|
125
|
+
if (row) row.pass = null; // show spinner while queued
|
|
119
126
|
if (FAST_CHECKS.has(k)) fastPending.add(k);
|
|
120
127
|
else slowPending.add(k);
|
|
121
128
|
}
|
|
129
|
+
render(rows, lastCheck, watchDirs, currentViolations);
|
|
122
130
|
if (fastPending.size) { clearTimeout(fastTimer); fastTimer = setTimeout(runFast, 50); }
|
|
123
131
|
if (slowPending.size) { clearTimeout(slowTimer); slowTimer = setTimeout(runSlow, 1500); }
|
|
124
132
|
}
|
|
@@ -126,13 +134,21 @@ export async function startWatch(projectDir) {
|
|
|
126
134
|
runKeys(new Set(specRows.map((r) => r.key)));
|
|
127
135
|
|
|
128
136
|
// f key — run fix commands for all currently-failing fixable checks
|
|
137
|
+
// Checks can provide a fix via cmds.fix[key] (built-ins) or row.fix() (extensions)
|
|
129
138
|
setOnFix(() => {
|
|
130
|
-
const fixable = specRows.filter((r) => !r.pass && cmds.fix?.[r.key]);
|
|
139
|
+
const fixable = specRows.filter((r) => !r.pass && (cmds.fix?.[r.key] || r.fix));
|
|
131
140
|
if (!fixable.length) return;
|
|
132
141
|
for (const row of fixable) {
|
|
133
|
-
|
|
142
|
+
row.pass = null; // show spinner immediately
|
|
134
143
|
slowPending.add(row.key);
|
|
135
144
|
}
|
|
145
|
+
render(rows, lastCheck, watchDirs, currentViolations);
|
|
146
|
+
for (const row of fixable) {
|
|
147
|
+
try {
|
|
148
|
+
if (row.fix) row.fix();
|
|
149
|
+
else execSync(cmds.fix[row.key], { cwd: projectDir, stdio: 'pipe' });
|
|
150
|
+
} catch { /* fixer may exit 1 even after fixing */ }
|
|
151
|
+
}
|
|
136
152
|
clearTimeout(slowTimer);
|
|
137
153
|
slowTimer = setTimeout(runSlow, 100);
|
|
138
154
|
});
|