vite-plugin-react-server 0.3.18 → 1.0.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 (246) hide show
  1. package/README.md +220 -141
  2. package/bin/patch.mjs +8 -2
  3. package/dist/package.json +15 -8
  4. package/dist/plugin/checkFilesExist.d.ts.map +1 -1
  5. package/dist/plugin/checkFilesExist.js +6 -2
  6. package/dist/plugin/checkFilesExist.js.map +1 -1
  7. package/dist/plugin/collect-manifest-client-files.d.ts +23 -0
  8. package/dist/plugin/collect-manifest-client-files.d.ts.map +1 -0
  9. package/dist/plugin/collect-manifest-client-files.js +131 -0
  10. package/dist/plugin/collect-manifest-client-files.js.map +1 -0
  11. package/dist/plugin/components.d.ts +3 -13
  12. package/dist/plugin/components.d.ts.map +1 -1
  13. package/dist/plugin/components.js +3 -13
  14. package/dist/plugin/config/defaults.d.ts +14 -6
  15. package/dist/plugin/config/defaults.d.ts.map +1 -1
  16. package/dist/plugin/config/defaults.js +9 -5
  17. package/dist/plugin/config/defaults.js.map +1 -1
  18. package/dist/plugin/config/getPaths.d.ts +0 -1
  19. package/dist/plugin/config/getPaths.d.ts.map +1 -1
  20. package/dist/plugin/config/getPaths.js +2 -7
  21. package/dist/plugin/config/getPaths.js.map +1 -1
  22. package/dist/plugin/config/mimeTypes.d.ts +2 -0
  23. package/dist/plugin/config/mimeTypes.d.ts.map +1 -0
  24. package/dist/plugin/config/mimeTypes.js +24 -0
  25. package/dist/plugin/config/mimeTypes.js.map +1 -0
  26. package/dist/plugin/config/resolveOptions.d.ts +2 -2
  27. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  28. package/dist/plugin/config/resolveOptions.js +47 -28
  29. package/dist/plugin/config/resolveOptions.js.map +1 -1
  30. package/dist/plugin/config/resolvePages.d.ts +1 -0
  31. package/dist/plugin/config/resolvePages.d.ts.map +1 -1
  32. package/dist/plugin/config/resolvePages.js +9 -5
  33. package/dist/plugin/config/resolvePages.js.map +1 -1
  34. package/dist/plugin/config/resolveUserConfig.d.ts +2 -1
  35. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  36. package/dist/plugin/config/resolveUserConfig.js +181 -147
  37. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  38. package/dist/plugin/copy-dir.js +23 -18
  39. package/dist/plugin/copy-dir.js.map +1 -0
  40. package/dist/plugin/css-collector-inline.d.ts +10 -0
  41. package/dist/plugin/css-collector-inline.d.ts.map +1 -0
  42. package/dist/plugin/css-collector-inline.js +55 -0
  43. package/dist/plugin/css-collector-inline.js.map +1 -0
  44. package/dist/plugin/css-collector.d.ts +14 -0
  45. package/dist/plugin/css-collector.d.ts.map +1 -0
  46. package/dist/plugin/css-collector.js +49 -0
  47. package/dist/plugin/css-collector.js.map +1 -0
  48. package/dist/plugin/helpers/createHandler.d.ts +17 -0
  49. package/dist/plugin/helpers/createHandler.d.ts.map +1 -0
  50. package/dist/plugin/helpers/createHandler.js +111 -0
  51. package/dist/plugin/helpers/createHandler.js.map +1 -0
  52. package/dist/plugin/helpers/createRscStream.d.ts +27 -0
  53. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -0
  54. package/dist/plugin/helpers/createRscStream.js +80 -0
  55. package/dist/plugin/helpers/createRscStream.js.map +1 -0
  56. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
  57. package/dist/plugin/helpers/getBundleManifest.js +12 -4
  58. package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
  59. package/dist/plugin/html.d.ts +5 -0
  60. package/dist/plugin/html.d.ts.map +1 -0
  61. package/dist/plugin/html.js +11 -0
  62. package/dist/plugin/html.js.map +1 -0
  63. package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
  64. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  65. package/dist/plugin/loader/createBuildLoader.js +8 -5
  66. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  67. package/dist/plugin/loader/css-loader.d.ts.map +1 -1
  68. package/dist/plugin/loader/css-loader.js.map +1 -1
  69. package/dist/plugin/loader/react-loader.js +2 -2
  70. package/dist/plugin/loader/react-loader.js.map +1 -1
  71. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  72. package/dist/plugin/preserver/plugin.js +49 -14
  73. package/dist/plugin/preserver/plugin.js.map +1 -1
  74. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  75. package/dist/plugin/react-client/plugin.js +21 -78
  76. package/dist/plugin/react-client/plugin.js.map +1 -1
  77. package/dist/plugin/react-server/index.d.ts.map +1 -1
  78. package/dist/plugin/react-server/index.js +2 -0
  79. package/dist/plugin/react-server/index.js.map +1 -1
  80. package/dist/plugin/react-server/plugin.d.ts +2 -1
  81. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  82. package/dist/plugin/react-server/plugin.js +92 -225
  83. package/dist/plugin/react-server/plugin.js.map +1 -1
  84. package/dist/plugin/react-static/index.d.ts +2 -0
  85. package/dist/plugin/react-static/index.d.ts.map +1 -0
  86. package/dist/plugin/react-static/index.js +1 -0
  87. package/dist/plugin/react-static/plugin.d.ts +7 -0
  88. package/dist/plugin/react-static/plugin.d.ts.map +1 -0
  89. package/dist/plugin/react-static/plugin.js +207 -0
  90. package/dist/plugin/react-static/plugin.js.map +1 -0
  91. package/dist/plugin/react-static/types.d.ts +2 -0
  92. package/dist/plugin/react-static/types.d.ts.map +1 -0
  93. package/dist/plugin/resolvePage.d.ts.map +1 -1
  94. package/dist/plugin/resolvePage.js +9 -0
  95. package/dist/plugin/resolvePage.js.map +1 -1
  96. package/dist/plugin/root.d.ts +2 -0
  97. package/dist/plugin/root.d.ts.map +1 -0
  98. package/dist/plugin/root.js +12 -0
  99. package/dist/plugin/root.js.map +1 -0
  100. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  101. package/dist/plugin/transformer/plugin.js +32 -23
  102. package/dist/plugin/transformer/plugin.js.map +1 -1
  103. package/dist/plugin/transformer/types.d.ts +1 -18
  104. package/dist/plugin/transformer/types.d.ts.map +1 -1
  105. package/dist/plugin/types.d.ts +70 -15
  106. package/dist/plugin/types.d.ts.map +1 -1
  107. package/dist/plugin/worker/createWorker.js +0 -1
  108. package/dist/plugin/worker/createWorker.js.map +1 -1
  109. package/dist/plugin/worker/html/html-worker.development.d.ts +30 -0
  110. package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
  111. package/dist/plugin/worker/html/html-worker.development.js +30 -2
  112. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  113. package/dist/plugin/worker/html/html-worker.production.js +3 -5
  114. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  115. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  116. package/dist/plugin/worker/html/messageHandler.js +12 -3
  117. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  118. package/dist/plugin/worker/html/renderPages.d.ts +13 -26
  119. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  120. package/dist/plugin/worker/html/renderPages.js +138 -86
  121. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  122. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  123. package/dist/plugin/worker/rsc/messageHandler.js +104 -84
  124. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  125. package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -18
  126. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  127. package/dist/plugin/worker/rsc/rsc-worker.production.js +4 -1
  128. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  129. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  130. package/dist/plugin/worker/rsc/state.js.map +1 -1
  131. package/dist/plugin/worker/types.d.ts +3 -0
  132. package/dist/plugin/worker/types.d.ts.map +1 -1
  133. package/dist/tsconfig.tsbuildinfo +1 -1
  134. package/package.json +14 -6
  135. package/plugin/checkFilesExist.ts +7 -3
  136. package/plugin/collect-manifest-client-files.ts +167 -0
  137. package/plugin/components.ts +3 -0
  138. package/plugin/config/defaults.tsx +70 -0
  139. package/plugin/config/getPaths.ts +1 -7
  140. package/plugin/config/mimeTypes.ts +17 -0
  141. package/plugin/config/resolveOptions.ts +58 -45
  142. package/plugin/config/resolvePages.ts +8 -4
  143. package/plugin/config/resolveUserConfig.ts +220 -176
  144. package/plugin/css-collector-inline.tsx +60 -0
  145. package/plugin/css-collector.tsx +62 -0
  146. package/plugin/helpers/createHandler.ts +135 -0
  147. package/plugin/helpers/createRscStream.ts +109 -0
  148. package/plugin/helpers/getBundleManifest.ts +14 -5
  149. package/plugin/html.tsx +9 -0
  150. package/plugin/loader/createBuildLoader.ts +9 -6
  151. package/plugin/loader/css-loader.ts +0 -2
  152. package/plugin/loader/react-loader.ts +2 -2
  153. package/plugin/preserver/plugin.ts +64 -17
  154. package/plugin/react-client/plugin.ts +23 -93
  155. package/plugin/react-server/index.ts +2 -0
  156. package/plugin/react-server/plugin.ts +111 -302
  157. package/plugin/react-static/index.ts +1 -0
  158. package/plugin/react-static/plugin.ts +256 -0
  159. package/plugin/react-static/types.ts +3 -0
  160. package/plugin/resolvePage.ts +9 -0
  161. package/plugin/root.ts +4 -0
  162. package/plugin/transformer/plugin.ts +40 -31
  163. package/plugin/transformer/types.ts +0 -19
  164. package/plugin/types.ts +77 -16
  165. package/plugin/worker/createWorker.ts +1 -1
  166. package/plugin/worker/html/README.md +63 -0
  167. package/plugin/worker/html/html-worker.development.tsx +89 -2
  168. package/plugin/worker/html/html-worker.production.tsx +8 -10
  169. package/plugin/worker/html/messageHandler.ts +12 -3
  170. package/plugin/worker/html/renderPages.ts +178 -138
  171. package/plugin/worker/rsc/README.md +58 -0
  172. package/plugin/worker/rsc/messageHandler.tsx +112 -113
  173. package/plugin/worker/rsc/rsc-worker.development.ts +12 -22
  174. package/plugin/worker/rsc/rsc-worker.production.ts +5 -1
  175. package/plugin/worker/rsc/state.ts +0 -3
  176. package/plugin/worker/types.ts +3 -0
  177. package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +114 -12
  178. package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +10571 -121
  179. package/tsconfig.json +2 -2
  180. package/dist/plugin/collect-css-manifest.d.ts +0 -4
  181. package/dist/plugin/collect-css-manifest.d.ts.map +0 -1
  182. package/dist/plugin/collect-css-manifest.js +0 -65
  183. package/dist/plugin/collect-css-manifest.js.map +0 -1
  184. package/dist/plugin/config/createModuleIdGenerator.d.ts +0 -11
  185. package/dist/plugin/config/createModuleIdGenerator.d.ts.map +0 -1
  186. package/dist/plugin/config/createModuleIdGenerator.js +0 -44
  187. package/dist/plugin/config/createModuleIdGenerator.js.map +0 -1
  188. package/dist/plugin/getEnv.d.ts +0 -19
  189. package/dist/plugin/getEnv.d.ts.map +0 -1
  190. package/dist/plugin/getEnv.js +0 -107
  191. package/dist/plugin/loader/createCssLoader.d.ts +0 -30
  192. package/dist/plugin/loader/createCssLoader.d.ts.map +0 -1
  193. package/dist/plugin/loader/createCssLoader.js +0 -35
  194. package/dist/plugin/loader/createPageLoader.d.ts +0 -24
  195. package/dist/plugin/loader/createPageLoader.d.ts.map +0 -1
  196. package/dist/plugin/loader/createPageLoader.js +0 -50
  197. package/dist/plugin/loader/rsc/messageHandler.d.ts +0 -2
  198. package/dist/plugin/loader/rsc/messageHandler.d.ts.map +0 -1
  199. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +0 -2
  200. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +0 -1
  201. package/dist/plugin/loader/rsc/rsc-worker.development.js +0 -1
  202. package/dist/plugin/module-graph.d.ts +0 -10
  203. package/dist/plugin/module-graph.d.ts.map +0 -1
  204. package/dist/plugin/module-graph.js +0 -35
  205. package/dist/plugin/react-server/createHandler.d.ts +0 -17
  206. package/dist/plugin/react-server/createHandler.d.ts.map +0 -1
  207. package/dist/plugin/react-server/createHandler.js +0 -126
  208. package/dist/plugin/react-server/createHandler.js.map +0 -1
  209. package/dist/plugin/react-server/createRscStream.d.ts +0 -16
  210. package/dist/plugin/react-server/createRscStream.d.ts.map +0 -1
  211. package/dist/plugin/react-server/createRscStream.js +0 -70
  212. package/dist/plugin/react-server/createRscStream.js.map +0 -1
  213. package/dist/plugin/react-server/createSsrHandler.d.ts +0 -4
  214. package/dist/plugin/react-server/createSsrHandler.d.ts.map +0 -1
  215. package/dist/plugin/react-server/createSsrHandler.js +0 -95
  216. package/dist/plugin/utils/logger.d.ts +0 -9
  217. package/dist/plugin/utils/logger.d.ts.map +0 -1
  218. package/dist/plugin/utils/logger.js +0 -68
  219. package/dist/plugin/utils/logger.js.map +0 -1
  220. package/dist/plugin/worker/html/plugin.d.ts +0 -4
  221. package/dist/plugin/worker/html/plugin.d.ts.map +0 -1
  222. package/dist/plugin/worker/html/plugin.js +0 -94
  223. package/dist/plugin/worker/plugin.d.ts +0 -19
  224. package/dist/plugin/worker/plugin.d.ts.map +0 -1
  225. package/dist/plugin/worker/plugin.js +0 -23
  226. package/dist/plugin/worker/rsc/plugin.d.ts +0 -4
  227. package/dist/plugin/worker/rsc/plugin.d.ts.map +0 -1
  228. package/dist/plugin/worker/rsc/plugin.js +0 -76
  229. package/plugin/collect-css-manifest.ts +0 -82
  230. package/plugin/components.tsx +0 -14
  231. package/plugin/config/createModuleIdGenerator.ts +0 -52
  232. package/plugin/config/defaults.ts +0 -51
  233. package/plugin/getEnv.ts +0 -135
  234. package/plugin/loader/createCssLoader.ts +0 -73
  235. package/plugin/loader/createPageLoader.ts +0 -103
  236. package/plugin/loader/rsc/messageHandler.tsx +0 -1
  237. package/plugin/loader/rsc/rsc-worker.development.ts +0 -1
  238. package/plugin/module-graph.ts +0 -48
  239. package/plugin/react-server/createHandler.ts +0 -162
  240. package/plugin/react-server/createRscStream.ts +0 -86
  241. package/plugin/react-server/createSsrHandler.ts +0 -125
  242. package/plugin/utils/logger.ts +0 -52
  243. package/plugin/worker/html/plugin.ts +0 -101
  244. package/plugin/worker/plugin.ts +0 -26
  245. package/plugin/worker/rsc/plugin.ts +0 -84
  246. /package/dist/plugin/{loader/rsc/messageHandler.js → react-static/types.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-server",
3
- "version": "0.3.18",
3
+ "version": "1.0.0",
4
4
  "description": "Vite plugin for React Server Components (RSC)",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin/index.js",
@@ -19,13 +19,15 @@
19
19
  ".": "./dist/plugin/index.js",
20
20
  "./client": "./dist/client.js",
21
21
  "./server": "./dist/server.js",
22
+ "./static": "./dist/static.js",
22
23
  "./html-worker": "./dist/plugin/worker/html-worker.js",
23
24
  "./rsc-worker": "./dist/plugin/worker/rsc-worker.js",
24
25
  "./loader": "./dist/plugin/worker/loader.js",
25
26
  "./package.json": "./package.json",
26
27
  "./patch": "./scripts/patch.mjs",
27
28
  "./check-react-version": "./scripts/check-react-version.mjs",
28
- "./css-loader": "./dist/plugin/loader/css-loader.js"
29
+ "./css-loader": "./dist/plugin/loader/css-loader.js",
30
+ "./components": "./dist/plugin/components.js"
29
31
  },
