Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
build: run pnpm typecheck through the native TypeScript compiler
Elian Doran249d676f7a13
diff --git a/CLAUDE.md b/CLAUDE.mdindex 84d4247775..e577f28800 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -42,7 +42,7 @@ pnpm typecheck # TypeScript type check across all projects- **Never run ESLint** — `pnpm dev:linter-check`, `dev:linter-fix`, or `npx eslint` on any path. It currently dies with an out-of-memory error, so a run tells you nothing and costs minutes. CI lints. (Note `packages/*` is globally ignored by the ESLint config anyway, so most of `trilium-core` was never linted locally to begin with.)- **Never run `pnpm test:all`, `test:parallel`, `test:sequential`, or `pnpm coverage`** during development. They take a long time, and CI runs them on every push.- **Run the narrowest suite that covers what you touched**, and iterate on that: `pnpm --filter <pkg> test <path-or-pattern>`. Vitest treats the trailing argument as a substring filter over test file paths, so `pnpm --filter server test special_notes` runs every matching spec.-- **Typecheck with `pnpm typecheck`, not a raw `tsc` invocation.** It resolves the project references and per-project configs that a hand-written `tsc --noEmit -p …` or `tsc -b …` gets wrong. It is cheaper than a suite but not instant, so run it when you've finished a change — not after every edit.+- **Typecheck with `pnpm typecheck`, not a raw `tsc` invocation.** It resolves the project references and per-project configs that a hand-written `tsc --noEmit -p …` or `tsc -b …` gets wrong. It drives the native compiler, so even a full check of every project is a few seconds — cheap enough to run whenever you finish a change.- Core specs are the one case where "narrowest" means **two** commands: they run under both the server and standalone suites (see Testing below), so a targeted run against each is still the right scope.- Only reach for a full suite if the user asks, or when the work is finished and they want a final check.@@ -419,3 +419,10 @@ The viewer under `packages/pdfjs-viewer/viewer/` is vendored from the pdf.js Git- ESBuild for production optimization- pnpm workspaces for dependency management- Docker support with multi-stage builds++### Two TypeScript versions, on purpose+The root `package.json` declares **both** `typescript` (6.x) and `tsc-native` (an alias of `typescript@7`). Do not "deduplicate" them by bumping `typescript` to 7:++- **`typescript` 6.x is the library.** TypeScript 7 is the native Go port and its package no longer exports the JS compiler API (`exports["."]` is just a version stub). Everything that does `require("typescript")` — TypeDoc, typescript-eslint, the Vite plugins — needs 6.x and declares peer ranges that stop there.+- **`tsc-native` is the compiler binary**, used only by `scripts/filter-tsc-output.mts` behind `pnpm typecheck`. It builds the whole project graph in roughly a seventh of the time 6.x takes.+- pnpm gives `node_modules/.bin/tsc` to the alias, so a bare `tsc` on the command line is **7**, not the 6.x that tooling loads. That is also what keeps `.tsbuildinfo` in one format — the two majors cannot read each other's, and mixing them forces a full rebuild every time.diff --git a/package.json b/package.jsonindex 332e549da5..f1adad0c9a 100644--- a/package.json+++ b/package.json@@ -75,6 +75,7 @@"http-server": "14.1.1","jiti": "2.7.0","js-yaml": "5.2.3",+ "tsc-native": "npm:[email protected]","tslib": "2.8.1","tsx": "4.23.8","typescript": "6.0.3",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 7e0e035910..b7921b9793 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -149,6 +149,9 @@ importers:js-yaml:specifier: 5.2.3version: 5.2.3+ tsc-native:+ specifier: npm:[email protected]+ version: [email protected]tslib:specifier: 2.8.1version: 2.8.1@@ -5285,6 +5288,126 @@ packages:resolution: {integrity: sha512-dkKR8q+lKciskj1Y3vthHktl+3cMLWGyVUP23bRiPZ5O9BRT++4EqDDV+TVeIKBL1VXVEqrJlz8MYbcnvJcAlg==}engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}+ '@typescript/[email protected]':+ resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==}+ engines: {node: '>=16.20.0'}+ cpu: [ppc64]+ os: [aix]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [darwin]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [darwin]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [freebsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [freebsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==}+ engines: {node: '>=16.20.0'}+ cpu: [arm]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==}+ engines: {node: '>=16.20.0'}+ cpu: [loong64]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==}+ engines: {node: '>=16.20.0'}+ cpu: [mips64el]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==}+ engines: {node: '>=16.20.0'}+ cpu: [ppc64]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==}+ engines: {node: '>=16.20.0'}+ cpu: [riscv64]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==}+ engines: {node: '>=16.20.0'}+ cpu: [s390x]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [linux]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [netbsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [netbsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [openbsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [openbsd]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [sunos]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==}+ engines: {node: '>=16.20.0'}+ cpu: [arm64]+ os: [win32]++ '@typescript/[email protected]':+ resolution: {integrity: sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==}+ engines: {node: '>=16.20.0'}+ cpu: [x64]+ os: [win32]+'@typescript/[email protected]':resolution: {integrity: sha512-PJFXFS4ZJKiJ9Qiuix6Dz/OwEIqHD7Dme1UwZhTK11vR+5dqW2ACbdndWQexBzCx+CPuMe5WBYQWCsFyGlQLlQ==}peerDependencies:@@ -11845,6 +11968,11 @@ packages:engines: {node: '>=14.17'}hasBin: true+ resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==}+ engines: {node: '>=16.20.0'}+ hasBin: true+resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==}@@ -17138,6 +17266,66 @@ snapshots:'@typescript-eslint/types': 8.66.0eslint-visitor-keys: 5.0.1+ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true++ '@typescript/[email protected]':+ optional: true+dependencies:debug: 4.4.3([email protected])@@ -25680,6 +25868,29 @@ snapshots:+ optionalDependencies:+ '@typescript/typescript-aix-ppc64': 7.0.2+ '@typescript/typescript-darwin-arm64': 7.0.2+ '@typescript/typescript-darwin-x64': 7.0.2+ '@typescript/typescript-freebsd-arm64': 7.0.2+ '@typescript/typescript-freebsd-x64': 7.0.2+ '@typescript/typescript-linux-arm': 7.0.2+ '@typescript/typescript-linux-arm64': 7.0.2+ '@typescript/typescript-linux-loong64': 7.0.2+ '@typescript/typescript-linux-mips64el': 7.0.2+ '@typescript/typescript-linux-ppc64': 7.0.2+ '@typescript/typescript-linux-riscv64': 7.0.2+ '@typescript/typescript-linux-s390x': 7.0.2+ '@typescript/typescript-linux-x64': 7.0.2+ '@typescript/typescript-netbsd-arm64': 7.0.2+ '@typescript/typescript-netbsd-x64': 7.0.2+ '@typescript/typescript-openbsd-arm64': 7.0.2+ '@typescript/typescript-openbsd-x64': 7.0.2+ '@typescript/typescript-sunos-x64': 7.0.2+ '@typescript/typescript-win32-arm64': 7.0.2+ '@typescript/typescript-win32-x64': 7.0.2+diff --git a/scripts/filter-tsc-output.mts b/scripts/filter-tsc-output.mtsindex 4652a55873..63d7763ff5 100644--- a/scripts/filter-tsc-output.mts+++ b/scripts/filter-tsc-output.mts@@ -1,24 +1,32 @@/*** Runs `tsc --build` and filters out noisy cascade errors (TS6305).* Numbers each remaining error and prints a summary at the end.+ *+ * The compiler is the native (Go) one, pulled in as the `tsc-native` alias of+ * typescript@7 -- it does the same build several times faster. The `typescript`+ * dependency stays on 6.x because TypeScript 7 ships no JS compiler API, and+ * typedoc / typescript-eslint / the Vite plugins all load it.*/-import { execSync } from "child_process";+import { spawnSync } from "child_process";+import { fileURLToPath } from "url";+const TSC = fileURLToPath(new URL("../node_modules/tsc-native/bin/tsc", import.meta.url));const SUPPRESSED_CODES = [ "TS6305" ];const ERROR_LINE_PATTERN = /^.+\(\d+,\d+\): error TS\d+:/;-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 result = spawnSync(process.execPath, [ TSC, "--build" ], {+ encoding: "utf-8",+ stdio: [ "inherit", "pipe", "pipe" ]+});++if (result.error) {+ console.error(`Failed to run ${TSC}: ${result.error.message}`);+ process.exit(1);}+const output = (result.stdout ?? "") + (result.stderr ?? "");+const lines = output.split(/\r?\n/);const filtered = lines.filter((line) => !SUPPRESSED_CODES.some((code) => line.includes(code))@@ -51,6 +59,11 @@ if (errorIndex > 0) {console.log(numbered.join("\n"));console.log(`\n${errorIndex} error(s) found.`);process.exit(1);+} else if (result.status !== 0) {+ // The compiler failed without emitting anything we recognise as a diagnostic+ // (crash, bad option, missing binary). Never report that as a clean build.+ console.error(output.trim() || `tsc exited with code ${result.status}.`);+ process.exit(result.status ?? 1);} else {console.log("No errors found.");}