vite-plugin-react-server 1.0.2 → 1.1.0

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 (490) hide show
  1. package/README.md +49 -76
  2. package/bin/patch.mjs +27 -20
  3. package/dist/_virtual/dynamic-import-helper.js +24 -0
  4. package/dist/_virtual/dynamic-import-helper.js.map +1 -0
  5. package/dist/client.d.ts +1 -1
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +1 -1
  8. package/dist/index.d.ts +2 -4
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +9 -26
  11. package/dist/index.js.map +1 -1
  12. package/dist/package.json +24 -14
  13. package/dist/plugin/components.d.ts +1 -1
  14. package/dist/plugin/components.d.ts.map +1 -1
  15. package/dist/plugin/components.js +1 -1
  16. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
  17. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
  18. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
  19. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
  20. package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
  21. package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
  22. package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
  23. package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
  24. package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
  25. package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
  26. package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
  27. package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
  28. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
  29. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
  30. package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
  31. package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
  32. package/dist/plugin/config/defaults.d.ts +18 -14
  33. package/dist/plugin/config/defaults.d.ts.map +1 -1
  34. package/dist/plugin/config/defaults.js +42 -21
  35. package/dist/plugin/config/defaults.js.map +1 -1
  36. package/dist/plugin/config/getCondition.d.ts +1 -1
  37. package/dist/plugin/config/getCondition.d.ts.map +1 -1
  38. package/dist/plugin/config/getCondition.js +2 -2
  39. package/dist/plugin/config/getCondition.js.map +1 -1
  40. package/dist/plugin/config/getPaths.d.ts +0 -1
  41. package/dist/plugin/config/getPaths.d.ts.map +1 -1
  42. package/dist/plugin/config/getPaths.js.map +1 -1
  43. package/dist/plugin/config/index.d.ts +0 -1
  44. package/dist/plugin/config/index.d.ts.map +1 -1
  45. package/dist/plugin/config/index.js +0 -1
  46. package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
  47. package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
  48. package/dist/plugin/config/resolveAutoDiscover.js +128 -0
  49. package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
  50. package/dist/plugin/config/resolveOptions.d.ts +1 -1
  51. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  52. package/dist/plugin/config/resolveOptions.js +109 -77
  53. package/dist/plugin/config/resolveOptions.js.map +1 -1
  54. package/dist/plugin/config/resolvePages.d.ts +0 -1
  55. package/dist/plugin/config/resolvePages.d.ts.map +1 -1
  56. package/dist/plugin/config/resolvePages.js +6 -8
  57. package/dist/plugin/config/resolvePages.js.map +1 -1
  58. package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
  59. package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
  60. package/dist/plugin/config/resolveUrlOption.js +37 -0
  61. package/dist/plugin/config/resolveUrlOption.js.map +1 -0
  62. package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
  63. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  64. package/dist/plugin/config/resolveUserConfig.js +80 -132
  65. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  66. package/dist/plugin/copy.d.ts +7 -0
  67. package/dist/plugin/copy.d.ts.map +1 -0
  68. package/dist/plugin/copy.js +30 -0
  69. package/dist/plugin/css-collector-elements.d.ts +4 -0
  70. package/dist/plugin/css-collector-elements.d.ts.map +1 -0
  71. package/dist/plugin/css-collector-elements.js +19 -0
  72. package/dist/plugin/css-collector-elements.js.map +1 -0
  73. package/dist/plugin/css-collector.d.ts +2 -8
  74. package/dist/plugin/css-collector.d.ts.map +1 -1
  75. package/dist/plugin/css-collector.js +9 -36
  76. package/dist/plugin/css-collector.js.map +1 -1
  77. package/dist/plugin/helpers/cleanObject.d.ts +3 -0
  78. package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
  79. package/dist/plugin/helpers/cleanObject.js +47 -0
  80. package/dist/plugin/helpers/cleanObject.js.map +1 -0
  81. package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
  82. package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
  83. package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
  84. package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
  85. package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
  86. package/dist/plugin/helpers/collectManifestCss.js +44 -0
  87. package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
  88. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
  89. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
  90. package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
  91. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
  92. package/dist/plugin/helpers/createCssProps.d.ts +25 -0
  93. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
  94. package/dist/plugin/helpers/createCssProps.js +57 -0
  95. package/dist/plugin/helpers/createCssProps.js.map +1 -0
  96. package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
  97. package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
  98. package/dist/plugin/helpers/createEventHandler.js +36 -0
  99. package/dist/plugin/helpers/createEventHandler.js.map +1 -0
  100. package/dist/plugin/helpers/createHandler.d.ts +7 -13
  101. package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
  102. package/dist/plugin/helpers/createHandler.js +54 -96
  103. package/dist/plugin/helpers/createHandler.js.map +1 -1
  104. package/dist/plugin/helpers/createRscStream.d.ts +12 -26
  105. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  106. package/dist/plugin/helpers/createRscStream.js +105 -51
  107. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  108. package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
  109. package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
  110. package/dist/plugin/helpers/defaultFileWriter.js +1 -0
  111. package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
  112. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
  113. package/dist/plugin/helpers/getBundleManifest.js +30 -22
  114. package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
  115. package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
  116. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
  117. package/dist/plugin/helpers/getRouteFiles.js +36 -0
  118. package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
  119. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  120. package/dist/plugin/helpers/inputNormalizer.js +38 -32
  121. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  122. package/dist/plugin/helpers/metrics.d.ts +11 -0
  123. package/dist/plugin/helpers/metrics.d.ts.map +1 -0
  124. package/dist/plugin/helpers/metrics.js +35 -0
  125. package/dist/plugin/helpers/metrics.js.map +1 -0
  126. package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
  127. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
  128. package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
  129. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
  130. package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
  131. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
  132. package/dist/plugin/helpers/serializeUserOptions.js +182 -0
  133. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
  134. package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
  135. package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
  136. package/dist/plugin/helpers/stashReturnValue.js +14 -0
  137. package/dist/plugin/helpers/tryManifest.d.ts +5 -3
  138. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  139. package/dist/plugin/helpers/tryManifest.js +16 -7
  140. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  141. package/dist/plugin/html.d.ts +2 -3
  142. package/dist/plugin/html.d.ts.map +1 -1
  143. package/dist/plugin/html.js +7 -1
  144. package/dist/plugin/html.js.map +1 -1
  145. package/dist/plugin/index.d.ts +1 -2
  146. package/dist/plugin/index.d.ts.map +1 -1
  147. package/dist/plugin/index.js +3 -1
  148. package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
  149. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  150. package/dist/plugin/loader/createBuildLoader.js +98 -33
  151. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  152. package/dist/plugin/loader/css-loader.development.d.ts +57 -0
  153. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
  154. package/dist/plugin/loader/css-loader.development.js +81 -0
  155. package/dist/plugin/loader/css-loader.development.js.map +1 -0
  156. package/dist/plugin/loader/css-loader.production.d.ts +31 -0
  157. package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
  158. package/dist/plugin/loader/css-loader.production.js +45 -0
  159. package/dist/plugin/loader/css-loader.production.js.map +1 -0
  160. package/dist/plugin/loader/index.d.ts +2 -0
  161. package/dist/plugin/loader/index.d.ts.map +1 -0
  162. package/dist/plugin/loader/index.js +1 -0
  163. package/dist/plugin/loader/plugin.d.ts +22 -0
  164. package/dist/plugin/loader/plugin.d.ts.map +1 -0
  165. package/dist/plugin/loader/plugin.js +27 -0
  166. package/dist/plugin/loader/react-loader.d.ts +3 -7
  167. package/dist/plugin/loader/react-loader.d.ts.map +1 -1
  168. package/dist/plugin/loader/react-loader.js +85 -30
  169. package/dist/plugin/loader/react-loader.js.map +1 -1
  170. package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
  171. package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
  172. package/dist/plugin/loader/temporaryReferences.js +11 -0
  173. package/dist/plugin/loader/temporaryReferences.js.map +1 -0
  174. package/dist/plugin/moduleRefs.d.ts +7 -0
  175. package/dist/plugin/moduleRefs.d.ts.map +1 -0
  176. package/dist/plugin/moduleRefs.js +17 -0
  177. package/dist/plugin/moduleRefs.js.map +1 -0
  178. package/dist/plugin/plugin.client.d.ts +3 -0
  179. package/dist/plugin/plugin.client.d.ts.map +1 -0
  180. package/dist/plugin/plugin.client.js +19 -0
  181. package/dist/plugin/plugin.client.js.map +1 -0
  182. package/dist/plugin/plugin.d.ts +1 -5
  183. package/dist/plugin/plugin.d.ts.map +1 -1
  184. package/dist/plugin/plugin.js +3 -9
  185. package/dist/plugin/plugin.server.d.ts +3 -0
  186. package/dist/plugin/plugin.server.d.ts.map +1 -0
  187. package/dist/plugin/plugin.server.js +28 -0
  188. package/dist/plugin/plugin.server.js.map +1 -0
  189. package/dist/plugin/preserver/plugin.js +1 -1
  190. package/dist/plugin/preserver/plugin.js.map +1 -1
  191. package/dist/plugin/react-client/index.d.ts +1 -2
  192. package/dist/plugin/react-client/index.d.ts.map +1 -1
  193. package/dist/plugin/react-client/index.js +1 -19
  194. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  195. package/dist/plugin/react-client/plugin.js +60 -219
  196. package/dist/plugin/react-client/plugin.js.map +1 -1
  197. package/dist/plugin/react-client/server.d.ts +27 -0
  198. package/dist/plugin/react-client/server.d.ts.map +1 -0
  199. package/dist/plugin/react-client/server.js +197 -0
  200. package/dist/plugin/react-client/server.js.map +1 -0
  201. package/dist/plugin/react-server/index.d.ts +1 -2
  202. package/dist/plugin/react-server/index.d.ts.map +1 -1
  203. package/dist/plugin/react-server/index.js +1 -21
  204. package/dist/plugin/react-server/plugin.d.ts +0 -1
  205. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  206. package/dist/plugin/react-server/plugin.js +60 -186
  207. package/dist/plugin/react-server/plugin.js.map +1 -1
  208. package/dist/plugin/react-server/server.d.ts +9 -0
  209. package/dist/plugin/react-server/server.d.ts.map +1 -0
  210. package/dist/plugin/react-server/server.js +120 -0
  211. package/dist/plugin/react-server/server.js.map +1 -0
  212. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
  213. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
  214. package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
  215. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
  216. package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
  217. package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
  218. package/dist/plugin/react-static/collectRscContent.js +49 -0
  219. package/dist/plugin/react-static/collectRscContent.js.map +1 -0
  220. package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
  221. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
  222. package/dist/plugin/react-static/configurePreviewServer.js +67 -0
  223. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
  224. package/dist/plugin/react-static/fileWriter.d.ts +23 -0
  225. package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
  226. package/dist/plugin/react-static/fileWriter.js +65 -0
  227. package/dist/plugin/react-static/fileWriter.js.map +1 -0
  228. package/dist/plugin/react-static/plugin.d.ts +15 -0
  229. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  230. package/dist/plugin/react-static/plugin.js +248 -149
  231. package/dist/plugin/react-static/plugin.js.map +1 -1
  232. package/dist/plugin/react-static/renderPage.d.ts +3 -0
  233. package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
  234. package/dist/plugin/react-static/renderPage.js +116 -0
  235. package/dist/plugin/react-static/renderPage.js.map +1 -0
  236. package/dist/plugin/react-static/renderPages.d.ts +3 -0
  237. package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
  238. package/dist/plugin/react-static/renderPages.js +125 -0
  239. package/dist/plugin/react-static/renderPages.js.map +1 -0
  240. package/dist/plugin/react-static/renderStreams.d.ts +26 -0
  241. package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
  242. package/dist/plugin/react-static/renderStreams.js +27 -0
  243. package/dist/plugin/react-static/renderStreams.js.map +1 -0
  244. package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
  245. package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
  246. package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
  247. package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
  248. package/dist/plugin/react-static/streamHandler.d.ts +2 -0
  249. package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
  250. package/dist/plugin/react-static/streamHandler.js +1 -0
  251. package/dist/plugin/react-static/types.d.ts +11 -0
  252. package/dist/plugin/react-static/types.d.ts.map +1 -1
  253. package/dist/plugin/resolvePage.d.ts +26 -9
  254. package/dist/plugin/resolvePage.d.ts.map +1 -1
  255. package/dist/plugin/resolvePage.js +41 -39
  256. package/dist/plugin/resolvePage.js.map +1 -1
  257. package/dist/plugin/resolveProps.d.ts +40 -7
  258. package/dist/plugin/resolveProps.d.ts.map +1 -1
  259. package/dist/plugin/resolveProps.js +100 -75
  260. package/dist/plugin/resolveProps.js.map +1 -1
  261. package/dist/plugin/root.d.ts +1 -0
  262. package/dist/plugin/root.d.ts.map +1 -1
  263. package/dist/plugin/root.js +1 -0
  264. package/dist/plugin/root.js.map +1 -1
  265. package/dist/plugin/transformer/index.d.ts +2 -1
  266. package/dist/plugin/transformer/index.d.ts.map +1 -1
  267. package/dist/plugin/transformer/index.js +2 -1
  268. package/dist/plugin/transformer/plugin.client.d.ts +4 -0
  269. package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
  270. package/dist/plugin/transformer/plugin.client.js +83 -0
  271. package/dist/plugin/transformer/plugin.client.js.map +1 -0
  272. package/dist/plugin/transformer/plugin.d.ts +1 -27
  273. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  274. package/dist/plugin/transformer/plugin.js +3 -87
  275. package/dist/plugin/transformer/plugin.js.map +1 -1
  276. package/dist/plugin/transformer/plugin.server.d.ts +4 -0
  277. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
  278. package/dist/plugin/transformer/plugin.server.js +76 -0
  279. package/dist/plugin/transformer/plugin.server.js.map +1 -0
  280. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
  281. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
  282. package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
  283. package/dist/plugin/types/css-tracking.d.ts +6 -0
  284. package/dist/plugin/types/css-tracking.d.ts.map +1 -0
  285. package/dist/plugin/types/css-tracking.js +1 -0
  286. package/dist/plugin/types.d.ts +372 -86
  287. package/dist/plugin/types.d.ts.map +1 -1
  288. package/dist/plugin/types.js +1 -1
  289. package/dist/plugin/vendor.client.d.ts +4 -0
  290. package/dist/plugin/vendor.client.d.ts.map +1 -0
  291. package/dist/plugin/vendor.client.js +16 -0
  292. package/dist/plugin/vendor.client.js.map +1 -0
  293. package/dist/plugin/vendor.server.d.ts +4 -0
  294. package/dist/plugin/vendor.server.d.ts.map +1 -0
  295. package/dist/plugin/vendor.server.js +16 -0
  296. package/dist/plugin/vendor.server.js.map +1 -0
  297. package/dist/plugin/worker/createWorker.d.ts +25 -7
  298. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  299. package/dist/plugin/worker/createWorker.js +108 -33
  300. package/dist/plugin/worker/createWorker.js.map +1 -1
  301. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
  302. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
  303. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
  304. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
  305. package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
  306. package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
  307. package/dist/plugin/worker/html/html-worker.development.js +3 -17
  308. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  309. package/dist/plugin/worker/html/html-worker.production.js +12 -5
  310. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  311. package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
  312. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  313. package/dist/plugin/worker/html/messageHandler.js +87 -84
  314. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  315. package/dist/plugin/worker/html/types.d.ts +18 -0
  316. package/dist/plugin/worker/html/types.d.ts.map +1 -0
  317. package/dist/plugin/worker/html/types.js +1 -0
  318. package/dist/plugin/worker/registerLoaders.d.ts +9 -0
  319. package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
  320. package/dist/plugin/worker/registerLoaders.js +45 -0
  321. package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
  322. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
  323. package/dist/plugin/worker/rsc/handleRender.js +147 -0
  324. package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
  325. package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
  326. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  327. package/dist/plugin/worker/rsc/messageHandler.js +47 -112
  328. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  329. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
  330. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
  331. package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
  332. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  333. package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
  334. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  335. package/dist/plugin/worker/rsc/state.d.ts +73 -2
  336. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  337. package/dist/plugin/worker/rsc/state.js +40 -3
  338. package/dist/plugin/worker/rsc/state.js.map +1 -1
  339. package/dist/plugin/worker/sendMessage.d.ts +3 -0
  340. package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
  341. package/dist/plugin/worker/sendMessage.js +48 -0
  342. package/dist/plugin/worker/types.d.ts +218 -76
  343. package/dist/plugin/worker/types.d.ts.map +1 -1
  344. package/dist/server.d.ts +1 -1
  345. package/dist/server.d.ts.map +1 -1
  346. package/dist/server.js +6 -1
  347. package/dist/server.js.map +1 -1
  348. package/dist/tsconfig.tsbuildinfo +1 -1
  349. package/package.json +24 -14
  350. package/plugin/components.ts +1 -1
  351. package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
  352. package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
  353. package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
  354. package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
  355. package/plugin/config/defaults.tsx +38 -29
  356. package/plugin/config/getCondition.ts +7 -3
  357. package/plugin/config/getPaths.ts +1 -7
  358. package/plugin/config/index.ts +0 -1
  359. package/plugin/config/resolveAutoDiscover.ts +177 -0
  360. package/plugin/config/resolveOptions.ts +220 -118
  361. package/plugin/config/resolvePages.ts +5 -7
  362. package/plugin/config/resolveUrlOption.ts +43 -0
  363. package/plugin/config/resolveUserConfig.ts +116 -166
  364. package/plugin/copy.ts +39 -0
  365. package/plugin/css-collector-elements.tsx +21 -0
  366. package/plugin/css-collector.tsx +20 -53
  367. package/plugin/helpers/cleanObject.ts +50 -0
  368. package/plugin/helpers/collectBundleManifestCss.ts +160 -0
  369. package/plugin/helpers/collectManifestCss.ts +61 -0
  370. package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
  371. package/plugin/helpers/createCssProps.tsx +85 -0
  372. package/plugin/helpers/createEventHandler.ts +44 -0
  373. package/plugin/helpers/createHandler.ts +57 -126
  374. package/plugin/helpers/createRscStream.tsx +156 -0
  375. package/plugin/helpers/defaultFileWriter.ts +0 -0
  376. package/plugin/helpers/getBundleManifest.ts +42 -37
  377. package/plugin/helpers/getRouteFiles.ts +47 -0
  378. package/plugin/helpers/inputNormalizer.ts +16 -10
  379. package/plugin/helpers/metrics.ts +64 -0
  380. package/plugin/helpers/resolvePageAndProps.ts +81 -0
  381. package/plugin/helpers/serializeUserOptions.ts +209 -0
  382. package/plugin/helpers/stashReturnValue.ts +16 -0
  383. package/plugin/helpers/tryManifest.ts +35 -18
  384. package/plugin/html.tsx +14 -3
  385. package/plugin/index.ts +5 -2
  386. package/plugin/loader/createBuildLoader.ts +152 -47
  387. package/plugin/loader/css-loader.development.ts +157 -0
  388. package/plugin/loader/css-loader.production.ts +86 -0
  389. package/plugin/loader/index.ts +1 -0
  390. package/plugin/loader/plugin.ts +33 -0
  391. package/plugin/loader/react-loader.ts +109 -41
  392. package/plugin/loader/temporaryReferences.ts +3 -0
  393. package/plugin/moduleRefs.ts +11 -0
  394. package/plugin/plugin.client.ts +12 -0
  395. package/plugin/plugin.server.ts +25 -0
  396. package/plugin/plugin.ts +5 -9
  397. package/plugin/preserver/plugin.ts +1 -1
  398. package/plugin/react-client/index.ts +1 -12
  399. package/plugin/react-client/plugin.ts +70 -259
  400. package/plugin/react-client/server.ts +276 -0
  401. package/plugin/react-server/index.ts +1 -14
  402. package/plugin/react-server/plugin.ts +69 -220
  403. package/plugin/react-server/server.ts +128 -0
  404. package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
  405. package/plugin/react-static/collectRscContent.ts +77 -0
  406. package/plugin/react-static/configurePreviewServer.ts +68 -0
  407. package/plugin/react-static/fileWriter.ts +103 -0
  408. package/plugin/react-static/plugin.ts +308 -181
  409. package/plugin/react-static/renderPage.ts +151 -0
  410. package/plugin/react-static/renderPages.ts +154 -0
  411. package/plugin/react-static/renderStreams.ts +48 -0
  412. package/plugin/react-static/rscToHtmlStream.ts +85 -0
  413. package/plugin/react-static/streamHandler.ts +0 -0
  414. package/plugin/react-static/types.ts +10 -0
  415. package/plugin/resolvePage.ts +67 -57
  416. package/plugin/resolveProps.ts +148 -104
  417. package/plugin/root.ts +1 -1
  418. package/plugin/transformer/index.ts +2 -1
  419. package/plugin/transformer/plugin.client.ts +109 -0
  420. package/plugin/transformer/plugin.server.ts +98 -0
  421. package/plugin/transformer/plugin.ts +2 -115
  422. package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
  423. package/plugin/types/css-tracking.ts +5 -0
  424. package/plugin/types/react-server-dom-esm.d.ts +54 -0
  425. package/plugin/types.ts +508 -97
  426. package/plugin/vendor.client.ts +12 -0
  427. package/plugin/vendor.server.ts +12 -0
  428. package/plugin/worker/createWorker.ts +158 -53
  429. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
  430. package/plugin/worker/html/html-worker.development.tsx +5 -75
  431. package/plugin/worker/html/html-worker.production.tsx +18 -7
  432. package/plugin/worker/html/messageHandler.tsx +126 -0
  433. package/plugin/worker/html/types.ts +19 -0
  434. package/plugin/worker/registerLoaders.ts +54 -0
  435. package/plugin/worker/rsc/handleRender.ts +180 -0
  436. package/plugin/worker/rsc/messageHandler.tsx +58 -132
  437. package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
  438. package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
  439. package/plugin/worker/rsc/state.ts +79 -2
  440. package/plugin/worker/sendMessage.ts +49 -0
  441. package/plugin/worker/types.ts +299 -100
  442. package/scripts/check-react-version.mjs +60 -48
  443. package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
  444. package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
  445. package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
  446. package/tsconfig.json +7 -2
  447. package/dist/plugin/assertServerCondition.d.ts +0 -6
  448. package/dist/plugin/assertServerCondition.d.ts.map +0 -1
  449. package/dist/plugin/assertServerCondition.js +0 -13
  450. package/dist/plugin/checkFilesExist.d.ts +0 -3
  451. package/dist/plugin/checkFilesExist.d.ts.map +0 -1
  452. package/dist/plugin/checkFilesExist.js +0 -67
  453. package/dist/plugin/checkFilesExist.js.map +0 -1
  454. package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
  455. package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
  456. package/dist/plugin/collect-manifest-client-files.js +0 -131
  457. package/dist/plugin/collect-manifest-client-files.js.map +0 -1
  458. package/dist/plugin/config/getWorkerPath.d.ts +0 -2
  459. package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
  460. package/dist/plugin/config/getWorkerPath.js +0 -4
  461. package/dist/plugin/copy-dir.d.ts +0 -4
  462. package/dist/plugin/copy-dir.d.ts.map +0 -1
  463. package/dist/plugin/copy-dir.js +0 -25
  464. package/dist/plugin/copy-dir.js.map +0 -1
  465. package/dist/plugin/css-collector-inline.d.ts +0 -10
  466. package/dist/plugin/css-collector-inline.d.ts.map +0 -1
  467. package/dist/plugin/css-collector-inline.js +0 -55
  468. package/dist/plugin/css-collector-inline.js.map +0 -1
  469. package/dist/plugin/loader/css-loader.d.ts +0 -16
  470. package/dist/plugin/loader/css-loader.d.ts.map +0 -1
  471. package/dist/plugin/loader/css-loader.js +0 -70
  472. package/dist/plugin/loader/css-loader.js.map +0 -1
  473. package/dist/plugin/react-client/index.js.map +0 -1
  474. package/dist/plugin/react-server/index.js.map +0 -1
  475. package/dist/plugin/worker/html/renderPages.d.ts +0 -26
  476. package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
  477. package/dist/plugin/worker/html/renderPages.js +0 -241
  478. package/dist/plugin/worker/html/renderPages.js.map +0 -1
  479. package/plugin/assertServerCondition.ts +0 -12
  480. package/plugin/checkFilesExist.ts +0 -66
  481. package/plugin/collect-manifest-client-files.ts +0 -167
  482. package/plugin/config/getWorkerPath.ts +0 -5
  483. package/plugin/copy-dir.ts +0 -27
  484. package/plugin/css-collector-inline.tsx +0 -60
  485. package/plugin/helpers/createRscStream.ts +0 -109
  486. package/plugin/loader/css-loader.ts +0 -94
  487. package/plugin/worker/html/messageHandler.ts +0 -130
  488. package/plugin/worker/html/renderPages.ts +0 -293
  489. package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
  490. package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
