Skip to content

Build your personal knowledge base with Trilium Notes

chore(scripts): improve typecheck with numbers & total count

Elian Doran01dae831a437
diff --git a/package.json b/package.json
index ee4cea354b..20bcd2c712 100644
--- a/package.json
+++ b/package.json
@@ -37,7 +37,7 @@
"test:all": "pnpm test:parallel && pnpm test:sequential",
"test:parallel": "pnpm --filter=!server --filter=!ckeditor5-mermaid --filter=!ckeditor5-math --parallel test",
"test:sequential": "pnpm --filter=server --filter=ckeditor5-mermaid --filter=ckeditor5-math --sequential test",
- "typecheck": "tsc --build | tsx scripts/filter-tsc-output.mts",
+ "typecheck": "tsx scripts/filter-tsc-output.mts",
"dev:format-check": "eslint -c eslint.format.config.mjs .",
"dev:format-fix": "eslint -c eslint.format.config.mjs . --fix",
"dev:linter-check": "cross-env NODE_OPTIONS=--max_old_space_size=4096 eslint .",
diff --git a/scripts/filter-tsc-output.mts b/scripts/filter-tsc-output.mts
index 754be10f66..bdc9263e4b 100644
--- a/scripts/filter-tsc-output.mts
+++ b/scripts/filter-tsc-output.mts
@@ -1,24 +1,46 @@
/**
- * Filters out TS6305 cascade errors from tsc --build output.
- * These "Output file has not been built from source" errors are noise
- * caused by upstream build failures and obscure the real errors.
+ * Runs `tsc --build` and filters out noisy cascade errors (TS6305).
+ * Numbers each remaining error and prints a summary at the end.
*/
-const SUPPRESSED_CODES = ["TS6305"];
+import { execSync } from "child_process";
-let data = "";
-process.stdin.resume();
-process.stdin.setEncoding("utf-8");
-process.stdin.on("data", (chunk) => (data += chunk));
-process.stdin.on("end", () => {
- const filtered = data
- .split(/\r?\n/)
- .filter((line) => !SUPPRESSED_CODES.some((code) => line.includes(code)))
- .join("\n")
- .trim();
+const SUPPRESSED_CODES = [ "TS6305" ];
+const ERROR_LINE_PATTERN = /^.+\(\d+,\d+\): error TS\d+:/;
- if (filtered) {
- console.log(filtered);
- process.exit(1);
+let output: string;
+try {
+ output = execSync("tsc --build", {
+ encoding: "utf-8",
+ stdio: [ "inherit", "pipe", "pipe" ]
+ });
+} catch (err: unknown) {
+ const execErr = err as { stdout?: string; stderr?: string };
+ output = (execErr.stdout ?? "") + (execErr.stderr ?? "");
+}
+
+const lines = output.split(/\r?\n/);
+const filtered = lines.filter(
+ (line) => !SUPPRESSED_CODES.some((code) => line.includes(code))
+);
+
+let errorIndex = 0;
+const numbered: string[] = [];
+
+for (const line of filtered) {
+ if (ERROR_LINE_PATTERN.test(line)) {
+ errorIndex++;
+ numbered.push(`[${errorIndex}] ${line}`);
+ } else if (line.trim()) {
+ // Continuation line (indented context for multi-line errors)
+ numbered.push(line);
}
-});
+}
+
+if (errorIndex > 0) {
+ console.log(numbered.join("\n"));
+ console.log(`\n${errorIndex} error(s) found.`);
+ process.exit(1);
+} else {
+ console.log("No errors found.");
+}