experimental-runtime.d.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * Compiler-emitted module-graph delta — topology (static + dynamic edges).
  3. * `ids[0, localCount)` are the modules this payload carries; `ids[localCount, …)` are foreign edge targets.
  4. * `edges[i]` / `dynamicEdges[i]` are the static / dynamic-`import()` out-edges of `ids[i]`.
  5. * `bindings[i][j]` are the export names `ids[i]` imports through `edges[i][j]`. `bindings` holds
  6. * only some rows; a missing row, or a missing or `null` entry, means the whole namespace.
  7. * `dynamicEdges` also holds only some rows; a missing row means no dynamic edges.
  8. * @typedef {{ ids: string[], localCount: number, edges: number[][], bindings?: Record<number, (string[] | null)[]>, dynamicEdges?: Record<number, number[]> }} ModuleGraphDelta
  9. * @typedef {{ createModuleHotContext(moduleId: string): any, onModuleCacheRemoval(moduleId: string): void }} DevRuntimeHooks
  10. */
  11. export class MissingFactoryError {
  12. /**
  13. * @param {string} id
  14. */
  15. constructor(id: string);
  16. id: string;
  17. }
  18. export class DevRuntime {
  19. /**
  20. * @param {string} clientId
  21. */
  22. constructor(clientId: string);
  23. /**
  24. * Client ID generated at runtime initialization, used for lazy compilation requests.
  25. * @type {string}
  26. */
  27. clientId: string;
  28. /**
  29. * Static import edges from `registerGraph` — entries persist across `removeModuleCache`
  30. * and change only by replacement from a newer payload (last write wins).
  31. * `bindings` is the payload row as sent; `getImportedBindings` resolves a missing entry.
  32. * @type {Map<string, { edges: string[], bindings: (string[] | null)[] | undefined }>}
  33. */
  34. staticImports: Map<string, {
  35. edges: string[];
  36. bindings: (string[] | null)[] | undefined;
  37. }>;
  38. /**
  39. * Reverse index over the static imports.
  40. * @type {Map<string, Set<string>>}
  41. */
  42. importers: Map<string, Set<string>>;
  43. /**
  44. * Dynamic `import()` edges from `registerGraph`, keyed by importer — mirror of
  45. * `staticImports` for the dynamic reverse index.
  46. * @type {Map<string, { edges: string[] }>}
  47. */
  48. dynamicImports: Map<string, {
  49. edges: string[];
  50. }>;
  51. /**
  52. * Reverse index over the dynamic imports.
  53. * @type {Map<string, Set<string>>}
  54. */
  55. dynamicImporters: Map<string, Set<string>>;
  56. /**
  57. * The module cache. Membership means "this module's side effects ran in this tab" —
  58. * registration is emitted ahead of every module body, and nothing un-registers on
  59. * unwind, so a factory that throws mid-body stays registered. A `Map` rather than a
  60. * plain object: HMR eviction deletes entries, and a `delete` on an object drops V8
  61. * into dictionary mode, taxing every later lookup on the hottest read path.
  62. * @type {Map<string, Module>}
  63. */
  64. moduleCache: Map<string, Module>;
  65. /**
  66. * Re-runnable factories from HMR patches and lazy chunks. The initial bundle stays
  67. * scope-hoisted and contributes none.
  68. * @type {Map<string, (id: string) => void>}
  69. */
  70. factories: Map<string, (id: string) => void>;
  71. /**
  72. * Installed by the dev client at boot. The runtime is a store + executor and makes
  73. * no HMR decisions; accepting, disposing, and reloading live behind these hooks.
  74. * @type {DevRuntimeHooks | null}
  75. */
  76. hooks: DevRuntimeHooks | null;
  77. /**
  78. * @param {ModuleGraphDelta} delta
  79. */
  80. registerGraph(delta: ModuleGraphDelta): void;
  81. /**
  82. * @param {string} id
  83. * @param {(id: string) => void} fn
  84. */
  85. registerFactory(id: string, fn: (id: string) => void): void;
  86. /**
  87. * @param {string} id
  88. * @param {{ exports: any }} [exportsHolder]
  89. */
  90. registerModule(id: string, exportsHolder?: {
  91. exports: any;
  92. }): void;
  93. /**
  94. * @param {string} id
  95. * @returns {string[]}
  96. */
  97. getImporters(id: string): string[];
  98. /**
  99. * `"*"` means the whole namespace, an empty list a side-effect-only import, `undefined` no edge.
  100. * @param {string} importer
  101. * @param {string} id
  102. * @returns {string[] | undefined}
  103. */
  104. getImportedBindings(importer: string, id: string): string[] | undefined;
  105. /**
  106. * @param {string} id
  107. */
  108. isExecuted(id: string): any;
  109. /**
  110. * @param {string} id
  111. */
  112. hasFactory(id: string): any;
  113. /**
  114. * Module-cache delete only — static imports and factories persist. Removal is what
  115. * re-arms a cache-gated factory for `initModule`.
  116. * @param {string} id
  117. */
  118. removeModuleCache(id: string): void;
  119. /**
  120. * The one re-execution gate: registered → return the live exports; otherwise run the
  121. * mapped factory (which registers itself first, then runs the body).
  122. * @param {string} id
  123. */
  124. initModule(id: string): any;
  125. /**
  126. * @param {string} id
  127. */
  128. loadExports(id: string): any;
  129. /**
  130. * @param {string} moduleId
  131. */
  132. createModuleHotContext(moduleId: string): any;
  133. /** @internal */
  134. __toESM: any;
  135. /** @internal */
  136. __toCommonJS: any;
  137. /** @internal */
  138. __exportAll: any;
  139. /**
  140. * @param {boolean} [isNodeMode]
  141. * @returns {(mod: any) => any}
  142. * @internal
  143. */
  144. __toDynamicImportESM: (isNodeMode?: boolean) => (mod: any) => any;
  145. /** @internal */
  146. __reExport: any;
  147. }
  148. /**
  149. * Compiler-emitted module-graph delta — topology (static + dynamic edges).
  150. * `ids[0, localCount)` are the modules this payload carries; `ids[localCount, …)` are foreign edge targets.
  151. * `edges[i]` / `dynamicEdges[i]` are the static / dynamic-`import()` out-edges of `ids[i]`.
  152. * `bindings[i][j]` are the export names `ids[i]` imports through `edges[i][j]`. `bindings` holds
  153. * only some rows; a missing row, or a missing or `null` entry, means the whole namespace.
  154. * `dynamicEdges` also holds only some rows; a missing row means no dynamic edges.
  155. */
  156. export type ModuleGraphDelta = {
  157. ids: string[];
  158. localCount: number;
  159. edges: number[][];
  160. bindings?: Record<number, (string[] | null)[]>;
  161. dynamicEdges?: Record<number, number[]>;
  162. };
  163. /**
  164. * Compiler-emitted module-graph delta — topology (static + dynamic edges).
  165. * `ids[0, localCount)` are the modules this payload carries; `ids[localCount, …)` are foreign edge targets.
  166. * `edges[i]` / `dynamicEdges[i]` are the static / dynamic-`import()` out-edges of `ids[i]`.
  167. * `bindings[i][j]` are the export names `ids[i]` imports through `edges[i][j]`. `bindings` holds
  168. * only some rows; a missing row, or a missing or `null` entry, means the whole namespace.
  169. * `dynamicEdges` also holds only some rows; a missing row means no dynamic edges.
  170. */
  171. export type DevRuntimeHooks = {
  172. createModuleHotContext(moduleId: string): any;
  173. onModuleCacheRemoval(moduleId: string): void;
  174. };
  175. declare class Module {
  176. /**
  177. * @param {string} id
  178. */
  179. constructor(id: string);
  180. /**
  181. * @type {{ exports: any }}
  182. */
  183. exportsHolder: {
  184. exports: any;
  185. };
  186. /**
  187. * @type {string}
  188. */
  189. id: string;
  190. get exports(): any;
  191. }
  192. export {};