perf(deps-dev): use native TypeScript for Vitest checks

Merged
GL
14d ago
+244-4

Change

Run the existing Vitest type checks with stable native TypeScript 7.0.2 through an explicit executable path. Pin the already-locked TypeScript 5.9.3 as a direct dev dependency for compiler API consumers and the published-package Node16 consumer test. This prevents either check from accidentally selecting a host-global or ambiguous tsc binary.

The existing tsdown/native-preview declaration build, runtime code, compiler strictness, Nix tools and CI workflows remain unchanged. Knip is told about the executable dependency it cannot discover from a file-path string. All 429 existing package records and 429 snapshots, including runtime/security policies, are unchanged; only 21 official stable compiler/platform records are added.

Local benchmark

Measured Vitest's root typechecking job only, including Vitest startup and result parsing. This excludes runtime tests, dependency installation, declaration builds and hosted CI overhead; it is not an application-runtime or end-to-end CI speed claim.

Existing typechecking jobTS 5.9.3 medianNative 7.0.2 medianTime savedReduction
Cold compiler cache1.600275 s0.607774 s0.992501 s62.02%
Immediate cached repeat0.945777 s0.514120 s0.431657 s45.64%

Same final source/dependency graph and Node v24.21.0, macOS arm64. Two warmup rounds followed by seven measured pairs; alternate compiler order. Each cold run removes Vitest's tsconfig.tmp.tsbuildinfo, then its warm run reuses that compiler's cache. All 36 invocations pass with 20 typechecked test files, 413 passed (417) and no type errors. The actual compiler version is verified from build-info after every invocation. Both compilers cover the same 59 project files and 1,146 dependency module-files, matched by package name/version, relative path and SHA-256. TS 5.9 additionally reports three identical Undici aliases, including an ancestor copy of exactly the same undici-types@6.21.0 entry point; there is no missing declaration coverage.

Audit workers were paused during timing. Host 1-minute load changed from 3.25 to 4.90; unrelated host work was not controlled. Cold ranges: legacy 1.548681–1.687273s, native 0.580724–0.641551s. Cached ranges: legacy 0.933433–1.008242s, native 0.473459–0.525081s.

Raw measured wall-clock seconds and reproduction
{
  "cold": {
    "legacy": [
      1.647859,
      1.600274917,
      1.605859209,
      1.687272625,
      1.548681333,
      1.582628083,
      1.565835375
    ],
    "native": [
      0.580724083,
      0.641550834,
      0.633643541,
      0.59531525,
      0.6077735,
      0.623569625,
      0.602699834
    ]
  },
  "warm": {
    "legacy": [
      0.945776709,
      0.93343275,
      1.008241916,
      0.94799475,
      0.94301525,
      0.953216542,
      0.942659542
    ],
    "native": [
      0.525080916,
      0.518334542,
      0.473459333,
      0.525013834,
      0.514120167,
      0.501108833,
      0.506509125
    ]
  }
}

Create two temporary root configs that import the final vitest.config.ts, clone its config, and select only the existing root project's typechecking stage. Set the checker to ./node_modules/typescript/bin/tsc for legacy or ./node_modules/@typescript/native/bin/tsc for native:

import base from './vitest.config';
const config = structuredClone(base);
config.test!.projects![0].test!.typecheck!.checker = './node_modules/typescript/bin/tsc';
config.test!.projects![0].test!.typecheck!.only = true;
export default config;

Run each using the repository-managed Node binary, for example:

./node_modules/node/bin/node ./node_modules/vitest/vitest.mjs run --config .audit-vitest-legacy.config.ts --project root

Vitest itself passes its existing --noEmit --pretty false --incremental --tsBuildInfoFile <vitest>/dist/tsconfig.tmp.tsbuildinfo arguments. Remove that build-info before cold checks; run the identical command immediately afterward for the cached check. Temporary configs are removed after measurement. Workspace project configuration overrides the similarly named global CLI flags, so the benchmark uses actual per-project checker settings rather than those ignored CLI overrides.

