@cedarjs/vite 0.0.4

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 (213) hide show
  1. package/LICENSE +21 -0
  2. package/bins/rw-vite-build.mjs +61 -0
  3. package/bins/rw-vite-dev.mjs +57 -0
  4. package/bins/vite.mjs +12 -0
  5. package/dist/build/build.d.ts +21 -0
  6. package/dist/build/build.d.ts.map +1 -0
  7. package/dist/build/build.js +78 -0
  8. package/dist/buildFeServer.d.ts +6 -0
  9. package/dist/buildFeServer.d.ts.map +1 -0
  10. package/dist/buildFeServer.js +39 -0
  11. package/dist/buildRouteHooks.d.ts +3 -0
  12. package/dist/buildRouteHooks.d.ts.map +1 -0
  13. package/dist/buildRouteHooks.js +45 -0
  14. package/dist/buildRouteManifest.d.ts +6 -0
  15. package/dist/buildRouteManifest.d.ts.map +1 -0
  16. package/dist/buildRouteManifest.js +58 -0
  17. package/dist/buildRscClientAndServer.d.ts +4 -0
  18. package/dist/buildRscClientAndServer.d.ts.map +1 -0
  19. package/dist/buildRscClientAndServer.js +30 -0
  20. package/dist/bundled/react-server-dom-webpack.server.d.ts +2 -0
  21. package/dist/bundled/react-server-dom-webpack.server.d.ts.map +1 -0
  22. package/dist/bundled/react-server-dom-webpack.server.js +33529 -0
  23. package/dist/cjs/ClientRouter.d.ts +1 -0
  24. package/dist/cjs/build/build.d.ts +1 -0
  25. package/dist/cjs/build/build.js +116 -0
  26. package/dist/cjs/buildFeServer.d.ts +1 -0
  27. package/dist/cjs/buildFeServer.js +63 -0
  28. package/dist/cjs/buildRouteHooks.js +66 -0
  29. package/dist/cjs/buildRouteManifest.js +92 -0
  30. package/dist/cjs/buildRscClientAndServer.js +54 -0
  31. package/dist/cjs/client.d.ts +1 -0
  32. package/dist/cjs/clientSsr.d.ts +1 -0
  33. package/dist/cjs/devFeServer.js +153 -0
  34. package/dist/cjs/index.d.ts +1 -0
  35. package/dist/cjs/index.js +184 -0
  36. package/dist/cjs/lib/StatusError.js +36 -0
  37. package/dist/cjs/lib/entries.js +53 -0
  38. package/dist/cjs/lib/envVarDefinitions.js +87 -0
  39. package/dist/cjs/lib/getMergedConfig.js +187 -0
  40. package/dist/cjs/lib/onWarn.js +36 -0
  41. package/dist/cjs/lib/registerFwGlobalsAndShims.js +117 -0
  42. package/dist/cjs/middleware/index.js +22 -0
  43. package/dist/cjs/middleware/invokeMiddleware.js +52 -0
  44. package/dist/cjs/middleware/register.js +106 -0
  45. package/dist/cjs/middleware/types.js +16 -0
  46. package/dist/cjs/package.json +1 -0
  47. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +42 -0
  48. package/dist/cjs/plugins/vite-plugin-remove-from-bundle.js +56 -0
  49. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +104 -0
  50. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +75 -0
  51. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +159 -0
  52. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +125 -0
  53. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +75 -0
  54. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +229 -0
  55. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +398 -0
  56. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +41 -0
  57. package/dist/cjs/rsc/rscBuildAnalyze.js +116 -0
  58. package/dist/cjs/rsc/rscBuildClient.js +91 -0
  59. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +56 -0
  60. package/dist/cjs/rsc/rscBuildEntriesFile.js +115 -0
  61. package/dist/cjs/rsc/rscBuildForServer.js +157 -0
  62. package/dist/cjs/rsc/rscBuildForSsr.js +172 -0
  63. package/dist/cjs/rsc/rscBuildRwEnvVars.js +56 -0
  64. package/dist/cjs/rsc/rscRenderer.js +165 -0
  65. package/dist/cjs/rsc/rscRequestHandler.js +162 -0
  66. package/dist/cjs/rsc/rscStudioHandlers.js +154 -0
  67. package/dist/cjs/runFeServer.js +166 -0
  68. package/dist/cjs/streaming/buildForStreamingServer.js +65 -0
  69. package/dist/cjs/streaming/collectCss.js +52 -0
  70. package/dist/cjs/streaming/createReactStreamingHandler.js +173 -0
  71. package/dist/cjs/streaming/streamHelpers.js +228 -0
  72. package/dist/cjs/streaming/transforms/bufferedTransform.js +61 -0
  73. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +34 -0
  74. package/dist/cjs/streaming/transforms/encode-decode.js +36 -0
  75. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +84 -0
  76. package/dist/cjs/streaming/triggerRouteHooks.js +96 -0
  77. package/dist/cjs/types.js +16 -0
  78. package/dist/cjs/utils.js +91 -0
  79. package/dist/devFeServer.d.ts +2 -0
  80. package/dist/devFeServer.d.ts.map +1 -0
  81. package/dist/devFeServer.js +134 -0
  82. package/dist/index.d.ts +6 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +154 -0
  85. package/dist/lib/StatusError.d.ts +8 -0
  86. package/dist/lib/StatusError.d.ts.map +1 -0
  87. package/dist/lib/StatusError.js +11 -0
  88. package/dist/lib/entries.d.ts +3 -0
  89. package/dist/lib/entries.d.ts.map +1 -0
  90. package/dist/lib/entries.js +32 -0
  91. package/dist/lib/envVarDefinitions.d.ts +14 -0
  92. package/dist/lib/envVarDefinitions.d.ts.map +1 -0
  93. package/dist/lib/envVarDefinitions.js +53 -0
  94. package/dist/lib/getMergedConfig.d.ts +11 -0
  95. package/dist/lib/getMergedConfig.d.ts.map +1 -0
  96. package/dist/lib/getMergedConfig.js +153 -0
  97. package/dist/lib/onWarn.d.ts +3 -0
  98. package/dist/lib/onWarn.d.ts.map +1 -0
  99. package/dist/lib/onWarn.js +12 -0
  100. package/dist/lib/registerFwGlobalsAndShims.d.ts +12 -0
  101. package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -0
  102. package/dist/lib/registerFwGlobalsAndShims.js +83 -0
  103. package/dist/middleware/index.d.ts +2 -0
  104. package/dist/middleware/index.d.ts.map +1 -0
  105. package/dist/middleware/index.js +1 -0
  106. package/dist/middleware/invokeMiddleware.d.ts +14 -0
  107. package/dist/middleware/invokeMiddleware.d.ts.map +1 -0
  108. package/dist/middleware/invokeMiddleware.js +32 -0
  109. package/dist/middleware/register.d.ts +23 -0
  110. package/dist/middleware/register.d.ts.map +1 -0
  111. package/dist/middleware/register.js +69 -0
  112. package/dist/middleware/types.d.ts +3 -0
  113. package/dist/middleware/types.d.ts.map +1 -0
  114. package/dist/middleware/types.js +0 -0
  115. package/dist/package.json +1 -0
  116. package/dist/plugins/vite-plugin-jsx-loader.d.ts +8 -0
  117. package/dist/plugins/vite-plugin-jsx-loader.d.ts.map +1 -0
  118. package/dist/plugins/vite-plugin-jsx-loader.js +18 -0
  119. package/dist/plugins/vite-plugin-remove-from-bundle.d.ts +17 -0
  120. package/dist/plugins/vite-plugin-remove-from-bundle.d.ts.map +1 -0
  121. package/dist/plugins/vite-plugin-remove-from-bundle.js +31 -0
  122. package/dist/plugins/vite-plugin-rsc-analyze.d.ts +3 -0
  123. package/dist/plugins/vite-plugin-rsc-analyze.d.ts.map +1 -0
  124. package/dist/plugins/vite-plugin-rsc-analyze.js +70 -0
  125. package/dist/plugins/vite-plugin-rsc-reload.d.ts +3 -0
  126. package/dist/plugins/vite-plugin-rsc-reload.d.ts.map +1 -0
  127. package/dist/plugins/vite-plugin-rsc-reload.js +41 -0
  128. package/dist/plugins/vite-plugin-rsc-routes-auto-loader.d.ts +3 -0
  129. package/dist/plugins/vite-plugin-rsc-routes-auto-loader.d.ts.map +1 -0
  130. package/dist/plugins/vite-plugin-rsc-routes-auto-loader.js +130 -0
  131. package/dist/plugins/vite-plugin-rsc-routes-imports.d.ts +3 -0
  132. package/dist/plugins/vite-plugin-rsc-routes-imports.d.ts.map +1 -0
  133. package/dist/plugins/vite-plugin-rsc-routes-imports.js +96 -0
  134. package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts +7 -0
  135. package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -0
  136. package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +41 -0
  137. package/dist/plugins/vite-plugin-rsc-transform-client.d.ts +3 -0
  138. package/dist/plugins/vite-plugin-rsc-transform-client.d.ts.map +1 -0
  139. package/dist/plugins/vite-plugin-rsc-transform-client.js +195 -0
  140. package/dist/plugins/vite-plugin-rsc-transform-server.d.ts +3 -0
  141. package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -0
  142. package/dist/plugins/vite-plugin-rsc-transform-server.js +364 -0
  143. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +12 -0
  144. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -0
  145. package/dist/plugins/vite-plugin-swap-apollo-provider.js +17 -0
  146. package/dist/rsc/rscBuildAnalyze.d.ts +16 -0
  147. package/dist/rsc/rscBuildAnalyze.d.ts.map +1 -0
  148. package/dist/rsc/rscBuildAnalyze.js +92 -0
  149. package/dist/rsc/rscBuildClient.d.ts +7 -0
  150. package/dist/rsc/rscBuildClient.d.ts.map +1 -0
  151. package/dist/rsc/rscBuildClient.js +67 -0
  152. package/dist/rsc/rscBuildCopyCssAssets.d.ts +7 -0
  153. package/dist/rsc/rscBuildCopyCssAssets.d.ts.map +1 -0
  154. package/dist/rsc/rscBuildCopyCssAssets.js +22 -0
  155. package/dist/rsc/rscBuildEntriesFile.d.ts +10 -0
  156. package/dist/rsc/rscBuildEntriesFile.d.ts.map +1 -0
  157. package/dist/rsc/rscBuildEntriesFile.js +81 -0
  158. package/dist/rsc/rscBuildForServer.d.ts +7 -0
  159. package/dist/rsc/rscBuildForServer.d.ts.map +1 -0
  160. package/dist/rsc/rscBuildForServer.js +133 -0
  161. package/dist/rsc/rscBuildForSsr.d.ts +9 -0
  162. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -0
  163. package/dist/rsc/rscBuildForSsr.js +138 -0
  164. package/dist/rsc/rscBuildRwEnvVars.d.ts +10 -0
  165. package/dist/rsc/rscBuildRwEnvVars.d.ts.map +1 -0
  166. package/dist/rsc/rscBuildRwEnvVars.js +22 -0
  167. package/dist/rsc/rscRenderer.d.ts +9 -0
  168. package/dist/rsc/rscRenderer.d.ts.map +1 -0
  169. package/dist/rsc/rscRenderer.js +130 -0
  170. package/dist/rsc/rscRequestHandler.d.ts +10 -0
  171. package/dist/rsc/rscRequestHandler.d.ts.map +1 -0
  172. package/dist/rsc/rscRequestHandler.js +131 -0
  173. package/dist/rsc/rscStudioHandlers.d.ts +10 -0
  174. package/dist/rsc/rscStudioHandlers.d.ts.map +1 -0
  175. package/dist/rsc/rscStudioHandlers.js +120 -0
  176. package/dist/runFeServer.d.ts +2 -0
  177. package/dist/runFeServer.d.ts.map +1 -0
  178. package/dist/runFeServer.js +132 -0
  179. package/dist/streaming/buildForStreamingServer.d.ts +4 -0
  180. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -0
  181. package/dist/streaming/buildForStreamingServer.js +41 -0
  182. package/dist/streaming/collectCss.d.ts +7 -0
  183. package/dist/streaming/collectCss.d.ts.map +1 -0
  184. package/dist/streaming/collectCss.js +27 -0
  185. package/dist/streaming/createReactStreamingHandler.d.ts +12 -0
  186. package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -0
  187. package/dist/streaming/createReactStreamingHandler.js +139 -0
  188. package/dist/streaming/streamHelpers.d.ts +23 -0
  189. package/dist/streaming/streamHelpers.d.ts.map +1 -0
  190. package/dist/streaming/streamHelpers.js +192 -0
  191. package/dist/streaming/transforms/bufferedTransform.d.ts +2 -0
  192. package/dist/streaming/transforms/bufferedTransform.d.ts.map +1 -0
  193. package/dist/streaming/transforms/bufferedTransform.js +37 -0
  194. package/dist/streaming/transforms/cancelTimeoutTransform.d.ts +2 -0
  195. package/dist/streaming/transforms/cancelTimeoutTransform.d.ts.map +1 -0
  196. package/dist/streaming/transforms/cancelTimeoutTransform.js +10 -0
  197. package/dist/streaming/transforms/encode-decode.d.ts +3 -0
  198. package/dist/streaming/transforms/encode-decode.d.ts.map +1 -0
  199. package/dist/streaming/transforms/encode-decode.js +11 -0
  200. package/dist/streaming/transforms/serverInjectionTransform.d.ts +16 -0
  201. package/dist/streaming/transforms/serverInjectionTransform.d.ts.map +1 -0
  202. package/dist/streaming/transforms/serverInjectionTransform.js +60 -0
  203. package/dist/streaming/triggerRouteHooks.d.ts +26 -0
  204. package/dist/streaming/triggerRouteHooks.d.ts.map +1 -0
  205. package/dist/streaming/triggerRouteHooks.js +71 -0
  206. package/dist/types.d.ts +31 -0
  207. package/dist/types.d.ts.map +1 -0
  208. package/dist/types.js +0 -0
  209. package/dist/utils.d.ts +14 -0
  210. package/dist/utils.d.ts.map +1 -0
  211. package/dist/utils.js +62 -0
  212. package/inject/reactRefresh.js +7 -0
  213. package/package.json +116 -0
