vxrn 1.27.1 → 2.0.0-beta.45.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 (456) hide show
  1. package/dist/cli.mjs +212 -261
  2. package/dist/cli.mjs.map +1 -1
  3. package/dist/cli.native.js +216 -265
  4. package/dist/cli.native.js.map +1 -1
  5. package/dist/config/getAdditionalViteConfig.mjs +33 -62
  6. package/dist/config/getAdditionalViteConfig.mjs.map +1 -1
  7. package/dist/config/getAdditionalViteConfig.native.js +33 -62
  8. package/dist/config/getAdditionalViteConfig.native.js.map +1 -1
  9. package/dist/config/getBaseViteConfigOnly.mjs +84 -77
  10. package/dist/config/getBaseViteConfigOnly.mjs.map +1 -1
  11. package/dist/config/getBaseViteConfigOnly.native.js +86 -79
  12. package/dist/config/getBaseViteConfigOnly.native.js.map +1 -1
  13. package/dist/config/getBaseViteConfigWithPlugins.mjs +6 -4
  14. package/dist/config/getBaseViteConfigWithPlugins.mjs.map +1 -1
  15. package/dist/config/getBaseViteConfigWithPlugins.native.js +6 -4
  16. package/dist/config/getBaseViteConfigWithPlugins.native.js.map +1 -1
  17. package/dist/config/getBaseVitePlugins.mjs +102 -130
  18. package/dist/config/getBaseVitePlugins.mjs.map +1 -1
  19. package/dist/config/getBaseVitePlugins.native.js +123 -152
  20. package/dist/config/getBaseVitePlugins.native.js.map +1 -1
  21. package/dist/config/getNonCliModeOnlyVitePlugins.mjs +3 -3
  22. package/dist/config/getNonCliModeOnlyVitePlugins.mjs.map +1 -1
  23. package/dist/config/getNonCliModeOnlyVitePlugins.native.js +3 -1
  24. package/dist/config/getNonCliModeOnlyVitePlugins.native.js.map +1 -1
  25. package/dist/config/getOptimizeDeps.mjs +138 -42
  26. package/dist/config/getOptimizeDeps.mjs.map +1 -1
  27. package/dist/config/getOptimizeDeps.native.js +138 -42
  28. package/dist/config/getOptimizeDeps.native.js.map +1 -1
  29. package/dist/config/getOptionsFilled.mjs +48 -52
  30. package/dist/config/getOptionsFilled.mjs.map +1 -1
  31. package/dist/config/getOptionsFilled.native.js +51 -55
  32. package/dist/config/getOptionsFilled.native.js.map +1 -1
  33. package/dist/config/getReactNativePlugins.mjs +23 -15
  34. package/dist/config/getReactNativePlugins.mjs.map +1 -1
  35. package/dist/config/getReactNativePlugins.native.js +25 -16
  36. package/dist/config/getReactNativePlugins.native.js.map +1 -1
  37. package/dist/config/getServerOptionsFilled.mjs +33 -35
  38. package/dist/config/getServerOptionsFilled.mjs.map +1 -1
  39. package/dist/config/getServerOptionsFilled.native.js +35 -38
  40. package/dist/config/getServerOptionsFilled.native.js.map +1 -1
  41. package/dist/config/getViteServerConfig.mjs +34 -45
  42. package/dist/config/getViteServerConfig.mjs.map +1 -1
  43. package/dist/config/getViteServerConfig.native.js +35 -46
  44. package/dist/config/getViteServerConfig.native.js.map +1 -1
  45. package/dist/config/mergeUserConfig.mjs +50 -28
  46. package/dist/config/mergeUserConfig.mjs.map +1 -1
  47. package/dist/config/mergeUserConfig.native.js +60 -38
  48. package/dist/config/mergeUserConfig.native.js.map +1 -1
  49. package/dist/constants/defaults.mjs +29 -12
  50. package/dist/constants/defaults.mjs.map +1 -1
  51. package/dist/constants/defaults.native.js +29 -12
  52. package/dist/constants/defaults.native.js.map +1 -1
  53. package/dist/constants.mjs +41 -6
  54. package/dist/constants.mjs.map +1 -1
  55. package/dist/constants.native.js +41 -6
  56. package/dist/constants.native.js.map +1 -1
  57. package/dist/exports/build.mjs +218 -270
  58. package/dist/exports/build.mjs.map +1 -1
  59. package/dist/exports/build.native.js +226 -283
  60. package/dist/exports/build.native.js.map +1 -1
  61. package/dist/exports/clean.mjs +71 -78
  62. package/dist/exports/clean.mjs.map +1 -1
  63. package/dist/exports/clean.native.js +76 -90
  64. package/dist/exports/clean.native.js.map +1 -1
  65. package/dist/exports/createServer.mjs +43 -46
  66. package/dist/exports/createServer.mjs.map +1 -1
  67. package/dist/exports/createServer.native.js +45 -48
  68. package/dist/exports/createServer.native.js.map +1 -1
  69. package/dist/exports/dev.mjs +177 -201
  70. package/dist/exports/dev.mjs.map +1 -1
  71. package/dist/exports/dev.native.js +191 -215
  72. package/dist/exports/dev.native.js.map +1 -1
  73. package/dist/exports/loadEnv.mjs +51 -48
  74. package/dist/exports/loadEnv.mjs.map +1 -1
  75. package/dist/exports/loadEnv.native.js +59 -57
  76. package/dist/exports/loadEnv.native.js.map +1 -1
  77. package/dist/exports/patch.mjs +9 -7
  78. package/dist/exports/patch.mjs.map +1 -1
  79. package/dist/exports/patch.native.js +9 -7
  80. package/dist/exports/patch.native.js.map +1 -1
  81. package/dist/exports/prebuild.mjs +177 -157
  82. package/dist/exports/prebuild.mjs.map +1 -1
  83. package/dist/exports/prebuild.native.js +197 -160
  84. package/dist/exports/prebuild.native.js.map +1 -1
  85. package/dist/exports/prebuildWithoutExpo.mjs +46 -44
  86. package/dist/exports/prebuildWithoutExpo.mjs.map +1 -1
  87. package/dist/exports/prebuildWithoutExpo.native.js +48 -46
  88. package/dist/exports/prebuildWithoutExpo.native.js.map +1 -1
  89. package/dist/exports/runAndroid.mjs +9 -10
  90. package/dist/exports/runAndroid.mjs.map +1 -1
  91. package/dist/exports/runAndroid.native.js +10 -11
  92. package/dist/exports/runAndroid.native.js.map +1 -1
  93. package/dist/exports/runIos.mjs +9 -10
  94. package/dist/exports/runIos.mjs.map +1 -1
  95. package/dist/exports/runIos.native.js +10 -11
  96. package/dist/exports/runIos.native.js.map +1 -1
  97. package/dist/exports/serve.mjs +23 -31
  98. package/dist/exports/serve.mjs.map +1 -1
  99. package/dist/exports/serve.native.js +26 -34
  100. package/dist/exports/serve.native.js.map +1 -1
  101. package/dist/exports/serveStaticAssets.mjs +109 -113
  102. package/dist/exports/serveStaticAssets.mjs.map +1 -1
  103. package/dist/exports/serveStaticAssets.native.js +180 -192
  104. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  105. package/dist/index.js +25 -14
  106. package/dist/index.mjs +25 -14
  107. package/dist/index.native.js +25 -14
  108. package/dist/patches/builtInDepPatches.mjs +346 -435
  109. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  110. package/dist/patches/builtInDepPatches.native.js +349 -438
  111. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  112. package/dist/plugins/applyBuiltInPatchesPlugin.mjs +11 -11
  113. package/dist/plugins/applyBuiltInPatchesPlugin.mjs.map +1 -1
  114. package/dist/plugins/applyBuiltInPatchesPlugin.native.js +11 -11
  115. package/dist/plugins/applyBuiltInPatchesPlugin.native.js.map +1 -1
  116. package/dist/plugins/autoDepOptimizePlugin.mjs +87 -90
  117. package/dist/plugins/autoDepOptimizePlugin.mjs.map +1 -1
  118. package/dist/plugins/autoDepOptimizePlugin.native.js +99 -102
  119. package/dist/plugins/autoDepOptimizePlugin.native.js.map +1 -1
  120. package/dist/plugins/clientInjectPlugin.mjs +13 -11
  121. package/dist/plugins/clientInjectPlugin.mjs.map +1 -1
  122. package/dist/plugins/clientInjectPlugin.native.js +13 -11
  123. package/dist/plugins/clientInjectPlugin.native.js.map +1 -1
  124. package/dist/plugins/defaultDepOptimizePlugin.mjs +15 -23
  125. package/dist/plugins/defaultDepOptimizePlugin.mjs.map +1 -1
  126. package/dist/plugins/defaultDepOptimizePlugin.native.js +15 -23
  127. package/dist/plugins/defaultDepOptimizePlugin.native.js.map +1 -1
  128. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs +163 -179
  129. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs.map +1 -1
  130. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js +169 -191
  131. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js.map +1 -1
  132. package/dist/plugins/getResolvedConfigSubset.mjs +6 -5
  133. package/dist/plugins/getResolvedConfigSubset.mjs.map +1 -1
  134. package/dist/plugins/getResolvedConfigSubset.native.js +6 -5
  135. package/dist/plugins/getResolvedConfigSubset.native.js.map +1 -1
  136. package/dist/plugins/reactNativeCommonJsPlugin.mjs +210 -178
  137. package/dist/plugins/reactNativeCommonJsPlugin.mjs.map +1 -1
  138. package/dist/plugins/reactNativeCommonJsPlugin.native.js +283 -259
  139. package/dist/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
  140. package/dist/plugins/reactNativeDevAssetPlugin.mjs +72 -83
  141. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  142. package/dist/plugins/reactNativeDevAssetPlugin.native.js +75 -92
  143. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  144. package/dist/plugins/reactNativeDevServer.mjs +283 -328
  145. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  146. package/dist/plugins/reactNativeDevServer.native.js +332 -391
  147. package/dist/plugins/reactNativeDevServer.native.js.map +1 -1
  148. package/dist/plugins/rnCodegenPlugin.mjs +13 -12
  149. package/dist/plugins/rnCodegenPlugin.mjs.map +1 -1
  150. package/dist/plugins/rnCodegenPlugin.native.js +13 -12
  151. package/dist/plugins/rnCodegenPlugin.native.js.map +1 -1
  152. package/dist/plugins/rollupRemoveUnusedImports.mjs +8 -7
  153. package/dist/plugins/rollupRemoveUnusedImports.mjs.map +1 -1
  154. package/dist/plugins/rollupRemoveUnusedImports.native.js +8 -7
  155. package/dist/plugins/rollupRemoveUnusedImports.native.js.map +1 -1
  156. package/dist/plugins/workletImportsPlugin.mjs +127 -132
  157. package/dist/plugins/workletImportsPlugin.mjs.map +1 -1
  158. package/dist/plugins/workletImportsPlugin.native.js +192 -203
  159. package/dist/plugins/workletImportsPlugin.native.js.map +1 -1
  160. package/dist/rn-commands/bundle/buildBundle.mjs +45 -79
  161. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  162. package/dist/rn-commands/bundle/buildBundle.native.js +45 -85
  163. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  164. package/dist/runtime/hmr-client.mjs +133 -140
  165. package/dist/runtime/hmr-client.mjs.map +1 -1
  166. package/dist/runtime/hmr-client.native.js +223 -222
  167. package/dist/runtime/hmr-client.native.js.map +1 -1
  168. package/dist/runtime/hmr-runtime.mjs +192 -194
  169. package/dist/runtime/hmr-runtime.mjs.map +1 -1
  170. package/dist/runtime/hmr-runtime.native.js +424 -411
  171. package/dist/runtime/hmr-runtime.native.js.map +1 -1
  172. package/dist/runtime/hmr-types.mjs +0 -2
  173. package/dist/runtime/hmr-types.native.js +0 -2
  174. package/dist/runtime/native-prelude.mjs +2 -1
  175. package/dist/runtime/native-prelude.mjs.map +1 -1
  176. package/dist/runtime/native-prelude.native.js +2 -1
  177. package/dist/runtime/native-prelude.native.js.map +1 -1
  178. package/dist/runtime/react-refresh-utils.mjs +23 -22
  179. package/dist/runtime/react-refresh-utils.mjs.map +1 -1
  180. package/dist/runtime/react-refresh-utils.native.js +23 -27
  181. package/dist/runtime/react-refresh-utils.native.js.map +1 -1
  182. package/dist/serve/node.mjs +49 -49
  183. package/dist/serve/node.mjs.map +1 -1
  184. package/dist/serve/node.native.js +92 -96
  185. package/dist/serve/node.native.js.map +1 -1
  186. package/dist/types.mjs +0 -2
  187. package/dist/types.native.js +0 -2
  188. package/dist/user-interface/index.mjs +245 -262
  189. package/dist/user-interface/index.mjs.map +1 -1
  190. package/dist/user-interface/index.native.js +274 -298
  191. package/dist/user-interface/index.native.js.map +1 -1
  192. package/dist/utils/assert.mjs +7 -6
  193. package/dist/utils/assert.mjs.map +1 -1
  194. package/dist/utils/assert.native.js +7 -18
  195. package/dist/utils/assert.native.js.map +1 -1
  196. package/dist/utils/bindKeypressInput.mjs +36 -38
  197. package/dist/utils/bindKeypressInput.mjs.map +1 -1
  198. package/dist/utils/bindKeypressInput.native.js +36 -38
  199. package/dist/utils/bindKeypressInput.native.js.map +1 -1
  200. package/dist/utils/coerceToArray.mjs +2 -1
  201. package/dist/utils/coerceToArray.mjs.map +1 -1
  202. package/dist/utils/coerceToArray.native.js +2 -1
  203. package/dist/utils/coerceToArray.native.js.map +1 -1
  204. package/dist/utils/connectedNativeClients.mjs +3 -2
  205. package/dist/utils/connectedNativeClients.mjs.map +1 -1
  206. package/dist/utils/connectedNativeClients.native.js +3 -2
  207. package/dist/utils/connectedNativeClients.native.js.map +1 -1
  208. package/dist/utils/createNativeDevEngine.mjs +992 -966
  209. package/dist/utils/createNativeDevEngine.mjs.map +1 -1
  210. package/dist/utils/createNativeDevEngine.native.js +1184 -1179
  211. package/dist/utils/createNativeDevEngine.native.js.map +1 -1
  212. package/dist/utils/dispose.mjs +4 -3
  213. package/dist/utils/dispose.mjs.map +1 -1
  214. package/dist/utils/dispose.native.js +6 -5
  215. package/dist/utils/dispose.native.js.map +1 -1
  216. package/dist/utils/environmentUtils.mjs +5 -4
  217. package/dist/utils/environmentUtils.mjs.map +1 -1
  218. package/dist/utils/environmentUtils.native.js +5 -4
  219. package/dist/utils/environmentUtils.native.js.map +1 -1
  220. package/dist/utils/execSync.mjs +7 -5
  221. package/dist/utils/execSync.mjs.map +1 -1
  222. package/dist/utils/execSync.native.js +8 -6
  223. package/dist/utils/execSync.native.js.map +1 -1
  224. package/dist/utils/expoRun.mjs +27 -35
  225. package/dist/utils/expoRun.mjs.map +1 -1
  226. package/dist/utils/expoRun.native.js +27 -35
  227. package/dist/utils/expoRun.native.js.map +1 -1
  228. package/dist/utils/filterViteServerResolvedUrls.mjs +24 -22
  229. package/dist/utils/filterViteServerResolvedUrls.mjs.map +1 -1
  230. package/dist/utils/filterViteServerResolvedUrls.native.js +61 -63
  231. package/dist/utils/filterViteServerResolvedUrls.native.js.map +1 -1
  232. package/dist/utils/getBoundPort.mjs +6 -5
  233. package/dist/utils/getBoundPort.mjs.map +1 -1
  234. package/dist/utils/getBoundPort.native.js +8 -12
  235. package/dist/utils/getBoundPort.native.js.map +1 -1
  236. package/dist/utils/getCacheDir.mjs +3 -1
  237. package/dist/utils/getCacheDir.mjs.map +1 -1
  238. package/dist/utils/getCacheDir.native.js +3 -1
  239. package/dist/utils/getCacheDir.native.js.map +1 -1
  240. package/dist/utils/getServerEntry.mjs +6 -4
  241. package/dist/utils/getServerEntry.mjs.map +1 -1
  242. package/dist/utils/getServerEntry.native.js +8 -11
  243. package/dist/utils/getServerEntry.native.js.map +1 -1
  244. package/dist/utils/getVitePath.mjs +42 -42
  245. package/dist/utils/getVitePath.mjs.map +1 -1
  246. package/dist/utils/getVitePath.native.js +43 -41
  247. package/dist/utils/getVitePath.native.js.map +1 -1
  248. package/dist/utils/globDir.mjs +7 -11
  249. package/dist/utils/globDir.mjs.map +1 -1
  250. package/dist/utils/globDir.native.js +10 -14
  251. package/dist/utils/globDir.native.js.map +1 -1
  252. package/dist/utils/isWithin.mjs +4 -2
  253. package/dist/utils/isWithin.mjs.map +1 -1
  254. package/dist/utils/isWithin.native.js +4 -2
  255. package/dist/utils/isWithin.native.js.map +1 -1
  256. package/dist/utils/patches.mjs +233 -255
  257. package/dist/utils/patches.mjs.map +1 -1
  258. package/dist/utils/patches.native.js +415 -460
  259. package/dist/utils/patches.native.js.map +1 -1
  260. package/dist/utils/printServerUrls.mjs +9 -7
  261. package/dist/utils/printServerUrls.mjs.map +1 -1
  262. package/dist/utils/printServerUrls.native.js +48 -51
  263. package/dist/utils/printServerUrls.native.js.map +1 -1
  264. package/dist/utils/removeUndefined.mjs +8 -7
  265. package/dist/utils/removeUndefined.mjs.map +1 -1
  266. package/dist/utils/removeUndefined.native.js +8 -7
  267. package/dist/utils/removeUndefined.native.js.map +1 -1
  268. package/dist/utils/scanDepsToOptimize.mjs +194 -161
  269. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  270. package/dist/utils/scanDepsToOptimize.native.js +227 -197
  271. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  272. package/dist/utils/state.mjs +18 -18
  273. package/dist/utils/state.mjs.map +1 -1
  274. package/dist/utils/state.native.js +18 -18
  275. package/dist/utils/state.native.js.map +1 -1
  276. package/dist/utils/symbolicateNativeStack.mjs +54 -54
  277. package/dist/utils/symbolicateNativeStack.mjs.map +1 -1
  278. package/dist/utils/symbolicateNativeStack.native.js +58 -58
  279. package/dist/utils/symbolicateNativeStack.native.js.map +1 -1
  280. package/dist/utils/uniq.mjs +2 -1
  281. package/dist/utils/uniq.mjs.map +1 -1
  282. package/dist/utils/uniq.native.js +2 -1
  283. package/dist/utils/uniq.native.js.map +1 -1
  284. package/dist/utils/utils.mjs +19 -19
  285. package/dist/utils/utils.mjs.map +1 -1
  286. package/dist/utils/utils.native.js +38 -40
  287. package/dist/utils/utils.native.js.map +1 -1
  288. package/dist/vendor/debugger-app/index.mjs +0 -2
  289. package/dist/vendor/debugger-app/index.native.js +0 -2
  290. package/dist/vendor/debugger-app/src/debuggerWorker.mjs +0 -2
  291. package/dist/vendor/debugger-app/src/debuggerWorker.native.js +0 -2
  292. package/dist/vendor/debugger-app/src/index.mjs +0 -2
  293. package/dist/vendor/debugger-app/src/index.native.js +0 -2
  294. package/dist/vxrn-vite-plugin.mjs +34 -33
  295. package/dist/vxrn-vite-plugin.mjs.map +1 -1
  296. package/dist/vxrn-vite-plugin.native.js +35 -34
  297. package/dist/vxrn-vite-plugin.native.js.map +1 -1
  298. package/expo-plugin.cjs +12 -6
  299. package/package.json +12 -13
  300. package/src/config/getBaseViteConfigOnly.ts +6 -0
  301. package/src/exports/prebuild.ts +40 -12
  302. package/src/patches/builtInDepPatches.ts +24 -48
  303. package/src/utils/createNativeDevEngine.test.ts +1 -1
  304. package/src/utils/createNativeDevEngine.ts +15 -9
  305. package/src/utils/scanDepsToOptimize.ts +0 -3
  306. package/types/config/getBaseViteConfigOnly.d.ts.map +1 -1
  307. package/types/config/getOptimizeDeps.d.ts.map +1 -1
  308. package/types/config/getOptionsFilled.d.ts +15 -15
  309. package/types/config/getOptionsFilled.d.ts.map +1 -1
  310. package/types/exports/build.d.ts +11 -11
  311. package/types/exports/build.d.ts.map +1 -1
  312. package/types/exports/clean.d.ts +1 -1
  313. package/types/exports/clean.d.ts.map +1 -1
  314. package/types/exports/createServer.d.ts.map +1 -1
  315. package/types/exports/dev.d.ts.map +1 -1
  316. package/types/exports/patch.d.ts.map +1 -1
  317. package/types/exports/prebuild.d.ts +3 -3
  318. package/types/exports/prebuild.d.ts.map +1 -1
  319. package/types/exports/prebuildWithoutExpo.d.ts +1 -1
  320. package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
  321. package/types/exports/runAndroid.d.ts.map +1 -1
  322. package/types/exports/runIos.d.ts.map +1 -1
  323. package/types/exports/serve.d.ts.map +1 -1
  324. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  325. package/types/plugins/autoDepOptimizePlugin.d.ts.map +1 -1
  326. package/types/plugins/rollupRemoveUnusedImports.d.ts.map +1 -1
  327. package/types/runtime/hmr-client.d.ts.map +1 -1
  328. package/types/runtime/hmr-runtime.d.ts.map +1 -1
  329. package/types/runtime/hmr-types.d.ts.map +1 -1
  330. package/types/utils/createNativeDevEngine.d.ts +1 -1
  331. package/types/utils/createNativeDevEngine.d.ts.map +1 -1
  332. package/types/utils/execSync.d.ts.map +1 -1
  333. package/types/utils/getServerEntry.d.ts.map +1 -1
  334. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  335. package/types/vxrn-vite-plugin.d.ts.map +1 -1
  336. package/dist/config/getOptimizeDeps.test.mjs +0 -20
  337. package/dist/config/getOptimizeDeps.test.mjs.map +0 -1
  338. package/dist/config/getOptimizeDeps.test.native.js +0 -39
  339. package/dist/config/getOptimizeDeps.test.native.js.map +0 -1
  340. package/dist/config/getServerOptionsFilled.test.mjs +0 -20
  341. package/dist/config/getServerOptionsFilled.test.mjs.map +0 -1
  342. package/dist/config/getServerOptionsFilled.test.native.js +0 -20
  343. package/dist/config/getServerOptionsFilled.test.native.js.map +0 -1
  344. package/dist/config/getViteServerConfig.test.mjs +0 -26
  345. package/dist/config/getViteServerConfig.test.mjs.map +0 -1
  346. package/dist/config/getViteServerConfig.test.native.js +0 -26
  347. package/dist/config/getViteServerConfig.test.native.js.map +0 -1
  348. package/dist/config/mergeUserConfig.test.mjs +0 -108
  349. package/dist/config/mergeUserConfig.test.mjs.map +0 -1
  350. package/dist/config/mergeUserConfig.test.native.js +0 -108
  351. package/dist/config/mergeUserConfig.test.native.js.map +0 -1
  352. package/dist/exports/clean.test.mjs +0 -81
  353. package/dist/exports/clean.test.mjs.map +0 -1
  354. package/dist/exports/clean.test.native.js +0 -88
  355. package/dist/exports/clean.test.native.js.map +0 -1
  356. package/dist/exports/loadEnv.test.mjs +0 -65
  357. package/dist/exports/loadEnv.test.mjs.map +0 -1
  358. package/dist/exports/loadEnv.test.native.js +0 -65
  359. package/dist/exports/loadEnv.test.native.js.map +0 -1
  360. package/dist/index.js.map +0 -1
  361. package/dist/index.mjs.map +0 -1
  362. package/dist/index.native.js.map +0 -1
  363. package/dist/plugins/autoDepOptimizePlugin.test.mjs +0 -31
  364. package/dist/plugins/autoDepOptimizePlugin.test.mjs.map +0 -1
  365. package/dist/plugins/autoDepOptimizePlugin.test.native.js +0 -39
  366. package/dist/plugins/autoDepOptimizePlugin.test.native.js.map +0 -1
  367. package/dist/plugins/resolveIdScan.test.mjs +0 -31
  368. package/dist/plugins/resolveIdScan.test.mjs.map +0 -1
  369. package/dist/plugins/resolveIdScan.test.native.js +0 -38
  370. package/dist/plugins/resolveIdScan.test.native.js.map +0 -1
  371. package/dist/plugins/rnCodegenPlugin.test.mjs +0 -239
  372. package/dist/plugins/rnCodegenPlugin.test.mjs.map +0 -1
  373. package/dist/plugins/rnCodegenPlugin.test.native.js +0 -242
  374. package/dist/plugins/rnCodegenPlugin.test.native.js.map +0 -1
  375. package/dist/plugins/serverExtensions.test.mjs +0 -106
  376. package/dist/plugins/serverExtensions.test.mjs.map +0 -1
  377. package/dist/plugins/serverExtensions.test.native.js +0 -117
  378. package/dist/plugins/serverExtensions.test.native.js.map +0 -1
  379. package/dist/runtime/hmr-types.mjs.map +0 -1
  380. package/dist/runtime/hmr-types.native.js.map +0 -1
  381. package/dist/serve/node.test.mjs +0 -60
  382. package/dist/serve/node.test.mjs.map +0 -1
  383. package/dist/serve/node.test.native.js +0 -72
  384. package/dist/serve/node.test.native.js.map +0 -1
  385. package/dist/types.mjs.map +0 -1
  386. package/dist/types.native.js.map +0 -1
  387. package/dist/utils/bindKeypressInput.test.mjs +0 -48
  388. package/dist/utils/bindKeypressInput.test.mjs.map +0 -1
  389. package/dist/utils/bindKeypressInput.test.native.js +0 -48
  390. package/dist/utils/bindKeypressInput.test.native.js.map +0 -1
  391. package/dist/utils/createNativeDevEngine.test.mjs +0 -1788
  392. package/dist/utils/createNativeDevEngine.test.mjs.map +0 -1
  393. package/dist/utils/createNativeDevEngine.test.native.js +0 -1942
  394. package/dist/utils/createNativeDevEngine.test.native.js.map +0 -1
  395. package/dist/utils/createNativeDevEngineFailure.test.mjs +0 -44
  396. package/dist/utils/createNativeDevEngineFailure.test.mjs.map +0 -1
  397. package/dist/utils/createNativeDevEngineFailure.test.native.js +0 -54
  398. package/dist/utils/createNativeDevEngineFailure.test.native.js.map +0 -1
  399. package/dist/utils/getBoundPort.test.mjs +0 -71
  400. package/dist/utils/getBoundPort.test.mjs.map +0 -1
  401. package/dist/utils/getBoundPort.test.native.js +0 -82
  402. package/dist/utils/getBoundPort.test.native.js.map +0 -1
  403. package/dist/utils/imageSizePatch.test.mjs +0 -29
  404. package/dist/utils/imageSizePatch.test.mjs.map +0 -1
  405. package/dist/utils/imageSizePatch.test.native.js +0 -30
  406. package/dist/utils/imageSizePatch.test.native.js.map +0 -1
  407. package/dist/utils/patches.test.mjs +0 -242
  408. package/dist/utils/patches.test.mjs.map +0 -1
  409. package/dist/utils/patches.test.native.js +0 -271
  410. package/dist/utils/patches.test.native.js.map +0 -1
  411. package/dist/utils/symbolicateNativeStack.test.mjs +0 -96
  412. package/dist/utils/symbolicateNativeStack.test.mjs.map +0 -1
  413. package/dist/utils/symbolicateNativeStack.test.native.js +0 -96
  414. package/dist/utils/symbolicateNativeStack.test.native.js.map +0 -1
  415. package/dist/vendor/debugger-app/index.mjs.map +0 -1
  416. package/dist/vendor/debugger-app/index.native.js.map +0 -1
  417. package/dist/vendor/debugger-app/src/debuggerWorker.mjs.map +0 -1
  418. package/dist/vendor/debugger-app/src/debuggerWorker.native.js.map +0 -1
  419. package/dist/vendor/debugger-app/src/index.mjs.map +0 -1
  420. package/dist/vendor/debugger-app/src/index.native.js.map +0 -1
  421. package/types/config/getOptimizeDeps.test.d.ts +0 -2
  422. package/types/config/getOptimizeDeps.test.d.ts.map +0 -1
  423. package/types/config/getServerOptionsFilled.test.d.ts +0 -2
  424. package/types/config/getServerOptionsFilled.test.d.ts.map +0 -1
  425. package/types/config/getViteServerConfig.test.d.ts +0 -2
  426. package/types/config/getViteServerConfig.test.d.ts.map +0 -1
  427. package/types/config/mergeUserConfig.test.d.ts +0 -2
  428. package/types/config/mergeUserConfig.test.d.ts.map +0 -1
  429. package/types/exports/clean.test.d.ts +0 -2
  430. package/types/exports/clean.test.d.ts.map +0 -1
  431. package/types/exports/loadEnv.test.d.ts +0 -2
  432. package/types/exports/loadEnv.test.d.ts.map +0 -1
  433. package/types/plugins/autoDepOptimizePlugin.test.d.ts +0 -2
  434. package/types/plugins/autoDepOptimizePlugin.test.d.ts.map +0 -1
  435. package/types/plugins/resolveIdScan.test.d.ts +0 -2
  436. package/types/plugins/resolveIdScan.test.d.ts.map +0 -1
  437. package/types/plugins/rnCodegenPlugin.test.d.ts +0 -2
  438. package/types/plugins/rnCodegenPlugin.test.d.ts.map +0 -1
  439. package/types/plugins/serverExtensions.test.d.ts +0 -2
  440. package/types/plugins/serverExtensions.test.d.ts.map +0 -1
  441. package/types/serve/node.test.d.ts +0 -2
  442. package/types/serve/node.test.d.ts.map +0 -1
  443. package/types/utils/bindKeypressInput.test.d.ts +0 -2
  444. package/types/utils/bindKeypressInput.test.d.ts.map +0 -1
  445. package/types/utils/createNativeDevEngine.test.d.ts +0 -2
  446. package/types/utils/createNativeDevEngine.test.d.ts.map +0 -1
  447. package/types/utils/createNativeDevEngineFailure.test.d.ts +0 -2
  448. package/types/utils/createNativeDevEngineFailure.test.d.ts.map +0 -1
  449. package/types/utils/getBoundPort.test.d.ts +0 -2
  450. package/types/utils/getBoundPort.test.d.ts.map +0 -1
  451. package/types/utils/imageSizePatch.test.d.ts +0 -2
  452. package/types/utils/imageSizePatch.test.d.ts.map +0 -1
  453. package/types/utils/patches.test.d.ts +0 -2
  454. package/types/utils/patches.test.d.ts.map +0 -1
  455. package/types/utils/symbolicateNativeStack.test.d.ts +0 -2
  456. package/types/utils/symbolicateNativeStack.test.d.ts.map +0 -1
