vite-plugin-react-server 0.3.10 → 0.3.12

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 (318) hide show
  1. package/dist/client.d.ts +1 -1
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/index.d.ts +3 -6
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/package.json +16 -14
  9. package/dist/plugin/assertServerCondition.d.ts +5 -1
  10. package/dist/plugin/assertServerCondition.d.ts.map +1 -1
  11. package/dist/plugin/assertServerCondition.js +1 -3
  12. package/dist/plugin/checkFilesExist.d.ts +2 -2
  13. package/dist/plugin/checkFilesExist.d.ts.map +1 -1
  14. package/dist/plugin/checkFilesExist.js +43 -58
  15. package/dist/plugin/checkFilesExist.js.map +1 -1
  16. package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
  17. package/dist/plugin/collect-css-manifest.js +5 -0
  18. package/dist/plugin/collect-css-manifest.js.map +1 -1
  19. package/dist/plugin/components.js +10 -15
  20. package/dist/plugin/config/createModuleIdGenerator.d.ts +11 -0
  21. package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
  22. package/dist/plugin/config/createModuleIdGenerator.js +44 -0
  23. package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
  24. package/dist/plugin/config/defaults.d.ts +27 -24
  25. package/dist/plugin/config/defaults.d.ts.map +1 -1
  26. package/dist/plugin/config/defaults.js +26 -31
  27. package/dist/plugin/config/defaults.js.map +1 -1
  28. package/dist/plugin/config/getPaths.js +1 -1
  29. package/dist/plugin/config/resolveOptions.d.ts +1 -1
  30. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  31. package/dist/plugin/config/resolveOptions.js +223 -16
  32. package/dist/plugin/config/resolveOptions.js.map +1 -1
  33. package/dist/plugin/config/resolvePages.d.ts +2 -0
  34. package/dist/plugin/config/resolvePages.d.ts.map +1 -1
  35. package/dist/plugin/config/resolvePages.js.map +1 -1
  36. package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
  37. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  38. package/dist/plugin/config/resolveUserConfig.js +149 -50
  39. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  40. package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
  41. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
  42. package/dist/plugin/helpers/getBundleManifest.js +72 -0
  43. package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
  44. package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
  45. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  46. package/dist/plugin/helpers/inputNormalizer.js +128 -16
  47. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  48. package/dist/plugin/helpers/tryManifest.d.ts +3 -1
  49. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  50. package/dist/plugin/helpers/tryManifest.js +1 -1
  51. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  52. package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
  53. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  54. package/dist/plugin/loader/createBuildLoader.js +37 -9
  55. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  56. package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
  57. package/dist/plugin/loader/createPageLoader.js +0 -7
  58. package/dist/plugin/loader/css-loader.d.ts +16 -0
  59. package/dist/plugin/loader/css-loader.d.ts.map +1 -0
  60. package/dist/plugin/loader/css-loader.js +70 -0
  61. package/dist/plugin/loader/css-loader.js.map +1 -0
  62. package/dist/plugin/loader/react-loader.d.ts +17 -0
  63. package/dist/plugin/loader/react-loader.d.ts.map +1 -0
  64. package/dist/plugin/loader/react-loader.js +647 -0
  65. package/dist/plugin/loader/react-loader.js.map +1 -0
  66. package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
  67. package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
  68. package/dist/plugin/loader/rsc/messageHandler.js +1 -0
  69. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
  70. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
  71. package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
  72. package/dist/plugin/plugin.d.ts +0 -1
  73. package/dist/plugin/plugin.d.ts.map +1 -1
  74. package/dist/plugin/plugin.js +2 -1
  75. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  76. package/dist/plugin/preserver/plugin.js +3 -2
  77. package/dist/plugin/preserver/plugin.js.map +1 -1
  78. package/dist/plugin/react-client/index.d.ts +2 -1
  79. package/dist/plugin/react-client/index.d.ts.map +1 -1
  80. package/dist/plugin/react-client/index.js +19 -1
  81. package/dist/plugin/react-client/index.js.map +1 -0
  82. package/dist/plugin/react-client/plugin.d.ts +2 -2
  83. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  84. package/dist/plugin/react-client/plugin.js +283 -10
  85. package/dist/plugin/react-client/plugin.js.map +1 -1
  86. package/dist/plugin/react-server/createHandler.d.ts +2 -2
  87. package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
  88. package/dist/plugin/react-server/createHandler.js +15 -9
  89. package/dist/plugin/react-server/createHandler.js.map +1 -1
  90. package/dist/plugin/react-server/createRscStream.d.ts +15 -3
  91. package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
  92. package/dist/plugin/react-server/createRscStream.js +53 -36
  93. package/dist/plugin/react-server/createRscStream.js.map +1 -1
  94. package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
  95. package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
  96. package/dist/plugin/react-server/createSsrHandler.js +5 -12
  97. package/dist/plugin/react-server/index.js +18 -9
  98. package/dist/plugin/react-server/index.js.map +1 -0
  99. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  100. package/dist/plugin/react-server/plugin.js +147 -137
  101. package/dist/plugin/react-server/plugin.js.map +1 -1
  102. package/dist/plugin/transformer/plugin.d.ts +2 -1
  103. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  104. package/dist/plugin/transformer/plugin.js +68 -75
  105. package/dist/plugin/transformer/plugin.js.map +1 -1
  106. package/dist/plugin/transformer/types.d.ts +4 -0
  107. package/dist/plugin/transformer/types.d.ts.map +1 -1
  108. package/dist/plugin/types.d.ts +56 -20
  109. package/dist/plugin/types.d.ts.map +1 -1
  110. package/dist/plugin/utils/logger.d.ts +9 -0
  111. package/dist/plugin/utils/logger.d.ts.map +1 -0
  112. package/dist/plugin/utils/logger.js +68 -0
  113. package/dist/plugin/utils/logger.js.map +1 -0
  114. package/dist/plugin/worker/createWorker.d.ts +1 -0
  115. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  116. package/dist/plugin/worker/createWorker.js +23 -36
  117. package/dist/plugin/worker/createWorker.js.map +1 -1
  118. package/dist/plugin/worker/html/html-worker.production.js +5 -1
  119. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  120. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  121. package/dist/plugin/worker/html/messageHandler.js +33 -28
  122. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  123. package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
  124. package/dist/plugin/worker/html/plugin.js +10 -5
  125. package/dist/plugin/worker/html/renderPages.d.ts +7 -6
  126. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  127. package/dist/plugin/worker/html/renderPages.js +147 -93
  128. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  129. package/dist/plugin/worker/loader.d.ts +1 -11
  130. package/dist/plugin/worker/loader.d.ts.map +1 -1
  131. package/dist/plugin/worker/loader.js +2 -2
  132. package/dist/plugin/worker/loader.js.map +1 -1
  133. package/dist/plugin/worker/plugin.d.ts +10 -1
  134. package/dist/plugin/worker/plugin.d.ts.map +1 -1
  135. package/dist/plugin/worker/plugin.js +10 -1
  136. package/dist/plugin/worker/rsc/index.d.ts +1 -3
  137. package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
  138. package/dist/plugin/worker/rsc/index.js +1 -9
  139. package/dist/plugin/worker/rsc/index.js.map +1 -1
  140. package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
  141. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
  142. package/dist/plugin/worker/rsc/messageHandler.js +107 -0
  143. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
  144. package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
  145. package/dist/plugin/worker/rsc/plugin.js +74 -80
  146. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
  147. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
  148. package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
  149. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
  150. package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
  151. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
  152. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
  153. package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
  154. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
  155. package/dist/plugin/worker/rsc/state.d.ts +11 -0
  156. package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
  157. package/dist/plugin/worker/rsc/state.js +12 -0
  158. package/dist/plugin/worker/rsc/state.js.map +1 -0
  159. package/dist/plugin/worker/types.d.ts +62 -35
  160. package/dist/plugin/worker/types.d.ts.map +1 -1
  161. package/dist/server.d.ts +1 -3
  162. package/dist/server.d.ts.map +1 -1
  163. package/dist/server.js +1 -3
  164. package/dist/server.js.map +1 -1
  165. package/dist/tsconfig.tsbuildinfo +1 -1
  166. package/package.json +16 -14
  167. package/plugin/assertServerCondition.ts +2 -3
  168. package/plugin/checkFilesExist.ts +46 -66
  169. package/plugin/collect-css-manifest.ts +5 -1
  170. package/plugin/config/createModuleIdGenerator.ts +52 -0
  171. package/plugin/config/defaults.ts +27 -20
  172. package/plugin/config/resolveOptions.ts +311 -25
  173. package/plugin/config/resolvePages.ts +1 -1
  174. package/plugin/config/resolveUserConfig.ts +195 -61
  175. package/plugin/helpers/getBundleManifest.ts +113 -0
  176. package/plugin/helpers/inputNormalizer.ts +186 -25
  177. package/plugin/helpers/tryManifest.ts +3 -1
  178. package/plugin/loader/createBuildLoader.ts +50 -9
  179. package/plugin/loader/createPageLoader.ts +1 -7
  180. package/plugin/loader/css-loader.ts +96 -0
  181. package/plugin/loader/react-loader.ts +945 -0
  182. package/plugin/loader/rsc/messageHandler.tsx +1 -0
  183. package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
  184. package/plugin/plugin.ts +2 -1
  185. package/plugin/preserver/plugin.ts +2 -1
  186. package/plugin/react-client/index.ts +12 -1
  187. package/plugin/react-client/plugin.ts +351 -11
  188. package/plugin/react-server/createHandler.ts +16 -18
  189. package/plugin/react-server/createRscStream.ts +75 -42
  190. package/plugin/react-server/createSsrHandler.ts +7 -26
  191. package/plugin/react-server/plugin.ts +192 -155
  192. package/plugin/transformer/plugin.ts +70 -104
  193. package/plugin/transformer/types.ts +4 -0
  194. package/plugin/types/global.d.ts +8 -0
  195. package/plugin/types.ts +120 -64
  196. package/plugin/utils/logger.ts +52 -0
  197. package/plugin/worker/createWorker.ts +43 -44
  198. package/plugin/worker/html/html-worker.production.tsx +7 -2
  199. package/plugin/worker/html/messageHandler.ts +42 -35
  200. package/plugin/worker/html/plugin.ts +15 -11
  201. package/plugin/worker/html/renderPages.ts +177 -123
  202. package/plugin/worker/loader.ts +4 -13
  203. package/plugin/worker/plugin.ts +10 -1
  204. package/plugin/worker/rsc/index.ts +4 -13
  205. package/plugin/worker/rsc/messageHandler.tsx +143 -0
  206. package/plugin/worker/rsc/plugin.ts +38 -37
  207. package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
  208. package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
  209. package/plugin/worker/rsc/rsc-worker.tsx +5 -128
  210. package/plugin/worker/rsc/state.ts +37 -0
  211. package/plugin/worker/types.ts +83 -38
  212. package/scripts/check-react-version.mjs +17 -7
  213. package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
  214. package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
  215. package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -1283
  216. package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
  217. package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
  218. package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
  219. package/dist/plugin/build/createClientBuildConfig.js +0 -14
  220. package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
  221. package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
  222. package/dist/plugin/build/createServerBuildConfig.js +0 -40
  223. package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
  224. package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
  225. package/dist/plugin/build/createSharedBuildConfig.js +0 -28
  226. package/dist/plugin/build/mergeInputs.d.ts +0 -9
  227. package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
  228. package/dist/plugin/build/mergeInputs.js +0 -56
  229. package/dist/plugin/components.js.map +0 -1
  230. package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
  231. package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
  232. package/dist/plugin/config/moduleIdDefault.js +0 -23
  233. package/dist/plugin/config/moduleIdDefault.js.map +0 -1
  234. package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
  235. package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
  236. package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
  237. package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
  238. package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
  239. package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
  240. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
  241. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
  242. package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
  243. package/dist/plugin/helpers/getModuleManifest.d.ts +0 -12
  244. package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
  245. package/dist/plugin/helpers/getModuleManifest.js +0 -24
  246. package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
  247. package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
  248. package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
  249. package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
  250. package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
  251. package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
  252. package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
  253. package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
  254. package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
  255. package/dist/plugin/helpers/resolveFilePath.js +0 -74
  256. package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
  257. package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
  258. package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
  259. package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
  260. package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
  261. package/dist/plugin/helpers/validateModuleBase.js +0 -16
  262. package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
  263. package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
  264. package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
  265. package/dist/plugin/react-server/createDevMiddleware.d.ts +0 -8
  266. package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
  267. package/dist/plugin/react-server/createDevMiddleware.js +0 -68
  268. package/dist/plugin/react-server/createDevServer.d.ts +0 -4
  269. package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
  270. package/dist/plugin/react-server/createDevServer.js +0 -4
  271. package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
  272. package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
  273. package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
  274. package/dist/plugin/transformer/transformer-client-components.d.ts +0 -21
  275. package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
  276. package/dist/plugin/transformer/transformer-client-components.js +0 -61
  277. package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
  278. package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
  279. package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
  280. package/dist/plugin/transformer/transformer-server-actions.js +0 -76
  281. package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
  282. package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
  283. package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
  284. package/dist/plugin/worker/rsc/createRscStream.js +0 -39
  285. package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
  286. package/dist/plugin/worker/rsc/development.d.ts +0 -5
  287. package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
  288. package/dist/plugin/worker/rsc/development.js +0 -13
  289. package/dist/plugin/worker/rsc/development.js.map +0 -1
  290. package/dist/plugin/worker/rsc/plugin.js.map +0 -1
  291. package/dist/plugin/worker/rsc/production.d.ts +0 -5
  292. package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
  293. package/dist/plugin/worker/rsc/production.js +0 -13
  294. package/dist/plugin/worker/rsc/production.js.map +0 -1
  295. package/plugin/build/createClientBuildConfig.ts +0 -21
  296. package/plugin/build/createServerBuildConfig.ts +0 -66
  297. package/plugin/build/createSharedBuildConfig.ts +0 -35
  298. package/plugin/build/mergeInputs.ts +0 -58
  299. package/plugin/config/moduleIdDefault.ts +0 -23
  300. package/plugin/helpers/createClientInputNormalizer.ts +0 -48
  301. package/plugin/helpers/createServerInputNormalizer.ts +0 -52
  302. package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
  303. package/plugin/helpers/getModuleManifest.ts +0 -31
  304. package/plugin/helpers/inputNormalizerWorker.ts +0 -47
  305. package/plugin/helpers/normalizedRelativePath.ts +0 -59
  306. package/plugin/helpers/resolveFilePath.ts +0 -108
  307. package/plugin/helpers/resolveWorkerModule.ts +0 -41
  308. package/plugin/helpers/validateModuleBase.ts +0 -30
  309. package/plugin/helpers/validateResolvedConfig.ts +0 -21
  310. package/plugin/react-server/createDevMiddleware.ts +0 -91
  311. package/plugin/react-server/createDevServer.ts +0 -9
  312. package/plugin/react-server/createReactNodeStreamer.ts +0 -26
  313. package/plugin/transformer/transformer-client-components.ts +0 -94
  314. package/plugin/transformer/transformer-server-actions.ts +0 -110
  315. package/plugin/worker/rsc/createRscStream.ts +0 -42
  316. package/plugin/worker/rsc/development.ts +0 -6
  317. package/plugin/worker/rsc/production.ts +0 -6
  318. package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
