@wyw-in-js/transform 1.1.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 (801) hide show
  1. package/esm/cache.js +433 -289
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js +171 -134
  4. package/esm/debug/fileReporter.js.map +1 -1
  5. package/esm/eval/broker.js +2275 -0
  6. package/esm/eval/broker.js.map +1 -0
  7. package/esm/eval/lru.js +36 -0
  8. package/esm/eval/lru.js.map +1 -0
  9. package/esm/eval/prepareModuleOnDemand.js +21 -0
  10. package/esm/eval/prepareModuleOnDemand.js.map +1 -0
  11. package/esm/eval/protocol.js +2 -0
  12. package/esm/eval/protocol.js.map +1 -0
  13. package/esm/eval/runner.js +1878 -0
  14. package/esm/eval/runner.js.map +1 -0
  15. package/esm/eval/serialize.js +333 -0
  16. package/esm/eval/serialize.js.map +1 -0
  17. package/esm/eval/writeQueue.js +81 -0
  18. package/esm/eval/writeQueue.js.map +1 -0
  19. package/esm/evaluators/index.js +11 -12
  20. package/esm/evaluators/index.js.map +1 -1
  21. package/esm/index.js +25 -29
  22. package/esm/index.js.map +1 -1
  23. package/esm/module.js +923 -520
  24. package/esm/module.js.map +1 -1
  25. package/esm/shaker.js +14 -80
  26. package/esm/shaker.js.map +1 -1
  27. package/esm/transform/BaseEntrypoint.js +162 -164
  28. package/esm/transform/BaseEntrypoint.js.map +1 -1
  29. package/esm/transform/Entrypoint.helpers.js +96 -253
  30. package/esm/transform/Entrypoint.helpers.js.map +1 -1
  31. package/esm/transform/Entrypoint.js +336 -270
  32. package/esm/transform/Entrypoint.js.map +1 -1
  33. package/esm/transform/Entrypoint.types.js +1 -1
  34. package/esm/transform/Entrypoint.types.js.map +1 -1
  35. package/esm/transform/EvaluatedEntrypoint.js +10 -4
  36. package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
  37. package/esm/transform/actions/AbortError.js +6 -6
  38. package/esm/transform/actions/AbortError.js.map +1 -1
  39. package/esm/transform/actions/BaseAction.js +140 -136
  40. package/esm/transform/actions/BaseAction.js.map +1 -1
  41. package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
  42. package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
  43. package/esm/transform/actions/actionRunner.js +63 -66
  44. package/esm/transform/actions/actionRunner.js.map +1 -1
  45. package/esm/transform/actions/types.js +1 -1
  46. package/esm/transform/actions/types.js.map +1 -1
  47. package/esm/transform/barrelManifest.types.js +2 -0
  48. package/esm/transform/barrelManifest.types.js.map +1 -0
  49. package/esm/transform/generators/baseProcessingHandlers.js +15 -17
  50. package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
  51. package/esm/transform/generators/collect.js +27 -55
  52. package/esm/transform/generators/collect.js.map +1 -1
  53. package/esm/transform/generators/createStylisPreprocessor.js +353 -321
  54. package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
  55. package/esm/transform/generators/evalFile.js +48 -47
  56. package/esm/transform/generators/evalFile.js.map +1 -1
  57. package/esm/transform/generators/extract.js +78 -90
  58. package/esm/transform/generators/extract.js.map +1 -1
  59. package/esm/transform/generators/getExports.js +57 -74
  60. package/esm/transform/generators/getExports.js.map +1 -1
  61. package/esm/transform/generators/index.js +11 -11
  62. package/esm/transform/generators/index.js.map +1 -1
  63. package/esm/transform/generators/processEntrypoint.js +93 -67
  64. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  65. package/esm/transform/generators/processImports.js +102 -67
  66. package/esm/transform/generators/processImports.js.map +1 -1
  67. package/esm/transform/generators/resolveImports.js +212 -197
  68. package/esm/transform/generators/resolveImports.js.map +1 -1
  69. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  70. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  71. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  72. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  73. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  74. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  75. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  76. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  77. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  78. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  79. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  80. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  81. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  82. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  83. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  84. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  85. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  86. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  87. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  88. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  89. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  90. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  91. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  92. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  93. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  94. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  95. package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
  96. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  97. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
  98. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  99. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  100. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  101. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  102. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  103. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  104. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  105. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  106. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  107. package/esm/transform/generators/resolveStaticOxcValues.js +2 -0
  108. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
  109. package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
  110. package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
  111. package/esm/transform/generators/transform.js +251 -248
  112. package/esm/transform/generators/transform.js.map +1 -1
  113. package/esm/transform/generators/workflow.js +87 -90
  114. package/esm/transform/generators/workflow.js.map +1 -1
  115. package/esm/transform/helpers/loadWywOptions.js +183 -74
  116. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  117. package/esm/transform/helpers/withDefaultServices.js +13 -22
  118. package/esm/transform/helpers/withDefaultServices.js.map +1 -1
  119. package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
  120. package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
  121. package/esm/transform/oxcBarrelManifest.js +349 -0
  122. package/esm/transform/oxcBarrelManifest.js.map +1 -0
  123. package/esm/transform/rootLog.js +3 -3
  124. package/esm/transform/rootLog.js.map +1 -1
  125. package/esm/transform/syntax.js +2 -0
  126. package/esm/transform/syntax.js.map +1 -0
  127. package/esm/transform/types.js +2 -2
  128. package/esm/transform/types.js.map +1 -1
  129. package/esm/transform.js +125 -147
  130. package/esm/transform.js.map +1 -1
  131. package/esm/types.js +4 -1
  132. package/esm/types.js.map +1 -1
  133. package/esm/utils/EventEmitter.js +79 -48
  134. package/esm/utils/EventEmitter.js.map +1 -1
  135. package/esm/utils/ShakerMetadata.js +2 -2
  136. package/esm/utils/ShakerMetadata.js.map +1 -1
  137. package/esm/utils/TransformDiagnostics.js +9 -9
  138. package/esm/utils/TransformDiagnostics.js.map +1 -1
  139. package/esm/utils/TransformMetadata.js +24 -26
  140. package/esm/utils/TransformMetadata.js.map +1 -1
  141. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  142. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  143. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  144. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  145. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
  146. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  147. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  148. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  149. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  150. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  151. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  152. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  153. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  154. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  155. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  156. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  157. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  158. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  159. package/esm/utils/applyOxcProcessors/types.js +2 -0
  160. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  161. package/esm/utils/applyOxcProcessors.js +2 -0
  162. package/esm/utils/applyOxcProcessors.js.map +1 -0
  163. package/esm/utils/collectOxcExportsAndImports.js +934 -0
  164. package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
  165. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  166. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  167. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  168. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  169. package/esm/utils/collectOxcRuntime/types.js +2 -0
  170. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  171. package/esm/utils/collectOxcRuntime.js +32 -0
  172. package/esm/utils/collectOxcRuntime.js.map +1 -0
  173. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  174. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  175. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  176. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  177. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  178. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  179. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  180. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  181. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  182. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  183. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  184. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  185. package/esm/utils/collectOxcTemplateDependencies.js +4 -0
  186. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
  187. package/esm/utils/dispose-polyfill.js +3 -4
  188. package/esm/utils/dispose-polyfill.js.map +1 -1
  189. package/esm/utils/getFileIdx.js +6 -6
  190. package/esm/utils/getFileIdx.js.map +1 -1
  191. package/esm/utils/getPluginKey.js +12 -12
  192. package/esm/utils/getPluginKey.js.map +1 -1
  193. package/esm/utils/getVisitorKeys.js +9 -3
  194. package/esm/utils/getVisitorKeys.js.map +1 -1
  195. package/esm/utils/hasCachedWywPrevalExport.js +23 -0
  196. package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
  197. package/esm/utils/hasWywPreval.js +5 -5
  198. package/esm/utils/hasWywPreval.js.map +1 -1
  199. package/esm/utils/importOverrides.js +75 -90
  200. package/esm/utils/importOverrides.js.map +1 -1
  201. package/esm/utils/isNode.js +2 -2
  202. package/esm/utils/isNode.js.map +1 -1
  203. package/esm/utils/isNotNull.js +2 -2
  204. package/esm/utils/isNotNull.js.map +1 -1
  205. package/esm/utils/isSerializable.js +11 -11
  206. package/esm/utils/isSerializable.js.map +1 -1
  207. package/esm/utils/nativeResolver.js +93 -0
  208. package/esm/utils/nativeResolver.js.map +1 -0
  209. package/esm/utils/oxc/ast.js +28 -0
  210. package/esm/utils/oxc/ast.js.map +1 -0
  211. package/esm/utils/oxc/parse.js +3 -0
  212. package/esm/utils/oxc/parse.js.map +1 -0
  213. package/esm/utils/oxc/replacements.js +14 -0
  214. package/esm/utils/oxc/replacements.js.map +1 -0
  215. package/esm/utils/oxc/sourceLocations.js +59 -0
  216. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  217. package/esm/utils/oxcAstService.js +121 -0
  218. package/esm/utils/oxcAstService.js.map +1 -0
  219. package/esm/utils/oxcEmit.js +447 -0
  220. package/esm/utils/oxcEmit.js.map +1 -0
  221. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  222. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  223. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  224. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  225. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  226. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  227. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  228. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  229. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  230. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  231. package/esm/utils/oxcPreevalStage/types.js +2 -0
  232. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  233. package/esm/utils/oxcPreevalStage.js +41 -0
  234. package/esm/utils/oxcPreevalStage.js.map +1 -0
  235. package/esm/utils/oxcPreevalTransforms.js +1065 -0
  236. package/esm/utils/oxcPreevalTransforms.js.map +1 -0
  237. package/esm/utils/oxcShaker.js +662 -0
  238. package/esm/utils/oxcShaker.js.map +1 -0
  239. package/esm/utils/parseOxc.js +37 -0
  240. package/esm/utils/parseOxc.js.map +1 -0
  241. package/esm/utils/parseRequest.js +27 -27
  242. package/esm/utils/parseRequest.js.map +1 -1
  243. package/esm/utils/peek.js +1 -1
  244. package/esm/utils/peek.js.map +1 -1
  245. package/esm/utils/processorLookup.js +125 -0
  246. package/esm/utils/processorLookup.js.map +1 -0
  247. package/esm/utils/processorStaticSemantics.js +157 -0
  248. package/esm/utils/processorStaticSemantics.js.map +1 -0
  249. package/esm/utils/resolveWithConditions.js +99 -0
  250. package/esm/utils/resolveWithConditions.js.map +1 -0
  251. package/esm/vm/createVmContext.js +140 -141
  252. package/esm/vm/createVmContext.js.map +1 -1
  253. package/esm/vm/process.js +11 -13
  254. package/esm/vm/process.js.map +1 -1
  255. package/package.json +19 -26
  256. package/types/cache.d.ts +17 -8
  257. package/types/cache.js +245 -95
  258. package/types/debug/fileReporter.js +68 -23
  259. package/types/eval/broker.d.ts +92 -0
  260. package/types/eval/broker.js +2411 -0
  261. package/types/eval/lru.d.ts +10 -0
  262. package/types/eval/lru.js +36 -0
  263. package/types/eval/prepareModuleOnDemand.d.ts +7 -0
  264. package/types/eval/prepareModuleOnDemand.js +24 -0
  265. package/types/eval/protocol.d.ts +111 -0
  266. package/types/eval/protocol.js +1 -0
  267. package/types/eval/serialize.d.ts +78 -0
  268. package/types/eval/serialize.js +357 -0
  269. package/types/eval/writeQueue.d.ts +13 -0
  270. package/types/eval/writeQueue.js +80 -0
  271. package/types/evaluators/index.d.ts +2 -2
  272. package/types/evaluators/index.js +6 -9
  273. package/types/index.d.ts +3 -6
  274. package/types/index.js +24 -82
  275. package/types/module.d.ts +38 -7
  276. package/types/module.js +613 -192
  277. package/types/shaker.d.ts +2 -10
  278. package/types/shaker.js +10 -100
  279. package/types/transform/BaseEntrypoint.js +6 -11
  280. package/types/transform/Entrypoint.d.ts +15 -15
  281. package/types/transform/Entrypoint.helpers.d.ts +2 -5
  282. package/types/transform/Entrypoint.helpers.js +43 -203
  283. package/types/transform/Entrypoint.js +130 -53
  284. package/types/transform/Entrypoint.types.d.ts +31 -6
  285. package/types/transform/Entrypoint.types.js +1 -2
  286. package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
  287. package/types/transform/EvaluatedEntrypoint.js +7 -6
  288. package/types/transform/actions/AbortError.js +2 -7
  289. package/types/transform/actions/BaseAction.js +4 -8
  290. package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
  291. package/types/transform/actions/actionRunner.js +8 -12
  292. package/types/transform/actions/types.d.ts +2 -2
  293. package/types/transform/actions/types.js +1 -2
  294. package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
  295. package/types/transform/barrelManifest.types.js +1 -0
  296. package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
  297. package/types/transform/generators/baseProcessingHandlers.js +10 -14
  298. package/types/transform/generators/collect.js +13 -39
  299. package/types/transform/generators/createStylisPreprocessor.js +19 -60
  300. package/types/transform/generators/evalFile.d.ts +2 -2
  301. package/types/transform/generators/evalFile.js +26 -28
  302. package/types/transform/generators/extract.js +5 -8
  303. package/types/transform/generators/getExports.js +23 -30
  304. package/types/transform/generators/index.d.ts +2 -2
  305. package/types/transform/generators/index.js +11 -14
  306. package/types/transform/generators/processEntrypoint.d.ts +2 -2
  307. package/types/transform/generators/processEntrypoint.js +60 -26
  308. package/types/transform/generators/processImports.d.ts +0 -3
  309. package/types/transform/generators/processImports.js +60 -20
  310. package/types/transform/generators/resolveImports.d.ts +3 -1
  311. package/types/transform/generators/resolveImports.js +66 -23
  312. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  313. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  314. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  315. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  316. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  317. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  318. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  319. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  320. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  321. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  322. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  323. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  324. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  325. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  326. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  327. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  328. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  329. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  330. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  331. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  332. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  333. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  334. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  335. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  336. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  337. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  338. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  339. package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
  340. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  341. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
  342. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  343. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  344. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  345. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  346. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  347. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  348. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  349. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  350. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -0
  351. package/types/transform/generators/resolveStaticOxcValues.js +1 -0
  352. package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
  353. package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
  354. package/types/transform/generators/transform.d.ts +3 -7
  355. package/types/transform/generators/transform.js +217 -199
  356. package/types/transform/generators/workflow.js +62 -45
  357. package/types/transform/helpers/loadWywOptions.js +115 -21
  358. package/types/transform/helpers/withDefaultServices.d.ts +1 -1
  359. package/types/transform/helpers/withDefaultServices.js +6 -44
  360. package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
  361. package/types/transform/isStaticallyEvaluatableModule.js +125 -126
  362. package/types/transform/oxcBarrelManifest.d.ts +2 -0
  363. package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
  364. package/types/transform/rootLog.js +2 -5
  365. package/types/transform/syntax.d.ts +38 -0
  366. package/types/transform/syntax.js +1 -0
  367. package/types/transform/types.d.ts +9 -6
  368. package/types/transform/types.js +1 -4
  369. package/types/transform.d.ts +2 -2
  370. package/types/transform.js +90 -101
  371. package/types/types.d.ts +0 -23
  372. package/types/types.js +1 -2
  373. package/types/utils/EventEmitter.d.ts +16 -1
  374. package/types/utils/EventEmitter.js +47 -18
  375. package/types/utils/ShakerMetadata.js +1 -5
  376. package/types/utils/TransformDiagnostics.js +3 -7
  377. package/types/utils/TransformMetadata.js +8 -16
  378. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
  379. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
  380. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  381. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  382. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  383. package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
  384. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  385. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  386. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  387. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  388. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  389. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  390. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  391. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  392. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  393. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  394. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  395. package/types/utils/applyOxcProcessors/shared.js +37 -0
  396. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  397. package/types/utils/applyOxcProcessors/types.js +1 -0
  398. package/types/utils/applyOxcProcessors.d.ts +1 -0
  399. package/types/utils/applyOxcProcessors.js +1 -0
  400. package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
  401. package/types/utils/collectOxcExportsAndImports.js +957 -0
  402. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  403. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  404. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  405. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  406. package/types/utils/collectOxcRuntime/types.d.ts +16 -0
  407. package/types/utils/collectOxcRuntime/types.js +1 -0
  408. package/types/utils/collectOxcRuntime.d.ts +4 -0
  409. package/types/utils/collectOxcRuntime.js +31 -0
  410. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  411. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  412. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  413. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  414. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  415. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  416. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  417. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  418. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  419. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  420. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  421. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  422. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -0
  423. package/types/utils/collectOxcTemplateDependencies.js +3 -0
  424. package/types/utils/getFileIdx.js +1 -4
  425. package/types/utils/getPluginKey.d.ts +5 -2
  426. package/types/utils/getPluginKey.js +2 -6
  427. package/types/utils/getVisitorKeys.d.ts +4 -4
  428. package/types/utils/getVisitorKeys.js +9 -6
  429. package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
  430. package/types/utils/hasCachedWywPrevalExport.js +30 -0
  431. package/types/utils/hasWywPreval.js +1 -4
  432. package/types/utils/importOverrides.js +17 -27
  433. package/types/utils/isNode.d.ts +2 -2
  434. package/types/utils/isNode.js +2 -6
  435. package/types/utils/isNotNull.js +1 -4
  436. package/types/utils/isSerializable.js +3 -6
  437. package/types/utils/nativeResolver.d.ts +13 -0
  438. package/types/utils/nativeResolver.js +91 -0
  439. package/types/utils/oxc/ast.d.ts +4 -0
  440. package/types/utils/oxc/ast.js +37 -0
  441. package/types/utils/oxc/parse.d.ts +3 -0
  442. package/types/utils/oxc/parse.js +2 -0
  443. package/types/utils/oxc/replacements.d.ts +12 -0
  444. package/types/utils/oxc/replacements.js +18 -0
  445. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  446. package/types/utils/oxc/sourceLocations.js +63 -0
  447. package/types/utils/oxcAstService.d.ts +11 -0
  448. package/types/utils/oxcAstService.js +79 -0
  449. package/types/utils/oxcEmit.d.ts +19 -0
  450. package/types/utils/oxcEmit.js +506 -0
  451. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  452. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  453. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  454. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  455. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  456. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  457. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  458. package/types/utils/oxcPreevalStage/processors.js +16 -0
  459. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  460. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  461. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  462. package/types/utils/oxcPreevalStage/types.js +1 -0
  463. package/types/utils/oxcPreevalStage.d.ts +4 -0
  464. package/types/utils/oxcPreevalStage.js +40 -0
  465. package/types/utils/oxcPreevalTransforms.d.ts +13 -0
  466. package/types/utils/oxcPreevalTransforms.js +1192 -0
  467. package/types/utils/oxcShaker.d.ts +13 -0
  468. package/types/utils/oxcShaker.js +751 -0
  469. package/types/utils/parseOxc.d.ts +11 -0
  470. package/types/utils/parseOxc.js +38 -0
  471. package/types/utils/parseRequest.js +2 -7
  472. package/types/utils/peek.js +1 -5
  473. package/types/utils/processorLookup.d.ts +8 -0
  474. package/types/utils/processorLookup.js +135 -0
  475. package/types/utils/processorStaticSemantics.d.ts +13 -0
  476. package/types/utils/processorStaticSemantics.js +191 -0
  477. package/types/utils/resolveWithConditions.d.ts +12 -0
  478. package/types/utils/resolveWithConditions.js +103 -0
  479. package/types/vm/createVmContext.d.ts +2 -2
  480. package/types/vm/createVmContext.js +25 -62
  481. package/types/vm/process.js +20 -26
  482. package/esm/babel.js +0 -2
  483. package/esm/babel.js.map +0 -1
  484. package/esm/options/buildOptions.js +0 -168
  485. package/esm/options/buildOptions.js.map +0 -1
  486. package/esm/options/buildOptions.test.js +0 -138
  487. package/esm/options/buildOptions.test.js.map +0 -1
  488. package/esm/options/loadBabelOptions.js +0 -24
  489. package/esm/options/loadBabelOptions.js.map +0 -1
  490. package/esm/plugins/babel-transform.js +0 -53
  491. package/esm/plugins/babel-transform.js.map +0 -1
  492. package/esm/plugins/collector.js +0 -60
  493. package/esm/plugins/collector.js.map +0 -1
  494. package/esm/plugins/dynamic-import.js +0 -56
  495. package/esm/plugins/dynamic-import.js.map +0 -1
  496. package/esm/plugins/preeval.js +0 -73
  497. package/esm/plugins/preeval.js.map +0 -1
  498. package/esm/plugins/shaker.js +0 -680
  499. package/esm/plugins/shaker.js.map +0 -1
  500. package/esm/transform/barrelManifest.js +0 -291
  501. package/esm/transform/barrelManifest.js.map +0 -1
  502. package/esm/transform/generators/explodeReexports.js +0 -64
  503. package/esm/transform/generators/explodeReexports.js.map +0 -1
  504. package/esm/transform/generators/rewriteBarrelImports.js +0 -733
  505. package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
  506. package/esm/utils/addIdentifierToWywPreval.js +0 -68
  507. package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
  508. package/esm/utils/collectExportsAndImports.js +0 -1157
  509. package/esm/utils/collectExportsAndImports.js.map +0 -1
  510. package/esm/utils/collectTemplateDependencies.js +0 -228
  511. package/esm/utils/collectTemplateDependencies.js.map +0 -1
  512. package/esm/utils/createId.js +0 -6
  513. package/esm/utils/createId.js.map +0 -1
  514. package/esm/utils/findIdentifiers.js +0 -62
  515. package/esm/utils/findIdentifiers.js.map +0 -1
  516. package/esm/utils/getConstantStringValue.js +0 -58
  517. package/esm/utils/getConstantStringValue.js.map +0 -1
  518. package/esm/utils/getMemberExpressionPropertyName.js +0 -11
  519. package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
  520. package/esm/utils/getScope.js +0 -6
  521. package/esm/utils/getScope.js.map +0 -1
  522. package/esm/utils/getSource.js +0 -15
  523. package/esm/utils/getSource.js.map +0 -1
  524. package/esm/utils/getTagProcessor.js +0 -404
  525. package/esm/utils/getTagProcessor.js.map +0 -1
  526. package/esm/utils/isExports.js +0 -22
  527. package/esm/utils/isExports.js.map +0 -1
  528. package/esm/utils/isGlobal.js +0 -6
  529. package/esm/utils/isGlobal.js.map +0 -1
  530. package/esm/utils/isNodePath.js +0 -4
  531. package/esm/utils/isNodePath.js.map +0 -1
  532. package/esm/utils/isRemoved.js +0 -46
  533. package/esm/utils/isRemoved.js.map +0 -1
  534. package/esm/utils/isRequire.js +0 -13
  535. package/esm/utils/isRequire.js.map +0 -1
  536. package/esm/utils/isTypedNode.js +0 -6
  537. package/esm/utils/isTypedNode.js.map +0 -1
  538. package/esm/utils/isUnnecessaryReactCall.js +0 -72
  539. package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
  540. package/esm/utils/removeDangerousCode.js +0 -276
  541. package/esm/utils/removeDangerousCode.js.map +0 -1
  542. package/esm/utils/replaceImportMetaEnv.js +0 -44
  543. package/esm/utils/replaceImportMetaEnv.js.map +0 -1
  544. package/esm/utils/scopeHelpers.js +0 -527
  545. package/esm/utils/scopeHelpers.js.map +0 -1
  546. package/esm/utils/traversalCache.js +0 -23
  547. package/esm/utils/traversalCache.js.map +0 -1
  548. package/esm/utils/unwrapExpression.js +0 -18
  549. package/esm/utils/unwrapExpression.js.map +0 -1
  550. package/esm/utils/unwrapSequence.js +0 -14
  551. package/esm/utils/unwrapSequence.js.map +0 -1
  552. package/esm/utils/valueToLiteral.js +0 -59
  553. package/esm/utils/valueToLiteral.js.map +0 -1
  554. package/esm/utils/visitors/JSXElementsRemover.js +0 -51
  555. package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
  556. package/lib/babel.js +0 -2
  557. package/lib/babel.js.map +0 -1
  558. package/lib/cache.js +0 -308
  559. package/lib/cache.js.map +0 -1
  560. package/lib/debug/fileReporter.js +0 -153
  561. package/lib/debug/fileReporter.js.map +0 -1
  562. package/lib/evaluators/index.js +0 -20
  563. package/lib/evaluators/index.js.map +0 -1
  564. package/lib/index.js +0 -286
  565. package/lib/index.js.map +0 -1
  566. package/lib/module.js +0 -552
  567. package/lib/module.js.map +0 -1
  568. package/lib/options/buildOptions.js +0 -176
  569. package/lib/options/buildOptions.js.map +0 -1
  570. package/lib/options/buildOptions.test.js +0 -141
  571. package/lib/options/buildOptions.test.js.map +0 -1
  572. package/lib/options/loadBabelOptions.js +0 -31
  573. package/lib/options/loadBabelOptions.js.map +0 -1
  574. package/lib/plugins/babel-transform.js +0 -60
  575. package/lib/plugins/babel-transform.js.map +0 -1
  576. package/lib/plugins/collector.js +0 -70
  577. package/lib/plugins/collector.js.map +0 -1
  578. package/lib/plugins/dynamic-import.js +0 -61
  579. package/lib/plugins/dynamic-import.js.map +0 -1
  580. package/lib/plugins/preeval.js +0 -81
  581. package/lib/plugins/preeval.js.map +0 -1
  582. package/lib/plugins/shaker.js +0 -691
  583. package/lib/plugins/shaker.js.map +0 -1
  584. package/lib/shaker.js +0 -95
  585. package/lib/shaker.js.map +0 -1
  586. package/lib/transform/BaseEntrypoint.js +0 -179
  587. package/lib/transform/BaseEntrypoint.js.map +0 -1
  588. package/lib/transform/Entrypoint.helpers.js +0 -279
  589. package/lib/transform/Entrypoint.helpers.js.map +0 -1
  590. package/lib/transform/Entrypoint.js +0 -289
  591. package/lib/transform/Entrypoint.js.map +0 -1
  592. package/lib/transform/Entrypoint.types.js +0 -2
  593. package/lib/transform/Entrypoint.types.js.map +0 -1
  594. package/lib/transform/EvaluatedEntrypoint.js +0 -13
  595. package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
  596. package/lib/transform/actions/AbortError.js +0 -16
  597. package/lib/transform/actions/AbortError.js.map +0 -1
  598. package/lib/transform/actions/BaseAction.js +0 -150
  599. package/lib/transform/actions/BaseAction.js.map +0 -1
  600. package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
  601. package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
  602. package/lib/transform/actions/actionRunner.js +0 -82
  603. package/lib/transform/actions/actionRunner.js.map +0 -1
  604. package/lib/transform/actions/types.js +0 -2
  605. package/lib/transform/actions/types.js.map +0 -1
  606. package/lib/transform/barrelManifest.js +0 -300
  607. package/lib/transform/barrelManifest.js.map +0 -1
  608. package/lib/transform/generators/baseProcessingHandlers.js +0 -27
  609. package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
  610. package/lib/transform/generators/collect.js +0 -66
  611. package/lib/transform/generators/collect.js.map +0 -1
  612. package/lib/transform/generators/createStylisPreprocessor.js +0 -372
  613. package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
  614. package/lib/transform/generators/evalFile.js +0 -57
  615. package/lib/transform/generators/evalFile.js.map +0 -1
  616. package/lib/transform/generators/explodeReexports.js +0 -71
  617. package/lib/transform/generators/explodeReexports.js.map +0 -1
  618. package/lib/transform/generators/extract.js +0 -102
  619. package/lib/transform/generators/extract.js.map +0 -1
  620. package/lib/transform/generators/getExports.js +0 -85
  621. package/lib/transform/generators/getExports.js.map +0 -1
  622. package/lib/transform/generators/index.js +0 -19
  623. package/lib/transform/generators/index.js.map +0 -1
  624. package/lib/transform/generators/processEntrypoint.js +0 -76
  625. package/lib/transform/generators/processEntrypoint.js.map +0 -1
  626. package/lib/transform/generators/processImports.js +0 -82
  627. package/lib/transform/generators/processImports.js.map +0 -1
  628. package/lib/transform/generators/resolveImports.js +0 -221
  629. package/lib/transform/generators/resolveImports.js.map +0 -1
  630. package/lib/transform/generators/rewriteBarrelImports.js +0 -743
  631. package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
  632. package/lib/transform/generators/transform.js +0 -272
  633. package/lib/transform/generators/transform.js.map +0 -1
  634. package/lib/transform/generators/workflow.js +0 -100
  635. package/lib/transform/generators/workflow.js.map +0 -1
  636. package/lib/transform/helpers/loadWywOptions.js +0 -88
  637. package/lib/transform/helpers/loadWywOptions.js.map +0 -1
  638. package/lib/transform/helpers/withDefaultServices.js +0 -31
  639. package/lib/transform/helpers/withDefaultServices.js.map +0 -1
  640. package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
  641. package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
  642. package/lib/transform/rootLog.js +0 -9
  643. package/lib/transform/rootLog.js.map +0 -1
  644. package/lib/transform/types.js +0 -8
  645. package/lib/transform/types.js.map +0 -1
  646. package/lib/transform.js +0 -160
  647. package/lib/transform.js.map +0 -1
  648. package/lib/types.js +0 -2
  649. package/lib/types.js.map +0 -1
  650. package/lib/utils/EventEmitter.js +0 -61
  651. package/lib/utils/EventEmitter.js.map +0 -1
  652. package/lib/utils/ShakerMetadata.js +0 -9
  653. package/lib/utils/ShakerMetadata.js.map +0 -1
  654. package/lib/utils/TransformDiagnostics.js +0 -20
  655. package/lib/utils/TransformDiagnostics.js.map +0 -1
  656. package/lib/utils/TransformMetadata.js +0 -45
  657. package/lib/utils/TransformMetadata.js.map +0 -1
  658. package/lib/utils/addIdentifierToWywPreval.js +0 -75
  659. package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
  660. package/lib/utils/collectExportsAndImports.js +0 -1173
  661. package/lib/utils/collectExportsAndImports.js.map +0 -1
  662. package/lib/utils/collectTemplateDependencies.js +0 -242
  663. package/lib/utils/collectTemplateDependencies.js.map +0 -1
  664. package/lib/utils/createId.js +0 -13
  665. package/lib/utils/createId.js.map +0 -1
  666. package/lib/utils/dispose-polyfill.js +0 -9
  667. package/lib/utils/dispose-polyfill.js.map +0 -1
  668. package/lib/utils/findIdentifiers.js +0 -73
  669. package/lib/utils/findIdentifiers.js.map +0 -1
  670. package/lib/utils/getConstantStringValue.js +0 -66
  671. package/lib/utils/getConstantStringValue.js.map +0 -1
  672. package/lib/utils/getFileIdx.js +0 -16
  673. package/lib/utils/getFileIdx.js.map +0 -1
  674. package/lib/utils/getMemberExpressionPropertyName.js +0 -18
  675. package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
  676. package/lib/utils/getPluginKey.js +0 -21
  677. package/lib/utils/getPluginKey.js.map +0 -1
  678. package/lib/utils/getScope.js +0 -12
  679. package/lib/utils/getScope.js.map +0 -1
  680. package/lib/utils/getSource.js +0 -24
  681. package/lib/utils/getSource.js.map +0 -1
  682. package/lib/utils/getTagProcessor.js +0 -424
  683. package/lib/utils/getTagProcessor.js.map +0 -1
  684. package/lib/utils/getVisitorKeys.js +0 -11
  685. package/lib/utils/getVisitorKeys.js.map +0 -1
  686. package/lib/utils/hasWywPreval.js +0 -13
  687. package/lib/utils/hasWywPreval.js.map +0 -1
  688. package/lib/utils/importOverrides.js +0 -119
  689. package/lib/utils/importOverrides.js.map +0 -1
  690. package/lib/utils/isExports.js +0 -27
  691. package/lib/utils/isExports.js.map +0 -1
  692. package/lib/utils/isGlobal.js +0 -13
  693. package/lib/utils/isGlobal.js.map +0 -1
  694. package/lib/utils/isNode.js +0 -9
  695. package/lib/utils/isNode.js.map +0 -1
  696. package/lib/utils/isNodePath.js +0 -10
  697. package/lib/utils/isNodePath.js.map +0 -1
  698. package/lib/utils/isNotNull.js +0 -10
  699. package/lib/utils/isNotNull.js.map +0 -1
  700. package/lib/utils/isRemoved.js +0 -52
  701. package/lib/utils/isRemoved.js.map +0 -1
  702. package/lib/utils/isRequire.js +0 -18
  703. package/lib/utils/isRequire.js.map +0 -1
  704. package/lib/utils/isSerializable.js +0 -19
  705. package/lib/utils/isSerializable.js.map +0 -1
  706. package/lib/utils/isTypedNode.js +0 -13
  707. package/lib/utils/isTypedNode.js.map +0 -1
  708. package/lib/utils/isUnnecessaryReactCall.js +0 -81
  709. package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
  710. package/lib/utils/parseRequest.js +0 -37
  711. package/lib/utils/parseRequest.js.map +0 -1
  712. package/lib/utils/peek.js +0 -9
  713. package/lib/utils/peek.js.map +0 -1
  714. package/lib/utils/removeDangerousCode.js +0 -284
  715. package/lib/utils/removeDangerousCode.js.map +0 -1
  716. package/lib/utils/replaceImportMetaEnv.js +0 -50
  717. package/lib/utils/replaceImportMetaEnv.js.map +0 -1
  718. package/lib/utils/scopeHelpers.js +0 -557
  719. package/lib/utils/scopeHelpers.js.map +0 -1
  720. package/lib/utils/traversalCache.js +0 -31
  721. package/lib/utils/traversalCache.js.map +0 -1
  722. package/lib/utils/unwrapExpression.js +0 -25
  723. package/lib/utils/unwrapExpression.js.map +0 -1
  724. package/lib/utils/unwrapSequence.js +0 -20
  725. package/lib/utils/unwrapSequence.js.map +0 -1
  726. package/lib/utils/valueToLiteral.js +0 -65
  727. package/lib/utils/valueToLiteral.js.map +0 -1
  728. package/lib/utils/visitors/JSXElementsRemover.js +0 -57
  729. package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
  730. package/lib/vm/createVmContext.js +0 -166
  731. package/lib/vm/createVmContext.js.map +0 -1
  732. package/lib/vm/process.js +0 -38
  733. package/lib/vm/process.js.map +0 -1
  734. package/types/babel.d.ts +0 -2
  735. package/types/babel.js +0 -2
  736. package/types/options/buildOptions.d.ts +0 -6
  737. package/types/options/buildOptions.js +0 -178
  738. package/types/options/loadBabelOptions.d.ts +0 -3
  739. package/types/options/loadBabelOptions.js +0 -26
  740. package/types/plugins/babel-transform.d.ts +0 -4
  741. package/types/plugins/babel-transform.js +0 -49
  742. package/types/plugins/collector.d.ts +0 -23
  743. package/types/plugins/collector.js +0 -62
  744. package/types/plugins/dynamic-import.d.ts +0 -6
  745. package/types/plugins/dynamic-import.js +0 -60
  746. package/types/plugins/preeval.d.ts +0 -16
  747. package/types/plugins/preeval.js +0 -69
  748. package/types/plugins/shaker.d.ts +0 -14
  749. package/types/plugins/shaker.js +0 -724
  750. package/types/transform/generators/explodeReexports.d.ts +0 -7
  751. package/types/transform/generators/explodeReexports.js +0 -65
  752. package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
  753. package/types/utils/addIdentifierToWywPreval.js +0 -74
  754. package/types/utils/collectExportsAndImports.d.ts +0 -31
  755. package/types/utils/collectExportsAndImports.js +0 -1147
  756. package/types/utils/collectTemplateDependencies.d.ts +0 -17
  757. package/types/utils/collectTemplateDependencies.js +0 -220
  758. package/types/utils/createId.d.ts +0 -2
  759. package/types/utils/createId.js +0 -9
  760. package/types/utils/findIdentifiers.d.ts +0 -6
  761. package/types/utils/findIdentifiers.js +0 -67
  762. package/types/utils/getConstantStringValue.d.ts +0 -2
  763. package/types/utils/getConstantStringValue.js +0 -94
  764. package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
  765. package/types/utils/getMemberExpressionPropertyName.js +0 -46
  766. package/types/utils/getScope.d.ts +0 -2
  767. package/types/utils/getScope.js +0 -10
  768. package/types/utils/getSource.d.ts +0 -2
  769. package/types/utils/getSource.js +0 -22
  770. package/types/utils/getTagProcessor.d.ts +0 -13
  771. package/types/utils/getTagProcessor.js +0 -411
  772. package/types/utils/isExports.d.ts +0 -6
  773. package/types/utils/isExports.js +0 -19
  774. package/types/utils/isGlobal.d.ts +0 -2
  775. package/types/utils/isGlobal.js +0 -9
  776. package/types/utils/isNodePath.d.ts +0 -3
  777. package/types/utils/isNodePath.js +0 -6
  778. package/types/utils/isRemoved.d.ts +0 -5
  779. package/types/utils/isRemoved.js +0 -41
  780. package/types/utils/isRequire.d.ts +0 -6
  781. package/types/utils/isRequire.js +0 -14
  782. package/types/utils/isTypedNode.d.ts +0 -5
  783. package/types/utils/isTypedNode.js +0 -9
  784. package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
  785. package/types/utils/isUnnecessaryReactCall.js +0 -75
  786. package/types/utils/removeDangerousCode.d.ts +0 -4
  787. package/types/utils/removeDangerousCode.js +0 -326
  788. package/types/utils/replaceImportMetaEnv.d.ts +0 -3
  789. package/types/utils/replaceImportMetaEnv.js +0 -39
  790. package/types/utils/scopeHelpers.d.ts +0 -12
  791. package/types/utils/scopeHelpers.js +0 -580
  792. package/types/utils/traversalCache.d.ts +0 -4
  793. package/types/utils/traversalCache.js +0 -27
  794. package/types/utils/unwrapExpression.d.ts +0 -2
  795. package/types/utils/unwrapExpression.js +0 -57
  796. package/types/utils/unwrapSequence.d.ts +0 -8
  797. package/types/utils/unwrapSequence.js +0 -16
  798. package/types/utils/valueToLiteral.d.ts +0 -3
  799. package/types/utils/valueToLiteral.js +0 -63
  800. package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
  801. package/types/utils/visitors/JSXElementsRemover.js +0 -51
