@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/esm/cache.js +7 -0
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js +35 -1
  4. package/esm/debug/fileReporter.js.map +1 -1
  5. package/esm/eval/broker.js +230 -89
  6. package/esm/eval/broker.js.map +1 -1
  7. package/esm/eval/protocol.js.map +1 -1
  8. package/esm/eval/runner.js +143 -24
  9. package/esm/eval/runner.js.map +1 -1
  10. package/esm/module.js +70 -43
  11. package/esm/module.js.map +1 -1
  12. package/esm/transform/Entrypoint.types.js.map +1 -1
  13. package/esm/transform/generators/processEntrypoint.js +35 -20
  14. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  15. package/esm/transform/generators/resolveImports.js +48 -2
  16. package/esm/transform/generators/resolveImports.js.map +1 -1
  17. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  18. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  19. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  20. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  21. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  22. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  23. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  24. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  25. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  26. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  27. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  28. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  29. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  30. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  31. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  32. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  33. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  34. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  35. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  36. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  37. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  38. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  39. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  40. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  41. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  42. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  43. package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
  44. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  45. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
  46. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  47. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  48. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  49. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  50. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  51. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  52. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  53. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  54. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  55. package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
  56. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
  57. package/esm/transform/generators/transform.js +57 -45
  58. package/esm/transform/generators/transform.js.map +1 -1
  59. package/esm/transform/helpers/loadWywOptions.js +33 -4
  60. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  61. package/esm/transform.js +3 -1
  62. package/esm/transform.js.map +1 -1
  63. package/esm/utils/EventEmitter.js +42 -9
  64. package/esm/utils/EventEmitter.js.map +1 -1
  65. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  66. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  67. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  68. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  69. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
  70. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  71. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  72. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  73. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  74. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  75. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  76. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  77. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  78. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  79. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  80. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  81. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  82. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  83. package/esm/utils/applyOxcProcessors/types.js +2 -0
  84. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  85. package/esm/utils/applyOxcProcessors.js +1 -1216
  86. package/esm/utils/applyOxcProcessors.js.map +1 -1
  87. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  88. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  89. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  90. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  91. package/esm/utils/collectOxcRuntime/types.js +2 -0
  92. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  93. package/esm/utils/collectOxcRuntime.js +5 -193
  94. package/esm/utils/collectOxcRuntime.js.map +1 -1
  95. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  96. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  97. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  98. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  99. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  100. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  101. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  102. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  103. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  104. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  105. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  106. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  107. package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
  108. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
  109. package/esm/utils/nativeResolver.js +93 -0
  110. package/esm/utils/nativeResolver.js.map +1 -0
  111. package/esm/utils/oxc/ast.js +28 -0
  112. package/esm/utils/oxc/ast.js.map +1 -0
  113. package/esm/utils/oxc/parse.js +3 -0
  114. package/esm/utils/oxc/parse.js.map +1 -0
  115. package/esm/utils/oxc/replacements.js +14 -0
  116. package/esm/utils/oxc/replacements.js.map +1 -0
  117. package/esm/utils/oxc/sourceLocations.js +59 -0
  118. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  119. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  120. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  121. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  122. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  123. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  124. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  125. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  126. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  127. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  128. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  129. package/esm/utils/oxcPreevalStage/types.js +2 -0
  130. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  131. package/esm/utils/oxcPreevalStage.js +17 -73
  132. package/esm/utils/oxcPreevalStage.js.map +1 -1
  133. package/esm/utils/oxcPreevalTransforms.js +12 -1
  134. package/esm/utils/oxcPreevalTransforms.js.map +1 -1
  135. package/esm/utils/processorStaticSemantics.js +157 -0
  136. package/esm/utils/processorStaticSemantics.js.map +1 -0
  137. package/esm/utils/resolveWithConditions.js +3 -3
  138. package/esm/utils/resolveWithConditions.js.map +1 -1
  139. package/package.json +4 -3
  140. package/types/cache.js +8 -0
  141. package/types/debug/fileReporter.js +46 -1
  142. package/types/eval/broker.d.ts +6 -2
  143. package/types/eval/broker.js +244 -95
  144. package/types/eval/protocol.d.ts +15 -1
  145. package/types/module.d.ts +4 -1
  146. package/types/module.js +97 -48
  147. package/types/transform/Entrypoint.types.d.ts +3 -0
  148. package/types/transform/generators/resolveImports.d.ts +3 -1
  149. package/types/transform/generators/resolveImports.js +49 -2
  150. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  151. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  152. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  153. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  154. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  155. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  156. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  157. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  158. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  159. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  160. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  161. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  162. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  163. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  164. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  165. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  166. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  167. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  168. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  169. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  170. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  171. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  172. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  173. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  174. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  175. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  176. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  177. package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
  178. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  179. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
  180. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  181. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  182. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  183. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  184. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  185. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  186. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  187. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  188. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
  189. package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
  190. package/types/transform/generators/transform.js +63 -49
  191. package/types/transform/helpers/loadWywOptions.js +23 -3
  192. package/types/transform.js +3 -1
  193. package/types/utils/EventEmitter.d.ts +16 -1
  194. package/types/utils/EventEmitter.js +44 -9
  195. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
  196. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
  197. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  198. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  199. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  200. package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
  201. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  202. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  203. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  204. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  205. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  206. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  207. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  208. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  209. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  210. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  211. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  212. package/types/utils/applyOxcProcessors/shared.js +37 -0
  213. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  214. package/types/utils/applyOxcProcessors/types.js +1 -0
  215. package/types/utils/applyOxcProcessors.d.ts +1 -16
  216. package/types/utils/applyOxcProcessors.js +1 -1391
  217. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  218. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  219. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  220. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  221. package/types/utils/collectOxcRuntime/types.d.ts +16 -0
  222. package/types/utils/collectOxcRuntime/types.js +1 -0
  223. package/types/utils/collectOxcRuntime.d.ts +2 -12
  224. package/types/utils/collectOxcRuntime.js +5 -224
  225. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  226. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  227. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  228. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  229. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  230. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  231. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  232. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  233. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  234. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  235. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  236. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  237. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
  238. package/types/utils/collectOxcTemplateDependencies.js +3 -1580
  239. package/types/utils/nativeResolver.d.ts +13 -0
  240. package/types/utils/nativeResolver.js +91 -0
  241. package/types/utils/oxc/ast.d.ts +4 -0
  242. package/types/utils/oxc/ast.js +37 -0
  243. package/types/utils/oxc/parse.d.ts +3 -0
  244. package/types/utils/oxc/parse.js +2 -0
  245. package/types/utils/oxc/replacements.d.ts +12 -0
  246. package/types/utils/oxc/replacements.js +18 -0
  247. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  248. package/types/utils/oxc/sourceLocations.js +63 -0
  249. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  250. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  251. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  252. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  253. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  254. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  255. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  256. package/types/utils/oxcPreevalStage/processors.js +16 -0
  257. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  258. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  259. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  260. package/types/utils/oxcPreevalStage/types.js +1 -0
  261. package/types/utils/oxcPreevalStage.d.ts +2 -18
  262. package/types/utils/oxcPreevalStage.js +17 -79
  263. package/types/utils/oxcPreevalTransforms.js +14 -1
  264. package/types/utils/processorStaticSemantics.d.ts +13 -0
  265. package/types/utils/processorStaticSemantics.js +191 -0
  266. package/types/utils/resolveWithConditions.js +3 -3
  267. package/esm/eval/resolverStrategy.js +0 -51
  268. package/esm/eval/resolverStrategy.js.map +0 -1
  269. package/types/eval/resolverStrategy.d.ts +0 -13
  270. package/types/eval/resolverStrategy.js +0 -46
