vite-plugin-react-server 1.1.9 → 1.1.11

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 (415) hide show
  1. package/README.md +208 -27
  2. package/dist/index.js.map +1 -1
  3. package/dist/package.json +34 -14
  4. package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
  5. package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
  6. package/dist/plugin/components/css-collector-elements.js.map +1 -0
  7. package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
  8. package/dist/plugin/components/css-collector.d.ts.map +1 -0
  9. package/dist/plugin/components/css-collector.js.map +1 -0
  10. package/dist/plugin/components/html.d.ts +4 -0
  11. package/dist/plugin/components/html.d.ts.map +1 -0
  12. package/dist/plugin/components/html.js +17 -0
  13. package/dist/plugin/components/html.js.map +1 -0
  14. package/dist/plugin/components/index.d.ts +5 -0
  15. package/dist/plugin/components/index.d.ts.map +1 -0
  16. package/dist/plugin/components.js +9 -3
  17. package/dist/plugin/components.js.map +1 -0
  18. package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
  19. package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
  20. package/dist/plugin/config/autoDiscover/index.js +8 -0
  21. package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
  22. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
  23. package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
  24. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
  25. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
  26. package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
  27. package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
  28. package/dist/plugin/config/defaults.d.ts +6 -4
  29. package/dist/plugin/config/defaults.d.ts.map +1 -1
  30. package/dist/plugin/config/defaults.js +8 -4
  31. package/dist/plugin/config/defaults.js.map +1 -1
  32. package/dist/plugin/config/index.d.ts +1 -0
  33. package/dist/plugin/config/index.d.ts.map +1 -1
  34. package/dist/plugin/config/index.js +1 -0
  35. package/dist/plugin/config/resolveDevServerConfig.d.ts +2 -0
  36. package/dist/plugin/config/resolveDevServerConfig.d.ts.map +1 -0
  37. package/dist/plugin/config/resolveEnv.d.ts +13 -0
  38. package/dist/plugin/config/resolveEnv.d.ts.map +1 -0
  39. package/dist/plugin/config/resolveEnv.js +120 -0
  40. package/dist/plugin/config/resolveEnv.js.map +1 -0
  41. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  42. package/dist/plugin/config/resolveOptions.js +34 -11
  43. package/dist/plugin/config/resolveOptions.js.map +1 -1
  44. package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
  45. package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
  46. package/dist/plugin/config/resolveUrlOption.js +1 -2
  47. package/dist/plugin/config/resolveUrlOption.js.map +1 -1
  48. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  49. package/dist/plugin/config/resolveUserConfig.js +80 -69
  50. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  51. package/dist/plugin/config.js +17 -0
  52. package/dist/plugin/config.js.map +1 -0
  53. package/dist/plugin/env/index.d.ts +2 -0
  54. package/dist/plugin/env/index.d.ts.map +1 -0
  55. package/dist/plugin/env/index.js +1 -0
  56. package/dist/plugin/env/plugin.d.ts +30 -0
  57. package/dist/plugin/env/plugin.d.ts.map +1 -0
  58. package/dist/plugin/env/plugin.js +64 -0
  59. package/dist/plugin/env.js +45 -0
  60. package/dist/plugin/env.js.map +1 -0
  61. package/dist/plugin/error/toError.d.ts +6 -0
  62. package/dist/plugin/error/toError.d.ts.map +1 -0
  63. package/dist/plugin/error/toError.js +19 -0
  64. package/dist/plugin/error/toError.js.map +1 -0
  65. package/dist/plugin/file-preserver/plugin.d.ts +19 -0
  66. package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
  67. package/dist/plugin/file-preserver/plugin.js +108 -0
  68. package/dist/plugin/file-preserver.js +96 -0
  69. package/dist/plugin/file-preserver.js.map +1 -0
  70. package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
  71. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  72. package/dist/plugin/helpers/createCssProps.js +10 -2
  73. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  74. package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
  75. package/dist/plugin/helpers/createRscStream.js +1 -1
  76. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  77. package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
  78. package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
  79. package/dist/plugin/helpers/formatMetrics.js +22 -7
  80. package/dist/plugin/helpers/formatMetrics.js.map +1 -0
  81. package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
  82. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
  83. package/dist/plugin/helpers/getRouteFiles.js +2 -0
  84. package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
  85. package/dist/plugin/helpers/index.d.ts +24 -0
  86. package/dist/plugin/helpers/index.d.ts.map +1 -0
  87. package/dist/plugin/helpers/index.js +31 -0
  88. package/dist/plugin/helpers/inputNormalizer.d.ts +2 -1
  89. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  90. package/dist/plugin/helpers/inputNormalizer.js +34 -9
  91. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  92. package/dist/plugin/helpers/metrics.js +26 -2
  93. package/dist/plugin/helpers/metrics.js.map +1 -1
  94. package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
  95. package/dist/plugin/helpers/moduleRefs.js.map +1 -0
  96. package/dist/plugin/helpers/requestInfo.d.ts +26 -0
  97. package/dist/plugin/helpers/requestInfo.d.ts.map +1 -0
  98. package/dist/plugin/helpers/requestInfo.js +66 -0
  99. package/dist/plugin/helpers/requestInfo.js.map +1 -0
  100. package/dist/plugin/helpers/requestToRoute.js.map +1 -1
  101. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
  102. package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
  103. package/dist/plugin/helpers/resolvePage.js.map +1 -0
  104. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
  105. package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
  106. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
  107. package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
  108. package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
  109. package/dist/plugin/helpers/resolveProps.js.map +1 -0
  110. package/dist/plugin/helpers/serializeUserOptions.js +1 -1
  111. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
  112. package/dist/plugin/helpers/stashReturnValue.js +19 -13
  113. package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
  114. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  115. package/dist/plugin/helpers/tryManifest.js +0 -1
  116. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  117. package/dist/plugin/helpers.js +27 -0
  118. package/dist/plugin/helpers.js.map +1 -0
  119. package/dist/plugin/loader/createBuildLoader.js +1 -1
  120. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  121. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
  122. package/dist/plugin/loader/css-loader.development.js +1 -7
  123. package/dist/plugin/loader/css-loader.development.js.map +1 -1
  124. package/dist/plugin/loader/css-loader.production.js.map +1 -1
  125. package/dist/plugin/loader/env-loader.development.d.ts +12 -0
  126. package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
  127. package/dist/plugin/loader/env-loader.development.js +60 -0
  128. package/dist/plugin/loader/react-loader.d.ts.map +1 -1
  129. package/dist/plugin/loader/react-loader.js +1 -8
  130. package/dist/plugin/loader/react-loader.js.map +1 -1
  131. package/dist/plugin/metrics/formatMetrics.d.ts +6 -1
  132. package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
  133. package/dist/plugin/metrics/formatMetrics.js +21 -3
  134. package/dist/plugin/metrics/formatMetrics.js.map +1 -1
  135. package/dist/plugin/metrics.js +1 -1
  136. package/dist/plugin/plugin.client.d.ts.map +1 -1
  137. package/dist/plugin/plugin.client.js +2 -0
  138. package/dist/plugin/plugin.client.js.map +1 -1
  139. package/dist/plugin/plugin.d.ts.map +1 -1
  140. package/dist/plugin/plugin.js +1 -2
  141. package/dist/plugin/plugin.server.d.ts.map +1 -1
  142. package/dist/plugin/plugin.server.js +3 -0
  143. package/dist/plugin/plugin.server.js.map +1 -1
  144. package/dist/plugin/preserver/plugin.js.map +1 -1
  145. package/dist/plugin/process-env.d.ts +14 -0
  146. package/dist/plugin/process-env.d.ts.map +1 -0
  147. package/dist/plugin/process-env.js +1 -0
  148. package/dist/plugin/react-client/createMessageHandlers.d.ts +11 -0
  149. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -0
  150. package/dist/plugin/react-client/createMessageHandlers.js +47 -0
  151. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -0
  152. package/dist/plugin/react-client/createWorkerStream.d.ts +9 -3
  153. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  154. package/dist/plugin/react-client/createWorkerStream.js +102 -70
  155. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  156. package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
  157. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
  158. package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
  159. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
  160. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  161. package/dist/plugin/react-client/plugin.js +19 -5
  162. package/dist/plugin/react-client/plugin.js.map +1 -1
  163. package/dist/plugin/react-client/restartWorker.d.ts +6 -1
  164. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  165. package/dist/plugin/react-client/restartWorker.js +13 -5
  166. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  167. package/dist/plugin/react-client/server.d.ts +2 -13
  168. package/dist/plugin/react-client/server.d.ts.map +1 -1
  169. package/dist/plugin/react-client/server.js +123 -121
  170. package/dist/plugin/react-client/server.js.map +1 -1
  171. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  172. package/dist/plugin/react-server/plugin.js +18 -8
  173. package/dist/plugin/react-server/plugin.js.map +1 -1
  174. package/dist/plugin/react-server/server.d.ts.map +1 -1
  175. package/dist/plugin/react-server/server.js +37 -23
  176. package/dist/plugin/react-server/server.js.map +1 -1
  177. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
  178. package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
  179. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
  180. package/dist/plugin/react-static/collectRscContent.js.map +1 -1
  181. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
  182. package/dist/plugin/react-static/configurePreviewServer.js +58 -54
  183. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
  184. package/dist/plugin/react-static/fileWriter.d.ts +1 -1
  185. package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
  186. package/dist/plugin/react-static/fileWriter.js.map +1 -1
  187. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  188. package/dist/plugin/react-static/plugin.js +21 -23
  189. package/dist/plugin/react-static/plugin.js.map +1 -1
  190. package/dist/plugin/react-static/renderPages.js.map +1 -1
  191. package/dist/plugin/root.d.ts +1 -0
  192. package/dist/plugin/root.d.ts.map +1 -1
  193. package/dist/plugin/root.js +3 -2
  194. package/dist/plugin/root.js.map +1 -1
  195. package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
  196. package/dist/plugin/transformer/plugin.client.js +3 -12
  197. package/dist/plugin/transformer/plugin.client.js.map +1 -1
  198. package/dist/plugin/transformer/plugin.js.map +1 -1
  199. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
  200. package/dist/plugin/transformer/plugin.server.js +17 -24
  201. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  202. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
  203. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
  204. package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
  205. package/dist/plugin/types.d.ts +60 -15
  206. package/dist/plugin/types.d.ts.map +1 -1
  207. package/dist/plugin/types.js +1 -1
  208. package/dist/plugin/utils/callServer.d.ts +1 -1
  209. package/dist/plugin/utils/callServer.d.ts.map +1 -1
  210. package/dist/plugin/utils/callServer.js +3 -17
  211. package/dist/plugin/utils/callServer.js.map +1 -1
  212. package/dist/plugin/utils/createCallServer.d.ts +2 -0
  213. package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
  214. package/dist/plugin/utils/createCallServer.js +28 -0
  215. package/dist/plugin/utils/createCallServer.js.map +1 -0
  216. package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
  217. package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
  218. package/dist/plugin/utils/createReactFetcher.js +11 -11
  219. package/dist/plugin/utils/createReactFetcher.js.map +1 -1
  220. package/dist/plugin/utils/env.d.ts +2 -0
  221. package/dist/plugin/utils/env.d.ts.map +1 -0
  222. package/dist/plugin/utils/env.js +9 -0
  223. package/dist/plugin/utils/env.js.map +1 -0
  224. package/dist/plugin/utils/envUrls.d.ts +9 -0
  225. package/dist/plugin/utils/envUrls.d.ts.map +1 -0
  226. package/dist/plugin/utils/envUrls.js +7 -0
  227. package/dist/plugin/utils/envUrls.node.d.ts +7 -0
  228. package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
  229. package/dist/plugin/utils/envUrls.node.js +11 -0
  230. package/dist/plugin/utils/envUrls.node.js.map +1 -0
  231. package/dist/plugin/utils/index.d.ts +2 -1
  232. package/dist/plugin/utils/index.d.ts.map +1 -1
  233. package/dist/plugin/utils/index.js +2 -1
  234. package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
  235. package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
  236. package/dist/plugin/utils/moduleBaseURL.js +4 -0
  237. package/dist/plugin/utils/urls.d.ts +130 -0
  238. package/dist/plugin/utils/urls.d.ts.map +1 -0
  239. package/dist/plugin/utils/urls.js +87 -0
  240. package/dist/plugin/utils/urls.js.map +1 -0
  241. package/dist/plugin/utils.js +2 -1
  242. package/dist/plugin/utils.js.map +1 -1
  243. package/dist/plugin/vendor/index.d.ts +2 -0
  244. package/dist/plugin/vendor/index.d.ts.map +1 -0
  245. package/dist/plugin/vendor/index.js +1 -0
  246. package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
  247. package/dist/plugin/vendor/vendor.client.js.map +1 -0
  248. package/dist/plugin/vendor/vendor.d.ts +2 -0
  249. package/dist/plugin/vendor/vendor.d.ts.map +1 -0
  250. package/dist/plugin/vendor/vendor.js +15 -0
  251. package/dist/plugin/vendor/vendor.js.map +1 -0
  252. package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
  253. package/dist/plugin/vendor/vendor.server.js.map +1 -0
  254. package/dist/plugin/vendor.js +7 -0
  255. package/dist/plugin/vendor.js.map +1 -0
  256. package/dist/plugin/worker/createWorker.d.ts +3 -0
  257. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  258. package/dist/plugin/worker/createWorker.js +37 -23
  259. package/dist/plugin/worker/createWorker.js.map +1 -1
  260. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
  261. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +4 -1
  262. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
  263. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  264. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  265. package/dist/plugin/worker/rsc/handleRender.d.ts +2 -7
  266. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  267. package/dist/plugin/worker/rsc/handleRender.js +4 -4
  268. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  269. package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
  270. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  271. package/dist/plugin/worker/rsc/messageHandler.js +42 -16
  272. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  273. package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
  274. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  275. package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
  276. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  277. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  278. package/dist/plugin/worker/rsc/state.js.map +1 -1
  279. package/dist/plugin/worker/sendMessage.js +45 -43
  280. package/dist/plugin/worker/sendMessage.js.map +1 -0
  281. package/dist/plugin/worker/types.d.ts +32 -4
  282. package/dist/plugin/worker/types.d.ts.map +1 -1
  283. package/dist/server.js +1 -1
  284. package/dist/server.js.map +1 -1
  285. package/dist/tsconfig.tsbuildinfo +1 -1
  286. package/package.json +34 -14
  287. package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
  288. package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
  289. package/plugin/{html.tsx → components/html.tsx} +1 -3
  290. package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
  291. package/plugin/config/autoDiscover/index.ts +10 -0
  292. package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
  293. package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
  294. package/plugin/config/defaults.tsx +6 -4
  295. package/plugin/config/index.ts +1 -1
  296. package/plugin/config/resolveEnv.ts +187 -0
  297. package/plugin/config/resolveOptions.ts +60 -27
  298. package/plugin/config/resolveUrlOption.ts +2 -7
  299. package/plugin/config/resolveUserConfig.ts +145 -98
  300. package/plugin/env/index.ts +1 -0
  301. package/plugin/env/plugin.ts +78 -0
  302. package/plugin/error/toError.ts +19 -0
  303. package/plugin/file-preserver/plugin.ts +117 -0
  304. package/plugin/helpers/createCssProps.tsx +14 -6
  305. package/plugin/helpers/createRscStream.tsx +1 -1
  306. package/plugin/helpers/formatMetrics.ts +2 -2
  307. package/plugin/helpers/getRouteFiles.ts +3 -1
  308. package/plugin/helpers/index.ts +38 -0
  309. package/plugin/helpers/inputNormalizer.ts +66 -17
  310. package/plugin/helpers/requestInfo.ts +91 -0
  311. package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
  312. package/plugin/helpers/resolvePageAndProps.ts +7 -4
  313. package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
  314. package/plugin/helpers/serializeUserOptions.ts +1 -1
  315. package/plugin/helpers/tryManifest.ts +0 -1
  316. package/plugin/loader/createBuildLoader.ts +1 -1
  317. package/plugin/loader/css-loader.development.ts +2 -8
  318. package/plugin/loader/env-loader.development.ts +84 -0
  319. package/plugin/loader/react-loader.ts +1 -10
  320. package/plugin/metrics/formatMetrics.ts +29 -4
  321. package/plugin/plugin.client.ts +2 -0
  322. package/plugin/plugin.server.ts +3 -0
  323. package/plugin/plugin.ts +1 -3
  324. package/plugin/preserver/plugin.ts +1 -0
  325. package/plugin/process-env.ts +13 -0
  326. package/plugin/react-client/createMessageHandlers.ts +49 -0
  327. package/plugin/react-client/createWorkerStream.ts +130 -83
  328. package/plugin/react-client/handleWorkerRscStream.ts +57 -0
  329. package/plugin/react-client/plugin.ts +30 -17
  330. package/plugin/react-client/restartWorker.ts +15 -7
  331. package/plugin/react-client/server.ts +129 -164
  332. package/plugin/react-server/plugin.ts +26 -13
  333. package/plugin/react-server/server.ts +40 -35
  334. package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
  335. package/plugin/react-static/configurePreviewServer.ts +75 -62
  336. package/plugin/react-static/fileWriter.ts +1 -1
  337. package/plugin/react-static/plugin.ts +23 -30
  338. package/plugin/root.ts +7 -1
  339. package/plugin/transformer/plugin.client.ts +4 -12
  340. package/plugin/transformer/plugin.server.ts +18 -25
  341. package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
  342. package/plugin/types/env.d.ts +7 -0
  343. package/plugin/types.ts +80 -29
  344. package/plugin/utils/callServer.ts +3 -24
  345. package/plugin/utils/createCallServer.ts +26 -0
  346. package/plugin/utils/createReactFetcher.ts +14 -12
  347. package/plugin/utils/env.ts +1 -0
  348. package/plugin/utils/envUrls.node.ts +19 -0
  349. package/plugin/utils/envUrls.ts +8 -0
  350. package/plugin/utils/index.ts +2 -1
  351. package/plugin/utils/moduleBaseURL.ts +7 -0
  352. package/plugin/utils/urls.ts +217 -0
  353. package/plugin/vendor/index.ts +1 -0
  354. package/plugin/vendor/vendor.ts +6 -0
  355. package/plugin/worker/createWorker.ts +41 -30
  356. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +4 -1
  357. package/plugin/worker/html/html-worker.development.tsx +2 -1
  358. package/plugin/worker/html/html-worker.production.tsx +2 -1
  359. package/plugin/worker/rsc/handleRender.ts +6 -12
  360. package/plugin/worker/rsc/messageHandler.tsx +53 -20
  361. package/plugin/worker/rsc/rsc-worker.development.ts +23 -9
  362. package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
  363. package/plugin/worker/types.ts +35 -4
  364. package/dist/plugin/components.d.ts.map +0 -1
  365. package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
  366. package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
  367. package/dist/plugin/copy.d.ts +0 -7
  368. package/dist/plugin/copy.d.ts.map +0 -1
  369. package/dist/plugin/copy.js +0 -30
  370. package/dist/plugin/css-collector-elements.d.ts.map +0 -1
  371. package/dist/plugin/css-collector-elements.js.map +0 -1
  372. package/dist/plugin/css-collector.d.ts.map +0 -1
  373. package/dist/plugin/css-collector.js.map +0 -1
  374. package/dist/plugin/getCondition.d.ts +0 -2
  375. package/dist/plugin/getCondition.d.ts.map +0 -1
  376. package/dist/plugin/html.d.ts +0 -4
  377. package/dist/plugin/html.d.ts.map +0 -1
  378. package/dist/plugin/html.js +0 -18
  379. package/dist/plugin/html.js.map +0 -1
  380. package/dist/plugin/manifest.d.ts +0 -6
  381. package/dist/plugin/manifest.d.ts.map +0 -1
  382. package/dist/plugin/manifest.js +0 -13
  383. package/dist/plugin/moduleRefs.d.ts.map +0 -1
  384. package/dist/plugin/moduleRefs.js.map +0 -1
  385. package/dist/plugin/resolvePage.d.ts.map +0 -1
  386. package/dist/plugin/resolvePage.js.map +0 -1
  387. package/dist/plugin/resolveProps.d.ts.map +0 -1
  388. package/dist/plugin/resolveProps.js.map +0 -1
  389. package/dist/plugin/utils/pageURL.d.ts +0 -2
  390. package/dist/plugin/utils/pageURL.d.ts.map +0 -1
  391. package/dist/plugin/utils/pageURL.js +0 -21
  392. package/dist/plugin/utils/pageURL.js.map +0 -1
  393. package/dist/plugin/vendor.client.d.ts.map +0 -1
  394. package/dist/plugin/vendor.client.js.map +0 -1
  395. package/dist/plugin/vendor.server.d.ts.map +0 -1
  396. package/dist/plugin/vendor.server.js.map +0 -1
  397. package/plugin/copy.ts +0 -39
  398. package/plugin/manifest.ts +0 -24
  399. package/plugin/utils/pageURL.ts +0 -28
  400. /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
  401. /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
  402. /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
  403. /package/dist/plugin/{getCondition.js → config/resolveDevServerConfig.js} +0 -0
  404. /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
  405. /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
  406. /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
  407. /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
  408. /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
  409. /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
  410. /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
  411. /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
  412. /package/plugin/{getCondition.ts → config/resolveDevServerConfig.tsx} +0 -0
  413. /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
  414. /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
  415. /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { normalizePath } from "vite";