package/esm/module.js CHANGED
@@ -1,539 +1,942 @@
1
1
  /**
2
- * This is a custom implementation for the module system for evaluating code,
3
- * used for resolving values for dependencies interpolated in `css` or `styled`.
4
- *
5
- * This serves 2 purposes:
6
- * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`
7
- * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
8
- *
9
- * We also use it to transpile the code with Babel by default.
10
- * We also store source maps for it to provide correct error stacktraces.
11
- *
12
- */
13
-
14
- import fs from 'fs';
15
- import NativeModule from 'module';
16
- import path from 'path';
17
- import vm from 'vm';
18
- import { invariant } from 'ts-invariant';
19
- import { isFeatureEnabled } from '@wyw-in-js/shared';
20
- import './utils/dispose-polyfill';
21
- import { Entrypoint } from './transform/Entrypoint';
22
- import { getStack, isSuperSet, mergeOnly } from './transform/Entrypoint.helpers';
23
- import { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';
24
- import { applyImportOverrideToOnly, getImportOverride, resolveMockSpecifier, toImportKey } from './utils/importOverrides';
25
- import { parseRequest, stripQueryAndHash } from './utils/parseRequest';
26
- import { createVmContext } from './vm/createVmContext';
27
- const CJS_DEFAULT_CONDITIONS = ['require', 'node', 'default'];
28
- function expandConditions(conditionNames) {
29
- const result = new Set();
30
- for (const name of conditionNames) {
31
- if (name === '...') {
32
- for (const d of CJS_DEFAULT_CONDITIONS) result.add(d);
33
- } else {
34
- result.add(name);
35
- }
36
- }
37
- return result;
38
- }
39
- function isBarePackageSubpath(id) {
40
- if (id.startsWith('.') || path.isAbsolute(id)) {
41
- return false;
42
- }
43
- if (id.startsWith('@')) {
44
- return id.split('/').length > 2;
45
- }
46
- return id.includes('/');
47
- }
2
+ * This is a custom implementation for the module system for evaluating code,
3
+ * used for resolving values for dependencies interpolated in `css` or `styled`.
4
+ *
5
+ * This serves 2 purposes:
6
+ * - Avoid leakage from evaluated code to module cache in current context
7
+ * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
8
+ *
9
+ * We also store prepared evaluator code in it.
10
+ * We also store source maps for it to provide correct error stacktraces.
11
+ *
12
+ */
13
+ import fs from "fs";
14
+ import NativeModule, { createRequire } from "module";
15
+ import path from "path";
16
+ import * as vm from "vm";
17
+ import { pathToFileURL } from "url";
18
+ import { invariant } from "ts-invariant";
19
+ import { isFeatureEnabled } from "@wyw-in-js/shared";
20
+ import "./utils/dispose-polyfill.js";
21
+ import { Entrypoint } from "./transform/Entrypoint.js";
22
+ import { getStack, isSuperSet, mergeOnly } from "./transform/Entrypoint.helpers.js";
23
+ import { isUnprocessedEntrypointError } from "./transform/actions/UnprocessedEntrypointError.js";
24
+ import { applyImportOverrideToOnly, getImportOverride, resolveMockSpecifier, toImportKey } from "./utils/importOverrides.js";
25
+ import { resolveWithNativeResolver } from "./utils/nativeResolver.js";
26
+ import { parseRequest, stripQueryAndHash } from "./utils/parseRequest.js";
27
+ import { resolveFilenameWithConditions } from "./utils/resolveWithConditions.js";
28
+ import { createVmContext } from "./vm/createVmContext.js";
29
+ const CJS_DEFAULT_CONDITIONS = [
30
+ "require",
31
+ "node",
32
+ "default"
33
+ ];
34
+ const expandConditions = (conditionNames) => {
35
+ const result = new Set();
36
+ conditionNames.forEach((name) => {
37
+ if (name === "...") {
38
+ CJS_DEFAULT_CONDITIONS.forEach((condition) => result.add(condition));
39
+ return;
40
+ }
41
+ result.add(name);
42
+ });
43
+ return result;
44
+ };
45
+ const isBarePackageSubpath = (id) => {
46
+ if (id.startsWith(".") || path.isAbsolute(id)) {
47
+ return false;
48
+ }
49
+ if (id.startsWith("@")) {
50
+ return id.split("/").length > 2;
51
+ }
52
+ return id.includes("/");
53
+ };
48
54
  export const DefaultModuleImplementation = NativeModule;
49
-
50
55
  // Supported node builtins based on the modules polyfilled by webpack
51
56
  // `true` means module is polyfilled, `false` means module is empty
52
57
  const builtins = {
53
- assert: true,
54
- buffer: true,
55
- child_process: false,
56
- cluster: false,
57
- console: true,
58
- constants: true,
59
- crypto: true,
60
- dgram: false,
61
- dns: false,
62
- domain: true,
63
- events: true,
64
- fs: false,
65
- http: true,
66
- https: true,
67
- module: false,
68
- net: false,
69
- os: true,
70
- path: true,
71
- punycode: true,
72
- process: true,
73
- querystring: true,
74
- readline: false,
75
- repl: false,
76
- stream: true,
77
- string_decoder: true,
78
- sys: true,
79
- timers: true,
80
- tls: false,
81
- tty: true,
82
- url: true,
83
- util: true,
84
- vm: true,
85
- zlib: true
86
- };
87
- const VITE_VIRTUAL_PREFIX = '/@';
88
- const REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';
89
- const reactRefreshRuntime = {
90
- createSignatureFunctionForTransform: () => () => {}
58
+ assert: true,
59
+ buffer: true,
60
+ child_process: false,
61
+ cluster: false,
62
+ console: true,
63
+ constants: true,
64
+ crypto: true,
65
+ dgram: false,
66
+ dns: false,
67
+ domain: true,
68
+ events: true,
69
+ fs: false,
70
+ http: true,
71
+ https: true,
72
+ module: false,
73
+ net: false,
74
+ os: true,
75
+ path: true,
76
+ punycode: true,
77
+ process: true,
78
+ querystring: true,
79
+ readline: false,
80
+ repl: false,
81
+ stream: true,
82
+ string_decoder: true,
83
+ sys: true,
84
+ timers: true,
85
+ tls: false,
86
+ tty: true,
87
+ url: true,
88
+ util: true,
89
+ vm: true,
90
+ zlib: true
91
91
  };
92
+ const VITE_VIRTUAL_PREFIX = "/@";
93
+ const REACT_REFRESH_VIRTUAL_ID = "/@react-refresh";
94
+ const reactRefreshRuntime = { createSignatureFunctionForTransform: () => () => {} };
95
+ const nodeRequire = createRequire(import.meta.url);
92
96
  const NOOP = () => {};
93
- const browserOnlyEvalHintTriggers = ['window is not defined', "evaluating 'window", 'document is not defined', "evaluating 'document", 'navigator is not defined', "evaluating 'navigator", 'self is not defined', "evaluating 'self"];
94
- const getBrowserOnlyEvalHint = error => {
95
- const message = error instanceof Error ? error.message : String(error);
96
- const looksLikeBrowserOnly = browserOnlyEvalHintTriggers.some(trigger => message.includes(trigger));
97
- if (!looksLikeBrowserOnly) return null;
98
- return ['', '[wyw-in-js] Evaluation hint:', 'This usually means browser-only code ran during build-time evaluation.', 'Move browser-only initialization out of evaluated modules, or mock the import via `importOverrides`.', "Example: importOverrides: { 'msw/browser': { mock: './src/__mocks__/msw-browser.js' } }"].join('\n');
97
+ const TROUBLESHOOTING_URL = "https://wyw-in-js.dev/troubleshooting";
98
+ const defaultEvalOptions = {
99
+ errors: "strict",
100
+ require: "warn-and-run",
101
+ resolver: "bundler"
102
+ };
103
+ const browserOnlyEvalHintTriggers = [
104
+ "window is not defined",
105
+ "evaluating 'window",
106
+ "document is not defined",
107
+ "evaluating 'document",
108
+ "navigator is not defined",
109
+ "evaluating 'navigator",
110
+ "self is not defined",
111
+ "evaluating 'self"
112
+ ];
113
+ const getBrowserOnlyEvalHint = (error) => {
114
+ const message = error instanceof Error ? error.message : String(error);
115
+ const looksLikeBrowserOnly = browserOnlyEvalHintTriggers.some((trigger) => message.includes(trigger));
116
+ if (!looksLikeBrowserOnly) return null;
117
+ return [
118
+ "",
119
+ "[wyw-in-js] Evaluation hint:",
120
+ "This usually means browser-only code ran during build-time evaluation.",
121
+ "Move browser-only initialization out of evaluated modules, or mock the import via `importOverrides`.",
122
+ "Example: importOverrides: { 'msw/browser': { mock: './src/__mocks__/msw-browser.js' } }",
123
+ `Docs: ${TROUBLESHOOTING_URL}`
124
+ ].join("\n");
99
125
  };
100
126
  const warnedUnknownImportsByServices = new WeakMap();
127
+ const getEvalOptions = (services) => ({
128
+ ...defaultEvalOptions,
129
+ ...services.options.pluginOptions.eval ?? {}
130
+ });
101
131
  function emitWarning(services, message) {
102
- if (services.emitWarning) {
103
- services.emitWarning(message);
104
- return;
105
- }
106
-
107
- // eslint-disable-next-line no-console
108
- console.warn(message);
132
+ if (services.emitWarning) {
133
+ services.emitWarning(message);
134
+ return;
135
+ }
136
+ // eslint-disable-next-line no-console
137
+ console.warn(message);
138
+ }
139
+ function emitEvalWarning(services, warning) {
140
+ const { onWarn } = getEvalOptions(services);
141
+ onWarn?.(warning);
142
+ emitWarning(services, warning.message);
109
143
  }
110
144
  function getWarnedUnknownImports(services) {
111
- const cached = warnedUnknownImportsByServices.get(services);
112
- if (cached) {
113
- return cached;
114
- }
115
- const created = new Set();
116
- warnedUnknownImportsByServices.set(services, created);
117
- return created;
145
+ const cached = warnedUnknownImportsByServices.get(services);
146
+ if (cached) {
147
+ return cached;
148
+ }
149
+ const created = new Set();
150
+ warnedUnknownImportsByServices.set(services, created);
151
+ return created;
118
152
  }
119
153
  function getUncached(cached, test) {
120
- const cachedSet = new Set(typeof cached === 'string' ? cached.split(',') : cached);
121
- if (cachedSet.has('*')) {
122
- return [];
123
- }
124
- return test.filter(t => !cachedSet.has(t));
125
- }
126
- function resolve(id) {
127
- const {
128
- resolved
129
- } = this.resolveDependency(id);
130
- invariant(resolved, `Unable to resolve "${id}"`);
131
- return resolved;
154
+ const cachedSet = new Set(typeof cached === "string" ? cached.split(",") : cached);
155
+ if (cachedSet.has("*")) {
156
+ return [];
157
+ }
158
+ return test.filter((t) => !cachedSet.has(t));
132
159
  }
133
160
  const defaultImportLoaders = {
134
- raw: 'raw',
135
- url: 'url'
161
+ raw: "raw",
162
+ url: "url"
163
+ };
164
+ const buildModulePreamble = (id) => {
165
+ const payload = JSON.stringify(id);
166
+ return [
167
+ `const __wyw_module = __wyw_getModule(${payload});`,
168
+ `let exports = __wyw_module.exports;`,
169
+ `const module = __wyw_module.module;`,
170
+ `const require = __wyw_module.require;`,
171
+ `const __filename = __wyw_module.filename;`,
172
+ `const __dirname = __wyw_module.dirname;`,
173
+ `const __wyw_dynamic_import = __wyw_module.dynamicImport;`,
174
+ ``
175
+ ].join("\n");
176
+ };
177
+ const applyModuleNamespace = (entrypointExports, module, moduleData) => {
178
+ const { namespace } = module;
179
+ const keys = Object.keys(namespace);
180
+ if (keys.length === 0 && moduleData.module.exports !== moduleData.exports) {
181
+ return moduleData.module.exports;
182
+ }
183
+ const nextExports = entrypointExports;
184
+ keys.forEach((key) => {
185
+ nextExports[key] = namespace[key];
186
+ });
187
+ return nextExports;
188
+ };
189
+ const ensureVmModules = () => {
190
+ if (!vm.SourceTextModule || !vm.SyntheticModule) {
191
+ throw new EvalError("[wyw-in-js] vm.SourceTextModule is not available in this runtime. " + "WyW v2 uses a separate eval runner process for ESM evaluation.");
192
+ }
193
+ };
194
+ const getImporterDependency = (importer, specifier) => {
195
+ if (importer instanceof Entrypoint) {
196
+ return importer.getDependency(specifier);
197
+ }
198
+ return importer.dependencies.get(specifier);
136
199
  };
137
200
  export class Module {
138
- callstack = [];
139
- isEvaluated = false;
140
- require = Object.assign(id => {
141
- if (id === REACT_REFRESH_VIRTUAL_ID) {
142
- this.dependencies.push(id);
143
- this.debug('require', `vite virtual '${id}'`);
144
- return reactRefreshRuntime;
145
- }
146
- if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
147
- this.dependencies.push(id);
148
- this.debug('require', `vite virtual '${id}'`);
149
- return {};
150
- }
151
- if (id in builtins) {
152
- // The module is in the allowed list of builtin node modules
153
- // Ideally we should prevent importing them, but webpack polyfills some
154
- // So we check for the list of polyfills to determine which ones to support
155
- if (builtins[id]) {
156
- this.debug('require', `builtin '${id}'`);
157
- return require(id);
158
- }
159
- return null;
160
- }
161
-
162
- // Resolve module id (and filename) relatively to parent module
163
- const dependency = this.resolveDependency(id);
164
- if (dependency.resolved === id && !path.isAbsolute(id)) {
165
- // The module is a builtin node modules, but not in the allowed list
166
- throw new Error(`Unable to import "${id}". Importing Node builtins is not supported in the sandbox.`);
167
- }
168
- invariant(dependency.resolved, `Dependency ${dependency.source} cannot be resolved`);
169
- const loaded = this.loadByImportLoaders(id, dependency.resolved);
170
- if (loaded.handled) {
171
- this.dependencies.push(id);
172
- this.debug('require', `${id} -> ${dependency.resolved} (loader)`);
173
- return loaded.value;
174
- }
175
- this.dependencies.push(id);
176
- this.debug('require', `${id} -> ${dependency.resolved}`);
177
- const entrypoint = this.getEntrypoint(dependency.resolved, dependency.only, this.debug);
178
- if (entrypoint === null) {
179
- return dependency.resolved;
180
- }
181
- if (entrypoint.evaluated || isSuperSet(entrypoint.evaluatedOnly, dependency.only)) {
182
- return entrypoint.exports;
183
- }
184
- const m = this.createChild(entrypoint);
185
- m.evaluate();
186
- return entrypoint.exports;
187
- }, {
188
- ensure: NOOP,
189
- resolve: resolve.bind(this)
190
- });
191
- resolve = resolve.bind(this);
192
- #entrypointRef;
193
- constructor(services, entrypoint, parentModule, moduleImpl = DefaultModuleImplementation) {
194
- this.services = services;
195
- this.moduleImpl = moduleImpl;
196
- this.cache = services.cache;
197
- this.#entrypointRef = isFeatureEnabled(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
198
- this.idx = entrypoint.idx;
199
- this.id = entrypoint.name;
200
- this.filename = entrypoint.name;
201
- this.dependencies = [];
202
- this.debug = entrypoint.log.extend('module');
203
- this.parentIsIgnored = parentModule?.ignored ?? false;
204
- this.ignored = entrypoint.ignored ?? this.parentIsIgnored;
205
- if (parentModule) {
206
- this.callstack = [entrypoint.name, ...parentModule.callstack];
207
- } else {
208
- this.callstack = [entrypoint.name];
209
- }
210
- this.extensions = services.options.pluginOptions.extensions;
211
- this.debug('init', entrypoint.name);
212
- }
213
- get exports() {
214
- return this.entrypoint.exports;
215
- }
216
- set exports(value) {
217
- this.entrypoint.exports = value;
218
- this.debug('the whole exports was overridden with %O', value);
219
- }
220
- get entrypoint() {
221
- const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
222
- invariant(entrypoint, `Module ${this.idx} is disposed`);
223
- return entrypoint;
224
- }
225
- evaluate() {
226
- const {
227
- entrypoint
228
- } = this;
229
- entrypoint.assertTransformed();
230
- const cached = this.cache.get('entrypoints', entrypoint.name);
231
- let evaluatedCreated = false;
232
- if (!entrypoint.supersededWith) {
233
- this.cache.add('entrypoints', entrypoint.name, entrypoint.createEvaluated());
234
- evaluatedCreated = true;
235
- }
236
- const {
237
- transformedCode: source
238
- } = entrypoint;
239
- const {
240
- pluginOptions
241
- } = this.services.options;
242
- if (!source) {
243
- this.debug(`evaluate`, 'there is nothing to evaluate');
244
- return;
245
- }
246
- if (this.isEvaluated) {
247
- this.debug('evaluate', `is already evaluated`);
248
- return;
249
- }
250
- this.debug('evaluate');
251
- this.debug.extend('source')('%s', source);
252
- this.isEvaluated = true;
253
- const filename = stripQueryAndHash(this.filename);
254
- if (/\.json$/.test(filename)) {
255
- // For JSON files, parse it to a JS object similar to Node
256
- this.exports = JSON.parse(source);
257
- return;
258
- }
259
- const {
260
- context,
261
- teardown
262
- } = createVmContext(filename, pluginOptions.features, {
263
- module: this,
264
- exports: entrypoint.exports,
265
- require: this.require,
266
- __wyw_dynamic_import: async id => this.require(String(id)),
267
- __dirname: path.dirname(filename)
268
- }, pluginOptions.overrideContext);
269
- try {
270
- const script = new vm.Script(`(function (exports) { ${source}\n})(exports);`, {
271
- filename
272
- });
273
- script.runInContext(context);
274
- } catch (e) {
275
- this.isEvaluated = false;
276
- if (evaluatedCreated) {
277
- this.cache.add('entrypoints', entrypoint.name, cached);
278
- }
279
- if (isUnprocessedEntrypointError(e)) {
280
- // It will be handled by evalFile scenario
281
- throw e;
282
- }
283
- if (e instanceof EvalError) {
284
- this.debug('%O', e);
285
- throw e;
286
- }
287
- this.debug('%O\n%O', e, this.callstack);
288
- const baseMessage = `${e.message} in${this.callstack.join('\n| ')}\n`;
289
- const hint = getBrowserOnlyEvalHint(e);
290
- throw new EvalError(hint ? `${baseMessage}${hint}\n` : baseMessage);
291
- } finally {
292
- teardown();
293
- }
294
- }
295
- getEntrypoint(filename, only, log) {
296
- const strippedFilename = stripQueryAndHash(filename);
297
- const extension = path.extname(strippedFilename);
298
- if (extension !== '.json' && !this.extensions.includes(extension)) {
299
- return null;
300
- }
301
- let entrypoint = this.cache.get('entrypoints', filename);
302
- if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {
303
- if (this.cache.checkFreshness(filename, strippedFilename)) {
304
- entrypoint = undefined;
305
- }
306
- if (entrypoint) {
307
- log(' file has been already evaluated');
308
- return entrypoint;
309
- }
310
- }
311
- if (entrypoint?.ignored) {
312
- log('✅ file has been ignored during prepare stage. Original code will be used');
313
- return entrypoint;
314
- }
315
- if (this.ignored) {
316
- log('one of the parent files has been ignored during prepare stage. Original code will be used');
317
- const newEntrypoint = this.entrypoint.createChild(filename, ['*'], fs.readFileSync(strippedFilename, 'utf-8'));
318
- if (newEntrypoint === 'loop') {
319
- const stack = getStack(this.entrypoint);
320
- throw new Error(`Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`);
321
- }
322
- return newEntrypoint;
323
- }
324
- let uncachedExports = null;
325
- let reprocessOnly = only;
326
- // Requested file can be already prepared for evaluation on the stage 1
327
- if (only && entrypoint) {
328
- const evaluatedExports = entrypoint.evaluatedOnly?.length !== 0 ? entrypoint.evaluatedOnly : entrypoint.only ?? [];
329
- uncachedExports = getUncached(evaluatedExports, only);
330
- if (uncachedExports.length === 0) {
331
- log('✅ ready for evaluation');
332
- return entrypoint;
333
- }
334
- if (entrypoint.evaluatedOnly?.length) {
335
- reprocessOnly = mergeOnly(evaluatedExports, only);
336
- }
337
- log('❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)', uncachedExports, evaluatedExports);
338
- } else {
339
- log('❌ file has not been processed during prepare stage');
340
- }
341
-
342
- // If code wasn't extracted from cache, it indicates that we were unable
343
- // to process some of the imports on stage1. Let's try to reprocess.
344
- const code = fs.readFileSync(strippedFilename, 'utf-8');
345
- const newEntrypoint = Entrypoint.createRoot(this.services, filename, reprocessOnly, code);
346
- if (newEntrypoint.evaluated) {
347
- log('✅ file has been already evaluated');
348
- return newEntrypoint;
349
- }
350
- if (newEntrypoint.ignored) {
351
- log('✅ file has been ignored during prepare stage. Original code will be used');
352
- return newEntrypoint;
353
- }
354
- return newEntrypoint;
355
- }
356
- resolveWithConditions(id, parent, conditions) {
357
- const resolveOptions = conditions ? {
358
- conditions
359
- } : undefined;
360
- const shouldRetryWithExtensions = conditions && path.extname(id) === '' && (id.startsWith('.') || path.isAbsolute(id) || isBarePackageSubpath(id));
361
- try {
362
- return this.moduleImpl._resolveFilename(id, parent, false, resolveOptions);
363
- } catch (e) {
364
- if (shouldRetryWithExtensions && e instanceof Error && e.code === 'MODULE_NOT_FOUND') {
365
- // Extensionless subpath requests (e.g. "pkg/src/*" or "./src/*") may
366
- // resolve to extensionless targets via conditional exports. Retry with
367
- // each known extension, but never rewrite already explicit specifiers.
368
- for (const ext of this.extensions) {
369
- try {
370
- return this.moduleImpl._resolveFilename(id + ext, parent, false, resolveOptions);
371
- } catch {
372
- // try next extension
373
- }
374
- }
375
- }
376
- throw e;
377
- }
378
- }
379
- resolveDependency = id => {
380
- const cached = this.entrypoint.getDependency(id);
381
- invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');
382
- if (cached) {
383
- return cached;
384
- }
385
- if (!this.ignored) {
386
- this.debug('❌ import has not been resolved during prepare stage. Fallback to Node.js resolver');
387
- }
388
- const extensions = this.moduleImpl._extensions;
389
- const added = [];
390
- try {
391
- // Check for supported extensions
392
- this.extensions.forEach(ext => {
393
- if (ext in extensions) {
394
- return;
395
- }
396
-
397
- // When an extension is not supported, add it
398
- // And keep track of it to clean it up after resolving
399
- // Use noop for the transform function since we handle it
400
- extensions[ext] = NOOP;
401
- added.push(ext);
402
- });
403
- const {
404
- filename
405
- } = this;
406
- const strippedId = stripQueryAndHash(id);
407
- const parent = {
408
- id: filename,
409
- filename,
410
- paths: this.moduleImpl._nodeModulePaths(path.dirname(filename))
411
- };
412
- const {
413
- conditionNames
414
- } = this.services.options.pluginOptions;
415
- const conditions = conditionNames?.length ? expandConditions(conditionNames) : undefined;
416
- let resolved = this.resolveWithConditions(strippedId, parent, conditions);
417
- const isFileSpecifier = strippedId.startsWith('.') || path.isAbsolute(strippedId);
418
- if (isFileSpecifier && path.extname(strippedId) === '' && resolved.endsWith('.cjs') && fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
419
- // When both `.cjs` and `.js` exist for an extensionless specifier, the
420
- // resolver may pick `.cjs` depending on the environment/extensions.
421
- // Prefer `.js` to keep resolved paths stable (e.g. importOverrides keys).
422
- resolved = `${resolved.slice(0, -4)}.js`;
423
- }
424
- const {
425
- root
426
- } = this.services.options;
427
- const keyInfo = toImportKey({
428
- source: id,
429
- resolved,
430
- root
431
- });
432
- const override = getImportOverride(this.services.options.pluginOptions.importOverrides, keyInfo.key);
433
- const policy = override?.unknown ?? (override?.mock ? 'allow' : 'warn');
434
- const shouldWarn = !this.ignored && policy === 'warn';
435
- let finalResolved = resolved;
436
- if (override?.mock) {
437
- try {
438
- finalResolved = resolveMockSpecifier({
439
- mock: override.mock,
440
- importer: filename,
441
- root,
442
- stack: this.callstack
443
- });
444
- } catch (e) {
445
- const errorMessage = String(e?.message ?? e);
446
- throw new Error(`[wyw-in-js] Failed to resolve import mock for "${keyInfo.key}" (${id} from ${filename}): ${errorMessage}`);
447
- }
448
- }
449
- if (policy === 'error') {
450
- throw new Error([`[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`, ``, `importer: ${filename}`, `source: ${id}`, `resolved: ${resolved}`, override?.mock ? `mock: ${override.mock} -> ${finalResolved}` : ``, ``, `callstack:`, ...this.callstack.map(item => ` ${item}`), ``, `config key: ${keyInfo.key}`].filter(Boolean).join('\n'));
451
- }
452
- const warnedUnknownImports = getWarnedUnknownImports(this.services);
453
- if (shouldWarn && !warnedUnknownImports.has(keyInfo.key)) {
454
- warnedUnknownImports.add(keyInfo.key);
455
- emitWarning(this.services, [`[wyw-in-js] Unknown import reached during eval (Node resolver fallback)`, ``, `importer: ${filename}`, `source: ${id}`, `resolved: ${resolved}`, override?.mock ? `mock: ${override.mock} -> ${finalResolved}` : ``, ``, `callstack:`, ...this.callstack.map(item => ` ${item}`), ``, `config key: ${keyInfo.key}`, `hint: add { importOverrides: { ${JSON.stringify(keyInfo.key)}: { unknown: 'allow' } } } to silence warnings, or use { mock } / { noShake: true } overrides.`].filter(Boolean).join('\n'));
456
- }
457
- return {
458
- source: id,
459
- only: applyImportOverrideToOnly(['*'], override),
460
- resolved: finalResolved
461
- };
462
- } finally {
463
- // Cleanup the extensions we added to restore previous behaviour
464
- added.forEach(ext => delete extensions[ext]);
465
- }
466
- };
467
- createChild(entrypoint) {
468
- return new Module(this.services, entrypoint, this, this.moduleImpl);
469
- }
470
- loadByImportLoaders(request, resolved) {
471
- const {
472
- pluginOptions
473
- } = this.services.options;
474
- const importLoaders = pluginOptions.importLoaders === undefined ? defaultImportLoaders : {
475
- ...defaultImportLoaders,
476
- ...pluginOptions.importLoaders
477
- };
478
- const {
479
- query,
480
- hash
481
- } = parseRequest(request);
482
- if (!query) return {
483
- handled: false,
484
- value: undefined
485
- };
486
- const params = new URLSearchParams(query);
487
- const matchedKey = Array.from(params.keys()).find(key => importLoaders[key] !== undefined && importLoaders[key] !== false);
488
- if (!matchedKey) return {
489
- handled: false,
490
- value: undefined
491
- };
492
- const loader = importLoaders[matchedKey];
493
- const filename = stripQueryAndHash(resolved);
494
- const importer = stripQueryAndHash(this.filename);
495
- const importerDir = path.dirname(importer);
496
- const toUrl = () => {
497
- const relative = path.relative(importerDir, filename).replace(/\\/g, path.posix.sep);
498
- if (relative.startsWith('.') || path.isAbsolute(relative)) {
499
- return relative;
500
- }
501
- return `./${relative}`;
502
- };
503
- const readFile = () => fs.readFileSync(filename, 'utf-8');
504
- const context = {
505
- importer,
506
- request,
507
- resolved,
508
- filename,
509
- query,
510
- hash,
511
- emitWarning: message => emitWarning(this.services, message),
512
- readFile,
513
- toUrl
514
- };
515
- if (loader === 'raw') {
516
- return {
517
- handled: true,
518
- value: context.readFile()
519
- };
520
- }
521
- if (loader === 'url') {
522
- return {
523
- handled: true,
524
- value: context.toUrl()
525
- };
526
- }
527
- if (typeof loader === 'function') {
528
- return {
529
- handled: true,
530
- value: loader(context)
531
- };
532
- }
533
- return {
534
- handled: false,
535
- value: undefined
536
- };
537
- }
201
+ callstack = [];
202
+ debug;
203
+ dependencies;
204
+ extensions;
205
+ filename;
206
+ id;
207
+ idx;
208
+ ignored;
209
+ isEvaluated = false;
210
+ parentIsIgnored;
211
+ require = Object.assign((id, nonLiteral) => this.requireWithFallback(id, this.entrypoint, nonLiteral), {
212
+ ensure: NOOP,
213
+ resolve: (id) => this.resolveRequire(id, this.entrypoint).resolved
214
+ });
215
+ resolve = (id) => this.resolveRequire(id, this.entrypoint).resolved;
216
+ cache;
217
+ context = null;
218
+ teardown = null;
219
+ moduleCache = new Map();
220
+ moduleEntrypoints = new WeakMap();
221
+ moduleLinkPromises = new WeakMap();
222
+ moduleData = new Map();
223
+ #entrypointRef;
224
+ constructor(services, entrypoint, parentModule, moduleImpl = DefaultModuleImplementation) {
225
+ this.services = services;
226
+ this.moduleImpl = moduleImpl;
227
+ this.cache = services.cache;
228
+ this.#entrypointRef = isFeatureEnabled(services.options.pluginOptions.features, "useWeakRefInEval", entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
229
+ this.idx = entrypoint.idx;
230
+ this.id = entrypoint.name;
231
+ this.filename = entrypoint.name;
232
+ this.dependencies = [];
233
+ this.debug = entrypoint.log.extend("module");
234
+ this.parentIsIgnored = parentModule?.ignored ?? false;
235
+ this.ignored = entrypoint.ignored ?? this.parentIsIgnored;
236
+ if (parentModule) {
237
+ this.callstack = [entrypoint.name, ...parentModule.callstack];
238
+ } else {
239
+ this.callstack = [entrypoint.name];
240
+ }
241
+ this.extensions = services.options.pluginOptions.extensions;
242
+ this.debug("init", entrypoint.name);
243
+ }
244
+ get exports() {
245
+ return this.entrypoint.exports;
246
+ }
247
+ set exports(value) {
248
+ this.entrypoint.exports = value;
249
+ this.debug("the whole exports was overridden with %O", value);
250
+ }
251
+ get entrypoint() {
252
+ const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
253
+ invariant(entrypoint, `Module ${this.idx} is disposed`);
254
+ return entrypoint;
255
+ }
256
+ async evaluate() {
257
+ const { entrypoint } = this;
258
+ entrypoint.assertTransformed();
259
+ const cached = this.cache.get("entrypoints", entrypoint.name);
260
+ let evaluatedCreated = false;
261
+ if (!entrypoint.supersededWith) {
262
+ this.cache.add("entrypoints", entrypoint.name, entrypoint.createEvaluated());
263
+ evaluatedCreated = true;
264
+ }
265
+ const { transformedCode: source } = entrypoint;
266
+ if (!source) {
267
+ this.debug(`evaluate`, "there is nothing to evaluate");
268
+ return;
269
+ }
270
+ if (this.isEvaluated) {
271
+ this.debug("evaluate", `is already evaluated`);
272
+ return;
273
+ }
274
+ this.debug("evaluate");
275
+ this.debug.extend("source")("%s", source);
276
+ this.isEvaluated = true;
277
+ const filename = stripQueryAndHash(this.filename);
278
+ if (/\.json$/.test(filename)) {
279
+ // For JSON files, parse it to a JS object similar to Node
280
+ this.exports = JSON.parse(source);
281
+ return;
282
+ }
283
+ const { teardown } = await this.ensureContext(filename);
284
+ try {
285
+ const module = await this.getModuleForEntrypoint(entrypoint);
286
+ await this.linkModule(module);
287
+ await module.evaluate();
288
+ const exports = applyModuleNamespace(entrypoint.exports, module, this.getModuleData(entrypoint.name));
289
+ if (exports !== entrypoint.exports) {
290
+ entrypoint.exports = exports;
291
+ }
292
+ } catch (e) {
293
+ this.isEvaluated = false;
294
+ if (evaluatedCreated) {
295
+ this.cache.add("entrypoints", entrypoint.name, cached);
296
+ }
297
+ if (isUnprocessedEntrypointError(e)) {
298
+ // It will be handled by evalFile scenario
299
+ throw e;
300
+ }
301
+ if (e instanceof EvalError) {
302
+ this.debug("%O", e);
303
+ throw e;
304
+ }
305
+ this.debug("%O\n%O", e, this.callstack);
306
+ const baseMessage = `${e.message} in${this.callstack.join("\n| ")}\n`;
307
+ const hint = getBrowserOnlyEvalHint(e);
308
+ throw new EvalError(hint ? `${baseMessage}${hint}\n` : baseMessage);
309
+ } finally {
310
+ teardown();
311
+ }
312
+ }
313
+ getEntrypoint(filename, only, log) {
314
+ const strippedFilename = stripQueryAndHash(filename);
315
+ const extension = path.extname(strippedFilename);
316
+ if (extension !== ".json" && !this.extensions.includes(extension)) {
317
+ return null;
318
+ }
319
+ let entrypoint = this.cache.get("entrypoints", filename);
320
+ if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {
321
+ if (this.cache.checkFreshness(filename, strippedFilename)) {
322
+ entrypoint = undefined;
323
+ }
324
+ if (entrypoint) {
325
+ log("✅ file has been already evaluated");
326
+ return entrypoint;
327
+ }
328
+ }
329
+ if (entrypoint?.ignored) {
330
+ log("✅ file has been ignored during prepare stage. Original code will be used");
331
+ return entrypoint;
332
+ }
333
+ if (this.ignored) {
334
+ log("✅ one of the parent files has been ignored during prepare stage. Original code will be used");
335
+ const newEntrypoint = this.entrypoint.createChild(filename, ["*"], fs.readFileSync(strippedFilename, "utf-8"));
336
+ if (newEntrypoint === "loop") {
337
+ const stack = getStack(this.entrypoint);
338
+ throw new Error(`Circular dependency detected: ${stack.join(" -> ")} -> ${filename}`);
339
+ }
340
+ return newEntrypoint;
341
+ }
342
+ let uncachedExports = null;
343
+ let reprocessOnly = only;
344
+ let cachedSource;
345
+ // Requested file can be already prepared for evaluation on the stage 1
346
+ if (only && entrypoint) {
347
+ const evaluatedExports = entrypoint.evaluatedOnly?.length !== 0 ? entrypoint.evaluatedOnly : entrypoint.only ?? [];
348
+ uncachedExports = getUncached(evaluatedExports, only);
349
+ if (uncachedExports.length === 0) {
350
+ log("✅ ready for evaluation");
351
+ return entrypoint;
352
+ }
353
+ if (entrypoint.evaluatedOnly?.length) {
354
+ if (this.cache.checkFreshness(filename, strippedFilename)) {
355
+ entrypoint = undefined;
356
+ uncachedExports = null;
357
+ } else {
358
+ reprocessOnly = mergeOnly(evaluatedExports, only);
359
+ cachedSource = entrypoint.loadedAndParsed?.code ?? entrypoint.initialCode;
360
+ }
361
+ }
362
+ if (entrypoint) {
363
+ log("❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)", uncachedExports, evaluatedExports);
364
+ } else {
365
+ log("❌ file has not been processed during prepare stage");
366
+ }
367
+ } else {
368
+ log("❌ file has not been processed during prepare stage");
369
+ }
370
+ // If code wasn't extracted from cache, it indicates that we were unable
371
+ // to process some of the imports on stage1. Let's try to reprocess.
372
+ const code = cachedSource ?? fs.readFileSync(strippedFilename, "utf-8");
373
+ const newEntrypoint = Entrypoint.createRoot(this.services, filename, reprocessOnly, code);
374
+ if (newEntrypoint.evaluated) {
375
+ log("✅ file has been already evaluated");
376
+ return newEntrypoint;
377
+ }
378
+ if (newEntrypoint.ignored) {
379
+ log("file has been ignored during prepare stage. Original code will be used");
380
+ return newEntrypoint;
381
+ }
382
+ return newEntrypoint;
383
+ }
384
+ async ensureContext(filename) {
385
+ if (this.context && this.teardown) {
386
+ return {
387
+ context: this.context,
388
+ teardown: this.teardown
389
+ };
390
+ }
391
+ const evalOptions = getEvalOptions(this.services);
392
+ const { context, teardown } = await createVmContext(filename, this.services.options.pluginOptions.features, {
393
+ ...evalOptions.globals ?? {},
394
+ __wyw_getModule: (id) => this.getModuleData(id)
395
+ }, this.services.options.pluginOptions.overrideContext);
396
+ this.context = context;
397
+ this.teardown = () => {
398
+ teardown();
399
+ this.context = null;
400
+ this.teardown = null;
401
+ };
402
+ return {
403
+ context: this.context,
404
+ teardown: this.teardown
405
+ };
406
+ }
407
+ getModuleData(id) {
408
+ const data = this.moduleData.get(id);
409
+ invariant(data, `Missing module data for ${id}`);
410
+ return data;
411
+ }
412
+ createModuleData(id, entrypoint) {
413
+ const cached = this.moduleData.get(id);
414
+ if (cached) return cached;
415
+ const exporter = entrypoint ?? this.entrypoint;
416
+ const exportsProxy = entrypoint && "exports" in entrypoint ? entrypoint.exports : {};
417
+ const moduleObj = { exports: exportsProxy };
418
+ const requireFn = Object.assign((request) => this.requireWithFallback(request, exporter), {
419
+ ensure: NOOP,
420
+ resolve: (request) => this.resolveRequire(request, exporter).resolved
421
+ });
422
+ const filename = stripQueryAndHash(id);
423
+ const data = {
424
+ exports: exportsProxy,
425
+ module: moduleObj,
426
+ require: requireFn,
427
+ filename,
428
+ dirname: path.dirname(filename),
429
+ dynamicImport: (request) => this.dynamicImportFrom(exporter, request)
430
+ };
431
+ this.moduleData.set(id, data);
432
+ return data;
433
+ }
434
+ async createSourceTextModule(id, code, entrypoint) {
435
+ ensureVmModules();
436
+ const { context } = await this.ensureContext(stripQueryAndHash(id));
437
+ this.createModuleData(id, entrypoint);
438
+ const module = new vm.SourceTextModule(`${buildModulePreamble(id)}${code}`, {
439
+ context,
440
+ identifier: id,
441
+ initializeImportMeta: (meta, targetModule) => {
442
+ const identifier = typeof targetModule.identifier === "string" ? targetModule.identifier : id;
443
+ const fileId = stripQueryAndHash(identifier);
444
+ Object.assign(meta, { url: path.isAbsolute(fileId) ? pathToFileURL(fileId).href : fileId });
445
+ },
446
+ importModuleDynamically: (specifier, referencingModule) => this.importModuleDynamically(specifier, referencingModule)
447
+ });
448
+ this.moduleCache.set(id, module);
449
+ if (entrypoint) {
450
+ this.moduleEntrypoints.set(module, entrypoint);
451
+ }
452
+ return module;
453
+ }
454
+ async createSyntheticModule(id, exportsValue) {
455
+ ensureVmModules();
456
+ const { context } = await this.ensureContext(stripQueryAndHash(id));
457
+ const exportNames = new Set(Object.keys(exportsValue));
458
+ const hasDefault = Object.prototype.hasOwnProperty.call(exportsValue, "default");
459
+ if (!exportNames.has("default")) {
460
+ exportNames.add("default");
461
+ }
462
+ const module = new vm.SyntheticModule([...exportNames], function init() {
463
+ exportNames.forEach((key) => {
464
+ const value = key === "default" && !hasDefault ? exportsValue : exportsValue[key];
465
+ this.setExport(key, value);
466
+ });
467
+ }, {
468
+ context,
469
+ identifier: id
470
+ });
471
+ this.moduleCache.set(id, module);
472
+ return module;
473
+ }
474
+ async getVirtualModule(specifier) {
475
+ if (specifier === REACT_REFRESH_VIRTUAL_ID) {
476
+ return this.createSyntheticModule(specifier, { createSignatureFunctionForTransform: reactRefreshRuntime.createSignatureFunctionForTransform });
477
+ }
478
+ if (specifier.startsWith(VITE_VIRTUAL_PREFIX)) {
479
+ return this.createSyntheticModule(specifier, { default: {} });
480
+ }
481
+ if (specifier.startsWith("virtual:")) {
482
+ return this.createSyntheticModule(specifier, { default: {} });
483
+ }
484
+ return null;
485
+ }
486
+ async getModuleForEntrypoint(entrypoint) {
487
+ const cached = this.moduleCache.get(entrypoint.name);
488
+ if (cached) return cached;
489
+ if (!(entrypoint instanceof Entrypoint)) {
490
+ return this.createSyntheticModule(entrypoint.name, entrypoint.exports);
491
+ }
492
+ entrypoint.assertTransformed();
493
+ const source = entrypoint.transformedCode ?? "";
494
+ return this.createSourceTextModule(entrypoint.name, source, entrypoint);
495
+ }
496
+ async linkModule(module) {
497
+ const cached = this.moduleLinkPromises.get(module);
498
+ if (cached) {
499
+ await cached;
500
+ return;
501
+ }
502
+ if (module.status !== "unlinked") {
503
+ return;
504
+ }
505
+ const linking = module.link((specifier, referencingModule) => this.getModuleForSpecifier(specifier, referencingModule, "import"));
506
+ this.moduleLinkPromises.set(module, linking);
507
+ await linking;
508
+ }
509
+ async importModuleDynamically(specifier, referencingModule) {
510
+ const module = await this.getModuleForSpecifier(specifier, referencingModule, "dynamic-import");
511
+ await this.linkModule(module);
512
+ if (module.status === "linked") {
513
+ await module.evaluate();
514
+ }
515
+ return module;
516
+ }
517
+ async dynamicImportFrom(importer, id) {
518
+ const specifier = String(id);
519
+ const module = await this.getModuleForSpecifierFromEntrypoint(specifier, importer, "dynamic-import");
520
+ await this.linkModule(module);
521
+ if (module.status === "linked") {
522
+ await module.evaluate();
523
+ }
524
+ return module.namespace;
525
+ }
526
+ async getModuleForSpecifier(specifier, referencingModule, kind) {
527
+ const importer = this.moduleEntrypoints.get(referencingModule) ?? this.entrypoint;
528
+ return this.getModuleForSpecifierFromEntrypoint(specifier, importer, kind);
529
+ }
530
+ async getModuleForSpecifierFromEntrypoint(specifier, importer, kind) {
531
+ const virtualModule = await this.getVirtualModule(specifier);
532
+ if (virtualModule) {
533
+ return virtualModule;
534
+ }
535
+ this.dependencies.push(specifier);
536
+ const resolved = await this.resolveImport(specifier, importer, kind);
537
+ const evalOptions = getEvalOptions(this.services);
538
+ if (!resolved) {
539
+ if (evalOptions.errors === "loose") {
540
+ return this.createSyntheticModule(specifier, { default: undefined });
541
+ }
542
+ throw new Error([
543
+ `[wyw-in-js] Unable to resolve "${specifier}" during evaluation.`,
544
+ ``,
545
+ `importer: ${importer.name}`,
546
+ `hint: check eval.resolver/customResolver or add importOverrides for this specifier.`,
547
+ `docs: ${TROUBLESHOOTING_URL}`
548
+ ].join("\n"));
549
+ }
550
+ if (resolved.external) {
551
+ return this.createSyntheticModule(resolved.resolved, { default: undefined });
552
+ }
553
+ return this.getModuleForResolved(resolved, importer);
554
+ }
555
+ async resolveImport(specifier, importer, kind) {
556
+ const evalOptions = getEvalOptions(this.services);
557
+ if (evalOptions.customResolver) {
558
+ const customResolved = await evalOptions.customResolver(specifier, importer.name, kind);
559
+ if (customResolved) {
560
+ return this.applyImportOverrides({
561
+ source: specifier,
562
+ resolved: customResolved.id,
563
+ only: ["*"],
564
+ external: customResolved.external
565
+ }, importer);
566
+ }
567
+ if (evalOptions.resolver === "custom") {
568
+ return null;
569
+ }
570
+ }
571
+ const resolveBundlerDependency = () => {
572
+ const dependency = getImporterDependency(importer, specifier);
573
+ if (dependency?.resolved) {
574
+ return {
575
+ source: specifier,
576
+ resolved: dependency.resolved,
577
+ only: dependency.only
578
+ };
579
+ }
580
+ return null;
581
+ };
582
+ if (evalOptions.resolver === "hybrid") {
583
+ try {
584
+ return this.resolveWithNativeFallback(specifier, importer, kind, { warnOnFallback: false });
585
+ } catch {}
586
+ }
587
+ if (evalOptions.resolver === "native") {
588
+ return this.resolveWithNativeFallback(specifier, importer, kind, { warnOnFallback: false });
589
+ }
590
+ if (evalOptions.resolver === "bundler" || evalOptions.resolver === "hybrid") {
591
+ const dependency = resolveBundlerDependency();
592
+ if (dependency) return dependency;
593
+ }
594
+ if (evalOptions.resolver === "bundler" && evalOptions.require !== "off") {
595
+ return this.resolveWithNativeFallback(specifier, importer, kind, { warnOnFallback: true });
596
+ }
597
+ return null;
598
+ }
599
+ resolveRequire(specifier, importer) {
600
+ const dependency = getImporterDependency(importer, specifier);
601
+ if (dependency?.resolved) {
602
+ return this.applyImportOverrides({
603
+ source: specifier,
604
+ resolved: dependency.resolved,
605
+ only: dependency.only
606
+ }, importer);
607
+ }
608
+ return this.resolveWithNativeFallback(specifier, importer, "require", { warnOnFallback: true });
609
+ }
610
+ applyImportOverrides(resolved, importer) {
611
+ const { root } = this.services.options;
612
+ const keyInfo = toImportKey({
613
+ source: resolved.source,
614
+ resolved: resolved.resolved,
615
+ root
616
+ });
617
+ const override = getImportOverride(this.services.options.pluginOptions.importOverrides, keyInfo.key);
618
+ if (!override) {
619
+ return resolved;
620
+ }
621
+ let nextResolved = resolved.resolved;
622
+ if (override.mock) {
623
+ nextResolved = resolveMockSpecifier({
624
+ mock: override.mock,
625
+ importer: importer.name,
626
+ root,
627
+ stack: getStack(importer)
628
+ });
629
+ }
630
+ return {
631
+ ...resolved,
632
+ resolved: nextResolved,
633
+ only: applyImportOverrideToOnly(resolved.only, override)
634
+ };
635
+ }
636
+ async getModuleForResolved(resolved, importer) {
637
+ const cached = this.moduleCache.get(resolved.resolved);
638
+ if (cached) return cached;
639
+ const evalOptions = getEvalOptions(this.services);
640
+ if (evalOptions.customLoader) {
641
+ const loaded = await evalOptions.customLoader(resolved.resolved);
642
+ if (loaded) {
643
+ if (loaded.loader === "json") {
644
+ const jsonValue = JSON.parse(loaded.code);
645
+ return this.createSyntheticModule(resolved.resolved, { default: jsonValue });
646
+ }
647
+ if (loaded.loader === "raw" || loaded.loader === "text") {
648
+ return this.createSyntheticModule(resolved.resolved, { default: loaded.code });
649
+ }
650
+ return this.createSourceTextModule(resolved.resolved, loaded.code, importer);
651
+ }
652
+ }
653
+ const loaded = this.loadByImportLoaders(resolved.source, resolved.resolved, importer.name);
654
+ if (loaded.handled) {
655
+ return this.createSyntheticModule(resolved.resolved, { default: loaded.value });
656
+ }
657
+ const stripped = stripQueryAndHash(resolved.resolved);
658
+ if (stripped.endsWith(".json")) {
659
+ const jsonSource = fs.readFileSync(stripped, "utf-8");
660
+ return this.createSyntheticModule(resolved.resolved, { default: JSON.parse(jsonSource) });
661
+ }
662
+ const entrypoint = this.getEntrypoint(resolved.resolved, resolved.only, importer.log);
663
+ if (!entrypoint) {
664
+ return this.createSyntheticModule(resolved.resolved, { default: resolved.resolved });
665
+ }
666
+ if ("evaluated" in entrypoint && entrypoint.evaluated) {
667
+ return this.createSyntheticModule(entrypoint.name, entrypoint.exports);
668
+ }
669
+ return this.getModuleForEntrypoint(entrypoint);
670
+ }
671
+ resolveWithConditions(id, parent, conditions) {
672
+ const shouldRetryWithExtensions = conditions && path.extname(id) === "" && (id.startsWith(".") || path.isAbsolute(id) || isBarePackageSubpath(id));
673
+ try {
674
+ return resolveFilenameWithConditions(this.moduleImpl, id, parent, conditions);
675
+ } catch (error) {
676
+ if (shouldRetryWithExtensions && error instanceof Error && error.code === "MODULE_NOT_FOUND") {
677
+ for (const ext of this.extensions) {
678
+ try {
679
+ return resolveFilenameWithConditions(this.moduleImpl, `${id}${ext}`, parent, conditions);
680
+ } catch {}
681
+ }
682
+ }
683
+ throw error;
684
+ }
685
+ }
686
+ resolveWithNativeFallback = (id, importer, kind, { warnOnFallback } = { warnOnFallback: true }) => {
687
+ if (!this.ignored && warnOnFallback) {
688
+ this.debug("❌ import has not been resolved during prepare stage. Fallback to native resolver");
689
+ }
690
+ const extensions = this.moduleImpl._extensions;
691
+ const added = [];
692
+ try {
693
+ const filename = importer.name;
694
+ const strippedId = stripQueryAndHash(id);
695
+ const { conditionNames, oxcOptions } = this.services.options.pluginOptions;
696
+ let resolved;
697
+ try {
698
+ if (this.moduleImpl === DefaultModuleImplementation) {
699
+ resolved = resolveWithNativeResolver({
700
+ conditionNames,
701
+ extensions: this.extensions,
702
+ importer: filename,
703
+ kind,
704
+ oxcOptions,
705
+ specifier: id
706
+ });
707
+ } else {
708
+ // Preserve the test-only custom module implementation hook.
709
+ this.extensions.forEach((ext) => {
710
+ if (ext === ".cjs" || ext === ".mjs") return;
711
+ if (ext in extensions) return;
712
+ extensions[ext] = NOOP;
713
+ added.push(ext);
714
+ });
715
+ const parent = {
716
+ id: filename,
717
+ filename,
718
+ paths: this.moduleImpl._nodeModulePaths(path.dirname(filename))
719
+ };
720
+ const conditions = conditionNames?.length ? expandConditions(conditionNames) : undefined;
721
+ resolved = this.resolveWithConditions(strippedId, parent, conditions);
722
+ const isFileSpecifier = strippedId.startsWith(".") || path.isAbsolute(strippedId);
723
+ if (isFileSpecifier && path.extname(strippedId) === "" && resolved.endsWith(".cjs") && fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
724
+ resolved = `${resolved.slice(0, -4)}.js`;
725
+ }
726
+ }
727
+ } catch (error) {
728
+ throw new Error([
729
+ `[wyw-in-js] Native resolver failed during eval.`,
730
+ ``,
731
+ `importer: ${filename}`,
732
+ `source: ${id}`,
733
+ ``,
734
+ `error: ${error instanceof Error ? error.message : String(error)}`
735
+ ].join("\n"));
736
+ }
737
+ const { root } = this.services.options;
738
+ const keyInfo = toImportKey({
739
+ source: id,
740
+ resolved,
741
+ root
742
+ });
743
+ const override = getImportOverride(this.services.options.pluginOptions.importOverrides, keyInfo.key);
744
+ const evalOptions = getEvalOptions(this.services);
745
+ const basePolicy = evalOptions.require === "warn-and-run" ? "warn" : "error";
746
+ let policy = warnOnFallback ? override?.unknown ?? (override?.mock ? "allow" : basePolicy) : "allow";
747
+ if (warnOnFallback && evalOptions.require === "off" && policy !== "error") {
748
+ policy = "error";
749
+ }
750
+ const shouldWarn = !this.ignored && policy === "warn";
751
+ let finalResolved = resolved;
752
+ if (override?.mock) {
753
+ try {
754
+ finalResolved = resolveMockSpecifier({
755
+ mock: override.mock,
756
+ importer: filename,
757
+ root,
758
+ stack: getStack(importer)
759
+ });
760
+ } catch (e) {
761
+ const errorMessage = String(e?.message ?? e);
762
+ throw new Error(`[wyw-in-js] Failed to resolve import mock for "${keyInfo.key}" (${id} from ${filename}): ${errorMessage}`);
763
+ }
764
+ }
765
+ if (policy === "error") {
766
+ throw new Error([
767
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
768
+ ``,
769
+ `importer: ${filename}`,
770
+ `source: ${id}`,
771
+ `resolved: ${resolved}`,
772
+ override?.mock ? `mock: ${override.mock} -> ${finalResolved}` : ``,
773
+ ``,
774
+ `callstack:`,
775
+ ...getStack(importer).map((item) => ` ${item}`),
776
+ ``,
777
+ `config key: ${keyInfo.key}`,
778
+ `docs: ${TROUBLESHOOTING_URL}`
779
+ ].filter(Boolean).join("\n"));
780
+ }
781
+ const warnedUnknownImports = getWarnedUnknownImports(this.services);
782
+ if (shouldWarn && !warnedUnknownImports.has(keyInfo.key)) {
783
+ warnedUnknownImports.add(keyInfo.key);
784
+ const warningMessage = [
785
+ `[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
786
+ ``,
787
+ `importer: ${filename}`,
788
+ `source: ${id}`,
789
+ `resolved: ${resolved}`,
790
+ override?.mock ? `mock: ${override.mock} -> ${finalResolved}` : ``,
791
+ ``,
792
+ `callstack:`,
793
+ ...getStack(importer).map((item) => ` ${item}`),
794
+ ``,
795
+ `config key: ${keyInfo.key}`,
796
+ `hint: add { importOverrides: { ${JSON.stringify(keyInfo.key)}: { unknown: 'allow' } } } to silence warnings, or use { mock } / { noShake: true } overrides.`,
797
+ `docs: ${TROUBLESHOOTING_URL}`
798
+ ].filter(Boolean).join("\n");
799
+ emitEvalWarning(this.services, {
800
+ code: kind === "require" ? "require-fallback" : "resolve-fallback",
801
+ message: warningMessage,
802
+ importer: filename,
803
+ specifier: id,
804
+ resolved: resolved ?? null,
805
+ callstack: getStack(importer),
806
+ hint: `Use importOverrides or eval.require settings to avoid fallback.`
807
+ });
808
+ }
809
+ return {
810
+ source: id,
811
+ only: applyImportOverrideToOnly(["*"], override),
812
+ resolved: finalResolved
813
+ };
814
+ } finally {
815
+ // Cleanup the extensions we added to restore previous behaviour
816
+ added.forEach((ext) => delete extensions[ext]);
817
+ }
818
+ };
819
+ requireWithFallback(id, importer, nonLiteral = false) {
820
+ const evalOptions = getEvalOptions(this.services);
821
+ if (nonLiteral || typeof id !== "string") {
822
+ if (evalOptions.errors === "strict") {
823
+ throw new Error(`[wyw-in-js] Non-literal require() is not supported during eval.\n` + `importer: ${importer.name}\n` + `hint: make it a string literal or mock the import via importOverrides.`);
824
+ }
825
+ emitEvalWarning(this.services, {
826
+ code: "require-error",
827
+ message: "[wyw-in-js] Non-literal require() reached during eval (eval.errors: \"loose\").",
828
+ importer: importer.name
829
+ });
830
+ return {};
831
+ }
832
+ const specifier = id;
833
+ if (id === REACT_REFRESH_VIRTUAL_ID) {
834
+ this.dependencies.push(id);
835
+ this.debug("require", `vite virtual '${id}'`);
836
+ return reactRefreshRuntime;
837
+ }
838
+ if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
839
+ this.dependencies.push(id);
840
+ this.debug("require", `vite virtual '${id}'`);
841
+ return {};
842
+ }
843
+ const normalizedId = specifier.startsWith("node:") ? specifier.slice(5) : specifier;
844
+ if (NativeModule.builtinModules?.includes(normalizedId) || NativeModule.builtinModules?.includes(`node:${normalizedId}`)) {
845
+ if (normalizedId in builtins) {
846
+ if (builtins[normalizedId]) {
847
+ this.debug("require", `builtin '${normalizedId}'`);
848
+ return nodeRequire(normalizedId);
849
+ }
850
+ return null;
851
+ }
852
+ throw new Error(`Unable to import "${normalizedId}". Importing Node builtins is not supported in the sandbox.`);
853
+ }
854
+ const dependency = this.resolveRequire(specifier, importer);
855
+ const loaded = this.loadByImportLoaders(specifier, dependency.resolved, importer.name);
856
+ if (loaded.handled) {
857
+ this.dependencies.push(id);
858
+ this.debug("require", `${id} -> ${dependency.resolved} (loader)`);
859
+ return loaded.value;
860
+ }
861
+ const stripped = stripQueryAndHash(dependency.resolved);
862
+ const extension = path.extname(stripped);
863
+ if (extension && extension !== ".json" && !this.extensions.includes(extension)) {
864
+ this.dependencies.push(id);
865
+ this.debug("require", `${id} -> ${dependency.resolved} (asset)`);
866
+ return stripped;
867
+ }
868
+ if (this.services.cache.consumeInvalidation(dependency.resolved)) {
869
+ delete nodeRequire.cache[dependency.resolved];
870
+ }
871
+ this.dependencies.push(id);
872
+ this.debug("require", `${id} -> ${dependency.resolved}`);
873
+ return nodeRequire(dependency.resolved);
874
+ }
875
+ createChild(entrypoint) {
876
+ return new Module(this.services, entrypoint, this, this.moduleImpl);
877
+ }
878
+ loadByImportLoaders(request, resolved, importer) {
879
+ const { pluginOptions } = this.services.options;
880
+ const importLoaders = pluginOptions.importLoaders === undefined ? defaultImportLoaders : {
881
+ ...defaultImportLoaders,
882
+ ...pluginOptions.importLoaders
883
+ };
884
+ const { query, hash } = parseRequest(request);
885
+ if (!query) return {
886
+ handled: false,
887
+ value: undefined
888
+ };
889
+ const params = new URLSearchParams(query);
890
+ const matchedKey = Array.from(params.keys()).find((key) => importLoaders[key] !== undefined && importLoaders[key] !== false);
891
+ if (!matchedKey) return {
892
+ handled: false,
893
+ value: undefined
894
+ };
895
+ const loader = importLoaders[matchedKey];
896
+ const filename = stripQueryAndHash(resolved);
897
+ const importerFilename = stripQueryAndHash(importer);
898
+ const importerDir = path.dirname(importerFilename);
899
+ const toUrl = () => {
900
+ const relative = path.relative(importerDir, filename).replace(/\\/g, path.posix.sep);
901
+ if (relative.startsWith(".") || path.isAbsolute(relative)) {
902
+ return relative;
903
+ }
904
+ return `./${relative}`;
905
+ };
906
+ const readFile = () => fs.readFileSync(filename, "utf-8");
907
+ const context = {
908
+ importer: importerFilename,
909
+ request,
910
+ resolved,
911
+ filename,
912
+ query,
913
+ hash,
914
+ emitWarning: (message) => emitWarning(this.services, message),
915
+ readFile,
916
+ toUrl
917
+ };
918
+ if (loader === "raw") {
919
+ return {
920
+ handled: true,
921
+ value: context.readFile()
922
+ };
923
+ }
924
+ if (loader === "url") {
925
+ return {
926
+ handled: true,
927
+ value: context.toUrl()
928
+ };
929
+ }
930
+ if (typeof loader === "function") {
931
+ return {
932
+ handled: true,
933
+ value: loader(context)
934
+ };
935
+ }
936
+ return {
937
+ handled: false,
938
+ value: undefined
939
+ };
940
+ }
538
941
  }
539
- //# sourceMappingURL=module.js.map
942
+ //# sourceMappingURL=module.js.map