@@ -0,0 +1,113 @@
1
+ import type {
2
+ OutputBundle,
3
+ PluginContext,
4
+ OutputChunk,
5
+ } from "rollup";
6
+ import { createInputNormalizer } from "./inputNormalizer.js";
7
+ import { join } from "path";
8
+ import { DEFAULT_CONFIG, resolveOptions } from "../config/index.js";
9
+
10
+ interface BundleManifestEntry {
11
+ file: string;
12
+ name: string;
13
+ src?: string;
14
+ isEntry?: boolean;
15
+ imports?: string[];
16
+ dynamicImports?: string[];
17
+ css?: string[];
18
+ }
19
+
20
+ /**
21
+ * Get the bundle manifest from the plugin context. Will only work during production build
22
+ * @param pluginContext - The plugin context
23
+ * @param bundle - The bundle
24
+ * @param preserveModulesRoot - The preserve modules root
25
+ * @returns The bundle manifest
26
+ */
27
+ export function getBundleManifest({
28
+ pluginContext,
29
+ bundle,
30
+ moduleBase,
31
+ preserveModulesRoot,
32
+ }: {
33
+ pluginContext: PluginContext,
34
+ bundle: OutputBundle,
35
+ moduleBase?: string,
36
+ preserveModulesRoot?: boolean,
37
+ }): Record<string, BundleManifestEntry> {
38
+
39
+ const normalizer = createInputNormalizer({
40
+ root: pluginContext.environment.config.root,
41
+ removeExtension: DEFAULT_CONFIG.FILE_REGEX,
42
+ preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined,
43
+ });
44
+
45
+ if (!bundle) return {};
46
+
47
+ // Track virtual modules to prevent duplicates
48
+ const virtualModules = new Map<string, string>();
49
+
50
+ const bundleManifest = Object.fromEntries(
51
+ Object.entries(bundle)
52
+ .map(([fileName, chunk]) => {
53
+ if (chunk.type !== "chunk") return null as never;
54
+ const chunkWithFacade = chunk as OutputChunk;
55
+
56
+ // Get the module ID, preferring facadeModuleId
57
+ const moduleId = chunkWithFacade.facadeModuleId || chunkWithFacade.moduleIds[0] || fileName;
58
+
59
+ // Handle commonjs helpers specially - must be done before normalization
60
+ if (moduleId.includes('commonjsHelpers')) {
61
+ return [
62
+ moduleId,
63
+ {
64
+ file: 'commonjs-runtime.js',
65
+ name: 'commonjsHelpers',
66
+ src: moduleId,
67
+ isEntry: false
68
+ }
69
+ ];
70
+ }
71
+
72
+ // Normalize both paths, removing the root prefix
73
+ const [normalizedId, sourcePath] = normalizer(moduleId);
74
+
75
+ // For virtual modules, use a consistent naming scheme
76
+ let finalFileName = fileName;
77
+ if (moduleId.includes('?')) {
78
+ const [basePath, query] = moduleId.split('?');
79
+ const virtualPath = basePath.includes('node_modules')
80
+ ? basePath.split('node_modules/')[1]
81
+ : basePath;
82
+
83
+ // Create a unique key for this virtual module
84
+ const virtualKey = `${virtualPath}?${query}`;
85
+
86
+ if (!virtualModules.has(virtualKey)) {
87
+ // First time seeing this virtual module
88
+ const virtualFileName = `${virtualPath.replace(/\.js$/, '')}.${query}.js`;
89
+ virtualModules.set(virtualKey, virtualFileName);
90
+ }
91
+
92
+ finalFileName = virtualModules.get(virtualKey)!;
93
+ }
94
+ const bundleManifestEntry = [
95
+ sourcePath,
96
+ {
97
+ file: finalFileName,
98
+ name: normalizedId.startsWith('\x00') ? normalizedId.replace('\x00', '') : normalizedId,
99
+ src: sourcePath.startsWith('/') ? sourcePath.slice(1) : sourcePath,
100
+ isEntry: chunk.isEntry,
101
+ ...(chunk.imports?.length > 0 ? { imports: chunk.imports } : {}),
102
+ ...(chunk.dynamicImports?.length > 0 ? { dynamicImports: chunk.dynamicImports } : {}),
103
+ ...(chunk.viteMetadata?.importedCss?.size ? {
104
+ css: Array.from(chunk.viteMetadata.importedCss),
105
+ } : {}),
106
+ },
107
+ ];
108
+ return bundleManifestEntry;
109
+ })
110
+ .filter(Boolean)
111
+ );
112
+ return bundleManifest;
113
+ }
@@ -1,37 +1,198 @@
1
- import { join } from "path";
2
1
  import { normalizePath } from "vite";