@@ -3,122 +3,57 @@
3
3
  * Copyright (c) Nico Brinkkemper
4
4
  * MIT License
5
5
  */
6
- import { join } from 'node:path';
7
- import { PassThrough } from 'node:stream';
8
- import { parentPort } from 'node:worker_threads';
9
- import React__default from 'react';
10
- import { addCssFile, cssFiles } from './state.js';
11
- import { InlineCssCollector } from '../../css-collector-inline.js';
12
- import { createRscStream } from '../../helpers/createRscStream.js';
13
- import { createLogger } from 'vite';
6
+ import { parentPort, workerData } from 'node:worker_threads';
7
+ import { addCssFileContent, hmrState } from './state.js';
8
+ import { handleRender } from './handleRender.js';
14
9
 
15
- async function messageHandler(message) {
16
- switch (message.type) {
10
+ function messageHandler(msg, port = parentPort, reactLoaderPort, cssLoaderPort) {
11
+ if (!port) {
12
+ throw new Error("No port found");
13
+ }
14
+ switch (msg.type) {
17
15
  case "RSC_RENDER":
18
- const {
19
- id,
20
- pageImport,
21
- propsImport,
22
- pageExportName,
23
- propsExportName,
24
- url,
25
- outDir,
26
- projectRoot,
27
- moduleRootPath,
28
- moduleBaseURL,
29
- moduleBasePath,
30
- moduleBase,
31
- pipableStreamOptions
32
- } = message;
33
- try {
34
- const [Component, propsModule] = await Promise.all([
35
- import(join(projectRoot, pageImport)),
36
- import(join(projectRoot, propsImport))
37
- ]);
38
- const propsAtExport = propsModule[propsExportName];
39
- const props = await Promise.resolve(
40
- typeof propsAtExport === "function" ? propsAtExport(url) : propsAtExport
41
- );
42
- const PageComponent = Component[pageExportName];
43
- const stream = createRscStream({
44
- Html: React__default.Fragment,
45
- Page: PageComponent,
46
- CssCollector: InlineCssCollector,
47
- loader: (id2) => import(id2).then((m) => m.default),
48
- props,
49
- moduleBase,
50
- moduleRootPath,
51
- moduleBasePath,
52
- moduleBaseURL,
53
- logger: createLogger(),
54
- inlineCss: true,
55
- cssFiles: Array.from(cssFiles.values()).map((css) => ({
56
- type: "text/css",
57
- content: css,
58
- path: css
59
- })),
60
- route: url,
61
- url: typeof moduleBaseURL === "string" && moduleBaseURL !== "" ? new URL(url, moduleBaseURL).toString() : url,
62
- root: projectRoot,
63
- pipableStreamOptions: {
64
- ...pipableStreamOptions,
65
- onError: (error) => {
66
- if (typeof pipableStreamOptions.onError === "function") {
67
- pipableStreamOptions.onError(error);
68
- }
69
- parentPort?.postMessage({
70
- type: "ERROR",
71
- id,
72
- error: error instanceof Error ? error.message : String(error)
73
- });
74
- },
75
- onPostpone: (reason) => {
76
- if (typeof pipableStreamOptions.onPostpone === "function") {
77
- pipableStreamOptions.onPostpone(reason);
78
- }
79
- parentPort?.postMessage({
80
- type: "POSTPONE",
81
- id,
82
- reason
83
- });
84
- }
85
- }
86
- });
87
- if (!stream) {
88
- throw new Error("Failed to create stream");
89
- }
90
- const passThrough = new PassThrough();
91
- stream.pipe(passThrough);
92
- passThrough.on("data", (chunk) => {
93
- parentPort?.postMessage({
94
- type: "RSC_CHUNK",
95
- id,
96
- chunk: chunk.toString(),
97
- moduleRootPath: moduleBasePath,
98
- moduleBaseURL,
99
- outDir,
100
- rscOutputPath: `${outDir}/${id}.rsc`,
101
- cssFiles: Array.from(cssFiles.entries())
102
- });
103
- });
104
- passThrough.on("end", () => {
105
- parentPort?.postMessage({
106
- type: "RSC_END",
107
- id
108
- });
109
- });
110
- } catch (error) {
111
- console.trace(error);
112
- parentPort?.postMessage({
113
- type: "ERROR",
114
- id,
115
- error: error instanceof Error ? error.message : String(error)
16
+ return handleRender(msg, port);
17
+ case "INITIALIZED_REACT_LOADER":
18
+ return;
19
+ case "INITIALIZED_CSS_LOADER":
20
+ return;
21
+ case "HMR_UPDATE":
22
+ hmrState.set(msg.path, {
23
+ timestamp: msg.timestamp || Date.now(),
24
+ invalidated: true,
25
+ routes: msg.routes || []
26
+ });
27
+ port.postMessage({
28
+ type: "HMR_ACCEPT",
29
+ path: msg.path,
30
+ routes: msg.routes
31
+ });
32
+ return;
33
+ case "HMR_CLEANUP":
34
+ hmrState.delete(msg.path);
35
+ port.postMessage({
36
+ type: "HMR_ACCEPT",
37
+ path: msg.path
38
+ });
39
+ return;
40
+ case "CSS_FILE":
41
+ if (msg.id) {
42
+ const cssOptions = workerData.userOptions.css || {
43
+ inlineThreshold: 1e3
44
+ };
45
+ addCssFileContent(msg.id, msg.content, {
46
+ projectRoot: workerData.userOptions.projectRoot || process.cwd(),
47
+ moduleBaseURL: workerData.userOptions.moduleBaseURL || "",
48
+ moduleBasePath: workerData.userOptions.moduleBasePath || "",
49
+ moduleRootPath: workerData.userOptions.moduleRootPath || "",
50
+ css: cssOptions
116
51
  });
117
52
  }
118
- break;
119
- case "CSS_FILE":
120
- addCssFile(message.id, message.cssFile);
121
- break;
53
+ return;
54
+ default: {
55
+ return;
56
+ }
122
57
  }
123
58
  }
124
59
 
@@ -1 +1 @@
1
- {"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { join } from \"node:path\";\nimport { PassThrough } from \"node:stream\";\nimport { parentPort } from \"node:worker_threads\";\nimport React from \"react\";\nimport type {\n RscChunkMessage,\n RscEndMessage,\n RscWorkerMessage,\n} from \"../types.js\";\nimport { addCssFile, cssFiles } from \"./state.js\";\nimport { InlineCssCollector } from \"../../css-collector-inline.js\";\nimport { createRscStream } from \"../../helpers/createRscStream.js\";\nimport { createLogger } from \"vite\";\n\nexport async function messageHandler(message: RscWorkerMessage) {\n switch (message.type) {\n case \"RSC_RENDER\":\n const {\n id,\n pageImport,\n propsImport,\n pageExportName,\n propsExportName,\n url,\n outDir,\n projectRoot,\n moduleRootPath,\n moduleBaseURL,\n moduleBasePath,\n moduleBase,\n pipableStreamOptions,\n } = message;\n\n try {\n // Load modules which will trigger CSS loading\n const [Component, propsModule] = await Promise.all([\n import(join(projectRoot, pageImport)),\n import(join(projectRoot, propsImport)),\n ]);\n\n const propsAtExport = propsModule[propsExportName];\n const props = await Promise.resolve(\n typeof propsAtExport === \"function\"\n ? propsAtExport(url)\n : propsAtExport\n );\n\n const PageComponent = Component[pageExportName];\n\n // Create stream using the helper\n const stream = createRscStream({\n Html: React.Fragment,\n Page: PageComponent,\n CssCollector: InlineCssCollector,\n loader: (id: string) => import(id).then((m) => m.default),\n props,\n moduleBase,\n moduleRootPath,\n moduleBasePath,\n moduleBaseURL,\n logger: createLogger(),\n inlineCss: true,\n cssFiles: Array.from(cssFiles.values()).map((css) => ({\n type: \"text/css\",\n content: css,\n path: css,\n })),\n route: url,\n url: typeof moduleBaseURL === \"string\" && moduleBaseURL !== \"\" ? new URL(url, moduleBaseURL).toString() : url,\n root: projectRoot,\n pipableStreamOptions: {\n ...pipableStreamOptions,\n onError: (error: unknown) => {\n if (typeof pipableStreamOptions.onError === \"function\") {\n pipableStreamOptions.onError(error);\n }\n parentPort?.postMessage({\n type: \"ERROR\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n },\n onPostpone: (reason: string) => {\n if (typeof pipableStreamOptions.onPostpone === \"function\") {\n pipableStreamOptions.onPostpone(reason);\n }\n parentPort?.postMessage({\n type: \"POSTPONE\",\n id,\n reason,\n });\n },\n },\n });\n\n if (!stream) {\n throw new Error(\"Failed to create stream\");\n }\n\n // Listen for data and end events\n const passThrough = new PassThrough();\n stream.pipe(passThrough);\n\n passThrough.on(\"data\", (chunk) => {\n // Send to parent\n parentPort?.postMessage({\n type: \"RSC_CHUNK\",\n id,\n chunk: chunk.toString(),\n moduleRootPath: moduleBasePath,\n moduleBaseURL,\n outDir,\n rscOutputPath: `${outDir}/${id}.rsc`,\n cssFiles: Array.from(cssFiles.entries()),\n } satisfies RscChunkMessage);\n });\n\n passThrough.on(\"end\", () => {\n parentPort?.postMessage({\n type: \"RSC_END\",\n id,\n } satisfies RscEndMessage);\n });\n } catch (error) {\n console.trace(error);\n parentPort?.postMessage({\n type: \"ERROR\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n break;\n case \"CSS_FILE\":\n addCssFile(message.id, message.cssFile);\n break;\n }\n}\n"],"names":["React","id"],"mappings":"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"}
1
+ {"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { parentPort, workerData, type MessagePort } from \"node:worker_threads\";\nimport { addCssFileContent, hmrState } from \"./state.js\";\nimport { handleRender } from \"./handleRender.js\";\n\nexport function messageHandler(\n msg: any,\n port = parentPort,\n reactLoaderPort: MessagePort,\n cssLoaderPort: MessagePort\n) {\n if (!port) {\n throw new Error(\"No port found\");\n }\n switch (msg.type) {\n case \"RSC_RENDER\":\n return handleRender(msg, port, reactLoaderPort, cssLoaderPort);\n case \"INITIALIZED_REACT_LOADER\":\n return;\n case \"INITIALIZED_CSS_LOADER\":\n return;\n case \"HMR_UPDATE\":\n // Mark the module as invalidated\n hmrState.set(msg.path, {\n timestamp: msg.timestamp || Date.now(),\n invalidated: true,\n routes: msg.routes || [],\n });\n // Notify the main thread that we've processed the update\n port.postMessage({\n type: \"HMR_ACCEPT\",\n path: msg.path,\n routes: msg.routes,\n });\n return;\n case \"HMR_CLEANUP\":\n // Clear the invalidation state\n hmrState.delete(msg.path);\n // Notify the main thread that we've processed the cleanup\n port.postMessage({\n type: \"HMR_ACCEPT\",\n path: msg.path,\n });\n return;\n case \"CSS_FILE\":\n if (msg.id) {\n const cssOptions = workerData.userOptions.css || {\n inlineThreshold: 1000,\n };\n \n addCssFileContent(msg.id, msg.content, {\n projectRoot: workerData.userOptions.projectRoot || process.cwd(),\n moduleBaseURL: workerData.userOptions.moduleBaseURL || \"\",\n moduleBasePath: workerData.userOptions.moduleBasePath || \"\",\n moduleRootPath: workerData.userOptions.moduleRootPath || \"\",\n css: cssOptions,\n });\n }\n return;\n default: {\n return;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAIO,SAAS,cACd,CAAA,GAAA,EACA,IAAO,GAAA,UAAA,EACP,iBACA,aACA,EAAA;AACA,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AAAA;AAEjC,EAAA,QAAQ,IAAI,IAAM;AAAA,IAChB,KAAK,YAAA;AACH,MAAA,OAAO,YAAa,CAAA,GAAA,EAAK,IAAoC,CAAA;AAAA,IAC/D,KAAK,0BAAA;AACH,MAAA;AAAA,IACF,KAAK,wBAAA;AACH,MAAA;AAAA,IACF,KAAK,YAAA;AAEH,MAAS,QAAA,CAAA,GAAA,CAAI,IAAI,IAAM,EAAA;AAAA,QACrB,SAAW,EAAA,GAAA,CAAI,SAAa,IAAA,IAAA,CAAK,GAAI,EAAA;AAAA,QACrC,WAAa,EAAA,IAAA;AAAA,QACb,MAAA,EAAQ,GAAI,CAAA,MAAA,IAAU;AAAC,OACxB,CAAA;AAED,MAAA,IAAA,CAAK,WAAY,CAAA;AAAA,QACf,IAAM,EAAA,YAAA;AAAA,QACN,MAAM,GAAI,CAAA,IAAA;AAAA,QACV,QAAQ,GAAI,CAAA;AAAA,OACb,CAAA;AACD,MAAA;AAAA,IACF,KAAK,aAAA;AAEH,MAAS,QAAA,CAAA,MAAA,CAAO,IAAI,IAAI,CAAA;AAExB,MAAA,IAAA,CAAK,WAAY,CAAA;AAAA,QACf,IAAM,EAAA,YAAA;AAAA,QACN,MAAM,GAAI,CAAA;AAAA,OACX,CAAA;AACD,MAAA;AAAA,IACF,KAAK,UAAA;AACH,MAAA,IAAI,IAAI,EAAI,EAAA;AACV,QAAM,MAAA,UAAA,GAAa,UAAW,CAAA,WAAA,CAAY,GAAO,IAAA;AAAA,UAC/C,eAAiB,EAAA;AAAA,SACnB;AAEA,QAAkB,iBAAA,CAAA,GAAA,CAAI,EAAI,EAAA,GAAA,CAAI,OAAS,EAAA;AAAA,UACrC,WAAa,EAAA,UAAA,CAAW,WAAY,CAAA,WAAA,IAAe,QAAQ,GAAI,EAAA;AAAA,UAC/D,aAAA,EAAe,UAAW,CAAA,WAAA,CAAY,aAAiB,IAAA,EAAA;AAAA,UACvD,cAAA,EAAgB,UAAW,CAAA,WAAA,CAAY,cAAkB,IAAA,EAAA;AAAA,UACzD,cAAA,EAAgB,UAAW,CAAA,WAAA,CAAY,cAAkB,IAAA,EAAA;AAAA,UACzD,GAAK,EAAA;AAAA,SACN,CAAA;AAAA;AAEH,MAAA;AAAA,IACF,SAAS;AACP,MAAA;AAAA;AACF;AAEJ;;;;"}
@@ -1,32 +1,2 @@
1
- declare module 'node:module' {
2
- interface ImportAttributes {
3
- [key: string]: string | undefined;
4
- }
5
- interface ResolveHookContext {
6
- conditions: string[];
7
- parentURL: string | undefined;
8
- importAttributes: ImportAttributes;
9
- }
10
- interface LoadHookContext {
11
- conditions: string[];
12
- format: ModuleFormat | null | undefined;
13
- importAttributes: ImportAttributes;
14
- shortCircuit?: boolean;
15
- }
16
- interface ResolveResult {
17
- url: string;
18
- shortCircuit: boolean;
19
- }
20
- interface LoadResult {
21
- format: string;
22
- source: string | SharedArrayBuffer | Uint8Array;
23
- shortCircuit: boolean;
24
- }
25
- interface HooksAPI {
26
- resolve?: (specifier: string, context: ResolveHookContext, nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult) => ResolveResult;
27
- load?: (url: string, context: LoadHookContext, nextLoad: (url: string, context: LoadHookContext) => LoadResult) => LoadResult;
28
- }
29
- function registerHooks(hooks: HooksAPI): void;
30
- }
31
1
  export {};
32
2
  //# sourceMappingURL=rsc-worker.development.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsc-worker.development.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAiB,gBAAgB;QAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC;IAED,UAAiB,kBAAkB;QACjC,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,gBAAgB,EAAE,gBAAgB,CAAC;KACpC;IAED,UAAiB,eAAe;QAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;QACxC,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;IAED,UAAiB,aAAa;QAC5B,GAAG,EAAE,MAAM,CAAC;QACZ,YAAY,EAAE,OAAO,CAAC;KACvB;IAED,UAAiB,UAAU;QACzB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,UAAU,CAAC;QAChD,YAAY,EAAE,OAAO,CAAC;KACvB;IAED,UAAiB,QAAQ;QACvB,OAAO,CAAC,EAAE,CACR,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,KAAK,aAAa,KAC3E,aAAa,CAAC;QAEnB,IAAI,CAAC,EAAE,CACL,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,UAAU,KAC5D,UAAU,CAAC;KACjB;IAED,SAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;CACtD"}
1
+ {"version":3,"file":"rsc-worker.development.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"names":[],"mappings":""}
@@ -3,22 +3,26 @@
3
3
  * Copyright (c) Nico Brinkkemper
4
4
  * MIT License
5
5
  */
6
- import { parentPort, MessageChannel } from 'node:worker_threads';
6
+ import { parentPort, workerData, MessageChannel } from 'node:worker_threads';
7
7
  import { messageHandler } from './messageHandler.js';
8
8
  import { register } from 'node:module';
9
9
  import { register as register$1 } from 'tsx/esm/api';
10
10
  import { join } from 'node:path';
11
11
  import { pluginRoot } from '../../root.js';
12
+ import { deserializeRegExp } from '../../helpers/serializeUserOptions.js';
12
13
 
13
14
  if (!parentPort) {
14
15
  throw new Error("This module must be run as a worker");
15
16
  }
17
+ if (workerData) {
18
+ workerData.userOptions = deserializeRegExp(workerData.userOptions);
19
+ }
16
20
  const reactLoaderChannel = new MessageChannel();
17
21
  const cssLoaderChannel = new MessageChannel();
18
22
  reactLoaderChannel.port2.on("message", messageHandler);
19
23
  cssLoaderChannel.port2.on("message", messageHandler);
20
24
  const loaderPath = "file://" + join(pluginRoot, "loader/react-loader.js");
21
- const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.js");
25
+ const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
22
26
  register(loaderPath, {
23
27
  parentURL: pluginRoot,
24
28
  data: { port: reactLoaderChannel.port1 },
@@ -26,12 +30,33 @@ register(loaderPath, {
26
30
  });
27
31
  register(cssLoaderPath, {
28
32
  parentURL: pluginRoot,
29
- data: { port: cssLoaderChannel.port1 },
33
+ data: { port: cssLoaderChannel.port1, resolvedConfig: workerData.resolvedConfig },
30
34
  transferList: [cssLoaderChannel.port1]
31
35
  });
32
36
  register$1();
33
37
  parentPort.on("message", messageHandler);
34
- parentPort.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
38
+ const { hmrPort } = workerData;
39
+ if (hmrPort) {
40
+ hmrPort.start();
41
+ hmrPort.on("message", (message) => {
42
+ if (message.type === "HMR_UPDATE") {
43
+ parentPort.postMessage({
44
+ type: "HMR_UPDATE",
45
+ path: message.path
46
+ });
47
+ }
48
+ });
49
+ hmrPort.on("message", (message) => {
50
+ parentPort.postMessage({
51
+ type: "HMR_ACCEPT",
52
+ path: message.path
53
+ });
54
+ });
55
+ }
56
+ parentPort.postMessage({
57
+ type: "READY",
58
+ env: process.env["NODE_ENV"]
59
+ });
35
60
  if (process.env["NODE_ENV"] !== "development") {
36
61
  throw new Error("This module must be run in development mode");
37
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["// no offical types for node:module available yet (23.7.0)\ndeclare module 'node:module' {\n export interface ImportAttributes {\n [key: string]: string | undefined;\n }\n\n export interface ResolveHookContext {\n conditions: string[];\n parentURL: string | undefined;\n importAttributes: ImportAttributes;\n }\n\n export interface LoadHookContext {\n conditions: string[];\n format: ModuleFormat | null | undefined;\n importAttributes: ImportAttributes;\n shortCircuit?: boolean;\n }\n\n export interface ResolveResult {\n url: string;\n shortCircuit: boolean;\n }\n\n export interface LoadResult {\n format: string;\n source: string | SharedArrayBuffer | Uint8Array;\n shortCircuit: boolean;\n }\n\n export interface HooksAPI {\n resolve?: (\n specifier: string,\n context: ResolveHookContext,\n nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult\n ) => ResolveResult;\n\n load?: (\n url: string,\n context: LoadHookContext,\n nextLoad: (url: string, context: LoadHookContext) => LoadResult\n ) => LoadResult;\n }\n\n export function registerHooks(hooks: HooksAPI): void;\n}\n//\nimport { parentPort, MessageChannel } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { \n register,\n} from 'node:module';\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from 'node:path';\nimport { pluginRoot } from \"../../root.js\";\n\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Create channels for each loader\nconst reactLoaderChannel = new MessageChannel();\nconst cssLoaderChannel = new MessageChannel();\n\n// Listen for messages from loaders\nreactLoaderChannel.port2.on('message', messageHandler);\ncssLoaderChannel.port2.on('message', messageHandler);\n\nconst loaderPath = 'file://' + join(pluginRoot, 'loader/react-loader.js');\nconst cssLoaderPath = 'file://' + join(pluginRoot, 'loader/css-loader.js');\n\n// Register react-loader\nregister(loaderPath, {\n parentURL: pluginRoot,\n data: { port: reactLoaderChannel.port1 },\n transferList: [reactLoaderChannel.port1]\n});\nregister(cssLoaderPath, {\n parentURL: pluginRoot,\n data: { port: cssLoaderChannel.port1 },\n transferList: [cssLoaderChannel.port1]\n});\n\n// Register loaders\nregisterTsx();\n\n// Set up message handling\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"] });\n\nif (process.env[\"NODE_ENV\"] !== \"development\") {\n throw new Error(\"This module must be run in development mode\");\n}\n\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;AAyDA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,kBAAA,GAAqB,IAAI,cAAe,EAAA;AAC9C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAG5C,kBAAmB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACrD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AAEnD,MAAM,UAAa,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,wBAAwB,CAAA;AACxE,MAAM,aAAgB,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,sBAAsB,CAAA;AAGzE,QAAA,CAAS,UAAY,EAAA;AAAA,EACnB,SAAW,EAAA,UAAA;AAAA,EACX,IAAM,EAAA,EAAE,IAAM,EAAA,kBAAA,CAAmB,KAAM,EAAA;AAAA,EACvC,YAAA,EAAc,CAAC,kBAAA,CAAmB,KAAK;AACzC,CAAC,CAAA;AACD,QAAA,CAAS,aAAe,EAAA;AAAA,EACtB,SAAW,EAAA,UAAA;AAAA,EACX,IAAM,EAAA,EAAE,IAAM,EAAA,gBAAA,CAAiB,KAAM,EAAA;AAAA,EACrC,YAAA,EAAc,CAAC,gBAAA,CAAiB,KAAK;AACvC,CAAC,CAAA;AAGDA,UAAY,EAAA;AAGZ,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAW,CAAA,WAAA,CAAY,EAAE,IAAM,EAAA,OAAA,EAAS,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,CAAA;AAEtE,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,aAAe,EAAA;AAC7C,EAAM,MAAA,IAAI,MAAM,6CAA6C,CAAA;AAC/D"}
1
+ {"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["import { parentPort, MessageChannel, workerData } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport { deserializeRegExp } from \"../../helpers/serializeUserOptions.js\";\n\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Deserialize workerData to restore RegExp objects\nif (workerData) {\n workerData.userOptions = deserializeRegExp(workerData.userOptions);\n}\n\n// Create channels for each loader\nconst reactLoaderChannel = new MessageChannel();\nconst cssLoaderChannel = new MessageChannel();\n\n// Listen for messages from loaders\nreactLoaderChannel.port2.on(\"message\", messageHandler);\ncssLoaderChannel.port2.on(\"message\", messageHandler);\n\nconst loaderPath = \"file://\" + join(pluginRoot, \"loader/react-loader.js\");\nconst cssLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/css-loader.development.js\");\n\n// Register react-loader\nregister(loaderPath, {\n parentURL: pluginRoot,\n data: { port: reactLoaderChannel.port1 },\n transferList: [reactLoaderChannel.port1],\n});\nregister(cssLoaderPath, {\n parentURL: pluginRoot,\n data: { port: cssLoaderChannel.port1, resolvedConfig: workerData.resolvedConfig },\n transferList: [cssLoaderChannel.port1],\n});\n\n// Register loaders\nregisterTsx();\n\n// Set up message handling\nparentPort!.on(\"message\", messageHandler);\n\nconst { hmrPort } = workerData;\nif (hmrPort) {\n // Start the message port\n hmrPort.start();\n\n // Listen for file changes\n hmrPort.on(\"message\", (message: any) => {\n if (message.type === \"HMR_UPDATE\") {\n // Invalidate the module in the worker\n parentPort!.postMessage({\n type: \"HMR_UPDATE\",\n path: message.path,\n });\n }\n });\n\n // Listen for HMR updates\n hmrPort.on(\"message\", (message: any) => {\n // Handle the update\n parentPort!.postMessage({\n type: \"HMR_ACCEPT\",\n path: message.path,\n });\n });\n}\n\n// Notify parent that we're ready\nparentPort!.postMessage({\n type: \"READY\",\n env: process.env[\"NODE_ENV\"],\n});\n\nif (process.env[\"NODE_ENV\"] !== \"development\") {\n throw new Error(\"This module must be run in development mode\");\n}\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;;AASA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,IAAI,UAAY,EAAA;AACd,EAAW,UAAA,CAAA,WAAA,GAAc,iBAAkB,CAAA,UAAA,CAAW,WAAW,CAAA;AACnE;AAGA,MAAM,kBAAA,GAAqB,IAAI,cAAe,EAAA;AAC9C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAG5C,kBAAmB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACrD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AAEnD,MAAM,UAAa,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,wBAAwB,CAAA;AACxE,MAAM,aACJ,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,kCAAkC,CAAA;AAGjE,QAAA,CAAS,UAAY,EAAA;AAAA,EACnB,SAAW,EAAA,UAAA;AAAA,EACX,IAAM,EAAA,EAAE,IAAM,EAAA,kBAAA,CAAmB,KAAM,EAAA;AAAA,EACvC,YAAA,EAAc,CAAC,kBAAA,CAAmB,KAAK;AACzC,CAAC,CAAA;AACD,QAAA,CAAS,aAAe,EAAA;AAAA,EACtB,SAAW,EAAA,UAAA;AAAA,EACX,MAAM,EAAE,IAAA,EAAM,iBAAiB,KAAO,EAAA,cAAA,EAAgB,WAAW,cAAe,EAAA;AAAA,EAChF,YAAA,EAAc,CAAC,gBAAA,CAAiB,KAAK;AACvC,CAAC,CAAA;AAGDA,UAAY,EAAA;AAGZ,UAAY,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAExC,MAAM,EAAE,SAAY,GAAA,UAAA;AACpB,IAAI,OAAS,EAAA;AAEX,EAAA,OAAA,CAAQ,KAAM,EAAA;AAGd,EAAQ,OAAA,CAAA,EAAA,CAAG,SAAW,EAAA,CAAC,OAAiB,KAAA;AACtC,IAAI,IAAA,OAAA,CAAQ,SAAS,YAAc,EAAA;AAEjC,MAAA,UAAA,CAAY,WAAY,CAAA;AAAA,QACtB,IAAM,EAAA,YAAA;AAAA,QACN,MAAM,OAAQ,CAAA;AAAA,OACf,CAAA;AAAA;AACH,GACD,CAAA;AAGD,EAAQ,OAAA,CAAA,EAAA,CAAG,SAAW,EAAA,CAAC,OAAiB,KAAA;AAEtC,IAAA,UAAA,CAAY,WAAY,CAAA;AAAA,MACtB,IAAM,EAAA,YAAA;AAAA,MACN,MAAM,OAAQ,CAAA;AAAA,KACf,CAAA;AAAA,GACF,CAAA;AACH;AAGA,UAAA,CAAY,WAAY,CAAA;AAAA,EACtB,IAAM,EAAA,OAAA;AAAA,EACN,GAAA,EAAK,OAAQ,CAAA,GAAA,CAAI,UAAU;AAC7B,CAAC,CAAA;AAED,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,aAAe,EAAA;AAC7C,EAAM,MAAA,IAAI,MAAM,6CAA6C,CAAA;AAC/D"}
@@ -6,12 +6,12 @@
6
6
  import { parentPort } from 'node:worker_threads';
7
7
  import { messageHandler } from './messageHandler.js';
8
8
 
9
+ if (process.env["NODE_ENV"] !== "production") {
10
+ process.exit(1);
11
+ }
9
12
  if (!parentPort) {
10
13
  throw new Error("This module must be run as a worker");
11
14
  }
12
15
  parentPort.on("message", messageHandler);
13
16
  parentPort.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
14
- if (process.env["NODE_ENV"] !== "production") {
15
- throw new Error("This module must be run in production mode");
16
- }
17
17
  //# sourceMappingURL=rsc-worker.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\n\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"] });\n\nif (process.env[\"NODE_ENV\"] !== \"production\") {\n throw new Error(\"This module must be run in production mode\");\n}\n"],"names":[],"mappings":";;;;;;;;AAIA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAW,CAAA,WAAA,CAAY,EAAE,IAAM,EAAA,OAAA,EAAS,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,CAAA;AAEtE,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,YAAc,EAAA;AAC5C,EAAM,MAAA,IAAI,MAAM,4CAA4C,CAAA;AAC9D"}
1
+ {"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["// Check environment before any imports\nif (process.env[\"NODE_ENV\"] !== \"production\") {\n process.exit(1);\n}\n\nimport { parentPort } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"] });\n"],"names":[],"mappings":";;;;;;;;AACA,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,YAAc,EAAA;AAC5C,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB;AAKA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAW,CAAA,WAAA,CAAY,EAAE,IAAM,EAAA,OAAA,EAAS,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,CAAA"}
@@ -1,11 +1,82 @@
1
- export declare const cssFiles: Map<string, string>;
1
+ import type { CssContent, ResolvedUserOptions, HmrState } from "../../types.js";
2
+ import type { PassThrough } from "node:stream";
3
+ export declare const activeStreams: Map<string, PassThrough>;
4
+ export declare const cssFiles: Map<string, ({
5
+ as: string;
6
+ id: string;
7
+ } & {
8
+ as: "link";
9
+ type?: never;
10
+ children?: {
11
+ as: string;
12
+ id: string;
13
+ } & {
14
+ as: "style";
15
+ type: "text/css";
16
+ children?: React.ReactNode;
17
+ precedence?: never;
18
+ rel?: never;
19
+ href?: never;
20
+ } extends false ? never : React.ReactNode;
21
+ id: string;
22
+ href: string;
23
+ rel: "stylesheet";
24
+ precedence?: string;
25
+ }) | ({
26
+ as: string;
27
+ id: string;
28
+ } & {
29
+ as: "style";
30
+ type: "text/css";
31
+ children?: React.ReactNode;
32
+ precedence?: never;
33
+ rel?: never;
34
+ href?: never;
35
+ })>;
36
+ export declare const hmrState: Map<string, HmrState>;
2
37
  export declare const clientFiles: Set<string>;
3
38
  export declare const serverActionFiles: Set<string>;
4
39
  export declare function clearCssFiles(): void;
40
+ export declare function getCssFiles(): MapIterator<[string, ({
41
+ as: string;
42
+ id: string;
43
+ } & {
44
+ as: "link";
45
+ type?: never;
46
+ children?: {
47
+ as: string;
48
+ id: string;
49
+ } & {
50
+ as: "style";
51
+ type: "text/css";
52
+ children?: React.ReactNode;
53
+ precedence?: never;
54
+ rel?: never;
55
+ href?: never;
56
+ } extends false ? never : React.ReactNode;
57
+ id: string;
58
+ href: string;
59
+ rel: "stylesheet";
60
+ precedence?: string;
61
+ }) | ({
62
+ as: string;
63
+ id: string;
64
+ } & {
65
+ as: "style";
66
+ type: "text/css";
67
+ children?: React.ReactNode;
68
+ precedence?: never;
69
+ rel?: never;
70
+ href?: never;
71
+ })]>;
5
72
  export declare function clearClientFiles(): void;
6
73
  export declare function clearServerActionFiles(): void;
7
- export declare function addCssFile(id: string, cssFile: string): void;
74
+ export declare function addCssFile(id: string, cssFile: CssContent): void;
75
+ export declare function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, "projectRoot" | "moduleBaseURL" | "moduleBasePath" | "moduleRootPath" | "css">): void;
8
76
  export declare function addClientFile(url: string): void;
9
77
  export declare function addServerActionFile(url: string): void;
10
78
  export declare function clearAllFiles(): void;
79
+ export declare function isModuleInvalidated(path: string): boolean;
80
+ export declare function clearHmrState(path: string): void;
81
+ export declare function getInvalidatedModules(): string[];
11
82
  //# sourceMappingURL=state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/state.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,QAAQ,qBAA4B,CAAC;AAClD,eAAO,MAAM,WAAW,aAAoB,CAAC;AAC7C,eAAO,MAAM,iBAAiB,aAAoB,CAAC;AAEnD,wBAAgB,aAAa,SAE5B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBAAgB,sBAAsB,SAErC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAErD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,QAExC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,QAE9C;AAED,wBAAgB,aAAa,SAI5B"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,eAAO,MAAM,aAAa,0BAAiC,CAAC;AAG5D,eAAO,MAAM,QAAQ;;;;;;;;;;;;mBAmG0xZ,MAAO,SAAS;;;;8BAArM,MAAO,SAAS;;;;;;;;;;;eAAqK,MAAO,SAAS;;;;GAnG1wZ,CAAC;AAGtD,eAAO,MAAM,QAAQ,uBAA8B,CAAC;AAyBpD,eAAO,MAAM,WAAW,aAAoB,CAAC;AAC7C,eAAO,MAAM,iBAAiB,aAAoB,CAAC;AAGnD,wBAAgB,aAAa,SAE5B;AAED,wBAAgB,WAAW;;;;;;;;;;;;mBA+DoxZ,MAAO,SAAS;;;;8BAArM,MAAO,SAAS;;;;;;;;;;;eAAqK,MAAO,SAAS;;;;KA7D9zZ;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBAAgB,sBAAsB,SAErC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,QAEzD;AAGD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,KAAK,CAAC,QAchL;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,QAExC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,QAE9C;AAED,wBAAgB,aAAa,SAI5B;AAGD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGzD;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhD;AAGD,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAIhD"}
@@ -3,10 +3,47 @@
3
3
  * Copyright (c) Nico Brinkkemper
4
4
  * MIT License
5
5
  */
6
+ import { workerData } from 'node:worker_threads';
7
+ import { createCssProps } from '../../helpers/createCssProps.js';
8
+ import { relative } from 'node:path';
9
+
10
+ const activeStreams = /* @__PURE__ */ new Map();
6
11
  const cssFiles = /* @__PURE__ */ new Map();
7
- function addCssFile(id, cssFile) {
8
- cssFiles.set(id, cssFile);
12
+ const hmrState = /* @__PURE__ */ new Map();
13
+ if (workerData) {
14
+ if (workerData.hmrPort) {
15
+ workerData.hmrPort.on("message", (msg) => {
16
+ if (msg.type === "HMR_UPDATE") {
17
+ const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);
18
+ hmrState.set(normalizedPath, {
19
+ timestamp: Date.now(),
20
+ invalidated: true,
21
+ routes: msg.routes || []
22
+ });
23
+ } else if (msg.type === "HMR_ACCEPT") {
24
+ const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);
25
+ hmrState.delete(normalizedPath);
26
+ }
27
+ });
28
+ }
29
+ } else {
30
+ throw new Error("This module must be run with workerData");
31
+ }
32
+ function addCssFileContent(id, code, userOptions) {
33
+ if (typeof code !== "string") {
34
+ throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);
35
+ }
36
+ const normalizeId = id.startsWith(userOptions.moduleRootPath) ? id.slice(userOptions.moduleRootPath.length) : id;
37
+ cssFiles.set(normalizeId, createCssProps({
38
+ id,
39
+ code,
40
+ projectRoot: userOptions.projectRoot,
41
+ moduleBaseURL: userOptions.moduleBaseURL,
42
+ moduleBasePath: userOptions.moduleBasePath,
43
+ moduleRootPath: userOptions.moduleRootPath,
44
+ css: userOptions.css
45
+ }));
9
46
  }
10
47
 
11
- export { addCssFile, cssFiles };
48
+ export { activeStreams, addCssFileContent, cssFiles, hmrState };
12
49
  //# sourceMappingURL=state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["// Create shared CSS registry\nexport const cssFiles = new Map<string, string>();\nexport const clientFiles = new Set<string>();\nexport const serverActionFiles = new Set<string>();\n// Helper functions\nexport function clearCssFiles() {\n cssFiles.clear();\n}\n\nexport function clearClientFiles() {\n clientFiles.clear();\n}\n\nexport function clearServerActionFiles() {\n serverActionFiles.clear();\n}\n\nexport function addCssFile(id: string, cssFile: string) {\n cssFiles.set(id, cssFile);\n} \n\nexport function addClientFile(url: string) {\n clientFiles.add(url);\n}\n\nexport function addServerActionFile(url: string) {\n serverActionFiles.add(url);\n}\n\nexport function clearAllFiles() {\n clearCssFiles();\n clearClientFiles();\n clearServerActionFiles();\n} "],"names":[],"mappings":";;;;;AACa,MAAA,QAAA,uBAAe,GAAoB;AAgBhC,SAAA,UAAA,CAAW,IAAY,OAAiB,EAAA;AACtD,EAAS,QAAA,CAAA,GAAA,CAAI,IAAI,OAAO,CAAA;AAC1B;;;;"}
1
+ {"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["import { workerData } from \"node:worker_threads\";\nimport { createCssProps } from \"../../helpers/createCssProps.js\";\nimport type { CssContent, ResolvedUserOptions, HmrState } from \"../../types.js\";\nimport type { PassThrough } from \"node:stream\";\nimport { relative } from \"node:path\";\n\n\n// Track active RSC streams\nexport const activeStreams = new Map<string, PassThrough>();\n\n// Track CSS files\nexport const cssFiles = new Map<string, CssContent>();\n\n\nexport const hmrState = new Map<string, HmrState>();\n\nif(workerData) {\n if(workerData.hmrPort) {\n workerData.hmrPort.on('message', (msg: { type: string; path: string; routes?: string[] }) => {\n if(msg.type === 'HMR_UPDATE') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.set(normalizedPath, { \n timestamp: Date.now(), \n invalidated: true,\n routes: msg.routes || []\n });\n } else if(msg.type === 'HMR_ACCEPT') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.delete(normalizedPath);\n }\n });\n }\n} else {\n throw new Error(\"This module must be run with workerData\");\n}\n\n// Create shared CSS registry\nexport const clientFiles = new Set<string>();\nexport const serverActionFiles = new Set<string>();\n\n// Helper functions\nexport function clearCssFiles() {\n cssFiles.clear();\n}\n\nexport function getCssFiles() {\n return cssFiles.entries();\n}\n\nexport function clearClientFiles() {\n clientFiles.clear();\n}\n\nexport function clearServerActionFiles() {\n serverActionFiles.clear();\n}\n\nexport function addCssFile(id: string, cssFile: CssContent) {\n cssFiles.set(id, cssFile);\n}\n\n\nexport function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, \"projectRoot\" | \"moduleBaseURL\" | \"moduleBasePath\" | \"moduleRootPath\" | \"css\">) {\n if(typeof code !== \"string\"){\n throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);\n }\n const normalizeId = id.startsWith(userOptions.moduleRootPath) ? id.slice(userOptions.moduleRootPath.length) : id;\n cssFiles.set(normalizeId, createCssProps({\n id,\n code,\n projectRoot: userOptions.projectRoot,\n moduleBaseURL: userOptions.moduleBaseURL,\n moduleBasePath: userOptions.moduleBasePath,\n moduleRootPath: userOptions.moduleRootPath,\n css: userOptions.css,\n }));\n} \n\nexport function addClientFile(url: string) {\n clientFiles.add(url);\n}\n\nexport function addServerActionFile(url: string) {\n serverActionFiles.add(url);\n}\n\nexport function clearAllFiles() {\n clearCssFiles();\n clearClientFiles();\n clearServerActionFiles();\n}\n\n// Helper to check if a module is invalidated\nexport function isModuleInvalidated(path: string): boolean {\n const state = hmrState.get(path);\n return state?.invalidated || false;\n}\n\n// Helper to clear HMR state for a module\nexport function clearHmrState(path: string): void {\n hmrState.delete(path);\n}\n\n// Helper to get all invalidated modules\nexport function getInvalidatedModules(): string[] {\n return Array.from(hmrState.entries())\n .filter(([_, state]) => state.invalidated)\n .map(([path]) => path);\n} "],"names":[],"mappings":";;;;;;;;;AAQa,MAAA,aAAA,uBAAoB,GAAyB;AAG7C,MAAA,QAAA,uBAAe,GAAwB;AAGvC,MAAA,QAAA,uBAAe,GAAsB;AAElD,IAAG,UAAY,EAAA;AACb,EAAA,IAAG,WAAW,OAAS,EAAA;AACrB,IAAA,UAAA,CAAW,OAAQ,CAAA,EAAA,CAAG,SAAW,EAAA,CAAC,GAA2D,KAAA;AAC3F,MAAG,IAAA,GAAA,CAAI,SAAS,YAAc,EAAA;AAE5B,QAAA,MAAM,iBAAiB,QAAS,CAAA,UAAA,CAAW,WAAY,CAAA,WAAA,EAAa,IAAI,IAAI,CAAA;AAC5E,QAAA,QAAA,CAAS,IAAI,cAAgB,EAAA;AAAA,UAC3B,SAAA,EAAW,KAAK,GAAI,EAAA;AAAA,UACpB,WAAa,EAAA,IAAA;AAAA,UACb,MAAA,EAAQ,GAAI,CAAA,MAAA,IAAU;AAAC,SACxB,CAAA;AAAA,OACH,MAAA,IAAU,GAAI,CAAA,IAAA,KAAS,YAAc,EAAA;AAEnC,QAAA,MAAM,iBAAiB,QAAS,CAAA,UAAA,CAAW,WAAY,CAAA,WAAA,EAAa,IAAI,IAAI,CAAA;AAC5E,QAAA,QAAA,CAAS,OAAO,cAAc,CAAA;AAAA;AAChC,KACD,CAAA;AAAA;AAEL,CAAO,MAAA;AACL,EAAM,MAAA,IAAI,MAAM,yCAAyC,CAAA;AAC3D;AA4BgB,SAAA,iBAAA,CAAkB,EAAY,EAAA,IAAA,EAAc,WAAuH,EAAA;AACjL,EAAG,IAAA,OAAO,SAAS,QAAS,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAkD,+CAAA,EAAA,OAAO,IAAI,CAAE,CAAA,CAAA;AAAA;AAEjF,EAAM,MAAA,WAAA,GAAc,EAAG,CAAA,UAAA,CAAW,WAAY,CAAA,cAAc,CAAI,GAAA,EAAA,CAAG,KAAM,CAAA,WAAA,CAAY,cAAe,CAAA,MAAM,CAAI,GAAA,EAAA;AAC9G,EAAS,QAAA,CAAA,GAAA,CAAI,aAAa,cAAe,CAAA;AAAA,IACvC,EAAA;AAAA,IACA,IAAA;AAAA,IACA,aAAa,WAAY,CAAA,WAAA;AAAA,IACzB,eAAe,WAAY,CAAA,aAAA;AAAA,IAC3B,gBAAgB,WAAY,CAAA,cAAA;AAAA,IAC5B,gBAAgB,WAAY,CAAA,cAAA;AAAA,IAC5B,KAAK,WAAY,CAAA;AAAA,GAClB,CAAC,CAAA;AACJ;;;;"}
@@ -0,0 +1,3 @@
1
+ import type { HtmlWorkerOutputMessage, RscWorkerOutputMessage } from "./types.js";
2
+ export declare function sendMessage(msg: HtmlWorkerOutputMessage | RscWorkerOutputMessage, port?: import("worker_threads").MessagePort | null): void;
3
+ //# sourceMappingURL=sendMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendMessage.d.ts","sourceRoot":"","sources":["../../../plugin/worker/sendMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGlF,wBAAgB,WAAW,CAAC,GAAG,EAAE,uBAAuB,GAAG,sBAAsB,EAAE,IAAI,8CAAa,QA4CnG"}
@@ -0,0 +1,48 @@
1
+ import { cleanObject } from "../helpers/cleanObject.js";
2
+ import { parentPort } from "node:worker_threads";
3
+ export function sendMessage(msg, port = parentPort) {
4
+ if (!port) {
5
+ console.error("[Worker] No port available to send message");
6
+ return;
7
+ }
8
+ try {
9
+ // Handle error messages
10
+ if ('error' in msg) {
11
+ const error = msg.error;
12
+ const serializedError = error instanceof Error ? {
13
+ message: error.message,
14
+ stack: error.stack,
15
+ name: error.name,
16
+ cause: error.cause,
17
+ } : {
18
+ message: String(error),
19
+ name: 'Error',
20
+ };
21
+ port.postMessage({
22
+ ...cleanObject(msg),
23
+ error: serializedError,
24
+ });
25
+ }
26
+ else {
27
+ // Handle non-error messages
28
+ port.postMessage(cleanObject(msg));
29
+ }
30
+ }
31
+ catch (err) {
32
+ console.error("[Worker] Failed to send message:", err);
33
+ // Try to send a basic error message
34
+ try {
35
+ port.postMessage({
36
+ type: "ERROR",
37
+ error: {
38
+ message: err instanceof Error ? err.message : String(err),
39
+ name: err instanceof Error ? err.name : 'Error',
40
+ },
41
+ });
42
+ }
43
+ catch {
44
+ // If we can't even send an error message, just log it
45
+ console.error("[Worker] Critical error - could not send error message");
46
+ }
47
+ }
48
+ }