one 1.15.10 → 1.16.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 (297) hide show
  1. package/dist/cjs/cli/build.cjs +98 -58
  2. package/dist/cjs/cli/build.native.js +106 -63
  3. package/dist/cjs/cli/build.native.js.map +1 -1
  4. package/dist/cjs/cli/buildPage.cjs +3 -3
  5. package/dist/cjs/cli/buildPage.native.js +3 -3
  6. package/dist/cjs/cli/buildPage.native.js.map +1 -1
  7. package/dist/cjs/constants.cjs +2 -0
  8. package/dist/cjs/constants.native.js +2 -0
  9. package/dist/cjs/constants.native.js.map +1 -1
  10. package/dist/cjs/createAPIRoute.native.js.map +1 -1
  11. package/dist/cjs/createApp.cjs +2 -6
  12. package/dist/cjs/createHandleRequest.cjs +2 -2
  13. package/dist/cjs/createHandleRequest.native.js +2 -2
  14. package/dist/cjs/createHandleRequest.native.js.map +1 -1
  15. package/dist/cjs/hooks.cjs +5 -1
  16. package/dist/cjs/hooks.native.js +7 -1
  17. package/dist/cjs/hooks.native.js.map +1 -1
  18. package/dist/cjs/index.native.js.map +1 -1
  19. package/dist/cjs/metro-config/getViteMetroPluginOptions.cjs +10 -7
  20. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js +13 -10
  21. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  22. package/dist/cjs/metro-config/getViteMetroPluginOptions.test.cjs +23 -0
  23. package/dist/cjs/metro-config/getViteMetroPluginOptions.test.native.js +26 -0
  24. package/dist/cjs/metro-config/getViteMetroPluginOptions.test.native.js.map +1 -0
  25. package/dist/cjs/router/Route.cjs +21 -1
  26. package/dist/cjs/router/Route.native.js +22 -1
  27. package/dist/cjs/router/Route.native.js.map +1 -1
  28. package/dist/cjs/router/interceptRoutes.cjs +6 -6
  29. package/dist/cjs/router/interceptRoutes.native.js +6 -6
  30. package/dist/cjs/router/interceptRoutes.native.js.map +1 -1
  31. package/dist/cjs/router/params.cjs +46 -0
  32. package/dist/cjs/router/params.native.js +70 -0
  33. package/dist/cjs/router/params.native.js.map +1 -0
  34. package/dist/cjs/router/router.cjs +21 -6
  35. package/dist/cjs/router/router.native.js +21 -6
  36. package/dist/cjs/router/router.native.js.map +1 -1
  37. package/dist/cjs/router/useScreens.cjs +3 -0
  38. package/dist/cjs/router/useScreens.native.js +2 -0
  39. package/dist/cjs/router/useScreens.native.js.map +1 -1
  40. package/dist/cjs/serve-worker.native.js.map +1 -1
  41. package/dist/cjs/server/getServerManifest.cjs +6 -6
  42. package/dist/cjs/server/getServerManifest.native.js +6 -6
  43. package/dist/cjs/server/getServerManifest.native.js.map +1 -1
  44. package/dist/cjs/server/oneServe.cjs +9 -5
  45. package/dist/cjs/server/oneServe.native.js +9 -5
  46. package/dist/cjs/server/oneServe.native.js.map +1 -1
  47. package/dist/cjs/server/workerHandler.cjs +2 -2
  48. package/dist/cjs/server/workerHandler.native.js +2 -2
  49. package/dist/cjs/server/workerHandler.native.js.map +1 -1
  50. package/dist/cjs/skewProtection.cjs +48 -7
  51. package/dist/cjs/skewProtection.native.js +48 -7
  52. package/dist/cjs/skewProtection.native.js.map +1 -1
  53. package/dist/cjs/useLoader.cjs +67 -69
  54. package/dist/cjs/useLoader.native.js +113 -117
  55. package/dist/cjs/useLoader.native.js.map +1 -1
  56. package/dist/cjs/utils/dynamicImport.cjs +3 -1
  57. package/dist/cjs/utils/dynamicImport.native.js +22 -1
  58. package/dist/cjs/utils/dynamicImport.native.js.map +1 -1
  59. package/dist/cjs/utils/toAbsolute.cjs +5 -2
  60. package/dist/cjs/utils/toAbsolute.native.js +6 -1
  61. package/dist/cjs/utils/toAbsolute.native.js.map +1 -1
  62. package/dist/cjs/utils/workerImport.cjs +1 -1
  63. package/dist/cjs/utils/workerImport.native.js +1 -1
  64. package/dist/cjs/utils/workerImport.native.js.map +1 -1
  65. package/dist/cjs/views/RootErrorBoundary.cjs +114 -117
  66. package/dist/cjs/views/RootErrorBoundary.native.js +126 -146
  67. package/dist/cjs/views/RootErrorBoundary.native.js.map +1 -1
  68. package/dist/cjs/views/Try.cjs +17 -18
  69. package/dist/cjs/views/Try.native.js +28 -42
  70. package/dist/cjs/views/Try.native.js.map +1 -1
  71. package/dist/cjs/vite/plugins/criticalCSSPlugin.cjs +2 -1
  72. package/dist/cjs/vite/plugins/criticalCSSPlugin.native.js +2 -1
  73. package/dist/cjs/vite/plugins/criticalCSSPlugin.native.js.map +1 -1
  74. package/dist/cjs/vite/plugins/criticalCSSPlugin.test.cjs +26 -20
  75. package/dist/cjs/vite/plugins/criticalCSSPlugin.test.native.js +28 -20
  76. package/dist/cjs/vite/plugins/criticalCSSPlugin.test.native.js.map +1 -1
  77. package/dist/cjs/vite/plugins/imageDataPlugin.cjs +3 -2
  78. package/dist/cjs/vite/plugins/imageDataPlugin.native.js +3 -2
  79. package/dist/cjs/vite/plugins/imageDataPlugin.native.js.map +1 -1
  80. package/dist/cjs/vite/plugins/imageDataPlugin.test.cjs +34 -69
  81. package/dist/cjs/vite/plugins/imageDataPlugin.test.native.js +34 -69
  82. package/dist/cjs/vite/plugins/imageDataPlugin.test.native.js.map +1 -1
  83. package/dist/cjs/vite/plugins/sourceInspectorPlugin.cjs +20 -2
  84. package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js +23 -2
  85. package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js.map +1 -1
  86. package/dist/cjs/vite/plugins/sourceInspectorPlugin.test.cjs +21 -0
  87. package/dist/cjs/vite/plugins/sourceInspectorPlugin.test.native.js +28 -0
  88. package/dist/cjs/vite/plugins/sourceInspectorPlugin.test.native.js.map +1 -0
  89. package/dist/cjs/vite/resolveResponse.cjs +7 -2
  90. package/dist/cjs/vite/resolveResponse.native.js +7 -2
  91. package/dist/cjs/vite/resolveResponse.native.js.map +1 -1
  92. package/dist/esm/cli/build.mjs +100 -60
  93. package/dist/esm/cli/build.mjs.map +1 -1
  94. package/dist/esm/cli/build.native.js +108 -65
  95. package/dist/esm/cli/build.native.js.map +1 -1
  96. package/dist/esm/cli/buildPage.mjs +4 -4
  97. package/dist/esm/cli/buildPage.mjs.map +1 -1
  98. package/dist/esm/cli/buildPage.native.js +4 -4
  99. package/dist/esm/cli/buildPage.native.js.map +1 -1
  100. package/dist/esm/constants.mjs +2 -1
  101. package/dist/esm/constants.mjs.map +1 -1
  102. package/dist/esm/constants.native.js +2 -1
  103. package/dist/esm/constants.native.js.map +1 -1
  104. package/dist/esm/createAPIRoute.mjs.map +1 -1
  105. package/dist/esm/createAPIRoute.native.js.map +1 -1
  106. package/dist/esm/createApp.mjs +2 -6
  107. package/dist/esm/createApp.mjs.map +1 -1
  108. package/dist/esm/createHandleRequest.mjs +2 -2
  109. package/dist/esm/createHandleRequest.mjs.map +1 -1
  110. package/dist/esm/createHandleRequest.native.js +2 -2
  111. package/dist/esm/createHandleRequest.native.js.map +1 -1
  112. package/dist/esm/hooks.mjs +5 -1
  113. package/dist/esm/hooks.mjs.map +1 -1
  114. package/dist/esm/hooks.native.js +7 -1
  115. package/dist/esm/hooks.native.js.map +1 -1
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/index.mjs.map +1 -1
  118. package/dist/esm/index.native.js.map +1 -1
  119. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs +9 -7
  120. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs.map +1 -1
  121. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js +12 -10
  122. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  123. package/dist/esm/metro-config/getViteMetroPluginOptions.test.mjs +24 -0
  124. package/dist/esm/metro-config/getViteMetroPluginOptions.test.mjs.map +1 -0
  125. package/dist/esm/metro-config/getViteMetroPluginOptions.test.native.js +24 -0
  126. package/dist/esm/metro-config/getViteMetroPluginOptions.test.native.js.map +1 -0
  127. package/dist/esm/router/Route.mjs +21 -1
  128. package/dist/esm/router/Route.mjs.map +1 -1
  129. package/dist/esm/router/Route.native.js +22 -1
  130. package/dist/esm/router/Route.native.js.map +1 -1
  131. package/dist/esm/router/interceptRoutes.mjs +7 -7
  132. package/dist/esm/router/interceptRoutes.mjs.map +1 -1
  133. package/dist/esm/router/interceptRoutes.native.js +7 -7
  134. package/dist/esm/router/interceptRoutes.native.js.map +1 -1
  135. package/dist/esm/router/params.mjs +21 -0
  136. package/dist/esm/router/params.mjs.map +1 -0
  137. package/dist/esm/router/params.native.js +42 -0
  138. package/dist/esm/router/params.native.js.map +1 -0
  139. package/dist/esm/router/router.mjs +21 -6
  140. package/dist/esm/router/router.mjs.map +1 -1
  141. package/dist/esm/router/router.native.js +21 -6
  142. package/dist/esm/router/router.native.js.map +1 -1
  143. package/dist/esm/router/useScreens.mjs +3 -0
  144. package/dist/esm/router/useScreens.mjs.map +1 -1
  145. package/dist/esm/router/useScreens.native.js +2 -0
  146. package/dist/esm/router/useScreens.native.js.map +1 -1
  147. package/dist/esm/serve-worker.mjs.map +1 -1
  148. package/dist/esm/serve-worker.native.js.map +1 -1
  149. package/dist/esm/server/getServerManifest.mjs +6 -6
  150. package/dist/esm/server/getServerManifest.mjs.map +1 -1
  151. package/dist/esm/server/getServerManifest.native.js +6 -6
  152. package/dist/esm/server/getServerManifest.native.js.map +1 -1
  153. package/dist/esm/server/oneServe.mjs +11 -7
  154. package/dist/esm/server/oneServe.mjs.map +1 -1
  155. package/dist/esm/server/oneServe.native.js +11 -7
  156. package/dist/esm/server/oneServe.native.js.map +1 -1
  157. package/dist/esm/server/workerHandler.mjs +2 -2
  158. package/dist/esm/server/workerHandler.mjs.map +1 -1
  159. package/dist/esm/server/workerHandler.native.js +2 -2
  160. package/dist/esm/server/workerHandler.native.js.map +1 -1
  161. package/dist/esm/skewProtection.mjs +48 -8
  162. package/dist/esm/skewProtection.mjs.map +1 -1
  163. package/dist/esm/skewProtection.native.js +48 -8
  164. package/dist/esm/skewProtection.native.js.map +1 -1
  165. package/dist/esm/useLoader.mjs +64 -66
  166. package/dist/esm/useLoader.mjs.map +1 -1
  167. package/dist/esm/useLoader.native.js +112 -116
  168. package/dist/esm/useLoader.native.js.map +1 -1
  169. package/dist/esm/utils/dynamicImport.mjs +1 -1
  170. package/dist/esm/utils/dynamicImport.mjs.map +1 -1
  171. package/dist/esm/utils/dynamicImport.native.js +20 -1
  172. package/dist/esm/utils/dynamicImport.native.js.map +1 -1
  173. package/dist/esm/utils/toAbsolute.mjs +3 -1
  174. package/dist/esm/utils/toAbsolute.mjs.map +1 -1
  175. package/dist/esm/utils/toAbsolute.native.js +5 -1
  176. package/dist/esm/utils/toAbsolute.native.js.map +1 -1
  177. package/dist/esm/utils/workerImport.mjs +2 -2
  178. package/dist/esm/utils/workerImport.mjs.map +1 -1
  179. package/dist/esm/utils/workerImport.native.js +2 -2
  180. package/dist/esm/utils/workerImport.native.js.map +1 -1
  181. package/dist/esm/views/RootErrorBoundary.mjs +114 -117
  182. package/dist/esm/views/RootErrorBoundary.mjs.map +1 -1
  183. package/dist/esm/views/RootErrorBoundary.native.js +126 -146
  184. package/dist/esm/views/RootErrorBoundary.native.js.map +1 -1
  185. package/dist/esm/views/Try.mjs +17 -18
  186. package/dist/esm/views/Try.mjs.map +1 -1
  187. package/dist/esm/views/Try.native.js +28 -42
  188. package/dist/esm/views/Try.native.js.map +1 -1
  189. package/dist/esm/vite/plugins/criticalCSSPlugin.mjs +2 -1
  190. package/dist/esm/vite/plugins/criticalCSSPlugin.mjs.map +1 -1
  191. package/dist/esm/vite/plugins/criticalCSSPlugin.native.js +2 -1
  192. package/dist/esm/vite/plugins/criticalCSSPlugin.native.js.map +1 -1
  193. package/dist/esm/vite/plugins/criticalCSSPlugin.test.mjs +26 -20
  194. package/dist/esm/vite/plugins/criticalCSSPlugin.test.mjs.map +1 -1
  195. package/dist/esm/vite/plugins/criticalCSSPlugin.test.native.js +28 -20
  196. package/dist/esm/vite/plugins/criticalCSSPlugin.test.native.js.map +1 -1
  197. package/dist/esm/vite/plugins/imageDataPlugin.mjs +4 -3
  198. package/dist/esm/vite/plugins/imageDataPlugin.mjs.map +1 -1
  199. package/dist/esm/vite/plugins/imageDataPlugin.native.js +4 -3
  200. package/dist/esm/vite/plugins/imageDataPlugin.native.js.map +1 -1
  201. package/dist/esm/vite/plugins/imageDataPlugin.test.mjs +34 -69
  202. package/dist/esm/vite/plugins/imageDataPlugin.test.mjs.map +1 -1
  203. package/dist/esm/vite/plugins/imageDataPlugin.test.native.js +34 -69
  204. package/dist/esm/vite/plugins/imageDataPlugin.test.native.js.map +1 -1
  205. package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs +19 -3
  206. package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs.map +1 -1
  207. package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js +22 -3
  208. package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js.map +1 -1
  209. package/dist/esm/vite/plugins/sourceInspectorPlugin.test.mjs +22 -0
  210. package/dist/esm/vite/plugins/sourceInspectorPlugin.test.mjs.map +1 -0
  211. package/dist/esm/vite/plugins/sourceInspectorPlugin.test.native.js +26 -0
  212. package/dist/esm/vite/plugins/sourceInspectorPlugin.test.native.js.map +1 -0
  213. package/dist/esm/vite/resolveResponse.mjs +7 -2
  214. package/dist/esm/vite/resolveResponse.mjs.map +1 -1
  215. package/dist/esm/vite/resolveResponse.native.js +7 -2
  216. package/dist/esm/vite/resolveResponse.native.js.map +1 -1
  217. package/expo-plugin.cjs +1 -0
  218. package/package.json +15 -10
  219. package/react-native-commands.cjs +1 -0
  220. package/src/cli/build.ts +156 -99
  221. package/src/cli/buildPage.ts +4 -4
  222. package/src/constants.ts +15 -0
  223. package/src/createAPIRoute.ts +35 -2
  224. package/src/createApp.tsx +2 -6
  225. package/src/createHandleRequest.ts +6 -2
  226. package/src/hooks.tsx +9 -1
  227. package/src/index.ts +8 -1
  228. package/src/metro-config/getViteMetroPluginOptions.test.ts +34 -0
  229. package/src/metro-config/getViteMetroPluginOptions.ts +14 -11
  230. package/src/router/Route.tsx +52 -2
  231. package/src/router/interceptRoutes.ts +7 -7
  232. package/src/router/params.ts +32 -0
  233. package/src/router/router.ts +43 -10
  234. package/src/router/useScreens.tsx +18 -0
  235. package/src/serve-worker.ts +4 -2
  236. package/src/server/getServerManifest.ts +11 -7
  237. package/src/server/oneServe.ts +12 -14
  238. package/src/server/workerHandler.ts +13 -2
  239. package/src/skewProtection.ts +45 -5
  240. package/src/useLoader.ts +6 -4
  241. package/src/utils/dynamicImport.ts +2 -2
  242. package/src/utils/toAbsolute.ts +5 -0
  243. package/src/utils/workerImport.ts +2 -2
  244. package/src/views/RootErrorBoundary.tsx +18 -0
  245. package/src/views/Try.tsx +18 -0
  246. package/src/vite/plugins/criticalCSSPlugin.test.ts +34 -24
  247. package/src/vite/plugins/criticalCSSPlugin.ts +3 -2
  248. package/src/vite/plugins/imageDataPlugin.test.ts +39 -83
  249. package/src/vite/plugins/imageDataPlugin.ts +5 -4
  250. package/src/vite/plugins/sourceInspectorPlugin.test.ts +40 -0
  251. package/src/vite/plugins/sourceInspectorPlugin.ts +30 -2
  252. package/src/vite/resolveResponse.ts +6 -2
  253. package/types/cli/build.d.ts.map +1 -1
  254. package/types/constants.d.ts +9 -0
  255. package/types/constants.d.ts.map +1 -1
  256. package/types/createAPIRoute.d.ts +28 -3
  257. package/types/createAPIRoute.d.ts.map +1 -1
  258. package/types/createApp.d.ts.map +1 -1
  259. package/types/createHandleRequest.d.ts +1 -1
  260. package/types/createHandleRequest.d.ts.map +1 -1
  261. package/types/headless-server.d.ts +1 -1
  262. package/types/hooks.d.ts.map +1 -1
  263. package/types/index.d.ts +1 -1
  264. package/types/index.d.ts.map +1 -1
  265. package/types/metro-config/getViteMetroPluginOptions.d.ts +5 -0
  266. package/types/metro-config/getViteMetroPluginOptions.d.ts.map +1 -1
  267. package/types/metro-config/getViteMetroPluginOptions.test.d.ts +2 -0
  268. package/types/metro-config/getViteMetroPluginOptions.test.d.ts.map +1 -0
  269. package/types/router/Route.d.ts +1 -0
  270. package/types/router/Route.d.ts.map +1 -1
  271. package/types/router/params.d.ts +3 -0
  272. package/types/router/params.d.ts.map +1 -0
  273. package/types/router/router.d.ts.map +1 -1
  274. package/types/router/useScreens.d.ts.map +1 -1
  275. package/types/serve-worker.d.ts +5 -3
  276. package/types/serve-worker.d.ts.map +1 -1
  277. package/types/server/getServerManifest.d.ts.map +1 -1
  278. package/types/server/oneServe.d.ts.map +1 -1
  279. package/types/server/workerHandler.d.ts +1 -1
  280. package/types/server/workerHandler.d.ts.map +1 -1
  281. package/types/skewProtection.d.ts +1 -0
  282. package/types/skewProtection.d.ts.map +1 -1
  283. package/types/useLoader.d.ts.map +1 -1
  284. package/types/utils/dynamicImport.d.ts +2 -0
  285. package/types/utils/dynamicImport.d.ts.map +1 -1
  286. package/types/utils/toAbsolute.d.ts +3 -0
  287. package/types/utils/toAbsolute.d.ts.map +1 -1
  288. package/types/views/RootErrorBoundary.d.ts.map +1 -1
  289. package/types/views/Try.d.ts.map +1 -1
  290. package/types/vite/plugins/criticalCSSPlugin.d.ts.map +1 -1
  291. package/types/vite/plugins/imageDataPlugin.d.ts.map +1 -1
  292. package/types/vite/plugins/sourceInspectorPlugin.d.ts +2 -0
  293. package/types/vite/plugins/sourceInspectorPlugin.d.ts.map +1 -1
  294. package/types/vite/plugins/sourceInspectorPlugin.test.d.ts +2 -0
  295. package/types/vite/plugins/sourceInspectorPlugin.test.d.ts.map +1 -0
  296. package/types/vite/resolveResponse.d.ts +1 -1
  297. package/types/vite/resolveResponse.d.ts.map +1 -1
