Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Run Open Knowledge typechecks on tsrs (#7406)

Dimitri POSTOLOV21b17e056ee6
diff --git a/.changeset/typecheck-on-tsrs.md b/.changeset/typecheck-on-tsrs.md
new file mode 100644
index 000000000..5fbe87833
--- /dev/null
+++ b/.changeset/typecheck-on-tsrs.md
@@ -0,0 +1,5 @@
+---
+'@inkeep/open-knowledge': patch
+---
+
+Contributor typechecks now run on `tsrs`, a Rust port of the TypeScript compiler. On Windows or an Intel Mac, set `TSRS_BINARY` first, as the [contributing guide](https://github.com/inkeep/open-knowledge/blob/main/CONTRIBUTING.md#toolchain) explains.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 94e3c34bb..b4b6eb564 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -30,7 +30,7 @@ When a fix ships, we close your issue, and our release automation usually commen
## Development setup
-A fresh clone builds and tests with no environment variables:
+A fresh clone builds and tests with no environment variables, except `TSRS_BINARY` on Windows or an Intel Mac (see Toolchain below):
```bash
corepack enable pnpm # make the pnpm commands below use the packageManager pin
@@ -58,7 +58,13 @@ The repo pins **Node.js 24.21.0** in `.node-version` and in `package.json`'s `de
Rust is pinned to one exact release. `rust-toolchain.toml` at the repo root declares it, and rustup applies it to every `cargo` and `rustc` call inside the repository and installs that release on the first build, so that build needs network access once. Install rustup from [rustup.rs](https://rustup.rs). The native-config package's build script refuses any other compiler: a `RUSTUP_TOOLCHAIN` variable, a `+toolchain` argument, a `rustup override` set on the directory, or a `cargo` or `rustc` earlier on your `PATH` that rustup does not manage (a Homebrew, distribution or Nix install, for example). Its error names the compiler it found and the release the file declares.
-TypeScript is pinned twice on purpose. `@typescript/native` is this repo's alias for `typescript@~7.0.2`, the Go compiler the gates run; it owns the `tsc` binary, so `node_modules/.bin/tsc --version` at the root reports 7. The root's own `typescript` stays on `~6.0.3` only to supply tsserver to your editor, because TypeScript 7 ships none — that is an API resolution, not the compiler. The split means 7.0-only lib typings or an unchecked side-effect import can red a gate your editor calls clean. Open your editor at the repo root, not inside a package, or its language server falls back to a machine-global TypeScript. Any package that runs `tsc` in a script declares `"typescript": "~7.0.2"` of its own; `node scripts/check-typescript-resolution.mjs`, which `pnpm run check:drift:guards` runs, enforces the *resolved* 7.0 line rather than the declared range; the range is a tilde for that reason, because a caret installs clean today and reds once 7.1 ships. Its errors say why.
+TypeScript is pinned twice on purpose. `@typescript/native` is this repo's alias for `typescript@~7.0.2`, the Go compiler that builds and declaration emit run; it owns the `tsc` binary, so `node_modules/.bin/tsc --version` at the root reports 7. The root's own `typescript` stays on `~6.0.3` only to supply tsserver to your editor, because TypeScript 7 ships none — that is an API resolution, not the compiler. The split means 7.x-only lib typings or an unchecked side-effect import can red a gate your editor calls clean. Open your editor at the repo root, not inside a package, or its language server falls back to a machine-global TypeScript. The typecheck gates run `tsrs` instead of `tsc`: a Rust port of the TypeScript compiler, built from TypeScript 7.1 dev builds, with native binaries only for macOS arm64 and Linux. Each package that runs it declares an exact `tsrs` version, and the guard below checks that pin. On Windows or an Intel Mac, `tsrs` has no binary and stops with an error that names its `TSRS_BINARY` setting. Point that setting at the native executable of the TypeScript 7.0.2 Go compiler (tsgo), which `tsrs` then runs with the same arguments. From the repo root, in a Bash-compatible shell:
+
+```bash
+export TSRS_BINARY="$(node -p "const p=require('path'),r=require('module').createRequire(require.resolve('@typescript/native/package.json'));p.join(p.dirname(r.resolve('@typescript/typescript-'+process.platform+'-'+process.arch+'/package.json')),'lib',process.platform==='win32'?'tsc.exe':'tsc')")"
+```
+
+`turbo.json` passes `TSRS_BINARY` to every task that runs `tsrs` and includes it in those tasks' cache keys, so `pnpm run typecheck` and `pnpm run check` pick it up and never reuse a result from the other compiler. Local checks on those platforms then run on TypeScript 7.0.2 instead of 7.1-dev. CI runs the typecheck gate on Linux, with `tsrs`. Any package that runs `tsc` in a script declares `"typescript": "~7.0.2"` of its own; `node scripts/check-typescript-resolution.mjs`, which `pnpm run check:drift:guards` runs, enforces the *resolved* 7.0 line rather than the declared range; the range is a tilde for that reason, because a caret installs clean today and reds once 7.1 ships. Its errors say why.
The base `tsconfig.json` carries three settings that red a first build. `erasableSyntaxOnly: true` makes constructor parameter properties (`constructor(private foo: string)`) an error; write the assignment out. `verbatimModuleSyntax: true` makes a plain `import { SomeType }` an error; write `import type`. `types: []` turns off automatic `@types/*` inclusion, so a package that uses Node globals lists `"types": ["node"]` in its own `tsconfig.json` and `@types/node` in its own `package.json`.
diff --git a/docs/package.json b/docs/package.json
index 8db5f51fd..53cc5aa28 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -11,7 +11,7 @@
"start": "next start --port 3010",
"test": "vitest run src && pnpm run test:real-source",
"test:real-source": "vitest run --config vitest.real-source.config.mts",
- "typecheck": "next typegen && fumadocs-mdx && tsc --noEmit",
+ "typecheck": "next typegen && fumadocs-mdx && tsrs --noEmit",
"validate-link": "node --import tsx scripts/validate-link.ts",
"generate:og-wordmark": "node --import tsx scripts/generate-og-wordmark.ts",
"generate:brand-assets": "node --import tsx scripts/generate-brand-assets.ts",
@@ -66,6 +66,7 @@
"sharp": "^0.35.3",
"tailwind-scrollbar": "^4.0.2",
"tailwindcss": "^4",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"typescript": "~7.0.2"
}
}
diff --git a/package.json b/package.json
index d66969366..3e9548ed4 100644
--- a/package.json
+++ b/package.json
@@ -53,8 +53,8 @@
"changeset": "changeset",
"version": "changeset version",
"release": "changeset publish",
- "typecheck:lint-plugins": "tsc --noEmit -p lint-plugins/ok-rules/tsconfig.json",
- "typecheck:no-net-connect": "tsc --noEmit -p test-support/tsconfig.no-net-connect.json"
+ "typecheck:lint-plugins": "tsrs --noEmit -p lint-plugins/ok-rules/tsconfig.json",
+ "typecheck:no-net-connect": "tsrs --noEmit -p test-support/tsconfig.no-net-connect.json"
},
"lint-staged": {
"packages/**/*.{ts,tsx,js,jsx,json,md}": [
@@ -88,6 +88,7 @@
"oxlint-tsgolint": "^7.0.2001",
"smol-toml": "^1.6.1",
"ts-morph": "^28.0.0",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"tsx": "^4.20.0",
"turbo": "^2.11.5",
"typescript": "~6.0.3",
diff --git a/packages/app/package.json b/packages/app/package.json
index b0788694c..e4328e48a 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -17,7 +17,7 @@
"dev": "vite",
"build": "node scripts/compile-i18n-catalogs.ts && node scripts/copy-excalidraw-assets.mjs && tsc --noEmit && vite build && pnpm run check:no-dev-harness",
"check:no-dev-harness": "node scripts/check-dev-harness-absent.mjs",
- "typecheck": "node scripts/compile-i18n-catalogs.ts && tsc --noEmit",
+ "typecheck": "node scripts/compile-i18n-catalogs.ts && tsrs --noEmit",
"i18n": "pnpm run i18n:extract && pnpm run i18n:compile",
"i18n:extract": "lingui extract --clean --locale en,zh-Hans,zh-Hant,hi,es,ar,fr,bn,pt-BR,id,ur,ko,pl",
"i18n:compile": "node scripts/compile-i18n-catalogs.ts",
@@ -30,7 +30,7 @@
"test:dom:shard3": "vitest run --config vitest.dom.config.ts --shard=3/3",
"test:browser": "vitest run --config vitest.browser.config.ts",
"test:node": "vitest run --config vitest.node.config.ts",
- "check": "node scripts/compile-i18n-catalogs.ts && tsc --noEmit && biome check . && pnpm run test && pnpm run test:dom && pnpm run test:integration && pnpm run test:conversion && pnpm -w run test:uncached",
+ "check": "node scripts/compile-i18n-catalogs.ts && tsrs --noEmit && biome check . && pnpm run test && pnpm run test:dom && pnpm run test:integration && pnpm run test:conversion && pnpm -w run test:uncached",
"test:integration": "vitest run --config vitest.integration.config.ts",
"test:integration:shard1": "vitest run --config vitest.integration.config.ts --shard=1/12",
"test:integration:shard2": "vitest run --config vitest.integration.config.ts --shard=2/12",
@@ -237,6 +237,7 @@
"sirv": "^3.0.2",
"size-limit": "^12.1.0",
"ts-morph": "^28.0.0",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"typescript": "~7.0.2",
"unified": "^11.0.5",
"vite": "^8.0.0",
diff --git a/packages/cli/package.json b/packages/cli/package.json
index abb59bbd6..9b8c9f1aa 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -51,7 +51,7 @@
"build": "pnpm run build:cli && pnpm run build:assets",
"test": "vitest run",
"test:e2e:cli": "vitest run --config vitest.e2e.config.ts",
- "typecheck": "tsc --noEmit",
+ "typecheck": "tsrs --noEmit",
"check:dts": "node scripts/check-published-dts.mjs",
"verify:package": "node scripts/verify-package-surface.mjs",
"prepublishOnly": "bash ../../scripts/check-notices-clean.sh && pnpm run build && pnpm run check:dts && pnpm run verify:package"
@@ -92,6 +92,7 @@
"ajv": "^8.18.0",
"ajv-formats": "^3.0.1",
"tsdown": "^0.22.14",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"typescript": "~7.0.2"
}
}
diff --git a/packages/core/package.json b/packages/core/package.json
index b2dcc47d8..87e46fa92 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -902,8 +902,8 @@
"scripts": {
"build": "node scripts/build-output.mjs build",
"verify:exports": "node scripts/verify-exports-targets.mjs",
- "typecheck": "tsc --noEmit && tsc -p tsconfig.perf.json --noEmit && tsc -p tests/contract/subpath-types/tsconfig.json --noEmit",
- "check:dts": "tsc -p tsconfig.check.json --noEmit",
+ "typecheck": "tsrs --noEmit && tsrs -p tsconfig.perf.json --noEmit && tsrs -p tests/contract/subpath-types/tsconfig.json --noEmit",
+ "check:dts": "tsrs -p tsconfig.check.json --noEmit",
"test": "vitest run src/ tests/contract/ scripts/",
"test:perf:bench": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --expose-gc\" RUN_BENCH=1 vitest run tests/perf/markdown-bench.test.ts",
"test:perf:regression:unit": "vitest run tests/perf/regression-gate.test.ts",
@@ -933,6 +933,7 @@
"micromark": "^4.0.2",
"micromark-util-symbol": "^2.0.1",
"tsdown": "^0.22.14",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"typescript": "~7.0.2",
"vitest": "^5.0.3",
"y-prosemirror": "1.3.7"
diff --git a/packages/desktop/package.json b/packages/desktop/package.json
index 7dcd5e352..9411ff2d7 100644
--- a/packages/desktop/package.json
+++ b/packages/desktop/package.json
@@ -31,7 +31,7 @@
"smoke:mock-update": "OK_UPDATER_FORCE_DEV=1 node scripts/smoke-mock-update.mjs",
"instances": "node scripts/launch-instances.mjs",
"lint": "biome check . && oxlint --max-warnings 0 .",
- "typecheck": "tsc --noEmit",
+ "typecheck": "tsrs --noEmit",
"test": "vitest run"
},
"dependencies": {
@@ -65,7 +65,7 @@
"electron-builder": "^26.16.1",
"electron-vite": "^6.0.0-beta.1",
"ts-morph": "^28.0.0",
- "typescript": "~7.0.2",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"vite": "^8.0.0"
}
}
diff --git a/packages/server/package.json b/packages/server/package.json
index f95ed57b2..671c24223 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -73,7 +73,7 @@
"scripts": {
"build": "tsdown && pnpm run build:skill-bundles",
"build:skill-bundles": "node --import tsx scripts/build-skill-bundles.ts",
- "typecheck": "pnpm run typecheck:bash && pnpm run typecheck:test-helper-callers && tsc",
+ "typecheck": "pnpm run typecheck:bash && pnpm run typecheck:test-helper-callers && tsrs",
"test": "vitest run",
"test:shard1": "vitest run --shard=1/4",
"test:shard2": "vitest run --shard=2/4",
@@ -83,8 +83,8 @@
"test:mcp-inspector": "vitest run --config vitest.mcp-inspector.config.ts",
"measure:generated-index-sweep": "node --import tsx --conditions=development measure-generated-index-sweep.ts",
"measure:observer-a-drain": "node --import tsx --conditions=development measure-observer-a-drain.ts",
- "typecheck:bash": "tsc -p tsconfig.bash.json",
- "typecheck:test-helper-callers": "tsc --noEmit -p tsconfig.test-helper-callers.json"
+ "typecheck:bash": "tsrs -p tsconfig.bash.json",
+ "typecheck:test-helper-callers": "tsrs --noEmit -p tsconfig.test-helper-callers.json"
},
"devDependencies": {
"@types/mdast": "^4.0.4",
@@ -97,6 +97,7 @@
"lib0": "^0.2.117",
"ts-morph": "^28.0.0",
"tsdown": "^0.22.14",
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
"typescript": "~7.0.2"
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 51b3171d9..756e4b326 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -206,6 +206,9 @@ importers:
ts-morph:
specifier: ^28.0.0
version: 28.0.0
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
tsx:
specifier: ^4.20.0
version: 4.23.0
@@ -363,6 +366,9 @@ importers:
tailwindcss:
specifier: ^4
version: 4.3.2
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
typescript:
specifier: ~7.0.2
version: 7.0.2
@@ -805,6 +811,9 @@ importers:
ts-morph:
specifier: ^28.0.0
version: 28.0.0
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
typescript:
specifier: ~7.0.2
version: 7.0.2
@@ -914,6 +923,9 @@ importers:
tsdown:
specifier: ^0.22.14
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
typescript:
specifier: ~7.0.2
version: 7.0.2
@@ -1159,6 +1171,9 @@ importers:
tsdown:
specifier: ^0.22.14
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
typescript:
specifier: ~7.0.2
version: 7.0.2
@@ -1247,9 +1262,9 @@ importers:
ts-morph:
specifier: ^28.0.0
version: 28.0.0
- typescript:
- specifier: ~7.0.2
- version: 7.0.2
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
vite:
specifier: ^8.0.0
@@ -1258,68 +1273,6 @@ importers:
specifier: 1.2.0-beta.15
version: 1.2.0-beta.15
- packages/md-conformance:
- dependencies:
- '@inkeep/open-knowledge-core':
- specifier: workspace:*
- version: link:../core
- '@tiptap/core':
- specifier: 3.22.3
- version: 3.22.3(@tiptap/[email protected])
- '@tiptap/pm':
- specifier: 3.22.4
- version: 3.22.4
- fast-check:
- specifier: ^4.6.0
- version: 4.9.0
- ts-morph:
- specifier: ^28.0.0
- version: 28.0.0
- yjs:
- specifier: ^13.6.30
- version: 13.6.31
- zod:
- specifier: ^4.3.6
- version: 4.4.3
- devDependencies:
- '@types/mdast':
- specifier: ^4.0.4
- version: 4.0.4
- '@types/node':
- specifier: ^24.7.0
- version: 24.13.3
- commonmark.json:
- specifier: 0.31.0
- version: 0.31.0
- typescript:
- specifier: ~7.0.2
- version: 7.0.2
-
- packages/md-conformance/md-audit:
- dependencies:
- '@types/mdast':
- specifier: ^4.0.4
- version: 4.0.4
- mdast-util-to-markdown:
- specifier: ^2.1.2
- version: 2.1.2
- ts-morph:
- specifier: ^28.0.0
- version: 28.0.0
- devDependencies:
- '@types/node':
- specifier: ^24.7.0
- version: 24.13.3
- tsx:
- specifier: ^4.20.0
- version: 4.23.0
- typescript:
- specifier: ~7.0.2
- version: 7.0.2
- vitest:
- specifier: ^5.0.3
-
packages/native-config:
devDependencies:
'@napi-rs/cli':
@@ -1490,6 +1443,9 @@ importers:
tsdown:
specifier: ^0.22.14
+ tsrs:
+ specifier: 0.18.0-ts7.1.0-dev.20260929
+ version: 0.18.0-ts7.1.0-dev.20260929
typescript:
specifier: ~7.0.2
version: 7.0.2
@@ -6047,6 +6003,40 @@ packages:
'@ts-morph/[email protected]':
resolution: {integrity: sha512-35oUmphHbJvQ/+UTwFNme/t2p3FoKiGJ5auTjjpNTop2dyREspirjMy82PLSC1pnDJ8ah1GU98hwpVt64YXQsg==}
+ resolution: {integrity: sha512-sAirMpaGA9uRQm2W+t4zC7PjnijNuFa4PCSIfLKKo0JyAUCRfnMeev0UGBQ9F3g+9Nz187tvikUs5Irh5+eajA==}
+ engines: {node: '>=16.20.0'}
+ cpu: [arm64]
+ os: [darwin]
+
+ resolution: {integrity: sha512-zm9/z9yylig68JiZF4Aq0Cm26n09KEU8YoQRlG7tdDWTBNAIViYw8knxnWYsjMWVZ2XiU4mYq1xdrOKuOgABHg==}
+ engines: {node: '>=16.20.0'}
+ cpu: [arm64]
+ os: [linux]
+ libc: [glibc]
+
+ resolution: {integrity: sha512-Lw7VVU/YQ9JcarODICEiwzMLdFqZprqh5RGTgbS5Uc6I95P635/g5xA1pOC8RVs4efBvAR30J54iDG3l5JEYiw==}
+ engines: {node: '>=16.20.0'}
+ cpu: [arm64]
+ os: [linux]
+ libc: [musl]
+
+ resolution: {integrity: sha512-EdBwBgNICGu1r1h23ixdcKwsMo6E9ll7ZsY3mNERNYqE1Pwdtcat99d5E7zB1J+oy/Xk6YqiizaB6nolIjpDTw==}
+ engines: {node: '>=16.20.0'}
+ cpu: [x64]
+ os: [linux]
+ libc: [glibc]
+
+ resolution: {integrity: sha512-LHk+AOAtXuTlhJhOJ2+elriEIX17ycXljojeNxrrzckOipTG1LksoVWuCSas2nu00EnWAzrdKpt9oqPylUKZfQ==}
+ engines: {node: '>=16.20.0'}
+ cpu: [x64]
+ os: [linux]
+ libc: [musl]
+
resolution: {integrity: sha512-KdY4y7BBjIisl+jAkb3FFaRjClGqHyaeHCcVcCT8LBzFFwUu6thgfxyRZAx0uL4KoxLmH+iOan8UhVf/aDDcaA==}
cpu: [x64]
@@ -11742,6 +11732,11 @@ packages:
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
+ resolution: {integrity: sha512-9T0b4Uam/yMFIK16GUx0fUrJqYZnJ/gvSmV9JB8NTyDePvwCI45WFWxyEV/UMV3KfdNRJG/PBsm3fSIB9WmWsA==}
+ engines: {node: '>=16.20.0'}
+ hasBin: true
+
resolution: {integrity: sha512-eUdUIaCr963q2h5u3+QwvYp0+eqPvn+egeqZUm0hwERCqqx1E3kK5ehbGCvqSE5MQAULr67ww0cA3jKc3YkM1w==}
engines: {node: '>=18.0.0'}
@@ -16914,6 +16909,21 @@ snapshots:
path-browserify: 1.0.1
tinyglobby: 0.2.17
+ optional: true
+
+ optional: true
+
+ optional: true
+
+ optional: true
+
+ optional: true
+
optional: true
@@ -23629,6 +23639,14 @@ snapshots:
+ optionalDependencies:
+ '@tsrs/darwin-arm64': 0.18.0-ts7.1.0-dev.20260929
+ '@tsrs/linux-arm64-gnu': 0.18.0-ts7.1.0-dev.20260929
+ '@tsrs/linux-arm64-musl': 0.18.0-ts7.1.0-dev.20260929
+ '@tsrs/linux-x64-gnu': 0.18.0-ts7.1.0-dev.20260929
+ '@tsrs/linux-x64-musl': 0.18.0-ts7.1.0-dev.20260929
+
dependencies:
esbuild: 0.28.1
diff --git a/scripts/check-override-floors.mjs b/scripts/check-override-floors.mjs
index 587737749..c53bc3e53 100644
--- a/scripts/check-override-floors.mjs
+++ b/scripts/check-override-floors.mjs
@@ -25,7 +25,7 @@ export function parseOverrideBlockLines(yamlText) {
return out;
}
-const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
+export const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
export function parseExactOverrides(yamlText) {
const out = new Map();
diff --git a/scripts/check-typescript-resolution.mjs b/scripts/check-typescript-resolution.mjs
index 87f9989e5..8bde2c2de 100644
--- a/scripts/check-typescript-resolution.mjs
+++ b/scripts/check-typescript-resolution.mjs
@@ -5,11 +5,77 @@ import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { pathToFileURL } from 'node:url';
-import { expandPackagePattern, parsePackagePatterns } from './check-override-floors.mjs';
+import {
+ EXACT_VERSION,
+ expandPackagePattern,
+ parsePackagePatterns,
+} from './check-override-floors.mjs';
import { readJsoncOrError } from './read-jsonc.mjs';
export const GATE_LINE = '7.0';
export const SHIM_LINE = '6.0';
+export const TSRS_LINE = '7.1';
+
+const RUNS_TSRS = /(^|[\s&|;(])(?:[^\s&|;()]*\/)?tsrs(\s|$)/;
+
+export function tsrsSupportsPlatform(optionalDependencies, platform, arch) {
+ const binaries = Object.keys(optionalDependencies ?? {}).filter((name) =>
+ name.startsWith('@tsrs/'),
+ );
+ if (binaries.length === 0) return null;
+ const key = `@tsrs/${platform}-${arch}`;
+ return binaries.some((name) => name === key || name.startsWith(`${key}-`));
+}
+
+export function checkTsrsPinsAgree(members) {
+ const pinned = members.filter(
+ ({ scripts, tsrsDeclared }) =>
+ tsrsDeclared &&
+ EXACT_VERSION.test(tsrsDeclared) &&
+ Object.values(scripts ?? {}).some((body) => RUNS_TSRS.test(String(body))),
+ );
+ const versions = new Set(pinned.map(({ tsrsDeclared }) => tsrsDeclared));
+ if (versions.size <= 1) return [];
+ const listed = pinned.map(({ name, tsrsDeclared }) => `${name}@${tsrsDeclared}`).join(', ');
+ return [
+ `packages that run \`tsrs\` pin ${versions.size} different exact versions (${listed}). Every typecheck gate must run one compiler build, so pin the same version everywhere.`,
+ ];
+}
+
+export function checkTsrs({
+ name,
+ dir,
+ scripts,
+ tsrsDeclared,
+ tsrsResolved,
+ tsrsBinVersion,
+ tsrsPlatformSupported = null,
+}) {
+ const runners = Object.entries(scripts ?? {}).filter(([, body]) => RUNS_TSRS.test(String(body)));
+ if (runners.length === 0) return [];
+ const where = `${name} (${dir})`;
+ const listed = runners.map(([script]) => `\`${script}\``).join(', ');
+ if (!tsrsDeclared) {
+ return [
+ `${where} runs \`tsrs\` in ${listed} without declaring tsrs. The binary then resolves by walking up to the workspace root, so this gate checks on whatever tsrs another package happens to install.`,
+ ];
+ }
+ if (!EXACT_VERSION.test(tsrsDeclared)) {
+ return [
+ `${where} declares tsrs ${tsrsDeclared}, not an exact version. tsrs ships TypeScript dev builds, so a range lets an install move the type checker to a different compiler build without a manifest edit.`,
+ ];
+ }
+ if (tsrsResolved !== tsrsDeclared) {
+ return [`${where} declares tsrs ${tsrsDeclared} but resolves ${tsrsResolved ?? 'nothing'}.`];
+ }
+ if (tsrsPlatformSupported === false) return [];
+ if (versionLine(tsrsBinVersion) !== TSRS_LINE) {
+ return [
+ `${where} runs a \`tsrs\` reporting TypeScript ${tsrsBinVersion ?? 'nothing'}, not ${TSRS_LINE}.x.`,
+ ];
+ }
+ return [];
+}
const VERSION_LINE = /^(\d+\.\d+)\./;
@@ -79,7 +145,7 @@ export function checkConditions({ baseConditions, declarationBuild }) {
baseConditions[0] !== SOURCE_CONDITION
) {
violations.push(
- `the base tsconfig declares customConditions ${JSON.stringify(baseConditions ?? null)}, not ["${SOURCE_CONDITION}"]. That condition is what makes a leaf typecheck resolve a sibling to its src rather than to a dist that may not exist yet; dropping it turns every per-package \`tsc --noEmit\` into a build-first command without any of them changing.`,
+ `the base tsconfig declares customConditions ${JSON.stringify(baseConditions ?? null)}, not ["${SOURCE_CONDITION}"]. That condition is what makes a leaf typecheck resolve a sibling to its src rather than to a dist that may not exist yet; dropping it turns every per-package \`tsrs --noEmit\` typecheck into a build-first command without any of them changing.`,
);
}
for (const [file, conditions] of declarationBuild.configs) {
@@ -490,10 +556,13 @@ export function collectViolations(
emitConfigs,
sourceSites,
tsconfigSites = [],
+ rootMember = null,
) {
return [
...checkRoot(root),
...members.flatMap((member) => checkMember(member)),
+ ...[...(rootMember ? [rootMember] : []), ...members].flatMap((member) => checkTsrs(member)),
+ ...checkTsrsPinsAgree([...(rootMember ? [rootMember] : []), ...members]),
...(conditions ? checkConditions(conditions) : []),
...checkTsconfigConditions(
tsconfigSites,
@@ -512,12 +581,12 @@ function readJson(file) {
}
}
-function binVersionOf(dir) {
+function binVersionOf(dir, program = 'tsc') {
const bin = path.join(
dir,
'node_modules',
'.bin',
- process.platform === 'win32' ? 'tsc.cmd' : 'tsc',
+ process.platform === 'win32' ? `${program}.cmd` : program,
);
if (!fs.existsSync(bin)) return null;
try {
@@ -676,6 +745,22 @@ export function probeMember(dir, readManifest = readJson) {
readJson(path.join(dir, 'node_modules', 'typescript', 'package.json'))?.version ?? null,
binVersion: declaredRange ? binVersionOf(dir) : null,
scripts: manifest.scripts ?? null,
+ ...probeTsrs(dir, manifest),
+ };
+}
+
+export function probeTsrs(dir, manifest) {
+ const tsrsDeclared = manifest?.devDependencies?.tsrs ?? manifest?.dependencies?.tsrs ?? null;
+ const resolved = readJson(path.join(dir, 'node_modules', 'tsrs', 'package.json'));
+ const tsrsPlatformSupported = resolved
+ ? tsrsSupportsPlatform(resolved.optionalDependencies, process.platform, process.arch)
+ : null;
+ return {
+ tsrsDeclared,
+ tsrsResolved: resolved?.version ?? null,
+ tsrsPlatformSupported,
+ tsrsBinVersion:
+ tsrsDeclared && tsrsPlatformSupported !== false ? binVersionOf(dir, 'tsrs') : null,
};
}
@@ -697,6 +782,12 @@ export function memberDirs(root, yamlText, onUnparsed, onEmptyPattern) {
return [...new Set(dirs)].sort();
}
+function tsrsBinNote(onTsrs) {
+ return onTsrs.some((member) => member.tsrsPlatformSupported === false)
+ ? `whose ${TSRS_LINE}.x binary line is not checked on ${process.platform}-${process.arch}, where tsrs ships no binary`
+ : `reporting ${TSRS_LINE}.x`;
+}
+
export function evaluate({
root,
rootSource = null,
@@ -708,6 +799,7 @@ export function evaluate({
emitConfigs,
sourceSites,
tsconfigs = { files: [], sites: [] },
+ rootMember = null,
}) {
const violations = collectViolations(
rootProbe,
@@ -716,6 +808,10 @@ export function evaluate({
emitConfigs,
sourceSites,
tsconfigs.sites,
+ rootMember,
+ );
+ const onTsrs = [...(rootMember ? [rootMember] : []), ...members].filter(
+ (member) => member.tsrsDeclared,
);
if (violations.length === 0) {
return {
@@ -723,7 +819,7 @@ export function evaluate({
violations,
err: [],
out: [
- `check-typescript-resolution: OK at ${root}${rootSource === null ? '' : ` [from ${rootSource}]`} (root tsc ${rootProbe.binVersion} over a ${rootProbe.shimVersion} tsserver shim; ${gated.length} of ${members.length} workspace packages declare typescript and all run ${GATE_LINE}.x; base customConditions ["${SOURCE_CONDITION}"] with every one of the ${declarationBuild.configs.length} packages that publish an emitted declaration resetting it, and every one of the ${emitConfigs.length} tsdown configs among them emitting declarations through that reset config, per entry (${unbundleCensus(emitConfigs)}); ${sourceSites.length} packages declare an \`exports\` field and each resolves through the source condition first, or not at all, exactly as its publication status requires; of the ${tsconfigs.files.length} tsconfig files under the root, customConditions appears only in the base ${BASE_TSCONFIG} and in ${RESET_TSCONFIGS.join(' or ')} configs that reset it)`,
+ `check-typescript-resolution: OK at ${root}${rootSource === null ? '' : ` [from ${rootSource}]`} (root tsc ${rootProbe.binVersion} over a ${rootProbe.shimVersion} tsserver shim; ${gated.length} of ${members.length} workspace packages declare typescript and all resolve ${GATE_LINE}.x for builds and the API; ${onTsrs.length} packages, the root included, type-check on an exact tsrs pin ${tsrsBinNote(onTsrs)}; base customConditions ["${SOURCE_CONDITION}"] with every one of the ${declarationBuild.configs.length} packages that publish an emitted declaration resetting it, and every one of the ${emitConfigs.length} tsdown configs among them emitting declarations through that reset config, per entry (${unbundleCensus(emitConfigs)}); ${sourceSites.length} packages declare an \`exports\` field and each resolves through the source condition first, or not at all, exactly as its publication status requires; of the ${tsconfigs.files.length} tsconfig files under the root, customConditions appears only in the base ${BASE_TSCONFIG} and in ${RESET_TSCONFIGS.join(' or ')} configs that reset it)`,
],
};
}
@@ -734,7 +830,7 @@ export function evaluate({
err: [
'check-typescript-resolution: the declaration and compiler contract this workspace declares does not hold.\n',
...violations.map((violation) => ` ${violation}`),
- `\nA compiler-version violation is usually a stale install: run \`pnpm install\` from ${root}, and declare typescript in any package that was added rather than letting resolution walk up to the root shim. A customConditions violation is a tsconfig edit, and the remedy differs by which one fired: the base tsconfig must declare \`customConditions: ["@inkeep/source"]\` so leaf typechecks resolve siblings from source; each declaration build config must extend that base and reset \`customConditions: []\` so the published surface resolves from built declarations instead; a declaration build config that is missing entirely must be added; and every other tsconfig under the root must carry no customConditions key of its own, since a child replaces the base array rather than adding to it. A dts violation is a tsdown edit: bind \`dts\` to \`{ tsconfig: 'tsconfig.build.json' }\` so the declaration emit runs under the reset config rather than the base. Do not answer a base-tsconfig violation by setting \`[]\` there, which is the opposite of what it asks.`,
+ `\nA compiler-version violation is usually a stale install: run \`pnpm install\` from ${root}, and declare typescript in any package that was added rather than letting resolution walk up to the root shim. A tsrs violation asks for the same exact tsrs version in every package whose scripts run \`tsrs\`: declare it with \`pnpm add -D -E tsrs@<version>\` in that package, then run \`pnpm install\`; a new tsrs release on another TypeScript line also needs TSRS_LINE raised in this script. A customConditions violation is a tsconfig edit, and the remedy differs by which one fired: the base tsconfig must declare \`customConditions: ["@inkeep/source"]\` so leaf typechecks resolve siblings from source; each declaration build config must extend that base and reset \`customConditions: []\` so the published surface resolves from built declarations instead; a declaration build config that is missing entirely must be added; and every other tsconfig under the root must carry no customConditions key of its own, since a child replaces the base array rather than adding to it. A dts violation is a tsdown edit: bind \`dts\` to \`{ tsconfig: 'tsconfig.build.json' }\` so the declaration emit runs under the reset config rather than the base. Do not answer a base-tsconfig violation by setting \`[]\` there, which is the opposite of what it asks.`,
],
};
}
@@ -835,6 +931,7 @@ function main() {
emitConfigs,
sourceSites,
tsconfigs: { files: listed.files, sites: declared.sites },
+ rootMember: probeMember(root),
});
for (const line of out) console.log(line);
for (const line of err) console.error(line);
diff --git a/scripts/check-typescript-resolution.test.mjs b/scripts/check-typescript-resolution.test.mjs
index 3d52d518d..92a516232 100644
--- a/scripts/check-typescript-resolution.test.mjs
+++ b/scripts/check-typescript-resolution.test.mjs
@@ -12,6 +12,8 @@ import {
checkRoot,
checkSourceCondition,
checkTsconfigConditions,
+ checkTsrs,
+ checkTsrsPinsAgree,
collectViolations,
declarationBuildConfigs,
declarationEmitConfigs,
@@ -27,6 +29,8 @@ import {
SHIM_LINE,
SOURCE_CONDITION,
sourceConditionSites,
+ TSRS_LINE,
+ tsrsSupportsPlatform,
staleNonTscListing,
tsconfigConditions,
tsconfigFiles,
@@ -121,6 +125,136 @@ describe('checkRoot', () => {
});
});
+const tsrsMember = (over = {}) => ({
+ name: '@inkeep/open-knowledge-core',
+ dir: '/ok/packages/core',
+ scripts: { typecheck: 'tsrs --noEmit' },
+ tsrsDeclared: '0.18.0-ts7.1.0-dev.20260929',
+ tsrsResolved: '0.18.0-ts7.1.0-dev.20260929',
+ tsrsBinVersion: '7.1.0-dev.20260930.4',
+ ...over,
+});
+
+describe('checkTsrs', () => {
+ it('accepts a package that pins, resolves and runs tsrs on its TypeScript line', () => {
+ expect(checkTsrs(tsrsMember())).toEqual([]);
+ });
+
+ it('ignores a package whose scripts do not run tsrs', () => {
+ expect(
+ checkTsrs(tsrsMember({ scripts: { typecheck: 'tsc --noEmit' }, tsrsDeclared: null })),
+ ).toEqual([]);
+ });
+
+ it('does not match a lookalike that merely starts with tsrs', () => {
+ expect(
+ checkTsrs(tsrsMember({ scripts: { typecheck: 'tsrs-bench run' }, tsrsDeclared: null })),
+ ).toEqual([]);
+ });
+
+ it('catches a package that runs tsrs without declaring it', () => {
+ const violations = checkTsrs(
+ tsrsMember({ scripts: { 'typecheck:x': 'node_modules/.bin/tsrs -p x' }, tsrsDeclared: null }),
+ );
+ expect(violations).toHaveLength(1);
+ expect(violations[0]).toContain('runs `tsrs` in `typecheck:x` without declaring tsrs');
+ });
+
+ it('rejects a range once, naming the manifest rather than the install', () => {
+ expect(checkTsrs(tsrsMember({ tsrsDeclared: '^0.18.0-ts7.1.0-dev.20260929' }))).toEqual([
+ expect.stringContaining('not an exact version'),
+ ]);
+ });
+
+ it('catches a stale install that resolves another tsrs build than the pin', () => {
+ expect(checkTsrs(tsrsMember({ tsrsResolved: '0.17.0-ts7.1.0-dev.20260901' }))).toEqual([
+ expect.stringContaining('but resolves 0.17.0-ts7.1.0-dev.20260901'),
+ ]);
+ });
+
+ it('catches a pin that resolved to nothing at all', () => {
+ expect(checkTsrs(tsrsMember({ tsrsResolved: null }))[0]).toContain('resolves nothing');
+ });
+
+ it('leaves the binary line unchecked on a platform tsrs ships no binary for', () => {
+ expect(
+ checkTsrs(tsrsMember({ tsrsPlatformSupported: false, tsrsBinVersion: null })),
+ ).toEqual([]);
+ });
+
+ it('still checks the pin on a platform tsrs ships no binary for', () => {
+ expect(
+ checkTsrs(
+ tsrsMember({ tsrsPlatformSupported: false, tsrsDeclared: '^0.18.0-ts7.1.0-dev.20260929' }),
+ ),
+ ).toEqual([expect.stringContaining('not an exact version')]);
+ });
+
+ it('catches a bin on another TypeScript line, or one that cannot run here', () => {
+ expect(checkTsrs(tsrsMember({ tsrsBinVersion: '7.2.0-dev.1' }))[0]).toContain(
+ `not ${TSRS_LINE}.x`,
+ );
+ expect(checkTsrs(tsrsMember({ tsrsBinVersion: null }))[0]).toContain('reporting TypeScript nothing');
+ });
+});
+
+describe('checkTsrsPinsAgree', () => {
+ it('accepts packages that all pin the same exact build', () => {
+ expect(
+ checkTsrsPinsAgree([tsrsMember(), tsrsMember({ name: '@inkeep/open-knowledge-server' })]),
+ ).toEqual([]);
+ });
+
+ it('rejects packages that pin different exact builds, naming each', () => {
+ const [violation, ...rest] = checkTsrsPinsAgree([
+ tsrsMember(),
+ tsrsMember({ name: '@inkeep/open-knowledge-server', tsrsDeclared: '0.19.0-ts7.1.0-dev.20261020' }),
+ ]);
+ expect(rest).toEqual([]);
+ expect(violation).toContain('2 different exact versions');
+ expect(violation).toContain('@inkeep/[email protected]');
+ expect(violation).toContain('@inkeep/[email protected]');
+ });
+
+ it('leaves a range pin to checkTsrs, and ignores a package that does not run tsrs', () => {
+ expect(
+ checkTsrsPinsAgree([
+ tsrsMember(),
+ tsrsMember({ name: 'a', tsrsDeclared: '^0.19.0-ts7.1.0-dev.20261020' }),
+ tsrsMember({ name: 'b', tsrsDeclared: '0.19.0', scripts: { typecheck: 'tsc --noEmit' } }),
+ ]),
+ ).toEqual([]);
+ });
+});
+
+describe('tsrsSupportsPlatform', () => {
+ const published = {
+ '@tsrs/darwin-arm64': '0.18.0',
+ '@tsrs/linux-x64-gnu': '0.18.0',
+ '@tsrs/linux-x64-musl': '0.18.0',
+ '@tsrs/linux-arm64-gnu': '0.18.0',
+ };
+
+ it('finds the binary for an exact or libc-suffixed platform name', () => {
+ expect(tsrsSupportsPlatform(published, 'darwin', 'arm64')).toBe(true);
+ expect(tsrsSupportsPlatform(published, 'linux', 'x64')).toBe(true);
+ });
+
+ it('reports no binary for Windows or an Intel Mac', () => {
+ expect(tsrsSupportsPlatform(published, 'win32', 'x64')).toBe(false);
+ expect(tsrsSupportsPlatform(published, 'darwin', 'x64')).toBe(false);
+ });
+
+ it('does not match a platform that only shares a prefix', () => {
+ expect(tsrsSupportsPlatform({ '@tsrs/linux-x64gnu': '0.18.0' }, 'linux', 'x64')).toBe(false);
+ });
+
+ it('cannot say when the package lists no tsrs binaries', () => {
+ expect(tsrsSupportsPlatform({}, 'linux', 'x64')).toBeNull();
+ expect(tsrsSupportsPlatform(undefined, 'linux', 'x64')).toBeNull();
+ });
+});
+
describe('checkMember', () => {
it('accepts a package that declares and resolves the gate compiler', () => {
expect(checkMember(gatedMember())).toEqual([]);
@@ -624,6 +758,47 @@ describe('evaluate wires every probe into the verdict', () => {
expect(evaluate(healthy).out.join(' ')).toContain('of the 3 tsconfig files under the root');
});
+ const rangePinned = {
+ name: 'open-knowledge',
+ dir: '/ok',
+ scripts: { 'typecheck:lint-plugins': 'tsrs --noEmit -p lint-plugins/ok-rules/tsconfig.json' },
+ tsrsDeclared: '^0.18.0-ts7.1.0-dev.20260929',
+ tsrsResolved: '0.18.0-ts7.1.0-dev.20260929',
+ tsrsBinVersion: '7.1.0-dev.20260930.4',
+ };
+
+ it('fails a range-pinned tsrs on the root package', () => {
+ const result = evaluate({ ...healthy, rootMember: rangePinned });
+
+ expect(result.code).toBe(1);
+ expect(result.violations).toEqual([expect.stringContaining('open-knowledge (/ok) declares tsrs')]);
+ });
+
+ it('fails a root and a workspace package that pin different tsrs builds', () => {
+ const member = {
+ ...healthy.members[0],
+ ...rangePinned,
+ name: '@inkeep/open-knowledge-core',
+ tsrsDeclared: '0.19.0-ts7.1.0-dev.20261020',
+ tsrsResolved: '0.19.0-ts7.1.0-dev.20261020',
+ };
+ const root = { ...rangePinned, tsrsDeclared: '0.18.0-ts7.1.0-dev.20260929' };
+ const result = evaluate({ ...healthy, members: [member], rootMember: root });
+
+ expect(result.code).toBe(1);
+ expect(result.violations).toEqual([expect.stringContaining('2 different exact versions')]);
+ });
+
+ it('fails a range-pinned tsrs on a workspace package', () => {
+ const member = { ...healthy.members[0], ...rangePinned, name: '@inkeep/open-knowledge-core' };
+ const result = evaluate({ ...healthy, members: [member] });
+
+ expect(result.code).toBe(1);
+ expect(result.violations).toEqual([
+ expect.stringContaining('@inkeep/open-knowledge-core (/ok) declares tsrs'),
+ ]);
+ });
+
it('fails when a leaf tsconfig declares customConditions of its own', () => {
const result = evaluate({
...healthy,
diff --git a/test-support/turbo-typecheck-attachment.test.ts b/test-support/turbo-typecheck-attachment.test.ts
index f94ed3ac0..515ec89cd 100644
--- a/test-support/turbo-typecheck-attachment.test.ts
+++ b/test-support/turbo-typecheck-attachment.test.ts
@@ -32,8 +32,9 @@ function programFiles(): string[] {
if (run.error) throw run.error;
if (run.status !== 0) {
throw new Error(
- `${TSC} exited ${run.status} on ${TSCONFIG}; its diagnostics (stdout) follow, and the ` +
- `typecheck cell reports the same program:\n${run.stdout}${run.stderr}`,
+ `${TSC} exited ${run.status} on ${TSCONFIG}; its diagnostics (stdout) follow. The typecheck ` +
+ `cell runs tsrs, and this test lists the program with tsc because both resolve the same ` +
+ `first-party files:\n${run.stdout}${run.stderr}`,
);
}
return run.stdout
diff --git a/turbo.json b/turbo.json
index ce04113ad..c105c6189 100644
--- a/turbo.json
+++ b/turbo.json
@@ -71,9 +71,11 @@
"dependsOn": ["^types", "build"]
},
"typecheck": {
+ "env": ["TSRS_BINARY"],
"dependsOn": ["^types", "//#typecheck:no-net-connect", "//#typecheck:lint-plugins"]
},
"//#typecheck:lint-plugins": {
+ "env": ["TSRS_BINARY"],
"inputs": [
"lint-plugins/ok-rules/**/*.ts",
"lint-plugins/ok-rules/tsconfig.json",
@@ -82,6 +84,7 @@
]
},
"//#typecheck:no-net-connect": {
+ "env": ["TSRS_BINARY"],
"inputs": [
"test-support/*.ts",
"test-support/*.mts",
@@ -104,6 +107,7 @@
]
},
"@inkeep/open-knowledge-core#check:dts": {
+ "env": ["TSRS_BINARY"],
"dependsOn": ["build"],
"inputs": ["tsconfig.json", "tsconfig.check.json", "tests/contract/subpath-types/consumer.ts"]
},