@@ -1 +1 @@
1
- {"mappings":"","names":[],"sources":["../../src/eval/protocol.ts"],"version":3,"sourcesContent":["import type {\n EvalResolverKind,\n EvalWarning,\n FeatureFlags,\n ImportOverrides,\n} from '@wyw-in-js/shared';\n\nimport type { SerializedError, SerializedValue } from './serialize';\n\nexport type EvalRunnerInitPayload = {\n evalOptions: {\n mode: 'strict' | 'loose';\n require: 'warn-and-run' | 'error' | 'off';\n globals: Record<string, unknown>;\n importOverrides?: ImportOverrides;\n root?: string;\n extensions?: string[];\n };\n features: FeatureFlags<'happyDOM'>;\n entrypoint: string;\n reuseModules?: boolean;\n};\n\nexport type EvalRequest = {\n id: string;\n};\n\nexport type EvalResultPayload = {\n values: Record<string, SerializedValue> | null;\n modules?: Record<string, Record<string, SerializedValue>>;\n};\n\nexport type ResolveRequestPayload = {\n specifier: string;\n importerId: string;\n kind: EvalResolverKind;\n};\n\nexport type ResolveResultPayload = {\n resolvedId: string | null;\n external?: boolean;\n error?: SerializedError;\n};\n\nexport type LoadRequestPayload = {\n id: string;\n importerId?: string | null;\n request?: string | null;\n};\n\nexport type LoadResultPayload = {\n id: string;\n code?: string;\n codeChunk?: string;\n chunkIndex?: number;\n chunkCount?: number;\n map?: unknown;\n hash?: string;\n only?: string[];\n exports?: Record<string, SerializedValue>;\n error?: SerializedError;\n};\n\nexport type InitMessage = {\n type: 'INIT';\n id: string;\n payload: EvalRunnerInitPayload;\n};\n\nexport type InitAckMessage = {\n type: 'INIT_ACK';\n id: string;\n error?: SerializedError;\n // Set by the runner when it just reset its moduleCache during INIT (full\n // reset on context rebuild, or `reuseModules: false`). The broker uses\n // this to invalidate its \"what runner has\" mirror without doing any\n // payload hashing or stringification on its own hot path.\n modulesReset?: boolean;\n};\n\nexport type EvalMessage = {\n type: 'EVAL';\n id: string;\n payload: EvalRequest;\n};\n\nexport type EvalResultMessage = {\n type: 'EVAL_RESULT';\n id: string;\n payload: EvalResultPayload;\n error?: SerializedError;\n};\n\nexport type ResolveMessage = {\n type: 'RESOLVE';\n id: string;\n payload: ResolveRequestPayload;\n};\n\nexport type ResolveResultMessage = {\n type: 'RESOLVE_RESULT';\n id: string;\n payload: ResolveResultPayload;\n};\n\nexport type LoadMessage = {\n type: 'LOAD';\n id: string;\n payload: LoadRequestPayload;\n};\n\nexport type LoadResultMessage = {\n type: 'LOAD_RESULT';\n id: string;\n payload: LoadResultPayload;\n};\n\nexport type WarnMessage = {\n type: 'WARN';\n payload: EvalWarning;\n};\n\nexport type RunnerToMainMessage =\n | ResolveMessage\n | LoadMessage\n | WarnMessage\n | InitAckMessage\n | EvalResultMessage;\n\nexport type MainToRunnerMessage =\n | InitMessage\n | EvalMessage\n | ResolveResultMessage\n | LoadResultMessage;\n"],"file":"protocol.js"}
1
+ {"mappings":"","names":[],"sources":["../../src/eval/protocol.ts"],"version":3,"sourcesContent":["import type {\n EvalResolverKind,\n EvalWarning,\n FeatureFlags,\n ImportOverrides,\n} from '@wyw-in-js/shared';\n\nimport type { SerializedError, SerializedValue } from './serialize';\n\nexport type EvalRunnerInitPayload = {\n evalOptions: {\n errors: 'strict' | 'loose';\n require: 'warn-and-run' | 'error' | 'off';\n globals: Record<string, unknown>;\n importOverrides?: ImportOverrides;\n root?: string;\n extensions?: string[];\n };\n features: FeatureFlags<'happyDOM'>;\n debugEvalFiles?: boolean;\n entrypoint: string;\n reuseModules?: boolean;\n};\n\nexport type EvalRequest = {\n id: string;\n};\n\nexport type EvalResultPayload = {\n values: Record<string, SerializedValue> | null;\n modules?: Record<string, Record<string, SerializedValue>>;\n debugEvalFiles?: Record<string, DebugEvalFileValues>;\n};\n\nexport type DebugEvalFileValue =\n | {\n serialized: SerializedValue;\n status: 'serialized';\n }\n | {\n reason: string;\n status: 'stringified';\n stringified: string;\n };\n\nexport type DebugEvalFileValues = {\n exports?: Record<string, DebugEvalFileValue>;\n preval?: Record<string, DebugEvalFileValue>;\n};\n\nexport type ResolveRequestPayload = {\n specifier: string;\n importerId: string;\n kind: EvalResolverKind;\n};\n\nexport type ResolveResultPayload = {\n resolvedId: string | null;\n external?: boolean;\n error?: SerializedError;\n};\n\nexport type LoadRequestPayload = {\n id: string;\n importerId?: string | null;\n request?: string | null;\n};\n\nexport type LoadResultPayload = {\n id: string;\n code?: string;\n codeChunk?: string;\n chunkIndex?: number;\n chunkCount?: number;\n map?: unknown;\n hash?: string;\n only?: string[];\n exports?: Record<string, SerializedValue>;\n error?: SerializedError;\n};\n\nexport type InitMessage = {\n type: 'INIT';\n id: string;\n payload: EvalRunnerInitPayload;\n};\n\nexport type InitAckMessage = {\n type: 'INIT_ACK';\n id: string;\n error?: SerializedError;\n // Set by the runner when it just reset its moduleCache during INIT (full\n // reset on context rebuild, or `reuseModules: false`). The broker uses\n // this to invalidate its \"what runner has\" mirror without doing any\n // payload hashing or stringification on its own hot path.\n modulesReset?: boolean;\n};\n\nexport type EvalMessage = {\n type: 'EVAL';\n id: string;\n payload: EvalRequest;\n};\n\nexport type EvalResultMessage = {\n type: 'EVAL_RESULT';\n id: string;\n payload: EvalResultPayload;\n error?: SerializedError;\n};\n\nexport type ResolveMessage = {\n type: 'RESOLVE';\n id: string;\n payload: ResolveRequestPayload;\n};\n\nexport type ResolveResultMessage = {\n type: 'RESOLVE_RESULT';\n id: string;\n payload: ResolveResultPayload;\n};\n\nexport type LoadMessage = {\n type: 'LOAD';\n id: string;\n payload: LoadRequestPayload;\n};\n\nexport type LoadResultMessage = {\n type: 'LOAD_RESULT';\n id: string;\n payload: LoadResultPayload;\n};\n\nexport type WarnMessage = {\n type: 'WARN';\n payload: EvalWarning;\n};\n\nexport type RunnerToMainMessage =\n | ResolveMessage\n | LoadMessage\n | WarnMessage\n | InitAckMessage\n | EvalResultMessage;\n\nexport type MainToRunnerMessage =\n | InitMessage\n | EvalMessage\n | ResolveResultMessage\n | LoadResultMessage;\n"],"file":"protocol.js"}
@@ -706,7 +706,7 @@ const state = {
706
706
  happyDomEnabled: null,
707
707
  globalsSignature: null,
708
708
  evalOptions: {
709
- mode: "strict",
709
+ errors: "strict",
710
710
  require: "warn-and-run",
711
711
  globals: {},
712
712
  importOverrides: undefined,
@@ -714,6 +714,7 @@ const state = {
714
714
  extensions: []
715
715
  },
716
716
  features: {},
717
+ debugEvalFiles: false,
717
718
  entrypoint: "eval-runner"
718
719
  };
719
720
  const moduleCache = new LruCache(LOAD_CACHE_SIZE);
@@ -729,12 +730,23 @@ const resolveCache = new LruCache(RESOLVE_CACHE_SIZE);
729
730
  const resolveInFlight = new Map();
730
731
  const pending = new Map();
731
732
  const loadResultChunks = new Map();
733
+ // Ids evicted during the in-flight EVAL session via resetSingleModuleState.
734
+ // Surfaced in EVAL_RESULT so the broker can drop matching entries from its
735
+ // "what runner has" mirror (lastSentLoadByModule) — otherwise the broker would
736
+ // keep short-circuiting subsequent LOADs with empty `code` and the runner
737
+ // would have no way to obtain fresh source.
738
+ const evictedThisSession = new Set();
732
739
  let nextId = 0;
733
740
  const stdoutWriteQueue = [];
734
741
  let stdoutWriteInFlight = false;
735
742
  let stdoutWriteFailed = null;
736
743
  let shutdownRequested = false;
737
744
  let shutdownFinished = false;
745
+ // Tracks the SourceTextModule identifier (versioned with hash) that was last
746
+ // included in an EVAL_RESULT for each id. Reused module variants don't need
747
+ // re-serialization across eval sessions — same variant = same namespace =
748
+ // same exports the broker already has cached.
749
+ const sentNamespaceIdentifiers = new Map();
738
750
  const resetModuleState = () => {
739
751
  moduleCache.clear();
740
752
  moduleHashes.clear();
@@ -749,11 +761,6 @@ const resetModuleState = () => {
749
761
  resolveCache.clear();
750
762
  sentNamespaceIdentifiers.clear();
751
763
  };
752
- // Tracks the SourceTextModule identifier (versioned with hash) that was last
753
- // included in an EVAL_RESULT for each id. Reused module variants don't need
754
- // re-serialization across eval sessions — same variant = same namespace =
755
- // same exports the broker already has cached.
756
- const sentNamespaceIdentifiers = new Map();
757
764
  const resetSingleModuleState = (id, cachedModule = moduleCache.get(id)) => {
758
765
  if (cachedModule) {
759
766
  linkPromises.delete(cachedModule);
@@ -767,6 +774,16 @@ const resetSingleModuleState = (id, cachedModule = moduleCache.get(id)) => {
767
774
  moduleData.delete(id);
768
775
  moduleVariants.delete(id);
769
776
  moduleLastVariant.delete(id);
777
+ sentNamespaceIdentifiers.delete(id);
778
+ };
779
+ // Stronger reset for error paths: clears moduleOnly too and records the id so
780
+ // the broker can drop its lastSentLoadByModule entry. Used when a module's
781
+ // SourceTextModule has reached an unrecoverable state (e.g. link errored
782
+ // against a transient missing import) and should not be reused.
783
+ const evictPoisonedModule = (id) => {
784
+ resetSingleModuleState(id);
785
+ moduleOnly.delete(id);
786
+ evictedThisSession.add(id);
770
787
  };
771
788
  const isFullModuleLoad = (loaded) => !loaded.only || loaded.only.length === 1 && loaded.only[0] === "*";
772
789
  const getModuleVariant = (id, hash) => moduleVariants.get(id)?.get(hash);
@@ -924,6 +941,22 @@ const sendWarn = (warning) => {
924
941
  payload: warning
925
942
  });
926
943
  };
944
+ const reviveSerializedError = (error) => {
945
+ if (error instanceof Error) {
946
+ return error;
947
+ }
948
+ const revived = new Error(error?.message ?? String(error));
949
+ if (error?.name) {
950
+ revived.name = error.name;
951
+ }
952
+ if (error?.stack) {
953
+ revived.stack = error.stack;
954
+ }
955
+ if (error?.cause) {
956
+ revived.cause = reviveSerializedError(error.cause);
957
+ }
958
+ return revived;
959
+ };
927
960
  const serializeError = (error) => {
928
961
  const result = {
929
962
  message: error?.message ?? String(error),
@@ -1022,12 +1055,12 @@ const createRequireFn = (importer) => {
1022
1055
  throw new Error(`[wyw-in-js] require() fallback is disabled by eval.require: 'off'.`);
1023
1056
  }
1024
1057
  if (nonLiteral || typeof specifier !== "string") {
1025
- if (state.evalOptions.mode === "strict") {
1058
+ if (state.evalOptions.errors === "strict") {
1026
1059
  throw new Error(`[wyw-in-js] Non-literal require() is not supported during eval.\n` + `importer: ${importerFile}\n` + `hint: make it a string literal or mock the import via importOverrides.`);
1027
1060
  }
1028
1061
  sendWarn({
1029
1062
  code: "require-error",
1030
- message: "[wyw-in-js] Non-literal require() reached during eval (loose mode).",
1063
+ message: "[wyw-in-js] Non-literal require() reached during eval (eval.errors: \"loose\").",
1031
1064
  importer: importerFile
1032
1065
  });
1033
1066
  return {};
@@ -1225,6 +1258,16 @@ const linkModule = async (module) => {
1225
1258
  await module.link((specifier, referencingModule) => resolveModule(specifier, referencingModule.identifier, "import"));
1226
1259
  return module;
1227
1260
  } catch (error) {
1261
+ // The vm SourceTextModule is now in 'errored' (or partially-linked)
1262
+ // state and can never be re-linked. With reuseModules:true the cached
1263
+ // module would otherwise stick around and short-circuit linkModule's
1264
+ // status guard above on the next session — surfacing the original
1265
+ // failure forever even after the user fixes the underlying problem.
1266
+ // Drop it so the next LOAD rebuilds a fresh SourceTextModule.
1267
+ const identifier = typeof module.identifier === "string" ? module.identifier : null;
1268
+ if (identifier) {
1269
+ evictPoisonedModule(toSourceModuleId(identifier));
1270
+ }
1228
1271
  // ERR_VM_MODULE_LINK_FAILURE means a dependency is in "errored" state.
1229
1272
  // Node chains .cause through the link failure hierarchy. Walk to the
1230
1273
  // deepest cause to surface the original evaluation error (e.g. a
@@ -1267,7 +1310,7 @@ resolveModule = async (specifier, importer, kind) => {
1267
1310
  const cached = resolveCache.get(key);
1268
1311
  if (cached) {
1269
1312
  if (!cached.resolvedId) {
1270
- if (state.evalOptions.mode === "loose") {
1313
+ if (state.evalOptions.errors === "loose") {
1271
1314
  return createSyntheticModule(specifier, { default: undefined });
1272
1315
  }
1273
1316
  throw new Error([
@@ -1312,7 +1355,7 @@ resolveModule = async (specifier, importer, kind) => {
1312
1355
  external: Boolean(resolved.external)
1313
1356
  });
1314
1357
  if (!normalized) {
1315
- if (state.evalOptions.mode === "loose") {
1358
+ if (state.evalOptions.errors === "loose") {
1316
1359
  return createSyntheticModule(specifier, { default: undefined });
1317
1360
  }
1318
1361
  throw new Error([
@@ -1355,7 +1398,29 @@ loadModule = async (id, importer, requestSpec) => {
1355
1398
  durationMs: Date.now() - loadStart
1356
1399
  });
1357
1400
  if (loaded.error) {
1358
- throw new Error(loaded.error.message);
1401
+ // Surface the importer + specifier alongside the broker's message.
1402
+ // Without this, ENOENT and similar load failures bubble up as a bare
1403
+ // path (or, after Node's VM wraps them, as the opaque
1404
+ // ERR_VM_MODULE_STATUS) leaving no clue which file's import is broken.
1405
+ const detail = [
1406
+ `[wyw-in-js] Failed to load module during evaluation.`,
1407
+ ` importer: ${importer ?? "(unknown)"}`,
1408
+ ` request: ${requestSpec ?? id}`,
1409
+ ` resolved: ${id}`,
1410
+ ` cause: ${loaded.error.message}`
1411
+ ].join("\n");
1412
+ // The importer's SourceTextModule (if it was already created and
1413
+ // cached) compiled this `import` against `id`; reusing it next session
1414
+ // would link against the same id and either re-trigger the failure or
1415
+ // skip linking via the status guard. Drop both so the next session
1416
+ // pulls fresh code for both ends of the broken edge.
1417
+ if (importer && importer !== id) {
1418
+ evictPoisonedModule(toSourceModuleId(importer));
1419
+ }
1420
+ evictPoisonedModule(id);
1421
+ const enhanced = new Error(detail);
1422
+ enhanced.cause = reviveSerializedError(loaded.error);
1423
+ throw enhanced;
1359
1424
  }
1360
1425
  if (loaded.only) {
1361
1426
  const current = moduleOnly.get(id) ?? [];
@@ -1379,12 +1444,7 @@ loadModule = async (id, importer, requestSpec) => {
1379
1444
  if (!evaluated) {
1380
1445
  const variants = moduleVariants.get(id);
1381
1446
  if (variants) {
1382
- for (const variant of variants.values()) {
1383
- if (variant.status === "evaluated" && coversKeys(variant)) {
1384
- evaluated = variant;
1385
- break;
1386
- }
1387
- }
1447
+ evaluated = Array.from(variants.values()).find((variant) => variant.status === "evaluated" && coversKeys(variant));
1388
1448
  }
1389
1449
  }
1390
1450
  if (evaluated) {
@@ -1467,7 +1527,7 @@ const createDynamicImportFn = (importer) => {
1467
1527
  message: "[wyw-in-js] Dynamic import with non-string specifier during eval.",
1468
1528
  importer
1469
1529
  });
1470
- if (state.evalOptions.mode === "strict") {
1530
+ if (state.evalOptions.errors === "strict") {
1471
1531
  throw new Error(`[wyw-in-js] Dynamic import with non-string specifier is not supported during eval.\n` + `importer: ${importer}\n` + `hint: make it a string literal or mock the import via importOverrides.`);
1472
1532
  }
1473
1533
  return createSyntheticModule(`dynamic:${String(specifier)}`, { default: undefined });
@@ -1518,8 +1578,21 @@ const resolveExportValue = (source, key) => {
1518
1578
  }
1519
1579
  return undefined;
1520
1580
  };
1581
+ const stringifyDebugValue = (value) => {
1582
+ try {
1583
+ const json = JSON.stringify(value);
1584
+ if (json !== undefined) return json;
1585
+ } catch {}
1586
+ try {
1587
+ return String(value);
1588
+ } catch {
1589
+ return Object.prototype.toString.call(value);
1590
+ }
1591
+ };
1592
+ const serializeDebugReason = (error) => error instanceof Error ? error.message : String(error);
1521
1593
  const collectModuleExports = () => {
1522
1594
  const exportsByModule = {};
1595
+ const debugEvalFiles = state.debugEvalFiles ? {} : undefined;
1523
1596
  moduleOnly.forEach((only, id) => {
1524
1597
  if (!only || only.length === 0) return;
1525
1598
  const module = moduleCache.get(id) ?? moduleLastVariant.get(id);
@@ -1551,6 +1624,7 @@ const collectModuleExports = () => {
1551
1624
  const keys = Array.from(new Set([...requestedKeys, ...discoveredKeys]));
1552
1625
  if (keys.length === 0) return;
1553
1626
  const serialized = {};
1627
+ const debugExports = state.debugEvalFiles ? {} : undefined;
1554
1628
  keys.forEach((key) => {
1555
1629
  const value = resolveExportValue(source, key);
1556
1630
  try {
@@ -1558,14 +1632,34 @@ const collectModuleExports = () => {
1558
1632
  rootLabel: "module exports",
1559
1633
  path: [id, key]
1560
1634
  });
1561
- } catch {}
1635
+ if (debugExports) {
1636
+ debugExports[key] = {
1637
+ serialized: serialized[key],
1638
+ status: "serialized"
1639
+ };
1640
+ }
1641
+ } catch (error) {
1642
+ if (debugExports) {
1643
+ debugExports[key] = {
1644
+ reason: serializeDebugReason(error),
1645
+ status: "stringified",
1646
+ stringified: stringifyDebugValue(value)
1647
+ };
1648
+ }
1649
+ }
1562
1650
  });
1651
+ if (debugEvalFiles && debugExports && Object.keys(debugExports).length) {
1652
+ debugEvalFiles[id] = { exports: debugExports };
1653
+ }
1563
1654
  if (Object.keys(serialized).length) {
1564
1655
  exportsByModule[id] = serialized;
1565
1656
  sentNamespaceIdentifiers.set(id, moduleIdentifier);
1566
1657
  }
1567
1658
  });
1568
- return exportsByModule;
1659
+ return {
1660
+ debugEvalFiles,
1661
+ modules: exportsByModule
1662
+ };
1569
1663
  };
1570
1664
  async function evaluateEntrypoint(id) {
1571
1665
  const evalStart = Date.now();
@@ -1590,9 +1684,10 @@ async function evaluateEntrypoint(id) {
1590
1684
  const hasPrevalExport = exportsValue && typeof exportsValue === "object" && "__wywPreval" in exportsValue;
1591
1685
  const { namespace } = module;
1592
1686
  const hasPrevalNamespace = namespace && typeof namespace === "object" && "__wywPreval" in namespace;
1593
- const modules = collectModuleExports();
1687
+ const { debugEvalFiles, modules } = collectModuleExports();
1594
1688
  if (!hasPrevalExport && !hasPrevalNamespace) {
1595
1689
  return {
1690
+ debugEvalFiles,
1596
1691
  values: null,
1597
1692
  modules
1598
1693
  };
@@ -1600,11 +1695,13 @@ async function evaluateEntrypoint(id) {
1600
1695
  const preval = hasPrevalExport ? exportsValue.__wywPreval : namespace.__wywPreval;
1601
1696
  if (!preval || typeof preval !== "object") {
1602
1697
  return {
1698
+ debugEvalFiles,
1603
1699
  values: null,
1604
1700
  modules
1605
1701
  };
1606
1702
  }
1607
1703
  const values = {};
1704
+ const debugPreval = state.debugEvalFiles ? {} : undefined;
1608
1705
  Object.entries(preval).forEach(([key, lazy]) => {
1609
1706
  let value;
1610
1707
  try {
@@ -1618,8 +1715,21 @@ async function evaluateEntrypoint(id) {
1618
1715
  rootLabel: "__wywPreval",
1619
1716
  path: [key]
1620
1717
  });
1718
+ if (debugPreval) {
1719
+ debugPreval[key] = {
1720
+ serialized: values[key],
1721
+ status: "serialized"
1722
+ };
1723
+ }
1621
1724
  });
1725
+ if (debugEvalFiles && debugPreval && Object.keys(debugPreval).length) {
1726
+ debugEvalFiles[id] = {
1727
+ ...debugEvalFiles[id] ?? {},
1728
+ preval: debugPreval
1729
+ };
1730
+ }
1622
1731
  return {
1732
+ debugEvalFiles,
1623
1733
  values,
1624
1734
  modules
1625
1735
  };
@@ -1633,6 +1743,7 @@ const handleMessage = async (message) => {
1633
1743
  const encodedGlobals = message.payload.evalOptions.globals ?? {};
1634
1744
  const nextGlobalsSignature = JSON.stringify(canonicalizeForSignature(encodedGlobals));
1635
1745
  const nextFeatures = message.payload.features ?? {};
1746
+ const nextDebugEvalFiles = Boolean(message.payload.debugEvalFiles);
1636
1747
  const nextEntrypoint = message.payload.entrypoint ?? "eval-runner";
1637
1748
  const nextHappyDomEnabled = isFeatureEnabled(nextFeatures, "happyDOM", nextEntrypoint);
1638
1749
  const globalsChanged = state.globalsSignature !== null && state.globalsSignature !== nextGlobalsSignature;
@@ -1663,6 +1774,7 @@ const handleMessage = async (message) => {
1663
1774
  }
1664
1775
  state.evalOptions = nextEvalOptions;
1665
1776
  state.features = nextFeatures;
1777
+ state.debugEvalFiles = nextDebugEvalFiles;
1666
1778
  state.entrypoint = nextEntrypoint;
1667
1779
  Object.assign(state.context, {
1668
1780
  __dirname: path.dirname(nextEntrypoint),
@@ -1682,6 +1794,7 @@ const handleMessage = async (message) => {
1682
1794
  resetEvaluationState();
1683
1795
  state.evalOptions = nextEvalOptions;
1684
1796
  state.features = nextFeatures;
1797
+ state.debugEvalFiles = nextDebugEvalFiles;
1685
1798
  state.entrypoint = nextEntrypoint;
1686
1799
  debug("init:globals", Date.now() - initStart);
1687
1800
  const windowStart = Date.now();
@@ -1711,21 +1824,27 @@ const handleMessage = async (message) => {
1711
1824
  break;
1712
1825
  }
1713
1826
  case "EVAL": {
1827
+ evictedThisSession.clear();
1714
1828
  try {
1715
- const { values, modules } = await evaluateEntrypoint(message.payload.id);
1829
+ const { debugEvalFiles, values, modules } = await evaluateEntrypoint(message.payload.id);
1716
1830
  sendMessage({
1717
1831
  type: "EVAL_RESULT",
1718
1832
  id: message.id,
1719
1833
  payload: {
1834
+ ...debugEvalFiles ? { debugEvalFiles } : {},
1720
1835
  values,
1721
- modules
1836
+ modules,
1837
+ evictedIds: Array.from(evictedThisSession)
1722
1838
  }
1723
1839
  });
1724
1840
  } catch (error) {
1725
1841
  sendMessage({
1726
1842
  type: "EVAL_RESULT",
1727
1843
  id: message.id,
1728
- payload: { values: null },
1844
+ payload: {
1845
+ values: null,
1846
+ evictedIds: Array.from(evictedThisSession)
1847
+ },
1729
1848
  error: serializeError(error)
1730
1849
  });
1731
1850
  }