@@ -322,10 +322,30 @@ async function build(args) {
322
322
  rolldownOptions: _rolldownOptions,
323
323
  ...optimizeDepsNoRolldown
324
324
  } = optimizeDeps;
325
- const clonedWebBuildConfig = clonePluginHooks(vxrnOutput.webBuildConfig);
326
- const apiBuildConfig = (0, import_vite.mergeConfig)(
327
- // feels like this should build off the *server* build config not web
328
- clonedWebBuildConfig, {
325
+ const serverOpts = oneOptions.build?.server;
326
+ const isUnified = typeof serverOpts === "object" && serverOpts !== null && serverOpts.unified === true;
327
+ let baseForApi = isUnified ? clonePluginHooks(vxrnOutput.serverBuildConfig ?? vxrnOutput.webBuildConfig) : clonePluginHooks(vxrnOutput.webBuildConfig);
328
+ if (isUnified) {
329
+ const clone = {
330
+ ...baseForApi,
331
+ build: baseForApi.build ? {
332
+ ...baseForApi.build
333
+ } : void 0,
334
+ plugins: baseForApi.plugins ? baseForApi.plugins.filter(p => p && typeof p === "object" && p.name !== "omit-api-routes") : void 0
335
+ };
336
+ if (clone.build && clone.build.rolldownOptions) {
337
+ const ro = {
338
+ ...clone.build.rolldownOptions
339
+ };
340
+ delete ro.input;
341
+ clone.build.rolldownOptions = ro;
342
+ }
343
+ if (clone.build) {
344
+ delete clone.build.outDir;
345
+ }
346
+ baseForApi = clone;
347
+ }
348
+ const apiBuildConfig = (0, import_vite.mergeConfig)(baseForApi, {
329
349
  configFile: false,
330
350
  appType: "custom",
331
351
  optimizeDeps: optimizeDepsNoRolldown,
@@ -350,13 +370,13 @@ async function build(args) {
350
370
  const mergedConfig = (0, import_vite.mergeConfig)(apiBuildConfig, {
351
371
  appType: "custom",
352
372
  configFile: false,
353
- // plugins: [
354
- // nodeExternals({
355
- // exclude: optimizeDeps.include,
356
- // }) as any,
357
- // ],
358
373
  define: vxrnOutput.processEnvDefines,
359
- ssr: {
374
+ ssr: isUnified ? {
375
+ // in unified mode let the base (serverBuildConfig) set ssr.noExternal
376
+ // — default is now ['react', 'react-dom'] instead of `true`, so
377
+ // rolldown can externalize the rest.
378
+ optimizeDeps: optimizeDepsNoRolldown
379
+ } : {
360
380
  noExternal: true,
361
381
  external: ["react", "react-dom"],
362
382
  optimizeDeps: optimizeDepsNoRolldown
@@ -388,7 +408,12 @@ async function build(args) {
388
408
  // prevents it from shaking out the exports
389
409
  preserveEntrySignatures: "strict",
390
410
  input,
391
- external: [],
411
+ // in unified mode, inherit externals from serverBuildConfig (user
412
+ // ssr.external / rolldownOptions.external). the legacy path resets
413
+ // them to [] so per-route files bundle everything.
414
+ ...(isUnified ? {} : {
415
+ external: []
416
+ }),
392
417
  output: {
393
418
  entryFileNames: "[name]",
394
419
  exports: "auto",
@@ -437,14 +462,14 @@ async function build(args) {
437
462
  if (middlewareBuildInfo) {
438
463
  for (const middleware of manifest.middlewareRoutes) {
439
464
  const absoluteRoot = (0, import_node_path.resolve)(process.cwd(), options.root);
440
- const fullPath = (0, import_node_path.join)(absoluteRoot, routerRoot, middleware.file);
465
+ const fullPath = (0, import_vite.normalizePath)((0, import_node_path.join)(absoluteRoot, routerRoot, middleware.file));
441
466
  const outChunks = middlewareBuildInfo.output.filter(x => x.type === "chunk");
442
467
  const chunk = outChunks.find(x => x.facadeModuleId === fullPath);
443
468
  if (!chunk) throw new Error(`internal err finding middleware`);
444
469
  builtMiddlewares[middleware.file] = (0, import_node_path.join)(outDir, "middlewares", chunk.fileName);
445
470
  }
446
471
  }
447
- globalThis["require"] = (0, import_node_module.createRequire)((0, import_node_path.join)(import_meta.url, ".."));
472
+ globalThis["require"] = (0, import_node_module.createRequire)(import_meta.dirname + "/");
448
473
  const assets = [];
449
474
  const builtRoutes = [];
450
475
  const sitemapData = [];
@@ -487,7 +512,7 @@ async function build(args) {
487
512
  const id = output.facadeModuleId || "";
488
513
  const file = import_node_path.default.basename(id);
489
514
  if (file.startsWith("_layout") && id.includes(`/${routerRoot}/`)) {
490
- const relativePath = (0, import_node_path.relative)(process.cwd(), id).replace(`${routerRoot}/`, "");
515
+ const relativePath = (0, import_vite.normalizePath)((0, import_node_path.relative)(process.cwd(), id)).replace(`${routerRoot}/`, "");
491
516
  const contextKey = `./${relativePath}`;
492
517
  layoutServerPaths.set(contextKey, output.fileName);
493
518
  }
@@ -538,7 +563,7 @@ async function build(args) {
538
563
  if (!foundRoute.file) {
539
564
  continue;
540
565
  }
541
- const routeModulePath = (0, import_node_path.join)((0, import_node_path.resolve)(process.cwd(), options.root), routerRoot, foundRoute.file.slice(2));
566
+ const routeModulePath = (0, import_vite.normalizePath)((0, import_node_path.join)((0, import_node_path.resolve)(process.cwd(), options.root), routerRoot, foundRoute.file.slice(2)));
542
567
  const serverFileName = moduleIdToServerChunk.get(routeModulePath);
543
568
  if (!serverFileName) {
544
569
  if (foundRoute.type === "spa") {
@@ -680,7 +705,7 @@ async function build(args) {
680
705
  const serverJsPath = (0, import_node_path.join)(`${outDir}/server`, serverFileName);
681
706
  let exported;
682
707
  try {
683
- exported = await import((0, import_toAbsolute.toAbsolute)(serverJsPath));
708
+ exported = await import((0, import_toAbsolute.toAbsoluteUrl)(serverJsPath));
684
709
  } catch (err) {
685
710
  console.error(`Error importing page (original error)`, err);
686
711
  throw new Error(`Error importing page: ${serverJsPath}`, {
@@ -822,9 +847,17 @@ async function build(args) {
822
847
  }));
823
848
  }
824
849
  const buildInfo = builtRoutes.find(x => x.routeFile === route.file);
825
- if (built.middlewares && buildInfo?.middlewares) {
850
+ if (built.middlewares) {
826
851
  for (const [index, mw] of built.middlewares.entries()) {
827
- mw.contextKey = buildInfo.middlewares[index];
852
+ const viaBuildInfo = buildInfo?.middlewares?.[index];
853
+ if (viaBuildInfo) {
854
+ mw.contextKey = viaBuildInfo;
855
+ continue;
856
+ }
857
+ const viaMiddlewareMap = builtMiddlewares[mw.contextKey];
858
+ if (viaMiddlewareMap) {
859
+ mw.contextKey = viaMiddlewareMap;
860
+ }
828
861
  }
829
862
  }
830
863
  if (buildInfo) {
@@ -900,6 +933,11 @@ async function build(args) {
900
933
  }
901
934
  case "cloudflare":
902
935
  {
936
+ const workerSrcDir = (0, import_node_path.join)(options.root, outDir);
937
+ const getWorkerSourceImportPath = routeFile => {
938
+ const importPath = (0, import_vite.normalizePath)((0, import_node_path.relative)(workerSrcDir, (0, import_node_path.join)(options.root, routerRoot, routeFile)));
939
+ return importPath.startsWith(".") ? importPath : `./${importPath}`;
940
+ };
903
941
  const pageRouteMap = [];
904
942
  const apiRouteMap = [];
905
943
  const middlewareRouteMap = [];
@@ -911,13 +949,12 @@ async function build(args) {
911
949
  }
912
950
  for (const route of buildInfoForWriting.manifest.apiRoutes) {
913
951
  if (route.file) {
914
- const apiFileName = route.page.slice(1).replace(/\[/g, "_").replace(/\]/g, "_");
915
- const importPath = `./api/${apiFileName}.js`;
952
+ const importPath = getWorkerSourceImportPath(route.file);
916
953
  apiRouteMap.push(` '${route.page}': () => import('${importPath}')`);
917
954
  }
918
955
  }
919
- for (const [, builtPath] of Object.entries(builtMiddlewares)) {
920
- const importPath = "./" + builtPath.replace(new RegExp(`^${outDir}/`), "");
956
+ for (const [sourceFile, builtPath] of Object.entries(builtMiddlewares)) {
957
+ const importPath = getWorkerSourceImportPath(sourceFile);
921
958
  middlewareRouteMap.push(` '${builtPath}': () => import('${importPath}')`);
922
959
  }
923
960
  const workerSrcPath = (0, import_node_path.join)(options.root, outDir, "_worker-src.js");
@@ -975,7 +1012,7 @@ export default {
975
1012
  }
976
1013
 
977
1014
  try {
978
- const response = await server.fetch(request)
1015
+ const response = await server.fetch(request, env, ctx)
979
1016
 
980
1017
  // no route matched or 404 \u2192 try static assets
981
1018
  if (!response || response.status === 404) {
@@ -999,38 +1036,34 @@ export default {
999
1036
  }
1000
1037
  `;
1001
1038
  await import_fs_extra.default.writeFile(workerSrcPath, workerCode);
1039
+ const projectName = await getCloudflareProjectName(options.root);
1040
+ const userWranglerConfig = await loadUserWranglerConfig(options.root);
1041
+ const wranglerInputConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig?.config);
1042
+ wranglerInputConfig.main = (0, import_node_path.relative)((0, import_node_path.join)(options.root, outDir), workerSrcPath);
1043
+ const wranglerInputPath = (0, import_node_path.join)(options.root, outDir, "_wrangler.input.jsonc");
1044
+ await import_fs_extra.default.writeFile(wranglerInputPath, `${JSON.stringify(wranglerInputConfig, null, 2)}
1045
+ `);
1002
1046
  console.info("\n [cloudflare] Bundling worker...");
1003
- await (0, import_vite.build)({
1047
+ const {
1048
+ cloudflare
1049
+ } = await import("@cloudflare/vite-plugin");
1050
+ const builder = await (0, import_vite.createBuilder)({
1004
1051
  root: options.root,
1005
1052
  mode: "production",
1006
1053
  logLevel: "warn",
1007
- build: {
1008
- outDir,
1009
- emptyOutDir: false,
1010
- // Use SSR mode with node target for proper Node.js module resolution
1011
- ssr: workerSrcPath,
1012
- rolldownOptions: {
1013
- external: [
1014
- // React Native dev tools - not needed in production
1015
- "@react-native/dev-middleware", "@react-native/debugger-shell", "metro", "metro-core", "metro-runtime",
1016
- // Native modules that can't run in workers
1017
- /\.node$/],
1018
- output: {
1019
- entryFileNames: "worker.js",
1020
- format: "es",
1021
- // Keep dynamic imports separate for lazy loading
1022
- inlineDynamicImports: false
1023
- }
1024
- },
1025
- minify: true,
1026
- target: "esnext"
1027
- },
1054
+ configFile: false,
1028
1055
  define: {
1029
1056
  "process.env.NODE_ENV": JSON.stringify("production"),
1030
- "process.env.VITE_ENVIRONMENT": JSON.stringify("ssr")
1057
+ "process.env.VITE_ENVIRONMENT": JSON.stringify("ssr"),
1058
+ "process.env.ONE_CACHE_KEY": JSON.stringify(constants.CACHE_KEY)
1031
1059
  },
1060
+ plugins: [cloudflare({
1061
+ configPath: wranglerInputPath,
1062
+ viteEnvironment: {
1063
+ name: "worker"
1064
+ }
1065
+ })],
1032
1066
  resolve: {
1033
- conditions: ["workerd", "worker", "node", "module", "default"],
1034
1067
  alias: [
1035
1068
  // rolldown can't parse react-native's Flow syntax; alias to react-native-web for ssr
1036
1069
  {
@@ -1047,22 +1080,29 @@ export default {
1047
1080
  replacement: (0, import_resolve.resolvePath)("@vxrn/safe-area", options.root)
1048
1081
  }]
1049
1082
  },
1050
- ssr: {
1051
- target: "node",
1052
- noExternal: true
1083
+ build: {
1084
+ outDir,
1085
+ emptyOutDir: false,
1086
+ rolldownOptions: {
1087
+ // Match the main web build behavior so RN packages that import
1088
+ // native-only symbols from react-native can still bundle against
1089
+ // the react-native-web alias in the worker graph.
1090
+ shimMissingExports: true
1091
+ }
1053
1092
  }
1054
1093
  });
1094
+ const workerEnv = builder.environments.worker;
1095
+ if (!workerEnv) {
1096
+ throw new Error('[one] plugin did not register "worker" environment');
1097
+ }
1098
+ await builder.build(workerEnv);
1055
1099
  await import_fs_extra.default.remove(workerSrcPath);
1056
- const projectName = await getCloudflareProjectName(options.root);
1057
- const userWranglerConfig = await loadUserWranglerConfig(options.root);
1058
- const wranglerConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig?.config);
1100
+ await import_fs_extra.default.remove(wranglerInputPath);
1059
1101
  if (userWranglerConfig) {
1060
- console.info(` [cloudflare] Merging ${(0, import_node_path.relative)(options.root, userWranglerConfig.path)} into ${outDir}/wrangler.jsonc`);
1102
+ console.info(` [cloudflare] Merging ${(0, import_node_path.relative)(options.root, userWranglerConfig.path)} into ${outDir}/worker/wrangler.json`);
1061
1103
  }
1062
- await import_fs_extra.default.writeFile((0, import_node_path.join)(options.root, outDir, "wrangler.jsonc"), `${JSON.stringify(wranglerConfig, null, 2)}
1063
- `);
1064
- postBuildLogs.push(`Cloudflare worker bundled at ${outDir}/worker.js`);
1065
- postBuildLogs.push(`To deploy: cd ${outDir} && wrangler deploy`);
1104
+ postBuildLogs.push(`Cloudflare worker bundled at ${outDir}/worker/index.js`);
1105
+ postBuildLogs.push(`To deploy: cd ${outDir}/worker && wrangler deploy`);
1066
1106
  break;
1067
1107
  }
1068
1108
  }
@@ -329,8 +329,8 @@ function clonePluginHooks(config) {
329
329
  };
330
330
  }
331
331
  async function build(args) {
332
- var _ref, _ref1, _args_skipEnv, _securityScanOption_level;
333
- var _oneOptions_web, _oneOptions_web1, _viteLoadedConfig_config_build, _viteLoadedConfig_config, _oneOptions_router, _oneOptions_build, _oneOptions_build_server, _oneOptions_build1, _oneOptions_build2, _oneOptions_web2, _oneOptions_build3;
332
+ var _ref, _ref1, _args_skipEnv, _vxrnOutput_serverBuildConfig, _securityScanOption_level;
333
+ var _oneOptions_web, _oneOptions_web1, _viteLoadedConfig_config_build, _viteLoadedConfig_config, _oneOptions_router, _oneOptions_build, _oneOptions_build_server, _oneOptions_build1, _oneOptions_build2, _oneOptions_build3, _oneOptions_web2, _oneOptions_build4;
334
334
  process.env.IS_VXRN_CLI = "true";
335
335
  if (!process.env.NODE_ENV) {
336
336
  process.env.NODE_ENV = "production";
@@ -395,10 +395,32 @@ async function build(args) {
395
395
  rolldownOptions: _rolldownOptions,
396
396
  ...optimizeDepsNoRolldown
397
397
  } = optimizeDeps;
398
- var clonedWebBuildConfig = clonePluginHooks(vxrnOutput.webBuildConfig);
399
- var apiBuildConfig = (0, import_vite.mergeConfig)(
400
- // feels like this should build off the *server* build config not web
401
- clonedWebBuildConfig, {
398
+ var serverOpts = (_oneOptions_build3 = oneOptions.build) === null || _oneOptions_build3 === void 0 ? void 0 : _oneOptions_build3.server;
399
+ var isUnified = (typeof serverOpts === "undefined" ? "undefined" : _type_of(serverOpts)) === "object" && serverOpts !== null && serverOpts.unified === true;
400
+ var baseForApi = isUnified ? clonePluginHooks((_vxrnOutput_serverBuildConfig = vxrnOutput.serverBuildConfig) !== null && _vxrnOutput_serverBuildConfig !== void 0 ? _vxrnOutput_serverBuildConfig : vxrnOutput.webBuildConfig) : clonePluginHooks(vxrnOutput.webBuildConfig);
401
+ if (isUnified) {
402
+ var clone = {
403
+ ...baseForApi,
404
+ build: baseForApi.build ? {
405
+ ...baseForApi.build
406
+ } : void 0,
407
+ plugins: baseForApi.plugins ? baseForApi.plugins.filter(function (p2) {
408
+ return p2 && (typeof p2 === "undefined" ? "undefined" : _type_of(p2)) === "object" && p2.name !== "omit-api-routes";
409
+ }) : void 0
410
+ };
411
+ if (clone.build && clone.build.rolldownOptions) {
412
+ var ro = {
413
+ ...clone.build.rolldownOptions
414
+ };
415
+ delete ro.input;
416
+ clone.build.rolldownOptions = ro;
417
+ }
418
+ if (clone.build) {
419
+ delete clone.build.outDir;
420
+ }
421
+ baseForApi = clone;
422
+ }
423
+ var apiBuildConfig = (0, import_vite.mergeConfig)(baseForApi, {
402
424
  configFile: false,
403
425
  appType: "custom",
404
426
  optimizeDeps: optimizeDepsNoRolldown,
@@ -412,7 +434,7 @@ async function build(args) {
412
434
  });
413
435
  async function buildCustomRoutes(subFolder, routes) {
414
436
  var _ref2;
415
- var _oneOptions_build_api, _oneOptions_build4, _oneOptions_build_api1, _oneOptions_build12, _oneOptions_build_api2, _oneOptions_build22;
437
+ var _oneOptions_build_api, _oneOptions_build5, _oneOptions_build_api1, _oneOptions_build12, _oneOptions_build_api2, _oneOptions_build22;
416
438
  var input = routes.reduce(function (entries, param) {
417
439
  var {
418
440
  page,
@@ -421,18 +443,18 @@ async function build(args) {
421
443
  entries[page.slice(1) + ".js"] = (0, import_path.join)(routerRoot, file2);
422
444
  return entries;
423
445
  }, {});
424
- var outputFormat = (_ref2 = oneOptions === null || oneOptions === void 0 ? void 0 : (_oneOptions_build4 = oneOptions.build) === null || _oneOptions_build4 === void 0 ? void 0 : (_oneOptions_build_api = _oneOptions_build4.api) === null || _oneOptions_build_api === void 0 ? void 0 : _oneOptions_build_api.outputFormat) !== null && _ref2 !== void 0 ? _ref2 : serverOutputFormat;
446
+ var outputFormat = (_ref2 = oneOptions === null || oneOptions === void 0 ? void 0 : (_oneOptions_build5 = oneOptions.build) === null || _oneOptions_build5 === void 0 ? void 0 : (_oneOptions_build_api = _oneOptions_build5.api) === null || _oneOptions_build_api === void 0 ? void 0 : _oneOptions_build_api.outputFormat) !== null && _ref2 !== void 0 ? _ref2 : serverOutputFormat;
425
447
  var treeshake = oneOptions === null || oneOptions === void 0 ? void 0 : (_oneOptions_build12 = oneOptions.build) === null || _oneOptions_build12 === void 0 ? void 0 : (_oneOptions_build_api1 = _oneOptions_build12.api) === null || _oneOptions_build_api1 === void 0 ? void 0 : _oneOptions_build_api1.treeshake;
426
448
  var mergedConfig = (0, import_vite.mergeConfig)(apiBuildConfig, {
427
449
  appType: "custom",
428
450
  configFile: false,
429
- // plugins: [
430
- // nodeExternals({
431
- // exclude: optimizeDeps.include,
432
- // }) as any,
433
- // ],
434
451
  define: vxrnOutput.processEnvDefines,
435
- ssr: {
452
+ ssr: isUnified ? {
453
+ // in unified mode let the base (serverBuildConfig) set ssr.noExternal
454
+ // — default is now ['react', 'react-dom'] instead of `true`, so
455
+ // rolldown can externalize the rest.
456
+ optimizeDeps: optimizeDepsNoRolldown
457
+ } : {
436
458
  noExternal: true,
437
459
  external: ["react", "react-dom"],
438
460
  optimizeDeps: optimizeDepsNoRolldown
@@ -464,7 +486,12 @@ async function build(args) {
464
486
  // prevents it from shaking out the exports
465
487
  preserveEntrySignatures: "strict",
466
488
  input,
467
- external: [],
489
+ // in unified mode, inherit externals from serverBuildConfig (user
490
+ // ssr.external / rolldownOptions.external). the legacy path resets
491
+ // them to [] so per-route files bundle everything.
492
+ ...(isUnified ? {} : {
493
+ external: []
494
+ }),
468
495
  output: {
469
496
  entryFileNames: "[name]",
470
497
  exports: "auto",
@@ -519,7 +546,7 @@ async function build(args) {
519
546
  var _loop = function () {
520
547
  var middleware = _step.value;
521
548
  var absoluteRoot = (0, import_path.resolve)(process.cwd(), options.root);
522
- var fullPath = (0, import_path.join)(absoluteRoot, routerRoot, middleware.file);
549
+ var fullPath = (0, import_vite.normalizePath)((0, import_path.join)(absoluteRoot, routerRoot, middleware.file));
523
550
  var outChunks = middlewareBuildInfo.output.filter(function (x) {
524
551
  return x.type === "chunk";
525
552
  });
@@ -545,7 +572,7 @@ async function build(args) {
545
572
  }
546
573
  }
547
574
  }
548
- globalThis["require"] = (0, import_module.createRequire)((0, import_path.join)(import_meta.url, ".."));
575
+ globalThis["require"] = (0, import_module.createRequire)(import_meta.dirname + "/");
549
576
  var assets = [];
550
577
  var builtRoutes = [];
551
578
  var sitemapData = [];
@@ -614,7 +641,7 @@ async function build(args) {
614
641
  var id = output.facadeModuleId || "";
615
642
  var file = import_path.default.basename(id);
616
643
  if (file.startsWith("_layout") && id.includes(`/${routerRoot}/`)) {
617
- var relativePath = (0, import_path.relative)(process.cwd(), id).replace(`${routerRoot}/`, "");
644
+ var relativePath = (0, import_vite.normalizePath)((0, import_path.relative)(process.cwd(), id)).replace(`${routerRoot}/`, "");
618
645
  var contextKey = `./${relativePath}`;
619
646
  layoutServerPaths.set(contextKey, output.fileName);
620
647
  }
@@ -740,7 +767,7 @@ async function build(args) {
740
767
  if (!foundRoute.file) {
741
768
  return "continue";
742
769
  }
743
- var routeModulePath = (0, import_path.join)((0, import_path.resolve)(process.cwd(), options.root), routerRoot, foundRoute.file.slice(2));
770
+ var routeModulePath = (0, import_vite.normalizePath)((0, import_path.join)((0, import_path.resolve)(process.cwd(), options.root), routerRoot, foundRoute.file.slice(2)));
744
771
  var serverFileName = moduleIdToServerChunk.get(routeModulePath);
745
772
  if (!serverFileName) {
746
773
  if (foundRoute.type === "spa") {
@@ -971,7 +998,7 @@ async function build(args) {
971
998
  var serverJsPath = (0, import_path.join)(`${outDir}/server`, serverFileName);
972
999
  var exported = void 0;
973
1000
  try {
974
- exported = await import((0, import_toAbsolute.toAbsolute)(serverJsPath));
1001
+ exported = await import((0, import_toAbsolute.toAbsoluteUrl)(serverJsPath));
975
1002
  } catch (err) {
976
1003
  console.error(`Error importing page (original error)`, err);
977
1004
  throw new Error(`Error importing page: ${serverJsPath}`, {
@@ -1191,14 +1218,23 @@ async function build(args) {
1191
1218
  var buildInfo = builtRoutes.find(function (x) {
1192
1219
  return x.routeFile === route3.file;
1193
1220
  });
1194
- if (built.middlewares && (buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.middlewares)) {
1221
+ if (built.middlewares) {
1195
1222
  var _iteratorNormalCompletion13 = true,
1196
1223
  _didIteratorError13 = false,
1197
1224
  _iteratorError13 = void 0;
1198
1225
  try {
1199
1226
  for (var _iterator13 = built.middlewares.entries()[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
1200
1227
  var [index, mw] = _step13.value;
1201
- mw.contextKey = buildInfo.middlewares[index];
1228
+ var _buildInfo_middlewares;
1229
+ var viaBuildInfo = buildInfo === null || buildInfo === void 0 ? void 0 : (_buildInfo_middlewares = buildInfo.middlewares) === null || _buildInfo_middlewares === void 0 ? void 0 : _buildInfo_middlewares[index];
1230
+ if (viaBuildInfo) {
1231
+ mw.contextKey = viaBuildInfo;
1232
+ continue;
1233
+ }
1234
+ var viaMiddlewareMap = builtMiddlewares[mw.contextKey];
1235
+ if (viaMiddlewareMap) {
1236
+ mw.contextKey = viaMiddlewareMap;
1237
+ }
1202
1238
  }
1203
1239
  } catch (err) {
1204
1240
  _didIteratorError13 = true;
@@ -1288,6 +1324,11 @@ async function build(args) {
1288
1324
  }
1289
1325
  case "cloudflare":
1290
1326
  {
1327
+ var workerSrcDir = (0, import_path.join)(options.root, outDir);
1328
+ var getWorkerSourceImportPath = function (routeFile2) {
1329
+ var importPath3 = (0, import_vite.normalizePath)((0, import_path.relative)(workerSrcDir, (0, import_path.join)(options.root, routerRoot, routeFile2)));
1330
+ return importPath3.startsWith(".") ? importPath3 : `./${importPath3}`;
1331
+ };
1291
1332
  var pageRouteMap = [];
1292
1333
  var apiRouteMap = [];
1293
1334
  var middlewareRouteMap = [];
@@ -1323,8 +1364,7 @@ async function build(args) {
1323
1364
  for (var _iterator11 = buildInfoForWriting.manifest.apiRoutes[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
1324
1365
  var route2 = _step11.value;
1325
1366
  if (route2.file) {
1326
- var apiFileName = route2.page.slice(1).replace(/\[/g, "_").replace(/\]/g, "_");
1327
- var importPath1 = `./api/${apiFileName}.js`;
1367
+ var importPath1 = getWorkerSourceImportPath(route2.file);
1328
1368
  apiRouteMap.push(` '${route2.page}': () => import('${importPath1}')`);
1329
1369
  }
1330
1370
  }
@@ -1347,8 +1387,8 @@ async function build(args) {
1347
1387
  _iteratorError12 = void 0;
1348
1388
  try {
1349
1389
  for (var _iterator12 = Object.entries(builtMiddlewares)[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
1350
- var [, builtPath] = _step12.value;
1351
- var importPath2 = "./" + builtPath.replace(new RegExp(`^${outDir}/`), "");
1390
+ var [sourceFile, builtPath] = _step12.value;
1391
+ var importPath2 = getWorkerSourceImportPath(sourceFile);
1352
1392
  middlewareRouteMap.push(` '${builtPath}': () => import('${importPath2}')`);
1353
1393
  }
1354
1394
  } catch (err) {
@@ -1420,7 +1460,7 @@ export default {
1420
1460
  }
1421
1461
 
1422
1462
  try {
1423
- const response = await server.fetch(request)
1463
+ const response = await server.fetch(request, env, ctx)
1424
1464
 
1425
1465
  // no route matched or 404 \u2192 try static assets
1426
1466
  if (!response || response.status === 404) {
@@ -1444,38 +1484,34 @@ export default {
1444
1484
  }
1445
1485
  `;
1446
1486
  await import_fs_extra.default.writeFile(workerSrcPath, workerCode);
1487
+ var projectName = await getCloudflareProjectName(options.root);
1488
+ var userWranglerConfig = await loadUserWranglerConfig(options.root);
1489
+ var wranglerInputConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig === null || userWranglerConfig === void 0 ? void 0 : userWranglerConfig.config);
1490
+ wranglerInputConfig.main = (0, import_path.relative)((0, import_path.join)(options.root, outDir), workerSrcPath);
1491
+ var wranglerInputPath = (0, import_path.join)(options.root, outDir, "_wrangler.input.jsonc");
1492
+ await import_fs_extra.default.writeFile(wranglerInputPath, `${JSON.stringify(wranglerInputConfig, null, 2)}
1493
+ `);
1447
1494
  console.info("\n [cloudflare] Bundling worker...");
1448
- await (0, import_vite.build)({
1495
+ var {
1496
+ cloudflare
1497
+ } = await import("@cloudflare/vite-plugin");
1498
+ var builder = await (0, import_vite.createBuilder)({
1449
1499
  root: options.root,
1450
1500
  mode: "production",
1451
1501
  logLevel: "warn",
1452
- build: {
1453
- outDir,
1454
- emptyOutDir: false,
1455
- // Use SSR mode with node target for proper Node.js module resolution
1456
- ssr: workerSrcPath,
1457
- rolldownOptions: {
1458
- external: [
1459
- // React Native dev tools - not needed in production
1460
- "@react-native/dev-middleware", "@react-native/debugger-shell", "metro", "metro-core", "metro-runtime",
1461
- // Native modules that can't run in workers
1462
- /\.node$/],
1463
- output: {
1464
- entryFileNames: "worker.js",
1465
- format: "es",
1466
- // Keep dynamic imports separate for lazy loading
1467
- inlineDynamicImports: false
1468
- }
1469
- },
1470
- minify: true,
1471
- target: "esnext"
1472
- },
1502
+ configFile: false,
1473
1503
  define: {
1474
1504
  "process.env.NODE_ENV": JSON.stringify("production"),
1475
- "process.env.VITE_ENVIRONMENT": JSON.stringify("ssr")
1505
+ "process.env.VITE_ENVIRONMENT": JSON.stringify("ssr"),
1506
+ "process.env.ONE_CACHE_KEY": JSON.stringify(constants.CACHE_KEY)
1476
1507
  },
1508
+ plugins: [cloudflare({
1509
+ configPath: wranglerInputPath,
1510
+ viteEnvironment: {
1511
+ name: "worker"
1512
+ }
1513
+ })],
1477
1514
  resolve: {
1478
- conditions: ["workerd", "worker", "node", "module", "default"],
1479
1515
  alias: [
1480
1516
  // rolldown can't parse react-native's Flow syntax; alias to react-native-web for ssr
1481
1517
  {
@@ -1492,26 +1528,33 @@ export default {
1492
1528
  replacement: (0, import_resolve.resolvePath)("@vxrn/safe-area", options.root)
1493
1529
  }]
1494
1530
  },
1495
- ssr: {
1496
- target: "node",
1497
- noExternal: true
1531
+ build: {
1532
+ outDir,
1533
+ emptyOutDir: false,
1534
+ rolldownOptions: {
1535
+ // Match the main web build behavior so RN packages that import
1536
+ // native-only symbols from react-native can still bundle against
1537
+ // the react-native-web alias in the worker graph.
1538
+ shimMissingExports: true
1539
+ }
1498
1540
  }
1499
1541
  });
1542
+ var workerEnv = builder.environments.worker;
1543
+ if (!workerEnv) {
1544
+ throw new Error('[one] plugin did not register "worker" environment');
1545
+ }
1546
+ await builder.build(workerEnv);
1500
1547
  await import_fs_extra.default.remove(workerSrcPath);
1501
- var projectName = await getCloudflareProjectName(options.root);
1502
- var userWranglerConfig = await loadUserWranglerConfig(options.root);
1503
- var wranglerConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig === null || userWranglerConfig === void 0 ? void 0 : userWranglerConfig.config);
1548
+ await import_fs_extra.default.remove(wranglerInputPath);
1504
1549
  if (userWranglerConfig) {
1505
- console.info(` [cloudflare] Merging ${(0, import_path.relative)(options.root, userWranglerConfig.path)} into ${outDir}/wrangler.jsonc`);
1550
+ console.info(` [cloudflare] Merging ${(0, import_path.relative)(options.root, userWranglerConfig.path)} into ${outDir}/worker/wrangler.json`);
1506
1551
  }
1507
- await import_fs_extra.default.writeFile((0, import_path.join)(options.root, outDir, "wrangler.jsonc"), `${JSON.stringify(wranglerConfig, null, 2)}
1508
- `);
1509
- postBuildLogs.push(`Cloudflare worker bundled at ${outDir}/worker.js`);
1510
- postBuildLogs.push(`To deploy: cd ${outDir} && wrangler deploy`);
1552
+ postBuildLogs.push(`Cloudflare worker bundled at ${outDir}/worker/index.js`);
1553
+ postBuildLogs.push(`To deploy: cd ${outDir}/worker && wrangler deploy`);
1511
1554
  break;
1512
1555
  }
1513
1556
  }
1514
- var securityScanOption = (_oneOptions_build3 = oneOptions.build) === null || _oneOptions_build3 === void 0 ? void 0 : _oneOptions_build3.securityScan;
1557
+ var securityScanOption = (_oneOptions_build4 = oneOptions.build) === null || _oneOptions_build4 === void 0 ? void 0 : _oneOptions_build4.securityScan;
1515
1558
  var securityScanLevel = securityScanOption === false ? null : securityScanOption === true || securityScanOption === void 0 ? "warn" : typeof securityScanOption === "string" ? securityScanOption : (_securityScanOption_level = securityScanOption.level) !== null && _securityScanOption_level !== void 0 ? _securityScanOption_level : "warn";
1516
1559
  var securitySafePatterns = (typeof securityScanOption === "undefined" ? "undefined" : _type_of(securityScanOption)) === "object" && securityScanOption !== null ? securityScanOption.safePatterns : void 0;
1517
1560
  if (securityScanLevel) {