vite-plugin-react-server 1.1.12 → 1.1.13

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 (373) hide show
  1. package/dist/package.json +10 -8
  2. package/dist/plugin/components/css-collector-elements.d.ts +4 -2
  3. package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
  4. package/dist/plugin/components/css-collector-elements.js +21 -7
  5. package/dist/plugin/components/css-collector-elements.js.map +1 -1
  6. package/dist/plugin/components/css-collector.d.ts +4 -5
  7. package/dist/plugin/components/css-collector.d.ts.map +1 -1
  8. package/dist/plugin/components/css-collector.js +5 -9
  9. package/dist/plugin/components/css-collector.js.map +1 -1
  10. package/dist/plugin/components/html.d.ts +1 -1
  11. package/dist/plugin/components/html.d.ts.map +1 -1
  12. package/dist/plugin/components/html.js +14 -3
  13. package/dist/plugin/components/html.js.map +1 -1
  14. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts +4 -4
  15. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
  16. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +14 -9
  17. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
  18. package/dist/plugin/config/defaults.d.ts +66 -12
  19. package/dist/plugin/config/defaults.d.ts.map +1 -1
  20. package/dist/plugin/config/defaults.js +69 -15
  21. package/dist/plugin/config/defaults.js.map +1 -1
  22. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts +5 -0
  23. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -0
  24. package/dist/plugin/config/resolveAutoDiscoverMatcher.js +25 -0
  25. package/dist/plugin/config/resolveAutoDiscoverMatcher.js.map +1 -0
  26. package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
  27. package/dist/plugin/config/resolveEnv.js +16 -5
  28. package/dist/plugin/config/resolveEnv.js.map +1 -1
  29. package/dist/plugin/config/resolveOptions.d.ts +3 -3
  30. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  31. package/dist/plugin/config/resolveOptions.js +59 -87
  32. package/dist/plugin/config/resolveOptions.js.map +1 -1
  33. package/dist/plugin/config/resolveUserConfig.d.ts +4 -4
  34. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  35. package/dist/plugin/config/resolveUserConfig.js +8 -1
  36. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  37. package/dist/plugin/error/toError.d.ts +3 -0
  38. package/dist/plugin/error/toError.d.ts.map +1 -1
  39. package/dist/plugin/error/toError.js +33 -4
  40. package/dist/plugin/error/toError.js.map +1 -1
  41. package/dist/plugin/helpers/cleanObject.d.ts.map +1 -1
  42. package/dist/plugin/helpers/cleanObject.js +19 -5
  43. package/dist/plugin/helpers/cleanObject.js.map +1 -1
  44. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +3 -3
  45. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  46. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  47. package/dist/plugin/helpers/createCssProps.d.ts +4 -3
  48. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  49. package/dist/plugin/helpers/createCssProps.js +7 -2
  50. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  51. package/dist/plugin/helpers/createHandler.d.ts +4 -3
  52. package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
  53. package/dist/plugin/helpers/createHandler.js +1 -1
  54. package/dist/plugin/helpers/createHandler.js.map +1 -1
  55. package/dist/plugin/helpers/createRscStream.d.ts +2 -2
  56. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  57. package/dist/plugin/helpers/createRscStream.js +15 -5
  58. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  59. package/dist/plugin/helpers/index.d.ts +2 -2
  60. package/dist/plugin/helpers/index.d.ts.map +1 -1
  61. package/dist/plugin/helpers/index.js +2 -2
  62. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  63. package/dist/plugin/helpers/inputNormalizer.js +4 -1
  64. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  65. package/dist/plugin/helpers/moduleResolver.d.ts +3 -0
  66. package/dist/plugin/helpers/moduleResolver.d.ts.map +1 -0
  67. package/dist/plugin/helpers/moduleResolver.js +25 -0
  68. package/dist/plugin/helpers/requestInfo.d.ts +18 -3
  69. package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
  70. package/dist/plugin/helpers/requestInfo.js +75 -11
  71. package/dist/plugin/helpers/requestInfo.js.map +1 -1
  72. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
  73. package/dist/plugin/helpers/resolvePage.js +2 -3
  74. package/dist/plugin/helpers/resolvePage.js.map +1 -1
  75. package/dist/plugin/helpers/resolvePageAndProps.d.ts +4 -3
  76. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
  77. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
  78. package/dist/plugin/helpers/serializeUserOptions.d.ts +3 -2
  79. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
  80. package/dist/plugin/helpers/serializeUserOptions.js +13 -1
  81. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
  82. package/dist/plugin/helpers/sourceMap.d.ts +8 -0
  83. package/dist/plugin/helpers/sourceMap.d.ts.map +1 -0
  84. package/dist/plugin/helpers/sourceMap.js +136 -0
  85. package/dist/plugin/helpers.js +1 -1
  86. package/dist/plugin/loader/createBuildLoader.d.ts +7 -22
  87. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  88. package/dist/plugin/loader/createBuildLoader.js +79 -65
  89. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  90. package/dist/plugin/loader/createDefaultLoader.d.ts +13 -0
  91. package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -0
  92. package/dist/plugin/loader/createDefaultLoader.js +47 -0
  93. package/dist/plugin/loader/css-loader.development.d.ts +1 -0
  94. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
  95. package/dist/plugin/loader/css-loader.development.js +1 -1
  96. package/dist/plugin/loader/css-loader.development.js.map +1 -1
  97. package/dist/plugin/loader/handleExports.d.ts +33 -0
  98. package/dist/plugin/loader/handleExports.d.ts.map +1 -0
  99. package/dist/plugin/loader/handleExports.js +174 -0
  100. package/dist/plugin/loader/handleExports.js.map +1 -0
  101. package/dist/plugin/loader/index.d.ts +1 -1
  102. package/dist/plugin/loader/index.d.ts.map +1 -1
  103. package/dist/plugin/loader/index.js +4 -1
  104. package/dist/plugin/loader/parse.d.ts +6 -0
  105. package/dist/plugin/loader/parse.d.ts.map +1 -0
  106. package/dist/plugin/loader/parse.js +23 -0
  107. package/dist/plugin/loader/parse.js.map +1 -0
  108. package/dist/plugin/loader/react-loader.client.d.ts +2 -0
  109. package/dist/plugin/loader/react-loader.client.d.ts.map +1 -0
  110. package/dist/plugin/loader/react-loader.client.js +2 -0
  111. package/dist/plugin/loader/react-loader.d.ts +1 -12
  112. package/dist/plugin/loader/react-loader.d.ts.map +1 -1
  113. package/dist/plugin/loader/react-loader.js +5 -687
  114. package/dist/plugin/loader/react-loader.js.map +1 -1
  115. package/dist/plugin/loader/react-loader.server.d.ts +21 -0
  116. package/dist/plugin/loader/react-loader.server.d.ts.map +1 -0
  117. package/dist/plugin/loader/react-loader.server.js +69 -0
  118. package/dist/plugin/loader/sourceMap.d.ts +35 -0
  119. package/dist/plugin/loader/sourceMap.d.ts.map +1 -0
  120. package/dist/plugin/loader/sourceMap.js +105 -0
  121. package/dist/plugin/loader/temporaryReferences.d.ts +1 -1
  122. package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -1
  123. package/dist/plugin/loader/transformModuleIfNeeded.d.ts +2 -0
  124. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -0
  125. package/dist/plugin/loader/transformModuleIfNeeded.js +27 -0
  126. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -0
  127. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +27 -0
  128. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -0
  129. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +52 -0
  130. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -0
  131. package/dist/plugin/loader/types.d.ts +8 -0
  132. package/dist/plugin/loader/types.d.ts.map +1 -0
  133. package/dist/plugin/loader/types.js +1 -0
  134. package/dist/plugin/plugin.client.d.ts +2 -2
  135. package/dist/plugin/plugin.client.d.ts.map +1 -1
  136. package/dist/plugin/plugin.client.js +2 -3
  137. package/dist/plugin/plugin.client.js.map +1 -1
  138. package/dist/plugin/plugin.server.d.ts +2 -2
  139. package/dist/plugin/plugin.server.d.ts.map +1 -1
  140. package/dist/plugin/plugin.server.js +2 -2
  141. package/dist/plugin/plugin.server.js.map +1 -1
  142. package/dist/plugin/preserver/plugin.d.ts +2 -2
  143. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  144. package/dist/plugin/preserver/plugin.js +6 -2
  145. package/dist/plugin/preserver/plugin.js.map +1 -1
  146. package/dist/plugin/react-client/{server.d.ts → configureWorkerRequestHandler.d.ts} +4 -4
  147. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -0
  148. package/dist/plugin/react-client/{server.js → configureWorkerRequestHandler.js} +11 -8
  149. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -0
  150. package/dist/plugin/react-client/createMessageHandlers.d.ts +1 -1
  151. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  152. package/dist/plugin/react-client/createMessageHandlers.js +18 -11
  153. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
  154. package/dist/plugin/react-client/createWorkerStream.d.ts +5 -3
  155. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  156. package/dist/plugin/react-client/createWorkerStream.js +61 -27
  157. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  158. package/dist/plugin/react-client/handleWorkerRscStream.d.ts +1 -1
  159. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
  160. package/dist/plugin/react-client/handleWorkerRscStream.js +14 -4
  161. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
  162. package/dist/plugin/react-client/plugin.d.ts +2 -2
  163. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  164. package/dist/plugin/react-client/plugin.js +7 -8
  165. package/dist/plugin/react-client/plugin.js.map +1 -1
  166. package/dist/plugin/react-client/restartWorker.d.ts +1 -1
  167. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  168. package/dist/plugin/react-client/restartWorker.js +9 -3
  169. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  170. package/dist/plugin/react-server/configureReactServer.d.ts +9 -0
  171. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -0
  172. package/dist/plugin/react-server/{server.js → configureReactServer.js} +26 -8
  173. package/dist/plugin/react-server/configureReactServer.js.map +1 -0
  174. package/dist/plugin/react-server/handleServerAction.d.ts +5 -0
  175. package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -0
  176. package/dist/plugin/react-server/handleServerAction.js +145 -0
  177. package/dist/plugin/react-server/handleServerAction.js.map +1 -0
  178. package/dist/plugin/react-server/plugin.d.ts +2 -2
  179. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  180. package/dist/plugin/react-server/plugin.js +1 -1
  181. package/dist/plugin/react-server/plugin.js.map +1 -1
  182. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +2 -2
  183. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
  184. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
  185. package/dist/plugin/react-static/collectRscContent.d.ts +2 -2
  186. package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -1
  187. package/dist/plugin/react-static/collectRscContent.js.map +1 -1
  188. package/dist/plugin/react-static/configurePreviewServer.d.ts +3 -3
  189. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
  190. package/dist/plugin/react-static/configurePreviewServer.js +18 -7
  191. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
  192. package/dist/plugin/react-static/plugin.d.ts +2 -2
  193. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  194. package/dist/plugin/react-static/plugin.js +28 -12
  195. package/dist/plugin/react-static/plugin.js.map +1 -1
  196. package/dist/plugin/react-static/renderPage.d.ts +2 -2
  197. package/dist/plugin/react-static/renderPage.d.ts.map +1 -1
  198. package/dist/plugin/react-static/renderPage.js.map +1 -1
  199. package/dist/plugin/react-static/renderPages.d.ts +2 -2
  200. package/dist/plugin/react-static/renderPages.d.ts.map +1 -1
  201. package/dist/plugin/react-static/renderPages.js.map +1 -1
  202. package/dist/plugin/react-static/renderStreams.d.ts +2 -2
  203. package/dist/plugin/react-static/renderStreams.d.ts.map +1 -1
  204. package/dist/plugin/react-static/renderStreams.js +4 -4
  205. package/dist/plugin/react-static/renderStreams.js.map +1 -1
  206. package/dist/plugin/source-map/createMappingsSerializer.d.ts +2 -0
  207. package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -0
  208. package/dist/plugin/source-map/createMappingsSerializer.js +159 -0
  209. package/dist/plugin/source-map/readMappings.d.ts +2 -0
  210. package/dist/plugin/source-map/readMappings.d.ts.map +1 -0
  211. package/dist/plugin/source-map/readMappings.js +201 -0
  212. package/dist/plugin/transformer/index.d.ts +0 -1
  213. package/dist/plugin/transformer/index.d.ts.map +1 -1
  214. package/dist/plugin/transformer/index.js +0 -1
  215. package/dist/plugin/transformer/plugin.client.d.ts +1 -3
  216. package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
  217. package/dist/plugin/transformer/plugin.client.js +1 -84
  218. package/dist/plugin/transformer/plugin.server.d.ts +2 -2
  219. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
  220. package/dist/plugin/transformer/plugin.server.js +52 -20
  221. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  222. package/dist/plugin/types.d.ts +89 -119
  223. package/dist/plugin/types.d.ts.map +1 -1
  224. package/dist/plugin/utils/callServer.d.ts +1 -1
  225. package/dist/plugin/utils/callServer.d.ts.map +1 -1
  226. package/dist/plugin/utils/createCallServer.d.ts +1 -1
  227. package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
  228. package/dist/plugin/utils/createCallServer.js +13 -4
  229. package/dist/plugin/utils/createCallServer.js.map +1 -1
  230. package/dist/plugin/utils/index.d.ts +1 -0
  231. package/dist/plugin/utils/index.d.ts.map +1 -1
  232. package/dist/plugin/utils/index.js +1 -0
  233. package/dist/plugin/utils.js +1 -0
  234. package/dist/plugin/utils.js.map +1 -1
  235. package/dist/plugin/vendor/vendor.client.d.ts +2 -1
  236. package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
  237. package/dist/plugin/vendor/vendor.client.js +2 -1
  238. package/dist/plugin/vendor/vendor.client.js.map +1 -1
  239. package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
  240. package/dist/plugin/vendor/vendor.server.js +1 -1
  241. package/dist/plugin/vendor/vendor.server.js.map +1 -1
  242. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  243. package/dist/plugin/worker/createWorker.js +17 -22
  244. package/dist/plugin/worker/createWorker.js.map +1 -1
  245. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
  246. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +25 -4
  247. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
  248. package/dist/plugin/worker/html/html-worker.development.js +15 -13
  249. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  250. package/dist/plugin/worker/html/html-worker.production.js +2 -12
  251. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  252. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  253. package/dist/plugin/worker/html/messageHandler.js +2 -2
  254. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  255. package/dist/plugin/worker/rsc/handleRender.d.ts +2 -1
  256. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  257. package/dist/plugin/worker/rsc/handleRender.js +8 -8
  258. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  259. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  260. package/dist/plugin/worker/rsc/messageHandler.js +166 -107
  261. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  262. package/dist/plugin/worker/rsc/rsc-worker.development.js +112 -52
  263. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  264. package/dist/plugin/worker/rsc/rsc-worker.production.js +1 -1
  265. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  266. package/dist/plugin/worker/rsc/state.d.ts +5 -64
  267. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  268. package/dist/plugin/worker/rsc/state.js +5 -1
  269. package/dist/plugin/worker/rsc/state.js.map +1 -1
  270. package/dist/plugin/worker/sendMessage.d.ts +2 -0
  271. package/dist/plugin/worker/sendMessage.d.ts.map +1 -1
  272. package/dist/plugin/worker/sendMessage.js +2 -1
  273. package/dist/plugin/worker/sendMessage.js.map +1 -1
  274. package/dist/plugin/worker/types.d.ts +52 -53
  275. package/dist/plugin/worker/types.d.ts.map +1 -1
  276. package/dist/tsconfig.tsbuildinfo +1 -1
  277. package/package.json +10 -8
  278. package/plugin/components/css-collector-elements.tsx +30 -9
  279. package/plugin/components/css-collector.tsx +13 -22
  280. package/plugin/components/html.tsx +12 -5
  281. package/plugin/config/autoDiscover/resolveAutoDiscover.ts +31 -13
  282. package/plugin/config/defaults.tsx +72 -16
  283. package/plugin/config/resolveAutoDiscoverMatcher.ts +23 -0
  284. package/plugin/config/resolveEnv.ts +20 -12
  285. package/plugin/config/resolveOptions.ts +152 -155
  286. package/plugin/config/resolveUserConfig.ts +20 -5
  287. package/plugin/error/toError.ts +35 -1
  288. package/plugin/helpers/cleanObject.ts +79 -15
  289. package/plugin/helpers/collectViteModuleGraphCss.ts +4 -3
  290. package/plugin/helpers/createCssProps.tsx +26 -9
  291. package/plugin/helpers/createHandler.ts +7 -4
  292. package/plugin/helpers/createRscStream.tsx +20 -14
  293. package/plugin/helpers/index.ts +2 -2
  294. package/plugin/helpers/inputNormalizer.ts +4 -2
  295. package/plugin/helpers/moduleResolver.ts +36 -0
  296. package/plugin/helpers/requestInfo.ts +117 -23
  297. package/plugin/helpers/resolvePage.ts +2 -3
  298. package/plugin/helpers/resolvePageAndProps.ts +7 -6
  299. package/plugin/helpers/serializeUserOptions.ts +20 -2
  300. package/plugin/helpers/sourceMap.ts +182 -0
  301. package/plugin/loader/createBuildLoader.ts +124 -104
  302. package/plugin/loader/createDefaultLoader.ts +62 -0
  303. package/plugin/loader/css-loader.development.ts +3 -2
  304. package/plugin/loader/handleExports.ts +276 -0
  305. package/plugin/loader/index.ts +6 -1
  306. package/plugin/loader/parse.ts +22 -0
  307. package/plugin/loader/react-loader.client.ts +1 -0
  308. package/plugin/loader/react-loader.server.ts +107 -0
  309. package/plugin/loader/react-loader.ts +4 -1002
  310. package/plugin/loader/sourceMap.ts +118 -0
  311. package/plugin/loader/transformModuleIfNeeded.ts +33 -0
  312. package/plugin/loader/transformModuleWithPreservedFunctions.ts +119 -0
  313. package/plugin/loader/types.ts +10 -0
  314. package/plugin/plugin.client.ts +18 -11
  315. package/plugin/plugin.server.ts +6 -3
  316. package/plugin/preserver/plugin.ts +37 -17
  317. package/plugin/react-client/{server.ts → configureWorkerRequestHandler.ts} +22 -12
  318. package/plugin/react-client/createMessageHandlers.ts +21 -13
  319. package/plugin/react-client/createWorkerStream.ts +71 -33
  320. package/plugin/react-client/handleWorkerRscStream.ts +15 -5
  321. package/plugin/react-client/plugin.ts +18 -13
  322. package/plugin/react-client/restartWorker.ts +17 -5
  323. package/plugin/react-server/{server.ts → configureReactServer.ts} +40 -9
  324. package/plugin/react-server/handleServerAction.ts +177 -0
  325. package/plugin/react-server/plugin.ts +8 -3
  326. package/plugin/react-static/collectHtmlWorkerContent.ts +11 -3
  327. package/plugin/react-static/collectRscContent.ts +17 -9
  328. package/plugin/react-static/configurePreviewServer.ts +37 -17
  329. package/plugin/react-static/plugin.ts +45 -22
  330. package/plugin/react-static/renderPage.ts +12 -6
  331. package/plugin/react-static/renderPages.ts +15 -4
  332. package/plugin/react-static/renderStreams.ts +13 -12
  333. package/plugin/source-map/createMappingsSerializer.ts +182 -0
  334. package/plugin/source-map/readMappings.ts +195 -0
  335. package/plugin/transformer/README.md +295 -29
  336. package/plugin/transformer/index.ts +0 -1
  337. package/plugin/transformer/plugin.client.ts +0 -111
  338. package/plugin/transformer/plugin.server.ts +94 -25
  339. package/plugin/types/react-server-dom-esm.d.ts +183 -24
  340. package/plugin/types/sourceMap.d.ts +2 -0
  341. package/plugin/types/webpack-sources.d.ts +24 -0
  342. package/plugin/types.ts +169 -132
  343. package/plugin/utils/createCallServer.ts +21 -6
  344. package/plugin/utils/index.ts +2 -1
  345. package/plugin/vendor/vendor.client.ts +2 -1
  346. package/plugin/vendor/vendor.server.ts +1 -1
  347. package/plugin/worker/createWorker.ts +21 -24
  348. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +31 -7
  349. package/plugin/worker/html/html-worker.development.tsx +16 -16
  350. package/plugin/worker/html/html-worker.production.tsx +3 -19
  351. package/plugin/worker/html/messageHandler.tsx +2 -4
  352. package/plugin/worker/rsc/handleRender.ts +15 -12
  353. package/plugin/worker/rsc/messageHandler.tsx +191 -120
  354. package/plugin/worker/rsc/rsc-worker.development.ts +148 -77
  355. package/plugin/worker/rsc/rsc-worker.production.ts +1 -1
  356. package/plugin/worker/rsc/state.ts +10 -0
  357. package/plugin/worker/sendMessage.ts +32 -14
  358. package/plugin/worker/types.ts +99 -64
  359. package/dist/plugin/react-client/server.d.ts.map +0 -1
  360. package/dist/plugin/react-client/server.js.map +0 -1
  361. package/dist/plugin/react-server/server.d.ts +0 -9
  362. package/dist/plugin/react-server/server.d.ts.map +0 -1
  363. package/dist/plugin/react-server/server.js.map +0 -1
  364. package/dist/plugin/transformer/plugin.client.js.map +0 -1
  365. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +0 -2
  366. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +0 -1
  367. package/dist/plugin/transformer/upgradeCssModuleCode.js +0 -40
  368. package/dist/plugin/worker/loader.d.ts +0 -5
  369. package/dist/plugin/worker/loader.d.ts.map +0 -1
  370. package/dist/plugin/worker/loader.js +0 -11
  371. package/dist/plugin/worker/loader.js.map +0 -1
  372. package/plugin/transformer/upgradeCssModuleCode.ts +0 -42
  373. package/plugin/worker/loader.ts +0 -7
