@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
@@ -11,8 +11,8 @@ import { isStaticallyEvaluatableModule } from '../transform/isStaticallyEvaluata
11
11
  import { applyImportOverrideToOnly, getImportOverride, resolveMockSpecifier, toImportKey, } from '../utils/importOverrides';
12
12
  import { getFileIdx } from '../utils/getFileIdx';
13
13
  import { collectOxcExportsAndImports } from '../utils/collectOxcExportsAndImports';
14
+ import { resolveWithNativeResolver } from '../utils/nativeResolver';
14
15
  import { parseRequest, stripQueryAndHash } from '../utils/parseRequest';
15
- import { resolveFilenameWithConditions } from '../utils/resolveWithConditions';
16
16
  import { hasCachedWywPrevalExport, } from '../utils/hasCachedWywPrevalExport';
17
17
  import { isSuperSet, mergeOnly } from '../transform/Entrypoint.helpers';
18
18
  import { oxcShaker } from '../shaker';
@@ -22,19 +22,6 @@ import { prepareModuleOnDemand, } from './prepareModuleOnDemand';
22
22
  import { deserializeValue, encodeGlobals, serializeValue, } from './serialize';
23
23
  import { createWriteQueue, writeToStream } from './writeQueue';
24
24
  const DefaultModuleImplementation = NativeModule;