@@ -0,0 +1,81 @@
1
+ import fs from "fs/promises";
2
+ import { normalizePath } from "vite";
3
+ import { getPaths } from "@cedarjs/project-config";
4
+ async function rscBuildEntriesMappings(clientBuildOutput, ssrBuildOutput, serverBuildOutput, clientEntryFiles) {
5
+ console.log("\n");
6
+ console.log("6. rscBuildEntriesMapping");
7
+ console.log("=========================\n");
8
+ const rwPaths = getPaths();
9
+ const clientEntries = {};
10
+ for (const item of clientBuildOutput) {
11
+ const { name, fileName } = item;
12
+ const entryFile = name && // TODO (RSC) Can't we just compare the names? `item.name === name`
13
+ serverBuildOutput.find(
14
+ (item2) => "moduleIds" in item2 && item2.moduleIds.includes(clientEntryFiles[name])
15
+ )?.fileName;
16
+ if (entryFile) {
17
+ if (process.platform === "win32") {
18
+ const entryFileSlash = entryFile.replaceAll("\\", "/");
19
+ clientEntries[entryFileSlash] = fileName;
20
+ } else {
21
+ clientEntries[entryFile] = fileName;
22
+ }
23
+ }
24
+ }
25
+ console.log("clientEntries", clientEntries);
26
+ const ssrEntries = {};
27
+ for (const item of ssrBuildOutput) {
28
+ const { name, fileName } = item;
29
+ const entryFile = name && // TODO (RSC) Can't we just compare the names? `item.name === name`
30
+ serverBuildOutput.find(
31
+ (item2) => "moduleIds" in item2 && item2.moduleIds.includes(clientEntryFiles[name])
32
+ )?.fileName;
33
+ if (entryFile) {
34
+ if (process.platform === "win32") {
35
+ const entryFileSlash = entryFile.replaceAll("\\", "/");
36
+ ssrEntries[entryFileSlash] = fileName;
37
+ } else {
38
+ ssrEntries[entryFile] = fileName;
39
+ }
40
+ }
41
+ }
42
+ console.log("ssrEntries", ssrEntries);
43
+ await fs.appendFile(
44
+ rwPaths.web.distRscEntries,
45
+ `// client component mapping (dist/rsc -> dist/browser)
46
+ export const clientEntries = ${JSON.stringify(clientEntries, void 0, 2)};
47
+
48
+ `
49
+ );
50
+ await fs.appendFile(
51
+ rwPaths.web.distRscEntries,
52
+ `// client component mapping (dist/rsc -> dist/ssr)
53
+ export const ssrEntries = ${JSON.stringify(ssrEntries, void 0, 2)};
54
+
55
+ `
56
+ );
57
+ const serverEntries = {};
58
+ const entries = {
59
+ __rwjs__ServerEntry: getPaths().web.entryServer || "",
60
+ __rwjs__Routes: getPaths().web.routes
61
+ };
62
+ for (const [name, sourceFile] of Object.entries(entries)) {
63
+ const buildOutputItem = serverBuildOutput.find((item) => {
64
+ return item.facadeModuleId === normalizePath(sourceFile);
65
+ });
66
+ if (buildOutputItem) {
67
+ serverEntries[name] = buildOutputItem.fileName;
68
+ }
69
+ }
70
+ console.log("serverEntries", serverEntries);
71
+ await fs.appendFile(
72
+ rwPaths.web.distRscEntries,
73
+ `// server component mapping (src -> dist/rsc)
74
+ export const serverEntries = ${JSON.stringify(serverEntries, void 0, 2)};
75
+
76
+ `
77
+ );
78
+ }
79
+ export {
80
+ rscBuildEntriesMappings
81
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * RSC build. Step 4.
3
+ * buildFeServer -> buildRscFeServer -> rscBuildForServer
4
+ * Generate the output to be used by the rsc worker (not the actual server!)
5
+ */
6
+ export declare function rscBuildForServer(clientEntryFiles: Record<string, string>, serverEntryFiles: Record<string, string>, customModules: Record<string, string>): Promise<[import("rollup").OutputChunk, ...(import("rollup").OutputChunk | import("rollup").OutputAsset)[]]>;
7
+ //# sourceMappingURL=rscBuildForServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscBuildForServer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscBuildForServer.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,+GAyItC"}
@@ -0,0 +1,133 @@
1
+ import { build as viteBuild } from "vite";
2
+ import { getPaths } from "@cedarjs/project-config";
3
+ import { getEntries } from "../lib/entries.js";
4
+ import { onWarn } from "../lib/onWarn.js";
5
+ import { rscRoutesImports } from "../plugins/vite-plugin-rsc-routes-imports.js";
6
+ import { rscTransformUseClientPlugin } from "../plugins/vite-plugin-rsc-transform-client.js";
7
+ import { rscTransformUseServerPlugin } from "../plugins/vite-plugin-rsc-transform-server.js";
8
+ async function rscBuildForServer(clientEntryFiles, serverEntryFiles, customModules) {
9
+ console.log("\n");
10
+ console.log("4. rscBuildForServer");
11
+ console.log("====================\n");
12
+ const rwPaths = getPaths();
13
+ const entryFiles = getEntries();
14
+ const entryFilesKeys = Object.keys(entryFiles);
15
+ if (!rwPaths.web.entryServer) {
16
+ throw new Error("Server Entry file not found");
17
+ }
18
+ const outDir = rwPaths.web.distRsc;
19
+ const rscServerBuildOutput = await viteBuild({
20
+ envFile: false,
21
+ define: {
22
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
23
+ },
24
+ ssr: {
25
+ // Inline every file apart from node built-ins. We want vite/rollup to
26
+ // inline dependencies in the server build. This gets round runtime
27
+ // importing of "server-only" and other packages with poisoned imports.
28
+ //
29
+ // Files included in `noExternal` are files we want Vite to analyze
30
+ // As of vite 5.2 `true` here means "all except node built-ins"
31
+ noExternal: true,
32
+ // TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
33
+ // What are we missing here? When/why is that a better choice? I know
34
+ // we would have to explicitly add a bunch of packages to noExternal, if
35
+ // we wanted to go that route.
36
+ // noExternal: ['@tobbe.dev/rsc-test'],
37
+ // Can't inline prisma client (db calls fail at runtime) or react-dom
38
+ // (css pre-init failure)
39
+ // Server store has to be externalized, because it's a singleton (shared between FW and App)
40
+ external: [
41
+ "@prisma/client",
42
+ "@prisma/fetch-engine",
43
+ "@prisma/internals",
44
+ "@cedarjs/auth-dbauth-api",
45
+ "@cedarjs/cookie-jar",
46
+ "@cedarjs/server-store",
47
+ "@simplewebauthn/server",
48
+ "graphql-scalars",
49
+ "minimatch",
50
+ "playwright",
51
+ "react-dom"
52
+ ],
53
+ resolve: {
54
+ // These conditions are used in the plugin pipeline, and only affect non-externalized
55
+ // dependencies during the SSR build. Which because of `noExternal: true` means all
56
+ // dependencies apart from node built-ins.
57
+ // TODO (RSC): What's the difference between `conditions` and
58
+ // `externalConditions`? When is one used over the other?
59
+ conditions: ["react-server"],
60
+ externalConditions: ["react-server"]
61
+ }
62
+ },
63
+ plugins: [
64
+ // The rscTransformUseClientPlugin maps paths like
65
+ // /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
66
+ // to
67
+ // /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
68
+ // That's why it needs the `clientEntryFiles` data
69
+ // (It does other things as well, but that's why it needs clientEntryFiles)
70
+ rscTransformUseClientPlugin(clientEntryFiles),
71
+ rscTransformUseServerPlugin(outDir, serverEntryFiles),
72
+ rscRoutesImports()
73
+ ],
74
+ build: {
75
+ // TODO (RSC): Remove `minify: false` when we don't need to debug as often
76
+ minify: false,
77
+ ssr: true,
78
+ ssrEmitAssets: true,
79
+ outDir,
80
+ emptyOutDir: true,
81
+ // Needed because `outDir` is not inside `root`
82
+ manifest: "server-build-manifest.json",
83
+ rollupOptions: {
84
+ onwarn: onWarn,
85
+ input: {
86
+ ...entryFiles,
87
+ ...clientEntryFiles,
88
+ ...serverEntryFiles,
89
+ ...customModules,
90
+ "entry.server": rwPaths.web.entryServer
91
+ },
92
+ output: {
93
+ banner: (chunk) => {
94
+ let code = "";
95
+ const clientValues = Object.values(clientEntryFiles);
96
+ if (chunk.moduleIds.some((id) => clientValues.includes(id))) {
97
+ code += '"use client";';
98
+ }
99
+ const serverValues = Object.values(serverEntryFiles);
100
+ if (chunk.moduleIds.some((id) => serverValues.includes(id))) {
101
+ code += '"use server";';
102
+ }
103
+ return code;
104
+ },
105
+ entryFileNames: (chunkInfo) => {
106
+ if (entryFilesKeys.includes(chunkInfo.name)) {
107
+ return "assets/[name]-[hash].mjs";
108
+ }
109
+ if (chunkInfo.name === "entry.server" || customModules[chunkInfo.name]) {
110
+ return "[name].mjs";
111
+ }
112
+ return "assets/[name].mjs";
113
+ },
114
+ chunkFileNames: `assets/[name]-[hash].mjs`,
115
+ // This is not ideal. See
116
+ // https://rollupjs.org/faqs/#why-do-additional-imports-turn-up-in-my-entry-chunks-when-code-splitting
117
+ // But we need it to prevent `import 'client-only'` from being
118
+ // hoisted into App.tsx
119
+ // TODO (RSC): Fix when https://github.com/rollup/rollup/issues/5235
120
+ // is resolved
121
+ hoistTransitiveImports: false
122
+ }
123
+ }
124
+ }
125
+ });
126
+ if (!("output" in rscServerBuildOutput)) {
127
+ throw new Error("Unexpected rsc server build output");
128
+ }
129
+ return rscServerBuildOutput.output;
130
+ }
131
+ export {
132
+ rscBuildForServer
133
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * RSC build. Step 3
3
+ * SSR build for when RSC is enabled
4
+ */
5
+ export declare function rscBuildForSsr({ clientEntryFiles, verbose, }: {
6
+ clientEntryFiles: Record<string, string>;
7
+ verbose?: boolean;
8
+ }): Promise<[import("rollup").OutputChunk, ...(import("rollup").OutputChunk | import("rollup").OutputAsset)[]]>;
9
+ //# sourceMappingURL=rscBuildForSsr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscBuildForSsr.d.ts","sourceRoot":"","sources":["../../src/rsc/rscBuildForSsr.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wBAAsB,cAAc,CAAC,EACnC,gBAAgB,EAChB,OAAe,GAChB,EAAE;IACD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,+GA8IA"}
@@ -0,0 +1,138 @@
1
+ import fs from "node:fs";
2
+ import { build as viteBuild } from "vite";
3
+ import { cjsInterop } from "vite-plugin-cjs-interop";
4
+ import { getPaths } from "@cedarjs/project-config";
5
+ import { onWarn } from "../lib/onWarn.js";
6
+ import { rscRoutesAutoLoader } from "../plugins/vite-plugin-rsc-routes-auto-loader.js";
7
+ import { rscSsrRouterImport } from "../plugins/vite-plugin-rsc-ssr-router-import.js";
8
+ async function rscBuildForSsr({
9
+ clientEntryFiles,
10
+ verbose = false
11
+ }) {
12
+ console.log("\n");
13
+ console.log("3. rscBuildForSsr");
14
+ console.log("=================\n");
15
+ const rwPaths = getPaths();
16
+ if (!rwPaths.web.entryClient) {
17
+ throw new Error("No client entry file found inside " + rwPaths.web.src);
18
+ }
19
+ if (!rwPaths.web.entryServer) {
20
+ throw new Error("No server entry file found inside " + rwPaths.web.src);
21
+ }
22
+ const ssrBuildOutput = await viteBuild({
23
+ envFile: false,
24
+ define: {
25
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
26
+ },
27
+ ssr: {
28
+ // Inline every file apart from node built-ins. We want vite/rollup to
29
+ // inline dependencies in the server build. This gets round runtime
30
+ // importing of "server-only" and other packages with poisoned imports.
31
+ //
32
+ // Files included in `noExternal` are files we want Vite to analyze
33
+ // As of vite 5.2 `true` here means "all except node built-ins"
34
+ noExternal: true,
35
+ external: [
36
+ "@prisma/client",
37
+ "@prisma/fetch-engine",
38
+ "@prisma/internals",
39
+ "@cedarjs/auth-dbauth-api",
40
+ "@cedarjs/cookie-jar",
41
+ "@cedarjs/server-store",
42
+ "@simplewebauthn/server",
43
+ "graphql-scalars",
44
+ "minimatch",
45
+ "playwright"
46
+ ]
47
+ },
48
+ plugins: [
49
+ cjsInterop({
50
+ dependencies: [
51
+ // Skip ESM modules: rwjs/auth, rwjs/web, rwjs/auth-*-middleware, rwjs/router
52
+ "@cedarjs/forms",
53
+ "@cedarjs/prerender/*",
54
+ "@cedarjs/auth-*-api",
55
+ "@cedarjs/auth-*-web"
56
+ ]
57
+ }),
58
+ rscRoutesAutoLoader(),
59
+ rscSsrRouterImport()
60
+ ],
61
+ build: {
62
+ // TODO (RSC): Remove `minify: false` when we don't need to debug as often
63
+ minify: false,
64
+ outDir: rwPaths.web.distSsr,
65
+ ssr: true,
66
+ emptyOutDir: true,
67
+ // Needed because `outDir` is not inside `root`
68
+ rollupOptions: {
69
+ onwarn: onWarn,
70
+ input: {
71
+ // @MARK: temporary hack to find the entry client so we can get the
72
+ // index.css bundle but we don't actually want this on an rsc page!
73
+ // TODO (RSC): Look into if we can remove this (and perhaps instead
74
+ // use entry.server)
75
+ __rwjs__client_entry: rwPaths.web.entryClient,
76
+ "entry.server": rwPaths.web.entryServer,
77
+ // we need this, so that the output contains rsc-specific bundles
78
+ // for the client-only components. They get loaded once the page is
79
+ // rendered
80
+ ...clientEntryFiles,
81
+ // These import redirections are so that we don't bundle multiple versions of react
82
+ __rwjs__react: "react",
83
+ __rwjs__location: "@cedarjs/router/location",
84
+ __rwjs__server_auth_provider: "@cedarjs/auth/ServerAuthProvider",
85
+ __rwjs__server_inject: "@cedarjs/web/serverInject",
86
+ "__rwjs__rsdw-client": "react-server-dom-webpack/client.edge",
87
+ // TODO (RSC): add __rwjs__ prefix to the entry below
88
+ "rd-server": "react-dom/server.edge",
89
+ // We need the document for React's fallback
90
+ Document: rwPaths.web.document
91
+ },
92
+ preserveEntrySignatures: "exports-only",
93
+ output: {
94
+ // This is not ideal. See
95
+ // https://rollupjs.org/faqs/#why-do-additional-imports-turn-up-in-my-entry-chunks-when-code-splitting
96
+ // But we need it to prevent `import 'client-only'` from being
97
+ // hoisted into App.tsx
98
+ // TODO (RSC): Fix when https://github.com/rollup/rollup/issues/5235
99
+ // is resolved
100
+ hoistTransitiveImports: false,
101
+ entryFileNames: (chunkInfo) => {
102
+ if (chunkInfo.name === "rd-server" || chunkInfo.name === "__rwjs__react" || chunkInfo.name === "__rwjs__location" || chunkInfo.name === "__rwjs__server_auth_provider" || chunkInfo.name === "__rwjs__server_inject" || chunkInfo.name === "__rwjs__rsdw-client" || chunkInfo.name === "entry.server" || chunkInfo.name === "Document") {
103
+ return "[name].mjs";
104
+ }
105
+ return "assets/[name]-[hash].mjs";
106
+ },
107
+ chunkFileNames: `assets/[name]-[hash].mjs`
108
+ }
109
+ },
110
+ manifest: "client-build-manifest-ssr.json"
111
+ },
112
+ esbuild: {
113
+ logLevel: verbose ? "debug" : "silent",
114
+ logOverride: {
115
+ "unsupported-dynamic-import": "silent"
116
+ }
117
+ },
118
+ logLevel: verbose ? "info" : "silent"
119
+ });
120
+ if (!("output" in ssrBuildOutput)) {
121
+ throw new Error("Unexpected vite ssr build output");
122
+ }
123
+ const entryServerMjs = fs.readFileSync(
124
+ rwPaths.web.distSsrEntryServer,
125
+ "utf-8"
126
+ );
127
+ fs.writeFileSync(
128
+ rwPaths.web.distSsrEntryServer,
129
+ entryServerMjs.replace(
130
+ /import (require\S+) from "graphql-scalars";/,
131
+ 'import * as $1 from "graphql-scalars";'
132
+ )
133
+ );
134
+ return ssrBuildOutput.output;
135
+ }
136
+ export {
137
+ rscBuildForSsr
138
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * RSC build. Step 7.
3
+ * Make RW specific env vars available to server components.
4
+ * For client components this is done as a side-effect of importing from
5
+ * @cedarjs/web (see packages/web/src/config.ts).
6
+ * The import of entries.js that we're adding this to is handled by the
7
+ * RSC worker we've got set up
8
+ */
9
+ export declare function rscBuildRwEnvVars(): Promise<void>;
10
+ //# sourceMappingURL=rscBuildRwEnvVars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscBuildRwEnvVars.d.ts","sourceRoot":"","sources":["../../src/rsc/rscBuildRwEnvVars.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,kBAoCtC"}
@@ -0,0 +1,22 @@
1
+ import fs from "fs/promises";
2
+ import { getPaths } from "@cedarjs/project-config";
3
+ async function rscBuildRwEnvVars() {
4
+ console.log("\n");
5
+ console.log("7. rscBuildRwEnvVars");
6
+ console.log("====================\n");
7
+ const rwPaths = getPaths();
8
+ await fs.appendFile(
9
+ rwPaths.web.distRscEntries,
10
+ `
11
+
12
+ globalThis.RWJS_API_GRAPHQL_URL = RWJS_ENV.RWJS_API_GRAPHQL_URL
13
+ globalThis.RWJS_API_URL = RWJS_ENV.RWJS_API_URL
14
+ globalThis.__REDWOOD__APP_TITLE = RWJS_ENV.__REDWOOD__APP_TITLE
15
+ globalThis.RWJS_EXP_STREAMING_SSR = RWJS_ENV.RWJS_EXP_STREAMING_SSR
16
+ globalThis.RWJS_EXP_RSC = RWJS_ENV.RWJS_EXP_RSC
17
+ `
18
+ );
19
+ }
20
+ export {
21
+ rscBuildRwEnvVars
22
+ };
@@ -0,0 +1,9 @@
1
+ import type { ReadableStream } from 'node:stream/web';
2
+ export type RenderInput = {
3
+ rscId?: string | undefined;
4
+ rsaId?: string | undefined;
5
+ args?: unknown[] | undefined;
6
+ };
7
+ export declare function renderRscToStream(input: RenderInput): Promise<ReadableStream>;
8
+ export declare function setClientEntries(): Promise<void>;
9
+ //# sourceMappingURL=rscRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscRenderer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAWrD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;CAC7B,CAAA;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAE7E;AAyBD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA2BtD"}
@@ -0,0 +1,130 @@
1
+ import path from "node:path";
2
+ import { createElement } from "react";
3
+ import { renderToReadableStream } from "react-server-dom-webpack/server.edge";
4
+ import { getPaths } from "@cedarjs/project-config";
5
+ import { getEntriesFromDist } from "../lib/entries.js";
6
+ import { StatusError } from "../lib/StatusError.js";
7
+ let absoluteClientEntries = {};
8
+ function renderRscToStream(input) {
9
+ return input.rscId ? renderRsc(input) : executeRsa(input);
10
+ }
11
+ async function loadServerFile(filePath) {
12
+ console.log("rscRenderer.ts loadServerFile filePath", filePath);
13
+ return import(`file://${filePath}`);
14
+ }
15
+ const getRoutesComponent = async () => {
16
+ const serverEntries = await getEntriesFromDist();
17
+ console.log("rscRenderer.ts serverEntries", serverEntries);
18
+ const routesPath = path.join(
19
+ getPaths().web.distRsc,
20
+ serverEntries["__rwjs__Routes"]
21
+ );
22
+ if (!routesPath) {
23
+ throw new StatusError("No entry found for __rwjs__Routes", 404);
24
+ }
25
+ const routes = await loadServerFile(routesPath);
26
+ return routes.default;
27
+ };
28
+ async function setClientEntries() {
29
+ const entriesFile = getPaths().web.distRscEntries;
30
+ console.log("setClientEntries :: entriesFile", entriesFile);
31
+ const { clientEntries } = await loadServerFile(entriesFile);
32
+ console.log("setClientEntries :: clientEntries", clientEntries);
33
+ if (!clientEntries) {
34
+ throw new Error("Failed to load clientEntries");
35
+ }
36
+ const baseDir = path.dirname(entriesFile);
37
+ absoluteClientEntries = Object.fromEntries(
38
+ Object.entries(clientEntries).map(([key, val]) => {
39
+ let fullKey = path.join(baseDir, key);
40
+ if (process.platform === "win32") {
41
+ fullKey = fullKey.replaceAll("\\", "/");
42
+ }
43
+ return [fullKey, "/" + val];
44
+ })
45
+ );
46
+ console.log(
47
+ "setClientEntries :: absoluteClientEntries",
48
+ absoluteClientEntries
49
+ );
50
+ }
51
+ function getBundlerConfig() {
52
+ const bundlerConfig = new Proxy(
53
+ {},
54
+ {
55
+ get(_target, encodedId) {
56
+ console.log("Proxy get encodedId", encodedId);
57
+ const [filePath, name] = encodedId.split("#");
58
+ const filePathSlash = filePath.replaceAll("\\", "/");
59
+ const id = absoluteClientEntries[filePathSlash];
60
+ console.log("absoluteClientEntries", absoluteClientEntries);
61
+ console.log("filePath", filePathSlash);
62
+ if (!id) {
63
+ throw new Error("No client entry found for " + filePathSlash);
64
+ }
65
+ console.log("rscRenderer proxy id", id);
66
+ return { id, chunks: [id], name, async: true };
67
+ }
68
+ }
69
+ );
70
+ return bundlerConfig;
71
+ }
72
+ async function renderRsc(input) {
73
+ if (input.rsaId || !input.args) {
74
+ throw new Error(
75
+ "Unexpected input. Can't request both RSCs and execute RSAs at the same time."
76
+ );
77
+ }
78
+ if (!input.rscId) {
79
+ throw new Error("Unexpected input. Missing rscId or props.");
80
+ }
81
+ console.log("renderRsc input", input);
82
+ const serverRoutes = await getRoutesComponent();
83
+ const model = {
84
+ __rwjs__Routes: createElement(serverRoutes)
85
+ };
86
+ console.log("rscRenderer.ts renderRsc model", model);
87
+ return renderToReadableStream(model, getBundlerConfig());
88
+ }
89
+ function isSerializedFormData(data) {
90
+ return !!data && data?.__formData__;
91
+ }
92
+ async function executeRsa(input) {
93
+ console.log("executeRsa input", input);
94
+ if (!input.rsaId || !input.args) {
95
+ throw new Error("Unexpected input");
96
+ }
97
+ const [fileName, actionName] = input.rsaId.split("#");
98
+ console.log("Server Action fileName", fileName, "actionName", actionName);
99
+ const module = await loadServerFile(fileName);
100
+ if (isSerializedFormData(input.args[0])) {
101
+ const formData = new FormData();
102
+ Object.entries(input.args[0].state).forEach(([key, value]) => {
103
+ if (Array.isArray(value)) {
104
+ value.forEach((v) => {
105
+ formData.append(key, v);
106
+ });
107
+ } else {
108
+ formData.append(key, value);
109
+ }
110
+ });
111
+ input.args[0] = formData;
112
+ }
113
+ const method = module[actionName] || module;
114
+ console.log("rscRenderer.ts method", method);
115
+ console.log("rscRenderer.ts args", ...input.args);
116
+ const data = await method(...input.args);
117
+ console.log("rscRenderer.ts rsa return data", data);
118
+ const serverRoutes = await getRoutesComponent();
119
+ console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
120
+ const model = {
121
+ __rwjs__Routes: createElement(serverRoutes),
122
+ __rwjs__rsa_data: data
123
+ };
124
+ console.log("rscRenderer.ts executeRsa model", model);
125
+ return renderToReadableStream(model, getBundlerConfig());
126
+ }
127
+ export {
128
+ renderRscToStream,
129
+ setClientEntries
130
+ };
@@ -0,0 +1,10 @@
1
+ import type { Request as ExpressRequest, Response as ExpressResponse } from 'express';
2
+ import type Router from 'find-my-way';
3
+ import type { ViteDevServer } from 'vite';
4
+ interface CreateRscRequestHandlerOptions {
5
+ getMiddlewareRouter: () => Promise<Router.Instance<any>>;
6
+ viteDevServer?: ViteDevServer;
7
+ }
8
+ export declare function createRscRequestHandler(options: CreateRscRequestHandlerOptions): (req: ExpressRequest, res: ExpressResponse, next: () => void) => Promise<void>;
9
+ export {};
10
+ //# sourceMappingURL=rscRequestHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscRequestHandler.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRequestHandler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAC5B,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAgBzC,UAAU,8BAA8B;IACtC,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACxD,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,SAMhC,cAAc,OACd,eAAe,QACd,MAAM,IAAI,mBAqHnB"}