2
2
  import type { InputNormalizer, NormalizerInput } from "../types.js";
3
- import path, { join } from "path";
3
+ import path, { join, sep } from "path";
4
4
  import { DEFAULT_CONFIG } from "../config/defaults.js";
5
5
 
6
6
  let stashedNormalizer: InputNormalizer | null = null;
@@ -9,6 +9,7 @@ type CreateInputNormalizerProps = {
9
9
  root: string;
10
10
  preserveModulesRoot?: string | undefined;
11
11
  removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
12
+ moduleBasePath?: string | undefined;
12
13
  };
13
14
 
14
15
  const resolveExtensionOptions = (
@@ -55,7 +56,10 @@ const resolveRootOption = (
55
56
  return normalizedPreserveModulesRoot.slice(root.length + 1);
56
57
  }
57
58
  return "";
58
- } else if (typeof preserveModulesRoot === "string" && typeof root !== "string") {
59
+ } else if (
60
+ typeof preserveModulesRoot === "string" &&
61
+ typeof root !== "string"
62
+ ) {
59
63
  return normalizePath(preserveModulesRoot);
60
64
  }
61
65
  return "";
@@ -65,23 +69,43 @@ const createKeyNormalizer =
65
69
  root: normalizedRoot,
66
70
  preserveModulesRoot,
