flightPackage
uses tcmts.loader.packages.ensureExternals, which uses node:fs
The Flight package for code written against React jsx (npm:react@19), installed beside it: at the very version
of that React, as Flight's halves are built for one React (each planApp keeps them together, through
tcm upgrade react too). Writes the module the server renders with (flightServerFile). Its alias.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { FLIGHT_PACKAGE, flightAlias, flightServerFile } from "#codebase/tcmts/cli/flight"; import type { ExtRef } from "#codebase/tcmts/core/types"; import { ensureExternals, lockOf, npmAlias, writeIfChanged } from "#codebase/tcmts/loader/packages"; export function flightPackage(cb: Codebase, jsx: string, also: ExtRef[] = []): string { const range = jsx.slice(jsx.lastIndexOf("@") + 1); const version = cb.store.lockedVersion("react", range); if (!version) throw new Error(`React ${range} isn't installed`); const lock = lockOf(cb.lay); if (lock.get(FLIGHT_PACKAGE, range) !== version) lock.set(FLIGHT_PACKAGE, range, version); // (with what the caller installs beside it, React DOM say: one install) ensureExternals(cb.lay, [ { module: `npm:${FLIGHT_PACKAGE}@${range}`, subpath: "client", export: "createFromReadableStream", }, ...also, ]); const flight = flightAlias(jsx); writeIfChanged( flightServerFile(cb), [ `// generated by tcm — do not edit. React's Flight server, and the React it renders with: in the cache, so they`, `// load with the react-server condition (\`useFlight\`), as all server code does`, `export { createClientReference, decodeReply, registerServerReference, renderToPipeableStream } from ${JSON.stringify(`${flight}/server`)};`, `export { createElement } from ${JSON.stringify(npmAlias(jsx))};`, "", ].join("\n"), ); return flight; }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.flight.FLIGHT_PACKAGE
- tcmts.cli.flight.flightAlias
- tcmts.cli.flight.flightServerFile
- tcmts.core.types.ExtRef
- tcmts.loader.packages.ensureExternals
- tcmts.loader.packages.lockOf
- tcmts.loader.packages.npmAlias
- tcmts.loader.packages.writeIfChanged