@@ -0,0 +1,276 @@
1
+ import type { Program } from "./types.js";
2
+ import type { FunctionDeclaration, VariableDeclaration, VariableDeclarator } from "acorn";
3
+
4
+ /**
5
+ * Collects and organizes export information from a module.
6
+ *
7
+ * For all modules:
8
+ * - Collects import statements
9
+ * - Collects export names
10
+ * - Collects declarations
11
+ *
12
+ * The actual transformation of exports (like wrapping with registerServerReference)
13
+ * happens in transformModuleWithPreservedFunctions.
14
+ *
15
+ * @param source - The source code of the module
16
+ * @param url - The URL of the module
17
+ * @param program - The parsed AST program
18
+ * @param isServerFunction - Whether this is a server module
19
+ * @param isClientComponent - Whether this is a client module
20
+ * @returns Object containing imports, declarations, and export names
21
+ */
22
+ export function handleExports(
23
+ source: string,
24
+ program: Program,
25
+ isServerFunction: boolean | RegExpMatchArray | null,
26
+ isClientComponent: boolean | RegExpMatchArray | null
27
+ ): {
28
+ imports: string[];
29
+ declarations: string[];
30
+ exportNames: string[];
31
+ exports: Map<
32
+ string,
33
+ {
34
+ type: "function" | "class" | "variable" | "default" | "all";
35
+ declaration?: string;
36
+ localName?: string;
37
+ before?: string[];
38
+ after?: string[];
39
+ isAsync?: boolean;
40
+ }
41
+ >;
42
+ } {
43
+ const imports: string[] = [];
44
+ const declarations: string[] = [];
45
+ const exportNames: string[] = [];
46
+ // Track exports and their types
47
+ const exports = new Map<
48
+ string,
49
+ {
50
+ type: "function" | "class" | "variable" | "default" | "all";
51
+ declaration?: string;
52
+ localName?: string;
53
+ before?: string[];
54
+ after?: string[];
55
+ isAsync?: boolean;
56
+ }
57
+ >();
58
+
59
+ let lastEnd = 0;
60
+ let currentBefore: string[] = [];
61
+ let foundFirstExport = false;
62
+
63
+ // First pass: collect all exports and code between them
64
+ for (const node of program.body) {
65
+ // Add any code before this node
66
+ if (node.start > lastEnd) {
67
+ const beforeCode = source.slice(lastEnd, node.start);
68
+ if (beforeCode.trim()) {
69
+ currentBefore.push(beforeCode);
70
+ }
71
+ }
72
+
73
+ if (node.type === "ImportDeclaration") {
74
+ imports.push(source.slice(node.start, node.end));
75
+ } else if (node.type === "ExportAllDeclaration") {
76
+ // For export * from './other', just add the * export
77
+ exports.set("*", {
78
+ type: "all",
79
+ before: [...currentBefore],
80
+ });
81
+ currentBefore = [];
82
+ exportNames.push("*");
83
+ } else if (node.type === "ExportNamedDeclaration") {
84
+ if (!foundFirstExport) {
85
+ // This is the first export, so all code before it goes into its before array
86
+ foundFirstExport = true;
87
+ }
88
+
89
+ if (node.declaration) {
90
+ if (
91
+ node.declaration.type === "FunctionDeclaration" &&
92
+ node.declaration.id
93
+ ) {
94
+ const name = node.declaration.id.name;
95
+ exports.set(name, {
96
+ type: "function",
97
+ declaration: source.slice(node.declaration.start, node.declaration.end),
98
+ before: [...currentBefore], // Copy the current before array
99
+ isAsync: node.declaration.async,
100
+ });
101
+ exportNames.push(name);
102
+ currentBefore = []; // Reset for next export
103
+ } else if (
104
+ node.declaration.type === "ClassDeclaration" &&
105
+ node.declaration.id
106
+ ) {
107
+ const name = node.declaration.id.name;
108
+ exports.set(name, {
109
+ type: "class",
110
+ declaration: source.slice(node.declaration.start, node.declaration.end),
111
+ before: [...currentBefore], // Copy the current before array
112
+ });
113
+ exportNames.push(name);
114
+ currentBefore = []; // Reset for next export
115
+ } else if (node.declaration.type === "VariableDeclaration") {
116
+ for (const decl of node.declaration.declarations) {
117
+ if (decl.id && decl.id.type === "Identifier") {
118
+ const name = decl.id.name;
119
+ // Check if the declaration is a function expression or arrow function
120
+ const init = decl.init;
121
+ const isFunction = init && (
122
+ init.type === "FunctionExpression" ||
123
+ init.type === "ArrowFunctionExpression"
124
+ );
125
+ // For function expressions and arrow functions, we want to mark them as async
126
+ // if they are explicitly marked as async
127
+ const isAsync = isFunction && (
128
+ (init.type === "FunctionExpression" && init.async === true) ||
129
+ (init.type === "ArrowFunctionExpression" && init.async === true)
130
+ );
131
+ exports.set(name, {
132
+ type: isFunction ? "function" : "variable",
133
+ declaration: source.slice(decl.start, decl.end),
134
+ before: [...currentBefore], // Copy the current before array
135
+ isAsync: isAsync || false
136
+ });
137
+ exportNames.push(name);
138
+ currentBefore = []; // Reset for next export
139
+ }
140
+ }
141
+ }
142
+ } else if (node.specifiers) {
143
+ // For named exports (export { a, b, c })
144
+ for (const spec of node.specifiers) {
145
+ if (spec.type === "ExportSpecifier") {
146
+ const localName = spec.local.type === "Identifier" ? spec.local.name : "";
147
+ const exportedName = spec.exported.type === "Identifier" ? spec.exported.name : "";
148
+ if (localName && exportedName) {
149
+ // Find the function declaration in the AST
150
+ const functionDecl = program.body.find(
151
+ (node): node is FunctionDeclaration =>
152
+ node.type === "FunctionDeclaration" &&
153
+ node.id?.name === localName
154
+ );
155
+
156
+ if (functionDecl) {
157
+ exports.set(exportedName, {
158
+ type: "function",
159
+ localName,
160
+ declaration: source.slice(functionDecl.start, functionDecl.end),
161
+ before: [...currentBefore],
162
+ isAsync: functionDecl.async
163
+ });
164
+ exportNames.push(exportedName);
165
+ } else {
166
+ // If we can't find a function declaration, check if it's a variable declaration
167
+ const varDecl = program.body.find(
168
+ (node): node is VariableDeclaration =>
169
+ node.type === "VariableDeclaration" &&
170
+ node.declarations.some(
171
+ (decl) =>
172
+ decl.id.type === "Identifier" &&
173
+ decl.id.name === localName &&
174
+ decl.init &&
175
+ (decl.init.type === "FunctionExpression" ||
176
+ decl.init.type === "ArrowFunctionExpression")
177
+ )
178
+ );
179
+
180
+ if (varDecl) {
181
+ const decl = varDecl.declarations.find(
182
+ (d: VariableDeclarator) => d.id.type === "Identifier" && d.id.name === localName
183
+ );
184
+ if (decl && decl.init) {
185
+ const isAsync = decl.init.type === "FunctionExpression" ? decl.init.async :
186
+ decl.init.type === "ArrowFunctionExpression" ? decl.init.async : false;
187
+ exports.set(exportedName, {
188
+ type: "function",
189
+ localName,
190
+ declaration: source.slice(decl.start, decl.end),
191
+ before: [...currentBefore],
192
+ isAsync
193
+ });
194
+ exportNames.push(exportedName);
195
+ }
196
+ } else {
197
+ exports.set(exportedName, {
198
+ type: "variable",
199
+ localName,
200
+ before: [...currentBefore],
201
+ });
202
+ exportNames.push(exportedName);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+ currentBefore = []; // Reset for next export
209
+ }
210
+ } else if (node.type === "ExportDefaultDeclaration") {
211
+ if (node.declaration && node.declaration.type === "FunctionDeclaration" && node.declaration.id) {
212
+ exports.set("default", {
213
+ type: "default",
214
+ before: [...currentBefore],
215
+ localName: node.declaration.id.name, // Capture the function name
216
+ isAsync: node.declaration.async
217
+ });
218
+ } else {
219
+ exports.set("default", {
220
+ type: "default",
221
+ before: [...currentBefore]
222
+ });
223
+ }
224
+ currentBefore = []; // Reset for next export
225
+ } else if (
226
+ node.type === "FunctionDeclaration" ||
227
+ node.type === "VariableDeclaration" ||
228
+ node.type === "ClassDeclaration"
229
+ ) {
230
+ // For non-exported declarations:
231
+ // - Keep all declarations for server functions
232
+ // - Remove function declarations for client components
233
+ if (
234
+ isServerFunction ||
235
+ !isClientComponent ||
236
+ node.type !== "FunctionDeclaration"
237
+ ) {
238
+ declarations.push(source.slice(node.start, node.end));
239
+ }
240
+ }
241
+
242
+ lastEnd = node.end;
243
+ }
244
+
245
+ // Add any remaining code after the last node
246
+ if (lastEnd < source.length) {
247
+ const afterCode = source.slice(lastEnd);
248
+ if (afterCode.trim()) {
249
+ // Add to the last export's after array
250
+ const lastExport = Array.from(exports.values()).pop();
251
+ if (lastExport) {
252
+ lastExport.after = [afterCode];
253
+ }
254
+ }
255
+ }
256
+
257
+ // Second pass: generate transformed exports
258
+ // Process all exports regardless of environment - the actual transformation
259
+ // happens in transformModuleWithPreservedFunctions
260
+ for (const [name, info] of exports) {
261
+ if (info.before) {
262
+ declarations.push(...info.before);
263
+ }
264
+ if (info.declaration) {
265
+ declarations.push(info.declaration);
266
+ }
267
+ if (info.after) {
268
+ declarations.push(...info.after);
269
+ }
270
+ if (!exportNames.includes(name)) {
271
+ exportNames.push(name);
272
+ }
273
+ }
274
+
275
+ return { imports, declarations, exportNames, exports };
276
+ }
@@ -1 +1,6 @@
1
- export { reactLoaderPlugin } from "./plugin.js";
1
+ import { getCondition } from "../config/getCondition.js"
2
+
3
+ const condition = getCondition('')
4
+ const loader = await import(`react-loader.${condition}.ts`);
5
+
6
+ export const { load, resolve } = loader;
@@ -0,0 +1,22 @@
1
+ import * as acorn from "acorn-loose";
2
+ import type { Program } from "./types.js";
3
+
4
+ /**
5
+ * Parses source code and handles source maps
6
+ */
7
+ export function parse(source: string): Program {
8
+ let program: Program;
9
+
10
+ // Parse the transformed code with acorn
11
+ program = acorn.parse(source, {
12
+ ecmaVersion: "latest" as const,
13
+ sourceType: "module",
14
+ locations: true,
15
+ allowAwaitOutsideFunction: true,
16
+ allowImportExportEverywhere: true,
17
+ allowReturnOutsideFunction: true,
18
+ allowReserved: true,
19
+ }) as Program;
20
+
21
+ return program
22
+ }
@@ -0,0 +1 @@
1
+ throw new Error("Not supported on the client");
@@ -0,0 +1,107 @@
1
+ import type { LoaderContext, ResolvedUserOptions } from "../types.js";
2
+ import type { ModuleInfo } from "rollup";
3
+ import { transformModuleIfNeeded } from "./transformModuleIfNeeded.js";
4
+ import type { MessagePort } from "node:worker_threads";
5
+ import type { InitializedReactLoaderMessage, ServerModuleMessage } from "../worker/types.js";
6
+ import { hydrateUserOptions } from "../helpers/index.js";
7
+ import { resolveOptions } from "../config/index.js";
8
+ import { fileURLToPath } from "node:url";
9
+ import { join } from "node:path";
10
+
11
+ export interface LoaderOptions {
12
+ id: string;
13
+ resolveDependencies?: boolean;
14
+ format?: string;
15
+ conditions?: string[];
16
+ importAssertions?: Record<string, any>;
17
+ importAttributes?: Record<string, any>;
18
+ source: string;
19
+ }
20
+
21
+ export type LoaderFunction = (options: LoaderOptions) => Promise<ModuleInfo>;
22
+
23
+ let userOptions: ResolvedUserOptions | undefined;
24
+ let loaderPort: MessagePort | undefined;
25
+ export async function initialize(data: { id: string, port: MessagePort, userOptions: any }) {
26
+ const userOptionsResult = resolveOptions(hydrateUserOptions(data.userOptions));
27
+ loaderPort = data.port;
28
+ loaderPort.postMessage({ type: "INITIALIZED_REACT_LOADER", id: data.id } satisfies InitializedReactLoaderMessage);
29
+ if(userOptionsResult.type === "error") {
30
+ throw userOptionsResult.error
31
+ }
32
+ userOptions = userOptionsResult.userOptions;
33
+ }
34
+
35
+ export async function load(url: string, context: LoaderContext, nextLoad: any) {
36
+ const { format } = context;
37
+
38
+ if (format === "module") {
39
+ const result = await nextLoad(url, context);
40
+ const source = typeof result.source === 'string' ? result.source :
41
+ result.source instanceof Uint8Array ? new TextDecoder().decode(result.source) :
42
+ String(result.source);
43
+
44
+ // Handle file URLs
45
+ const filePath = url.startsWith("file://") ? fileURLToPath(url) : url;
46
+
47
+ // Normalize the URL using the same logic as plugin.server.ts
48
+ let moduleID = filePath;
49
+ let finalID = filePath;
50
+ if (userOptions?.normalizer) {
51
+ const [, value] = userOptions.normalizer(filePath);
52
+ moduleID = join(userOptions.moduleBasePath, value);
53
+ finalID = userOptions.moduleID(moduleID);
54
+ }
55
+ if (userOptions?.verbose) {
56
+ console.log("[react-loader] moduleID:", moduleID);
57
+ console.log("[react-loader] finalID:", finalID);
58
+ }
59
+
60
+ const transformed = transformModuleIfNeeded(
61
+ source,
62
+ finalID,
63
+ userOptions?.autoDiscover?.isServerFunction(source),
64
+ userOptions?.autoDiscover?.isClientComponent(source),
65
+ true, // isServerEnvironment
66
+ );
67
+
68
+ if (userOptions?.verbose) {
69
+ console.log("[react-loader] Transformed source:", transformed);
70
+ }
71
+
72
+ if (loaderPort) {
73
+ if (userOptions?.verbose) {
74
+ console.log("[react-loader] Sending SERVER_MODULE message:", { id: finalID, url: filePath });
75
+ }
76
+ loaderPort.postMessage({
77
+ type: "SERVER_MODULE",
78
+ id: finalID,
79
+ url: filePath,
80
+ source: transformed,
81
+ } satisfies ServerModuleMessage);
82
+ }
83
+
84
+ // If we have a source map, update it to point to the transformed source
85
+ const map = result.map ? {
86
+ ...result.map,
87
+ sourcesContent: [transformed],
88
+ mappings: result.map.mappings
89
+ } : null;
90
+
91
+ return {
92
+ ...result,
93
+ source: transformed,
94
+ map
95
+ };
96
+ }
97
+
98
+ return nextLoad(url, context);
99
+ }
100
+
101
+ export async function resolve(
102
+ specifier: string,
103
+ context: any,
104
+ nextResolve: any
105
+ ) {
106
+ return nextResolve(specifier, context);
107
+ }