@@ -1,1942 +0,0 @@
1
- import { existsSync, realpathSync } from "fs";
2
- import { mkdir, mkdtemp, rm, writeFile } from "fs/promises";
3
- import { tmpdir } from "os";
4
- import { join } from "path";
5
- import { createContext, runInContext, runInNewContext } from "vm";
6
- import { TraceMap, originalPositionFor } from "@jridgewell/trace-mapping";
7
- import { rolldown } from "rolldown";
8
- import { dev } from "rolldown/experimental";
9
- import { normalizePath } from "vite";
10
- import { describe, expect, it, vi } from "vitest";
11
- import { getNativePrelude } from "../runtime/native-prelude.native.js";
12
- import { workletImportsPlugin } from "../plugins/workletImportsPlugin.native.js";
13
- import { buildNativeBundle, createNativeDevAssetRegistry, createNativeDevEngine, getHermesSWCIncludes, getHmrRuntimeSource, getNativeAssetData, getNativeTransformConfig, hermesCompatSWCPlugin, hmrClientNoopPlugin, nativeAnimatedGuardPlugin, normalizeNativeCommonJSInterop, postProcessNativeBundle, vxrnCompilerPlugin, wrapNativeBundleModuleScope } from "./createNativeDevEngine.native.js";
14
- function _instanceof(left, right) {
15
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);else return left instanceof right;
16
- }
17
- function _type_of(obj) {
18
- "@swc/helpers - typeof";
19
-
20
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
21
- }
22
- describe.each(["ios", "android"])("native plugin adapters on %s", function (platform) {
23
- it.each(["dev", "build"])("binds configured plugins to the %s bundle", async function (mode) {
24
- var root2 = await mkdtemp(join(tmpdir(), "vxrn-native-plugin-adapter-"));
25
- await writeFile(join(root2, "entry.js"), `globalThis.nativePluginResult = [__GLOBAL_PLUGIN__, __DIRECT_PLUGIN__, 'plain-plugin']`);
26
- var factories = ["global", "direct"].map(function (name) {
27
- return vi.fn(function (context2) {
28
- return {
29
- name: `${name}-native`,
30
- transform(code2, id) {
31
- if (id.endsWith("/entry.js")) return code2.replace(`__${name.toUpperCase()}_PLUGIN__`, JSON.stringify({
32
- name,
33
- ...context2
34
- }));
35
- }
36
- };
37
- });
38
- });
39
- var plugins = factories.map(function (vxrnNative, index) {
40
- return {
41
- name: `adapter-${index}`,
42
- api: {
43
- vxrnNative
44
- }
45
- };
46
- });
47
- var previousPlugins = globalThis.__vxrnAddNativePlugins;
48
- globalThis.__vxrnAddNativePlugins = [plugins[0]];
49
- var configuredPlugins = [plugins[1], {
50
- name: "plain-native-plugin",
51
- transform(code2, id) {
52
- if (id.endsWith("/__virtual-native-entry.tsx")) return `import './entry.js'`;
53
- if (id.endsWith("/entry.js")) return code2.replace("plain-plugin", "plain");
54
- }
55
- }];
56
- var native;
57
- try {
58
- var code;
59
- if (mode === "dev") {
60
- native = await createNativeDevEngine({
61
- root: root2,
62
- platform,
63
- port: 0,
64
- plugins: configuredPlugins
65
- });
66
- code = (await native.getBundle()).code;
67
- } else code = (await buildNativeBundle({
68
- root: root2,
69
- platform,
70
- entryFile: "entry.js",
71
- plugins: configuredPlugins
72
- })).code;
73
- var context = {
74
- console,
75
- setTimeout,
76
- clearTimeout,
77
- __GLOBAL_PLUGIN__: "unadapted",
78
- __DIRECT_PLUGIN__: "unadapted"
79
- };
80
- runInNewContext(code, context);
81
- expect(Reflect.get(context, "nativePluginResult")).toEqual([{
82
- name: "global",
83
- root: root2,
84
- platform,
85
- dev: mode === "dev"
86
- }, {
87
- name: "direct",
88
- root: root2,
89
- platform,
90
- dev: mode === "dev"
91
- }, "plain"]);
92
- var _iteratorNormalCompletion = true,
93
- _didIteratorError = false,
94
- _iteratorError = void 0;
95
- try {
96
- for (var _iterator = factories[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
97
- var factory = _step.value;
98
- expect(factory).toHaveBeenCalledExactlyOnceWith({
99
- root: root2,
100
- platform,
101
- dev: mode === "dev"
102
- });
103
- }
104
- } catch (err) {
105
- _didIteratorError = true;
106
- _iteratorError = err;
107
- } finally {
108
- try {
109
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
110
- } finally {
111
- if (_didIteratorError) throw _iteratorError;
112
- }
113
- }
114
- } finally {
115
- await (native === null || native === void 0 ? void 0 : native.close());
116
- globalThis.__vxrnAddNativePlugins = previousPlugins;
117
- await rm(root2, {
118
- recursive: true,
119
- force: true
120
- });
121
- }
122
- });
123
- });
124
- var nativeTransformProbe = `
125
- export const transformProbe = () => {
126
- 'worklet'
127
- return 'transformed'
128
- }
129
- `;
130
- describe.each(["rolldown-dev", "rolldown-build", "metro-module", "metro-script"])("native async through %s", function (pipeline) {
131
- it("preserves defaults, lexical bindings, bigint, rejection, and iterator cleanup", async function () {
132
- var id = "/project/native-async.js";
133
- var source = `
134
- globalThis.result = (function(parentArgument) {
135
- const events = [];
136
- const run = async(value = 2n, fail = false) => {
137
- try {
138
- const awaited = await (fail ? Promise.reject(new Error('rejected')) : Promise.resolve(3n));
139
- events.push('after-await');
140
- return [String(value + awaited), this.base, arguments[0]];
141
- } catch (error) { return error.message; }
142
- finally { events.push('finally'); }
143
- };
144
- const badDefault = async(value = (() => { throw new Error('default'); })()) => value;
145
- let synchronousThrow = false;
146
- let rejectedDefault;
147
- try { rejectedDefault = badDefault().catch(error => error.message); }
148
- catch { synchronousThrow = true; }
149
- async function* values() {
150
- try { yield 1n; yield 2n; }
151
- finally { events.push('closed'); }
152
- }
153
- const first = async() => { for await (const value of values()) return String(value); };
154
- return Promise.all([run(), run(4n), run(undefined, true), rejectedDefault, first()])
155
- .then(values => ({ values, events, synchronousThrow }));
156
- }).call({ base: 7 }, 'lexical');
157
- `;
158
- var output;
159
- if (pipeline.startsWith("metro")) {
160
- var {
161
- transform
162
- } = await import("@vxrn/vite-plugin-metro/metroNativeWorker");
163
- var data = (await transform({}, "/project", id, Buffer.from(source), {
164
- dev: false,
165
- platform: "ios",
166
- type: pipeline === "metro-script" ? "script" : "module"
167
- })).output[0].data;
168
- var {
169
- fromRawMappings
170
- } = await import("metro-source-map");
171
- output = {
172
- code: data.code,
173
- map: fromRawMappings([{
174
- code: data.code,
175
- path: id,
176
- source,
177
- map: data.map
178
- }]).toMap()
179
- };
180
- } else {
181
- var plugin = hermesCompatSWCPlugin(pipeline === "rolldown-dev", true);
182
- output = await Reflect.apply(plugin.transform, void 0, [source, id]);
183
- }
184
- var context = {};
185
- context.__d = function (factory) {
186
- var module = {
187
- exports: {}
188
- };
189
- factory(context, function (name) {
190
- throw new Error(`unexpected dependency ${name}`);
191
- }, function () {}, function () {}, module, module.exports, []);
192
- };
193
- runInNewContext(output.code, context);
194
- var result1 = await context.result;
195
- expect(result1.values).toEqual([["5", 7, "lexical"], ["7", 7, "lexical"], "rejected", "default", "1"]);
196
- expect(result1.synchronousThrow).toBe(false);
197
- expect(result1.events.filter(function (value) {
198
- return value === "finally";
199
- })).toHaveLength(3);
200
- expect(result1.events.filter(function (value) {
201
- return value === "closed";
202
- })).toHaveLength(1);
203
- var {
204
- originalPositionFor: originalPositionFor2,
205
- TraceMap: TraceMap2
206
- } = await import("@jridgewell/trace-mapping");
207
- var lines = output.code.split("\n");
208
- var line = lines.findIndex(function (value) {
209
- return value.includes("after-await");
210
- });
211
- var position = originalPositionFor2(new TraceMap2(output.map), {
212
- line: line + 1,
213
- column: lines[line].indexOf("events.push")
214
- });
215
- expect(position.source).toBe(id);
216
- expect(position.line).toBe(source.split("\n").findIndex(function (value) {
217
- return value.includes("after-await");
218
- }) + 1);
219
- });
220
- });
221
- describe.each(["shared", "rolldown", "metro"])("React Compiler worklets through %s", function (pipeline) {
222
- it.each([["block", "useDerivedValue(() => { return value + 8 }, [value])", 18], ["expression", "useDerivedValue(() => value + 8, [value])", 18], ["object", "useDerivedValue(() => ({ lift: value + 8 }), [value])", {
223
- lift: 18
224
- }], ["nested", "useDerivedValue(() => runOnUI(() => value + 8), [value])", 18], ["gesture", "useDerivedValue(() => Gesture.Pan().onUpdate(() => value + 8), [value])", 18]])("preserves %s callbacks on the UI runtime and memoizes stable inputs", async function (_name, callback, expected) {
225
- var compiler = await import("@vxrn/compiler");
226
- var {
227
- parseSync
228
- } = await import("oxc-parser");
229
- var {
230
- default: MagicString
231
- } = await import("magic-string");
232
- var {
233
- TraceMap: TraceMap2,
234
- originalPositionFor: originalPositionFor2
235
- } = await import("@jridgewell/trace-mapping");
236
- var projectRoot = await createWorkletsProject(false);
237
- var sourceMaps = process.env.VXRN_ENABLE_SOURCE_MAP;
238
- process.env.VXRN_ENABLE_SOURCE_MAP = "1";
239
- compiler.configureVXRNCompilerPlugin({
240
- enableCompiler: true,
241
- enableReanimated: true,
242
- enableNativeWorklets: true
243
- });
244
- try {
245
- var _first___initData;
246
- var id = join(projectRoot, "useProbe.ts");
247
- var source = `export function useProbe(value) {
248
- return ${callback};
249
- }
250
- `;
251
- await writeFile(id, source);
252
- var result;
253
- if (pipeline === "shared") {
254
- var plugin = (await compiler.createVXRNCompilerPlugin()).find(function (p) {
255
- return p.name === "one:compiler";
256
- });
257
- await plugin.configResolved({
258
- root: projectRoot,
259
- build: {}
260
- });
261
- result = await (plugin.transform.handler || plugin.transform).call({
262
- environment: {
263
- name: "ios"
264
- }
265
- }, source, id);
266
- } else if (pipeline === "metro") {
267
- var {
268
- transform
269
- } = await import("@vxrn/vite-plugin-metro/metroNativeWorker");
270
- var data = (await transform({}, projectRoot, id, Buffer.from(source), {
271
- dev: false,
272
- platform: "ios",
273
- type: "module",
274
- customTransformOptions: {
275
- reactCompiler: true,
276
- worklets: true
277
- }
278
- })).output[0].data;
279
- var msm = await import("metro-source-map");
280
- result = {
281
- code: data.code,
282
- map: msm.fromRawMappings([{
283
- code: data.code,
284
- path: id,
285
- source,
286
- map: data.map
287
- }]).toMap()
288
- };
289
- } else {
290
- var plugin1 = vxrnCompilerPlugin("ios", false, projectRoot, true);
291
- result = await Reflect.apply(plugin1.transform, void 0, [source, id]);
292
- }
293
- var runnable = new MagicString(result.code);
294
- var _iteratorNormalCompletion = true,
295
- _didIteratorError = false,
296
- _iteratorError = void 0;
297
- try {
298
- for (var _iterator = parseSync("probe.js", result.code).program.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
299
- var node = _step.value;
300
- if (node.type === "ImportDeclaration") runnable.remove(node.start, node.end);
301
- if (node.type === "ExportNamedDeclaration" && node.declaration) runnable.remove(node.start, node.declaration.start);
302
- }
303
- } catch (err) {
304
- _didIteratorError = true;
305
- _iteratorError = err;
306
- } finally {
307
- try {
308
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
309
- } finally {
310
- if (_didIteratorError) throw _iteratorError;
311
- }
312
- }
313
- var cache;
314
- var cacheCalls = 0;
315
- var memo = function (size) {
316
- cacheCalls++;
317
- return cache !== null && cache !== void 0 ? cache : cache = Array(size).fill(/* @__PURE__ */Symbol.for("react.memo_cache_sentinel"));
318
- };
319
- var module = {
320
- exports: {}
321
- };
322
- var probe = new Function("_c", "useDerivedValue", "runOnUI", "Gesture", "__d", "module", `${runnable}
323
- return ${pipeline === "metro" ? "module.exports.useProbe" : "useProbe"}`)(memo, function (fn2) {
324
- return fn2;
325
- }, function (fn2) {
326
- return fn2;
327
- }, {
328
- Pan: function () {
329
- return {
330
- onUpdate: function (fn2) {
331
- return fn2;
332
- }
333
- };
334
- }
335
- }, function (factory) {
336
- return factory(globalThis, function () {
337
- return {
338
- c: memo
339
- };
340
- }, function () {}, function () {}, module, module.exports, []);
341
- }, module);
342
- var first = probe(10);
343
- expect((_first___initData = first.__initData) === null || _first___initData === void 0 ? void 0 : _first___initData.code).toBeTypeOf("string");
344
- for (var _i = 0, _iter = [false, true]; _i < _iter.length; _i++) {
345
- var onUI = _iter[_i];
346
- var fn = first;
347
- var value = void 0;
348
- for (var depth = 0; depth < 2; depth++) {
349
- var _fn___initData;
350
- expect((_fn___initData = fn.__initData) === null || _fn___initData === void 0 ? void 0 : _fn___initData.code).toBeTypeOf("string");
351
- value = onUI ? new Function("runOnUI", `return (${fn.__initData.code})`)(function (fn2) {
352
- return fn2;
353
- }).call({
354
- __closure: fn.__closure
355
- }) : fn();
356
- if (typeof value !== "function") break;
357
- fn = value;
358
- }
359
- expect(value).toEqual(expected);
360
- }
361
- expect(probe(10)).toBe(first);
362
- expect(cacheCalls).toBe(2);
363
- expect(probe(20)).not.toBe(first);
364
- var lines = result.code.split("\n");
365
- var line = lines.findIndex(function (text) {
366
- return text.includes("function useProbe(");
367
- });
368
- expect(line).toBeGreaterThanOrEqual(0);
369
- var position = originalPositionFor2(new TraceMap2(result.map), {
370
- line: line + 1,
371
- column: lines[line].indexOf("function")
372
- });
373
- expect(position.source).toBe(id);
374
- expect(position.line).toBe(1);
375
- } finally {
376
- if (sourceMaps === void 0) delete process.env.VXRN_ENABLE_SOURCE_MAP;else process.env.VXRN_ENABLE_SOURCE_MAP = sourceMaps;
377
- compiler.configureVXRNCompilerPlugin({
378
- enableCompiler: false,
379
- enableReanimated: false,
380
- enableNativeWorklets: false
381
- });
382
- await rm(projectRoot, {
383
- recursive: true,
384
- force: true
385
- });
386
- }
387
- });
388
- });
389
- async function createWorkletsProject() {
390
- var throwOnTransform = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
391
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-transform-failure-"));
392
- var packageRoot = join(testRoot, "node_modules/react-native-worklets");
393
- await mkdir(packageRoot, {
394
- recursive: true
395
- });
396
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
397
- name: "react-native-worklets",
398
- version: "0.10.1"
399
- }));
400
- await writeFile(join(packageRoot, "plugin.js"), throwOnTransform ? `module.exports = () => ({
401
- visitor: {
402
- Program() {
403
- throw new Error('NATIVE_TRANSFORM_NEGATIVE_CONTROL')
404
- }
405
- }
406
- })` : `module.exports = () => ({ visitor: {} })`);
407
- await writeFile(join(testRoot, "entry.ts"), nativeTransformProbe);
408
- return testRoot;
409
- }
410
- describe("native prelude", function () {
411
- it("does not advertise a host event API that cannot remove listeners", function () {
412
- var context = {
413
- addEventListener() {}
414
- };
415
- runInNewContext(getNativePrelude({
416
- dev: false,
417
- platform: "ios"
418
- }), context);
419
- expect(Reflect.get(context, "addEventListener")).toBeUndefined();
420
- });
421
- it("preserves a complete host event API", function () {
422
- var addEventListener = function () {};
423
- var removeEventListener = function () {};
424
- var context = {
425
- addEventListener,
426
- removeEventListener
427
- };
428
- runInNewContext(getNativePrelude({
429
- dev: false,
430
- platform: "ios"
431
- }), context);
432
- expect(context.addEventListener).toBe(addEventListener);
433
- expect(context.removeEventListener).toBe(removeEventListener);
434
- });
435
- });
436
- describe("native pure-function worklet imports", function () {
437
- it("keeps live module versions isolated across a transitive HMR update", async function () {
438
- var root2 = await createWorkletsProject(false);
439
- var packageRoot = join(root2, "node_modules/pure-math");
440
- await mkdir(packageRoot, {
441
- recursive: true
442
- });
443
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
444
- type: "module",
445
- exports: "./index.js"
446
- }));
447
- var dependency = join(packageRoot, "amount.ios.js");
448
- await writeFile(dependency, "export const amount = 2");
449
- await writeFile(join(packageRoot, "amount.android.js"), "export const amount = 99");
450
- await writeFile(join(packageRoot, "index.js"), `
451
- import { amount } from './amount'
452
- const instance = globalThis.moduleInitializations = (globalThis.moduleInitializations || 0) + 1
453
- export default function calculate(value) { return value + amount }
454
- export function reads() { return instance }
455
- `);
456
- await writeFile(join(root2, "entry.mjs"), `
457
- import calculate, { reads } from 'pure-math'
458
- globalThis.calculate = calculate
459
- globalThis.reads = reads
460
- if (import.meta.hot) import.meta.hot.accept(() => {})
461
- `);
462
- var compiler = await import("@vxrn/compiler");
463
- compiler.configureVXRNCompilerPlugin({
464
- enableReanimated: true,
465
- enableNativeWorklets: true
466
- });
467
- var resolveUpdate;
468
- var updated = new Promise(function (resolve) {
469
- resolveUpdate = resolve;
470
- });
471
- var native = await createNativeDevEngine({
472
- root: root2,
473
- port: 0,
474
- platform: "ios",
475
- plugins: [workletImportsPlugin({
476
- "pure-math": ["default", "reads"]
477
- }), {
478
- name: "worklet-import-fixture",
479
- transform(_code, id) {
480
- if (id.endsWith("/__virtual-native-entry.tsx")) return `import './entry.mjs'`;
481
- }
482
- }],
483
- onHmrUpdate: resolveUpdate
484
- });
485
- try {
486
- var initial = await native.getBundle();
487
- var rn = {
488
- console,
489
- setTimeout,
490
- clearTimeout
491
- };
492
- runInNewContext(initial.code, rn);
493
- expect(rn.calculate(10)).toBe(12);
494
- expect(rn.reads()).toBe(1);
495
- var ui = createContext({});
496
- var compiled = /* @__PURE__ */new Map();
497
- var reconstruct = function (worklet) {
498
- if (!worklet.__initData || !worklet.__workletHash) throw new Error("remote function");
499
- var fn = compiled.get(worklet.__workletHash);
500
- if (!fn) {
501
- fn = runInContext(`(${worklet.__initData.code})`, ui);
502
- compiled.set(worklet.__workletHash, fn);
503
- }
504
- var closure = Object.fromEntries(Object.entries(worklet.__closure).map(function (param) {
505
- var [name, value] = param;
506
- return [name, typeof value === "function" ? reconstruct(value) : value];
507
- }));
508
- return fn.bind({
509
- __closure: closure
510
- });
511
- };
512
- expect(function () {
513
- return reconstruct(function (value) {
514
- return value + 2;
515
- });
516
- }).toThrow("remote function");
517
- var old = reconstruct(rn.calculate);
518
- var oldReads = reconstruct(rn.reads);
519
- expect(old(10)).toBe(12);
520
- expect(reconstruct(rn.calculate)(11)).toBe(13);
521
- expect(oldReads()).toBe(1);
522
- expect(rn.reads()).toBe(1);
523
- var runtime = rn.__rolldown_runtime__;
524
- await native.engine.registerClient(runtime.clientId);
525
- await writeFile(dependency, "export const amount = 3");
526
- var update = await updated;
527
- expect(update.type).toBe("hmr:update");
528
- expect(runtime.applyHmrUpdate(update.code, update.changedIds, update.seq)).toBe(true);
529
- expect(rn.calculate(10)).toBe(13);
530
- var next = reconstruct(rn.calculate);
531
- expect([old(10), next(10), old(10), next(10)]).toEqual([12, 13, 12, 13]);
532
- var nextReads = reconstruct(rn.reads);
533
- expect([oldReads(), nextReads(), oldReads(), nextReads()]).toEqual([1, 2, 1, 2]);
534
- expect(ui.moduleInitializations).toBe(2);
535
- expect(rn.reads()).toBe(2);
536
- await writeFile(join(root2, "production.mjs"), `import calculate, { reads } from 'pure-math'; globalThis.calculate = calculate; globalThis.reads = reads`);
537
- var production = await buildNativeBundle({
538
- root: root2,
539
- platform: "android",
540
- entryFile: "production.mjs",
541
- plugins: [workletImportsPlugin({
542
- "pure-math": ["default", "reads"]
543
- })]
544
- });
545
- expect(production.code).not.toContain("__esmMin");
546
- var productionRN = {
547
- console
548
- };
549
- runInNewContext(production.code, productionRN);
550
- expect(productionRN.calculate(10)).toBe(109);
551
- expect(reconstruct(productionRN.calculate)(10)).toBe(109);
552
- expect(reconstruct(productionRN.reads)()).toBe(3);
553
- expect(productionRN.reads()).toBe(1);
554
- var unminifiedProduction = await buildNativeBundle({
555
- root: root2,
556
- platform: "android",
557
- entryFile: "production.mjs",
558
- minify: false,
559
- plugins: [workletImportsPlugin({
560
- "pure-math": ["default", "reads"]
561
- })]
562
- });
563
- expect(unminifiedProduction.code).toContain("__esmMin");
564
- var unminifiedRN = {
565
- console
566
- };
567
- runInNewContext(unminifiedProduction.code, unminifiedRN);
568
- expect(unminifiedRN.calculate(10)).toBe(109);
569
- expect(reconstruct(unminifiedRN.calculate)(10)).toBe(109);
570
- expect(reconstruct(unminifiedRN.reads)()).toBe(3);
571
- var sharedPlugin = workletImportsPlugin({
572
- "pure-math": ["default", "reads"]
573
- });
574
- expect(await Promise.all(["ios", "android"].map(async function (platform) {
575
- var output = await buildNativeBundle({
576
- root: root2,
577
- platform,
578
- entryFile: "production.mjs",
579
- plugins: [sharedPlugin]
580
- });
581
- var context = {
582
- console
583
- };
584
- runInNewContext(output.code, context);
585
- return context.calculate(10);
586
- }))).toEqual([13, 109]);
587
- } finally {
588
- await native.close();
589
- compiler.configureVXRNCompilerPlugin({
590
- enableReanimated: false,
591
- enableNativeWorklets: false
592
- });
593
- await rm(root2, {
594
- recursive: true,
595
- force: true
596
- });
597
- }
598
- });
599
- it.each([["unselected", "export default function value() { return 1 }; export const other = 2", `import { other } from 'pure-math'; globalThis.value = other`, /unselected export other/], ["missing", "export const other = 2", `import value from 'pure-math'; globalThis.value = value`, /default.*not exported|MISSING_EXPORT/], ["builtin", `import fs from 'node:fs'; export default function value() { return fs.readFileSync('x') }`, `import value from 'pure-math'; globalThis.value = value`, /runtime dependency node:fs/], ["global", "export default function value() { return process.pid }", `import value from 'pure-math'; globalThis.value = value`, /unsupported runtime globals: process/], ["dynamic", `export default function value() { return import('./other.js') }`, `import value from 'pure-math'; globalThis.value = value`, /dynamic imports are unsupported/]])("rejects %s through the native engine", async function (_name, source, entry, expected) {
600
- var root2 = await createWorkletsProject(false);
601
- var packageRoot = join(root2, "node_modules/pure-math");
602
- await mkdir(packageRoot, {
603
- recursive: true
604
- });
605
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
606
- type: "module",
607
- exports: "./index.js"
608
- }));
609
- await writeFile(join(packageRoot, "index.js"), source);
610
- await writeFile(join(root2, "entry.mjs"), entry);
611
- var compiler = await import("@vxrn/compiler");
612
- compiler.configureVXRNCompilerPlugin({
613
- enableReanimated: true,
614
- enableNativeWorklets: true
615
- });
616
- var native = await createNativeDevEngine({
617
- root: root2,
618
- port: 0,
619
- platform: "ios",
620
- plugins: [workletImportsPlugin({
621
- "pure-math": ["default"]
622
- }), {
623
- name: "worklet-import-negative-fixture",
624
- transform(_code, id) {
625
- if (id.endsWith("/__virtual-native-entry.tsx")) return `import './entry.mjs'`;
626
- }
627
- }]
628
- });
629
- try {
630
- await expect(native.getBundle()).rejects.toThrow(expected);
631
- } finally {
632
- await native.close();
633
- compiler.configureVXRNCompilerPlugin({
634
- enableReanimated: false,
635
- enableNativeWorklets: false
636
- });
637
- await rm(root2, {
638
- recursive: true,
639
- force: true
640
- });
641
- }
642
- });
643
- });
644
- describe("native Rolldown HMR runtime", function () {
645
- it.each([true, false])("keeps CommonJS default components callable through the native HMR wire path (Babel=%s)", async function (babel) {
646
- var root2 = await mkdtemp(join(tmpdir(), "vxrn-native-hmr-interop-"));
647
- var entry = join(root2, "entry.mjs");
648
- var packageRoot = join(root2, "node_modules/component");
649
- await mkdir(packageRoot, {
650
- recursive: true
651
- });
652
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
653
- main: "./component(view).js"
654
- }));
655
- await writeFile(join(packageRoot, "component(view).js"), babel ? `Object.defineProperty(exports, '__esModule', { value: true }); exports.default = function Component() { return 42 }` : `module.exports = function Component() { return 42 }`);
656
- var source = function (version) {
657
- return `
658
- import Component from 'component'
659
- globalThis.renderComponent = Component
660
- export const version = ${version}
661
- if (import.meta.hot) import.meta.hot.accept(() => {})
662
- `;
663
- };
664
- await writeFile(entry, source(1));
665
- var resolveUpdate;
666
- var updateReceived = new Promise(function (resolve) {
667
- resolveUpdate = resolve;
668
- });
669
- var native = await createNativeDevEngine({
670
- root: root2,
671
- port: 0,
672
- platform: "ios",
673
- plugins: [{
674
- name: "native-hmr-fixture-entry",
675
- transform(_code, id) {
676
- if (id.endsWith("/__virtual-native-entry.tsx")) return `import './entry.mjs'`;
677
- }
678
- }],
679
- onHmrUpdate: resolveUpdate
680
- });
681
- try {
682
- var initial = await native.getBundle();
683
- var context = {
684
- console,
685
- setTimeout,
686
- clearTimeout
687
- };
688
- runInNewContext(initial.code, context);
689
- expect(context.renderComponent()).toBe(42);
690
- var runtime = context.__rolldown_runtime__;
691
- await native.engine.registerClient(runtime.clientId);
692
- await writeFile(entry, source(2));
693
- var update = await updateReceived;
694
- expect(update.type).toBe("hmr:update");
695
- expect(update.clientId).toBe(runtime.clientId);
696
- expect(runtime.applyHmrUpdate(update.code, update.changedIds, update.seq)).toBe(true);
697
- expect(context.renderComponent()).toBe(42);
698
- } finally {
699
- await native.close();
700
- await rm(root2, {
701
- recursive: true,
702
- force: true
703
- });
704
- }
705
- });
706
- it("registers a Rolldown 1.2 client and applies a self-accepted patch", {
707
- timeout: 3e4
708
- }, async function () {
709
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-hmr-"));
710
- var entry = join(testRoot, "entry.js");
711
- var source = function (version) {
712
- return `
713
- globalThis.__vxrnHmrBody = '${version}'
714
- export const value = '${version}'
715
- if (import.meta.hot) {
716
- import.meta.hot.accept((next) => {
717
- globalThis.__vxrnHmrAccepted = next.value
718
- })
719
- }
720
- `;
721
- };
722
- await writeFile(entry, source("v1"));
723
- var resolveInitialOutput;
724
- var initialOutput = new Promise(function (resolve) {
725
- resolveInitialOutput = resolve;
726
- });
727
- var resolveHmrUpdate;
728
- var hmrUpdate = new Promise(function (resolve) {
729
- resolveHmrUpdate = resolve;
730
- });
731
- var registeredClientId;
732
- var engine = await dev({
733
- cwd: testRoot,
734
- input: entry,
735
- experimental: {
736
- devMode: {
737
- implement: getHmrRuntimeSource()
738
- }
739
- }
740
- }, {
741
- format: "esm"
742
- }, {
743
- onOutput(result2) {
744
- resolveInitialOutput(result2);
745
- },
746
- onHmrUpdates(result2) {
747
- if (!_instanceof(result2, Error) && result2.updates.some(function (item) {
748
- return item.clientId === registeredClientId && item.update.type === "Patch";
749
- })) resolveHmrUpdate(result2);
750
- }
751
- });
752
- try {
753
- var _result_updates_find;
754
- await engine.run();
755
- var initial = await initialOutput;
756
- if (_instanceof(initial, Error)) throw initial;
757
- var chunk = initial.output.find(function (item) {
758
- return item.type === "chunk" && item.isEntry;
759
- });
760
- expect(chunk).toBeTruthy();
761
- delete globalThis.__rolldown_runtime__;
762
- await import(`data:text/javascript;base64,${Buffer.from(chunk.code).toString("base64")}`);
763
- var runtime = globalThis.__rolldown_runtime__;
764
- expect(_type_of(runtime.clientId)).toBe("string");
765
- registeredClientId = runtime.clientId;
766
- await engine.registerClient(runtime.clientId);
767
- await writeFile(entry, source("v2"));
768
- var patch = (_result_updates_find = (await Promise.race([hmrUpdate, new Promise(function (_, reject) {
769
- return setTimeout(function () {
770
- return reject(/* @__PURE__ */new Error("timed out waiting for HMR patch"));
771
- }, 1e4);
772
- })])).updates.find(function (item) {
773
- return item.clientId === runtime.clientId && item.update.type === "Patch";
774
- })) === null || _result_updates_find === void 0 ? void 0 : _result_updates_find.update;
775
- expect(patch).toBeTruthy();
776
- var applyHmrUpdate = Reflect.get(runtime, "applyHmrUpdate");
777
- expect(Reflect.apply(applyHmrUpdate, runtime, [patch.code, patch.changedIds, patch.seq])).toBe(true);
778
- expect(globalThis.__vxrnHmrBody).toBe("v2");
779
- expect(globalThis.__vxrnHmrAccepted).toBe("v2");
780
- } finally {
781
- await engine.close();
782
- await rm(testRoot, {
783
- recursive: true,
784
- force: true
785
- });
786
- delete globalThis.__rolldown_runtime__;
787
- delete globalThis.__vxrnHmrBody;
788
- delete globalThis.__vxrnHmrAccepted;
789
- }
790
- });
791
- it("propagates a non-component update to a React Refresh boundary", {
792
- timeout: 3e4
793
- }, async function () {
794
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-refresh-boundary-"));
795
- var entry = join(testRoot, "entry.js");
796
- var leaf = join(testRoot, "leaf.js");
797
- await writeFile(entry, `
798
- import { value } from './leaf.js'
799
- globalThis.__vxrnRefreshBoundaryValue = value
800
- export function App() {}
801
- if (import.meta.hot) {
802
- import.meta.hot.acceptReactRefresh(() => {
803
- globalThis.__vxrnRefreshBoundaryAccepted = true
804
- })
805
- }
806
- `);
807
- await writeFile(leaf, `export const value = 'v1'`);
808
- var resolveInitialOutput;
809
- var initialOutput = new Promise(function (resolve) {
810
- resolveInitialOutput = resolve;
811
- });
812
- var resolveHmrUpdate;
813
- var hmrUpdate = new Promise(function (resolve) {
814
- resolveHmrUpdate = resolve;
815
- });
816
- var registeredClientId;
817
- var engine = await dev({
818
- cwd: testRoot,
819
- input: entry,
820
- experimental: {
821
- devMode: {
822
- implement: getHmrRuntimeSource()
823
- }
824
- }
825
- }, {
826
- format: "esm"
827
- }, {
828
- onOutput(result2) {
829
- resolveInitialOutput(result2);
830
- },
831
- onHmrUpdates(result2) {
832
- if (!_instanceof(result2, Error) && result2.updates.some(function (item) {
833
- return item.clientId === registeredClientId && item.update.type === "Patch";
834
- })) resolveHmrUpdate(result2);
835
- }
836
- });
837
- var previousRefreshRuntime = Reflect.get(globalThis, "__ReactRefresh");
838
- Reflect.set(globalThis, "__ReactRefresh", {
839
- isLikelyComponentType(value) {
840
- return typeof value === "function";
841
- }
842
- });
843
- try {
844
- var _result_updates_find;
845
- await engine.run();
846
- var initial = await initialOutput;
847
- if (_instanceof(initial, Error)) throw initial;
848
- var chunk = initial.output.find(function (item) {
849
- return item.type === "chunk" && item.isEntry;
850
- });
851
- expect(chunk).toBeTruthy();
852
- Reflect.deleteProperty(globalThis, "__rolldown_runtime__");
853
- await import(`data:text/javascript;base64,${Buffer.from(chunk.code).toString("base64")}`);
854
- var runtime = Reflect.get(globalThis, "__rolldown_runtime__");
855
- registeredClientId = runtime.clientId;
856
- await engine.registerClient(runtime.clientId);
857
- await writeFile(leaf, `export const value = 'v2'`);
858
- var patch = (_result_updates_find = (await Promise.race([hmrUpdate, new Promise(function (_, reject) {
859
- return setTimeout(function () {
860
- return reject(/* @__PURE__ */new Error("timed out waiting for HMR patch"));
861
- }, 1e4);
862
- })])).updates.find(function (item) {
863
- return item.clientId === runtime.clientId && item.update.type === "Patch";
864
- })) === null || _result_updates_find === void 0 ? void 0 : _result_updates_find.update;
865
- expect(patch).toBeTruthy();
866
- var applyHmrUpdate = Reflect.get(runtime, "applyHmrUpdate");
867
- expect(Reflect.apply(applyHmrUpdate, runtime, [patch.code, patch.changedIds, patch.seq])).toBe(true);
868
- expect(Reflect.get(globalThis, "__vxrnRefreshBoundaryValue")).toBe("v2");
869
- expect(Reflect.get(globalThis, "__vxrnRefreshBoundaryAccepted")).toBe(true);
870
- } finally {
871
- await engine.close();
872
- await rm(testRoot, {
873
- recursive: true,
874
- force: true
875
- });
876
- Reflect.deleteProperty(globalThis, "__rolldown_runtime__");
877
- Reflect.deleteProperty(globalThis, "__vxrnRefreshBoundaryValue");
878
- Reflect.deleteProperty(globalThis, "__vxrnRefreshBoundaryAccepted");
879
- if (previousRefreshRuntime === void 0) Reflect.deleteProperty(globalThis, "__ReactRefresh");else Reflect.set(globalThis, "__ReactRefresh", previousRefreshRuntime);
880
- }
881
- });
882
- });
883
- describe("native production import.meta lowering", function () {
884
- it("emits a Hermes-compatible bundle for guarded import.meta.env reads", async function () {
885
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-import-meta-"));
886
- await writeFile(join(testRoot, "entry.js"), `globalThis.__vxrnNativeImportMetaProbe = typeof import.meta !== 'undefined' && import.meta.env.DEV`);
887
- try {
888
- var result = await buildNativeBundle({
889
- root: testRoot,
890
- platform: "ios",
891
- entryFile: "entry.js"
892
- });
893
- expect(result.code).not.toContain("typeof import.meta");
894
- var context = {
895
- globalThis: {},
896
- process: {
897
- env: {}
898
- }
899
- };
900
- runInNewContext(result.code, context);
901
- expect(Reflect.get(context.globalThis, "__vxrnNativeImportMetaProbe")).toBe(false);
902
- } finally {
903
- await rm(testRoot, {
904
- recursive: true,
905
- force: true
906
- });
907
- }
908
- });
909
- });
910
- describe("native animated guard transform", function () {
911
- it("preserves line count and returns a composable source map", async function () {
912
- var plugin = nativeAnimatedGuardPlugin();
913
- if (typeof plugin.transform !== "function") throw new Error("native animated guard transform hook is not callable");
914
- var source = ["function call(methodName) {", " const method = nullthrows(NativeAnimatedModule)[methodName];", " method();", "}"].join("\n");
915
- var result = await Reflect.apply(plugin.transform, void 0, [source, "/project/node_modules/react-native/src/private/animated/NativeAnimatedHelper.js"]);
916
- expect(result.code.split("\n")).toHaveLength(source.split("\n").length);
917
- expect(result.code).toContain("if (typeof method !== 'function') return");
918
- expect(result.map).toEqual({
919
- version: 3,
920
- sources: ["/project/node_modules/react-native/src/private/animated/NativeAnimatedHelper.js"],
921
- sourcesContent: [source],
922
- names: [],
923
- mappings: "AAAA;AACA;AACA;AACA"
924
- });
925
- });
926
- });
927
- var root = "/tmp/vxrn-native-env-define-test-nonexistent";
928
- describe("getNativeTransformConfig platform env defines", function () {
929
- var _loop = function (_i2, _iter2) {
930
- var _loop2 = function (_i12, _iter12) {
931
- var dev2 = _iter12[_i12];
932
- it(`injects TAMAGUI_TARGET=native for ${platform} (dev=${dev2})`, function () {
933
- var {
934
- define
935
- } = getNativeTransformConfig(platform, dev2, root);
936
- expect(define["import.meta.env.TAMAGUI_TARGET"]).toBe("\"native\"");
937
- expect(define["process.env.TAMAGUI_TARGET"]).toBe("\"native\"");
938
- expect(define["import.meta.env.TAMAGUI_ENVIRONMENT"]).toBe(JSON.stringify(platform));
939
- expect(define["import.meta.env.VITE_ENVIRONMENT"]).toBe(JSON.stringify(platform));
940
- expect(define["import.meta.env.VITE_NATIVE"]).toBe("\"1\"");
941
- expect(define["import.meta.env.EXPO_OS"]).toBe(JSON.stringify(platform));
942
- var envObject = JSON.parse(define["import.meta.env"]);
943
- expect(envObject.TAMAGUI_TARGET).toBe("native");
944
- expect(envObject.TAMAGUI_ENVIRONMENT).toBe(platform);
945
- });
946
- };
947
- var platform = _iter2[_i2];
948
- for (var _i1 = 0, _iter1 = [true, false]; _i1 < _iter1.length; _i1++) _loop2(_i1, _iter1);
949
- };
950
- for (var _i = 0, _iter = ["ios", "android"]; _i < _iter.length; _i++) _loop(_i, _iter);
951
- it("inlines EXPO_PUBLIC values supplied by the native build environment", function () {
952
- var key = "EXPO_PUBLIC_VXRN_NATIVE_ENV_PROBE";
953
- var previous = process.env[key];
954
- process.env[key] = "native-env-value";
955
- try {
956
- var {
957
- define
958
- } = getNativeTransformConfig("ios", false, root);
959
- expect(define[`process.env.${key}`]).toBe("\"native-env-value\"");
960
- expect(define[`import.meta.env.${key}`]).toBe("\"native-env-value\"");
961
- expect(JSON.parse(define["import.meta.env"])[key]).toBe("native-env-value");
962
- } finally {
963
- if (previous === void 0) delete process.env[key];else process.env[key] = previous;
964
- }
965
- });
966
- it("keeps native platform values authoritative over inherited SSR env", function () {
967
- var previousEnvironment = process.env.VITE_ENVIRONMENT;
968
- var previousNative = process.env.VITE_NATIVE;
969
- process.env.VITE_ENVIRONMENT = "ssr";
970
- process.env.VITE_NATIVE = "";
971
- try {
972
- var {
973
- define
974
- } = getNativeTransformConfig("ios", false, root);
975
- var envObject = JSON.parse(define["import.meta.env"]);
976
- expect(define["process.env.VITE_ENVIRONMENT"]).toBe("\"ios\"");
977
- expect(define["import.meta.env.VITE_ENVIRONMENT"]).toBe("\"ios\"");
978
- expect(define["process.env.VITE_NATIVE"]).toBe("\"1\"");
979
- expect(define["import.meta.env.VITE_NATIVE"]).toBe("\"1\"");
980
- expect(envObject.VITE_ENVIRONMENT).toBe("ios");
981
- expect(envObject.VITE_NATIVE).toBe("1");
982
- } finally {
983
- if (previousEnvironment === void 0) delete process.env.VITE_ENVIRONMENT;else process.env.VITE_ENVIRONMENT = previousEnvironment;
984
- if (previousNative === void 0) delete process.env.VITE_NATIVE;else process.env.VITE_NATIVE = previousNative;
985
- }
986
- });
987
- });
988
- describe("wrapNativeBundleModuleScope", function () {
989
- var RUNTIME_MARKER = "//#region \\0rolldown/runtime.js";
990
- it("wraps module code after the prelude so top-level vars do not leak to global", function () {
991
- var out = wrapNativeBundleModuleScope(`globalThis.global = globalThis;
992
- globalThis.__DEV__ = true;
993
- ${RUNTIME_MARKER}
994
- var fetch_hot, fetch$1, Headers, Request, Response$1;
995
- globalThis.__rolldown_runtime__ = {};
996
- `);
997
- var openIdx = out.indexOf(";(function() {");
998
- expect(openIdx).toBeGreaterThan(-1);
999
- expect(out.indexOf("globalThis.__DEV__")).toBeLessThan(openIdx);
1000
- expect(out.indexOf("var fetch_hot")).toBeGreaterThan(openIdx);
1001
- expect(function () {
1002
- return new Function(out);
1003
- }).not.toThrow();
1004
- });
1005
- it("is a no-op when the runtime marker is absent (e.g. prod bundle)", function () {
1006
- var input = "var x = 1;\nconsole.log(x);\n";
1007
- expect(wrapNativeBundleModuleScope(input)).toBe(input);
1008
- });
1009
- });
1010
- describe("getHermesSWCIncludes", function () {
1011
- var CLASS_SET = ["transform-classes", "transform-parameters", "transform-block-scoping", "transform-class-properties", "transform-class-static-block", "transform-private-methods", "transform-private-property-in-object"];
1012
- it("always includes the full Hermes class-transform set (dev and prod)", function () {
1013
- expect(getHermesSWCIncludes(true)).toEqual(expect.arrayContaining(CLASS_SET));
1014
- expect(getHermesSWCIncludes(false)).toEqual(expect.arrayContaining(CLASS_SET));
1015
- });
1016
- it("adds transform-async-to-generator in development and production", function () {
1017
- expect(getHermesSWCIncludes(true)).toContain("transform-async-to-generator");
1018
- expect(getHermesSWCIncludes(false)).toContain("transform-async-to-generator");
1019
- });
1020
- it("lowers async generators for the Hermes development interpreter", async function () {
1021
- var plugin = hermesCompatSWCPlugin(true);
1022
- if (typeof plugin.transform !== "function") throw new Error("Hermes compatibility transform hook is not callable");
1023
- var result = await Reflect.apply(plugin.transform, void 0, ["export async function* values() { yield await Promise.resolve(1) }", "/project/async-generator.ts"]);
1024
- expect(result.code).not.toContain("async function*");
1025
- expect(result.code).not.toContain("async function *");
1026
- });
1027
- it("downlevels private fields, public class fields, and static blocks for Hermes", async function () {
1028
- var plugin = hermesCompatSWCPlugin(true);
1029
- if (typeof plugin.transform !== "function") throw new Error("Hermes compatibility transform hook is not callable");
1030
- var result = await Reflect.apply(plugin.transform, void 0, [`
1031
- class TransformProbe {
1032
- #privateField = 1
1033
- publicField = 2
1034
- static {
1035
- TransformProbe.initialized = true
1036
- }
1037
-
1038
- getSecret() {
1039
- return this.#privateField
1040
- }
1041
- }
1042
- `, "/project/TransformProbe.ts"]);
1043
- expect(result.code).not.toContain("#privateField");
1044
- expect(result.code).not.toMatch(/^\s*publicField\s*=/m);
1045
- expect(result.code).not.toContain("static {");
1046
- expect(result.code).toContain("this.publicField = 2");
1047
- });
1048
- it("preserves per-iteration bindings used by lazy method getters", async function () {
1049
- var plugin = hermesCompatSWCPlugin(true);
1050
- if (typeof plugin.transform !== "function") throw new Error("Hermes compatibility transform hook is not callable");
1051
- var result = await Reflect.apply(plugin.transform, void 0, [`
1052
- const installedGroups = new WeakMap()
1053
- function install(inst, methods) {
1054
- const proto = Object.getPrototypeOf(inst)
1055
- for (const key in methods) {
1056
- const fn = methods[key]
1057
- Object.defineProperty(proto, key, {
1058
- get() { return fn.bind(this) }
1059
- })
1060
- }
1061
- }
1062
- function Schema() {
1063
- install(this, {
1064
- nullish() { return 'nullish' },
1065
- apply(fn) { return fn(this) }
1066
- })
1067
- }
1068
- globalThis.__vxrnBlockScopeProbe = new Schema().nullish()
1069
- `, "/project/block-scope-loop.ts"]);
1070
- try {
1071
- new Function(result.code)();
1072
- expect(Reflect.get(globalThis, "__vxrnBlockScopeProbe")).toBe("nullish");
1073
- } finally {
1074
- Reflect.deleteProperty(globalThis, "__vxrnBlockScopeProbe");
1075
- }
1076
- });
1077
- it("bundles lowered classes whose constructors use default and rest parameters", async function () {
1078
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-hermes-parameters-"));
1079
- var entry = join(testRoot, "entry.js");
1080
- await writeFile(entry, `
1081
- class ParameterProbe {
1082
- prefix = 'value'
1083
-
1084
- constructor(value = 'default', ...rest) {
1085
- this.result = [this.prefix, value, ...rest].join(':')
1086
- }
1087
- }
1088
-
1089
- export const result = new ParameterProbe(undefined, 'rest-a', 'rest-b').result
1090
- `);
1091
- var build = await rolldown({
1092
- input: entry,
1093
- plugins: [hermesCompatSWCPlugin(true)]
1094
- });
1095
- try {
1096
- var chunk = (await build.generate({
1097
- format: "esm"
1098
- })).output.find(function (item) {
1099
- return item.type === "chunk";
1100
- });
1101
- expect(chunk).toBeTruthy();
1102
- if (!chunk) throw new Error("Rolldown did not emit a JavaScript chunk");
1103
- expect((await import(`data:text/javascript;base64,${Buffer.from(chunk.code).toString("base64")}`)).result).toBe("value:default:rest-a:rest-b");
1104
- } finally {
1105
- await build.close();
1106
- await rm(testRoot, {
1107
- recursive: true,
1108
- force: true
1109
- });
1110
- }
1111
- });
1112
- });
1113
- describe("hmrClientNoopPlugin", function () {
1114
- var plugin = hmrClientNoopPlugin();
1115
- var resolveId = plugin.resolveId;
1116
- var load = plugin.load;
1117
- var VIRTUAL_ID = "\0vxrn-hmr-client-noop";
1118
- it.each([["react-native/Libraries/Utilities/HMRClient", void 0], ["../Utilities/HMRClient", "/project/node_modules/react-native/Libraries/Core.js"], ["../../Utilities/HMRClient.js", "/project/react-native/Libraries/Core.js"], ["..\\Utilities\\HMRClient.js", "C:\\project\\react-native\\Libraries\\Core.js"], ["../Utilities/HMRClient.ts", "/project/node_modules/react-native/Core.js"], ["../Utilities/HMRClient.tsx", "/project/node_modules/react-native/Core.js"], ["../Utilities/HMRClient.cjs", "/project/node_modules/react-native/Core.js"]])("aliases RN HMRClient specifier %j to the no-op virtual module", function (source, importer) {
1119
- expect(resolveId(source, importer)).toEqual({
1120
- id: VIRTUAL_ID,
1121
- external: false
1122
- });
1123
- });
1124
- it.each(["react-native/Libraries/Utilities/HMRClientRegistry", "some/MyUtilities/HMRClient", "react-native/Libraries/Core/setUpDeveloperTools", "react"])("does not touch unrelated specifier %j", function (source) {
1125
- expect(resolveId(source)).toBeUndefined();
1126
- });
1127
- it("does not alias an app-authored Utilities/HMRClient module", function () {
1128
- expect(resolveId("../Utilities/HMRClient", "/project/src/App.tsx")).toBeUndefined();
1129
- });
1130
- it("loads a no-op module exposing every HMRClient method RN calls", function () {
1131
- var result = load(VIRTUAL_ID);
1132
- expect(result === null || result === void 0 ? void 0 : result.moduleType).toBe("js");
1133
- for (var _i = 0, _iter = ["setup", "enable", "disable", "registerBundle", "log", "isEnabled"]; _i < _iter.length; _i++) {
1134
- var method = _iter[_i];
1135
- expect(result.code).toContain(method);
1136
- }
1137
- expect(result.code).toContain("export default HMRClient");
1138
- });
1139
- it("does not load unrelated ids", function () {
1140
- expect(load("\0some-other-virtual")).toBeUndefined();
1141
- });
1142
- });
1143
- describe("vxrnCompilerPlugin React Refresh registration", function () {
1144
- it("keeps initial-bundle registrations visible to rolldown", async function () {
1145
- var previousNodeEnv = process.env.NODE_ENV;
1146
- process.env.NODE_ENV = "test";
1147
- try {
1148
- var transform = vxrnCompilerPlugin("ios", true).transform;
1149
- var code = (await transform("export const marker = \"$RefreshReg$(\"; export function Probe() { return <div>probe</div> }", "/project/src/Probe.tsx")).code;
1150
- expect(code).toContain("var __vxrnRefreshReg = globalThis.$RefreshReg$");
1151
- expect(code).toContain("__vxrnRefreshReg(");
1152
- expect(code).toContain("\"$RefreshReg$(\"");
1153
- expect(code).toContain("import.meta.hot.acceptReactRefresh(");
1154
- } finally {
1155
- process.env.NODE_ENV = previousNodeEnv;
1156
- }
1157
- });
1158
- });
1159
- describe("native required transform failures", function () {
1160
- it.each([true, false])("rejects valid worklet source when its required compiler transform fails (dev=%s)", async function (dev2) {
1161
- var testRoot = await createWorkletsProject();
1162
- var compiler = await import("@vxrn/compiler");
1163
- var spy = vi.spyOn(compiler, "transformWorklets").mockRejectedValue(/* @__PURE__ */new Error("NATIVE_TRANSFORM_NEGATIVE_CONTROL"));
1164
- compiler.configureVXRNCompilerPlugin({
1165
- enableReanimated: true
1166
- });
1167
- try {
1168
- var plugin = vxrnCompilerPlugin("ios", dev2, testRoot);
1169
- if (typeof plugin.transform !== "function") throw new Error("vxrn compiler transform hook is not callable");
1170
- await expect(Reflect.apply(plugin.transform, void 0, [nativeTransformProbe, join(testRoot, "entry.ts")])).rejects.toThrow("NATIVE_TRANSFORM_NEGATIVE_CONTROL");
1171
- } finally {
1172
- spy.mockRestore();
1173
- compiler.configureVXRNCompilerPlugin({
1174
- enableReanimated: false
1175
- });
1176
- await rm(testRoot, {
1177
- recursive: true,
1178
- force: true
1179
- });
1180
- }
1181
- });
1182
- it("returns a dev build error and no output when the required compiler transform fails", async function () {
1183
- var testRoot = await createWorkletsProject();
1184
- var compiler = await import("@vxrn/compiler");
1185
- var spy = vi.spyOn(compiler, "transformWorklets").mockRejectedValue(/* @__PURE__ */new Error("NATIVE_TRANSFORM_NEGATIVE_CONTROL"));
1186
- compiler.configureVXRNCompilerPlugin({
1187
- enableReanimated: true
1188
- });
1189
- var resolveOutput;
1190
- var output = new Promise(function (resolve) {
1191
- resolveOutput = resolve;
1192
- });
1193
- var engine = await dev({
1194
- cwd: testRoot,
1195
- input: join(testRoot, "entry.ts"),
1196
- plugins: [vxrnCompilerPlugin("ios", true, testRoot)]
1197
- }, {
1198
- format: "esm"
1199
- }, {
1200
- onOutput: resolveOutput
1201
- });
1202
- try {
1203
- await engine.run();
1204
- var result = await output;
1205
- expect(result).toBeInstanceOf(Error);
1206
- expect(String(result)).toContain("NATIVE_TRANSFORM_NEGATIVE_CONTROL");
1207
- } finally {
1208
- spy.mockRestore();
1209
- await engine.close();
1210
- compiler.configureVXRNCompilerPlugin({
1211
- enableReanimated: false
1212
- });
1213
- await rm(testRoot, {
1214
- recursive: true,
1215
- force: true
1216
- });
1217
- }
1218
- });
1219
- it("emits no production bundle when the required compiler transform fails", async function () {
1220
- var testRoot = await createWorkletsProject();
1221
- var compiler = await import("@vxrn/compiler");
1222
- var spy = vi.spyOn(compiler, "transformWorklets").mockRejectedValue(/* @__PURE__ */new Error("NATIVE_TRANSFORM_NEGATIVE_CONTROL"));
1223
- compiler.configureVXRNCompilerPlugin({
1224
- enableReanimated: true
1225
- });
1226
- try {
1227
- await expect(buildNativeBundle({
1228
- root: testRoot,
1229
- platform: "ios",
1230
- entryFile: "entry.ts"
1231
- })).rejects.toThrow("NATIVE_TRANSFORM_NEGATIVE_CONTROL");
1232
- } finally {
1233
- spy.mockRestore();
1234
- compiler.configureVXRNCompilerPlugin({
1235
- enableReanimated: false
1236
- });
1237
- await rm(testRoot, {
1238
- recursive: true,
1239
- force: true
1240
- });
1241
- }
1242
- });
1243
- it("rejects Hermes compatibility transform errors instead of returning source", async function () {
1244
- var plugin = hermesCompatSWCPlugin(true);
1245
- if (typeof plugin.transform !== "function") throw new Error("Hermes compatibility transform hook is not callable");
1246
- await expect(Reflect.apply(plugin.transform, void 0, ["class TransformProbe { value = ; }", "/project/TransformProbe.ts"])).rejects.toBeTruthy();
1247
- });
1248
- it("returns maps for every required production transform", async function () {
1249
- var testRoot = await createWorkletsProject(false);
1250
- var compiler = await import("@vxrn/compiler");
1251
- compiler.configureVXRNCompilerPlugin({
1252
- enableReanimated: true
1253
- });
1254
- try {
1255
- var compilerPlugin = vxrnCompilerPlugin("ios", false, testRoot, true);
1256
- if (typeof compilerPlugin.transform !== "function") throw new Error("vxrn compiler transform hook is not callable");
1257
- expect((await Reflect.apply(compilerPlugin.transform, void 0, [nativeTransformProbe, join(testRoot, "entry.ts")])).map).toBeTruthy();
1258
- var hermesPlugin = hermesCompatSWCPlugin(false, true);
1259
- if (typeof hermesPlugin.transform !== "function") throw new Error("Hermes compatibility transform hook is not callable");
1260
- expect((await Reflect.apply(hermesPlugin.transform, void 0, ["export class TransformProbe { value = 1 }", join(testRoot, "TransformProbe.ts")])).map).toBeTruthy();
1261
- } finally {
1262
- compiler.configureVXRNCompilerPlugin({
1263
- enableReanimated: false
1264
- });
1265
- await rm(testRoot, {
1266
- recursive: true,
1267
- force: true
1268
- });
1269
- }
1270
- });
1271
- it("composes source maps across React Compiler, Fast Refresh, and module wrapper back to original source lines", async function () {
1272
- var {
1273
- TraceMap: TraceMap2,
1274
- originalPositionFor: originalPositionFor2
1275
- } = await import("@jridgewell/trace-mapping");
1276
- var compiler = await import("@vxrn/compiler");
1277
- compiler.configureVXRNCompilerPlugin({
1278
- enableCompiler: true
1279
- });
1280
- try {
1281
- var plugin = vxrnCompilerPlugin("ios", true, "/project", true);
1282
- if (typeof plugin.transform !== "function") throw new Error("transform hook not callable");
1283
- var inputCode = `import { useState } from 'react'
1284
-
1285
- export function Counter() {
1286
- const [count, setCount] = useState(0)
1287
- return <button onClick={() => setCount(count + 1)}>{count}</button>
1288
- }
1289
- `;
1290
- var id = "/project/Counter.tsx";
1291
- var result = await Reflect.apply(plugin.transform, void 0, [inputCode, id]);
1292
- expect(result).toBeDefined();
1293
- expect(result.map).toBeDefined();
1294
- var tracer = new TraceMap2(result.map);
1295
- var counterLineIndex = result.code.split("\n").findIndex(function (l) {
1296
- return l.includes("function Counter");
1297
- });
1298
- expect(counterLineIndex).toBeGreaterThan(0);
1299
- var pos = originalPositionFor2(tracer, {
1300
- line: counterLineIndex + 1,
1301
- column: 16
1302
- });
1303
- expect(pos.source).toBe(id);
1304
- expect(pos.line).toBe(3);
1305
- } finally {
1306
- compiler.configureVXRNCompilerPlugin({
1307
- enableCompiler: false
1308
- });
1309
- }
1310
- });
1311
- it("composes source maps accurately across mixed path (React Compiler + Babel + Fast Refresh + module wrapper)", async function () {
1312
- var {
1313
- TraceMap: TraceMap2,
1314
- originalPositionFor: originalPositionFor2
1315
- } = await import("@jridgewell/trace-mapping");
1316
- var compiler = await import("@vxrn/compiler");
1317
- var origEnv = process.env.VXRN_USE_BABEL_FOR_GENERATORS;
1318
- process.env.VXRN_USE_BABEL_FOR_GENERATORS = "1";
1319
- compiler.configureVXRNCompilerPlugin({
1320
- enableCompiler: true,
1321
- enableReanimated: false
1322
- });
1323
- try {
1324
- var plugin = vxrnCompilerPlugin("ios", true, "/project", true);
1325
- if (typeof plugin.transform !== "function") throw new Error("transform hook not callable");
1326
- var inputCode = `export function Counter() { return <View />; }
1327
-
1328
-
1329
-
1330
-
1331
-
1332
-
1333
-
1334
- export async function* probe() { throw new Error("MARKER"); }
1335
- `;
1336
- var id = "/project/Counter.tsx";
1337
- var result = await Reflect.apply(plugin.transform, void 0, [inputCode, id]);
1338
- expect(result).toBeDefined();
1339
- expect(result.map).toBeDefined();
1340
- expect(result.code.includes("_wrapAsyncGenerator") || result.code.includes("regeneratorRuntime")).toBe(true);
1341
- var tracer = new TraceMap2(result.map);
1342
- var lines = result.code.split("\n");
1343
- var markerLineIndex = lines.findIndex(function (l) {
1344
- return l.includes("MARKER");
1345
- });
1346
- expect(markerLineIndex).toBeGreaterThan(0);
1347
- var markerCol = lines[markerLineIndex].indexOf("throw");
1348
- var pos = originalPositionFor2(tracer, {
1349
- line: markerLineIndex + 1,
1350
- column: markerCol
1351
- });
1352
- expect(pos.source).toBe(id);
1353
- expect(pos.line).toBe(9);
1354
- expect(pos.column).toBe(33);
1355
- var compilerOut = await compiler.transformOxcReactCompiler(id, inputCode, "19", true);
1356
- var remapping = (await import("@jridgewell/remapping")).default;
1357
- var badPos = originalPositionFor2(new TraceMap2(remapping([result.map, compilerOut.map], function () {
1358
- return null;
1359
- })), {
1360
- line: markerLineIndex + 1,
1361
- column: markerCol
1362
- });
1363
- expect(badPos.source).toBeNull();
1364
- expect(badPos.line).toBeNull();
1365
- } finally {
1366
- compiler.configureVXRNCompilerPlugin({
1367
- enableCompiler: false
1368
- });
1369
- if (origEnv !== void 0) process.env.VXRN_USE_BABEL_FOR_GENERATORS = origEnv;else delete process.env.VXRN_USE_BABEL_FOR_GENERATORS;
1370
- }
1371
- });
1372
- it("transforms worklets via native Rust/Wasm SWC with zero Babel execution and accurate sourcemaps", async function () {
1373
- var {
1374
- TraceMap: TraceMap2,
1375
- originalPositionFor: originalPositionFor2
1376
- } = await import("@jridgewell/trace-mapping");
1377
- var compiler = await import("@vxrn/compiler");
1378
- var {
1379
- vi: vi2
1380
- } = await import("vitest");
1381
- var babelSpy = vi2.spyOn(compiler, "transformBabel");
1382
- compiler.configureVXRNCompilerPlugin({
1383
- enableReanimated: true,
1384
- enableNativeWorklets: true,
1385
- enableCompiler: false
1386
- });
1387
- try {
1388
- var projectRoot = process.cwd();
1389
- var plugin = vxrnCompilerPlugin("ios", true, projectRoot, true);
1390
- if (typeof plugin.transform !== "function") throw new Error("transform hook not callable");
1391
- var inputCode = `import { useAnimatedStyle } from 'react-native-reanimated'
1392
-
1393
- export function Box() {
1394
- const animatedStyle = useAnimatedStyle(() => {
1395
- return { opacity: 1 }
1396
- })
1397
- return <div style={animatedStyle} />
1398
- }
1399
- `;
1400
- var id = join(projectRoot, "Box.tsx");
1401
- var result = await Reflect.apply(plugin.transform, void 0, [inputCode, id]);
1402
- expect(result).toBeDefined();
1403
- expect(result.code).toContain("__workletHash");
1404
- expect(result.code).toContain("__closure");
1405
- expect(babelSpy).not.toHaveBeenCalled();
1406
- expect(result.map).toBeDefined();
1407
- var tracer = new TraceMap2(result.map);
1408
- var boxLineIndex = result.code.split("\n").findIndex(function (l) {
1409
- return l.includes("export function Box");
1410
- });
1411
- expect(boxLineIndex).toBeGreaterThan(0);
1412
- var pos = originalPositionFor2(tracer, {
1413
- line: boxLineIndex + 1,
1414
- column: 16
1415
- });
1416
- expect(pos.source).toBe(id);
1417
- expect(pos.line).toBe(3);
1418
- } finally {
1419
- babelSpy.mockRestore();
1420
- compiler.configureVXRNCompilerPlugin({
1421
- enableReanimated: false,
1422
- enableNativeWorklets: false
1423
- });
1424
- }
1425
- });
1426
- it("retains the existing Babel backend by default when enableNativeWorklets is false for auto-detected Reanimated and ordinary configured worklets plugin", async function () {
1427
- var compiler = await import("@vxrn/compiler");
1428
- var {
1429
- vi: vi2
1430
- } = await import("vitest");
1431
- var babelSpy = vi2.spyOn(compiler, "transformBabel").mockResolvedValue({
1432
- code: "/* babel transformed */"
1433
- });
1434
- var workletSpy = vi2.spyOn(compiler, "transformWorklets");
1435
- compiler.configureVXRNCompilerPlugin({
1436
- enableReanimated: true,
1437
- enableNativeWorklets: false
1438
- });
1439
- var getBabelOptionsSpy = vi2.spyOn(compiler, "getBabelOptions").mockReturnValue({
1440
- plugins: ["react-native-reanimated/plugin"]
1441
- });
1442
- try {
1443
- var projectRoot = process.cwd();
1444
- var plugin = vxrnCompilerPlugin("ios", true, projectRoot, false);
1445
- if (typeof plugin.transform !== "function") throw new Error("transform hook not callable");
1446
- var inputCode = `export function fn() { 'worklet'; return 1 }`;
1447
- var id = join(projectRoot, "DefaultWorklet.tsx");
1448
- expect(await Reflect.apply(plugin.transform, void 0, [inputCode, id])).toBeDefined();
1449
- expect(babelSpy).toHaveBeenCalledWith(id, inputCode, expect.objectContaining({
1450
- plugins: expect.arrayContaining(["react-native-reanimated/plugin"])
1451
- }));
1452
- expect(workletSpy).not.toHaveBeenCalled();
1453
- } finally {
1454
- babelSpy.mockRestore();
1455
- workletSpy.mockRestore();
1456
- getBabelOptionsSpy.mockRestore();
1457
- compiler.configureVXRNCompilerPlugin({
1458
- enableReanimated: false,
1459
- enableNativeWorklets: false
1460
- });
1461
- }
1462
- });
1463
- it("intercepts tuple worklet plugins with options, executes native SWC with options, and skips Babel when enableNativeWorklets is true", async function () {
1464
- var compiler = await import("@vxrn/compiler");
1465
- var {
1466
- vi: vi2
1467
- } = await import("vitest");
1468
- var babelSpy = vi2.spyOn(compiler, "transformBabel");
1469
- var workletSpy = vi2.spyOn(compiler, "transformWorklets");
1470
- compiler.configureVXRNCompilerPlugin({
1471
- enableReanimated: true,
1472
- enableNativeWorklets: true
1473
- });
1474
- var getBabelOptionsSpy = vi2.spyOn(compiler, "getBabelOptions").mockReturnValue({
1475
- plugins: [["react-native-reanimated/plugin", {
1476
- globals: ["customGlobal"]
1477
- }]]
1478
- });
1479
- try {
1480
- var projectRoot = process.cwd();
1481
- var plugin = vxrnCompilerPlugin("ios", true, projectRoot, false);
1482
- if (typeof plugin.transform !== "function") throw new Error("transform hook not callable");
1483
- var inputCode = `export function fn() { 'worklet'; return customGlobal * 2 }`;
1484
- var id = join(projectRoot, "TupleWorklet.tsx");
1485
- var result = await Reflect.apply(plugin.transform, void 0, [inputCode, id]);
1486
- expect(result).toBeDefined();
1487
- expect(result.code).toContain("__workletHash");
1488
- expect(workletSpy).toHaveBeenCalledWith(id, expect.any(String), false, expect.objectContaining({
1489
- globals: ["customGlobal"],
1490
- projectRoot
1491
- }));
1492
- expect(babelSpy).not.toHaveBeenCalled();
1493
- } finally {
1494
- babelSpy.mockRestore();
1495
- workletSpy.mockRestore();
1496
- getBabelOptionsSpy.mockRestore();
1497
- compiler.configureVXRNCompilerPlugin({
1498
- enableReanimated: false,
1499
- enableNativeWorklets: false
1500
- });
1501
- }
1502
- });
1503
- });
1504
- describe("native production minification", function () {
1505
- async function writeMinifyFixture() {
1506
- var root2 = await mkdtemp(join(tmpdir(), "vxrn-native-minify-"));
1507
- var dep = join(root2, "node_modules", "legacy-color");
1508
- await mkdir(dep, {
1509
- recursive: true
1510
- });
1511
- await writeFile(join(dep, "package.json"), JSON.stringify({
1512
- name: "legacy-color",
1513
- main: "index.js"
1514
- }));
1515
- await writeFile(join(dep, "index.js"), `function LegacyColor(value) { this.value = value }
1516
- LegacyColor.prototype.describe = function () { return 'legacy:' + this.value }
1517
- module.exports = LegacyColor`);
1518
- await writeFile(join(root2, "views.js"), `'use strict';
1519
- import LegacyColor from 'legacy-color'
1520
- import { level } from './entry.js'
1521
- export const describeHeader = () => new LegacyColor(level()).describe()`);
1522
- await writeFile(join(root2, "entry.js"), `import { describeHeader } from './views.js'
1523
- export const level = () => 'header'
1524
- globalThis.minifyProbe = describeHeader()`);
1525
- return root2;
1526
- }
1527
- function runFixture(code) {
1528
- var context = {
1529
- console
1530
- };
1531
- runInNewContext(code, context);
1532
- return Reflect.get(context, "minifyProbe");
1533
- }
1534
- it("minifies when asked, leaves the bundle alone when not, and both behave the same", async function () {
1535
- var root2 = await writeMinifyFixture();
1536
- try {
1537
- var [plain, minified] = await Promise.all([false, true].map(function (minify) {
1538
- return buildNativeBundle({
1539
- root: root2,
1540
- platform: "ios",
1541
- entryFile: "entry.js",
1542
- minify
1543
- });
1544
- }));
1545
- expect(plain.code).toContain("__toESM");
1546
- expect(plain.code).toContain("describeHeader");
1547
- expect(plain.code.split("\n").length).toBeGreaterThan(40);
1548
- expect(minified.code).not.toContain("describeHeader");
1549
- expect(minified.code).not.toContain("//#region");
1550
- expect(minified.code.length).toBeLessThan(plain.code.length * .7);
1551
- expect(runFixture(minified.code)).toBe("legacy:header");
1552
- expect(runFixture(plain.code)).toBe("legacy:header");
1553
- } finally {
1554
- await rm(root2, {
1555
- recursive: true,
1556
- force: true
1557
- });
1558
- }
1559
- });
1560
- it("defaults to react native's rule: minify a production bundle, never a dev one", async function () {
1561
- var root2 = await writeMinifyFixture();
1562
- try {
1563
- var [prod, devBundle, explicitOff] = await Promise.all([buildNativeBundle({
1564
- root: root2,
1565
- platform: "ios",
1566
- entryFile: "entry.js"
1567
- }), buildNativeBundle({
1568
- root: root2,
1569
- platform: "ios",
1570
- entryFile: "entry.js",
1571
- dev: true
1572
- }), buildNativeBundle({
1573
- root: root2,
1574
- platform: "ios",
1575
- entryFile: "entry.js",
1576
- minify: false
1577
- })]);
1578
- expect(prod.code).not.toContain("describeHeader");
1579
- expect(devBundle.code).toContain("describeHeader");
1580
- expect(explicitOff.code).toContain("describeHeader");
1581
- expect(prod.code.length).toBeLessThan(explicitOff.code.length);
1582
- } finally {
1583
- await rm(root2, {
1584
- recursive: true,
1585
- force: true
1586
- });
1587
- }
1588
- });
1589
- });
1590
- describe("native production assets", function () {
1591
- it("registers scale siblings and keeps monorepo assets inside assetsDest", async function () {
1592
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-assets-"));
1593
- var appRoot = join(testRoot, "workspace/apps/native-app");
1594
- var appAssets = join(appRoot, "assets");
1595
- var packageAssets = join(testRoot, "workspace/node_modules/example/assets");
1596
- var assetsDest = join(testRoot, "output");
1597
- await mkdir(appAssets, {
1598
- recursive: true
1599
- });
1600
- await mkdir(packageAssets, {
1601
- recursive: true
1602
- });
1603
- await writeFile(join(appAssets, "icon.png"), "icon-1x");
1604
- await writeFile(join(appAssets, "icon@2x.png"), "icon-2x");
1605
- await writeFile(join(appAssets, "icon@3x.png"), "icon-3x");
1606
- await writeFile(join(packageAssets, "back.png"), "back-1x");
1607
- await writeFile(join(packageAssets, "back@2x.png"), "back-2x");
1608
- await writeFile(join(appRoot, "entry.js"), `
1609
- import icon from './assets/icon.png'
1610
- import back from '../../node_modules/example/assets/back.png'
1611
- globalThis.__nativeAssetProbe = [icon, back]
1612
- `);
1613
- try {
1614
- var _registry_resolve;
1615
- var assetData = await getNativeAssetData(join(appAssets, "icon.png"), appRoot, "ios");
1616
- expect(assetData.scales).toEqual([1, 2, 3]);
1617
- expect(assetData.files.map(function (file2) {
1618
- return file2.slice(appAssets.length + 1);
1619
- })).toEqual(["icon.png", "icon@2x.png", "icon@3x.png"]);
1620
- expect(assetData.hash).not.toBe("");
1621
- var registry = createNativeDevAssetRegistry();
1622
- registry.register(assetData);
1623
- expect((_registry_resolve = registry.resolve("/assets/assets/icon@2x.png", assetData.hash)) === null || _registry_resolve === void 0 ? void 0 : _registry_resolve.filePath).toBe(join(appAssets, "icon@2x.png"));
1624
- expect(registry.resolve("/assets/assets/icon.png", "stale-content-hash")).toBeUndefined();
1625
- expect(registry.resolve("/assets/../../package.json", assetData.hash)).toBeUndefined();
1626
- var result = await buildNativeBundle({
1627
- root: appRoot,
1628
- platform: "ios",
1629
- entryFile: "entry.js",
1630
- assetsDest
1631
- });
1632
- var registered = [];
1633
- runInNewContext(result.code, {
1634
- console,
1635
- require: function (id) {
1636
- return id === "react-native/Libraries/Image/AssetRegistry" ? {
1637
- registerAsset: function (asset) {
1638
- registered.push(asset);
1639
- return asset;
1640
- }
1641
- } : {};
1642
- }
1643
- });
1644
- expect(registered.map(function (asset) {
1645
- return [asset.name, asset.scales];
1646
- })).toEqual([["icon", [1, 2, 3]], ["back", [1, 2]]]);
1647
- for (var _i = 0, _iter = ["icon.png", "icon@2x.png", "icon@3x.png"]; _i < _iter.length; _i++) {
1648
- var file = _iter[_i];
1649
- expect(existsSync(join(assetsDest, "assets/assets", file))).toBe(true);
1650
- }
1651
- for (var _i1 = 0, _iter1 = ["back.png", "back@2x.png"]; _i1 < _iter1.length; _i1++) {
1652
- var file1 = _iter1[_i1];
1653
- expect(existsSync(join(assetsDest, "assets/_/_/node_modules/example/assets", file1))).toBe(true);
1654
- }
1655
- expect(existsSync(join(testRoot, "node_modules/example/assets/back.png"))).toBe(false);
1656
- } finally {
1657
- await rm(testRoot, {
1658
- recursive: true,
1659
- force: true
1660
- });
1661
- }
1662
- });
1663
- });
1664
- describe("native conditional exports", function () {
1665
- it("uses the require condition for CommonJS calls", async function () {
1666
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-conditions-"));
1667
- var packageRoot = join(testRoot, "node_modules/conditional-helper");
1668
- await mkdir(packageRoot, {
1669
- recursive: true
1670
- });
1671
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
1672
- name: "conditional-helper",
1673
- exports: {
1674
- ".": {
1675
- import: "./esm.js",
1676
- require: "./cjs.cjs"
1677
- }
1678
- },
1679
- type: "module"
1680
- }));
1681
- await writeFile(join(packageRoot, "esm.js"), `export default function helper() { return 'import' }`);
1682
- await writeFile(join(packageRoot, "cjs.cjs"), `module.exports = function helper() { return 'require' }`);
1683
- await writeFile(join(testRoot, "entry.cjs"), `
1684
- const helper = require('conditional-helper')
1685
- globalThis.__vxrnConditionalExportProbe = helper()
1686
- `);
1687
- try {
1688
- var result = await buildNativeBundle({
1689
- root: testRoot,
1690
- platform: "ios",
1691
- entryFile: "entry.cjs",
1692
- dev: true
1693
- });
1694
- var context = {
1695
- clearTimeout,
1696
- console,
1697
- process: {
1698
- env: {}
1699
- },
1700
- setTimeout
1701
- };
1702
- runInNewContext(result.code, context);
1703
- expect(Reflect.get(context, "__vxrnConditionalExportProbe")).toBe("require");
1704
- } finally {
1705
- await rm(testRoot, {
1706
- recursive: true,
1707
- force: true
1708
- });
1709
- }
1710
- });
1711
- it("unwraps the default export of Babel CommonJS modules in dev output", {
1712
- timeout: 3e4
1713
- }, async function () {
1714
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-cjs-default-"));
1715
- var packageRoot = join(testRoot, "node_modules/default-export-helper");
1716
- await mkdir(packageRoot, {
1717
- recursive: true
1718
- });
1719
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
1720
- name: "default-export-helper",
1721
- main: "./index.js"
1722
- }));
1723
- await writeFile(join(packageRoot, "index.js"), `Object.defineProperty(exports, '__esModule', { value: true }); exports.default = function Component() {}`);
1724
- await writeFile(join(testRoot, "entry.js"), `import Component from 'default-export-helper'; globalThis.__vxrnCjsDefaultProbe = typeof Component`);
1725
- var resolveOutput;
1726
- var output = new Promise(function (resolve) {
1727
- resolveOutput = resolve;
1728
- });
1729
- var engine = await dev({
1730
- cwd: testRoot,
1731
- input: join(testRoot, "entry.js"),
1732
- experimental: {
1733
- devMode: {
1734
- implement: getHmrRuntimeSource()
1735
- }
1736
- }
1737
- }, {
1738
- format: "esm",
1739
- codeSplitting: false,
1740
- strictExecutionOrder: true
1741
- }, {
1742
- onOutput: resolveOutput
1743
- });
1744
- try {
1745
- await engine.run();
1746
- var result = await output;
1747
- if (_instanceof(result, Error)) throw result;
1748
- var chunk = result.output.find(function (item) {
1749
- return item.type === "chunk" && item.isEntry;
1750
- });
1751
- if (!chunk || chunk.type !== "chunk") throw new Error("Rolldown did not emit a native dev entry chunk");
1752
- var nodeModeCode = chunk.code.replace(/(\b__toESM(?:\$\d+)?\(\s*require[\w$]*\(\)\s*)\)/, "$1, 1)");
1753
- expect(nodeModeCode).not.toBe(chunk.code);
1754
- Reflect.deleteProperty(globalThis, "__rolldown_runtime__");
1755
- await import(`data:text/javascript;base64,${Buffer.from(nodeModeCode).toString("base64")}`);
1756
- expect(Reflect.get(globalThis, "__vxrnCjsDefaultProbe")).toBe("object");
1757
- Reflect.deleteProperty(globalThis, "__rolldown_runtime__");
1758
- Reflect.deleteProperty(globalThis, "__vxrnCjsDefaultProbe");
1759
- var normalized = normalizeNativeCommonJSInterop(nodeModeCode);
1760
- await import(`data:text/javascript;base64,${Buffer.from(normalized).toString("base64")}`);
1761
- expect(Reflect.get(globalThis, "__vxrnCjsDefaultProbe")).toBe("function");
1762
- } finally {
1763
- await engine.close();
1764
- Reflect.deleteProperty(globalThis, "__rolldown_runtime__");
1765
- Reflect.deleteProperty(globalThis, "__vxrnCjsDefaultProbe");
1766
- await rm(testRoot, {
1767
- recursive: true,
1768
- force: true
1769
- });
1770
- }
1771
- });
1772
- it("unwraps the default export of Babel CommonJS modules in production output", async function () {
1773
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-prod-cjs-default-"));
1774
- var packageRoot = join(testRoot, "node_modules/default-export-helper");
1775
- await mkdir(packageRoot, {
1776
- recursive: true
1777
- });
1778
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
1779
- name: "default-export-helper",
1780
- main: "./index.js"
1781
- }));
1782
- await writeFile(join(packageRoot, "index.js"), `Object.defineProperty(exports, '__esModule', { value: true }); exports.default = function Component() {}`);
1783
- await writeFile(join(testRoot, "entry.js"), `import Component from 'default-export-helper'; globalThis.__vxrnProdCjsDefaultProbe = typeof Component`);
1784
- try {
1785
- var result = await buildNativeBundle({
1786
- root: testRoot,
1787
- platform: "ios",
1788
- entryFile: "entry.js"
1789
- });
1790
- var context = {
1791
- clearTimeout,
1792
- console,
1793
- process: {
1794
- env: {}
1795
- },
1796
- setTimeout
1797
- };
1798
- runInNewContext(result.code, context);
1799
- expect(Reflect.get(context, "__vxrnProdCjsDefaultProbe")).toBe("function");
1800
- } finally {
1801
- await rm(testRoot, {
1802
- recursive: true,
1803
- force: true
1804
- });
1805
- }
1806
- });
1807
- });
1808
- describe("native Flow sources", function () {
1809
- it.each(["", `/* ${"license text ".repeat(150)} */
1810
- `])("strips third-party Flow following a license header (%#)", async function (license) {
1811
- var testRoot = await mkdtemp(join(tmpdir(), "vxrn-native-flow-"));
1812
- var packageRoot = join(testRoot, "node_modules/@flowy-scope/flowy-lib");
1813
- await mkdir(packageRoot, {
1814
- recursive: true
1815
- });
1816
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
1817
- name: "@flowy-scope/flowy-lib",
1818
- main: "./js/Flowy.js"
1819
- }));
1820
- await mkdir(join(packageRoot, "js"), {
1821
- recursive: true
1822
- });
1823
- await writeFile(join(packageRoot, "js/Flowy.js"), `${license}/**
1824
- * @flow
1825
- * @format
1826
- */
1827
-
1828
- type FlowyProps = {|
1829
- +value: number,
1830
- |}
1831
-
1832
- export default class Flowy {
1833
- _seen: boolean = false
1834
-
1835
- measure(props: FlowyProps): number {
1836
- const { value, ...rest }: FlowyProps = props
1837
- this._seen = true
1838
- return ((value: any): number) + Object.keys(rest).length
1839
- }
1840
- }
1841
- `);
1842
- await writeFile(join(testRoot, "entry.js"), `import Flowy from '@flowy-scope/flowy-lib'
1843
- globalThis.__vxrnFlowProbe = new Flowy().measure({ value: 41 }) + 1
1844
- `);
1845
- try {
1846
- var result = await buildNativeBundle({
1847
- root: testRoot,
1848
- platform: "ios",
1849
- entryFile: "entry.js"
1850
- });
1851
- var context = {
1852
- clearTimeout,
1853
- console,
1854
- process: {
1855
- env: {}
1856
- },
1857
- setTimeout
1858
- };
1859
- runInNewContext(result.code, context);
1860
- expect(Reflect.get(context, "__vxrnFlowProbe")).toBe(42);
1861
- } finally {
1862
- await rm(testRoot, {
1863
- recursive: true,
1864
- force: true
1865
- });
1866
- }
1867
- });
1868
- });
1869
- describe("native bundle source maps", function () {
1870
- var generatedPositionOf = function (code, marker) {
1871
- var _ref;
1872
- var _before_match;
1873
- var index = code.indexOf(marker);
1874
- expect(index).toBeGreaterThan(-1);
1875
- var before = code.slice(0, index);
1876
- var lastNewline = before.lastIndexOf("\n");
1877
- return {
1878
- line: ((_ref = (_before_match = before.match(/\n/g)) === null || _before_match === void 0 ? void 0 : _before_match.length) !== null && _ref !== void 0 ? _ref : 0) + 1,
1879
- column: index - lastNewline - 1
1880
- };
1881
- };
1882
- it("resolves a frame to the authored file and line across an app file and a package file", {
1883
- timeout: 6e4
1884
- }, async function () {
1885
- var testRoot = realpathSync(await mkdtemp(join(tmpdir(), "vxrn-native-sourcemap-")));
1886
- var packageRoot = join(testRoot, "node_modules/probe-package");
1887
- await mkdir(packageRoot, {
1888
- recursive: true
1889
- });
1890
- await writeFile(join(packageRoot, "package.json"), JSON.stringify({
1891
- name: "probe-package",
1892
- main: "index.js",
1893
- type: "module"
1894
- }));
1895
- await writeFile(join(packageRoot, "index.js"), [`function packageThrow() {`, ` throw new Error('__probe_package__')`, `}`, ``, `export default packageThrow`].join("\n"));
1896
- await writeFile(join(testRoot, "entry.js"), [`import packageThrow from 'probe-package'`, ``, `function appThrow() {`, ` throw new Error('__probe_app__')`, `}`, ``, `globalThis.__probe = [appThrow, packageThrow]`].join("\n"));
1897
- try {
1898
- var _app_source, _pkg_source;
1899
- var result = await buildNativeBundle({
1900
- root: testRoot,
1901
- platform: "ios",
1902
- entryFile: "entry.js",
1903
- dev: true,
1904
- sourcemap: true
1905
- });
1906
- expect(result.map).toBeTruthy();
1907
- var traced = new TraceMap(JSON.parse(result.map));
1908
- var app = originalPositionFor(traced, generatedPositionOf(result.code, "__probe_app__"));
1909
- var pkg = originalPositionFor(traced, generatedPositionOf(result.code, "__probe_package__"));
1910
- expect((_app_source = app.source) === null || _app_source === void 0 ? void 0 : _app_source.endsWith("/entry.js")).toBe(true);
1911
- expect(app.line).toBe(4);
1912
- expect((_pkg_source = pkg.source) === null || _pkg_source === void 0 ? void 0 : _pkg_source.endsWith("/index.js")).toBe(true);
1913
- expect(pkg.line).toBe(2);
1914
- expect(app.source).toBe(normalizePath(join(testRoot, "entry.js")));
1915
- expect(pkg.source).toBe(normalizePath(join(packageRoot, "index.js")));
1916
- } finally {
1917
- await rm(testRoot, {
1918
- recursive: true,
1919
- force: true
1920
- });
1921
- }
1922
- });
1923
- });
1924
- describe("postProcessNativeBundle", function () {
1925
- var lines = function (code) {
1926
- return code.split("\n").length;
1927
- };
1928
- it("keeps the blank line above an export default", function () {
1929
- var input = ["var a = 1;", "", "export default a;", "var b = 2;", ""].join("\n");
1930
- var out = postProcessNativeBundle(input);
1931
- expect(lines(out)).toBe(lines(input));
1932
- expect(out.split("\n")[2]).toBe("a;");
1933
- });
1934
- it("keeps the lines of a multi-line export statement", function () {
1935
- var input = ["var a = 1;", "export {", " a", "};", "var b = 2;", ""].join("\n");
1936
- var out = postProcessNativeBundle(input);
1937
- expect(lines(out)).toBe(lines(input));
1938
- expect(out).not.toContain("export {");
1939
- expect(out.split("\n")[4]).toBe("var b = 2;");
1940
- });
1941
- });
1942
- //# sourceMappingURL=createNativeDevEngine.test.native.js.map