3
- import { DEFAULT_CONFIG } from "../config/defaults.js";
4
2
  import type { InputNormalizer, NormalizerInput } from "../types.js";
3
+ import { join } from "path";
4
+ import { DEFAULT_CONFIG } from "../config/defaults.js";
5
5
 
6
- export function createInputNormalizer(root: string): InputNormalizer {
6
+ type CreateInputNormalizerProps = {
7
+ root: string;
8
+ preserveModulesRoot?: string | undefined;
9
+ removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
10
+ };
7
11
 
8
- // Normalize a key by removing file extensions and leading slashes
9
- const normalizeKey = (key: string): string => {
10
- return key
11
- .replace(DEFAULT_CONFIG.FILE_REGEX, "") // Remove TypeScript/JavaScript extensions
12
- .replace(/^\/+/, ""); // Remove leading slashes
13
- };
12
+ const resolveExtensionOptions = (
13
+ removeExtension: CreateInputNormalizerProps["removeExtension"]
14
+ ) => {
15
+ if (typeof removeExtension === "boolean") {
16
+ if (removeExtension) {
17
+ return (path: string) => {
18
+ const extensionIndex = path.lastIndexOf(".");
19
+ return extensionIndex !== -1 ? path.slice(0, extensionIndex) : path;
20
+ };
21
+ }
22
+ return (path: string) => path;
23
+ }
24
+ if (typeof removeExtension === "string") {
25
+ return (path: string) => path.replace(removeExtension, "");
26
+ }
27
+ if (removeExtension instanceof RegExp) {
28
+ return (path: string) =>
29
+ removeExtension.test(path) ? path.replace(removeExtension, "") : path;
30
+ }
31
+ if (typeof removeExtension === "function") {
32
+ return (path: string) => {
33
+ const extIndex = path.lastIndexOf(".");
34
+ if (extIndex !== -1) {
35
+ const extension = path.slice(extIndex);
36
+ if (removeExtension(extension)) {
37
+ return path.slice(0, extIndex);
38
+ }
39
+ }
40
+ return path;
41
+ };
42
+ }
43
+ return (path: string) => path;
44
+ };
14
45
 
15
- // Main normalize function
16
- return (input: NormalizerInput): [string, string] => {
46
+ const resolveRootOption = (
47
+ root: CreateInputNormalizerProps["root"],
48
+ preserveModulesRoot: CreateInputNormalizerProps["preserveModulesRoot"]
49
+ ) => {
50
+ if (typeof preserveModulesRoot === "string" && typeof root === "string") {
51
+ const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);
52
+ if (normalizedPreserveModulesRoot.startsWith(root)) {
53
+ return normalizedPreserveModulesRoot.slice(root.length + 1);
54
+ }
55
+ return "";
56
+ } else if (typeof preserveModulesRoot === "string" && typeof root !== "string") {
57
+ return normalizePath(preserveModulesRoot);
58
+ }
59
+ return "";
60
+ };
61
+ const createKeyNormalizer =
62
+ ({
63
+ root: normalizedRoot,
64
+ preserveModulesRoot,
65
+ handleExtension,
66
+ }: {
67
+ root: string;
68
+ preserveModulesRoot: string | undefined;
69
+ handleExtension: (path: string) => string;
70
+ }) =>
71
+ (key: string) => {
72
+ // Handle virtual modules first
73
+ const virtualPrefix = key.match(/^\0+/)?.[0] || '';
74
+ const actualKey = key.slice(virtualPrefix.length);
17
75
 
18
- // Handle tuple input [key, path]
19
- if (Array.isArray(input)) {
20
- const [key, path] = input;
21
- const normalized: [string, string] = [
22
- normalizeKey(key),
23
- normalizePath(join(root, path))
24
- ]
25
- return normalized;
76
+ let moduleId = normalizePath(actualKey);
77
+
78
+ if (moduleId.startsWith(normalizedRoot)) {
79
+ moduleId = moduleId.slice(normalizedRoot.length);
80
+ }
81
+
82
+ moduleId = handleExtension(moduleId);
83
+ while (moduleId.startsWith("/") || moduleId.startsWith(".")) {
84
+ moduleId = moduleId.slice(1);
85
+ }
86
+ while (moduleId.endsWith("/")) {
87
+ moduleId = moduleId.slice(0, -1);
88
+ }
89
+ if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
90
+ moduleId = moduleId.startsWith(preserveModulesRoot)
91
+ ? moduleId.slice(preserveModulesRoot.length)
92
+ : moduleId;
26
93
  }
94
+
95
+ // Add virtual prefix back
96
+ return virtualPrefix + moduleId;
97
+ };
27
98
 
28
- // Handle string input
29
- if (typeof input === "string") {
30
- const key = normalizeKey(input);
31
- const path = normalizePath(join(root, input));
32
- return [key, path];
99
+ const createPathNormalizer =
100
+ ({
101
+ root,
102
+ preserveModulesRoot,
103
+ }: {
104
+ root: string;
105
+ preserveModulesRoot: string | undefined;
106
+ }) =>
107
+ (path: string) => {
108
+ if (typeof path !== "string") {
109
+ throw new Error(`Invalid path: ${JSON.stringify(path)}`);
110
+ }
111
+ let normalPath = normalizePath(path);
112
+ if(normalPath.startsWith(root)) {
113
+ normalPath = normalPath.slice(root.length);
114
+ }
115
+ if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
116
+ normalPath = normalPath.startsWith(preserveModulesRoot)
117
+ ? normalPath.slice(preserveModulesRoot.length)
118
+ : normalPath;
33
119
  }
120
+ while (normalPath.endsWith("/")) {
121
+ normalPath = normalPath.slice(0, -1);
122
+ }
123
+ return normalPath;
124
+ };
125
+ /**
126
+ * @description Create a function that normalizes the input
127
+ * @param root - The root of the project
128
+ * @param preserveModulesRoot - The root of the preserve modules
129
+ * @param removeExtension - Whether to remove the extension of the file
130
+ * @returns A function that normalizes the input
131
+ */
132
+ export function createInputNormalizer({
133
+ root,
134
+ preserveModulesRoot = undefined,
135
+ removeExtension = DEFAULT_CONFIG.FILE_REGEX,
136
+ }: CreateInputNormalizerProps): InputNormalizer {
137
+ const relativeRoot = resolveRootOption(root, preserveModulesRoot);
138
+ const handleExtension = resolveExtensionOptions(removeExtension);
34
139
 
35
- throw new Error(`Invalid input type: ${typeof input}`);
140
+ const normalizeEntryKey = createKeyNormalizer({
141
+ root: root,
142
+ preserveModulesRoot: relativeRoot,
143
+ handleExtension,
144
+ });
145
+
146
+ const normalizeEntryPath = createPathNormalizer({
147
+ root: root,
148
+ preserveModulesRoot: relativeRoot,
149
+ });
150
+ function normalizeInput(id: NormalizerInput): [string, string] {
151
+ // Normalize both paths to use POSIX separators
152
+ if (Array.isArray(id)) {
153
+ const [key, path] = id;
154
+ if (typeof key === "string" && Array.isArray(path) && path.length === 2) {
155
+ const isNumber = !isNaN(Number(key));
156
+ if (isNumber) {
157
+ // ignore it
158
+ return normalizeInput([path[0], path[1]]);
159
+ }
160
+ return normalizeInput([join(key, path[0]), path[1]]);
161
+ }
162
+ if (typeof key !== "string" || typeof path !== "string") {
163
+ throw new Error(`Invalid input: ${JSON.stringify(id)}`);
164
+ }
165
+ return [normalizeEntryKey(key), normalizeEntryPath(path)];
166
+ } else if (typeof id === "string") {
167
+ // Return both the normalized ID and original normalized path
168
+ return [normalizeEntryKey(id), normalizeEntryPath(id)];
169
+ } else if (
170
+ typeof id === "object" &&
171
+ id !== null &&
172
+ "$$typeof" in id &&
173
+ "$$id" in id &&
174
+ typeof id.$$id === "string"
175
+ ) {
176
+ const normalized: [string, string] = [
177
+ normalizeEntryKey(id.$$id),
178
+ normalizeEntryPath(id.$$id),
179
+ ];
180
+ return normalized;
181
+ }
182
+ throw new Error(`Invalid input type: ${typeof id}`);
183
+ };
184
+
185
+ return (input: NormalizerInput): [string, string] => {
186
+ const [key, path] = normalizeInput(input);
187
+ // Apply the same normalization to both key and path
188
+ const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
189
+ const virtualPrefix = key.match(/^\0+/)?.[0] || '';
190
+
191
+ // If key has virtual prefix, ensure path has it too
192
+ const finalPath = virtualPrefix ?
193
+ (normalizedPath.startsWith(virtualPrefix) ? normalizedPath : virtualPrefix + normalizedPath) :
194
+ normalizedPath;
195
+
196
+ return [key, finalPath];
36
197
  };
37
198
  }
@@ -5,15 +5,17 @@ import type { Manifest } from "vite";
5
5
  type TryManifestOptions<SSR extends boolean> = {
6
6
  root: string;
7
7
  outDir: string;
8
- ssrManifest: SSR;
8
+ ssrManifest?: SSR;
9
9
  };
10
10
 
11
11
  export function tryManifest<SSR extends boolean>(options: TryManifestOptions<SSR>): {
12
12
  type: "success";
13
13
  manifest: SSR extends true ? Record<string, string[]> : Manifest;
14
+ error?:never
14
15
  } | {
15
16
  type: "error";
16
17
  error: Error;
18
+ manifest?:never
17
19
  } {
18
20
  const manifestPath = resolve(
19
21
  options.root,
@@ -1,23 +1,64 @@
1
- import { join } from "path";
1
+ import { join, relative, resolve } from "node:path";
2
2
  import type { PluginContext } from "rollup";
3
- import type { ResolvedUserConfig } from "../../server.js";
4
- import { DEFAULT_CONFIG } from "../config/defaults.js";
3
+ import type { ResolvedUserConfig, ResolvedUserOptions } from "../../server.js";
4
+ import type { Manifest } from "vite";
5
+ import { createInputNormalizer } from "../helpers/inputNormalizer.js";
5
6
 
6
7
  export interface BuildLoaderOptions {
7
8
  root: string;
8
9
  pluginContext: PluginContext;
9
10
  userConfig: ResolvedUserConfig;
11
+ userOptions: ResolvedUserOptions;
12
+ serverManifest: Manifest;
13
+ clientManifest: Manifest;
10
14
  }
11
15
 
12
16
  export function createBuildLoader({
13
17
  root,
14
18
  userConfig,
19
+ userOptions,
20
+ pluginContext,
21
+ serverManifest,
22
+ clientManifest,
15
23
  }: BuildLoaderOptions) {
16
- return async (id: string) => {
17
- return import(join(
18
- root,
19
- userConfig.build.outDir,
20
- id.replace(DEFAULT_CONFIG.FILE_REGEX, "") + ".js"
21
- ));
24
+ const normalizer = createInputNormalizer({
25
+ root,
26
+ preserveModulesRoot: undefined,
27
+ removeExtension: false,
28
+ });
29
+ return async function buildLoader(id: string) {
30
+ const [key, value] = normalizer(id);
31
+ // Remove leading slash if present
32
+ const distDir = userOptions.build.outDir;
33
+ const manifests = [clientManifest, serverManifest];
34
+ // Try to find the module in the manifest
35
+ for (const n of [0, 1]) {
36
+ const manifest = manifests[n];
37
+ const manifestEntry = manifest[key]
38
+ if (!manifestEntry) {
39
+ continue;
40
+ }
41
+ const isClient = userOptions.autoDiscover.clientComponents(id);
42
+ const isServer = userOptions.autoDiscover.serverFunctions(id);
43
+ const outDir = isClient
44
+ ? userOptions.build.client
45
+ : isServer
46
+ ? userOptions.build.server
47
+ : n === 0
48
+ ? userOptions.build.client
49
+ : userOptions.build.server;
50
+ if (manifestEntry.file.startsWith(`${root}/${distDir}/${outDir}/`)) {
51
+ return import(manifestEntry.file);
52
+ }
53
+ if (manifestEntry.file.startsWith(`${distDir}/`)) {
54
+ return import(join(root, manifestEntry.file));
55
+ }
56
+ if (manifestEntry.file.startsWith(`${outDir}/`)) {
57
+ return import(join(root, distDir, outDir, manifestEntry.file));
58
+ }
59
+ // Load the module
60
+ return import(join(root, distDir, outDir, manifestEntry.file));
61
+ }
62
+ throw new Error(`Module not found: ${id}`);
22
63
  };
23
64
  }
@@ -76,13 +76,7 @@ export function createPageLoader({
76
76
  registerClient,
77
77
  }: CreatePageLoaderOptions) {
78
78
  return async function loader(id: string) {
79
- console.log("[pageLoader] Loading:", {
80
- id,
81
- manifest: Object.keys(manifest),
82
- outDir,
83
- moduleBase
84
- });
85
- console.log("[pageLoader] Manifest:", manifest);
79
+
86
80
  // Try to find the entry directly or by source file
87
81
  const manifestEntry = manifest[id] ||
88
82
  Object.values(manifest).find(entry => entry.src === id);
@@ -0,0 +1,96 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { basename } from 'path';
3
+ import postcss from 'postcss';
4
+ import type { MessagePort } from 'node:worker_threads';
5
+ import type { CssFileMessage } from '../worker/types.js';
6
+ import type { LoadHookContext } from 'node:module';
7
+
8
+ type LoaderContext = {
9
+ data?: { port: MessagePort };
10
+ };
11
+ // Store port globally for CSS loader
12
+ let cssLoaderPort: MessagePort | undefined;
13
+
14
+ // Initialize hook
15
+ export async function initialize(data: { port: MessagePort }) {
16
+ cssLoaderPort = data.port; // Store port
17
+ data.port.postMessage({ type: 'INITIALIZED' });
18
+ data.port.unref();
19
+ }
20
+
21
+ // CSS file tracking per page
22
+ const cssFilesByPage = new Map<string, Set<string>>();
23
+ let currentPage: string | null = null;
24
+
25
+ export function setCurrentPage(page: string | null) {
26
+ currentPage = page;
27
+ if (page && !cssFilesByPage.has(page)) {
28
+ cssFilesByPage.set(page, new Set());
29
+ }
30
+ }
31
+
32
+ export function getCssFilesForPage(page: string): string[] {
33
+ return Array.from(cssFilesByPage.get(page) || []);
34
+ }
35
+
36
+ // Modify the CSS handling in the load function
37
+ export async function load(url: string, context: LoadHookContext & LoaderContext, defaultLoad: any) {
38
+ // Handle CSS files
39
+ if(url.endsWith(".css")) {
40
+ const source = await readFile(new URL(url), 'utf-8');
41
+
42
+ // Process CSS with PostCSS
43
+ const result = await postcss().process(source, {
44
+ from: url,
45
+ to: url,
46
+ map: {
47
+ inline: false,
48
+ annotation: false
49
+ }
50
+ });
51
+
52
+ // Generate both transformed CSS and class mappings
53
+ const moduleName = basename(url, '.css').replace('.', '_');
54
+ const classes: Record<string, string> = {};
55
+
56
+ // Transform selectors
57
+ result.root.walkRules(rule => {
58
+ const selector = rule.selector.replace('.', '');
59
+ const className = `${moduleName}_${selector}`;
60
+ classes[selector] = className;
61
+ rule.selector = `.${className}`;
62
+ });
63
+
64
+ // Get transformed CSS using root.toString()
65
+ const transformedCss = result.root.toString();
66
+
67
+ // Send processed CSS to worker
68
+ if (cssLoaderPort) {
69
+ cssLoaderPort.postMessage({
70
+ type: 'CSS_FILE',
71
+ id: url,
72
+ cssFile: transformedCss
73
+ } satisfies CssFileMessage);
74
+ }
75
+
76
+ // Return CSS module
77
+ const moduleSource = `
78
+ const styles = ${JSON.stringify(classes)};
79
+ export default styles;
80
+ export const css = ${JSON.stringify(transformedCss)};
81
+ `;
82
+
83
+ return {
84
+ format: 'module',
85
+ source: moduleSource,
86
+ shortCircuit: true
87
+ };
88
+ }
89
+ return defaultLoad(url, context, defaultLoad);
90
+ }
91
+
92
+ export function resolve(specifier: string, context: any, defaultResolve: any) {
93
+ return defaultResolve(specifier, context, defaultResolve);
94
+ }
95
+
96
+