LibreChat/scripts/typecheck.mts
Marco Beretta e1b4e09d7c
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Main Promotion Policy Tests / Main promotion denial and fast-forward tests (push) Has been cancelled
🥟 ci: Type-Check Workspaces with bun check (#17009)
* ci: Type-Check Workspaces with bun check

Make every workspace tsconfig valid under TypeScript 7 semantics while
staying clean on the installed tsc 5.9: explicit types arrays (TS 7 no
longer auto-includes node_modules/@types), es2017 target for
data-provider, rootDir for api specs that import client contracts, and
noUncheckedSideEffectImports off for the CSS and matchMedia mock imports.

Fix the four client type errors newer DOM and Intl libs expose, and drop
the fetch.preconnect copy in useRum that only existed to satisfy the
leaked @types/bun globals.

Switch the client typecheck script and the CI type-check steps to
bun check (Bun 1.4.3); tsc --noEmit stays available as typecheck:tsc.

* chore: Fall Back to tsc When bun check Is Unavailable

Add scripts/typecheck.mts, which runs bun check when the installed Bun
provides it and the repository's tsc otherwise, so contributors without
Bun can still type-check. The client typecheck script and the
static-checks TypeScript gate both resolve their checker through it,
keeping local runs on the same checker CI uses whenever Bun is present.

* ci: Type-Check the Chat Package Through the Shared Checker

* ci: Run the Type Check When Only the Shared Checker Changes

A change to scripts/typecheck.mts alone started neither frontend review
nor the static-checks TypeScript gate, so a broken resolver could merge
unexercised. Add it to the frontend-review triggers and to every
typecheck project's paths.

The suppression-baseline scenarios copy static-checks.mts into synthetic
roots; copy its new typecheck.mts import alongside i18n.mts so the runner
loads there. Add scenarios for the checker choice and its fallback.
2026-10-12 06:40:07 -04:00

53 lines
1.9 KiB
TypeScript

/**
* Type-checks a TypeScript project with `bun check` when the installed Bun provides it, and
* with the repository's `tsc` otherwise, so Bun stays optional locally while CI runs the same
* checker. Both pass on every workspace config; `bun check` applies TypeScript 7 semantics.
*
* Usage: node scripts/typecheck.mts [-p <tsconfig>]
*/
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import { spawnSync } from 'node:child_process';
export interface TypecheckCommand {
checker: 'bun' | 'tsc';
command: string;
/** Arguments before `-p <project>`. */
args: string[];
}
let bunCheck: boolean | undefined;
/** Probes the subcommand rather than the binary: older Bun releases have no `check`. */
function hasBunCheck(): boolean {
bunCheck ??= spawnSync('bun', ['check', '--help'], { stdio: 'ignore' }).status === 0;
return bunCheck;
}
/** Resolves the checker to run, or null when neither Bun nor `typescript` is available. */
export function resolveTypecheck(root: string): TypecheckCommand | null {
if (hasBunCheck()) {
return { checker: 'bun', command: 'bun', args: ['check'] };
}
try {
const tsc = createRequire(import.meta.url).resolve('typescript/bin/tsc', { paths: [root] });
return { checker: 'tsc', command: process.execPath, args: [tsc, '--noEmit'] };
} catch {
return null;
}
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const typecheck = resolveTypecheck(process.cwd());
if (!typecheck) {
console.error('typecheck: neither `bun check` nor typescript is available; run npm ci');
process.exit(1);
}
if (typecheck.checker === 'tsc') {
console.error('typecheck: `bun check` is unavailable, falling back to tsc');
}
const result = spawnSync(typecheck.command, [...typecheck.args, ...process.argv.slice(2)], {
stdio: 'inherit',
});
process.exit(result.status ?? 1);
}