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
@@ -1,39 +1,17 @@
1
1
  import type { PreRenderedAsset } from "rollup";
2
2
  import type { PreRenderedChunk } from "rollup";
3
- import type { StreamPluginOptions, ResolvedUserOptions } from "../types.js";
3
+ import type {
4
+ StreamPluginOptions,
5
+ ResolvedUserOptions,
6
+ PagePropOpt,
7
+ InlineCssOpt,
8
+ } from "../types.js";
4
9
  import { DEFAULT_CONFIG } from "./defaults.js";
5
10
  import { join } from "node:path";
6
11
  import { pluginRoot } from "../root.js";
7
12
  import { CssCollector } from "../components/css-collector.js";
8
13
  import { createInputNormalizer } from "../helpers/inputNormalizer.js";
9
-
10
- // ============================================================================
11
- // Utility Functions
12
- // ============================================================================
13
-
14
- /**
15
- * Resolves a matcher pattern to a function that tests paths
16
- */
17
- const resolveAutoDiscoverMatcher = (
18
- options: undefined | string | RegExp | ((path: string) => boolean),
19
- fallback: RegExp | ((path: string) => boolean)
20
- ) => {
21
- if (!options) {
22
- if (typeof fallback === "function") {
23
- return fallback;
24
- } else {
25
- return (path: string) => fallback.test(path);
26
- }
27
- }
28
- if (typeof options === "string") {
29
- const matcher = new RegExp(options);
30
- return (path: string) => matcher.test(path);
31
- } else if (typeof options === "function") {
32
- return options;
33
- } else {
34
- return (path: string) => options.test(path);
35
- }
36
- };
14
+ import { resolveAutoDiscoverMatcher } from "./resolveAutoDiscoverMatcher.js";
37
15
 