30
32
  "typesVersions": {
31
33
  "*": {
@@ -38,11 +40,17 @@
38
40
  "server": [
39
41
  "./dist/plugin/react-server/plugin.d.ts"
40
42
  ],
43
+ "static": [
44
+ "./dist/plugin/static/plugin.d.ts"
45
+ ],
41
46
  "worker": [
42
47
  "./dist/plugin/worker/worker.d.ts"
43
48
  ],
44
49
  "loader": [
45
50
  "./dist/plugin/worker/loader.d.ts"
51
+ ],
52
+ "components": [
53
+ "./dist/plugin/components.d.ts"
46
54
  ]
47
55
  }
48
56
  },
@@ -91,8 +99,8 @@
91
99
  },
92
100
  "homepage": "https://github.com/nicobrinkkemper/vite-plugin-react-server#readme",
93
101
  "peerDependencies": {
94
- "react": "^0.0.0-experimental-d55cc79b-20250228",
95
- "react-dom": "^0.0.0-experimental-d55cc79b-20250228",
102
+ "react": "^0.0.0-experimental-f9d78089-20250306",
103
+ "react-dom": "^0.0.0-experimental-f9d78089-20250306",
96
104
  "vite": "*"
97
105
  },
98
106
  "peerDependenciesMeta": {
@@ -120,13 +128,13 @@
120
128
  "typescript": "^5.7.3",
121
129
  "vite": "^6.0.11",
122
130
  "vitest": "^3.0.4",
123
- "webpack-sources": "^3.2.3"
131
+ "webpack-sources": "^3.2.3",
132
+ "tsx": "^4.19.2"
124
133
  },
