@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
@@ -0,0 +1,157 @@
1
+ export const unknownProcessorStaticValue = Symbol("unknownProcessorStaticValue");
2
+ export const createProcessorStaticContext = (processor) => {
3
+ const processorWithInternals = processor;
4
+ return {
5
+ addDependency: () => {},
6
+ debug: () => {},
7
+ fileContext: processorWithInternals.context ?? {},
8
+ metadata: {
9
+ className: processor.className,
10
+ displayName: processor.displayName,
11
+ isReferenced: processor.isReferenced,
12
+ location: processor.location,
13
+ slug: processor.slug,
14
+ tagSource: processor.tagSource
15
+ },
16
+ options: processorWithInternals.options ?? {},
17
+ unresolved: (reason, details) => ({
18
+ ...details ? { details } : {},
19
+ kind: "unresolved",
20
+ reason
21
+ })
22
+ };
23
+ };
24
+ export const isProcessorStaticValue = (value) => {
25
+ if (typeof value !== "object" || value === null || !("kind" in value)) {
26
+ return false;
27
+ }
28
+ const candidate = value;
29
+ switch (candidate.kind) {
30
+ case "class-name": return typeof candidate.className === "string";
31
+ case "opaque-component": return candidate.className === undefined || typeof candidate.className === "string";
32
+ case "runtime-callback":
33
+ case "serializable": return true;
34
+ case "selector-chain": return typeof candidate.className === "string" && Array.isArray(candidate.selectors) && candidate.selectors.every((selector) => typeof selector === "string");
35
+ case "unresolved": return typeof candidate.reason === "string";
36
+ default: return false;
37
+ }
38
+ };
39
+ export const getProcessorStaticValue = (processor) => {
40
+ if (!processor.getStaticValue) {
41
+ return null;
42
+ }
43
+ try {
44
+ const value = processor.getStaticValue(createProcessorStaticContext(processor));
45
+ return isProcessorStaticValue(value) ? value : null;
46
+ } catch {
47
+ return null;
48
+ }
49
+ };
50
+ export const processorStaticValueToRuntimeValue = (value) => {
51
+ switch (value.kind) {
52
+ case "class-name": return value.value === undefined ? value.className : value.value;
53
+ case "opaque-component":
54
+ case "runtime-callback": return value.value === undefined ? unknownProcessorStaticValue : value.value;
55
+ case "selector-chain":
56
+ case "serializable": return value.value;
57
+ case "unresolved": return unknownProcessorStaticValue;
58
+ default: return unknownProcessorStaticValue;
59
+ }
60
+ };
61
+ export const resolveProcessorStaticRuntimeValue = (processor) => {
62
+ const staticValue = getProcessorStaticValue(processor);
63
+ return staticValue ? processorStaticValueToRuntimeValue(staticValue) : unknownProcessorStaticValue;
64
+ };
65
+ export const resolveProcessorStaticClassName = (processor) => {
66
+ const staticValue = getProcessorStaticValue(processor);
67
+ if (staticValue?.kind !== "class-name") {
68
+ return null;
69
+ }
70
+ const runtimeValue = processorStaticValueToRuntimeValue(staticValue);
71
+ return typeof runtimeValue === "string" ? runtimeValue : staticValue.className;
72
+ };
73
+ export const processorLiteralValue = (expression) => {
74
+ const expressionWithValue = expression;
75
+ if (expression.type === "StringLiteral" || expression.type === "NumericLiteral" || expression.type === "BooleanLiteral" || expression.type === "Literal") {
76
+ return expressionWithValue.value;
77
+ }
78
+ if (expression.type === "NullLiteral") {
79
+ return null;
80
+ }
81
+ return unknownProcessorStaticValue;
82
+ };
83
+ export const processorPropertyKeyName = (key) => {
84
+ if (key.type === "Identifier") {
85
+ return key.name;
86
+ }
87
+ const value = processorLiteralValue(key);
88
+ return typeof value === "string" ? value : null;
89
+ };
90
+ export const processorObjectPropertyValue = (expression, name) => {
91
+ if (expression.type !== "ObjectExpression") {
92
+ return null;
93
+ }
94
+ const { properties } = expression;
95
+ if (!properties) {
96
+ return null;
97
+ }
98
+ for (const property of properties) {
99
+ if ((property.type === "ObjectProperty" || property.type === "Property") && property.key && processorPropertyKeyName(property.key) === name) {
100
+ return property.value ?? null;
101
+ }
102
+ }
103
+ return null;
104
+ };
105
+ export const processorExpressionToStaticValue = (expression, resolveHelperCall) => {
106
+ const literal = processorLiteralValue(expression);
107
+ if (literal !== unknownProcessorStaticValue) {
108
+ return literal;
109
+ }
110
+ if (expression.type === "ArrayExpression") {
111
+ const { elements } = expression;
112
+ if (!elements) {
113
+ return unknownProcessorStaticValue;
114
+ }
115
+ const result = [];
116
+ for (const element of elements) {
117
+ if (element === null) {
118
+ result.push(null);
119
+ } else {
120
+ const value = processorExpressionToStaticValue(element, resolveHelperCall);
121
+ if (value === unknownProcessorStaticValue) {
122
+ return unknownProcessorStaticValue;
123
+ }
124
+ result.push(value);
125
+ }
126
+ }
127
+ return result;
128
+ }
129
+ if (expression.type === "ObjectExpression") {
130
+ const metaExpression = processorObjectPropertyValue(expression, "__wyw_meta");
131
+ if (!metaExpression || metaExpression.type !== "ObjectExpression") {
132
+ return unknownProcessorStaticValue;
133
+ }
134
+ const classNameExpression = processorObjectPropertyValue(metaExpression, "className");
135
+ const className = classNameExpression ? processorLiteralValue(classNameExpression) : unknownProcessorStaticValue;
136
+ if (typeof className !== "string") {
137
+ return unknownProcessorStaticValue;
138
+ }
139
+ const extendsExpression = processorObjectPropertyValue(metaExpression, "extends");
140
+ const extended = extendsExpression ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall) : null;
141
+ if (extended === unknownProcessorStaticValue) {
142
+ return unknownProcessorStaticValue;
143
+ }
144
+ return { __wyw_meta: {
145
+ className,
146
+ extends: extended
147
+ } };
148
+ }
149
+ if (expression.type === "CallExpression") {
150
+ const call = expression;
151
+ if (call.arguments?.length === 0 && call.callee?.type === "Identifier") {
152
+ return resolveHelperCall(call.callee.name);
153
+ }
154
+ }
155
+ return unknownProcessorStaticValue;
156
+ };
157
+ //# sourceMappingURL=processorStaticSemantics.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","names":[],"sources":["../../src/utils/processorStaticSemantics.ts"],"version":3,"sourcesContent":["import type {\n BaseProcessor,\n Expression as ProcessorExpression,\n ProcessorStaticContext,\n ProcessorStaticValue,\n} from '@wyw-in-js/processor-utils';\n\nexport const unknownProcessorStaticValue = Symbol(\n 'unknownProcessorStaticValue'\n);\n\nexport type UnknownProcessorStaticValue = typeof unknownProcessorStaticValue;\n\ntype ProcessorWithStaticInternals = BaseProcessor & {\n context?: ProcessorStaticContext['fileContext'];\n options?: ProcessorStaticContext['options'];\n};\n\nexport const createProcessorStaticContext = (\n processor: BaseProcessor\n): ProcessorStaticContext => {\n const processorWithInternals = processor as ProcessorWithStaticInternals;\n\n return {\n addDependency: () => {},\n debug: () => {},\n fileContext:\n processorWithInternals.context ??\n ({} as ProcessorStaticContext['fileContext']),\n metadata: {\n className: processor.className,\n displayName: processor.displayName,\n isReferenced: processor.isReferenced,\n location: processor.location,\n slug: processor.slug,\n tagSource: processor.tagSource,\n },\n options:\n processorWithInternals.options ??\n ({} as ProcessorStaticContext['options']),\n unresolved: (reason, details) => ({\n ...(details ? { details } : {}),\n kind: 'unresolved',\n reason,\n }),\n };\n};\n\nexport const isProcessorStaticValue = (\n value: unknown\n): value is ProcessorStaticValue => {\n if (typeof value !== 'object' || value === null || !('kind' in value)) {\n return false;\n }\n\n const candidate = value as ProcessorStaticValue;\n switch (candidate.kind) {\n case 'class-name':\n return typeof candidate.className === 'string';\n case 'opaque-component':\n return (\n candidate.className === undefined ||\n typeof candidate.className === 'string'\n );\n case 'runtime-callback':\n case 'serializable':\n return true;\n case 'selector-chain':\n return (\n typeof candidate.className === 'string' &&\n Array.isArray(candidate.selectors) &&\n candidate.selectors.every((selector) => typeof selector === 'string')\n );\n case 'unresolved':\n return typeof candidate.reason === 'string';\n default:\n return false;\n }\n};\n\nexport const getProcessorStaticValue = (\n processor: BaseProcessor\n): ProcessorStaticValue | null => {\n if (!processor.getStaticValue) {\n return null;\n }\n\n try {\n const value = processor.getStaticValue(\n createProcessorStaticContext(processor)\n );\n return isProcessorStaticValue(value) ? value : null;\n } catch {\n return null;\n }\n};\n\nexport const processorStaticValueToRuntimeValue = (\n value: ProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n switch (value.kind) {\n case 'class-name':\n return value.value === undefined ? value.className : value.value;\n case 'opaque-component':\n case 'runtime-callback':\n return value.value === undefined\n ? unknownProcessorStaticValue\n : value.value;\n case 'selector-chain':\n case 'serializable':\n return value.value;\n case 'unresolved':\n return unknownProcessorStaticValue;\n default:\n return unknownProcessorStaticValue;\n }\n};\n\nexport const resolveProcessorStaticRuntimeValue = (\n processor: BaseProcessor\n): unknown | UnknownProcessorStaticValue => {\n const staticValue = getProcessorStaticValue(processor);\n return staticValue\n ? processorStaticValueToRuntimeValue(staticValue)\n : unknownProcessorStaticValue;\n};\n\nexport const resolveProcessorStaticClassName = (\n processor: BaseProcessor\n): string | null => {\n const staticValue = getProcessorStaticValue(processor);\n if (staticValue?.kind !== 'class-name') {\n return null;\n }\n\n const runtimeValue = processorStaticValueToRuntimeValue(staticValue);\n return typeof runtimeValue === 'string'\n ? runtimeValue\n : staticValue.className;\n};\n\nexport const processorLiteralValue = (\n expression: ProcessorExpression\n): unknown | UnknownProcessorStaticValue => {\n const expressionWithValue = expression as ProcessorExpression & {\n value?: unknown;\n };\n\n if (\n expression.type === 'StringLiteral' ||\n expression.type === 'NumericLiteral' ||\n expression.type === 'BooleanLiteral' ||\n expression.type === 'Literal'\n ) {\n return expressionWithValue.value;\n }\n\n if (expression.type === 'NullLiteral') {\n return null;\n }\n\n return unknownProcessorStaticValue;\n};\n\nexport const processorPropertyKeyName = (\n key: ProcessorExpression\n): string | null => {\n if (key.type === 'Identifier') {\n return (key as ProcessorExpression & { name: string }).name;\n }\n\n const value = processorLiteralValue(key);\n return typeof value === 'string' ? value : null;\n};\n\nexport const processorObjectPropertyValue = (\n expression: ProcessorExpression,\n name: string\n): ProcessorExpression | null => {\n if (expression.type !== 'ObjectExpression') {\n return null;\n }\n\n const { properties } = expression as ProcessorExpression & {\n properties?: Array<\n ProcessorExpression & {\n key?: ProcessorExpression;\n type: string;\n value?: ProcessorExpression;\n }\n >;\n };\n if (!properties) {\n return null;\n }\n\n for (const property of properties) {\n if (\n (property.type === 'ObjectProperty' || property.type === 'Property') &&\n property.key &&\n processorPropertyKeyName(property.key) === name\n ) {\n return property.value ?? null;\n }\n }\n\n return null;\n};\n\nexport const processorExpressionToStaticValue = (\n expression: ProcessorExpression,\n resolveHelperCall: (name: string) => unknown | UnknownProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n const literal = processorLiteralValue(expression);\n if (literal !== unknownProcessorStaticValue) {\n return literal;\n }\n\n if (expression.type === 'ArrayExpression') {\n const { elements } = expression as ProcessorExpression & {\n elements?: Array<ProcessorExpression | null>;\n };\n if (!elements) {\n return unknownProcessorStaticValue;\n }\n\n const result: unknown[] = [];\n for (const element of elements) {\n if (element === null) {\n result.push(null);\n } else {\n const value = processorExpressionToStaticValue(\n element,\n resolveHelperCall\n );\n if (value === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n result.push(value);\n }\n }\n\n return result;\n }\n\n if (expression.type === 'ObjectExpression') {\n const metaExpression = processorObjectPropertyValue(\n expression,\n '__wyw_meta'\n );\n if (!metaExpression || metaExpression.type !== 'ObjectExpression') {\n return unknownProcessorStaticValue;\n }\n\n const classNameExpression = processorObjectPropertyValue(\n metaExpression,\n 'className'\n );\n const className = classNameExpression\n ? processorLiteralValue(classNameExpression)\n : unknownProcessorStaticValue;\n if (typeof className !== 'string') {\n return unknownProcessorStaticValue;\n }\n\n const extendsExpression = processorObjectPropertyValue(\n metaExpression,\n 'extends'\n );\n const extended = extendsExpression\n ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall)\n : null;\n if (extended === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n return {\n __wyw_meta: {\n className,\n extends: extended,\n },\n };\n }\n\n if (expression.type === 'CallExpression') {\n const call = expression as ProcessorExpression & {\n arguments?: ProcessorExpression[];\n callee?: ProcessorExpression;\n };\n if (call.arguments?.length === 0 && call.callee?.type === 'Identifier') {\n return resolveHelperCall(\n (call.callee as ProcessorExpression & { name: string }).name\n );\n }\n }\n\n return unknownProcessorStaticValue;\n};\n"],"file":"processorStaticSemantics.js"}
@@ -53,7 +53,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
53
53
  parsed = JSON.parse(stdout);