38
16
  /**
39
17
  * Ensures a path ends with .js extension
@@ -72,13 +50,13 @@ const registerPath = (
72
50
  // ============================================================================
73
51
 
74
52
  export const resolveOptions = <
75
- InlineCSS extends boolean | undefined = boolean | undefined
53
+ T extends PagePropOpt = PagePropOpt,
54
+ InlineCSS extends InlineCssOpt = InlineCssOpt
76
55
  >(
77
- options: StreamPluginOptions<InlineCSS>
56
+ options: StreamPluginOptions<T, InlineCSS>
78
57
  ):
79
- | { type: "success"; userOptions: ResolvedUserOptions<InlineCSS> }
58
+ | { type: "success"; userOptions: ResolvedUserOptions<T, InlineCSS> }
80
59
  | { type: "error"; error: Error } => {
81
-
82
60
  // Basic configuration
83
61
  const projectRoot = options.projectRoot ?? process.cwd();
84
62
  const {
@@ -102,40 +80,81 @@ export const resolveOptions = <
102
80
  const assetsDir =
103
81
  options.build?.assetsDir ?? `${DEFAULT_CONFIG.CLIENT_ASSETS_DIR}`;
104
82
 
105
- // Path normalization helpers
106
- const ensureModuleBase = (n: string | null) => {
107
- if (!n) return "";
108
- return n.startsWith(moduleBase + "/") ? n.slice(moduleBase.length + 1) : n;
109
- };
83
+ // Build options
84
+ const preserveModulesRoot =
85
+ options.build?.preserveModulesRoot ??
86
+ DEFAULT_CONFIG.BUILD.preserveModulesRoot;
87
+
88
+ // Module path configuration
89
+ const moduleBase =
90
+ typeof options.moduleBase === "string"
91
+ ? options.moduleBase
92
+ : DEFAULT_CONFIG.MODULE_BASE;
93
+
94
+ const moduleBasePath =
95
+ typeof options.moduleBasePath === "string"
96
+ ? options.moduleBasePath
97
+ : process.env.VITE_BASE_URL ?? DEFAULT_CONFIG.MODULE_BASE_PATH;
110
98
 
111
- const hasWrongRoot = !projectRoot.startsWith("/");
112
- if (hasWrongRoot) {
113
- console.warn("projectRoot is not a full path", projectRoot);
99
+ const moduleBaseURL =
100
+ typeof options.moduleBaseURL === "string"
101
+ ? options.moduleBaseURL
102
+ : process.env.VITE_BASE_URL ?? DEFAULT_CONFIG.MODULE_BASE_URL;
103
+
104
+ const moduleRootPath =
105
+ typeof options.moduleRootPath === "string"
106
+ ? options.moduleRootPath
107
+ : join(projectRoot, outDir, client);
108
+
109
+ const publicOrigin =
110
+ typeof options.publicOrigin === "string"
111
+ ? options.publicOrigin
112
+ : process.env.VITE_PUBLIC_ORIGIN ?? DEFAULT_CONFIG.PUBLIC_ORIGIN;
113
+
114
+ // Worker and loader paths
115
+ const rscWorkerPath =
116
+ typeof options.rscWorkerPath === "string"
117
+ ? join(projectRoot, options.rscWorkerPath)
118
+ : join(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
119
+
120
+ const htmlWorkerPath =
121
+ typeof options.htmlWorkerPath === "string"
122
+ ? join(projectRoot, options.htmlWorkerPath)
123
+ : join(pluginRoot, DEFAULT_CONFIG.HTML_WORKER_PATH);
124
+
125
+ const loaderPath =
126
+ typeof options.loaderPath === "string"
127
+ ? join(projectRoot, options.loaderPath)
128
+ : join(pluginRoot, DEFAULT_CONFIG.LOADER_PATH);
129
+ // these will never be cleaned up, because, we are resolving the user options
130
+ // and it's assumed they are relevant until the process stops
131
+ if (process.env.VITE_BASE_URL !== moduleBaseURL) {
132
+ process.env.VITE_BASE_URL = moduleBaseURL;
114
133
  }
115
- /**
116
- * If the defined project root is already wrong, we keep it as is.
117
- * Otherwise, we remove the leading slash as a representation of the wrong root.
118
- */
119
- const wrongRoot = !hasWrongRoot ? projectRoot.slice(1) : projectRoot;
120
-
121
- const ensureNoRoot = (n: string | null) => {
122
- if (typeof n !== "string" || n === "") {
123
- return "";
124
- }
125
- // if the path starts with the wrong root, we remove the wrong root
126
- if (n.startsWith(wrongRoot)) {
127
- return n.slice(wrongRoot.length + 1);
128
- }
129
- // if the path starts with the project root, we remove the project root
130
- return n.startsWith(projectRoot + "/")
131
- ? n.slice(projectRoot.length + 1)
132
- : n;
133
- };
134
+ if (process.env.VITE_PUBLIC_ORIGIN !== publicOrigin) {
135
+ process.env.VITE_PUBLIC_ORIGIN = publicOrigin;
136
+ }
137
+
138
+ const normalizer =
139
+ options.normalizer ??
140
+ createInputNormalizer({
141
+ root: projectRoot,
142
+ preserveModulesRoot:
143
+ preserveModulesRoot === true ? moduleBase : undefined,
144
+ removeExtension: true,
145
+ moduleBasePath,
146
+ });
134
147
 
148
+ const testModuleExtension = resolveAutoDiscoverMatcher(
149
+ options.autoDiscover?.moduleExtension,
150
+ DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension
151
+ );
135
152
  // Auto-discovery pattern matchers
136
153
  const testModulePattern = resolveAutoDiscoverMatcher(
137
154
  options.autoDiscover?.modulePattern,
138
- DEFAULT_CONFIG.AUTO_DISCOVER.modulePattern
155
+ options.autoDiscover?.moduleExtension
156
+ ? (id: string) => testModuleExtension(id.toLowerCase())
157
+ : DEFAULT_CONFIG.AUTO_DISCOVER.modulePattern
139
158
  );
140
159
 
141
160
  const testJson = resolveAutoDiscoverMatcher(
@@ -160,12 +179,20 @@ export const resolveOptions = <
160
179
 
161
180
  const testClientComponents = resolveAutoDiscoverMatcher(
162
181
  options.autoDiscover?.clientComponents,
163
- DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents
182
+ options.autoDiscover?.moduleExtension
183
+ ? (id: string) =>
184
+ testModuleExtension(id.toLowerCase()) &&
185
+ /(\.|\/)?client(\.|\/)/.test(id.toLowerCase())
186
+ : DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents
164
187
  );
165
188
 
166
189
  const testServerFunctions = resolveAutoDiscoverMatcher(
167
190
  options.autoDiscover?.serverFunctions,
168
- DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions
191
+ options.autoDiscover?.moduleExtension
192
+ ? (id: string) =>
193
+ testModuleExtension(id.toLowerCase()) &&
194
+ /(\.|\/)?server(\.|\/)/.test(id.toLowerCase())
195
+ : DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions
169
196
  );
170
197
 
171
198
  const testNodeOnly = resolveAutoDiscoverMatcher(
@@ -175,12 +202,20 @@ export const resolveOptions = <
175
202
 
176
203
  const testPropsPattern = resolveAutoDiscoverMatcher(
177
204
  options.autoDiscover?.propsPattern,
178
- DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern
205
+ options.autoDiscover?.moduleExtension
206
+ ? (id: string) =>
207
+ testModuleExtension(id.toLowerCase()) &&
208
+ /(\.|\/)?props(\.|\/)/.test(id.toLowerCase())
209
+ : DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern
179
210
  );
180
211
 
181
212
  const testPagePattern = resolveAutoDiscoverMatcher(
182
213
  options.autoDiscover?.pagePattern,
183
- DEFAULT_CONFIG.AUTO_DISCOVER.pagePattern
214
+ options.autoDiscover?.moduleExtension
215
+ ? (id: string) =>
216
+ testModuleExtension(id.toLowerCase()) &&
217
+ /(\.|\/)?page(\.|\/)/.test(id.toLowerCase())
218
+ : DEFAULT_CONFIG.AUTO_DISCOVER.pagePattern
184
219
  );
185
220
 
186
221
  const testCssModule = resolveAutoDiscoverMatcher(
@@ -203,10 +238,21 @@ export const resolveOptions = <
203
238
  DEFAULT_CONFIG.AUTO_DISCOVER.dotFiles
204
239
  );
205
240
 
206
- // Build options
207
- const preserveModulesRoot =
208
- options.build?.preserveModulesRoot ??
209
- DEFAULT_CONFIG.BUILD.preserveModulesRoot;
241
+ const isServerFunction = resolveAutoDiscoverMatcher(
242
+ options.autoDiscover?.isServerFunction,
243
+ options.autoDiscover?.serverDirective
244
+ ? (code: string) =>
245
+ code.match(options.autoDiscover?.serverDirective!) !== null
246
+ : DEFAULT_CONFIG.AUTO_DISCOVER.serverDirective
247
+ );
248
+
249
+ const isClientComponent = resolveAutoDiscoverMatcher(
250
+ options.autoDiscover?.isClientComponent,
251
+ options.autoDiscover?.clientDirective
252
+ ? (code: string) =>
253
+ code.match(options.autoDiscover?.clientDirective!) !== null
254
+ : DEFAULT_CONFIG.AUTO_DISCOVER.clientDirective
255
+ );
210
256
 
211
257
  const hashOption =
212
258
  typeof options.build?.hash === "string"
@@ -304,45 +350,47 @@ export const resolveOptions = <
304
350
  return hash(`${n.name}.js`, ssr);
305
351
  }
306
352
  }
307
- return hash(
308
- addModuleExtension(getOutputPath(ensureModuleBase(ensureNoRoot(n.name)))),
309
- ssr
310
- );
353
+ return hash(addModuleExtension(getOutputPath(normalizer(n.name)[0])), ssr);
311
354
  };
312
355
 
313
356
  const chunkFile = (n: PreRenderedChunk, ssr: boolean) => {
314
- return hash(
315
- addModuleExtension(
316
- getOutputPath(ensureModuleBase(ensureNoRoot("_" + n.name)))
317
- ),
318
- ssr
319
- );
357
+ return hash(addModuleExtension(getOutputPath(normalizer(n.name)[0])), ssr);
320
358
  };
321
359
 
322
360
  const assetFile = (n: PreRenderedAsset, ssr: boolean) => {
323
- return hash(getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0]))), ssr);
361
+ return hash(getOutputPath(normalizer(n.names[0])[0]), ssr);
324
362
  };
325
363
 
326
364
  const moduleID =
327
365
  typeof options.moduleID === "function"
328
366
  ? options.moduleID
329
367
  : (id: string) => {
330
- if (moduleBasePath !== "" && !id.startsWith(moduleBasePath)) {
331
- id = join(moduleBasePath, id);
368
+ // First normalize the path to handle any leading/trailing slashes
369
+ let normalizedId = id.replace(/^\/+|\/+$/g, "");
370
+
371
+ // If moduleBasePath is set and id doesn't start with it, add it
372
+ if (
373
+ moduleBasePath !== "" &&
374
+ !normalizedId.startsWith(moduleBasePath)
375
+ ) {
376
+ normalizedId = join(moduleBasePath, normalizedId);
332
377
  }
333
- if (!id.startsWith("/")) {
334
- if (id.startsWith(moduleBase)) {
335
- id = id.slice(moduleBase.length);
378
+
379
+ // Handle moduleBase in production
380
+ if (process.env["NODE_ENV"] === "production") {
381
+ if (normalizedId.startsWith(moduleBase)) {
382
+ normalizedId = normalizedId.slice(moduleBase.length);
383
+ } else if (normalizedId.startsWith("/" + moduleBase)) {
384
+ normalizedId = normalizedId.slice(moduleBase.length + 1);
336
385
  }
337
- id = "/" + id;
338
386
  }
339
- if (id.startsWith("/" + moduleBase)) {
340
- id = id.slice(moduleBase.length + 1);
341
- if (!id.startsWith("/")) {
342
- id = "/" + id;
343
- }
387
+
388
+ // Ensure the path starts with a slash
389
+ if (!normalizedId.startsWith("/")) {
390
+ normalizedId = "/" + normalizedId;
344
391
  }
345
- return id;
392
+
393
+ return normalizedId;
346
394
  };
347
395
 
348
396
  const rscOutputPath =
@@ -377,59 +425,17 @@ export const resolveOptions = <
377
425
  : assetFile,
378
426
  };
379
427
 
380
- // Module path configuration
381
- const moduleBase =
382
- typeof options.moduleBase === "string"
383
- ? options.moduleBase
384
- : DEFAULT_CONFIG.MODULE_BASE;
385
-
386
- const moduleBasePath =
387
- typeof options.moduleBasePath === "string"
388
- ? options.moduleBasePath
389
- : process.env.VITE_BASE_URL ?? DEFAULT_CONFIG.MODULE_BASE_PATH;
390
-
391
- const moduleBaseURL =
392
- typeof options.moduleBaseURL === "string"
393
- ? options.moduleBaseURL
394
- : process.env.VITE_BASE_URL ?? DEFAULT_CONFIG.MODULE_BASE_URL;
395
-
396
- const moduleRootPath =
397
- typeof options.moduleRootPath === "string"
398
- ? options.moduleRootPath
399
- : join(projectRoot, outDir, client);
400
-
401
- const publicOrigin =
402
- typeof options.publicOrigin === "string"
403
- ? options.publicOrigin
404
- : process.env.VITE_PUBLIC_ORIGIN ?? DEFAULT_CONFIG.PUBLIC_ORIGIN;
405
-
406
- // Worker and loader paths
407
- const rscWorkerPath =
408
- typeof options.rscWorkerPath === "string"
409
- ? join(projectRoot, options.rscWorkerPath)
410
- : join(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
411
-
412
- const htmlWorkerPath =
413
- typeof options.htmlWorkerPath === "string"
414
- ? join(projectRoot, options.htmlWorkerPath)
415
- : join(pluginRoot, DEFAULT_CONFIG.HTML_WORKER_PATH);
416
-
417
- const loaderPath =
418
- typeof options.loaderPath === "string"
419
- ? join(projectRoot, options.loaderPath)
420
- : join(pluginRoot, DEFAULT_CONFIG.LOADER_PATH);
421
- // these will never be cleaned up, because, we are resolving the user options
422
- // and it's assumed they are relevant until the process stops
423
- if (process.env.VITE_BASE_URL !== moduleBaseURL) {
424
- process.env.VITE_BASE_URL = moduleBaseURL;
425
- }
426
- if (process.env.VITE_PUBLIC_ORIGIN !== publicOrigin) {
427
- process.env.VITE_PUBLIC_ORIGIN = publicOrigin;
428
- }
429
428
  // Auto-discovery configuration
430
429
  const autoDiscover = {
431
430
  moduleExtension:
432
- options.autoDiscover?.moduleExtension ?? DEFAULT_CONFIG.MODULE_EXTENSION,
431
+ options.autoDiscover?.moduleExtension ??
432
+ DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension,
433
+ serverDirective:
434
+ options.autoDiscover?.serverDirective ??
435
+ DEFAULT_CONFIG.AUTO_DISCOVER.serverDirective,
436
+ clientDirective:
437
+ options.autoDiscover?.clientDirective ??
438
+ DEFAULT_CONFIG.AUTO_DISCOVER.clientDirective,
433
439
  modulePattern: testModulePattern,
434
440
  cssPattern: testCss,
435
441
  jsonPattern: testJson,
@@ -444,17 +450,9 @@ export const resolveOptions = <
444
450
  virtualPattern: testVirtual,
445
451
  htmlPattern: testHtml,
446
452
  rscPattern: testRsc,
453
+ isServerFunction: isServerFunction,
454
+ isClientComponent: isClientComponent,
447
455
  };
448
-
449
- const normalizer =
450
- options.normalizer ??
451
- createInputNormalizer({
452
- root: projectRoot,
453
- preserveModulesRoot:
454
- preserveModulesRoot === true ? moduleBase : undefined,
455
- removeExtension: true,
456
- moduleBasePath,
457
- });
458
456
  const pipeableStreamOptions = options.pipeableStreamOptions
459
457
  ? options.pipeableStreamOptions
460
458
  : {};
@@ -486,7 +484,6 @@ export const resolveOptions = <
486
484
  inlineCss: options.css?.inlineCss ?? DEFAULT_CONFIG.CSS.inlineCss,
487
485
  inlineThreshold:
488
486
  options.css?.inlineThreshold ?? DEFAULT_CONFIG.CSS.inlineThreshold,
489
- purgeCss: options.css?.purgeCss ?? DEFAULT_CONFIG.CSS.purgeCss,
490
487
  inlinePatterns:
491
488
  options.css?.inlinePatterns ?? DEFAULT_CONFIG.CSS.inlinePatterns,
492
489
  linkPatterns:
@@ -497,10 +494,10 @@ export const resolveOptions = <
497
494
  loaderPath: loaderPath,
498
495
  clientEntry: options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
499
496
  serverEntry: options.serverEntry ?? DEFAULT_CONFIG.SERVER_ENTRY,
500
- moduleBaseExceptions: options.moduleBaseExceptions ?? [],
497
+ // moduleBaseExceptions: options.moduleBaseExceptions ?? [],
501
498
  autoDiscover: autoDiscover,
502
499
  pipeableStreamOptions,
503
- } as ResolvedUserOptions<InlineCSS>,
500
+ } as ResolvedUserOptions<T, InlineCSS>,
504
501
  };
505
502
  } catch (error) {
506
503
  return {
@@ -3,6 +3,8 @@ import type {
3
3
  ResolvedUserConfig,
4
4
  ResolvedUserOptions,
5
5
  AutoDiscoveredFiles,
6
+ PagePropOpt,
7
+ InlineCssOpt,
6
8
  } from "../types.js";
7
9
  import { join } from "node:path";
8
10
  import type { OutputOptions, PreRenderedAsset, PreRenderedChunk } from "rollup";
@@ -10,11 +12,14 @@ import { DEFAULT_CONFIG } from "./defaults.js";
10
12
 
11
13
  let stashedUserConfig: Record<string, ResolvedUserConfig | null> = {};
12
14
 
13
- export type ResolveUserConfigProps = {
15
+ export type ResolveUserConfigProps<
16
+ T extends PagePropOpt = PagePropOpt,
17
+ InlineCSS extends InlineCssOpt = InlineCssOpt
18
+ > = {
14
19
  condition: "react-client" | "react-server";
15
20
  config: UserConfig;
16
21
  configEnv: ConfigEnv;
17
- userOptions: ResolvedUserOptions;
22
+ userOptions: ResolvedUserOptions<T, InlineCSS>;
18
23
  autoDiscoveredFiles: Pick<AutoDiscoveredFiles, "inputs" | "staticManifest">;
19
24
  };
20
25
 
@@ -22,13 +27,16 @@ export type ResolveUserConfigReturn =
22
27
  | { type: "success"; userConfig: ResolvedUserConfig }
23
28
  | { type: "error"; error: Error };
24
29
 
25
- export function resolveUserConfig({
30
+ export function resolveUserConfig<
31
+ T extends PagePropOpt = PagePropOpt,
32
+ InlineCSS extends InlineCssOpt = InlineCssOpt
33
+ >({
26
34
  condition,
27
35
  config,
28
36
  configEnv,
29
37
  userOptions,
30
38
  autoDiscoveredFiles,
31
- }: ResolveUserConfigProps): ResolveUserConfigReturn {
39
+ }: ResolveUserConfigProps<T, InlineCSS>): ResolveUserConfigReturn {
32
40
  const ssr =
33
41
  typeof config.build?.ssr === "boolean"
34
42
  ? config.build?.ssr
@@ -62,6 +70,9 @@ export function resolveUserConfig({
62
70
  fallback: (info: T, ssr: boolean) => string,
63
71
  ssr: boolean
64
72
  ) => {
73
+ if ("source" in info && info.source === "") {
74
+ return "";
75
+ }
65
76
  if (!ssr || !input) {
66
77
  return fallback(info, false);
67
78
  }
@@ -234,6 +245,7 @@ export function resolveUserConfig({
234
245
  // client build options
235
246
  build: {
236
247
  ...config.build,
248
+ modulePreload: config.build?.modulePreload ?? false,
237
249
  emptyOutDir: config.build?.emptyOutDir ?? true,
238
250
  outDir: config.build?.outDir ?? join(userOptions.build.outDir, envDir),
239
251
  assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
@@ -246,7 +258,9 @@ export function resolveUserConfig({
246
258
  minify: minify,
247
259
  rollupOptions: {
248
260
  ...config.build?.rollupOptions,
249
- input: autoDiscoveredFiles.inputs,
261
+ input: {
262
+ ...autoDiscoveredFiles.inputs,
263
+ },
250
264
  output: newOutput,
251
265
  preserveEntrySignatures:
252
266
  config.build?.rollupOptions?.preserveEntrySignatures ??
@@ -285,6 +299,7 @@ export function resolveUserConfig({
285
299
  // server build options
286
300
  build: {
287
301
  ...config.build,
302
+ modulePreload: config.build?.modulePreload ?? false,
288
303
  emptyOutDir: config.build?.emptyOutDir ?? true,
289
304
  outDir: config.build?.outDir ?? join(userOptions.build.outDir, envDir),
290
305
  target: config.build?.target ?? "node18",
@@ -1,19 +1,53 @@
1
+ import type { Logger } from "vite";
2
+
1
3
  export function toError(error: unknown): {
2
4
  name: string;
3
5
  message: string;
4
6
  stack?: string;
7
+ cause?: unknown;
5
8
  } {
9
+ if(typeof error === "string") {
10
+ return {
11
+ name: "Error",
12
+ message: error,
13
+ stack: undefined,
14
+ cause: undefined,
15
+ };
16
+ }
6
17
  return error instanceof Error
7
18
  ? error
8
19
  : typeof error === "object" && error !== null
9
20
  ? {
10
21
  name: "name" in error ? String(error.name) : "Unknown Error",
11
- message: "message" in error ? String(error.message) : "Unknown Error",
22
+ message: "message" in error ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : "Unknown Error",
12
23
  stack: "stack" in error ? String(error.stack) : undefined,
24
+ cause: "cause" in error ? toError(error.cause) : error,
13
25
  }
14
26
  : {
15
27
  name: "Unknown Error",
16
28
  message: typeof error === "string" ? error : "Unknown Error",
17
29
  stack: undefined,
30
+ cause: error,
18
31
  };
19
32
  }
33
+
34
+ export function logError(error: unknown, logger: Logger | Console = console) {
35
+ const err = toError(error);
36
+ if (process.env["NODE_ENV"] !== "production") {
37
+ console.trace(err)
38
+
39
+ if (err.stack && err.stack.includes(err.message)) {
40
+ logger.error(err.stack);
41
+ } else if (err.stack) {
42
+ logger.error(err.message + "\n" + err.stack, {
43
+ error: err,
44
+ });
45
+ } else {
46
+ logger.error(err.message, {
47
+ error: err,
48
+ });
49
+ }
50
+ } else {
51
+ logger.error(err.message);
52
+ }
53
+ }
@@ -1,44 +1,105 @@
1
1
  import type { SerializableRecord } from "../types.js";
2
2
 
3
3
  // Helper function to serialize RegExp objects
4
- function serializeRegExp(regex: RegExp): { source: string; flags: string; __isRegExp: boolean } {
4
+ function serializeRegExp(regex: RegExp): {
5
+ source: string;
6
+ flags: string;
7
+ __isRegExp: boolean;
8
+ } {
5
9
  return {
6
10
  source: regex.source,
7
11
  flags: regex.flags,
8
- __isRegExp: true
12
+ __isRegExp: true,
9
13
  };
10
14
  }
11
15
 
12
- export function cleanObject<T>(obj: T, knownNonSerializableFunctions: Set<string> = new Set(), currentPath: string = ''): SerializableRecord & T {
13
- if (obj === null || obj === undefined) return obj as Extract<SerializableRecord, T>;
14
- if (typeof obj !== 'object') return obj as Extract<SerializableRecord, T>;
15
- if (obj instanceof RegExp) return serializeRegExp(obj) as unknown as Extract<SerializableRecord, T>;
16
+ const isSerializable = (
17
+ x: unknown
18
+ ): x is
19
+ | number
20
+ | bigint
21
+ | boolean
22
+ | string
23
+ | undefined
24
+ | null
25
+ | Uint8Array
26
+ | Uint16Array
27
+ | Uint32Array
28
+ | Int8Array
29
+ | Int16Array
30
+ | Int32Array => {
31
+ return (
32
+ typeof x === "number" ||
33
+ typeof x === "bigint" ||
34
+ typeof x === "boolean" ||
35
+ typeof x === "string" ||
36
+ x instanceof Buffer ||
37
+ (Array.isArray(x) &&
38
+ (!x.length ||
39
+ x instanceof Uint8Array ||
40
+ x instanceof Uint16Array ||
41
+ x instanceof Uint32Array ||
42
+ x instanceof Int8Array ||
43
+ x instanceof Int16Array ||
44
+ x instanceof Int32Array))
45
+ );
46
+ };
47
+
48
+ export function cleanObject<T>(
49
+ obj: T,
50
+ knownNonSerializableFunctions: Set<string> = new Set(),
51
+ currentPath: string = ""
52
+ ): SerializableRecord & T {
53
+ if (typeof obj !== "object" || obj == null) return obj as Extract<SerializableRecord, T>;
54
+ if (isSerializable(obj)) return obj as Extract<SerializableRecord, T>;
55
+
16
56
  if (Array.isArray(obj)) {
17
- return obj.map((x, i) => cleanObject(x, knownNonSerializableFunctions, `${currentPath}[${i}]`)).filter(x => x !== undefined) as Extract<SerializableRecord, T>;
57
+ return obj
58
+ .map((x, i) =>
59
+ cleanObject(x, knownNonSerializableFunctions, `${currentPath}[${i}]`)
60
+ )
61
+ .filter((x) => x !== undefined) as Extract<SerializableRecord, T>;
18
62
  }
19
-
63
+ if (obj instanceof RegExp)
64
+ return serializeRegExp(obj) as unknown as Extract<SerializableRecord, T>;
65
+
20
66
  const result: Record<string, any> = {};
21
67
  for (const [key, value] of Object.entries(obj)) {
22
68
  const fullPath = currentPath ? `${currentPath}.${key}` : key;
23
- const normalizedPath = fullPath.replace(/\[\d+\]/g, '[]');
69
+ const normalizedPath = fullPath.replace(/\[\d+\]/g, "[]");
24
70
  // Skip if it's a function or known non-serializable property
25
- if (typeof value === 'function' || knownNonSerializableFunctions.has(normalizedPath) || knownNonSerializableFunctions.has(key)) {
71
+ if(isSerializable(value)) {
72
+ result[key] = value;
73
+ continue;
74
+ }
75
+ if (
76
+ typeof value === "function" ||
77
+ knownNonSerializableFunctions.has(normalizedPath) ||
78
+ knownNonSerializableFunctions.has(key)
79
+ ) {
26
80
  continue;
27
81
  }
28
82
 
29
83
  // Handle nested objects
30
- if (typeof value === 'object' && value !== null) {
84
+ if (typeof value === "object" && value !== null) {
31
85
  // Check if the object has any functions
32
86
  const hasFunctions = Object.entries(value).some(([k, v]) => {
33
87
  const nestedPath = `${normalizedPath}.${k}`;
34
- return typeof v === 'function' || knownNonSerializableFunctions.has(nestedPath);
88
+ return (
89
+ typeof v === "function" ||
90
+ knownNonSerializableFunctions.has(nestedPath)
91
+ );
35
92
  });
36
93
 
37
94
  if (hasFunctions) {
38
95
  continue;
39
96
  }
40
97
 
41
- const cleaned = cleanObject(value, knownNonSerializableFunctions, `${normalizedPath}.${key}`);
98
+ const cleaned = cleanObject(
99
+ value,
100
+ knownNonSerializableFunctions,
101
+ `${normalizedPath}.${key}`
102
+ );
42
103
  if (cleaned !== undefined && Object.keys(cleaned).length > 0) {
43
104
  result[key] = cleaned;
44
105
  }
@@ -46,5 +107,8 @@ export function cleanObject<T>(obj: T, knownNonSerializableFunctions: Set<string
46
107
  result[key] = value;
47
108
  }
48
109
  }
49
- return (Object.keys(result).length > 0 ? result : {}) as Extract<SerializableRecord, T>;
50
- }
110
+ return (Object.keys(result).length > 0 ? result : {}) as Extract<
111
+ SerializableRecord,
112
+ T
113
+ >;
114
+ }