Unverified Commit 6caa7860 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Typecheck the Turbopack ECMAScript runtime in CI (#98422)

### What?

Integrate the Turbopack ECMAScript runtime package checks into the
repository TypeScript task graph and resolve the latent type errors
those checks expose.

### Why?

The runtime package already had checks for its environment-specific
TypeScript projects, but CI never executed them. This allowed its public
runtime context types to diverge from their implementations, including
the `EsmExport` binding representation.

### How?

The package now participates in the existing Turbo `typescript` task
used by CI. Its package-local Turbo configuration builds workspace
dependencies first, ensuring the React Refresh type output is available
on clean checkouts without adding build dependencies to every repository
typecheck.

The runtime declarations now reflect the actual flat ESM binding format
and HMR behavior. Browser development references and return types also
mirror the runtime files and concatenation order used by the Rust
runtime builder. Turbopack snapshots that embed these runtime sources
and source maps are regenerated to match.

### Verification

- `cargo nextest run -p turbopack-tests -E 'test(snapshot)'` (125
passed)
- `pnpm --dir turbopack/crates/turbopack-ecmascript-runtime/js check`
- `pnpm lint-typescript --filter=@vercel/turbopack-ecmascript-runtime
--log-order=stream --force` after removing
`packages/react-refresh-utils/dist`
- Focused Prettier and ESLint checks
- `git diff --check`

<!-- NEXT_JS_LLM -->

<!-- fleet 56074f5a-b0e2-4b27-ac56-a2b6cebe3c8e -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent b145ad6f
......@@ -5,6 +5,7 @@
"license": "UNLICENSED",
"private": true,
"scripts": {
"typescript": "pnpm check",
"check": "run-p check:*",
"check:nodejs": "tsc -p src/nodejs",
"check:browser-dev-client": "tsc -p src/browser/dev/hmr-client",
......
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
interface TurbopackDevContext extends TurbopackBrowserBaseContext<HotModule> {
k: RefreshContext
......@@ -88,7 +89,7 @@ const chunkChunkListsMap: Map<ChunkPath, Set<ChunkListPath>> = new Map()
function getOrInstantiateRuntimeModule(
chunkPath: ChunkPath | undefined,
moduleId: ModuleId
): Module {
): HotModule {
const module = devModuleCache[moduleId]
if (module) {
if (module.error) {
......@@ -158,7 +159,7 @@ function instantiateModule(
moduleId: ModuleId,
sourceType: SourceType,
sourceData: SourceData
): Module {
): HotModule {
// Browser: creates base HotModule object (hot API added by shared code)
const createModuleObjectFn = (id: ModuleId) => {
return createModuleObject(id) as HotModule
......
......@@ -74,7 +74,7 @@ type ModuleEffect =
}
| {
type: 'accepted'
moduleId: ModuleId
moduleId: ModuleId | undefined
outdatedModules: Set<ModuleId>
outdatedDependencies: Map<ModuleId, Set<ModuleId>>
}
......
......@@ -62,9 +62,16 @@ type EsmImport = (
allowExportDefault: boolean
) => EsmNamespaceObject | Promise<EsmNamespaceObject>
type InvokeAsyncLoader = (moduleId: ModuleId) => Promise<Exports>
type ModuleFactoryFunction<
M extends Module,
C extends TurbopackBaseContext<M>,
> = {
bivarianceHack(this: M['exports'], context: C): unknown
}['bivarianceHack']
type EsmExport = (
exportGetters: Record<string, () => any>,
id: ModuleId | undefined
bindings: EsmBindings,
id: ModuleId | undefined,
dynamic?: boolean
) => void
type ExportValue = (value: any, id: ModuleId | undefined) => void
type ExportUrl = (url: string, id: ModuleId | undefined) => void
......
......@@ -44,9 +44,6 @@ declare function getOrInstantiateModuleFromParent<M>(
sourceModule: M
): M
// @ts-ignore Defined in `hmr-runtime.ts` (dev mode only)
declare let devModuleCache: Record<ModuleId, any> | undefined
/**
* Flag indicating which module object type to create when a module is merged. Set to `true`
* by each runtime that uses ModuleWithDirection (browser dev-base.ts, nodejs dev-base.ts,
......
{
"$schema": "https://turborepo.org/schema.json",
"extends": ["//"],
"tasks": {
"typescript": {
"dependsOn": ["^build"]
}
}
}
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="f71e4bf6-0f5b-0cff-0120-ee23e8ff7775")}catch(e){}}();
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="37ea5bcf-f259-1cd1-a144-361dcb52f06f")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/0rv8_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js",
{"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvsq4xsbk.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
......@@ -1733,6 +1733,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......@@ -2494,5 +2495,5 @@ chunkListsToRegister.forEach(registerChunkList);
})();
//# debugId=f71e4bf6-0f5b-0cff-0120-ee23e8ff7775
//# debugId=37ea5bcf-f259-1cd1-a144-361dcb52f06f
//# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js.map
\ No newline at end of file
......@@ -1732,6 +1732,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......
......@@ -1732,6 +1732,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......
......@@ -1732,6 +1732,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......
......@@ -1732,6 +1732,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......
......@@ -1732,6 +1732,7 @@ function formatDependencyChain(dependencyChain) {
}
/// <reference path="../../../shared/runtime/dev-globals.d.ts" />
/// <reference path="../../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../../shared/runtime/hmr-runtime.ts" />
const devContextPrototype = Context.prototype;
/**
* This file contains runtime types and functions that are shared between all
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment