Unverified Commit 4e4cfaff authored by vercel-fleet[bot]'s avatar vercel-fleet[bot] Committed by GitHub

Keep runtime HMR type copies, point them at the generated source of truth

Follow-up to the ts-rs HMR codegen: rather than restructure the browser runtime
(which models these wire types as self-tagged with branded keys and has ~250
lines of merge logic depending on that shape), keep the turbopack runtime's
ambient copies and document them as mirrors of the Rust source of truth.

- Restore `nodejs/hmr-types.d.ts` and `nodejs/dev/hmr-client.ts` to their
  original state (an earlier edit had deleted the ambient file, which is the sole
  input of `check:nodejs`).
- Replace the stale "duplicate of types.ts / keep in sync" comment on
  `hmr-types.d.ts` and add a "source of truth" comment to `dev-protocol.d.ts`,
  both pointing at `turbopack-ecmascript`'s `chunk_list` structs and the generated
  `packages/next/src/build/swc/generated-hmr-types.ts`.

<!-- NEXT_JS_LLM -->
Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 8e02bdd1
......@@ -10,10 +10,7 @@ type NodeJsHmrPayload = {
}
issues: Issue[]
type: 'partial'
// These are the shared, ambient HMR wire-protocol types from
// `dev-protocol.d.ts` (generated on the Rust side from
// `turbopack-ecmascript`'s `chunk_list` instruction structs).
instruction: ChunkListUpdate | EcmascriptMergedUpdate
instruction: NodeJsEcmascriptMergedUpdate | NodeJsChunkListUpdate
}
/**
......@@ -117,7 +114,7 @@ function handleNodejsUpdate(
}
function applyEcmascriptMergedUpdate(
instruction: EcmascriptMergedUpdate,
instruction: NodeJsEcmascriptMergedUpdate,
moduleFactories: ModuleFactories,
devModuleCache: ModuleCache<HotModule>
): void {
......
/**
* Type definitions for Node.js HMR updates.
*
* SOURCE OF TRUTH: the HMR update-instruction wire format is defined in Rust in
* `turbopack/crates/turbopack-ecmascript/src/chunk_list` and generated to
* TypeScript at `packages/next/src/build/swc/generated-hmr-types.ts` (via
* `pnpm swc-generate-hmr-types`). These ambient declarations are an isolated,
* self-contained mirror of that shape: this file must type-check on its own (it
* is what `check:nodejs` validates) and cannot import from an ES module without
* becoming a module itself, so it can't reference the generated file directly.
* Keep it consistent with the generated types (and the shared runtime copy in
* `../shared/runtime/dev-protocol.d.ts`).
*/
interface NodeJsEcmascriptMergedUpdate {
type: 'EcmascriptMergedUpdate'
entries?: Record<
string,
{ code: string; url: string; map?: string | undefined }
>
chunks?: Record<
string,
| { type: 'added' | 'deleted'; modules?: string[] }
| { type: 'partial'; added?: string[]; deleted?: string[] }
>
}
interface NodeJsChunkListUpdate {
type: 'ChunkListUpdate'
merged?: NodeJsEcmascriptMergedUpdate[]
chunks?: Record<string, { type: 'added' | 'deleted' | 'total' | 'partial' }>
}
interface NodeJsPartialHmrUpdate {
type: 'partial'
instruction: NodeJsEcmascriptMergedUpdate | NodeJsChunkListUpdate
}
interface NodeJsRestartHmrUpdate {
type: 'restart'
}
/**
* Definitions for the protocol that is used to communicate between the
* Turbopack runtime and the Turbopack server for issue reporting and HMR.
*
* SOURCE OF TRUTH for the HMR update-instruction types below (`PartialUpdate`,
* `ChunkListUpdate`, `ChunkUpdate`, `MergedChunkUpdate`, `EcmascriptMergedUpdate`,
* `EcmascriptMergedChunkUpdate`, `EcmascriptModuleEntry`): the Rust structs in
* `turbopack/crates/turbopack-ecmascript/src/chunk_list`, generated to TypeScript
* at `packages/next/src/build/swc/generated-hmr-types.ts` (via
* `pnpm swc-generate-hmr-types`). These ambient runtime declarations use
* branded key types (`ChunkPath` / `ModuleId`) and a couple of runtime-only
* refinements, so they are kept as a hand-written mirror rather than replaced by
* the generated module; keep them consistent with the generated types when the
* wire format changes.
*/
type PartialServerMessage = {
resource: ResourceIdentifier
......
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