Skip to content

Build your personal knowledge base with Trilium Notes

build: name the native compiler @typescript/native, and record why the compat package is unusable

Elian Doran02edbeb1c1bc
diff --git a/CLAUDE.md b/CLAUDE.md
index e577f28800..eefa7e4b02 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -421,8 +421,15 @@ The viewer under `packages/pdfjs-viewer/viewer/` is vendored from the pdf.js Git
- 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:
+The root `package.json` declares **both** `typescript` (6.x) and `@typescript/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.
+- **`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")` needs 6.x: TypeDoc, typescript-eslint, and — the one that also ships to users — `packages/codemirror`, which runs the real language service in the browser for script-note IntelliSense.
+- **`@typescript/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.
+
+**Do not switch to `@typescript/typescript6`.** Microsoft's documented side-by-side layout aliases `typescript` to that compatibility shim so the native compiler can own the `tsc` bin name. It does not fit here, for two reasons that only show up at build time:
+
+- The shim ships five files and **no `lib.*.d.ts`**, so the 96 `typescript/lib/lib.*.d.ts?raw` imports in `packages/codemirror/src/type_completion/ts_lib_files.ts` fail to resolve and the client build dies.
+- Working around that by keeping a real `typescript` under `packages/codemirror` splits resolution: `@typescript/vfs` and `@valtown/codemirror-ts` are hoisted to the root and follow the shim, while codemirror's own source follows its nested copy. Two physical paths means the 3.3 MB compiler is bundled **twice** into the lazy script-note chunk (measured: client `dist` 69 M → 72 M).
+
+The official layout assumes the only consumer of the `typescript` name is tooling. This repo also bundles it into a browser app, so the plain package has to stay.
diff --git a/package.json b/package.json
index f1adad0c9a..5b6de60dda 100644
--- a/package.json
+++ b/package.json
@@ -61,6 +61,7 @@
"@triliumnext/server": "workspace:*",
"@types/express": "5.0.6",
"@types/node": "24.13.3",
+ "@typescript/native": "npm:[email protected]",
"@vitest/browser-webdriverio": "4.1.10",
"@vitest/coverage-v8": "4.1.10",
"@vitest/ui": "4.1.10",
@@ -75,7 +76,6 @@
"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.yaml
index b7921b9793..e0170a86c7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -107,6 +107,9 @@ importers:
'@types/node':
specifier: 24.13.3
version: 24.13.3
+ '@typescript/native':
+ specifier: npm:[email protected]
'@vitest/browser-webdriverio':
specifier: 4.1.10
@@ -149,9 +152,6 @@ importers:
js-yaml:
specifier: 5.2.3
version: 5.2.3
- tsc-native:
- specifier: npm:[email protected]
tslib:
specifier: 2.8.1
version: 2.8.1
diff --git a/scripts/filter-tsc-output.mts b/scripts/filter-tsc-output.mts
index 63d7763ff5..42811876af 100644
--- a/scripts/filter-tsc-output.mts
+++ b/scripts/filter-tsc-output.mts
@@ -2,16 +2,17 @@
* 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.
+ * The compiler is the native (Go) one, installed as `@typescript/native` -- 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 and the browser-side script editor all load it.
+ * See "Two TypeScript versions, on purpose" in CLAUDE.md.
*/
import { spawnSync } from "child_process";
import { fileURLToPath } from "url";
-const TSC = fileURLToPath(new URL("../node_modules/tsc-native/bin/tsc", import.meta.url));
+const TSC = fileURLToPath(new URL("../node_modules/@typescript/native/bin/tsc", import.meta.url));
const SUPPRESSED_CODES = [ "TS6305" ];
const ERROR_LINE_PATTERN = /^.+\(\d+,\d+\): error TS\d+:/;