Validation and limits

  • Full baseline and candidate pnpm test: 45 files passed, 1288 passed (1292), no type errors. This includes existing runtime/mocked HTTP tests, examples and CJS/ESM/Node16 package-consumer checks. The initial local baseline found a host-global TypeScript 5.1.6; the accepted baseline explicitly selected the lockfile's 5.9.3 in an untracked local binary link. No tests were removed or weakened.
  • Baseline and candidate pnpm build and package validation pass. 154/156 outputs are byte-identical. The only differences are package.cjs.map and package.mjs.map: the exact changed package manifest in sourcesContent and its corresponding mappings. All runtime JS and declarations are identical.
  • Both compiler paths complete Vitest watch startup with all 20 typechecked files and no errors; bounded probes then exit on intentional SIGINT. The default remains watch: false; ongoing edit/rebuild behaviour was not benchmarked.
  • pnpm lint:knip passes with the same two pre-existing configuration hints. Full local pnpm lint is not passed: this host lacks Nix's pinned Oxfmt/Oxlint executables (exit 127). An exact-version recovery was attempted, but the old platform metadata was unavailable; the unchanged hosted Nix lint job has now passed: Oxfmt checked 96 files, type-aware/type-checking Oxlint checked 66 files with 104 rules and no warnings/errors, and Knip passed with the same two hints. Hosted build/test also passed with the same 45 files and 1288 passed (1292); all three AI peer-range jobs (5.0.108, 6.0.7, 7.0.0), pinned Python/Node conformance and ci-ok passed.
  • Full normal pnpm install --frozen-lockfile succeeds under pinned pnpm10.26.0, preserving the existing Node runtime and lifecycle/security policies. The lockfile's 21 new records were generated normally in a minimal compiler-only fixture using official cached registry metadata, then added to the unchanged existing graph. Full root nonfrozen generation could not start through the available network transport; this is not claimed as a full root resolver run. No peer snapshots were guessed or rewritten.
  • Independent security review verified all new official package integrities, platforms, engine requirements and lack of lifecycle scripts; existing dependencies and security settings are unchanged. Independent whole-diff Forge review found no actionable issue. Post-review whole-diff Forge also found no actionable issue; its meter is unchanged (2 added comment lines, longest block 1, zero type escapes/copies).

The existing declaration native-preview upgrade is deferred: the wrapper interface looked compatible, but normal peer-graph re-resolution could not be proven with the available metadata. This PR claims the measured Vitest improvement only.

Hosted review and security

At head 2c2643eb8a0f2c6d223d1bc34e1c26a3df664fd5, Cubic approved all seven files without findings; there are no inline review threads or unanswered findings. Copilot did not review because its quota was exhausted, so its failed check is not a code failure or a clean review. It was not retriggered.

Hosted CI, Gitleaks (no leaks found), Aikido, dry-publish and the repository's existing automatic release-artifact checks passed. Coverage/deploy-coverage jobs were skipped by their existing branch conditions. GitHub security overview shows Dependabot enabled, code scanning needing setup, and secret scanning/code quality disabled; no alert count was shown. These unavailable scanners are not claimed as passed. No security settings were changed and no manual deployment or merge was performed.


Summary by cubic

Switches Vitest type checks to run with native TypeScript 7.0.2 via an explicit checker path, and pins TypeScript 5.9.3 as a direct dev dependency so compiler API consumers and the published-package consumer test keep using the JS compiler. Both compilers are now invoked through explicit binaries, so checks no longer risk selecting a host-global or ambiguous tsc.

Runtime code, declaration builds, compiler strictness, Nix tooling, CI workflows, and all test/security records are unchanged; only 21 official TypeScript compiler platform records are added to the lockfile. Build output is byte-identical except for the two source maps that embed the changed package manifest. Knip is configured to allow the native checker dependency, which it cannot discover from a file-path string.

Performance

  • Vitest typechecking is about 62% faster on a cold compiler cache and 46% faster on a cached repeat (medians 1.60→0.61s and 0.95→0.51s).
  • Both compilers cover the same 59 project files and 1,146 dependency modules; all 36 measured runs passed with 20 typechecked files and no type errors.