vxrn 0.1.30 → 0.1.32

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 (340) hide show
  1. package/dist/cjs/cli.js +20 -1
  2. package/dist/cjs/cli.js.map +2 -2
  3. package/dist/cjs/cli.native.js +43 -1
  4. package/dist/cjs/cli.native.js.map +2 -2
  5. package/dist/cjs/constants.js +65 -2
  6. package/dist/cjs/constants.js.map +1 -1
  7. package/dist/cjs/constants.native.js +103 -3
  8. package/dist/cjs/constants.native.js.map +2 -2
  9. package/dist/cjs/exports/build.js +66 -50
  10. package/dist/cjs/exports/build.js.map +2 -2
  11. package/dist/cjs/exports/build.native.js +182 -83
  12. package/dist/cjs/exports/build.native.js.map +2 -2
  13. package/dist/cjs/exports/dev.js +292 -293
  14. package/dist/cjs/exports/dev.js.map +2 -2
  15. package/dist/cjs/exports/dev.native.js +575 -561
  16. package/dist/cjs/exports/dev.native.js.map +2 -2
  17. package/dist/cjs/exports/serve.js +7 -1
  18. package/dist/cjs/exports/serve.js.map +1 -1
  19. package/dist/cjs/exports/serve.native.js +76 -81
  20. package/dist/cjs/exports/serve.native.js.map +2 -2
  21. package/dist/cjs/plugins/clientBundleTreeShakePlugin.js +25 -11
  22. package/dist/cjs/plugins/clientBundleTreeShakePlugin.js.map +1 -1
  23. package/dist/cjs/plugins/clientBundleTreeShakePlugin.native.js +38 -22
  24. package/dist/cjs/plugins/clientBundleTreeShakePlugin.native.js.map +2 -2
  25. package/dist/cjs/utils/getBaseViteConfig.js +14 -4
  26. package/dist/cjs/utils/getBaseViteConfig.js.map +2 -2
  27. package/dist/cjs/utils/getBaseViteConfig.native.js +16 -4
  28. package/dist/cjs/utils/getBaseViteConfig.native.js.map +2 -2
  29. package/dist/cjs/{utils.js → utils/getHtml.js} +16 -12
  30. package/dist/cjs/utils/getHtml.js.map +6 -0
  31. package/dist/cjs/{utils.native.js → utils/getHtml.native.js} +11 -16
  32. package/dist/cjs/utils/getHtml.native.js.map +6 -0
  33. package/dist/cjs/utils/getVitePath.js.map +1 -1
  34. package/dist/cjs/utils/getVitePath.native.js.map +1 -1
  35. package/dist/cjs/utils/readVXRNConfig.js +2 -2
  36. package/dist/cjs/utils/readVXRNConfig.js.map +1 -1
  37. package/dist/cjs/utils/readVXRNConfig.native.js +1 -1
  38. package/dist/cjs/utils/readVXRNConfig.native.js.map +2 -2
  39. package/dist/esm/cli.js +20 -1
  40. package/dist/esm/cli.js.map +2 -2
  41. package/dist/esm/cli.mjs +25 -1
  42. package/dist/esm/cli.native.js +43 -1
  43. package/dist/esm/cli.native.js.map +2 -2
  44. package/dist/esm/constants.js +65 -2
  45. package/dist/esm/constants.js.map +1 -1
  46. package/dist/esm/constants.mjs +30 -2
  47. package/dist/esm/constants.native.js +96 -2
  48. package/dist/esm/constants.native.js.map +2 -2
  49. package/dist/esm/exports/build.js +70 -51
  50. package/dist/esm/exports/build.js.map +1 -1
  51. package/dist/esm/exports/build.mjs +79 -29
  52. package/dist/esm/exports/build.native.js +186 -84
  53. package/dist/esm/exports/build.native.js.map +2 -2
  54. package/dist/esm/exports/dev.js +291 -295
  55. package/dist/esm/exports/dev.js.map +1 -1
  56. package/dist/esm/exports/dev.mjs +298 -283
  57. package/dist/esm/exports/dev.native.js +575 -561
  58. package/dist/esm/exports/dev.native.js.map +2 -2
  59. package/dist/esm/exports/serve.js +8 -1
  60. package/dist/esm/exports/serve.js.map +1 -1
  61. package/dist/esm/exports/serve.mjs +8 -1
  62. package/dist/esm/exports/serve.native.js +77 -81
  63. package/dist/esm/exports/serve.native.js.map +2 -2
  64. package/dist/esm/plugins/clientBundleTreeShakePlugin.js +25 -11
  65. package/dist/esm/plugins/clientBundleTreeShakePlugin.js.map +1 -1
  66. package/dist/esm/plugins/clientBundleTreeShakePlugin.mjs +29 -13
  67. package/dist/esm/plugins/clientBundleTreeShakePlugin.native.js +38 -22
  68. package/dist/esm/plugins/clientBundleTreeShakePlugin.native.js.map +2 -2
  69. package/dist/esm/utils/getBaseViteConfig.js +4 -2
  70. package/dist/esm/utils/getBaseViteConfig.js.map +1 -1
  71. package/dist/esm/utils/getBaseViteConfig.mjs +4 -2
  72. package/dist/esm/utils/getBaseViteConfig.native.js +6 -2
  73. package/dist/esm/utils/getBaseViteConfig.native.js.map +2 -2
  74. package/dist/esm/utils/getHtml.js +16 -0
  75. package/dist/esm/utils/getHtml.js.map +6 -0
  76. package/dist/esm/utils/getHtml.mjs +13 -0
  77. package/dist/esm/utils/getHtml.native.js +10 -0
  78. package/dist/esm/utils/getHtml.native.js.map +6 -0
  79. package/dist/esm/utils/getVitePath.js.map +1 -1
  80. package/dist/esm/utils/getVitePath.native.js.map +1 -1
  81. package/dist/esm/utils/readVXRNConfig.js +2 -2
  82. package/dist/esm/utils/readVXRNConfig.js.map +1 -1
  83. package/dist/esm/utils/readVXRNConfig.mjs +2 -2
  84. package/dist/esm/utils/readVXRNConfig.native.js +1 -1
  85. package/dist/esm/utils/readVXRNConfig.native.js.map +2 -2
  86. package/package.json +10 -8
  87. package/src/cli.ts +27 -0
  88. package/src/constants.ts +71 -0
  89. package/src/exports/build.ts +93 -59
  90. package/src/exports/dev.ts +408 -398
  91. package/src/exports/serve.ts +12 -14
  92. package/src/types.ts +1 -1
  93. package/src/utils/getBaseViteConfig.ts +8 -2
  94. package/src/utils/getHtml.ts +12 -0
  95. package/src/utils/getVitePath.ts +1 -0
  96. package/src/utils/readVXRNConfig.ts +5 -0
  97. package/types/constants.d.ts +13 -0
  98. package/types/exports/dev.d.ts +0 -6
  99. package/types/types.d.ts +1 -1
  100. package/types/utils/getHtml.d.ts +8 -0
  101. package/types/utils/getOptionsFilled.d.ts +1 -1
  102. package/types/vendor/createExpoServer.d.ts +3 -1
  103. package/dist/cjs/build.js +0 -145
  104. package/dist/cjs/build.js.map +0 -6
  105. package/dist/cjs/build.native.js +0 -409
  106. package/dist/cjs/build.native.js.map +0 -6
  107. package/dist/cjs/commands/cli-build.js +0 -36
  108. package/dist/cjs/commands/cli-build.js.map +0 -6
  109. package/dist/cjs/commands/cli-build.native.js +0 -171
  110. package/dist/cjs/commands/cli-build.native.js.map +0 -6
  111. package/dist/cjs/commands/cli-dev.js +0 -52
  112. package/dist/cjs/commands/cli-dev.js.map +0 -6
  113. package/dist/cjs/commands/cli-dev.native.js +0 -217
  114. package/dist/cjs/commands/cli-dev.native.js.map +0 -6
  115. package/dist/cjs/commands/index.js +0 -34
  116. package/dist/cjs/commands/index.js.map +0 -6
  117. package/dist/cjs/commands/index.native.js +0 -45
  118. package/dist/cjs/commands/index.native.js.map +0 -6
  119. package/dist/cjs/create.js +0 -643
  120. package/dist/cjs/create.js.map +0 -6
  121. package/dist/cjs/create.native.js +0 -1318
  122. package/dist/cjs/create.native.js.map +0 -6
  123. package/dist/cjs/createDevServer.js +0 -601
  124. package/dist/cjs/createDevServer.js.map +0 -6
  125. package/dist/cjs/createDevServer.native.js +0 -1220
  126. package/dist/cjs/createDevServer.native.js.map +0 -6
  127. package/dist/cjs/createExpoServer.js +0 -34
  128. package/dist/cjs/createExpoServer.js.map +0 -6
  129. package/dist/cjs/createExpoServer.native.js +0 -42
  130. package/dist/cjs/createExpoServer.native.js.map +0 -6
  131. package/dist/cjs/dev/clientInjectPlugin.js +0 -67
  132. package/dist/cjs/dev/clientInjectPlugin.js.map +0 -6
  133. package/dist/cjs/dev/clientInjectPlugin.native.js +0 -191
  134. package/dist/cjs/dev/clientInjectPlugin.native.js.map +0 -6
  135. package/dist/cjs/dev/createDevServer.js +0 -1
  136. package/dist/cjs/dev/createDevServer.js.map +0 -6
  137. package/dist/cjs/dev/createDevServer.native.js +0 -2
  138. package/dist/cjs/dev/createDevServer.native.js.map +0 -6
  139. package/dist/cjs/dispose.js +0 -28
  140. package/dist/cjs/dispose.js.map +0 -6
  141. package/dist/cjs/dispose.native.js +0 -36
  142. package/dist/cjs/dispose.native.js.map +0 -6
  143. package/dist/cjs/exports/checkPatches.js +0 -62
  144. package/dist/cjs/exports/checkPatches.js.map +0 -6
  145. package/dist/cjs/exports/checkPatches.native.js +0 -289
  146. package/dist/cjs/exports/checkPatches.native.js.map +0 -6
  147. package/dist/cjs/getVitePath.js +0 -50
  148. package/dist/cjs/getVitePath.js.map +0 -6
  149. package/dist/cjs/getVitePath.native.js +0 -197
  150. package/dist/cjs/getVitePath.native.js.map +0 -6
  151. package/dist/cjs/nativePlugin.js +0 -89
  152. package/dist/cjs/nativePlugin.js.map +0 -6
  153. package/dist/cjs/nativePlugin.native.js +0 -346
  154. package/dist/cjs/nativePlugin.native.js.map +0 -6
  155. package/dist/cjs/utils/checkPatches.js +0 -62
  156. package/dist/cjs/utils/checkPatches.js.map +0 -6
  157. package/dist/cjs/utils/checkPatches.native.js +0 -289
  158. package/dist/cjs/utils/checkPatches.native.js.map +0 -6
  159. package/dist/cjs/utils/constants.js +0 -21
  160. package/dist/cjs/utils/constants.js.map +0 -6
  161. package/dist/cjs/utils/constants.native.js +0 -26
  162. package/dist/cjs/utils/constants.native.js.map +0 -6
  163. package/dist/cjs/utils/prerender.js +0 -1
  164. package/dist/cjs/utils/prerender.js.map +0 -6
  165. package/dist/cjs/utils/prerender.native.js +0 -2
  166. package/dist/cjs/utils/prerender.native.js.map +0 -6
  167. package/dist/cjs/utils.js.map +0 -6
  168. package/dist/cjs/utils.native.js.map +0 -6
  169. package/dist/esm/build.js +0 -128
  170. package/dist/esm/build.js.map +0 -6
  171. package/dist/esm/build.mjs +0 -119
  172. package/dist/esm/build.native.js +0 -385
  173. package/dist/esm/build.native.js.map +0 -6
  174. package/dist/esm/commands/cli-build.js +0 -23
  175. package/dist/esm/commands/cli-build.js.map +0 -6
  176. package/dist/esm/commands/cli-build.mjs +0 -22
  177. package/dist/esm/commands/cli-build.native.js +0 -156
  178. package/dist/esm/commands/cli-build.native.js.map +0 -6
  179. package/dist/esm/commands/cli-dev.js +0 -39
  180. package/dist/esm/commands/cli-dev.js.map +0 -6
  181. package/dist/esm/commands/cli-dev.mjs +0 -45
  182. package/dist/esm/commands/cli-dev.native.js +0 -202
  183. package/dist/esm/commands/cli-dev.native.js.map +0 -6
  184. package/dist/esm/commands/index.js +0 -10
  185. package/dist/esm/commands/index.js.map +0 -6
  186. package/dist/esm/commands/index.mjs +0 -8
  187. package/dist/esm/commands/index.native.js +0 -16
  188. package/dist/esm/commands/index.native.js.map +0 -6
  189. package/dist/esm/create.js +0 -655
  190. package/dist/esm/create.js.map +0 -6
  191. package/dist/esm/create.mjs +0 -622
  192. package/dist/esm/create.native.js +0 -1309
  193. package/dist/esm/create.native.js.map +0 -6
  194. package/dist/esm/createDevServer.js +0 -614
  195. package/dist/esm/createDevServer.js.map +0 -6
  196. package/dist/esm/createDevServer.mjs +0 -570
  197. package/dist/esm/createDevServer.native.js +0 -1211
  198. package/dist/esm/createDevServer.native.js.map +0 -6
  199. package/dist/esm/createExpoServer.js +0 -20
  200. package/dist/esm/createExpoServer.js.map +0 -6
  201. package/dist/esm/createExpoServer.mjs +0 -17
  202. package/dist/esm/createExpoServer.native.js +0 -22
  203. package/dist/esm/createExpoServer.native.js.map +0 -6
  204. package/dist/esm/dev/clientInjectPlugin.js +0 -43
  205. package/dist/esm/dev/clientInjectPlugin.js.map +0 -6
  206. package/dist/esm/dev/clientInjectPlugin.mjs +0 -57
  207. package/dist/esm/dev/clientInjectPlugin.native.js +0 -162
  208. package/dist/esm/dev/clientInjectPlugin.native.js.map +0 -6
  209. package/dist/esm/dev/createDevServer.js +0 -1
  210. package/dist/esm/dev/createDevServer.js.map +0 -6
  211. package/dist/esm/dev/createDevServer.mjs +0 -0
  212. package/dist/esm/dev/createDevServer.native.js +0 -1
  213. package/dist/esm/dev/createDevServer.native.js.map +0 -6
  214. package/dist/esm/dispose.js +0 -12
  215. package/dist/esm/dispose.js.map +0 -6
  216. package/dist/esm/dispose.mjs +0 -8
  217. package/dist/esm/dispose.native.js +0 -14
  218. package/dist/esm/dispose.native.js.map +0 -6
  219. package/dist/esm/exports/checkPatches.js +0 -40
  220. package/dist/esm/exports/checkPatches.js.map +0 -6
  221. package/dist/esm/exports/checkPatches.mjs +0 -31
  222. package/dist/esm/exports/checkPatches.native.js +0 -262
  223. package/dist/esm/exports/checkPatches.native.js.map +0 -6
  224. package/dist/esm/getVitePath.js +0 -28
  225. package/dist/esm/getVitePath.js.map +0 -6
  226. package/dist/esm/getVitePath.mjs +0 -21
  227. package/dist/esm/getVitePath.native.js +0 -170
  228. package/dist/esm/getVitePath.native.js.map +0 -6
  229. package/dist/esm/nativePlugin.js +0 -75
  230. package/dist/esm/nativePlugin.js.map +0 -6
  231. package/dist/esm/nativePlugin.mjs +0 -55
  232. package/dist/esm/nativePlugin.native.js +0 -327
  233. package/dist/esm/nativePlugin.native.js.map +0 -6
  234. package/dist/esm/utils/checkPatches.js +0 -40
  235. package/dist/esm/utils/checkPatches.js.map +0 -6
  236. package/dist/esm/utils/checkPatches.mjs +0 -31
  237. package/dist/esm/utils/checkPatches.native.js +0 -262
  238. package/dist/esm/utils/checkPatches.native.js.map +0 -6
  239. package/dist/esm/utils/constants.js +0 -5
  240. package/dist/esm/utils/constants.js.map +0 -6
  241. package/dist/esm/utils/constants.mjs +0 -2
  242. package/dist/esm/utils/constants.native.js +0 -5
  243. package/dist/esm/utils/constants.native.js.map +0 -6
  244. package/dist/esm/utils/prerender.js +0 -1
  245. package/dist/esm/utils/prerender.js.map +0 -6
  246. package/dist/esm/utils/prerender.mjs +0 -0
  247. package/dist/esm/utils/prerender.native.js +0 -1
  248. package/dist/esm/utils/prerender.native.js.map +0 -6
  249. package/dist/esm/utils.js +0 -12
  250. package/dist/esm/utils.js.map +0 -6
  251. package/dist/esm/utils.mjs +0 -8
  252. package/dist/esm/utils.native.js +0 -14
  253. package/dist/esm/utils.native.js.map +0 -6
  254. package/src/plugins/clientBundleTreeShakePlugin.tsx +0 -105
  255. package/src/vendor/createExpoServer.ts +0 -43
  256. package/src/vendor/repack/dev-server/src/createServer.ts +0 -128
  257. package/src/vendor/repack/dev-server/src/img/favicon.ico +0 -0
  258. package/src/vendor/repack/dev-server/src/index.ts +0 -2
  259. package/src/vendor/repack/dev-server/src/plugins/api/apiPlugin.ts +0 -50
  260. package/src/vendor/repack/dev-server/src/plugins/api/index.ts +0 -1
  261. package/src/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.ts +0 -84
  262. package/src/vendor/repack/dev-server/src/plugins/compiler/index.ts +0 -2
  263. package/src/vendor/repack/dev-server/src/plugins/compiler/types.ts +0 -37
  264. package/src/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.ts +0 -107
  265. package/src/vendor/repack/dev-server/src/plugins/devtools/index.ts +0 -1
  266. package/src/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.ts +0 -14
  267. package/src/vendor/repack/dev-server/src/plugins/favicon/index.ts +0 -1
  268. package/src/vendor/repack/dev-server/src/plugins/multipart/index.ts +0 -2
  269. package/src/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.ts +0 -77
  270. package/src/vendor/repack/dev-server/src/plugins/multipart/types.ts +0 -13
  271. package/src/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.ts +0 -233
  272. package/src/vendor/repack/dev-server/src/plugins/symbolicate/index.ts +0 -3
  273. package/src/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.ts +0 -48
  274. package/src/vendor/repack/dev-server/src/plugins/symbolicate/types.ts +0 -71
  275. package/src/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.ts +0 -74
  276. package/src/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.ts +0 -60
  277. package/src/vendor/repack/dev-server/src/plugins/wss/index.ts +0 -3
  278. package/src/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.ts +0 -158
  279. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.ts +0 -69
  280. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.ts +0 -134
  281. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.ts +0 -74
  282. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.ts +0 -205
  283. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.ts +0 -97
  284. package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.ts +0 -401
  285. package/src/vendor/repack/dev-server/src/plugins/wss/types.ts +0 -17
  286. package/src/vendor/repack/dev-server/src/plugins/wss/wssPlugin.ts +0 -73
  287. package/src/vendor/repack/dev-server/src/types.ts +0 -197
  288. package/types/VXRNConfigFilled.d.ts +0 -21
  289. package/types/build.d.ts +0 -4
  290. package/types/commands/cli-build.d.ts +0 -3
  291. package/types/commands/cli-dev.d.ts +0 -3
  292. package/types/commands/index.d.ts +0 -6
  293. package/types/create.d.ts +0 -13
  294. package/types/createDevServer.d.ts +0 -13
  295. package/types/createExpoServer.d.ts +0 -4
  296. package/types/dev/bindKeypressInput.d.ts +0 -3
  297. package/types/dev/clientInjectPlugin.d.ts +0 -7
  298. package/types/dev/createDevServer.d.ts +0 -1
  299. package/types/dispose.d.ts +0 -3
  300. package/types/getBaseViteConfig.d.ts +0 -5
  301. package/types/getOptionsFIlled.d.ts +0 -21
  302. package/types/getVitePath.d.ts +0 -2
  303. package/types/nativePlugin.d.ts +0 -7
  304. package/types/plugins/clientBundleTreeShakePlugni.d.ts +0 -13
  305. package/types/plugins/server-tree-shake.d.ts +0 -13
  306. package/types/utils/checkPatches.d.ts +0 -3
  307. package/types/utils/constants.d.ts +0 -2
  308. package/types/utils/prerender.d.ts +0 -1
  309. package/types/utils.d.ts +0 -3
  310. package/types/vendor/repack/dev-server/src/createServer.d.ts +0 -1
  311. package/types/vendor/repack/dev-server/src/index.d.ts +0 -1
  312. package/types/vendor/repack/dev-server/src/plugins/api/apiPlugin.d.ts +0 -1
  313. package/types/vendor/repack/dev-server/src/plugins/api/index.d.ts +0 -1
  314. package/types/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.d.ts +0 -1
  315. package/types/vendor/repack/dev-server/src/plugins/compiler/index.d.ts +0 -1
  316. package/types/vendor/repack/dev-server/src/plugins/compiler/types.d.ts +0 -1
  317. package/types/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.d.ts +0 -1
  318. package/types/vendor/repack/dev-server/src/plugins/devtools/index.d.ts +0 -1
  319. package/types/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.d.ts +0 -1
  320. package/types/vendor/repack/dev-server/src/plugins/favicon/index.d.ts +0 -1
  321. package/types/vendor/repack/dev-server/src/plugins/multipart/index.d.ts +0 -1
  322. package/types/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.d.ts +0 -1
  323. package/types/vendor/repack/dev-server/src/plugins/multipart/types.d.ts +0 -1
  324. package/types/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.d.ts +0 -1
  325. package/types/vendor/repack/dev-server/src/plugins/symbolicate/index.d.ts +0 -1
  326. package/types/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.d.ts +0 -1
  327. package/types/vendor/repack/dev-server/src/plugins/symbolicate/types.d.ts +0 -1
  328. package/types/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.d.ts +0 -1
  329. package/types/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.d.ts +0 -1
  330. package/types/vendor/repack/dev-server/src/plugins/wss/index.d.ts +0 -1
  331. package/types/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.d.ts +0 -1
  332. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.d.ts +0 -1
  333. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.d.ts +0 -1
  334. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.d.ts +0 -1
  335. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.d.ts +0 -1
  336. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.d.ts +0 -1
  337. package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.d.ts +0 -1
  338. package/types/vendor/repack/dev-server/src/plugins/wss/types.d.ts +0 -1
  339. package/types/vendor/repack/dev-server/src/plugins/wss/wssPlugin.d.ts +0 -1
  340. package/types/vendor/repack/dev-server/src/types.d.ts +0 -1