125
134
  "bin": {
126
135
  "check-react-version": "./scripts/check-react-version.mjs",
127
136
  "patch": "./bin/patch.mjs"
128
137
  },
129
138
  "dependencies": {
130
- "tsx": "^4.19.2"
131
139
  }
132
140
  }
@@ -1,9 +1,10 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import type { CheckFilesExistReturn, ResolvedUserOptions } from "./types.js";
4
- import { normalizePath } from "vite";
5
4
  import { createInputNormalizer } from "./helpers/inputNormalizer.js";
6
5
 
6
+ let stashedFiles: CheckFilesExistReturn | null = null;
7
+
7
8
  const resolveFileOption = (pageOrProps: string | ((url: string) => string)) => {
8
9
  if (typeof pageOrProps === "string") {
9
10
  return () => pageOrProps;
@@ -16,6 +17,9 @@ export async function checkFilesExist(
16
17
  options: ResolvedUserOptions,
17
18
  root: string
18
19
  ): Promise<CheckFilesExistReturn> {
20
+ if(stashedFiles){
21
+ return stashedFiles;
22
+ }
19
23
  if (!root || root === "") {
20
24
  throw new Error("Root not found");
21
25
  }
@@ -57,6 +61,6 @@ export async function checkFilesExist(
57
61
  pageMap.set(pageKey, pageValue);
58
62
  propsMap.set(propsKey, propsValue);
59
63
  }
60
-
61
- return { pageMap, pageSet, propsMap, propsSet, urlMap, errors };
64
+ stashedFiles = { pageMap, pageSet, propsMap, propsSet, urlMap, errors };
65
+ return stashedFiles;
62
66
  }
@@ -0,0 +1,167 @@
1
+ import type { Manifest, ModuleGraph } from "vite";
2
+ import { createInputNormalizer } from "./helpers/inputNormalizer.js";
3
+ import { DEFAULT_CONFIG } from "./config/defaults.js";
4
+
5
+ export async function collectModuleGraphCss({
6
+ moduleGraph,
7
+ pagePath,
8
+ onCss,
9
+ parentUrl,
10
+ }: {
11
+ moduleGraph: ModuleGraph;
12
+ pagePath: string;
13
+ onCss?: (path: string, parentUrl: string) => void;
14
+ parentUrl?: string;
15
+ }) {
16
+ if (!pagePath) return new Map<string, string>();
17
+
18
+ const cssFiles = new Map<string, string>();
19
+ const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);
20
+ if (!pageModule) {
21
+ return new Map<string, string>();
22
+ }
23
+ const seen = new Set<string>();
24
+ const walkModule = (mod: any) => {
25
+ if (!mod?.id || seen.has(mod.id)) return;
26
+ seen.add(mod.id);
27
+ if (mod?.id?.endsWith(".css")) {
28
+ cssFiles.set(mod?.url, mod?.id);
29
+ onCss?.(mod?.url, parentUrl ?? pagePath);
30
+ }
31
+ mod?.importedModules?.forEach((imp: any) => walkModule(imp));
32
+ };
33
+ walkModule(pageModule);
34
+ return cssFiles;
35
+ }
36
+
37
+ export function collectManifestClientFiles({
38
+ manifest,
39
+ root,
40
+ pagePath,
41
+ preserveModulesRoot,
42
+ moduleBase,
43
+ onCss,
44
+ onClientModule,
45
+ testClient = DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents,
46
+ testJson = DEFAULT_CONFIG.AUTO_DISCOVER.jsonPattern,
47
+ }: {
48
+ manifest: Manifest;
49
+ root: string;
50
+ pagePath: string;
51
+ preserveModulesRoot?: boolean;
52
+ moduleBase?: string;
53
+ onCss?: (path: string, parentUrl: string) => void;
54
+ onClientModule?: (path: string, parentUrl: string) => void;
55
+ parentUrl?: string;
56
+ testClient?: (id: string) => boolean;
57
+ testJson?: (id: string) => boolean;
58
+ }) {
59
+ const normalizer = createInputNormalizer({
60
+ root,
61
+ removeExtension: true,
62
+ preserveModulesRoot: preserveModulesRoot ? moduleBase : undefined,
63
+ });
64
+ const [_, value] = normalizer(pagePath);
65
+
66
+ const cssFiles = new Map<string, string>();
67
+ const clientFiles = new Map<string, string>();
68
+ const seen = new Set<string>();
69
+ const manifestValues = Object.values(manifest);
70
+
71
+ // Try different variations of the path
72
+ const possibleKeys = [
73
+ value, // Relative path
74
+ ];
75
+
76
+ const walkManifestEntry = (id: string, parentUrl: string) => {
77
+ if (seen.has(id)) return;
78
+ seen.add(id);
79
+
80
+ // Get the manifest entry
81
+ const entry = manifest[id] ?? manifestValues.find((e) => id === e.file);
82
+ if (!entry) {
83
+ const hasKey = Object.keys(manifest).find((key) => id === key);
84
+ if (hasKey) {
85
+ console.log(
86
+ `Manifest entry found for ${id}, but it is ${typeof entry}`
87
+ );
88
+ return;
89
+ } else {
90
+ console.log(
91
+ `No manifest entry found for ${id}, possible keys: ${Object.keys(
92
+ manifest
93
+ ).join(", ")}`
94
+ );
95
+ }
96
+ return;
97
+ }
98
+ if (
99
+ (typeof testClient === "function" &&
100
+ typeof onClientModule === "function" &&
101
+ testClient(entry.file)) ||
102
+ (typeof testJson === "function" && testJson(entry.file))
103
+ ) {
104
+ onClientModule?.(entry.file ?? "", parentUrl);
105
+ clientFiles.set(id, entry.name ?? "");
106
+ }
107
+
108
+ // Add direct CSS from the css array
109
+ if (entry.css) {
110
+ entry.css.forEach((css: string) => {
111
+ cssFiles.set(css, css);
112
+ onCss?.(css, id);
113
+ onClientModule?.(css, id);
114
+ });
115
+ }
116
+
117
+ // Walk imports recursively
118
+ if (entry.imports) {
119
+ entry.imports.forEach((imp: string) =>
120
+ walkManifestEntry(imp, entry.file)
121
+ );
122
+ }
123
+
124
+ // Also check dynamicImports
125
+ if (entry.dynamicImports) {
126
+ entry.dynamicImports.forEach((imp: string) =>
127
+ walkManifestEntry(imp, entry.file)
128
+ );
129
+ }
130
+ };
131
+
132
+ // Try all possible keys
133
+ for (const possibleKey of possibleKeys) {
134
+ if (manifest[possibleKey]) {
135
+ walkManifestEntry(possibleKey, pagePath);
136
+ break;
137
+ }
138
+ }
139
+
140
+ // If no entry found by key, try matching by file
141
+ if (cssFiles.size === 0) {
142
+ const entry = manifestValues.find(
143
+ (e) =>
144
+ possibleKeys.includes(e.file) ||
145
+ (e.src && possibleKeys.includes(e.src)) ||
146
+ (e.name && possibleKeys.includes(e.name))
147
+ );
148
+ if (entry) {
149
+ walkManifestEntry(value, pagePath);
150
+ } else {
151
+ const hasKey = Object.keys(manifest).find((key) => value === key);
152
+ if (hasKey) {
153
+ console.warn(
154
+ `Manifest entry found for ${value}, but it is ${typeof manifest[hasKey]}`
155
+ );
156
+ } else {
157
+ console.warn(
158
+ `No manifest entry found for ${value} (tried all possible keys: ${possibleKeys.join(
159
+ ", "
160
+ )} for manifest keys: ${Object.keys(manifest).join(", ")})`
161
+ );
162
+ }
163
+ }
164
+ }
165
+
166
+ return { cssFiles, clientFiles };
167
+ }
@@ -0,0 +1,3 @@
1
+ export { Html } from "./html.js";
2
+ export { CssCollector } from "./css-collector.js";
3
+ export { InlineCssCollector } from "./css-collector-inline.js";
@@ -0,0 +1,70 @@
1
+ import { CssCollector } from "../css-collector.js";
2
+ import { Html } from "../html.js";
3
+ export const DEFAULT_CONFIG = {
4
+ FILE_REGEX: /\.(m|c)?(j|t)sx?$/,
5
+ CLIENT_ASSETS_DIR: "assets",
6
+ RSC_DIR: "rsc",
7
+ MODULE_BASE: "src",
8
+ MODULE_BASE_PATH: "",
9
+ MODULE_BASE_URL: "",
10
+ PAGE: "src/page/page.tsx",
11
+ PROPS: "src/page/props.ts",
12
+ CLIENT_ENTRY: "src/client.tsx",
13
+ SERVER_ENTRY: "src/server.tsx",
14
+ PAGE_EXPORT_NAME: "Page",
15
+ PROPS_EXPORT_NAME: "props",
16
+ HTML_WORKER_PATH: `worker/html/html-worker.${
17
+ process.env["NODE_ENV"] === "development" ? "development" : "production"
18
+ }.js`,
19
+ RSC_WORKER_PATH: `worker/rsc/rsc-worker.${
20
+ process.env["NODE_ENV"] === "development" ? "development" : "production"
21
+ }.js`,
22
+ LOADER_PATH: "worker/loader.js",
23
+ RSC_EXTENSION: ".rsc",
24
+ CSS_COLLECTOR: CssCollector,
25
+ HTML: Html,
26
+ COLLECT_CSS: true,
27
+ COLLECT_ASSETS: true,
28
+ INLINE_CSS: true,
29
+ DEV_PORT: 5173,
30
+ PREVIEW_PORT: 4173,
31
+ DEV_HOST: "localhost",
32
+ PREVIEW_HOST: "localhost",
33
+ ENV_PREFIX: "VITE_",
34
+ BUILD: {
35
+ pages: () => ["/"],
36
+ client: "client",
37
+ server: "server",
38
+ static: "static",
39
+ api: "api",
40
+ outDir: "dist",
41
+ assetsDir: "assets",
42
+ hash: "hash",
43
+ preserveModulesRoot: true,
44
+ },
45
+ CSS: {
46
+ inlineThreshold: 4096, // 4KB
47
+ inlinePatterns: [/\.module\.css$/], // Always inline CSS modules
48
+ linkPatterns: [/node_modules/], // Always link node_modules CSS
49
+ },
50
+ MODULE_BASE_EXCEPTIONS: [] as string[],
51
+ AUTO_DISCOVER: {
52
+ modulePattern: (n: string) => DEFAULT_CONFIG.FILE_REGEX.test(n),
53
+ pagePattern: (n: string) =>
54
+ n.toLowerCase().endsWith("/page") || n.toLowerCase() === "page",
55
+ propsPattern: (n: string) =>
56
+ n.toLowerCase().endsWith("/props") || n.toLowerCase() === "props",
57
+ clientComponents: (n: string) =>
58
+ n.toLowerCase().endsWith(".client") || n.toLowerCase() === "client",
59
+ serverFunctions: (n: string) =>
60
+ n.toLowerCase().endsWith(".server") || n.toLowerCase() === "server",
61
+ cssPattern: (n: string) => n.toLowerCase().endsWith(".css"),
62
+ cssModulePattern: (n: string) => n.toLowerCase().endsWith(".css.js"),
63
+ vendorPattern: (n: string) =>
64
+ n.toLowerCase().startsWith("node_modules") ||
65
+ n.toLowerCase().startsWith("_virtual"),
66
+ htmlPattern: (n: string) => n.toLowerCase().endsWith(".html"),
67
+ jsonPattern: (n: string) => n.toLowerCase().endsWith(".json"),
68
+ },
69
+ MODULE_ID: (id: string) => id,
70
+ } as const;
@@ -1,15 +1,9 @@
1
- import { join, dirname } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ import { join } from 'node:path';
3
2
 
4
3
  export const getNodePath = (root: string = process.cwd()): string => {
5
4
  return process.env['module_root'] ?? join(root, "node_modules");
6
5
  }
7
6
 
8
- export const getPluginRoot = (): string => {
9
- const __dirname = dirname(fileURLToPath(import.meta.url));
10
- return join(__dirname, '..');
11
- }
12
-
13
7
  export const getMode = (): "production" | "development" | "test" => {
14
8
  return process.env['NODE_ENV'] === "development"
15
9
  ? "development"
@@ -0,0 +1,17 @@
1
+
2
+ export const MIME_TYPES: Record<string, string> = {
3
+ '.html': 'text/html',
4
+ '.css': 'text/css',
5
+ '.js': 'application/javascript',
6
+ '.json': 'application/json',
7
+ '.png': 'image/png',
8
+ '.jpg': 'image/jpeg',
9
+ '.jpeg': 'image/jpeg',
10
+ '.gif': 'image/gif',
11
+ '.svg': 'image/svg+xml',
12
+ '.ico': 'image/x-icon',
13
+ '.woff': 'font/woff',
14
+ '.woff2': 'font/woff2',
15
+ '.ttf': 'font/ttf',
16
+ '.rsc': 'text/x-component'
17
+ };
@@ -1,9 +1,11 @@
1
1
  import type { PreRenderedAsset } from "rollup";
2
2
  import type { PreRenderedChunk } from "rollup";
3
- import type { StreamPluginOptions, ResolvedUserOptions } from "../types.js";
3
+ import type { StreamPluginOptions, ResolvedUserOptions, InlineCssCollectorProps, CssCollectorProps } from "../types.js";
4
4
  import { DEFAULT_CONFIG } from "./defaults.js";
5
- import { createModuleIdGenerator } from "./createModuleIdGenerator.js";
6
- import { normalizePath } from "vite";
5
+ import { join } from "node:path";
6
+ import { pluginRoot } from "../root.js";
7
+ import { InlineCssCollector } from "../css-collector-inline.js";
8
+ import { CssCollector } from "../css-collector.js";
7
9
 
8
10
  const resolveAutoDiscoverMatcher = (
9
11
  options: undefined | string | RegExp | ((path: string) => boolean),
@@ -45,18 +47,18 @@ const handleSearchQuery = (path: string) => {
45
47
 
46
48
  const applyPattern = (
47
49
  path: string,
48
- pattern?: string | RegExp | ((path: string) => boolean) | undefined,
49
- fallback?: string | undefined
50
+ _pattern?: string | RegExp | ((path: string) => boolean) | undefined,
51
+ _fallback?: string | undefined
50
52
  ) => {
51
53
  // TODO: What to actually do here? I guess we could replace the extension, but it's not needed since we map them from the manifest anyway.
52
54
  return path;
53
55
  };
54
56
 
55
- export const resolveOptions = (
56
- options: StreamPluginOptions,
57
- isClient: boolean = false
57
+ export const resolveOptions = <InlineCSS extends boolean = boolean>(
58
+ options: StreamPluginOptions<InlineCSS>,
59
+ isClient: boolean
58
60
  ):
59
- | { type: "success"; userOptions: ResolvedUserOptions }
61
+ | { type: "success"; userOptions: ResolvedUserOptions<InlineCSS> }
60
62
  | { type: "error"; error: Error } => {
61
63
  const projectRoot = options.projectRoot ?? process.cwd();
62
64
  const {
@@ -149,7 +151,9 @@ export const resolveOptions = (
149
151
  const hashString = hashOption === "" ? "" : `-[${hashOption}]`;
150
152
  const hash = (n: string | null) => {
151
153
  if (!n) return "";
152
- if (hashString === "") return n;
154
+ if (hashString === "" || ( !isClient && !n.endsWith('.css') && !n.endsWith('.json') ) ) {
155
+ return n;
156
+ }
153
157
  const extensionIndex = n.lastIndexOf(".");
154
158
  if (extensionIndex !== -1) {
155
159
  // put hash between extension and filename
@@ -172,19 +176,27 @@ export const resolveOptions = (
172
176
  if (testVendor(path)) {
173
177
  return path;
174
178
  }
175
-
179
+
176
180
  if (testCssModule(path)) {
177
181
  // For CSS modules, keep the .css.js extension
178
- return applyPattern(path, options.autoDiscover?.cssModulePattern, ".css.js");
182
+ return applyPattern(
183
+ path,
184
+ options.autoDiscover?.cssModulePattern,
185
+ ".css.js"
186
+ );
179
187
  }
180
-
188
+
181
189
  if (testCss(path)) {
182
190
  // For regular CSS files, keep the .css extension
183
191
  return applyPattern(path, options.autoDiscover?.cssPattern, ".css");
184
192
  }
185
193
 
186
194
  if (testClientComponents(path)) {
187
- return applyPattern(path, options.autoDiscover?.clientComponents, "client");
195
+ return applyPattern(
196
+ path,
197
+ options.autoDiscover?.clientComponents,
198
+ "client"
199
+ );
188
200
  }
189
201
  if (testHtml(path)) {
190
202
  return applyPattern(path, options.autoDiscover?.htmlPattern, ".html");
@@ -209,7 +221,11 @@ export const resolveOptions = (
209
221
  );
210
222
  }
211
223
  if (testServerFunctions(path)) {
212
- return applyPattern(path, options.autoDiscover?.serverFunctions, "server");
224
+ return applyPattern(
225
+ path,
226
+ options.autoDiscover?.serverFunctions,
227
+ "server"
228
+ );
213
229
  }
214
230
  if (testModulePattern(path)) {
215
231
  return path;
@@ -220,23 +236,23 @@ export const resolveOptions = (
220
236
  const entryFile = (n: PreRenderedChunk) => {
221
237
  if (testVendor(n.name)) {
222
238
  const search = n.facadeModuleId?.split("?")[1];
223
- if(search) {
224
- return `${n.name}.${search}.js`;
239
+ if (search) {
240
+ return hash(`${n.name}.${search}.js`);
225
241
  } else {
226
- return n.name + ".js";
242
+ return hash(`${n.name}.js`);
227
243
  }
228
244
  }
229
- return addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name))));
245
+ return hash(addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name)))));
230
246
  };
231
247
 
232
248
  const chunkFile = (n: PreRenderedChunk) => {
233
249
  // For chunks, we always want .js
234
- return addJS(getOutputPath(ensureModuleBase(ensureNoRoot('_'+n.name))));
250
+ return hash(addJS(getOutputPath(ensureModuleBase(ensureNoRoot("_" + n.name)))));
235
251
  };
236
252
 
237
253
  const assetFile = (n: PreRenderedAsset) => {
238
254
  // For assets, keep the original extension
239
- return getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0])));
255
+ return hash(getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0]))));
240
256
  };