54
54
  } catch {
55
55
  throw new Error([
56
- "[wyw-in-js] Failed to parse Node resolver fallback output.",
56
+ "[wyw-in-js] Failed to parse custom module resolver output.",
57
57
  `stdout: ${stdout}`,
58
58
  result.stderr ? `stderr: ${result.stderr.trim()}` : ""
59
59
  ].filter(Boolean).join("\n"));
@@ -66,7 +66,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
66
66
  }
67
67
  if (result.status !== 0 || !parsed?.resolved) {
68
68
  throw new Error([
69
- "[wyw-in-js] Node resolver fallback failed.",
69
+ "[wyw-in-js] Custom module resolver fallback failed.",
70
70
  `status: ${result.status ?? "null"}`,
71
71
  result.stderr ? `stderr: ${result.stderr.trim()}` : ""
72
72
  ].filter(Boolean).join("\n"));
@@ -82,7 +82,7 @@ export const resolveFilenameWithConditions = (moduleImpl, id, parent, conditions
82
82
  // Bun crashes on macOS/Silicon in this exact path:
83
83
  // Module._resolveFilename(specifier, parent, false, { conditions })
84
84
  // We reproduced it both with a tiny standalone script and through the
85
- // `EvalBroker > passes conditionNames to node fallback resolution` test,
85
+ // `EvalBroker > passes conditionNames to native fallback resolution` test,
86
86
  // including on Bun 1.3.13. Keep this fallback narrow: only conditioned
87
87
  // resolution under Bun goes through a short-lived Node subprocess.
88
88
  //
@@ -1 +1 @@
1
- {"mappings":"AAAA,SAAS,iBAAiB;AAC1B,OAAO,kBAAkB;AAsBzB,MAAM,kCAAkC,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BlD,MAAM,qBAAqB,QAAQ,SAAS,SAAS,MAAM;AAE3D,MAAM,wBACJ,aACA;AAEF,MAAM,0BACJ,IACA,QACA,eACW;CACX,MAAM,aAAa,QAAQ,IAAI,mBAAmB;CAClD,MAAM,SAAS,UACb,YACA,CAAC,MAAM,gCAAgC,EACvC;EACE,UAAU;EACV,OAAO,KAAK,UAAU;GACpB,YAAY,CAAC,GAAG,WAAW;GAC3B;GACA;GACD,CAAC;EACF,WAAW,OAAO;EACnB,CACF;AAED,KAAI,OAAO,OAAO;AAChB,QAAM,OAAO;;CAGf,IAAI,SAA8C;CAClD,MAAM,SAAS,OAAO,OAAO,MAAM;AACnC,KAAI,QAAQ;AACV,MAAI;AACF,YAAS,KAAK,MAAM,OAAO;UACrB;AACN,SAAM,IAAI,MACR;IACE;IACA,WAAW;IACX,OAAO,SAAS,WAAW,OAAO,OAAO,MAAM,KAAK;IACrD,CACE,OAAO,QAAQ,CACf,KAAK,KAAK,CACd;;;AAIL,KAAI,QAAQ,OAAO;EACjB,MAAM,QAAQ,IAAI,MAAM,OAAO,MAAM,QAAQ;AAC7C,QAAM,OAAO,OAAO,MAAM;AAC1B,QAAM;;AAGR,KAAI,OAAO,WAAW,KAAK,CAAC,QAAQ,UAAU;AAC5C,QAAM,IAAI,MACR;GACE;GACA,WAAW,OAAO,UAAU;GAC5B,OAAO,SAAS,WAAW,OAAO,OAAO,MAAM,KAAK;GACrD,CACE,OAAO,QAAQ,CACf,KAAK,KAAK,CACd;;AAGH,QAAO,OAAO;;AAGhB,OAAO,MAAM,iCACX,YACA,IACA,QACA,eACW;CACX,MAAM,iBAAiB,aAAa,EAAE,YAAY,GAAG;CACrD,MAAM,qBACJ,WAAW,qBAAqB;AAElC,KAAI,CAAC,cAAc,CAAC,cAAc,IAAI,CAAC,oBAAoB;AACzD,SAAO,WAAW,iBAAiB,IAAI,QAAQ,OAAO,eAAe;;;;;;;;;;;;;;;;;AAkBvE,QAAO,uBAAuB,IAAI,QAAQ,WAAW","names":[],"sources":["../../src/utils/resolveWithConditions.ts"],"version":3,"sourcesContent":["import { spawnSync } from 'child_process';\nimport NativeModule from 'module';\n\ntype ResolveFilenameParent = {\n filename: string;\n id: string;\n paths: string[];\n};\n\ntype ResolveFilenameModuleImplementation = {\n _resolveFilename: (\n id: string,\n options: ResolveFilenameParent,\n isMain?: boolean,\n resolveOptions?: { conditions?: Set<string> }\n ) => string;\n};\n\ntype NodeConditionalResolveResult = {\n error?: { code?: string; message: string };\n resolved?: string;\n};\n\nconst NODE_CONDITIONAL_RESOLVE_SCRIPT = String.raw`\nconst fs = require('node:fs');\nconst Module = require('node:module');\n\nconst input = JSON.parse(fs.readFileSync(0, 'utf8'));\n\ntry {\n const resolved = Module._resolveFilename(\n input.id,\n input.parent,\n false,\n input.conditions ? { conditions: new Set(input.conditions) } : undefined\n );\n fs.writeFileSync(1, JSON.stringify({ resolved }));\n} catch (error) {\n fs.writeFileSync(\n 1,\n JSON.stringify({\n error: {\n code:\n error && typeof error === 'object' && 'code' in error\n ? error.code\n : undefined,\n message: error instanceof Error ? error.message : String(error),\n },\n })\n );\n process.exitCode = 1;\n}\n`;\n\nconst isBunRuntime = () => process.execPath.includes('bun');\n\nconst nativeResolveFilename = (\n NativeModule as unknown as ResolveFilenameModuleImplementation\n)._resolveFilename;\n\nconst resolveWithNodeProcess = (\n id: string,\n parent: ResolveFilenameParent,\n conditions: Set<string>\n): string => {\n const nodeBinary = process.env.WYW_NODE_BINARY || 'node';\n const result = spawnSync(\n nodeBinary,\n ['-e', NODE_CONDITIONAL_RESOLVE_SCRIPT],\n {\n encoding: 'utf8',\n input: JSON.stringify({\n conditions: [...conditions],\n id,\n parent,\n }),\n maxBuffer: 1024 * 1024,\n }\n );\n\n if (result.error) {\n throw result.error;\n }\n\n let parsed: NodeConditionalResolveResult | null = null;\n const stdout = result.stdout.trim();\n if (stdout) {\n try {\n parsed = JSON.parse(stdout) as NodeConditionalResolveResult;\n } catch {\n throw new Error(\n [\n '[wyw-in-js] Failed to parse Node resolver fallback output.',\n `stdout: ${stdout}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n }\n\n if (parsed?.error) {\n const error = new Error(parsed.error.message) as NodeJS.ErrnoException;\n error.code = parsed.error.code;\n throw error;\n }\n\n if (result.status !== 0 || !parsed?.resolved) {\n throw new Error(\n [\n '[wyw-in-js] Node resolver fallback failed.',\n `status: ${result.status ?? 'null'}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n\n return parsed.resolved;\n};\n\nexport const resolveFilenameWithConditions = (\n moduleImpl: ResolveFilenameModuleImplementation,\n id: string,\n parent: ResolveFilenameParent,\n conditions?: Set<string>\n): string => {\n const resolveOptions = conditions ? { conditions } : undefined;\n const usesNativeResolver =\n moduleImpl._resolveFilename === nativeResolveFilename;\n\n if (!conditions || !isBunRuntime() || !usesNativeResolver) {\n return moduleImpl._resolveFilename(id, parent, false, resolveOptions);\n }\n\n // Bun crashes on macOS/Silicon in this exact path:\n // Module._resolveFilename(specifier, parent, false, { conditions })\n // We reproduced it both with a tiny standalone script and through the\n // `EvalBroker > passes conditionNames to node fallback resolution` test,\n // including on Bun 1.3.13. Keep this fallback narrow: only conditioned\n // resolution under Bun goes through a short-lived Node subprocess.\n //\n // Cleanup criteria:\n // 1. Bun passes the minimal local `_resolveFilename(..., { conditions })`\n // repro on macOS without segfaulting.\n // 2. The conditionNames runner path passes without this fallback.\n //\n // As of 2026-04-20 we did not find an exact open upstream Bun issue for this\n // `_resolveFilename(..., { conditions })` crash, so keep the comment factual\n // and the workaround self-contained.\n return resolveWithNodeProcess(id, parent, conditions);\n};\n"],"file":"resolveWithConditions.js"}
1
+ {"mappings":"AAAA,SAAS,iBAAiB;AAC1B,OAAO,kBAAkB;AAsBzB,MAAM,kCAAkC,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BlD,MAAM,qBAAqB,QAAQ,SAAS,SAAS,MAAM;AAE3D,MAAM,wBACJ,aACA;AAEF,MAAM,0BACJ,IACA,QACA,eACW;CACX,MAAM,aAAa,QAAQ,IAAI,mBAAmB;CAClD,MAAM,SAAS,UACb,YACA,CAAC,MAAM,gCAAgC,EACvC;EACE,UAAU;EACV,OAAO,KAAK,UAAU;GACpB,YAAY,CAAC,GAAG,WAAW;GAC3B;GACA;GACD,CAAC;EACF,WAAW,OAAO;EACnB,CACF;AAED,KAAI,OAAO,OAAO;AAChB,QAAM,OAAO;;CAGf,IAAI,SAA8C;CAClD,MAAM,SAAS,OAAO,OAAO,MAAM;AACnC,KAAI,QAAQ;AACV,MAAI;AACF,YAAS,KAAK,MAAM,OAAO;UACrB;AACN,SAAM,IAAI,MACR;IACE;IACA,WAAW;IACX,OAAO,SAAS,WAAW,OAAO,OAAO,MAAM,KAAK;IACrD,CACE,OAAO,QAAQ,CACf,KAAK,KAAK,CACd;;;AAIL,KAAI,QAAQ,OAAO;EACjB,MAAM,QAAQ,IAAI,MAAM,OAAO,MAAM,QAAQ;AAC7C,QAAM,OAAO,OAAO,MAAM;AAC1B,QAAM;;AAGR,KAAI,OAAO,WAAW,KAAK,CAAC,QAAQ,UAAU;AAC5C,QAAM,IAAI,MACR;GACE;GACA,WAAW,OAAO,UAAU;GAC5B,OAAO,SAAS,WAAW,OAAO,OAAO,MAAM,KAAK;GACrD,CACE,OAAO,QAAQ,CACf,KAAK,KAAK,CACd;;AAGH,QAAO,OAAO;;AAGhB,OAAO,MAAM,iCACX,YACA,IACA,QACA,eACW;CACX,MAAM,iBAAiB,aAAa,EAAE,YAAY,GAAG;CACrD,MAAM,qBACJ,WAAW,qBAAqB;AAElC,KAAI,CAAC,cAAc,CAAC,cAAc,IAAI,CAAC,oBAAoB;AACzD,SAAO,WAAW,iBAAiB,IAAI,QAAQ,OAAO,eAAe;;;;;;;;;;;;;;;;;AAkBvE,QAAO,uBAAuB,IAAI,QAAQ,WAAW","names":[],"sources":["../../src/utils/resolveWithConditions.ts"],"version":3,"sourcesContent":["import { spawnSync } from 'child_process';\nimport NativeModule from 'module';\n\ntype ResolveFilenameParent = {\n filename: string;\n id: string;\n paths: string[];\n};\n\ntype ResolveFilenameModuleImplementation = {\n _resolveFilename: (\n id: string,\n options: ResolveFilenameParent,\n isMain?: boolean,\n resolveOptions?: { conditions?: Set<string> }\n ) => string;\n};\n\ntype NodeConditionalResolveResult = {\n error?: { code?: string; message: string };\n resolved?: string;\n};\n\nconst NODE_CONDITIONAL_RESOLVE_SCRIPT = String.raw`\nconst fs = require('node:fs');\nconst Module = require('node:module');\n\nconst input = JSON.parse(fs.readFileSync(0, 'utf8'));\n\ntry {\n const resolved = Module._resolveFilename(\n input.id,\n input.parent,\n false,\n input.conditions ? { conditions: new Set(input.conditions) } : undefined\n );\n fs.writeFileSync(1, JSON.stringify({ resolved }));\n} catch (error) {\n fs.writeFileSync(\n 1,\n JSON.stringify({\n error: {\n code:\n error && typeof error === 'object' && 'code' in error\n ? error.code\n : undefined,\n message: error instanceof Error ? error.message : String(error),\n },\n })\n );\n process.exitCode = 1;\n}\n`;\n\nconst isBunRuntime = () => process.execPath.includes('bun');\n\nconst nativeResolveFilename = (\n NativeModule as unknown as ResolveFilenameModuleImplementation\n)._resolveFilename;\n\nconst resolveWithNodeProcess = (\n id: string,\n parent: ResolveFilenameParent,\n conditions: Set<string>\n): string => {\n const nodeBinary = process.env.WYW_NODE_BINARY || 'node';\n const result = spawnSync(\n nodeBinary,\n ['-e', NODE_CONDITIONAL_RESOLVE_SCRIPT],\n {\n encoding: 'utf8',\n input: JSON.stringify({\n conditions: [...conditions],\n id,\n parent,\n }),\n maxBuffer: 1024 * 1024,\n }\n );\n\n if (result.error) {\n throw result.error;\n }\n\n let parsed: NodeConditionalResolveResult | null = null;\n const stdout = result.stdout.trim();\n if (stdout) {\n try {\n parsed = JSON.parse(stdout) as NodeConditionalResolveResult;\n } catch {\n throw new Error(\n [\n '[wyw-in-js] Failed to parse custom module resolver output.',\n `stdout: ${stdout}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n }\n\n if (parsed?.error) {\n const error = new Error(parsed.error.message) as NodeJS.ErrnoException;\n error.code = parsed.error.code;\n throw error;\n }\n\n if (result.status !== 0 || !parsed?.resolved) {\n throw new Error(\n [\n '[wyw-in-js] Custom module resolver fallback failed.',\n `status: ${result.status ?? 'null'}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n\n return parsed.resolved;\n};\n\nexport const resolveFilenameWithConditions = (\n moduleImpl: ResolveFilenameModuleImplementation,\n id: string,\n parent: ResolveFilenameParent,\n conditions?: Set<string>\n): string => {\n const resolveOptions = conditions ? { conditions } : undefined;\n const usesNativeResolver =\n moduleImpl._resolveFilename === nativeResolveFilename;\n\n if (!conditions || !isBunRuntime() || !usesNativeResolver) {\n return moduleImpl._resolveFilename(id, parent, false, resolveOptions);\n }\n\n // Bun crashes on macOS/Silicon in this exact path:\n // Module._resolveFilename(specifier, parent, false, { conditions })\n // We reproduced it both with a tiny standalone script and through the\n // `EvalBroker > passes conditionNames to native fallback resolution` test,\n // including on Bun 1.3.13. Keep this fallback narrow: only conditioned\n // resolution under Bun goes through a short-lived Node subprocess.\n //\n // Cleanup criteria:\n // 1. Bun passes the minimal local `_resolveFilename(..., { conditions })`\n // repro on macOS without segfaulting.\n // 2. The conditionNames runner path passes without this fallback.\n //\n // As of 2026-04-20 we did not find an exact open upstream Bun issue for this\n // `_resolveFilename(..., { conditions })` crash, so keep the comment factual\n // and the workaround self-contained.\n return resolveWithNodeProcess(id, parent, conditions);\n};\n"],"file":"resolveWithConditions.js"}
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@wyw-in-js/transform",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@jridgewell/remapping": "^2.3.5",
7
- "@wyw-in-js/processor-utils": "2.0.0-alpha.0",
8
- "@wyw-in-js/shared": "2.0.0-alpha.0",
7
+ "@wyw-in-js/processor-utils": "2.0.0-alpha.1",
8
+ "@wyw-in-js/shared": "2.0.0-alpha.1",
9
9
  "cosmiconfig": "^8.0.0",
10
10
  "happy-dom": "^20.1.0",
11
11
  "minimatch": "^9.0.5",
12
12
  "oxc-parser": "0.127.0",
13
+ "oxc-resolver": "11.19.1",
13
14
  "oxc-transform": "0.127.0",
14
15
  "source-map": "^0.7.4",
15
16
  "stylis": "^4.3.0",
package/types/cache.js CHANGED
@@ -298,7 +298,15 @@ export class TransformCacheCollection {
298
298
  return true;
299
299
  }
300
300
  // A cached file without a cached entrypoint was invalidated earlier.
301
+ // If the caller forced a content check and the content hash is stable,
302
+ // the missing entrypoint is only cache churn and must not invalidate
303
+ // output-dependent parents.
301
304
  if (!cachedEntrypoint && nestedDependencies.size === 0) {
305
+ if (forceContentCheck &&
306
+ this.contentHashes.get(dependencyFilename)?.fs !== undefined) {
307
+ dependencyChangeMemo.set(dependencyFilename, false);
308
+ return false;
309
+ }
302
310
  dependencyChangeMemo.set(dependencyFilename, true);
303
311
  return true;
304
312
  }
@@ -4,6 +4,13 @@ import path from 'path';
4
4
  import { EventEmitter, isOnActionStartArgs } from '../utils/EventEmitter';
5
5
  const workingDir = process.cwd();
6
6
  function replacer(_key, value) {
7
+ if (value instanceof Error) {
8
+ return {
9
+ message: value.message,
10
+ name: value.name,
11
+ stack: value.stack,
12
+ };
13
+ }
7
14
  if (typeof value === 'string' && path.isAbsolute(value)) {
8
15
  return path.relative(workingDir, value);
9
16
  }
@@ -41,6 +48,29 @@ function printTimings(timings, startedAt, sourceRoot) {
41
48
  const writeJSONl = (stream, data) => {
42
49
  stream.write(`${JSON.stringify(data, replacer)}\n`);
43
50
  };
51
+ const isPerfFinishEvent = (event) => {
52
+ if (!event || typeof event !== 'object') {
53
+ return false;
54
+ }
55
+ return ('type' in event &&
56
+ event.type === 'perf-span' &&
57
+ 'method' in event &&
58
+ typeof event.method === 'string' &&
59
+ 'spanId' in event &&
60
+ typeof event.spanId === 'number' &&
61
+ 'startedAt' in event &&
62
+ typeof event.startedAt === 'number' &&
63
+ 'finishedAt' in event &&
64
+ typeof event.finishedAt === 'number' &&
65
+ 'durationMs' in event &&
66
+ typeof event.durationMs === 'number');
67
+ };
68
+ const isPerfStartEvent = (event) => {
69
+ if (!event || typeof event !== 'object') {
70
+ return false;
71
+ }
72
+ return 'type' in event && event.type === 'perf-span-start';
73
+ };
44
74
  export const createFileReporter = (options = false) => {
45
75
  if (!options || !options.dir) {
46
76
  return {
@@ -60,6 +90,8 @@ export const createFileReporter = (options = false) => {
60
90
  const dependenciesStream = createWriteStream(path.join(options.dir, 'dependencies.jsonl'));
61
91
  const entrypointStream = createWriteStream(path.join(options.dir, 'entrypoints.jsonl'));
62
92
  const staticResolveStream = createWriteStream(path.join(options.dir, 'static-resolve.jsonl'));
93
+ const perfSpanStream = createWriteStream(path.join(options.dir, 'perf-spans.jsonl'));
94
+ const evalFilesStream = createWriteStream(path.join(options.dir, 'eval-files.jsonl'));
63
95
  const startedAt = performance.now();
64
96
  const timings = new Map();
65
97
  const addTiming = (label, key, value) => {
@@ -85,13 +117,24 @@ export const createFileReporter = (options = false) => {
85
117
  if (meta.type === 'staticResolve') {
86
118
  writeJSONl(staticResolveStream, meta);
87
119
  }
120
+ if (meta.type === 'eval-file') {
121
+ writeJSONl(evalFilesStream, meta);
122
+ }
88
123
  };
89
124
  const startTimes = new Map();
90
- const onEvent = (meta, type) => {
125
+ const onEvent = (meta, type, event) => {
91
126
  if (type === 'single') {
92
127
  processSingleEvent(meta);
93
128
  return;
94
129
  }
130
+ if (type === 'finish' && isPerfFinishEvent(event)) {
131
+ addTiming('method', event.method, event.durationMs);
132
+ writeJSONl(perfSpanStream, event);
133
+ return;
134
+ }
135
+ if (type === 'start' && isPerfStartEvent(event)) {
136
+ return;
137
+ }
95
138
  if (type === 'start') {
96
139
  Object.entries(meta).forEach(([label, value]) => {
97
140
  startTimes.set(`${label}\0${value}`, performance.now());
@@ -145,6 +188,8 @@ export const createFileReporter = (options = false) => {
145
188
  dependenciesStream.end();
146
189
  entrypointStream.end();
147
190
  staticResolveStream.end();
191
+ perfSpanStream.end();
192
+ evalFilesStream.end();
148
193
  timings.clear();
149
194
  },
150
195
  };
@@ -22,6 +22,7 @@ export declare class EvalBroker {
22
22
  private readonly loadInFlight;
23
23
  private readonly importsByModule;
24
24
  private readonly onlyByModule;
25
+ private readonly sessionLinkGraph;
25
26
  private readonly runtimeDependenciesByModule;
26
27
  private readonly emittedDependencies;
27
28
  private readonly lastSentLoadByModule;
@@ -29,6 +30,7 @@ export declare class EvalBroker {
29
30
  private evalFlushScheduled;
30
31
  private stableInitHashCache;
31
32
  private evalSeq;
33
+ private evalFileDebugLines;
32
34
  private happyDomDisabled;
33
35
  private happyDomDisableWarned;
34
36
  private activeResolveRootId;
@@ -41,6 +43,8 @@ export declare class EvalBroker {
41
43
  private scheduleEvalFlush;
42
44
  private runEvalBatch;
43
45
  private runOneEntrypoint;
46
+ private recordEvalFileDebugLine;
47
+ private flushEvalFileDebugLines;
44
48
  private resetPerEntrypointState;
45
49
  private applyModuleExports;
46
50
  dispose(): void;
@@ -69,8 +73,8 @@ export declare class EvalBroker {
69
73
  private trackImporterDependency;
70
74
  private collectEntrypointDependencies;
71
75
  private applyImportOverrides;
72
- private resolveWithNodeFallback;
73
- private maybeWarnNodeFallback;
76
+ private resolveWithNativeFallback;
77
+ private maybeWarnNativeFallback;
74
78
  private handleLoad;
75
79
  private loadModule;
76
80
  private loadModuleImpl;