@@ -3,7 +3,6 @@ import {
3
3
  createApp,
4
4
  createRouter,
5
5
  defineEventHandler,
6
- defineWebSocketHandler,
7
6
  eventHandler,
8
7
  getQuery,
9
8
  toNodeListener,
@@ -34,7 +33,7 @@ import {
34
33
  import createViteFlow from '@vxrn/vite-flow'
35
34
  import type { Peer } from 'crossws'
36
35
  import { resolve as importMetaResolve } from 'import-meta-resolve'
37
- import { clientBundleTreeShakePlugin } from '../plugins/clientBundleTreeShakePlugin'
36
+ import { depsToOptimize, nativeExtensions, ssrOptimizeDeps, webExtensions } from '../constants'
38
37
  import { clientInjectionsPlugin } from '../plugins/clientInjectPlugin'
39
38
  import { reactNativeCommonJsPlugin } from '../plugins/reactNativeCommonJsPlugin'
40
39
  import type { VXRNConfig } from '../types'
@@ -42,9 +41,11 @@ import { getBaseViteConfig } from '../utils/getBaseViteConfig'
42
41
  import { getOptionsFilled, type VXRNConfigFilled } from '../utils/getOptionsFilled'
43
42
  import { getVitePath } from '../utils/getVitePath'
44
43
  import { checkPatches } from '../utils/patches'
45
- import { createExpoServer } from '../vendor/createExpoServer'
46
44
 
47
- const depsToOptimize = ['react', 'react-dom', '@react-native/normalize-color']
45
+ // sorry for the mess, exploring before abstracting
46
+
47
+ let isBuildingNativeBundle: Promise<string> | null = null
48
+ const hotUpdateCache = new Map<string, string>()
48
49
 
49
50
  export const resolveFile = (path: string) => {
50
51
  try {
@@ -54,30 +55,6 @@ export const resolveFile = (path: string) => {
54
55
  }
55
56
  }
56
57
 
57
- const nativeExtensions = [
58
- '.native.tsx',
59
- '.native.jsx',
60
- '.native.js',
61
- '.tsx',
62
- '.ts',
63
- '.js',
64
- '.css',
65
- '.json',
66
- ]
67
-
68
- const extensions = [
69
- '.web.tsx',
70
- '.tsx',
71
- '.web.ts',
72
- '.ts',
73
- '.web.jsx',
74
- '.jsx',
75
- '.web.js',
76
- '.js',
77
- '.css',
78
- '.json',
79
- ]
80
-
81
58
  const { ensureDir, pathExists, pathExistsSync } = FSExtra
82
59
 
83
60
  export const dev = async (optionsIn: VXRNConfig) => {
@@ -93,124 +70,7 @@ export const dev = async (optionsIn: VXRNConfig) => {
93
70
 
94
71
  await ensureDir(cacheDir)
95
72
 
96
- const prebuilds = {
97
- reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
98
- react: join(cacheDir, 'react.js'),
99
- reactNative: join(cacheDir, 'react-native.js'),
100
- }
101
-
102
- if (!(await pathExists(prebuilds.reactNative))) {
103
- console.info('Pre-building react, react-native react/jsx-runtime (one time cost)...')
104
- await Promise.all([
105
- buildReactNative({
106
- entryPoints: [resolveFile('react-native')],
107
- outfile: prebuilds.reactNative,
108
- }),
109
- buildReact({
110
- entryPoints: [resolveFile('react')],
111
- outfile: prebuilds.react,
112
- }),
113
- buildReactJSX({
114
- entryPoints: [resolveFile('react/jsx-dev-runtime')],
115
- outfile: prebuilds.reactJSX,
116
- }),
117
- ])
118
- }
119
- const viteFlow = options.flow ? createViteFlow(options.flow) : null
120
-
121
- const templateFile = resolveFile('vxrn/react-native-template.js')
122
-
123
- // react native port (it scans 19000 +5)
124
- const jsxRuntime = {
125
- // alias: 'virtual:react-jsx',
126
- alias: prebuilds.reactJSX,
127
- contents: await readFile(prebuilds.reactJSX, 'utf-8'),
128
- } as const
129
-
130
- const virtualModules = {
131
- 'react-native': {
132
- // alias: 'virtual:react-native',
133
- alias: prebuilds.reactNative,
134
- contents: await readFile(prebuilds.reactNative, 'utf-8'),
135
- },
136
- react: {
137
- // alias: 'virtual:react',
138
- alias: prebuilds.react,
139
- contents: await readFile(prebuilds.react, 'utf-8'),
140
- },
141
- 'react/jsx-runtime': jsxRuntime,
142
- 'react/jsx-dev-runtime': jsxRuntime,
143
- } as const
144
-
145
- const swapRnPlugin: PluginOption = {
146
- name: `swap-react-native`,
147
- enforce: 'pre',
148
-
149
- resolveId(id, importer = '') {
150
- if (id.startsWith('react-native/Libraries')) {
151
- return `virtual:rn-internals:${id}`
152
- }
153
-
154
- // this will break web support, we need a way to somehow switch between?
155
- if (id === 'react-native-web') {
156
- return prebuilds.reactNative
157
- }
158
-
159
- for (const targetId in virtualModules) {
160
- if (id === targetId || id.includes(`node_modules/${targetId}/`)) {
161
- const info = virtualModules[targetId]
162
-
163
- return info.alias
164
- }
165
- }
166
-
167
- // TODO this is terrible and slow, we should be able to get extensions working:
168
- // having trouble getting .native.js to be picked up via vite
169
- // tried adding packages to optimizeDeps, tried resolveExtensions + extensions...
170
- // tried this but seems to not be called for node_modules
171
- if (id[0] === '.') {
172
- const absolutePath = resolve(dirname(importer), id)
173
- const nativePath = absolutePath.replace(/(.m?js)/, '.native.js')
174
- if (nativePath === id) return
175
- try {
176
- const directoryPath = absolutePath + '/index.native.js'
177
- const directoryNonNativePath = absolutePath + '/index.js'
178
- if (pathExistsSync(directoryPath)) {
179
- return directoryPath
180
- }
181
- if (pathExistsSync(directoryNonNativePath)) {
182
- return directoryNonNativePath
183
- }
184
- if (pathExistsSync(nativePath)) {
185
- return nativePath
186
- }
187
- } catch (err) {
188
- console.warn(`error probably fine`, err)
189
- }
190
- }
191
- },
192
-
193
- load(id) {
194
- if (id.startsWith('virtual:rn-internals')) {
195
- const idOut = id.replace('virtual:rn-internals:', '')
196
- let out = `const ___val = __cachedModules["${idOut}"]
197
- const ___defaultVal = ___val ? ___val.default || ___val : ___val
198
- export default ___defaultVal`
199
- // export const PressabilityDebugView = val.PressabilityDebugView
200
- //
201
- return out
202
- }
203
-
204
- for (const targetId in virtualModules) {
205
- const info = virtualModules[targetId as keyof typeof virtualModules]
206
- if (id === info.alias) {
207
- return info.contents
208
- }
209
- }
210
- },
211
- } as const
212
-
213
- const { serverConfig, hotUpdateCache } = await getViteServerConfig(options)
73
+ const serverConfig = await getViteServerConfig(options)
214
74
  const viteServer = await createServer(serverConfig)
215
75
 
216
76
  // first resolve config so we can pass into client plugin, then add client plugin:
@@ -232,25 +92,21 @@ export const dev = async (optionsIn: VXRNConfig) => {
232
92
  }
233
93
  })
234
94
 
235
- let isBuilding: Promise<string> | null = null
236
-
237
95
  await viteServer.listen()
238
96
  const vitePort = viteServer.config.server.port
239
97
 
240
- console.info('vite running on', vitePort)
241
-
242
98
  const router = createRouter()
243
99
  const app = createApp({
244
100
  onError: (error) => {
245
101
  console.error(error)
246
102
  },
247
103
  onRequest: (event) => {
248
- console.info(' →', event.path)
104
+ if (process.env.DEBUG) {
105
+ console.info(' →', event.path)
106
+ }
249
107
  },
250
108
  })
251
109
 
252
- createExpoServer(root, app, viteServer)
253
-
254
110
  router.get(
255
111
  '/file',
256
112
  defineEventHandler((e) => {
@@ -269,7 +125,7 @@ export const dev = async (optionsIn: VXRNConfig) => {
269
125
  router.get(
270
126
  '/index.bundle',
271
127
  defineEventHandler(async (e) => {
272
- return new Response(await getBundleCode(), {
128
+ return new Response(await getReactNativeBundle(options, viteRNClientPlugin), {
273
129
  headers: {
274
130
  'content-type': 'text/javascript',
275
131
  },
@@ -306,8 +162,6 @@ export const dev = async (optionsIn: VXRNConfig) => {
306
162
 
307
163
  socket.on('message', (msg) => {
308
164
  const message = msg.toString()
309
- console.info(clients.size, 'message', message)
310
-
311
165
  for (const listener of [...clients]) {
312
166
  listener.send(message)
313
167
  }
@@ -320,23 +174,29 @@ export const dev = async (optionsIn: VXRNConfig) => {
320
174
  // vite hmr:
321
175
  app.use(
322
176
  '/__vxrnhmr',
323
- defineWebSocketHandler({
324
- open(peer) {
325
- console.debug('[hmr:web] open', peer)
326
- clients.add(peer)
177
+ defineEventHandler({
178
+ handler() {
179
+ //
327
180
  },
328
181
 
329
- message(peer, message) {
330
- socket.send(message.rawData)
331
- },
182
+ websocket: {
183
+ open(peer) {
184
+ if (process.env.DEBUG) console.debug('[hmr:web] open', peer)
185
+ clients.add(peer)
186
+ },
332
187
 
333
- close(peer, event) {
334
- console.info('[hmr:web] close', peer, event)
335
- clients.delete(peer)
336
- },
188
+ message(peer, message) {
189
+ socket.send(message.rawData)
190
+ },
337
191
 
338
- error(peer, error) {
339
- console.error('[hmr:web] error', peer, error)
192
+ close(peer, event) {
193
+ if (process.env.DEBUG) console.info('[hmr:web] close', peer, event)
194
+ clients.delete(peer)
195
+ },
196
+
197
+ error(peer, error) {
198
+ console.error('[hmr:web] error', peer, error)
199
+ },
340
200
  },
341
201
  })
342
202
  )
@@ -345,24 +205,30 @@ export const dev = async (optionsIn: VXRNConfig) => {
345
205
  // react native hmr:
346
206
  app.use(
347
207
  '/__hmr',
348
- defineWebSocketHandler({
349
- open(peer) {
350
- console.debug('[hmr] open', peer)
208
+ defineEventHandler({
209
+ handler() {
210
+ //
351
211
  },
352
212
 
353
- message(peer, message) {
354
- console.info('[hmr] message', peer, message)
355
- if (message.text().includes('ping')) {
356
- peer.send('pong')
357
- }
358
- },
213
+ websocket: {
214
+ open(peer) {
215
+ console.debug('[hmr] open', peer)
216
+ },
359
217
 
360
- close(peer, event) {
361
- console.info('[hmr] close', peer, event)
362
- },
218
+ message(peer, message) {
219
+ console.info('[hmr] message', peer, message)
220
+ if (message.text().includes('ping')) {
221
+ peer.send('pong')
222
+ }
223
+ },
224
+
225
+ close(peer, event) {
226
+ console.info('[hmr] close', peer, event)
227
+ },
363
228
 
364
- error(peer, error) {
365
- console.error('[hmr] error', peer, error)
229
+ error(peer, error) {
230
+ console.error('[hmr] error', peer, error)
231
+ },
366
232
  },
367
233
  })
368
234
  )
@@ -373,35 +239,49 @@ export const dev = async (optionsIn: VXRNConfig) => {
373
239
  data: string[]
374
240
  }
375
241
 
242
+ // symbolicate
243
+ app.use(
244
+ '/symbolicate',
245
+ defineEventHandler(() => {
246
+ return 'TODO'
247
+ })
248
+ )
249
+
376
250
  // react native log bridge
377
251
  app.use(
378
252
  '/__client',
379
- defineWebSocketHandler({
380
- open(peer) {
381
- console.info('[client] open', peer)
253
+ defineEventHandler({
254
+ handler() {
255
+ // no
382
256
  },
383
257
 
384
- message(peer, messageRaw) {
385
- const message = JSON.parse(messageRaw.text()) as any as ClientMessage
258
+ websocket: {
259
+ open(peer) {
260
+ console.info('[client] open', peer)
261
+ },
262
+
263
+ message(peer, messageRaw) {
264
+ const message = JSON.parse(messageRaw.text()) as any as ClientMessage
386
265
 
387
- switch (message.type) {
388
- case 'client-log': {
389
- console.info(`🪵 [${message.level}]`, ...message.data)
390
- return
391
- }
266
+ switch (message.type) {
267
+ case 'client-log': {
268
+ console.info(`🪵 [${message.level}]`, ...message.data)
269
+ return
270
+ }
392
271
 
393
- default: {
394
- console.warn(`[client] Unknown message type`, message)
272
+ default: {
273
+ console.warn(`[client] Unknown message type`, message)
274
+ }
395
275
  }
396
- }
397
- },
276
+ },
398
277
 
399
- close(peer, event) {
400
- console.info('[client] close', peer, event)
401
- },
278
+ close(peer, event) {
279
+ console.info('[client] close', peer, event)
280
+ },
402
281
 
403
- error(peer, error) {
404
- console.error('[client] error', peer, error)
282
+ error(peer, error) {
283
+ console.error('[client] error', peer, error)
284
+ },
405
285
  },
406
286
  })
407
287
  )
@@ -435,162 +315,169 @@ export const dev = async (optionsIn: VXRNConfig) => {
435
315
  await Promise.all([server.close(), viteServer.close()])
436
316
  },
437
317
  }
318
+ }
438
319
 
439
- async function getBundleCode() {
440
- if (process.env.LOAD_TMP_BUNDLE) {
441
- // for easier quick testing things:
442
- const tmpBundle = join(process.cwd(), 'bundle.tmp.js')
443
- if (await pathExists(tmpBundle)) {
444
- console.info('⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ returning temp bundle ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️', tmpBundle)
445
- return await readFile(tmpBundle, 'utf-8')
446
- }
447
- }
320
+ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugin: any) {
321
+ const { root, port, cacheDir } = options
448
322
 
449
- if (isBuilding) {
450
- const res = await isBuilding
451
- return res
323
+ if (process.env.LOAD_TMP_BUNDLE) {
324
+ // for easier quick testing things:
325
+ const tmpBundle = join(process.cwd(), 'bundle.tmp.js')
326
+ if (await pathExists(tmpBundle)) {
327
+ console.info('⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ returning temp bundle ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️', tmpBundle)
328
+ return await readFile(tmpBundle, 'utf-8')
452
329
  }
330
+ }
453
331
 
454
- let done
455
- isBuilding = new Promise((res) => {
456
- done = res
457
- })
458
-
459
- async function babelReanimated(input: string, filename: string) {
460
- return await new Promise<string>((res, rej) => {
461
- babel.transform(
462
- input,
463
- {
464
- plugins: ['react-native-reanimated/plugin'],
465
- filename,
466
- },
467
- (err: any, result) => {
468
- if (!result || err) rej(err || 'no res')
469
- res(result!.code!)
470
- }
471
- )
472
- })
473
- }
332
+ if (isBuildingNativeBundle) {
333
+ const res = await isBuildingNativeBundle
334
+ return res
335
+ }
474
336
 
475
- // build app
476
- let buildConfig = {
477
- plugins: [
478
- viteFlow,
479
- swapRnPlugin,
337
+ let done
338
+ isBuildingNativeBundle = new Promise((res) => {
339
+ done = res
340
+ })
480
341
 
342
+ async function babelReanimated(input: string, filename: string) {
343
+ return await new Promise<string>((res, rej) => {
344
+ babel.transform(
345
+ input,
481
346
  {
482
- name: 'reanimated',
483
-
484
- async transform(code, id) {
485
- if (code.includes('worklet')) {
486
- const out = await babelReanimated(code, id)
487
- return out
488
- }
489
- },
347
+ plugins: ['react-native-reanimated/plugin'],
348
+ filename,
490
349
  },
350
+ (err: any, result) => {
351
+ if (!result || err) rej(err || 'no res')
352
+ res(result!.code!)
353
+ }
354
+ )
355
+ })
356
+ }
491
357
 
492
- clientBundleTreeShakePlugin({}),
493
- viteRNClientPlugin,
358
+ const viteFlow = options.flow ? createViteFlow(options.flow) : null
494
359
 
495
- reactNativeCommonJsPlugin({
496
- root,
497
- port,
498
- mode: 'build',
499
- }),
360
+ // build app
361
+ let nativeBuildConfig = {
362
+ plugins: [
363
+ viteFlow,
500
364
 
501
- viteReactPlugin({
502
- tsDecorators: true,
503
- mode: 'build',
504
- }),
365
+ swapPrebuiltReactModules(cacheDir),
505
366
 
506
- {
507
- name: 'treat-js-files-as-jsx',
508
- async transform(code, id) {
509
- if (!id.match(/expo-status-bar/)) return null
510
- // Use the exposed transform from vite, instead of directly
511
- // transforming with esbuild
512
- return transformWithEsbuild(code, id, {
513
- loader: 'jsx',
514
- jsx: 'automatic',
515
- })
516
- },
517
- },
518
- ].filter(Boolean),
519
- appType: 'custom',
520
- root,
521
- clearScreen: false,
367
+ {
368
+ name: 'reanimated',
522
369
 
523
- optimizeDeps: {
524
- include: depsToOptimize,
525
- esbuildOptions: {
526
- jsx: 'automatic',
370
+ async transform(code, id) {
371
+ if (code.includes('worklet')) {
372
+ const out = await babelReanimated(code, id)
373
+ return out
374
+ }
527
375
  },
528
376
  },
529
377
 
530
- resolve: {
531
- extensions: nativeExtensions,
378
+ viteRNClientPlugin,
379
+
380
+ reactNativeCommonJsPlugin({
381
+ root,
382
+ port,
383
+ mode: 'build',
384
+ }),
385
+
386
+ viteReactPlugin({
387
+ tsDecorators: true,
388
+ mode: 'build',
389
+ }),
390
+
391
+ {
392
+ name: 'treat-js-files-as-jsx',
393
+ async transform(code, id) {
394
+ if (!id.match(/expo-status-bar/)) return null
395
+ // Use the exposed transform from vite, instead of directly
396
+ // transforming with esbuild
397
+ return transformWithEsbuild(code, id, {
398
+ loader: 'jsx',
399
+ jsx: 'automatic',
400
+ })
401
+ },
402
+ },
403
+ ].filter(Boolean),
404
+ appType: 'custom',
405
+ root,
406
+ clearScreen: false,
407
+
408
+ optimizeDeps: {
409
+ include: depsToOptimize,
410
+ esbuildOptions: {
411
+ jsx: 'automatic',
532
412
  },
413
+ },
533
414
 
534
- mode: 'development',
535
- define: {
536
- 'process.env.NODE_ENV': `"development"`,
415
+ resolve: {
416
+ extensions: nativeExtensions,
417
+ },
418
+
419
+ mode: 'development',
420
+
421
+ define: {
422
+ 'process.env.NODE_ENV': `"development"`,
423
+ },
424
+
425
+ build: {
426
+ ssr: false,
427
+ minify: false,
428
+ commonjsOptions: {
429
+ transformMixedEsModules: true,
537
430
  },
538
- build: {
539
- ssr: false,
540
- minify: false,
541
- commonjsOptions: {
542
- transformMixedEsModules: true,
543
- },
544
- rollupOptions: {
545
- treeshake: false,
546
- preserveEntrySignatures: 'strict',
547
- output: {
548
- preserveModules: true,
549
- format: 'cjs',
550
- },
431
+ rollupOptions: {
432
+ treeshake: false,
433
+ preserveEntrySignatures: 'strict',
434
+ output: {
435
+ preserveModules: true,
436
+ format: 'cjs',
551
437
  },
552
438
  },
553
- } satisfies InlineConfig
439
+ },
440
+ } satisfies InlineConfig
554
441
 
555
- if (options.buildConfig) {
556
- buildConfig = mergeConfig(buildConfig, options.buildConfig) as any
557
- }
442
+ if (options.nativeConfig) {
443
+ nativeBuildConfig = mergeConfig(nativeBuildConfig, options.nativeConfig) as any
444
+ }
558
445
 
559
- // this fixes my swap-react-native plugin not being called pre 😳
560
- await resolveConfig(buildConfig, 'build')
446
+ // this fixes my swap-react-native plugin not being called pre 😳
447
+ await resolveConfig(nativeBuildConfig, 'build')
561
448
 
562
- // seems to be not working but needed to put it after the resolve or else it was cleared
563
- // @ts-ignore
564
- // buildConfig.build.rollupOptions.input = join(root, buildInput)
449
+ // seems to be not working but needed to put it after the resolve or else it was cleared
450
+ // @ts-ignore
451
+ // nativeBuildConfig.build.rollupOptions.input = join(root, buildInput)
565
452
 
566
- const buildOutput = await build(buildConfig)
453
+ const buildOutput = await build(nativeBuildConfig)
567
454
 
568
- if (!('output' in buildOutput)) {
569
- throw `❌`
570
- }
455
+ if (!('output' in buildOutput)) {
456
+ throw `❌`
457
+ }
571
458
 
572
- let appCode = buildOutput.output
573
- // entry last
574
- .sort((a, b) => (a['isEntry'] ? 1 : -1))
575
- .map((outputModule) => {
576
- if (outputModule.type == 'chunk') {
577
- const importsMap = {
578
- currentPath: outputModule.fileName,
579
- }
580
- for (const imp of outputModule.imports) {
581
- const relativePath = relative(dirname(outputModule.fileName), imp)
582
- importsMap[relativePath[0] === '.' ? relativePath : './' + relativePath] = imp
583
- }
459
+ let appCode = buildOutput.output
460
+ // entry last
461
+ .sort((a, b) => (a['isEntry'] ? 1 : -1))
462
+ .map((outputModule) => {
463
+ if (outputModule.type == 'chunk') {
464
+ const importsMap = {
465
+ currentPath: outputModule.fileName,
466
+ }
467
+ for (const imp of outputModule.imports) {
468
+ const relativePath = relative(dirname(outputModule.fileName), imp)
469
+ importsMap[relativePath[0] === '.' ? relativePath : './' + relativePath] = imp
470
+ }
584
471
 
585
- if (outputModule.isEntry) {
586
- entryRoot = dirname(outputModule.fileName)
587
- }
472
+ if (outputModule.isEntry) {
473
+ entryRoot = dirname(outputModule.fileName)
474
+ }
588
475
 
589
- return `
476
+ return `
590
477
  ___modules___["${outputModule.fileName}"] = ((exports, module) => {
591
- const require = createRequire(${JSON.stringify(importsMap, null, 2)})
478
+ const require = createRequire(${JSON.stringify(importsMap, null, 2)})
592
479
 
593
- ${outputModule.code}
480
+ ${outputModule.code}
594
481
  })
595
482
 
596
483
  ${
@@ -604,38 +491,162 @@ __require("${outputModule.fileName}")
604
491
  : ''
605
492
  }
606
493
  `
607
- }
608
- })
609
- .join('\n')
494
+ }
495
+ })
496
+ .join('\n')
610
497
 
611
- if (!appCode) {
612
- throw `❌`
613
- }
498
+ if (!appCode) {
499
+ throw `❌`
500
+ }
501
+
502
+ appCode = appCode
503
+ // this can be done in the individual file transform
504
+ .replaceAll('undefined.accept(() => {})', '')
505
+ .replaceAll('undefined.accept(function() {});', '')
506
+ .replaceAll('(void 0).accept(() => {})', '')
507
+ .replaceAll('(void 0).accept(function() {});', '')
508
+ // TEMP FIX for expo-router tamagui thing since expo router 3 upgrade
509
+ .replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"')
614
510
 
615
- appCode = appCode
616
- // this can be done in the individual file transform
617
- .replaceAll('undefined.accept(() => {})', '')
618
- .replaceAll('undefined.accept(function() {});', '')
619
- .replaceAll('(void 0).accept(() => {})', '')
620
- .replaceAll('(void 0).accept(function() {});', '')
621
- // TEMP FIX for expo-router tamagui thing since expo router 3 upgrade
622
- .replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"')
511
+ // TODO this is not stable based on cwd
512
+ const appRootParent = join(root, '..', '..')
623
513
 
624
- // TODO this is not stable based on cwd
625
- const appRootParent = join(root, '..', '..')
514
+ const prebuilds = {
515
+ reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
516
+ react: join(cacheDir, 'react.js'),
517
+ reactNative: join(cacheDir, 'react-native.js'),
518
+ }
626
519
 
627
- const template = (await readFile(templateFile, 'utf-8'))
628
- .replace('_virtual/virtual_react-native.js', relative(appRootParent, prebuilds.reactNative))
629
- .replace('_virtual/virtual_react.js', relative(appRootParent, prebuilds.react))
630
- .replaceAll('_virtual/virtual_react-jsx.js', relative(appRootParent, prebuilds.reactJSX))
520
+ const templateFile = resolveFile('vxrn/react-native-template.js')
521
+ const template = (await readFile(templateFile, 'utf-8'))
522
+ .replace('_virtual/virtual_react-native.js', relative(appRootParent, prebuilds.reactNative))
523
+ .replace('_virtual/virtual_react.js', relative(appRootParent, prebuilds.react))
524
+ .replaceAll('_virtual/virtual_react-jsx.js', relative(appRootParent, prebuilds.reactJSX))
631
525
 
632
- const out = template + appCode
526
+ const out = template + appCode
633
527
 
634
- done(out)
635
- isBuilding = null
528
+ done(out)
529
+ isBuildingNativeBundle = null
636
530
 
637
- return out
531
+ return out
532
+ }
533
+
534
+ // we should just detect or whitelist and use flow to convert instead of this but i did a
535
+ // few things to the prebuilts to make them work, we may need to account for
536
+ async function swapPrebuiltReactModules(cacheDir: string) {
537
+ const prebuilds = {
538
+ reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
539
+ react: join(cacheDir, 'react.js'),
540
+ reactNative: join(cacheDir, 'react-native.js'),
541
+ }
542
+
543
+ if (!(await pathExists(prebuilds.reactNative))) {
544
+ console.info('Pre-building react, react-native react/jsx-runtime (one time cost)...')
545
+ await Promise.all([
546
+ buildReactNative({
547
+ entryPoints: [resolveFile('react-native')],
548
+ outfile: prebuilds.reactNative,
549
+ }),
550
+ buildReact({
551
+ entryPoints: [resolveFile('react')],
552
+ outfile: prebuilds.react,
553
+ }),
554
+ buildReactJSX({
555
+ entryPoints: [resolveFile('react/jsx-dev-runtime')],
556
+ outfile: prebuilds.reactJSX,
557
+ }),
558
+ ])
638
559
  }
560
+
561
+ // react native port (it scans 19000 +5)
562
+ const jsxRuntime = {
563
+ // alias: 'virtual:react-jsx',
564
+ alias: prebuilds.reactJSX,
565
+ contents: await readFile(prebuilds.reactJSX, 'utf-8'),
566
+ } as const
567
+
568
+ const virtualModules = {
569
+ 'react-native': {
570
+ // alias: 'virtual:react-native',
571
+ alias: prebuilds.reactNative,
572
+ contents: await readFile(prebuilds.reactNative, 'utf-8'),
573
+ },
574
+ react: {
575
+ // alias: 'virtual:react',
576
+ alias: prebuilds.react,
577
+ contents: await readFile(prebuilds.react, 'utf-8'),
578
+ },
579
+ 'react/jsx-runtime': jsxRuntime,
580
+ 'react/jsx-dev-runtime': jsxRuntime,
581
+ } as const
582
+
583
+ return {
584
+ name: `swap-react-native`,
585
+ enforce: 'pre',
586
+
587
+ resolveId(id, importer = '') {
588
+ if (id.startsWith('react-native/Libraries')) {
589
+ return `virtual:rn-internals:${id}`
590
+ }
591
+
592
+ // this will break web support, we need a way to somehow switch between?
593
+ if (id === 'react-native-web') {
594
+ return prebuilds.reactNative
595
+ }
596
+
597
+ for (const targetId in virtualModules) {
598
+ if (id === targetId || id.includes(`node_modules/${targetId}/`)) {
599
+ const info = virtualModules[targetId]
600
+
601
+ return info.alias
602
+ }
603
+ }
604
+
605
+ // TODO this is terrible and slow, we should be able to get extensions working:
606
+ // having trouble getting .native.js to be picked up via vite
607
+ // tried adding packages to optimizeDeps, tried resolveExtensions + extensions...
608
+ // tried this but seems to not be called for node_modules
609
+ if (isBuildingNativeBundle) {
610
+ if (id[0] === '.') {
611
+ const absolutePath = resolve(dirname(importer), id)
612
+ const nativePath = absolutePath.replace(/(.m?js)/, '.native.js')
613
+ if (nativePath === id) return
614
+ try {
615
+ const directoryPath = absolutePath + '/index.native.js'
616
+ const directoryNonNativePath = absolutePath + '/index.js'
617
+ if (pathExistsSync(directoryPath)) {
618
+ return directoryPath
619
+ }
620
+ if (pathExistsSync(directoryNonNativePath)) {
621
+ return directoryNonNativePath
622
+ }
623
+ if (pathExistsSync(nativePath)) {
624
+ return nativePath
625
+ }
626
+ } catch (err) {
627
+ console.warn(`error probably fine`, err)
628
+ }
629
+ }
630
+ }
631
+ },
632
+
633
+ load(id) {
634
+ if (id.startsWith('virtual:rn-internals')) {
635
+ const idOut = id.replace('virtual:rn-internals:', '')
636
+ let out = `const ___val = __cachedModules["${idOut}"]
637
+ const ___defaultVal = ___val ? ___val.default || ___val : ___val
638
+ export default ___defaultVal`
639
+ return out
640
+ }
641
+
642
+ for (const targetId in virtualModules) {
643
+ const info = virtualModules[targetId as keyof typeof virtualModules]
644
+ if (id === info.alias) {
645
+ return info.contents
646
+ }
647
+ }
648
+ },
649
+ } satisfies PluginOption
639
650
  }
640
651
 
641
652
  function getIndexJsonResponse({ port, root }: { port: number | string; root }) {
@@ -742,10 +753,53 @@ function isWithin(outer: string, inner: string) {
742
753
  // used for normalizing hot reloads
743
754
  let entryRoot = ''
744
755
 
745
- export async function getViteServerConfig({ root, host, webConfig, cacheDir }: VXRNConfigFilled) {
746
- const hotUpdateCache = new Map<string, string>()
756
+ async function getViteServerConfig(config: VXRNConfigFilled) {
757
+ const { root, host, webConfig, cacheDir } = config
758
+
759
+ let serverConfig: UserConfig = mergeConfig(
760
+ getBaseViteConfig({
761
+ mode: 'development',
762
+ }),
763
+ {
764
+ root,
765
+ clearScreen: false,
766
+
767
+ plugins: [reactNativeHMRPlugin(config)],
768
+ optimizeDeps: {
769
+ include: depsToOptimize,
770
+ exclude: [`${cacheDir}/*`],
771
+ esbuildOptions: {
772
+ resolveExtensions: webExtensions,
773
+ },
774
+ },
775
+ ssr: {
776
+ noExternal: true,
777
+ optimizeDeps: ssrOptimizeDeps,
778
+ },
779
+ server: {
780
+ hmr: {
781
+ path: '/__vxrnhmr',
782
+ },
783
+ cors: true,
784
+ host,
785
+ },
786
+ } satisfies UserConfig
787
+ ) satisfies InlineConfig
747
788
 
748
- const reactNativeHMRPlugin = {
789
+ if (webConfig) {
790
+ serverConfig = mergeConfig(serverConfig, webConfig) as any
791
+ }
792
+
793
+ serverConfig = {
794
+ ...serverConfig,
795
+ plugins: [...serverConfig.plugins!],
796
+ }
797
+
798
+ return serverConfig
799
+ }
800
+
801
+ function reactNativeHMRPlugin({ root }: VXRNConfigFilled) {
802
+ return {
749
803
  name: 'client-transform',
750
804
 
751
805
  async handleHotUpdate({ read, modules, file }) {
@@ -836,48 +890,4 @@ export async function getViteServerConfig({ root, host, webConfig, cacheDir }: V
836
890
  }
837
891
  },
838
892
  }
839
-
840
- let serverConfig: UserConfig = mergeConfig(
841
- getBaseViteConfig({
842
- mode: 'development',
843
- }),
844
- {
845
- root,
846
- clearScreen: false,
847
- plugins: [
848
- reactNativeHMRPlugin,
849
-
850
- clientBundleTreeShakePlugin({}),
851
- ],
852
- optimizeDeps: {
853
- include: depsToOptimize,
854
- exclude: [`${cacheDir}/*`],
855
- force: true,
856
- esbuildOptions: {
857
- resolveExtensions: extensions,
858
- },
859
- },
860
- server: {
861
- hmr: {
862
- path: '/__vxrnhmr',
863
- },
864
- cors: true,
865
- host,
866
- },
867
- } satisfies UserConfig
868
- ) satisfies InlineConfig
869
-
870
- if (webConfig) {
871
- serverConfig = mergeConfig(serverConfig, webConfig) as any
872
- }
873
-
874
- serverConfig = {
875
- ...serverConfig,
876
- plugins: [...serverConfig.plugins!],
877
- }
878
-
879
- return {
880
- serverConfig,
881
- hotUpdateCache,
882
- }
883
893
  }