25
- const CJS_DEFAULT_CONDITIONS = ['require', 'node', 'default'];
26
- const expandConditions = (conditionNames) => {
27
- const result = new Set();
28
- conditionNames.forEach((name) => {
29
- if (name === '...') {
30
- CJS_DEFAULT_CONDITIONS.forEach((condition) => result.add(condition));
31
- return;
32
- }
33
- result.add(name);
34
- });
35
- return result;
36
- };
37
- const NOOP = () => { };
38
25
  const isBuiltinSpecifier = (specifier) => {
39
26
  const normalized = specifier.startsWith('node:')
40
27
  ? specifier.slice(5)
@@ -187,7 +174,7 @@ const getSerializableStaticImportKeys = (services, id, cachedEntrypoint, require
187
174
  return requiredOnly.includes('*') ? evaluatedOnly : requiredOnly;
188
175
  };
189
176
  const DEFAULT_EVAL_OPTIONS = {
190
- mode: 'strict',
177
+ errors: 'strict',
191
178
  require: 'warn-and-run',
192
179
  resolver: 'bundler',
193
180
  };
@@ -236,6 +223,32 @@ const resolveDebugEvalDir = () => {
236
223
  };
237
224
  const debugEvalDir = resolveDebugEvalDir();
238
225
  let debugEvalDirReady = false;
226
+ const toBase64 = (value) => Buffer.from(value, 'utf8').toString('base64');
227
+ const toJsonBase64 = (value) => toBase64(JSON.stringify(value));
228
+ const serializedExportsToDebugValues = (serializedExports) => ({
229
+ exports: Object.fromEntries(Object.entries(serializedExports).map(([key, serialized]) => [
230
+ key,
231
+ {
232
+ serialized,
233
+ status: 'serialized',
234
+ },
235
+ ])),
236
+ });
237
+ const getDebugValuesStatus = (values) => {
238
+ const statuses = [
239
+ ...Object.values(values?.exports ?? {}),
240
+ ...Object.values(values?.preval ?? {}),
241
+ ].map((value) => value.status);
242
+ if (statuses.length === 0) {
243
+ return 'none';
244
+ }
245
+ const hasSerialized = statuses.includes('serialized');
246
+ const hasStringified = statuses.includes('stringified');
247
+ if (hasSerialized && hasStringified) {
248
+ return 'mixed';
249
+ }
250
+ return hasStringified ? 'stringified' : 'serialized';
251
+ };
239
252
  const ensureDebugEvalDir = () => {
240
253
  if (!debugEvalDir || debugEvalDirReady) {
241
254
  return;
@@ -365,7 +378,7 @@ const buildRunnerInitPayload = (services, entrypoint, featuresOverride) => {
365
378
  evalOptions: {
366
379
  globals: encodeGlobalsCached(sanitizedGlobals),
367
380
  importOverrides,
368
- mode: evalOptions.mode ?? 'strict',
381
+ errors: evalOptions.errors ?? 'strict',
369
382
  require: evalOptions.require ?? 'warn-and-run',
370
383
  root,
371
384
  extensions,
@@ -703,9 +716,6 @@ const canonicalizeForHash = (value) => {
703
716
  }
704
717
  return value;
705
718
  };
706
- const getInitPayloadKey = (payload) => createHash('sha256')
707
- .update(JSON.stringify(canonicalizeForHash(payload)))
708
- .digest('hex');
709
719
  // Hash everything in the init payload that affects whether the runner needs
710
720
  // a fresh INIT — i.e. everything except `entrypoint` (which only affects
711
721
  // __filename/__dirname rebinding, not context reuse). The broker memoizes
@@ -713,7 +723,8 @@ const getInitPayloadKey = (payload) => createHash('sha256')
713
723
  // with one SHA-256 of the stable bits + a cheap string concat per
714
724
  // entrypoint.
715
725
  const getStableInitPayloadHash = (payload) => {
716
- const { entrypoint: _entrypoint, ...stable } = payload;
726
+ const { entrypoint, ...stable } = payload;
727
+ void entrypoint;
717
728
  return createHash('sha256')
718
729
  .update(JSON.stringify(canonicalizeForHash(stable)))
719
730
  .digest('hex');
@@ -769,6 +780,12 @@ export class EvalBroker {
769
780
  loadInFlight = new Map();
770
781
  importsByModule = new Map();
771
782
  onlyByModule = new Map();
783
+ // Modules that are part of the current eval session's link graph. Used
784
+ // to scope `mergeKnownDependencyOnly` to entrypoints that share the
785
+ // current runner's VM, instead of unioning across every cached
786
+ // entrypoint project-wide. Cleared whenever the runner is killed or
787
+ // respawned (mirrors lastSentLoadByModule).
788
+ sessionLinkGraph = new Set();
772
789
  runtimeDependenciesByModule = new Map();
773
790
  emittedDependencies = new Set();
774
791
  // Mirrors the runner's view: for each module id, the (hash, mergedOnly) of
@@ -792,6 +809,7 @@ export class EvalBroker {
792
809
  // re-canonicalizing+stringifying+SHA-256ing the whole payload per call.
793
810
  stableInitHashCache = null;
794
811
  evalSeq = 0;
812
+ evalFileDebugLines = null;
795
813
  happyDomDisabled = false;
796
814
  happyDomDisableWarned = false;
797
815
  activeResolveRootId = null;
@@ -908,6 +926,7 @@ export class EvalBroker {
908
926
  this.activeResolveRootId = resolveRootId;
909
927
  this.resetPerEntrypointState(entrypoint);
910
928
  this.evalSeq += 1;
929
+ this.evalFileDebugLines = activeServices.eventEmitter.enabled ? [] : null;
911
930
  if (debugEvalDir) {
912
931
  debugAction({
913
932
  type: 'eval:start',
@@ -919,6 +938,7 @@ export class EvalBroker {
919
938
  try {
920
939
  await this.initRunner(entrypoint);
921
940
  const payload = await this.request('EVAL', { id: entrypoint.name }, EVAL_TIMEOUT_MS);
941
+ this.flushEvalFileDebugLines(payload.debugEvalFiles);
922
942
  if (debugEvalDir) {
923
943
  debugAction({
924
944
  type: 'eval:finish',
@@ -944,11 +964,64 @@ export class EvalBroker {
944
964
  };
945
965
  }
946
966
  finally {
967
+ this.evalFileDebugLines = null;
947
968
  if (this.activeResolveRootId === resolveRootId) {
948
969
  this.activeResolveRootId = null;
949
970
  }
950
971
  }
951
972
  }
973
+ recordEvalFileDebugLine(payload, prepared, shouldShipCode) {
974
+ if (!this.evalFileDebugLines) {
975
+ return;
976
+ }
977
+ if (shouldShipCode && prepared.code) {
978
+ this.evalFileDebugLines.push({
979
+ contentBase64: toBase64(prepared.code),
980
+ evalSeq: this.evalSeq,
981
+ hash: prepared.hash ?? null,
982
+ id: payload.id,
983
+ importer: payload.importerId ?? null,
984
+ only: prepared.only,
985
+ payloadKind: 'code',
986
+ request: payload.request ?? null,
987
+ type: 'eval-file',
988
+ valueStatus: 'none',
989
+ valuesBase64: null,
990
+ });
991
+ return;
992
+ }
993
+ if (prepared.exports) {
994
+ const values = serializedExportsToDebugValues(prepared.exports);
995
+ this.evalFileDebugLines.push({
996
+ contentBase64: null,
997
+ evalSeq: this.evalSeq,
998
+ hash: prepared.hash ?? null,
999
+ id: payload.id,
1000
+ importer: payload.importerId ?? null,
1001
+ only: prepared.only,
1002
+ payloadKind: 'serialized-exports',
1003
+ request: payload.request ?? null,
1004
+ type: 'eval-file',
1005
+ valueStatus: getDebugValuesStatus(values),
1006
+ valuesBase64: toJsonBase64(values),
1007
+ });
1008
+ }
1009
+ }
1010
+ flushEvalFileDebugLines(valuesById) {
1011
+ const lines = this.evalFileDebugLines;
1012
+ if (!lines) {
1013
+ return;
1014
+ }
1015
+ for (const line of lines) {
1016
+ this.currentServices.eventEmitter.single({
1017
+ ...line,
1018
+ valueStatus: line.valueStatus === 'none'
1019
+ ? getDebugValuesStatus(valuesById?.[line.id])
1020
+ : line.valueStatus,
1021
+ valuesBase64: line.valuesBase64 ?? toJsonBase64(valuesById?.[line.id] ?? {}),
1022
+ });
1023
+ }
1024
+ }
952
1025
  resetPerEntrypointState(entrypoint) {
953
1026
  this.runtimeDependenciesByModule.clear();
954
1027
  this.emittedDependencies.clear();
@@ -956,6 +1029,8 @@ export class EvalBroker {
956
1029
  this.onlyByModule.clear();
957
1030
  this.resolveCache.clear();
958
1031
  this.resolveInFlight.clear();
1032
+ this.sessionLinkGraph.clear();
1033
+ this.sessionLinkGraph.add(entrypoint.name);
959
1034
  this.onlyByModule.set(entrypoint.name, ['__wywPreval']);
960
1035
  }
961
1036
  applyModuleExports(modules) {
@@ -1001,6 +1076,7 @@ export class EvalBroker {
1001
1076
  this.lastInitKey = null;
1002
1077
  this.lastHappyDomEnabled = false;
1003
1078
  this.lastSentLoadByModule.clear();
1079
+ this.sessionLinkGraph.clear();
1004
1080
  this.stableInitHashCache = null;
1005
1081
  flushDebugStreams();
1006
1082
  }
@@ -1037,6 +1113,7 @@ export class EvalBroker {
1037
1113
  this.lastInitKey = null;
1038
1114
  this.lastHappyDomEnabled = false;
1039
1115
  this.lastSentLoadByModule.clear();
1116
+ this.sessionLinkGraph.clear();
1040
1117
  });
1041
1118
  }
1042
1119
  async ensureRunner() {
@@ -1147,6 +1224,7 @@ export class EvalBroker {
1147
1224
  // New process ⇒ runner's moduleCache/moduleHashes are empty, so our mirror
1148
1225
  // of "what we already shipped" is stale.
1149
1226
  this.lastSentLoadByModule.clear();
1227
+ this.sessionLinkGraph.clear();
1150
1228
  }
1151
1229
  getStableInitHash(services, features) {
1152
1230
  const pluginOptionsRef = services.options.pluginOptions;
@@ -1178,13 +1256,18 @@ export class EvalBroker {
1178
1256
  async initRunner(entrypoint) {
1179
1257
  const features = this.getRunnerFeatures();
1180
1258
  const stableHash = this.getStableInitHash(this.currentServices, features);
1181
- const initKey = `${stableHash}::${entrypoint.name}`;
1259
+ const debugEvalFiles = this.currentServices.eventEmitter.enabled;
1260
+ const debugEvalFilesKeyPart = debugEvalFiles ? '1' : '0';
1261
+ const initKey = `${stableHash}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1182
1262
  if (this.lastInitKey === initKey) {
1183
1263
  return;
1184
1264
  }
1185
1265
  const nextHappyDomEnabled = isFeatureEnabled(features, 'happyDOM', entrypoint.name);
1186
1266
  const payload = buildRunnerInitPayload(this.services, entrypoint, features);
1187
1267
  payload.reuseModules = true;
1268
+ if (debugEvalFiles) {
1269
+ payload.debugEvalFiles = true;
1270
+ }
1188
1271
  const timeoutMs = this.getInitTimeoutMs(entrypoint, features);
1189
1272
  if (this.runner &&
1190
1273
  this.lastInitKey !== null &&
@@ -1205,8 +1288,11 @@ export class EvalBroker {
1205
1288
  const fallbackFeatures = this.getRunnerFeatures();
1206
1289
  const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
1207
1290
  fallbackPayload.reuseModules = true;
1291
+ if (debugEvalFiles) {
1292
+ fallbackPayload.debugEvalFiles = true;
1293
+ }
1208
1294
  await this.request('INIT', fallbackPayload, INIT_TIMEOUT_MS);
1209
- this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}`;
1295
+ this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1210
1296
  this.lastHappyDomEnabled = false;
1211
1297
  return;
1212
1298
  }
@@ -1229,8 +1315,11 @@ export class EvalBroker {
1229
1315
  const fallbackFeatures = this.getRunnerFeatures();
1230
1316
  const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
1231
1317
  fallbackPayload.reuseModules = true;
1318
+ if (debugEvalFiles) {
1319
+ fallbackPayload.debugEvalFiles = true;
1320
+ }
1232
1321
  await this.request('INIT', fallbackPayload, INIT_TIMEOUT_MS);
1233
- this.lastInitKey = getInitPayloadKey(fallbackPayload);
1322
+ this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1234
1323
  this.lastHappyDomEnabled = false;
1235
1324
  return;
1236
1325
  }
@@ -1299,16 +1388,29 @@ export class EvalBroker {
1299
1388
  // context rebuild or reuseModules:false). Drop our shipped-code
1300
1389
  // mirror so handleLoad ships fresh code on the next LOAD.
1301
1390
  this.lastSentLoadByModule.clear();
1391
+ this.sessionLinkGraph.clear();
1302
1392
  }
1303
1393
  this.resolvePending(message.id, {});
1304
1394
  return;
1305
- case 'EVAL_RESULT':
1395
+ case 'EVAL_RESULT': {
1396
+ // Runner reports any ids it dropped from its caches during this
1397
+ // session (e.g. modules whose link errored after a transient missing
1398
+ // import). Mirror those evictions here — otherwise lastSentLoadByModule
1399
+ // would keep claiming the runner has them and handleLoad would ship
1400
+ // empty `code` on the next session, leaving the runner stuck.
1401
+ const evictedIds = message.payload?.evictedIds;
1402
+ if (evictedIds && evictedIds.length > 0) {
1403
+ for (const evictedId of evictedIds) {
1404
+ this.lastSentLoadByModule.delete(evictedId);
1405
+ }
1406
+ }
1306
1407
  if (message.error) {
1307
1408
  this.rejectPending(message.id, message.error);
1308
1409
  return;
1309
1410
  }
1310
1411
  this.resolvePending(message.id, message.payload);
1311
1412
  return;
1413
+ }
1312
1414
  case 'RESOLVE':
1313
1415
  this.handleResolve(message.id, message.payload).catch((error) => {
1314
1416
  void this.sendMessage({
@@ -1384,7 +1486,7 @@ export class EvalBroker {
1384
1486
  },
1385
1487
  });
1386
1488
  }
1387
- normalizeResolvedId(resolvedId, specifier, importerId) {
1489
+ normalizeResolvedId(resolvedId, specifier, importerId, kind) {
1388
1490
  const stripped = stripQueryAndHash(resolvedId);
1389
1491
  if (!stripped)
1390
1492
  return resolvedId;
@@ -1416,17 +1518,29 @@ export class EvalBroker {
1416
1518
  if (importerId) {
1417
1519
  try {
1418
1520
  const importerFile = stripQueryAndHash(importerId);
1419
- const resolved = DefaultModuleImplementation._resolveFilename(stripped, {
1420
- id: importerFile,
1421
- filename: importerFile,
1422
- paths: DefaultModuleImplementation._nodeModulePaths(path.dirname(importerFile)),
1521
+ const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
1522
+ const resolved = resolveWithNativeResolver({
1523
+ conditionNames,
1524
+ extensions,
1525
+ importer: importerFile,
1526
+ kind,
1527
+ oxcOptions,
1528
+ specifier: resolvedId,
1423
1529
  });
1424
1530
  if (resolved && resolved !== stripped) {
1425
- return `${resolved}${suffix}`;
1531
+ return resolved;
1426
1532
  }
1427
1533
  }
1428
- catch {
1429
- // ignore fallback failures
1534
+ catch (error) {
1535
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1536
+ // eslint-disable-next-line no-console
1537
+ console.warn('[wyw-eval:resolve:native-normalize-miss]', {
1538
+ specifier,
1539
+ importerId,
1540
+ kind,
1541
+ error,
1542
+ });
1543
+ }
1430
1544
  }
1431
1545
  }
1432
1546
  return resolvedId;
@@ -1460,7 +1574,7 @@ export class EvalBroker {
1460
1574
  }
1461
1575
  const strippedSpecifier = stripQueryAndHash(specifier);
1462
1576
  if (path.isAbsolute(strippedSpecifier)) {
1463
- const normalized = this.normalizeResolvedId(specifier, specifier, importerId);
1577
+ const normalized = this.normalizeResolvedId(specifier, specifier, importerId, kind);
1464
1578
  const overridden = this.applyImportOverrides({
1465
1579
  source: specifier,
1466
1580
  resolved: normalized,
@@ -1478,15 +1592,15 @@ export class EvalBroker {
1478
1592
  only: ['*'],
1479
1593
  });
1480
1594
  }
1481
- const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId);
1595
+ const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId, kind);
1482
1596
  const overridden = this.applyImportOverrides({
1483
1597
  source: specifier,
1484
1598
  resolved: normalized,
1485
1599
  only,
1486
1600
  external: cached.external,
1487
1601
  }, importerId, stack);
1488
- if (cached.usedNodeFallback) {
1489
- this.maybeWarnNodeFallback({
1602
+ if (cached.usedNativeFallback) {
1603
+ this.maybeWarnNativeFallback({
1490
1604
  importerId,
1491
1605
  specifier,
1492
1606
  resolvedId: normalized,
@@ -1504,15 +1618,15 @@ export class EvalBroker {
1504
1618
  only: ['*'],
1505
1619
  });
1506
1620
  }
1507
- const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId);
1621
+ const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId, kind);
1508
1622
  const overridden = this.applyImportOverrides({
1509
1623
  source: specifier,
1510
1624
  resolved: normalized,
1511
1625
  only,
1512
1626
  external: cachedResult.external,
1513
1627
  }, importerId, stack);
1514
- if (cachedResult.usedNodeFallback) {
1515
- this.maybeWarnNodeFallback({
1628
+ if (cachedResult.usedNativeFallback) {
1629
+ this.maybeWarnNativeFallback({
1516
1630
  importerId,
1517
1631
  specifier,
1518
1632
  resolvedId: normalized,
@@ -1525,7 +1639,7 @@ export class EvalBroker {
1525
1639
  if (evalOptions.customResolver) {
1526
1640
  const customResolved = await evalOptions.customResolver(specifier, importerId, kind);
1527
1641
  if (customResolved) {
1528
- const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId);
1642
+ const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId, kind);
1529
1643
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1530
1644
  // eslint-disable-next-line no-console
1531
1645
  console.warn('[wyw-eval:resolve:custom]', {
@@ -1545,7 +1659,47 @@ export class EvalBroker {
1545
1659
  return { resolvedId: null };
1546
1660
  }
1547
1661
  }
1548
- if (evalOptions.resolver !== 'node') {
1662
+ if (evalOptions.resolver === 'hybrid') {
1663
+ try {
1664
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1665
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1666
+ // eslint-disable-next-line no-console
1667
+ console.warn('[wyw-eval:resolve:native]', {
1668
+ specifier,
1669
+ importerId,
1670
+ resolved: nativeResolved.resolvedId,
1671
+ });
1672
+ }
1673
+ return nativeResolved;
1674
+ }
1675
+ catch (error) {
1676
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1677
+ // eslint-disable-next-line no-console
1678
+ console.warn('[wyw-eval:resolve:native-miss]', {
1679
+ specifier,
1680
+ importerId,
1681
+ kind,
1682
+ error,
1683
+ });
1684
+ }
1685
+ // Hybrid mode lets the bundler resolver handle aliases, virtual IDs,
1686
+ // and other specifiers that the native resolver cannot resolve.
1687
+ }
1688
+ }
1689
+ if (evalOptions.resolver === 'native') {
1690
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1691
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1692
+ // eslint-disable-next-line no-console
1693
+ console.warn('[wyw-eval:resolve:native]', {
1694
+ specifier,
1695
+ importerId,
1696
+ resolved: nativeResolved.resolvedId,
1697
+ });
1698
+ }
1699
+ return nativeResolved;
1700
+ }
1701
+ if (evalOptions.resolver === 'bundler' ||
1702
+ evalOptions.resolver === 'hybrid') {
1549
1703
  let resolved = null;
1550
1704
  try {
1551
1705
  resolved = await this.asyncResolve(specifier, importerId, stack);
@@ -1554,7 +1708,7 @@ export class EvalBroker {
1554
1708
  resolved = null;
1555
1709
  }
1556
1710
  if (resolved) {
1557
- const normalized = this.normalizeResolvedId(resolved, specifier, importerId);
1711
+ const normalized = this.normalizeResolvedId(resolved, specifier, importerId, kind);
1558
1712
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1559
1713
  // eslint-disable-next-line no-console
1560
1714
  console.warn('[wyw-eval:resolve:async]', {
@@ -1569,19 +1723,19 @@ export class EvalBroker {
1569
1723
  };
1570
1724
  }
1571
1725
  }
1572
- if (evalOptions.resolver === 'node' || evalOptions.require !== 'off') {
1573
- const nodeResolved = this.resolveWithNodeFallback(specifier, importerId);
1726
+ if (evalOptions.resolver === 'bundler' && evalOptions.require !== 'off') {
1727
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1574
1728
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1575
1729
  // eslint-disable-next-line no-console
1576
- console.warn('[wyw-eval:resolve:node]', {
1730
+ console.warn('[wyw-eval:resolve:native-fallback]', {
1577
1731
  specifier,
1578
1732
  importerId,
1579
- resolved: nodeResolved.resolvedId,
1733
+ resolved: nativeResolved.resolvedId,
1580
1734
  });
1581
1735
  }
1582
1736
  return {
1583
- ...nodeResolved,
1584
- usedNodeFallback: evalOptions.resolver !== 'node',
1737
+ ...nativeResolved,
1738
+ usedNativeFallback: true,
1585
1739
  };
1586
1740
  }
1587
1741
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
@@ -1609,8 +1763,8 @@ export class EvalBroker {
1609
1763
  only,
1610
1764
  external: result.external,
1611
1765
  }, importerId, stack);
1612
- if (result.usedNodeFallback && result.resolvedId) {
1613
- this.maybeWarnNodeFallback({
1766
+ if (result.usedNativeFallback && result.resolvedId) {
1767
+ this.maybeWarnNativeFallback({
1614
1768
  importerId,
1615
1769
  specifier,
1616
1770
  resolvedId: result.resolvedId,
@@ -1716,56 +1870,33 @@ export class EvalBroker {
1716
1870
  only: nextOnly,
1717
1871
  };
1718
1872
  }
1719
- resolveWithNodeFallback(specifier, importerId) {
1720
- const extensions = DefaultModuleImplementation._extensions;
1721
- const added = [];
1722
- const { conditionNames } = this.services.options.pluginOptions;
1723
- const conditions = conditionNames?.length
1724
- ? expandConditions(conditionNames)
1725
- : undefined;
1873
+ resolveWithNativeFallback(specifier, importerId, kind) {
1874
+ const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
1726
1875
  try {
1727
- this.services.options.pluginOptions.extensions.forEach((ext) => {
1728
- if (ext in extensions)
1729
- return;
1730
- extensions[ext] = NOOP;
1731
- added.push(ext);
1876
+ const resolved = resolveWithNativeResolver({
1877
+ conditionNames,
1878
+ extensions,
1879
+ importer: importerId,
1880
+ kind,
1881
+ oxcOptions,
1882
+ specifier,
1732
1883
  });
1733
- const filename = importerId;
1734
- const strippedId = stripQueryAndHash(specifier);
1735
- let resolved;
1736
- try {
1737
- resolved = resolveFilenameWithConditions(DefaultModuleImplementation, strippedId, {
1738
- id: filename,
1739
- filename,
1740
- paths: DefaultModuleImplementation._nodeModulePaths(path.dirname(filename)),
1741
- }, conditions);
1742
- }
1743
- catch (error) {
1744
- throw new Error([
1745
- `[wyw-in-js] Node resolver failed during eval.`,
1746
- ``,
1747
- `importer: ${filename}`,
1748
- `source: ${specifier}`,
1749
- ``,
1750
- `error: ${error instanceof Error ? error.message : String(error)}`,
1751
- ].join('\n'));
1752
- }
1753
- const isFileSpecifier = strippedId.startsWith('.') || path.isAbsolute(strippedId);
1754
- if (isFileSpecifier &&
1755
- path.extname(strippedId) === '' &&
1756
- resolved.endsWith('.cjs') &&
1757
- fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
1758
- resolved = `${resolved.slice(0, -4)}.js`;
1759
- }
1760
1884
  return {
1761
- resolvedId: this.normalizeResolvedId(resolved, specifier, importerId),
1885
+ resolvedId: this.normalizeResolvedId(resolved, specifier, importerId, kind),
1762
1886
  };
1763
1887
  }
1764
- finally {
1765
- added.forEach((ext) => delete extensions[ext]);
1888
+ catch (error) {
1889
+ throw new Error([
1890
+ `[wyw-in-js] Native resolver failed during eval.`,
1891
+ ``,
1892
+ `importer: ${importerId}`,
1893
+ `source: ${specifier}`,
1894
+ ``,
1895
+ `error: ${error instanceof Error ? error.message : String(error)}`,
1896
+ ].join('\n'));
1766
1897
  }
1767
1898
  }
1768
- maybeWarnNodeFallback({ importerId, specifier, resolvedId, kind, }) {
1899
+ maybeWarnNativeFallback({ importerId, specifier, resolvedId, kind, }) {
1769
1900
  const evalOptions = getEvalOptions(this.services);
1770
1901
  const { root } = this.services.options;
1771
1902
  const keyInfo = toImportKey({
@@ -1784,7 +1915,7 @@ export class EvalBroker {
1784
1915
  }
1785
1916
  if (policy === 'error') {
1786
1917
  throw new Error([
1787
- `[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`,
1918
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
1788
1919
  ``,
1789
1920
  `importer: ${importerId}`,
1790
1921
  `source: ${specifier}`,
@@ -1800,7 +1931,7 @@ export class EvalBroker {
1800
1931
  if (policy === 'warn' && !warnedUnknownImports.has(keyInfo.key)) {
1801
1932
  warnedUnknownImports.add(keyInfo.key);
1802
1933
  const warningMessage = [
1803
- `[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`,
1934
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
1804
1935
  ``,
1805
1936
  `importer: ${importerId}`,
1806
1937
  `source: ${specifier}`,
@@ -1864,6 +1995,7 @@ export class EvalBroker {
1864
1995
  ts: performance.now(),
1865
1996
  });
1866
1997
  }
1998
+ this.recordEvalFileDebugLine(payload, prepared, shouldShipCode);
1867
1999
  await this.sendLoadResult(id, {
1868
2000
  id: payload.id,
1869
2001
  code: shouldShipCode ? prepared.code : '',
@@ -1881,6 +2013,14 @@ export class EvalBroker {
1881
2013
  only: merged,
1882
2014
  });
1883
2015
  }
2016
+ // Session link graph tracks every module that's been admitted into
2017
+ // the current runner's VM. mergeKnownDependencyOnly uses this to
2018
+ // narrow its consumer-set to entrypoints actually linking against
2019
+ // the same module instance.
2020
+ this.sessionLinkGraph.add(payload.id);
2021
+ if (payload.importerId) {
2022
+ this.sessionLinkGraph.add(payload.importerId);
2023
+ }
1884
2024
  }
1885
2025
  async loadModule({ id, importerId, request, }) {
1886
2026
  const actionEntrypoint = importerId ?? id;
@@ -2222,6 +2362,15 @@ export class EvalBroker {
2222
2362
  }
2223
2363
  let mergedOnly = storedOnly;
2224
2364
  for (const cachedEntrypoint of this.services.cache.entrypoints.values()) {
2365
+ // Scope the union to entrypoints that are part of the CURRENT
2366
+ // session's link graph. Cached entrypoints from prior transforms
2367
+ // already evaluated against their own VMs; their imports must not
2368
+ // widen this load. Empty session graph (initial load) falls back
2369
+ // to project-wide for safety.
2370
+ if (this.sessionLinkGraph.size > 0 &&
2371
+ !this.sessionLinkGraph.has(cachedEntrypoint.name)) {
2372
+ continue;
2373
+ }
2225
2374
  const { dependencies } = cachedEntrypoint;
2226
2375
  if (!dependencies) {
2227
2376
  continue;
@@ -2,7 +2,7 @@ import type { EvalResolverKind, EvalWarning, FeatureFlags, ImportOverrides } fro
2
2
  import type { SerializedError, SerializedValue } from './serialize';
3
3
  export type EvalRunnerInitPayload = {
4
4
  evalOptions: {
5
- mode: 'strict' | 'loose';
5
+ errors: 'strict' | 'loose';
6
6
  require: 'warn-and-run' | 'error' | 'off';
7
7
  globals: Record<string, unknown>;
8
8
  importOverrides?: ImportOverrides;
@@ -10,6 +10,7 @@ export type EvalRunnerInitPayload = {
10
10
  extensions?: string[];
11
11
  };
12
12
  features: FeatureFlags<'happyDOM'>;
13
+ debugEvalFiles?: boolean;
13
14
  entrypoint: string;
14
15
  reuseModules?: boolean;
15
16
  };
@@ -19,6 +20,19 @@ export type EvalRequest = {
19
20
  export type EvalResultPayload = {
20
21
  values: Record<string, SerializedValue> | null;
21
22
  modules?: Record<string, Record<string, SerializedValue>>;
23
+ debugEvalFiles?: Record<string, DebugEvalFileValues>;
24
+ };
25
+ export type DebugEvalFileValue = {
26
+ serialized: SerializedValue;
27
+ status: 'serialized';
28
+ } | {
29
+ reason: string;
30
+ status: 'stringified';
31
+ stringified: string;
32
+ };
33
+ export type DebugEvalFileValues = {
34
+ exports?: Record<string, DebugEvalFileValue>;
35
+ preval?: Record<string, DebugEvalFileValue>;
22
36
  };
23
37
  export type ResolveRequestPayload = {
24
38
  specifier: string;