67
71
  handleExtension,
72
+ moduleBasePath,
68
73
  }: {
69
74
  root: string;
70
75
  preserveModulesRoot: string | undefined;
71
76
  handleExtension: (path: string) => string;
77
+ moduleBasePath: string | undefined;
72
78
  }) =>
73
79
  (key: string) => {
80
+ if (key.includes("?")) {
81
+ key = key.split("?")[0];
82
+ }
83
+
74
84
  // Handle virtual modules first
75
- const virtualPrefix = key.match(/^\0+/)?.[0] || '';
76
- const actualKey = key.slice(virtualPrefix.length);
77
-
85
+ const virtualPrefix = key.match(/^\0+/) ?? "";
86
+ const actualKey = virtualPrefix ? key.slice(virtualPrefix[0].length) : key;
87
+
78
88
  let moduleId = normalizePath(actualKey);
79
-
89
+
80
90
  // Normalize root path to handle both absolute and relative paths
81
91
  const normalizedRootPath = normalizePath(normalizedRoot);
82
92
  if (moduleId.startsWith(normalizedRootPath)) {
83
93
  moduleId = moduleId.slice(normalizedRootPath.length);
84
94
  }
95
+ if (
96
+ typeof moduleBasePath === "string" &&
97
+ moduleBasePath !== "" &&
98
+ moduleBasePath !== "/"
99
+ ) {
100
+ moduleId = moduleId.startsWith(
101
+ moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
102
+ )
103
+ ? moduleId.slice(
104
+ moduleBasePath.length +
105
+ (moduleBasePath.endsWith(sep) ? 0 : sep.length)
106
+ )
107
+ : moduleId;
108
+ }
85
109
 
86
110
  moduleId = handleExtension(moduleId);
87
111
  while (moduleId.startsWith("/") || moduleId.startsWith(".")) {
@@ -95,7 +119,7 @@ const createKeyNormalizer =
95
119
  ? moduleId.slice(preserveModulesRoot.length + path.sep.length)
96
120
  : moduleId;
97
121
  }
98
-
122
+
99
123
  // Add virtual prefix back
100
124
  return virtualPrefix + moduleId;
101
125
  };
