@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.js";
12
12
  import { getFileIdx } from "../utils/getFileIdx.js";
13
13
  import { collectOxcExportsAndImports } from "../utils/collectOxcExportsAndImports.js";
14
+ import { resolveWithNativeResolver } from "../utils/nativeResolver.js";
14
15
  import { parseRequest, stripQueryAndHash } from "../utils/parseRequest.js";
15
- import { resolveFilenameWithConditions } from "../utils/resolveWithConditions.js";
16
16
  import { hasCachedWywPrevalExport } from "../utils/hasCachedWywPrevalExport.js";
17
17
  import { isSuperSet, mergeOnly } from "../transform/Entrypoint.helpers.js";
18
18
  import { oxcShaker } from "../shaker.js";
@@ -22,23 +22,6 @@ import { prepareModuleOnDemand } from "./prepareModuleOnDemand.js";
22
22
  import { deserializeValue, encodeGlobals, serializeValue } from "./serialize.js";
23
23
  import { createWriteQueue, writeToStream } from "./writeQueue.js";
24
24
  const DefaultModuleImplementation = NativeModule;
25
- const CJS_DEFAULT_CONDITIONS = [
26
- "require",
27
- "node",
28
- "default"
29
- ];
30
- const expandConditions = (conditionNames) => {
31
- const result = new Set();
32
- conditionNames.forEach((name) => {
33
- if (name === "...") {
34
- CJS_DEFAULT_CONDITIONS.forEach((condition) => result.add(condition));
35
- return;
36
- }
37
- result.add(name);
38
- });
39
- return result;
40
- };
41
- const NOOP = () => {};
42
25
  const isBuiltinSpecifier = (specifier) => {
43
26
  const normalized = specifier.startsWith("node:") ? specifier.slice(5) : specifier;
44
27
  return DefaultModuleImplementation.builtinModules?.includes(normalized) || DefaultModuleImplementation.builtinModules?.includes(`node:${normalized}`);
@@ -160,7 +143,7 @@ const getSerializableStaticImportKeys = (services, id, cachedEntrypoint, require
160
143
  return requiredOnly.includes("*") ? evaluatedOnly : requiredOnly;
161
144
  };
162
145
  const DEFAULT_EVAL_OPTIONS = {
163
- mode: "strict",
146
+ errors: "strict",
164
147
  require: "warn-and-run",
165
148
  resolver: "bundler"
166
149
  };
@@ -203,6 +186,24 @@ const resolveDebugEvalDir = () => {
203
186
  };
204
187
  const debugEvalDir = resolveDebugEvalDir();
205
188
  let debugEvalDirReady = false;
189
+ const toBase64 = (value) => Buffer.from(value, "utf8").toString("base64");
190
+ const toJsonBase64 = (value) => toBase64(JSON.stringify(value));
191
+ const serializedExportsToDebugValues = (serializedExports) => ({ exports: Object.fromEntries(Object.entries(serializedExports).map(([key, serialized]) => [key, {
192
+ serialized,
193
+ status: "serialized"
194
+ }])) });
195
+ const getDebugValuesStatus = (values) => {
196
+ const statuses = [...Object.values(values?.exports ?? {}), ...Object.values(values?.preval ?? {})].map((value) => value.status);
197
+ if (statuses.length === 0) {
198
+ return "none";
199
+ }
200
+ const hasSerialized = statuses.includes("serialized");
201
+ const hasStringified = statuses.includes("stringified");
202
+ if (hasSerialized && hasStringified) {
203
+ return "mixed";
204
+ }
205
+ return hasStringified ? "stringified" : "serialized";
206
+ };
206
207
  const ensureDebugEvalDir = () => {
207
208
  if (!debugEvalDir || debugEvalDirReady) {
208
209
  return;
@@ -322,7 +323,7 @@ const buildRunnerInitPayload = (services, entrypoint, featuresOverride) => {
322
323
  evalOptions: {
323
324
  globals: encodeGlobalsCached(sanitizedGlobals),
324
325
  importOverrides,
325
- mode: evalOptions.mode ?? "strict",
326
+ errors: evalOptions.errors ?? "strict",
326
327
  require: evalOptions.require ?? "warn-and-run",
327
328
  root,
328
329
  extensions
@@ -657,7 +658,6 @@ const canonicalizeForHash = (value) => {
657
658
  }
658
659
  return value;
659
660
  };
660
- const getInitPayloadKey = (payload) => createHash("sha256").update(JSON.stringify(canonicalizeForHash(payload))).digest("hex");
661
661
  // Hash everything in the init payload that affects whether the runner needs
662
662
  // a fresh INIT — i.e. everything except `entrypoint` (which only affects
663
663
  // __filename/__dirname rebinding, not context reuse). The broker memoizes
@@ -665,7 +665,8 @@ const getInitPayloadKey = (payload) => createHash("sha256").update(JSON.stringif
665
665
  // with one SHA-256 of the stable bits + a cheap string concat per
666
666
  // entrypoint.
667
667
  const getStableInitPayloadHash = (payload) => {
668
- const { entrypoint: _entrypoint, ...stable } = payload;
668
+ const { entrypoint, ...stable } = payload;
669
+ void entrypoint;
669
670
  return createHash("sha256").update(JSON.stringify(canonicalizeForHash(stable))).digest("hex");
670
671
  };
671
672
  // Memoize encodeGlobals on input reference. The user's globals object is
@@ -716,6 +717,12 @@ export class EvalBroker {
716
717
  loadInFlight = new Map();
717
718
  importsByModule = new Map();
718
719
  onlyByModule = new Map();
720
+ // Modules that are part of the current eval session's link graph. Used
721
+ // to scope `mergeKnownDependencyOnly` to entrypoints that share the
722
+ // current runner's VM, instead of unioning across every cached
723
+ // entrypoint project-wide. Cleared whenever the runner is killed or
724
+ // respawned (mirrors lastSentLoadByModule).
725
+ sessionLinkGraph = new Set();
719
726
  runtimeDependenciesByModule = new Map();
720
727
  emittedDependencies = new Set();
721
728
  // Mirrors the runner's view: for each module id, the (hash, mergedOnly) of
@@ -739,6 +746,7 @@ export class EvalBroker {
739
746
  // re-canonicalizing+stringifying+SHA-256ing the whole payload per call.
740
747
  stableInitHashCache = null;
741
748
  evalSeq = 0;
749
+ evalFileDebugLines = null;
742
750
  happyDomDisabled = false;
743
751
  happyDomDisableWarned = false;
744
752
  activeResolveRootId = null;
@@ -845,6 +853,7 @@ export class EvalBroker {
845
853
  this.activeResolveRootId = resolveRootId;
846
854
  this.resetPerEntrypointState(entrypoint);
847
855
  this.evalSeq += 1;
856
+ this.evalFileDebugLines = activeServices.eventEmitter.enabled ? [] : null;
848
857
  if (debugEvalDir) {
849
858
  debugAction({
850
859
  type: "eval:start",
@@ -856,6 +865,7 @@ export class EvalBroker {
856
865
  try {
857
866
  await this.initRunner(entrypoint);
858
867
  const payload = await this.request("EVAL", { id: entrypoint.name }, EVAL_TIMEOUT_MS);
868
+ this.flushEvalFileDebugLines(payload.debugEvalFiles);
859
869
  if (debugEvalDir) {
860
870
  debugAction({
861
871
  type: "eval:finish",
@@ -883,11 +893,62 @@ export class EvalBroker {
883
893
  dependencies: this.collectEntrypointDependencies(entrypoint.name)
884
894
  };
885
895
  } finally {
896
+ this.evalFileDebugLines = null;
886
897
  if (this.activeResolveRootId === resolveRootId) {
887
898
  this.activeResolveRootId = null;
888
899
  }
889
900
  }
890
901
  }
902
+ recordEvalFileDebugLine(payload, prepared, shouldShipCode) {
903
+ if (!this.evalFileDebugLines) {
904
+ return;
905
+ }
906
+ if (shouldShipCode && prepared.code) {
907
+ this.evalFileDebugLines.push({
908
+ contentBase64: toBase64(prepared.code),
909
+ evalSeq: this.evalSeq,
910
+ hash: prepared.hash ?? null,
911
+ id: payload.id,
912
+ importer: payload.importerId ?? null,
913
+ only: prepared.only,
914
+ payloadKind: "code",
915
+ request: payload.request ?? null,
916
+ type: "eval-file",
917
+ valueStatus: "none",
918
+ valuesBase64: null
919
+ });
920
+ return;
921
+ }
922
+ if (prepared.exports) {
923
+ const values = serializedExportsToDebugValues(prepared.exports);
924
+ this.evalFileDebugLines.push({
925
+ contentBase64: null,
926
+ evalSeq: this.evalSeq,
927
+ hash: prepared.hash ?? null,
928
+ id: payload.id,
929
+ importer: payload.importerId ?? null,
930
+ only: prepared.only,
931
+ payloadKind: "serialized-exports",
932
+ request: payload.request ?? null,
933
+ type: "eval-file",
934
+ valueStatus: getDebugValuesStatus(values),
935
+ valuesBase64: toJsonBase64(values)
936
+ });
937
+ }
938
+ }
939
+ flushEvalFileDebugLines(valuesById) {
940
+ const lines = this.evalFileDebugLines;
941
+ if (!lines) {
942
+ return;
943
+ }
944
+ for (const line of lines) {
945
+ this.currentServices.eventEmitter.single({
946
+ ...line,
947
+ valueStatus: line.valueStatus === "none" ? getDebugValuesStatus(valuesById?.[line.id]) : line.valueStatus,
948
+ valuesBase64: line.valuesBase64 ?? toJsonBase64(valuesById?.[line.id] ?? {})
949
+ });
950
+ }
951
+ }
891
952
  resetPerEntrypointState(entrypoint) {
892
953
  this.runtimeDependenciesByModule.clear();
893
954
  this.emittedDependencies.clear();
@@ -895,6 +956,8 @@ export class EvalBroker {
895
956
  this.onlyByModule.clear();
896
957
  this.resolveCache.clear();
897
958
  this.resolveInFlight.clear();
959
+ this.sessionLinkGraph.clear();
960
+ this.sessionLinkGraph.add(entrypoint.name);
898
961
  this.onlyByModule.set(entrypoint.name, ["__wywPreval"]);
899
962
  }
900
963
  applyModuleExports(modules) {
@@ -934,6 +997,7 @@ export class EvalBroker {
934
997
  this.lastInitKey = null;
935
998
  this.lastHappyDomEnabled = false;
936
999
  this.lastSentLoadByModule.clear();
1000
+ this.sessionLinkGraph.clear();
937
1001
  this.stableInitHashCache = null;
938
1002
  flushDebugStreams();
939
1003
  }
@@ -973,6 +1037,7 @@ export class EvalBroker {
973
1037
  this.lastInitKey = null;
974
1038
  this.lastHappyDomEnabled = false;
975
1039
  this.lastSentLoadByModule.clear();
1040
+ this.sessionLinkGraph.clear();
976
1041
  });
977
1042
  }
978
1043
  async ensureRunner() {
@@ -1081,6 +1146,7 @@ export class EvalBroker {
1081
1146
  // New process ⇒ runner's moduleCache/moduleHashes are empty, so our mirror
1082
1147
  // of "what we already shipped" is stale.
1083
1148
  this.lastSentLoadByModule.clear();
1149
+ this.sessionLinkGraph.clear();
1084
1150
  }
1085
1151
  getStableInitHash(services, features) {
1086
1152
  const pluginOptionsRef = services.options.pluginOptions;
@@ -1108,13 +1174,18 @@ export class EvalBroker {
1108
1174
  async initRunner(entrypoint) {
1109
1175
  const features = this.getRunnerFeatures();
1110
1176
  const stableHash = this.getStableInitHash(this.currentServices, features);
1111
- const initKey = `${stableHash}::${entrypoint.name}`;
1177
+ const debugEvalFiles = this.currentServices.eventEmitter.enabled;
1178
+ const debugEvalFilesKeyPart = debugEvalFiles ? "1" : "0";
1179
+ const initKey = `${stableHash}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1112
1180
  if (this.lastInitKey === initKey) {
1113
1181
  return;
1114
1182
  }
1115
1183
  const nextHappyDomEnabled = isFeatureEnabled(features, "happyDOM", entrypoint.name);
1116
1184
  const payload = buildRunnerInitPayload(this.services, entrypoint, features);
1117
1185
  payload.reuseModules = true;
1186
+ if (debugEvalFiles) {
1187
+ payload.debugEvalFiles = true;
1188
+ }
1118
1189
  const timeoutMs = this.getInitTimeoutMs(entrypoint, features);
1119
1190
  if (this.runner && this.lastInitKey !== null && nextHappyDomEnabled && !this.lastHappyDomEnabled && !this.happyDomDisabled) {
1120
1191
  try {
@@ -1130,8 +1201,11 @@ export class EvalBroker {
1130
1201
  const fallbackFeatures = this.getRunnerFeatures();
1131
1202
  const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
1132
1203
  fallbackPayload.reuseModules = true;
1204
+ if (debugEvalFiles) {
1205
+ fallbackPayload.debugEvalFiles = true;
1206
+ }
1133
1207
  await this.request("INIT", fallbackPayload, INIT_TIMEOUT_MS);
1134
- this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}`;
1208
+ this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1135
1209
  this.lastHappyDomEnabled = false;
1136
1210
  return;
1137
1211
  }
@@ -1151,8 +1225,11 @@ export class EvalBroker {
1151
1225
  const fallbackFeatures = this.getRunnerFeatures();
1152
1226
  const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
1153
1227
  fallbackPayload.reuseModules = true;
1228
+ if (debugEvalFiles) {
1229
+ fallbackPayload.debugEvalFiles = true;
1230
+ }
1154
1231
  await this.request("INIT", fallbackPayload, INIT_TIMEOUT_MS);
1155
- this.lastInitKey = getInitPayloadKey(fallbackPayload);
1232
+ this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
1156
1233
  this.lastHappyDomEnabled = false;
1157
1234
  return;
1158
1235
  }
@@ -1218,16 +1295,29 @@ export class EvalBroker {
1218
1295
  // context rebuild or reuseModules:false). Drop our shipped-code
1219
1296
  // mirror so handleLoad ships fresh code on the next LOAD.
1220
1297
  this.lastSentLoadByModule.clear();
1298
+ this.sessionLinkGraph.clear();
1221
1299
  }
1222
1300
  this.resolvePending(message.id, {});
1223
1301
  return;
1224
- case "EVAL_RESULT":
1302
+ case "EVAL_RESULT": {
1303
+ // Runner reports any ids it dropped from its caches during this
1304
+ // session (e.g. modules whose link errored after a transient missing
1305
+ // import). Mirror those evictions here — otherwise lastSentLoadByModule
1306
+ // would keep claiming the runner has them and handleLoad would ship
1307
+ // empty `code` on the next session, leaving the runner stuck.
1308
+ const evictedIds = message.payload?.evictedIds;
1309
+ if (evictedIds && evictedIds.length > 0) {
1310
+ for (const evictedId of evictedIds) {
1311
+ this.lastSentLoadByModule.delete(evictedId);
1312
+ }
1313
+ }
1225
1314
  if (message.error) {
1226
1315
  this.rejectPending(message.id, message.error);
1227
1316
  return;
1228
1317
  }
1229
1318
  this.resolvePending(message.id, message.payload);
1230
1319
  return;
1320
+ }
1231
1321
  case "RESOLVE":
1232
1322
  this.handleResolve(message.id, message.payload).catch((error) => {
1233
1323
  void this.sendMessage({
@@ -1301,7 +1391,7 @@ export class EvalBroker {
1301
1391
  }
1302
1392
  });
1303
1393
  }
1304
- normalizeResolvedId(resolvedId, specifier, importerId) {
1394
+ normalizeResolvedId(resolvedId, specifier, importerId, kind) {
1305
1395
  const stripped = stripQueryAndHash(resolvedId);
1306
1396
  if (!stripped) return resolvedId;
1307
1397
  if (path.extname(stripped)) return resolvedId;
@@ -1331,15 +1421,29 @@ export class EvalBroker {
1331
1421
  if (importerId) {
1332
1422
  try {
1333
1423
  const importerFile = stripQueryAndHash(importerId);
1334
- const resolved = DefaultModuleImplementation._resolveFilename(stripped, {
1335
- id: importerFile,
1336
- filename: importerFile,
1337
- paths: DefaultModuleImplementation._nodeModulePaths(path.dirname(importerFile))
1424
+ const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
1425
+ const resolved = resolveWithNativeResolver({
1426
+ conditionNames,
1427
+ extensions,
1428
+ importer: importerFile,
1429
+ kind,
1430
+ oxcOptions,
1431
+ specifier: resolvedId
1338
1432
  });
1339
1433
  if (resolved && resolved !== stripped) {
1340
- return `${resolved}${suffix}`;
1434
+ return resolved;
1341
1435
  }
1342
- } catch {}
1436
+ } catch (error) {
1437
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1438
+ // eslint-disable-next-line no-console
1439
+ console.warn("[wyw-eval:resolve:native-normalize-miss]", {
1440
+ specifier,
1441
+ importerId,
1442
+ kind,
1443
+ error
1444
+ });
1445
+ }
1446
+ }
1343
1447
  }
1344
1448
  return resolvedId;
1345
1449
  }
@@ -1380,7 +1484,7 @@ export class EvalBroker {
1380
1484
  }
1381
1485
  const strippedSpecifier = stripQueryAndHash(specifier);
1382
1486
  if (path.isAbsolute(strippedSpecifier)) {
1383
- const normalized = this.normalizeResolvedId(specifier, specifier, importerId);
1487
+ const normalized = this.normalizeResolvedId(specifier, specifier, importerId, kind);
1384
1488
  const overridden = this.applyImportOverrides({
1385
1489
  source: specifier,
1386
1490
  resolved: normalized,
@@ -1401,15 +1505,15 @@ export class EvalBroker {
1401
1505
  only: ["*"]
1402
1506
  });
1403
1507
  }
1404
- const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId);
1508
+ const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId, kind);
1405
1509
  const overridden = this.applyImportOverrides({
1406
1510
  source: specifier,
1407
1511
  resolved: normalized,
1408
1512
  only,
1409
1513
  external: cached.external
1410
1514
  }, importerId, stack);
1411
- if (cached.usedNodeFallback) {
1412
- this.maybeWarnNodeFallback({
1515
+ if (cached.usedNativeFallback) {
1516
+ this.maybeWarnNativeFallback({
1413
1517
  importerId,
1414
1518
  specifier,
1415
1519
  resolvedId: normalized,
@@ -1427,15 +1531,15 @@ export class EvalBroker {
1427
1531
  only: ["*"]
1428
1532
  });
1429
1533
  }
1430
- const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId);
1534
+ const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId, kind);
1431
1535
  const overridden = this.applyImportOverrides({
1432
1536
  source: specifier,
1433
1537
  resolved: normalized,
1434
1538
  only,
1435
1539
  external: cachedResult.external
1436
1540
  }, importerId, stack);
1437
- if (cachedResult.usedNodeFallback) {
1438
- this.maybeWarnNodeFallback({
1541
+ if (cachedResult.usedNativeFallback) {
1542
+ this.maybeWarnNativeFallback({
1439
1543
  importerId,
1440
1544
  specifier,
1441
1545
  resolvedId: normalized,
@@ -1448,7 +1552,7 @@ export class EvalBroker {
1448
1552
  if (evalOptions.customResolver) {
1449
1553
  const customResolved = await evalOptions.customResolver(specifier, importerId, kind);
1450
1554
  if (customResolved) {
1451
- const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId);
1555
+ const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId, kind);
1452
1556
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1453
1557
  // eslint-disable-next-line no-console
1454
1558
  console.warn("[wyw-eval:resolve:custom]", {
@@ -1468,7 +1572,43 @@ export class EvalBroker {
1468
1572
  return { resolvedId: null };
1469
1573
  }
1470
1574
  }
1471
- if (evalOptions.resolver !== "node") {
1575
+ if (evalOptions.resolver === "hybrid") {
1576
+ try {
1577
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1578
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1579
+ // eslint-disable-next-line no-console
1580
+ console.warn("[wyw-eval:resolve:native]", {
1581
+ specifier,
1582
+ importerId,
1583
+ resolved: nativeResolved.resolvedId
1584
+ });
1585
+ }
1586
+ return nativeResolved;
1587
+ } catch (error) {
1588
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1589
+ // eslint-disable-next-line no-console
1590
+ console.warn("[wyw-eval:resolve:native-miss]", {
1591
+ specifier,
1592
+ importerId,
1593
+ kind,
1594
+ error
1595
+ });
1596
+ }
1597
+ }
1598
+ }
1599
+ if (evalOptions.resolver === "native") {
1600
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1601
+ if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1602
+ // eslint-disable-next-line no-console
1603
+ console.warn("[wyw-eval:resolve:native]", {
1604
+ specifier,
1605
+ importerId,
1606
+ resolved: nativeResolved.resolvedId
1607
+ });
1608
+ }
1609
+ return nativeResolved;
1610
+ }
1611
+ if (evalOptions.resolver === "bundler" || evalOptions.resolver === "hybrid") {
1472
1612
  let resolved = null;
1473
1613
  try {
1474
1614
  resolved = await this.asyncResolve(specifier, importerId, stack);
@@ -1476,7 +1616,7 @@ export class EvalBroker {
1476
1616
  resolved = null;
1477
1617
  }
1478
1618
  if (resolved) {
1479
- const normalized = this.normalizeResolvedId(resolved, specifier, importerId);
1619
+ const normalized = this.normalizeResolvedId(resolved, specifier, importerId, kind);
1480
1620
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1481
1621
  // eslint-disable-next-line no-console
1482
1622
  console.warn("[wyw-eval:resolve:async]", {
@@ -1489,19 +1629,19 @@ export class EvalBroker {
1489
1629
  return { resolvedId: normalized };
1490
1630
  }
1491
1631
  }
1492
- if (evalOptions.resolver === "node" || evalOptions.require !== "off") {
1493
- const nodeResolved = this.resolveWithNodeFallback(specifier, importerId);
1632
+ if (evalOptions.resolver === "bundler" && evalOptions.require !== "off") {
1633
+ const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
1494
1634
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
1495
1635
  // eslint-disable-next-line no-console
1496
- console.warn("[wyw-eval:resolve:node]", {
1636
+ console.warn("[wyw-eval:resolve:native-fallback]", {
1497
1637
  specifier,
1498
1638
  importerId,
1499
- resolved: nodeResolved.resolvedId
1639
+ resolved: nativeResolved.resolvedId
1500
1640
  });
1501
1641
  }
1502
1642
  return {
1503
- ...nodeResolved,
1504
- usedNodeFallback: evalOptions.resolver !== "node"
1643
+ ...nativeResolved,
1644
+ usedNativeFallback: true
1505
1645
  };
1506
1646
  }
1507
1647
  if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
@@ -1529,8 +1669,8 @@ export class EvalBroker {
1529
1669
  only,
1530
1670
  external: result.external
1531
1671
  }, importerId, stack);
1532
- if (result.usedNodeFallback && result.resolvedId) {
1533
- this.maybeWarnNodeFallback({
1672
+ if (result.usedNativeFallback && result.resolvedId) {
1673
+ this.maybeWarnNativeFallback({
1534
1674
  importerId,
1535
1675
  specifier,
1536
1676
  resolvedId: result.resolvedId,
@@ -1632,46 +1772,30 @@ export class EvalBroker {
1632
1772
  only: nextOnly
1633
1773
  };
1634
1774
  }
1635
- resolveWithNodeFallback(specifier, importerId) {
1636
- const extensions = DefaultModuleImplementation._extensions;
1637
- const added = [];
1638
- const { conditionNames } = this.services.options.pluginOptions;
1639
- const conditions = conditionNames?.length ? expandConditions(conditionNames) : undefined;
1775
+ resolveWithNativeFallback(specifier, importerId, kind) {
1776
+ const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
1640
1777
  try {
1641
- this.services.options.pluginOptions.extensions.forEach((ext) => {
1642
- if (ext in extensions) return;
1643
- extensions[ext] = NOOP;
1644
- added.push(ext);
1778
+ const resolved = resolveWithNativeResolver({
1779
+ conditionNames,
1780
+ extensions,
1781
+ importer: importerId,
1782
+ kind,
1783
+ oxcOptions,
1784
+ specifier
1645
1785
  });
1646
- const filename = importerId;
1647
- const strippedId = stripQueryAndHash(specifier);
1648
- let resolved;
1649
- try {
1650
- resolved = resolveFilenameWithConditions(DefaultModuleImplementation, strippedId, {
1651
- id: filename,
1652
- filename,
1653
- paths: DefaultModuleImplementation._nodeModulePaths(path.dirname(filename))
1654
- }, conditions);
1655
- } catch (error) {
1656
- throw new Error([
1657
- `[wyw-in-js] Node resolver failed during eval.`,
1658
- ``,
1659
- `importer: ${filename}`,
1660
- `source: ${specifier}`,
1661
- ``,
1662
- `error: ${error instanceof Error ? error.message : String(error)}`
1663
- ].join("\n"));
1664
- }
1665
- const isFileSpecifier = strippedId.startsWith(".") || path.isAbsolute(strippedId);
1666
- if (isFileSpecifier && path.extname(strippedId) === "" && resolved.endsWith(".cjs") && fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
1667
- resolved = `${resolved.slice(0, -4)}.js`;
1668
- }
1669
- return { resolvedId: this.normalizeResolvedId(resolved, specifier, importerId) };
1670
- } finally {
1671
- added.forEach((ext) => delete extensions[ext]);
1786
+ return { resolvedId: this.normalizeResolvedId(resolved, specifier, importerId, kind) };
1787
+ } catch (error) {
1788
+ throw new Error([
1789
+ `[wyw-in-js] Native resolver failed during eval.`,
1790
+ ``,
1791
+ `importer: ${importerId}`,
1792
+ `source: ${specifier}`,
1793
+ ``,
1794
+ `error: ${error instanceof Error ? error.message : String(error)}`
1795
+ ].join("\n"));
1672
1796
  }
1673
1797
  }
1674
- maybeWarnNodeFallback({ importerId, specifier, resolvedId, kind }) {
1798
+ maybeWarnNativeFallback({ importerId, specifier, resolvedId, kind }) {
1675
1799
  const evalOptions = getEvalOptions(this.services);
1676
1800
  const { root } = this.services.options;
1677
1801
  const keyInfo = toImportKey({
@@ -1690,7 +1814,7 @@ export class EvalBroker {
1690
1814
  }
1691
1815
  if (policy === "error") {
1692
1816
  throw new Error([
1693
- `[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`,
1817
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
1694
1818
  ``,
1695
1819
  `importer: ${importerId}`,
1696
1820
  `source: ${specifier}`,
@@ -1704,7 +1828,7 @@ export class EvalBroker {
1704
1828
  if (policy === "warn" && !warnedUnknownImports.has(keyInfo.key)) {
1705
1829
  warnedUnknownImports.add(keyInfo.key);
1706
1830
  const warningMessage = [
1707
- `[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`,
1831
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
1708
1832
  ``,
1709
1833
  `importer: ${importerId}`,
1710
1834
  `source: ${specifier}`,
@@ -1759,6 +1883,7 @@ export class EvalBroker {
1759
1883
  ts: performance.now()
1760
1884
  });
1761
1885
  }
1886
+ this.recordEvalFileDebugLine(payload, prepared, shouldShipCode);
1762
1887
  await this.sendLoadResult(id, {
1763
1888
  id: payload.id,
1764
1889
  code: shouldShipCode ? prepared.code : "",
@@ -1774,6 +1899,14 @@ export class EvalBroker {
1774
1899
  only: merged
1775
1900
  });
1776
1901
  }
1902
+ // Session link graph tracks every module that's been admitted into
1903
+ // the current runner's VM. mergeKnownDependencyOnly uses this to
1904
+ // narrow its consumer-set to entrypoints actually linking against
1905
+ // the same module instance.
1906
+ this.sessionLinkGraph.add(payload.id);
1907
+ if (payload.importerId) {
1908
+ this.sessionLinkGraph.add(payload.importerId);
1909
+ }
1777
1910
  }
1778
1911
  async loadModule({ id, importerId, request }) {
1779
1912
  const actionEntrypoint = importerId ?? id;
@@ -2092,6 +2225,14 @@ export class EvalBroker {
2092
2225
  }
2093
2226
  let mergedOnly = storedOnly;
2094
2227
  for (const cachedEntrypoint of this.services.cache.entrypoints.values()) {
2228
+ // Scope the union to entrypoints that are part of the CURRENT
2229
+ // session's link graph. Cached entrypoints from prior transforms
2230
+ // already evaluated against their own VMs; their imports must not
2231
+ // widen this load. Empty session graph (initial load) falls back
2232
+ // to project-wide for safety.
2233
+ if (this.sessionLinkGraph.size > 0 && !this.sessionLinkGraph.has(cachedEntrypoint.name)) {
2234
+ continue;
2235
+ }
2095
2236
  const { dependencies } = cachedEntrypoint;
2096
2237
  if (!dependencies) {
2097
2238
  continue;