next.js
6fa344b8 - turbopack-ecmascript-runtime: type-check every runtime file (#99670)

Commit
2 days ago
turbopack-ecmascript-runtime: type-check every runtime file (#99670) ## Summary Most of the Turbopack runtime in `turbopack-ecmascript-runtime/js/src` was never type-checked, and editors showed hundreds of bogus "Cannot find name" errors in it. - `src/nodejs/tsconfig.json` had `"include": ["*.ts"]`, which only matched `nodejs/hmr-types.d.ts`. So `nodejs/runtime/*` and `nodejs/dev/*` were in no project, and `pnpm check` never covered them. - `browser/runtime/base/tsconfig.json` included only `runtime-base.ts` and `dummy.ts`. `build-base.ts`, `dev-base.ts` and `dev-dummy.ts` were left out. `dev-base.ts` was checked indirectly through the `dom` project. - tsserver then fell back to `turbopack/tsconfig.json`, which uses `"module": "NodeNext"`. That implies `moduleDetection: force`, so these global-script files were treated as modules and their shared `/// <reference>` declarations disappeared. `build-base.ts` and `dev-base.ts` are alternative entry points that both define `instantiateModule`, so they can't share a project. In both `nodejs/` and `browser/runtime/base/`, `tsconfig.json` is now a solution-style config that references a `tsconfig.build.json` and a `tsconfig.dev.json`. tsserver follows these references, so every file opens in the right project. Files that are only pulled in through `/// <reference>` are listed in `include` explicitly, because tsserver doesn't otherwise count them as part of a project. The `check:` scripts are split the same way. `tsconfig.base.json` now sets `moduleDetection: "auto"` explicitly. That's already the default for `module: CommonJS`, but it documents that these files have to stay scripts. This also fixes the errors in files that were never checked before: - `nodejs-globals.d.ts` referenced `shared/runtime-types.d.ts`, which doesn't exist. The file is `shared/runtime/runtime-types.d.ts`. - In `nodejs/runtime/build-base.ts`, `moduleCache.get(...)` returned `Module` where `ModuleWithDirection` was expected. This matches the existing cast on `nodeContextPrototype.c`. - `nodejs/dev/dev-nodejs.ts` read `.merged` on an instruction union where only `ChunkListUpdate` has that field. - `nodejs/runtime/dev-base.ts` had an unused parameter. ## Verification - `pnpm check` in `turbopack/crates/turbopack-ecmascript-runtime/js` passes. - Opened all 31 `.ts` files in a real tsserver. Each resolves to one of this package's tsconfigs, with 0 errors. - Not run: Turbopack snapshot tests. The `dev-nodejs.ts` change affects emitted runtime code, so snapshots may need regenerating. <!-- NEXT_JS_LLM -->
Author
Parents
Loading