241
257
 
242
258
  const build =
@@ -286,13 +302,23 @@ export const resolveOptions = (
286
302
  const moduleBasePath =
287
303
  typeof options.moduleBasePath === "string"
288
304
  ? options.moduleBasePath
289
- : options.moduleBase.startsWith("/")
290
- ? options.moduleBase
291
- : "/" + options.moduleBase;
305
+ : DEFAULT_CONFIG.MODULE_BASE_PATH;
292
306
  const moduleBaseURL =
293
307
  typeof options.moduleBaseURL === "string"
294
308
  ? options.moduleBaseURL
295
- : moduleBasePath ?? DEFAULT_CONFIG.MODULE_BASE_URL;
309
+ : DEFAULT_CONFIG.MODULE_BASE_URL;
310
+ const rscWorkerPath =
311
+ typeof options.rscWorkerPath === "string"
312
+ ? join(projectRoot, options.rscWorkerPath)
313
+ : join(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
314
+ const htmlWorkerPath =
315
+ typeof options.htmlWorkerPath === "string"
316
+ ? join(projectRoot, options.htmlWorkerPath)
317
+ : join(pluginRoot, DEFAULT_CONFIG.HTML_WORKER_PATH);
318
+ const loaderPath =
319
+ typeof options.loaderPath === "string"
320
+ ? join(projectRoot, options.loaderPath)
321
+ : join(pluginRoot, DEFAULT_CONFIG.LOADER_PATH);
296
322
 
297
323
  const autoDiscover = {
298
324
  modulePattern: testModulePattern,
@@ -305,27 +331,13 @@ export const resolveOptions = (
305
331
  cssModulePattern: testCssModule,
306
332
  vendorPattern: testVendor,
307
333
  };
308
-
309
- const moduleId =
310
- typeof options.moduleId === "function"
311
- ? options.moduleId
312
- : createModuleIdGenerator({
313
- isProduction: process.env["NODE_ENV"] === "production",
314
- inputRoot: projectRoot,
315
- client: client,
316
- server: server,
317
- moduleBase: moduleBase,
318
- preserveModulesRoot: preserveModulesRoot,
319
- removeExtension: DEFAULT_CONFIG.FILE_REGEX,
320
- imports: {},
321
- });
322
-
334
+ const inlineCss = options.inlineCss;
335
+ const InlineOrLinkCssCollector = options.CssCollector ?? inlineCss ? InlineCssCollector : CssCollector;
323
336
  try {
324
337
  return {
325
338
  type: "success",
326
339
  userOptions: {
327
340
  projectRoot,
328
- moduleId: moduleId,
329
341
  moduleBase,
330
342
  moduleBasePath,
331
343
  moduleBaseURL,
@@ -333,14 +345,15 @@ export const resolveOptions = (
333
345
  Page: options.Page ?? DEFAULT_CONFIG.PAGE,
334
346
  props: options.props ?? DEFAULT_CONFIG.PROPS,
335
347
  Html: options.Html ?? DEFAULT_CONFIG.HTML,
348
+ CssCollector: InlineOrLinkCssCollector as InlineCSS extends true ? React.FC<React.PropsWithChildren<InlineCssCollectorProps>> : React.FC<React.PropsWithChildren<CssCollectorProps>>,
336
349
  pageExportName: pageExportName,
337
350
  propsExportName: propsExportName,
338
351
  collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,
339
352
  collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,
340
- htmlWorkerPath:
341
- options.htmlWorkerPath ?? DEFAULT_CONFIG.HTML_WORKER_PATH,
342
- rscWorkerPath: options.rscWorkerPath ?? DEFAULT_CONFIG.RSC_WORKER_PATH,
343
- loaderPath: options.loaderPath ?? DEFAULT_CONFIG.LOADER_PATH,
353
+ inlineCss: options.inlineCss ?? DEFAULT_CONFIG.INLINE_CSS,
354
+ htmlWorkerPath: htmlWorkerPath,
355
+ rscWorkerPath: rscWorkerPath,
356
+ loaderPath: loaderPath,
344
357
  clientEntry: options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
345
358
  serverEntry: options.serverEntry ?? DEFAULT_CONFIG.SERVER_ENTRY,
346
359
  moduleBaseExceptions: options.moduleBaseExceptions ?? [],
@@ -1,8 +1,12 @@
1
1
  import type { ResolvedUserOptions } from '../types.js';
2
2
 
3
+ export let stashedPages: string[] = [];
3
4
  export async function resolvePages(
4
5
  pages: ResolvedUserOptions["build"]["pages"]
5
6
  ): Promise<{ type: "success"; error?:never; pages: string[] } | { type: "error"; error: Error; pages?:never }> {
7
+ if(stashedPages.length > 0){
8
+ return { type: "success", pages: stashedPages };
9
+ }
6
10
  if (!pages) {
7
11
  return { type: "success", pages: [] };
8
12
  }
@@ -10,24 +14,24 @@ export async function resolvePages(
10
14
  try {
11
15
  // Handle function
12
16
  if (typeof pages === "function") {
13
- const result = await Promise.resolve(pages());
14
- return resolvePages(result);
17
+ return resolvePages(pages());
15
18
  }
16
19
 
17
20
  // Handle Promise
18
21
  if (pages instanceof Promise) {
19
- const result = await pages;
20
- return resolvePages(result);
22
+ return resolvePages(await pages);
21
23
  }
22
24
 
23
25
  // Handle string
24
26
  if (typeof pages === "string") {
27
+ stashedPages = [pages];
25
28
  return { type: "success", pages: [pages] };
26
29
  }
27
30
 
28
31
  // Handle array
29
32
  if (Array.isArray(pages)) {
30
33
  if (pages.every(page => typeof page === "string")) {
34
+ stashedPages = pages;
31
35
  return { type: "success", pages };
32
36
  }
33
37
  throw new Error('All pages must be strings');