@@ -104,18 +128,37 @@ const createPathNormalizer =
104
128
  ({
105
129
  root,
106
130
  preserveModulesRoot,
131
+ moduleBasePath,
107
132
  }: {
108
133
  root: string;
109
134
  preserveModulesRoot: string | undefined;
135
+ moduleBasePath: string | undefined;
110
136
  }) =>
111
137
  (path: string) => {
112
138
  if (typeof path !== "string") {
113
139
  throw new Error(`Invalid path: ${JSON.stringify(path)}`);
114
140
  }
141
+ if (path.includes("?")) {
142
+ path = path.split("?")[0];
143
+ }
115
144
  let normalPath = normalizePath(path);
116
- if(normalPath.startsWith(root)) {
145
+ if (normalPath.startsWith(root)) {
117
146
  normalPath = normalPath.slice(root.length);
118
147
  }
148
+ if (
149
+ typeof moduleBasePath === "string" &&
150
+ moduleBasePath !== "" &&
151
+ moduleBasePath !== "/"
152
+ ) {
153
+ normalPath = normalPath.startsWith(
154
+ moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
155
+ )
156
+ ? normalPath.slice(
157
+ moduleBasePath.length +
158
+ (moduleBasePath.endsWith(sep) ? 0 : sep.length)
159
+ )
160
+ : normalPath;
161
+ }
119
162
  if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
120
163
  normalPath = normalPath.startsWith(preserveModulesRoot)
121
164
  ? normalPath.slice(preserveModulesRoot.length)
@@ -135,10 +178,11 @@ const createPathNormalizer =
135
178
  */
136
179
  export function createInputNormalizer({
137
180
  root,
181
+ moduleBasePath,
138
182
  preserveModulesRoot = undefined,
139
183
  removeExtension = DEFAULT_CONFIG.MODULE_EXTENSION,
140
184
  }: CreateInputNormalizerProps): InputNormalizer {
141
- if(stashedNormalizer) {
185
+ if (stashedNormalizer) {
142
186
  return stashedNormalizer;
143
187
  }
144
188
  const relativeRoot = resolveRootOption(root, preserveModulesRoot);
@@ -147,10 +191,12 @@ export function createInputNormalizer({
147
191
  root: root,
148
192
  preserveModulesRoot: preserveModulesRoot,
149
193
  handleExtension,
194
+ moduleBasePath,
150
195
  });
151
196
  const normalizeEntryPath = createPathNormalizer({
152
197
  root: root,
153
198
  preserveModulesRoot: relativeRoot,
199
+ moduleBasePath,
154
200
  });
155
201
  function normalizeInput(id: NormalizerInput): [string, string] {
156
202
  // Normalize both paths to use POSIX separators
@@ -185,19 +231,22 @@ export function createInputNormalizer({
185
231
  return normalized;
186
232
  }
187
233
  throw new Error(`Invalid input type: ${typeof id}`);
188
- };
234
+ }
189
235
 
190
236
  stashedNormalizer = (input: NormalizerInput): [string, string] => {
191
237
  const [key, path] = normalizeInput(input);
192
238
  // Apply the same normalization to both key and path
193
- const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
194
- const virtualPrefix = key.match(/^\0+/)?.[0] || '';
195
-
239
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
240
+ const virtualPrefix = key.match(/^\0+/) ?? "";
196
241
  // If key has virtual prefix, ensure path has it too
197
- const finalPath = virtualPrefix ?
198
- (normalizedPath.startsWith(virtualPrefix) ? normalizedPath : virtualPrefix + normalizedPath) :
199
- normalizedPath;
200
-
242
+ const finalPath = virtualPrefix
243
+ ? virtualPrefix.length && normalizedPath.startsWith(virtualPrefix[0])
244
+ ? normalizedPath
245
+ : virtualPrefix.length
246
+ ? virtualPrefix[0] + normalizedPath
247
+ : normalizedPath
248
+ : normalizedPath;
249
+
201
250
  return [key, finalPath];
202
251
  };
203
252
  return stashedNormalizer;
@@ -0,0 +1,91 @@
1
+ import { join } from "node:path";
2
+ import type { ResolvedUserOptions } from "../types.js";
3
+ import type { Connect } from "vite";
4
+ import { MIME_TYPES } from "../config/mimeTypes.js";
5
+
6
+ /**
7
+ * # Request info
8
+ *
9
+ * Does the initial work to check if the request is for html, rsc, css, or something else not handled by this plugin.
10
+ *
11
+ * @param req
12
+ * @param userOptions
13
+ * @param hostDir
14
+ * @returns
15
+ */
16
+ export function requestInfo(
17
+ req: Connect.IncomingMessage,
18
+ userOptions: Pick<ResolvedUserOptions, "normalizer" | "build" | "autoDiscover">,
19
+ hostDir: string
20
+ ) {
21
+ const [, value] = userOptions.normalizer(req.url);
22
+ const dotIndex = value.lastIndexOf(".");
23
+ const ext = dotIndex === -1 ? "" : value.slice(dotIndex);
24
+ // handle index.html
25
+ const isHtml = userOptions.autoDiscover.htmlPattern(value);
26
+ const hasHtmlHeader = req.headers.accept?.includes("text/html");
27
+ const isRsc = userOptions.autoDiscover.rscPattern(value);
28
+ const hasRscHeader = req.headers.accept?.includes("text/x-component");
29
+ const isFolder = !ext;
30
+ const isHtmlRequest =
31
+ isHtml || hasHtmlHeader || (isFolder && !hasRscHeader && !isRsc);
32
+ const isRscRequest = !isHtmlRequest && (isRsc || hasRscHeader);
33
+ const isCss = userOptions.autoDiscover.cssPattern(value);
34
+ const isCssRequest =
35
+ !isHtmlRequest &&
36
+ !isRscRequest &&
37
+ (isCss || req.headers.accept?.includes("text/css"));
38
+ let filePath = join(hostDir, value);
39
+ let contentType;
40
+ if (isHtmlRequest) {
41
+ if (!isHtml) {
42
+ filePath = join(hostDir, value, userOptions.build.htmlOutputPath);
43
+ }
44
+ contentType = "text/html; charset=utf-8";
45
+ } else if (isRscRequest) {
46
+ if (!isRsc) {
47
+ filePath = join(hostDir, value, userOptions.build.rscOutputPath);
48
+ }
49
+ contentType = "text/x-component; charset=utf-8";
50
+ } else if (isCssRequest) {
51
+ if (!isCss) {
52
+ filePath = join(hostDir, value);
53
+ }
54
+ contentType = "text/css; charset=utf-8";
55
+ } else {
56
+ const mimeType = MIME_TYPES[ext];
57
+ if (mimeType) {
58
+ contentType = mimeType;
59
+ } else {
60
+ contentType = "application/octet-stream";
61
+ }
62
+ }
63
+ const route = value
64
+ .replace(userOptions.build.rscOutputPath, "")
65
+ .replace(userOptions.build.htmlOutputPath, "");
66
+
67
+ const routeWithoutTrailingSlash =
68
+ route === "" || route === "/"
69
+ ? "/"
70
+ : route.endsWith("/")
71
+ ? route.slice(0, -1)
72
+ : route;
73
+ const routeWithLeadingSlash =
74
+ routeWithoutTrailingSlash.startsWith("/")
75
+ ? routeWithoutTrailingSlash
76
+ : `/${routeWithoutTrailingSlash}`;
77
+
78
+ return {
79
+ route: routeWithLeadingSlash,
80
+ ext,
81
+ isHtmlRequest,
82
+ isRscRequest,
83
+ isCssRequest,
84
+ isCss,
85
+ isHtml,
86
+ isRsc,
87
+ isFolder,
88
+ contentType,
89
+ filePath,
90
+ };
91
+ }
@@ -1,3 +1,4 @@
1
+ import { toError } from "../error/toError.js";
1
2
 
2
3
  type ResolvePageOptions<N extends string> = {
3
4
  id: string;
@@ -16,7 +17,7 @@ type ResolvePageResult<T, N extends string> =
16
17
  * During development (ssrLoadModule):
17
18
  * - Real modules have exports available directly on the module object
18
19
  * - Virtual modules have exports stored in temporaryReferences
19
- *
20
+ *
20
21
  * @param options.id - The module ID to resolve
21
22
  * @param options.exportName - The name of the export to resolve (e.g. 'Page')
22
23
  * @param options.loader - The loader function to use for loading the module
@@ -58,17 +59,31 @@ export const resolvePage = async <T, N extends string>({
58
59
  if (module instanceof Error) {
59
60
  return {
60
61
  type: "error",
61
- error: module,
62
+ error: {
63
+ name: module.name,
64
+ message: module.message,
65
+ stack: module.stack,
66
+ },
62
67
  };
63
68
  } else if (!(exportName in module)) {
69
+ if ("error" in module) {
70
+ return {
71
+ type: "error",
72
+ error: toError(module.error),
73
+ };
74
+ }
64
75
  return {
65
76
  type: "error",
66
- error: new Error(`Export ${exportName} not found in module ${id}`),
77
+ error: new Error(
78
+ `Export "${exportName}" not found in module ${id}.`
79
+ ),
67
80
  };
68
81
  } else if (!Page) {
69
82
  return {
70
83
  type: "error",
71
- error: new Error(`Export ${exportName} is null or undefined in module ${id}`),
84
+ error: new Error(
85
+ `Export "${exportName}" is null or undefined in module ${id}.`
86
+ ),
72
87
  };
73
88
  } else if (Page instanceof Error) {
74
89
  return {
@@ -1,5 +1,5 @@
1
- import { resolvePage } from "../resolvePage.js";
2
- import { resolveProps } from "../resolveProps.js";
1
+ import { resolvePage } from "./resolvePage.js";
2
+ import { resolveProps } from "./resolveProps.js";
3
3
 
4
4
  type ResolvePageAndPropsOptions<N1 extends string, N2 extends string> = {
5
5
  pagePath: string;
@@ -52,8 +52,11 @@ export async function resolvePageAndProps<
52
52
  ? handlerOptions.loader
53
53
  : async () => {
54
54
  const resolvePageResult = await resolvePagePromise;
55
- if (resolvePageResult.type != "success") {
56
- return resolvePageResult;
55
+ if (resolvePageResult.type === "error") {
56
+ return resolvePageResult.error
57
+ }
58
+ if (resolvePageResult.type === "skip") {
59
+ return null;
57
60
  }
58
61
  return resolvePageResult.module;
59
62
  },
@@ -1,3 +1,4 @@
1
+ import { toError } from "../error/toError.js";
1
2
 
2
3
  type ResolvePropsOptions<N extends string> = {
3
4
  id: string;
@@ -53,15 +54,16 @@ export const resolveProps = async <T, N extends string>({
53
54
  | { type: "error"; error: Error; module?: never }
54
55
  > => {
55
56
  try {
57
+ const result = await loader(id);
56
58
  return {
57
59
  type: "success",
58
60
  key: id,
59
- module: await loader(id),
61
+ module: result,
60
62
  };
61
63
  } catch (error) {
62
64
  return {
63
65
  type: "error",
64
- error: error instanceof Error ? error : new Error(String(error)),
66
+ error: toError(error),
65
67
  };
66
68
  }
67
69
  })();
@@ -117,7 +119,7 @@ export const resolveProps = async <T, N extends string>({
117
119
  } catch (error) {
118
120
  return {
119
121
  type: "error",
120
- error: error instanceof Error ? error : new Error(String(error)),
122
+ error: toError(error),
121
123
  };
122
124
  }
123
125
  } else if (props instanceof Promise) {
@@ -132,7 +134,7 @@ export const resolveProps = async <T, N extends string>({
132
134
  } catch (error) {
133
135
  return {
134
136
  type: "error",
135
- error: error instanceof Error ? error : new Error(String(error)),
137
+ error: toError(error),
136
138
  };
137
139
  }
138
140
  } else if (Array.isArray(props)) {
@@ -149,7 +151,7 @@ export const resolveProps = async <T, N extends string>({
149
151
  } catch (error) {
150
152
  return {
151
153
  type: "error",
152
- error: error instanceof Error ? error : new Error(String(error)),
154
+ error: toError(error),
153
155
  };
154
156
  }
155
157
  } else if (typeof props === "string") {
@@ -162,7 +164,7 @@ export const resolveProps = async <T, N extends string>({
162
164
  } catch (error) {
163
165
  return {
164
166
  type: "error",
165
- error: error instanceof Error ? error : new Error(String(error)),
167
+ error: toError(error),
166
168
  };
167
169
  }
168
170
  }
@@ -190,7 +190,7 @@ export const serializedOptions = <T extends ResolvedUserOptions>(
190
190
  autoDiscover,
191
191
  ...handlerOptions
192
192
  } = userOptions;
193
- const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build;
193
+ const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build ?? {};
194
194
  const result = {
195
195
  ...handlerOptions,
196
196
  build: {
@@ -38,7 +38,6 @@ export async function tryManifest<SSR extends boolean>(
38
38
  manifest: result,
39
39
  };
40
40
  } catch (e) {
41
- console.trace("No manifest found", manifestPath);
42
41
  return {
43
42
  type: "error",
44
43
  error: e as Error,
@@ -1,7 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import type { ResolvedUserConfig, ResolvedUserOptions } from "../../server.js";
3
3
  import type { Manifest } from "vite";
4
- import { getModuleRef } from "../moduleRefs.js";
4
+ import { getModuleRef } from "../helpers/moduleRefs.js";
5
5
  import { readFile } from "node:fs/promises";
6
6
  import type { OutputBundle } from "rollup";
7
7
  import { temporaryReferences } from "./temporaryReferences.js";
@@ -6,6 +6,7 @@ import { preprocessCSS } from "vite";
6
6
  import type { ResolvedConfig } from "vite";
7
7
  import { readFile } from "node:fs/promises";
8
8
  import { join } from "node:path";
9
+ import { env } from "../utils/env.js";
9
10
 
10
11
  /**
11
12
  * Global port for communication between the main thread and the CSS loader.
@@ -21,14 +22,7 @@ const cssFilesByPage = new Map<string, Set<string>>();
21
22
 
22
23
  let currentPage: string | null = null;
23
24
  let resolvedConfig: ResolvedConfig | undefined;
24
- // Get environment variables
25
- const env = import.meta?.env || {
26
- BASE_URL: '/',
27
- DEV: true,
28
- MODE: 'development',
29
- PROD: false,
30
- SSR: true
31
- };
25
+
32
26
 
33
27
  /**
34
28
  * Initializes the CSS loader with the necessary communication channels.
@@ -0,0 +1,84 @@
1
+ import type { LoadHookContext } from "node:module";
2
+ import type { LoaderContext } from "../types.js";
3
+ import type { MessagePort } from "node:worker_threads";
4
+ import type { ResolvedConfig } from "vite";
5
+
6
+ export let loaderPort: MessagePort | undefined;
7
+ let resolvedConfig: ResolvedConfig | undefined;
8
+
9
+ // Initialize hook
10
+ export async function initialize(data: { port: MessagePort, resolvedConfig: ResolvedConfig }) {
11
+ loaderPort = data.port;
12
+ resolvedConfig = data.resolvedConfig;
13
+ data.port.postMessage({ type: "INITIALIZED_ENV_LOADER" });
14
+ }
15
+
16
+ // Load hook
17
+ export async function load(
18
+ url: string,
19
+ context: LoadHookContext & LoaderContext,
20
+ nextLoad: any
21
+ ) {
22
+ const result = await nextLoad(url, context);
23
+
24
+ // Skip if not a module
25
+ if (result.format !== "module") {
26
+ return result;
27
+ }
28
+
29
+ // Skip node internals and hidden files
30
+ if (url.startsWith('node:') || url.includes('/.')) {
31
+ return result;
32
+ }
33
+
34
+ // Convert source to string if it's a Buffer or Uint8Array
35
+ let sourceStr: string;
36
+ if (typeof result.source === "string") {
37
+ sourceStr = result.source;
38
+ } else if (result.source instanceof Uint8Array || Buffer.isBuffer(result.source)) {
39
+ sourceStr = result.source.toString("utf-8");
40
+ } else {
41
+ console.warn(`[env-loader] Unexpected source type: ${typeof result.source}`);
42
+ return result;
43
+ }
44
+
45
+ // Get define object from resolved config
46
+ const define = resolvedConfig?.define || {};
47
+
48
+ // Create the env object with Vite's default environment variables
49
+ const envObject = {
50
+ MODE: resolvedConfig?.mode || 'development',
51
+ BASE_URL: resolvedConfig?.base || '/',
52
+ PROD: resolvedConfig?.isProduction ? true : false,
53
+ DEV: resolvedConfig?.isProduction ? false : true,
54
+ SSR: true,
55
+ ...Object.fromEntries(
56
+ Object.entries(define)
57
+ .filter(([key]) => key.startsWith('import.meta.env.'))
58
+ .map(([key, value]) => [key.replace('import.meta.env.', ''), JSON.parse(value as string)])
59
+ )
60
+ };
61
+
62
+ // Replace environment variable references in the source
63
+ let newSource = sourceStr;
64
+
65
+ // Check if we need to handle import.meta.env
66
+ if (newSource.includes('import.meta.env')) {
67
+ newSource = `Object.defineProperty(import.meta, "env", { value: ${JSON.stringify(envObject)}, writable: false, configurable: false });\n${newSource}`;
68
+ }
69
+
70
+ return {
71
+ ...result,
72
+ source: newSource
73
+ };
74
+ }
75
+
76
+ // Transform hook
77
+ export async function transformSource(
78
+ source: string,
79
+ context: any,
80
+ defaultTransformSource: any
81
+ ) {
82
+ const transformed = await defaultTransformSource(source, context, defaultTransformSource);
83
+ return transformed;
84
+ }
@@ -8,9 +8,9 @@ import {
8
8
  type LoadHookContext,
9
9
  type ResolveHookContext,
10
10
  } from "node:module";
11
- import { workerData } from "node:worker_threads";
12
11
  import type { MessagePort } from "node:worker_threads";
13
12
  import type { LoaderContext } from "../types.js";
13
+ import { env } from '../utils/env.js';
14
14
 
15
15
  let stashedGetSource: any = null;
16
16
  let stashedResolve: any = null;
@@ -21,15 +21,6 @@ setSourceMapsSupport(true, {
21
21
  generatedCode: true, // Enable for generated code
22
22
  });
23
23
 
24
- // Get environment variables from workerData or import.meta
25
- const env = workerData?.importMeta?.env ||
26
- import.meta?.env || {
27
- BASE_URL: "/",
28
- DEV: false,
29
- MODE: "production",
30
- PROD: true,
31
- SSR: true,
32
- };
33
24
 
34
25
  // Store port globally for use in load hook
35
26
  export let loaderPort: MessagePort | undefined;
@@ -12,7 +12,8 @@ export function formatMetrics(metrics: RenderMetrics): string {
12
12
  } = metrics;
13
13
 
14
14
  // Format memory usage in MB
15
- const formatMemory = (bytes: number) => `${(bytes / 1024 / 1024).toFixed(2)}MB`;
15
+ const formatMemory = (bytes: number) =>
16
+ `${(bytes / 1024 / 1024).toFixed(2)}MB`;
16
17
 
17
18
  return `
18
19
  Route: ${route}
@@ -32,6 +33,30 @@ Stream:
32
33
  `.trim();
33
34
  }
34
35
 
35
- export function logMetrics(metrics: RenderMetrics) {
36
- console.log(formatMetrics(metrics));
37
- }
36
+ export function metricWatcher({
37
+ maxTime = 200,
38
+ warnOnly = false,
39
+ warn = console.warn,
40
+ info = console.info,
41
+ }: {
42
+ maxTime?: number;
43
+ warnOnly?: boolean;
44
+ warn?: (...args: any[]) => void;
45
+ info?: (...args: any[]) => void;
46
+ }) {
47
+ return (metrics: RenderMetrics) => {
48
+ if (metrics.processingTime > maxTime) {
49
+ warn(`It took over ${maxTime}ms to render ${metrics.route}`);
50
+ warn(formatMetrics(metrics));
51
+ } else if (!warnOnly) {
52
+ const rounded = Math.round(metrics.processingTime);
53
+ if (rounded === 0) {
54
+ // smaller unit of time
55
+ const rounded = Math.round(metrics.processingTime * 1000);
56
+ info(`${metrics.route} (${rounded}μs)`);
57
+ } else {
58
+ info(`${metrics.route} (${rounded}ms)`);
59
+ }
60
+ }
61
+ };
62
+ }
@@ -2,9 +2,11 @@ import { reactPreservePlugin } from "./preserver/plugin.js";
2
2
  import { reactTransformPlugin } from "./transformer/plugin.client.js";
3
3
  import type { StreamPluginOptions } from "../types.js";
4
4
  import { reactClientPlugin } from "./react-client/plugin.js";
5
+ import { envPlugin } from "./env/plugin.js";
5
6
 
6
7
  export function vitePluginReactServer(options = {} as StreamPluginOptions): import("vite").Plugin[] {
7
8
  return [
9
+ envPlugin(),
8
10
  reactClientPlugin(options),
9
11
  reactTransformPlugin(options),
10
12
  reactPreservePlugin(options),
@@ -3,6 +3,7 @@ import { reactStaticPlugin } from "./react-static/plugin.js";
3
3
  import { reactTransformPlugin } from "./transformer/plugin.server.js";
4
4
  import type { StreamPluginOptions } from "./types.js";
5
5
  import { reactServerPlugin } from "./react-server/plugin.js";
6
+ import { envPlugin } from "./env/plugin.js";
6
7
 
7
8
 
8
9
  export function vitePluginReactServer(
@@ -11,12 +12,14 @@ export function vitePluginReactServer(
11
12
  if(!options.build?.pages || (Array.isArray(options.build.pages) && options.build.pages.length === 0)) {
12
13
  // in this case we do not need the static plugin at all
13
14
  return [
15
+ envPlugin(),
14
16
  reactTransformPlugin(options),
15
17
  reactServerPlugin(options),
16
18
  reactPreservePlugin(options),
17
19
  ];
18
20
  }
19
21
  return [
22
+ envPlugin(),
20
23
  reactTransformPlugin(options),
21
24
  reactServerPlugin(options),
22
25
  reactStaticPlugin(options),
package/plugin/plugin.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import { getCondition } from './config/getCondition.js';
2
2
 
3
- const condition = getCondition().slice(6); // remove react-
4
-
5
- export const { vitePluginReactServer } = await import(`./plugin.${condition}.js`);
3
+ export const { vitePluginReactServer } = await import(`./plugin.${getCondition('')}.js`);
@@ -155,3 +155,4 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
155
155
  },
156
156
  };
157
157
  }
158
+
@@ -0,0 +1,13 @@
1
+ declare global {
2
+ namespace NodeJS {
3
+ interface ProcessEnv {
4
+ VITE_BASE_URL: string;
5
+ VITE_DEV: string;
6
+ VITE_PROD: string;
7
+ VITE_SSR: string;
8
+ VITE_MODE: string;
9
+ VITE_PUBLIC_ORIGIN: string;
10
+ }
11
+ }
12
+ }
13
+ export {};