@cedarjs/vite 5.0.0 → 6.0.0-canary.2615

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 (74) hide show
  1. package/dist/apiDevMiddleware.d.ts.map +1 -1
  2. package/dist/apiDevMiddleware.js +8 -1
  3. package/dist/buildApp.d.ts.map +1 -1
  4. package/dist/buildApp.js +6 -2
  5. package/dist/bundled/react-server-dom-webpack.server.js +1224 -28521
  6. package/dist/cjs/apiDevMiddleware.js +8 -1
  7. package/dist/cjs/buildApp.js +6 -2
  8. package/dist/cjs/devFeServer.js +268 -15
  9. package/dist/cjs/index.js +19 -13
  10. package/dist/cjs/lib/registerFwGlobalsAndShims.js +9 -0
  11. package/dist/cjs/plugins/vite-plugin-cedar-data-uri-shim.js +67 -0
  12. package/dist/cjs/plugins/vite-plugin-cedar-gqlorm-inject.js +106 -0
  13. package/dist/cjs/plugins/vite-plugin-cedar-graphql-options-extract.js +113 -0
  14. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
  15. package/dist/cjs/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +11 -11
  16. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  17. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +4 -0
  18. package/dist/cjs/rsc/rscRenderer.js +23 -9
  19. package/dist/cjs/rsc/rscRequestHandler.js +6 -6
  20. package/dist/cjs/rsc/rscWebSocketServer.js +56 -0
  21. package/dist/cjs/rsc/utils.js +56 -0
  22. package/dist/cjs/runFeServer.js +3 -22
  23. package/dist/cjs/streaming/createReactStreamingHandler.js +13 -10
  24. package/dist/cjs/streaming/streamHelpers.js +49 -32
  25. package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
  26. package/dist/devFeServer.js +272 -16
  27. package/dist/index.d.ts +5 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +13 -9
  30. package/dist/lib/registerFwGlobalsAndShims.js +9 -0
  31. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  32. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  33. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  34. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  35. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  36. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  37. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +38 -0
  38. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  39. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +88 -0
  40. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
  41. package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +5 -5
  42. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  43. package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +6 -6
  44. package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
  45. package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  46. package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
  47. package/dist/plugins/vite-plugin-rsc-transform-server.js +4 -0
  48. package/dist/rsc/rscRenderer.d.ts.map +1 -1
  49. package/dist/rsc/rscRenderer.js +19 -5
  50. package/dist/rsc/rscRequestHandler.d.ts +2 -2
  51. package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
  52. package/dist/rsc/rscRequestHandler.js +4 -4
  53. package/dist/rsc/rscWebSocketServer.d.ts +2 -0
  54. package/dist/rsc/rscWebSocketServer.d.ts.map +1 -0
  55. package/dist/rsc/rscWebSocketServer.js +22 -0
  56. package/dist/rsc/utils.d.ts +10 -0
  57. package/dist/rsc/utils.d.ts.map +1 -0
  58. package/dist/rsc/utils.js +21 -0
  59. package/dist/runFeServer.js +2 -21
  60. package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
  61. package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
  62. package/dist/streaming/createReactStreamingHandler.js +13 -10
  63. package/dist/streaming/streamHelpers.d.ts +2 -2
  64. package/dist/streaming/streamHelpers.d.ts.map +1 -1
  65. package/dist/streaming/streamHelpers.js +49 -31
  66. package/dist/streaming/triggerRouteHooks.d.ts +2 -2
  67. package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
  68. package/dist/streaming/triggerRouteHooks.js +3 -3
  69. package/package.json +18 -19
  70. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  71. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  72. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  73. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  74. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
@@ -0,0 +1,43 @@
1
+ import { getConfig } from "@cedarjs/project-config";
2
+ function dataUriToBuffer(uri) {
3
+ const match = uri.match(/^data:(.*?)(;(.*?))?(,(.*))$/);
4
+ if (!match) {
5
+ throw new Error("Invalid data URI");
6
+ }
7
+ const mediaType = match[1] || "text/plain";
8
+ const params = match[3] || "";
9
+ const data = match[5];
10
+ const [type] = mediaType.split(";");
11
+ const typeFull = params ? mediaType + ";" + params : mediaType;
12
+ const lowerParams = params.toLowerCase();
13
+ const isBase64 = lowerParams.includes("base64");
14
+ const charset = lowerParams.startsWith("charset=") ? lowerParams.slice(8) : "";
15
+ const bytes = isBase64 ? Uint8Array.from(atob(data), (c) => c.charCodeAt(0)) : new TextEncoder().encode(decodeURIComponent(data));
16
+ const decoder = new TextDecoder();
17
+ bytes.toString = () => decoder.decode(bytes);
18
+ return Object.assign(bytes, { type, typeFull, charset });
19
+ }
20
+ function cedarDataUriShim() {
21
+ if (getConfig().experimental?.rsc?.enabled) {
22
+ return void 0;
23
+ }
24
+ return {
25
+ name: "cedar-data-uri-shim",
26
+ apply: "serve",
27
+ resolveId(id) {
28
+ if (id === "data-uri-to-buffer") {
29
+ return "\0cedar-data-uri-to-buffer";
30
+ }
31
+ return void 0;
32
+ },
33
+ load(id) {
34
+ if (id === "\0cedar-data-uri-to-buffer") {
35
+ return "export default " + dataUriToBuffer.toString();
36
+ }
37
+ return void 0;
38
+ }
39
+ };
40
+ }
41
+ export {
42
+ cedarDataUriShim
43
+ };
@@ -0,0 +1,29 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that injects the auto-generated gqlorm backend into
4
+ * `api/src/functions/graphql.ts` at build time.
5
+ *
6
+ * When `experimental.gqlorm.enabled = true` and `.cedar/gqlorm/backend.ts`
7
+ * exists, this plugin:
8
+ *
9
+ * 1. Adds imports at the top of graphql.ts:
10
+ * import * as __gqlorm_sdl__ from '../../../.cedar/gqlorm/backend'
11
+ * import { db as __gqlorm_db__ } from 'src/lib/db'
12
+ *
13
+ * 2. Inserts a statement immediately before the `createGraphQLHandler` call:
14
+ * Object.assign(sdls, {
15
+ * __gqlorm__: {
16
+ * schema: __gqlorm_sdl__.schema,
17
+ * resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
18
+ * },
19
+ * })
20
+ *
21
+ * The `sdls` variable is already a `let` binding because
22
+ * `vite-plugin-cedar-import-dir` transforms the glob import
23
+ * `import sdls from 'src/graphql/**\/*.sdl.{js,ts}'` into `let sdls = {}`.
24
+ *
25
+ * This plugin is a no-op when gqlorm is disabled or the backend file does
26
+ * not exist.
27
+ */
28
+ export declare function cedarGqlormInjectPlugin(): Plugin;
29
+ //# sourceMappingURL=vite-plugin-cedar-gqlorm-inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-gqlorm-inject.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-gqlorm-inject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAQlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAgHhD"}
@@ -0,0 +1,76 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import {
4
+ getConfig,
5
+ getPaths,
6
+ importStatementPath
7
+ } from "@cedarjs/project-config";
8
+ function cedarGqlormInjectPlugin() {
9
+ return {
10
+ name: "cedar-gqlorm-inject",
11
+ transform(code, id) {
12
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
13
+ return null;
14
+ }
15
+ if (code.includes("__gqlorm_sdl__")) {
16
+ return null;
17
+ }
18
+ if (!code.includes("createGraphQLHandler")) {
19
+ return null;
20
+ }
21
+ let config;
22
+ try {
23
+ config = getConfig();
24
+ } catch {
25
+ return null;
26
+ }
27
+ if (!config.experimental?.gqlorm?.enabled) {
28
+ return null;
29
+ }
30
+ let paths;
31
+ try {
32
+ paths = getPaths();
33
+ } catch {
34
+ return null;
35
+ }
36
+ const backendPathWithoutExt = path.join(
37
+ paths.generated.base,
38
+ "gqlorm",
39
+ "backend"
40
+ );
41
+ if (!fs.existsSync(backendPathWithoutExt + ".ts")) {
42
+ return null;
43
+ }
44
+ const handlerPattern = /^export\s+const\s+(\w+)\s*=\s*createGraphQLHandler\s*\(/m;
45
+ const handlerMatch = handlerPattern.exec(code);
46
+ if (!handlerMatch) {
47
+ return null;
48
+ }
49
+ const handlerLineStart = code.lastIndexOf("\n", handlerMatch.index) + 1;
50
+ const relPath = importStatementPath(
51
+ path.relative(path.dirname(id), backendPathWithoutExt)
52
+ ) + ".ts";
53
+ const dbSrcPath = path.join(paths.api.src, "lib", "db");
54
+ const relDbPath = importStatementPath(path.relative(path.dirname(id), dbSrcPath)) + ".ts";
55
+ const importDb = `import { db as __gqlorm_db__ } from '${relDbPath}'`;
56
+ const importSdl = `import * as __gqlorm_sdl__ from '${relPath}'`;
57
+ const importsToAdd = `${importDb}
58
+ ${importSdl}
59
+ `;
60
+ const sdlsMutation = `Object.assign(sdls, {
61
+ __gqlorm__: {
62
+ schema: __gqlorm_sdl__.schema,
63
+ resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
64
+ },
65
+ })
66
+ `;
67
+ const transformed = importsToAdd + code.slice(0, handlerLineStart) + sdlsMutation + code.slice(handlerLineStart);
68
+ return {
69
+ code: transformed
70
+ };
71
+ }
72
+ };
73
+ }
74
+ export {
75
+ cedarGqlormInjectPlugin
76
+ };
@@ -0,0 +1,38 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that extracts options passed to createGraphQLHandler into an
4
+ * exported variable.
5
+ *
6
+ * Transforms:
7
+ * export const handler = createGraphQLHandler({ options })
8
+ * into:
9
+ * export const __cedar_graphqlOptions = { options }
10
+ * export const handler = createGraphQLHandler(__cedar_graphqlOptions)
11
+ *
12
+ * This allows options to be imported elsewhere and enables the gqlorm-inject
13
+ * plugin to mutate the sdls object in-place before the call.
14
+ *
15
+ * The extraction uses an oxc-parser AST walk (see `applyGraphqlOptionsExtract`
16
+ * below) so the transform is robust against aliased imports, nested calls, and
17
+ * string escapes. The same logic is duplicated in
18
+ * `@cedarjs/internal` (`applyGraphqlOptionsExtract`) for the standalone esbuild
19
+ * API build
20
+ */
21
+ export declare function cedarGraphqlOptionsExtractPlugin(): Plugin;
22
+ /**
23
+ * Extracts the options argument from createGraphQLHandler calls and stores
24
+ * them in an exported variable. Returns the transformed code, or null if no
25
+ * transformation was needed.
26
+ *
27
+ * Transforms:
28
+ * export const handler = createGraphQLHandler({ options })
29
+ * into:
30
+ * export const __cedar_graphqlOptions = { options }
31
+ * export const handler = createGraphQLHandler(__cedar_graphqlOptions)
32
+ *
33
+ * Duplicate of `@cedarjs/internal`'s `applyGraphqlOptionsExtract` so this
34
+ * logic can run inside the Vite plugin pipeline without depending on internal's
35
+ * build output.
36
+ */
37
+ export declare function applyGraphqlOptionsExtract(code: string): string | null;
38
+ //# sourceMappingURL=vite-plugin-cedar-graphql-options-extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-graphql-options-extract.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-graphql-options-extract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gCAAgC,IAAI,MAAM,CA0BzD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA6FtE"}
@@ -0,0 +1,88 @@
1
+ import { parseSync, Visitor } from "oxc-parser";
2
+ function cedarGraphqlOptionsExtractPlugin() {
3
+ return {
4
+ name: "cedar-graphql-options-extract",
5
+ transform(code, id) {
6
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
7
+ return null;
8
+ }
9
+ if (!code.includes("createGraphQLHandler")) {
10
+ return null;
11
+ }
12
+ const transformed = applyGraphqlOptionsExtract(code);
13
+ if (!transformed || transformed === code) {
14
+ return null;
15
+ }
16
+ return {
17
+ code: transformed
18
+ };
19
+ }
20
+ };
21
+ }
22
+ function applyGraphqlOptionsExtract(code) {
23
+ if (code.includes("__cedar_graphqlOptions")) {
24
+ return null;
25
+ }
26
+ const { program } = parseSync("graphql.ts", code, {
27
+ // lang is only a parse hint; 'ts' also parses JS (the graphql handler can
28
+ // be graphql.js in JS projects), so this is safe for both file types.
29
+ lang: "ts",
30
+ sourceType: "module"
31
+ });
32
+ const importNames = /* @__PURE__ */ new Set();
33
+ for (const node of program.body) {
34
+ if (node.type === "ImportDeclaration") {
35
+ if (node.source.value !== "@cedarjs/graphql-server") {
36
+ continue;
37
+ }
38
+ for (const specifier of node.specifiers) {
39
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
40
+ importNames.add(specifier.local.name);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ if (importNames.size === 0) {
46
+ return null;
47
+ }
48
+ const callExpressionPaths = [];
49
+ new Visitor({
50
+ CallExpression(node) {
51
+ if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
52
+ callExpressionPaths.push(node);
53
+ }
54
+ }
55
+ }).visit(program);
56
+ if (callExpressionPaths.length > 1) {
57
+ return null;
58
+ }
59
+ const callExpression = callExpressionPaths[0];
60
+ if (!callExpression) {
61
+ return null;
62
+ }
63
+ const options = callExpression.arguments[0];
64
+ if (!options) {
65
+ return null;
66
+ }
67
+ if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
68
+ return null;
69
+ }
70
+ const optionsStart = options.start;
71
+ const optionsEnd = options.end;
72
+ const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
73
+ const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
74
+ const indent = indentMatch ? indentMatch[0] : "";
75
+ const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
76
+ optionsStart,
77
+ optionsEnd
78
+ )}
79
+ `;
80
+ const before = code.slice(0, lineStart);
81
+ const between = code.slice(lineStart, optionsStart);
82
+ const after = code.slice(optionsEnd);
83
+ return before + optionsConst + between + "__cedar_graphqlOptions" + after;
84
+ }
85
+ export {
86
+ applyGraphqlOptionsExtract,
87
+ cedarGraphqlOptionsExtractPlugin
88
+ };
@@ -296,7 +296,7 @@ async function generateFunctionModule(distPath) {
296
296
  const ctx = await buildCedarContext(request);
297
297
  // Wrap the handler in an AsyncLocalStorage run so the global
298
298
  // @cedarjs/context is available inside it (and isolated per request).
299
- // Mirrors the GraphQL module above and the cedarContextWrappingPlugin
299
+ // Mirrors the GraphQL module above and the handlerAlsWrappingPlugin
300
300
  // used for non-UD builds.
301
301
  const { getAsyncStoreInstance } = await import(
302
302
  '@cedarjs/context/dist/store'
@@ -22,10 +22,10 @@ import type { Plugin } from 'vite';
22
22
  * return __rw_handler(__rw_event, __rw__context)
23
23
  * }
24
24
  *
25
- * This replaces `babel-plugin-redwood-context-wrapping` for Vite builds.
25
+ * This replaces `babel-plugin-handler-als-wrapping` for Vite builds.
26
26
  * The babel plugin is still used for Jest and prerender.
27
27
  */
28
- export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
28
+ export declare function handlerAlsWrappingPlugin({ projectIsEsm, }?: {
29
29
  projectIsEsm?: boolean;
30
30
  }): Plugin;
31
31
  /**
@@ -34,11 +34,11 @@ export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
34
34
  * export a `handler`.
35
35
  *
36
36
  * This is the context-isolation safeguard that used to be performed by
37
- * `babel-plugin-redwood-context-wrapping`. It is exported as a standalone
37
+ * `babel-plugin-handler-als-wrapping`. It is exported as a standalone
38
38
  * function so it can be applied from build pipelines that don't go through
39
39
  * Vite's plugin pipeline (e.g. the legacy esbuild API build).
40
40
  */
41
- export declare function applyContextWrapping(code: string, { projectIsEsm }?: {
41
+ export declare function applyHandlerAlsWrapping(code: string, { projectIsEsm }?: {
42
42
  projectIsEsm?: boolean;
43
43
  }): string | null;
44
- //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
44
+ //# sourceMappingURL=vite-plugin-handler-als-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CAuBd;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CAsDf"}
@@ -1,11 +1,11 @@
1
1
  import path from "node:path";
2
2
  import { normalizePath } from "vite";
3
3
  import { getPaths } from "@cedarjs/project-config";
4
- function cedarContextWrappingPlugin({
4
+ function handlerAlsWrappingPlugin({
5
5
  projectIsEsm = false
6
6
  } = {}) {
7
7
  return {
8
- name: "cedar-context-wrapping",
8
+ name: "handler-als-wrapping",
9
9
  transform(code, id) {
10
10
  let paths;
11
11
  try {
@@ -17,12 +17,12 @@ function cedarContextWrappingPlugin({
17
17
  if (!normalizePath(id).startsWith(functionsDir + "/")) {
18
18
  return null;
19
19
  }
20
- const wrapped = applyContextWrapping(code, { projectIsEsm });
20
+ const wrapped = applyHandlerAlsWrapping(code, { projectIsEsm });
21
21
  return wrapped ? { code: wrapped, map: null } : null;
22
22
  }
23
23
  };
24
24
  }
25
- function applyContextWrapping(code, { projectIsEsm = false } = {}) {
25
+ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
26
26
  const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
27
27
  const handlerMatch = handlerRe.exec(code);
28
28
  if (!handlerMatch) {
@@ -55,6 +55,6 @@ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) =>
55
55
  return before + importStatement + renamed + wrappedHandler;
56
56
  }
57
57
  export {
58
- applyContextWrapping,
59
- cedarContextWrappingPlugin
58
+ applyHandlerAlsWrapping,
59
+ handlerAlsWrappingPlugin
60
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-rsc-ssr-router-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-ssr-router-import.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAqC3C"}
1
+ {"version":3,"file":"vite-plugin-rsc-ssr-router-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-ssr-router-import.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAsC3C"}
@@ -11,8 +11,8 @@ function rscSsrRouterImport() {
11
11
  const routesFileId = normalizePath(getPaths().web.routes);
12
12
  return {
13
13
  name: "rsc-ssr-router-import",
14
- transform: async function(code, id) {
15
- if (id !== routesFileId) {
14
+ transform: async function(code, id, options) {
15
+ if (!options?.ssr || id !== routesFileId) {
16
16
  return null;
17
17
  }
18
18
  const ext = path.extname(id);
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-rsc-transform-server.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-transform-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,MAAM,CA8GR"}
1
+ {"version":3,"file":"vite-plugin-rsc-transform-server.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-transform-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,MAAM,CAuHR"}
@@ -8,6 +8,10 @@ function rscTransformUseServerPlugin(outDir, serverEntryFiles) {
8
8
  if (!code.includes("use server")) {
9
9
  return code;
10
10
  }
11
+ if (id.includes("node_modules/.vite") || id.includes("/react-server-dom-webpack/") || id.includes("/react-server-dom-webpack.server")) {
12
+ console.log("vite-plugin-rsc-transform-server.ts: Skipping", id);
13
+ return code;
14
+ }
11
15
  let mod;
12
16
  const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
13
17
  try {
@@ -1 +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"}
1
+ {"version":3,"file":"rscRenderer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AASrD,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,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,cAAc,CAAC,CAEzB;AAyCD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA2BtD"}
@@ -1,18 +1,26 @@
1
1
  import path from "node:path";
2
- import { createElement } from "react";
3
- import { renderToReadableStream } from "react-server-dom-webpack/server.edge";
4
2
  import { getPaths } from "@cedarjs/project-config";
5
3
  import { getEntriesFromDist } from "../lib/entries.js";
6
4
  import { StatusError } from "../lib/StatusError.js";
5
+ import { importRscReact, importRsdwServer } from "./utils.js";
7
6
  let absoluteClientEntries = {};
8
- function renderRscToStream(input) {
7
+ async function renderRscToStream(input) {
9
8
  return input.rscId ? renderRsc(input) : executeRsa(input);
10
9
  }
11
10
  async function loadServerFile(filePath) {
12
11
  console.log("rscRenderer.ts loadServerFile filePath", filePath);
12
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
13
+ const serverMod = await globalThis.__cedarjs__vite_rsc_runtime.import(filePath);
14
+ return serverMod.default ? serverMod.default : serverMod;
15
+ }
13
16
  return import(`file://${filePath}`);
14
17
  }
15
18
  const getRoutesComponent = async () => {
19
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
20
+ const routesPath2 = getPaths().web.routes;
21
+ const routesMod = await globalThis.__cedarjs__vite_rsc_runtime.import(routesPath2);
22
+ return routesMod.default;
23
+ }
16
24
  const serverEntries = await getEntriesFromDist();
17
25
  console.log("rscRenderer.ts serverEntries", serverEntries);
18
26
  const routesPath = path.join(
@@ -53,10 +61,12 @@ function getBundlerConfig() {
53
61
  {},
54
62
  {
55
63
  get(_target, encodedId) {
56
- console.log("Proxy get encodedId", encodedId);
64
+ console.log("rscRenderer.ts Proxy get encodedId", encodedId);
57
65
  const [filePath, name] = encodedId.split("#");
66
+ console.log("filePath", filePath);
67
+ console.log("name", name);
58
68
  const filePathSlash = filePath.replaceAll("\\", "/");
59
- const id = absoluteClientEntries[filePathSlash];
69
+ const id = globalThis.__cedarjs__vite_rsc_runtime ? filePath : absoluteClientEntries[filePathSlash];
60
70
  console.log("absoluteClientEntries", absoluteClientEntries);
61
71
  console.log("filePath", filePathSlash);
62
72
  if (!id) {
@@ -79,6 +89,8 @@ async function renderRsc(input) {
79
89
  throw new Error("Unexpected input. Missing rscId or props.");
80
90
  }
81
91
  console.log("renderRsc input", input);
92
+ const { createElement } = await importRscReact();
93
+ const { renderToReadableStream } = await importRsdwServer();
82
94
  const serverRoutes = await getRoutesComponent();
83
95
  const model = {
84
96
  __cedarjs__Routes: createElement(serverRoutes)
@@ -115,6 +127,8 @@ async function executeRsa(input) {
115
127
  console.log("rscRenderer.ts args", ...input.args);
116
128
  const data = await method(...input.args);
117
129
  console.log("rscRenderer.ts rsa return data", data);
130
+ const { createElement } = await importRscReact();
131
+ const { renderToReadableStream } = await importRsdwServer();
118
132
  const serverRoutes = await getRoutesComponent();
119
133
  console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
120
134
  const model = {
@@ -3,8 +3,8 @@ import type Router from 'find-my-way';
3
3
  import type { ViteDevServer } from 'vite';
4
4
  interface CreateRscRequestHandlerOptions {
5
5
  getMiddlewareRouter: () => Promise<Router.Instance<any>>;
6
- viteDevServer?: ViteDevServer;
6
+ viteSsrDevServer?: ViteDevServer;
7
7
  }
8
- export declare function createRscRequestHandler(options: CreateRscRequestHandlerOptions): (req: ExpressRequest, res: ExpressResponse, next: () => void) => Promise<void>;
8
+ export declare function createRscRequestHandler(options: CreateRscRequestHandlerOptions): Promise<(req: ExpressRequest, res: ExpressResponse, next: () => void) => Promise<void>>;
9
9
  export {};
10
10
  //# sourceMappingURL=rscRequestHandler.d.ts.map
@@ -1 +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,IAMrC,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,MAAM,MAAM,IAAI,mBAqHnB"}
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;AAazC,UAAU,8BAA8B;IACtC,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACxD,gBAAgB,CAAC,EAAE,aAAa,CAAA;CACjC;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,iBAShC,cAAc,OACd,eAAe,QACd,MAAM,IAAI,oBAqHnB"}
@@ -8,10 +8,10 @@ import {
8
8
  } from "../bundled/react-server-dom-webpack.server.js";
9
9
  import { hasStatusCode } from "../lib/StatusError.js";
10
10
  import { invoke } from "../middleware/invokeMiddleware.js";
11
- import { renderRscToStream } from "./rscRenderer.js";
12
- import { sendRscFlightToStudio } from "./rscStudioHandlers.js";
13
11
  const BASE_PATH = "/rw-rsc/";
14
- function createRscRequestHandler(options) {
12
+ async function createRscRequestHandler(options) {
13
+ const { renderRscToStream } = await import("./rscRenderer.js");
14
+ const { sendRscFlightToStudio } = await import("./rscStudioHandlers.js");
15
15
  return async (req, res, next) => {
16
16
  console.log("BASE_PATH", BASE_PATH);
17
17
  console.log("req.originalUrl", req.originalUrl, "req.url", req.url);
@@ -26,7 +26,7 @@ function createRscRequestHandler(options) {
26
26
  matchedMw?.handler,
27
27
  {
28
28
  params: matchedMw?.params,
29
- viteDevServer: options.viteDevServer
29
+ viteSsrDevServer: options.viteSsrDevServer
30
30
  }
31
31
  );
32
32
  const webRes = mwResponse.toResponse();
@@ -0,0 +1,2 @@
1
+ export declare function createWebSocketServer(): void;
2
+ //# sourceMappingURL=rscWebSocketServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rscWebSocketServer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscWebSocketServer.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,SAwBpC"}
@@ -0,0 +1,22 @@
1
+ import WebSocket, { WebSocketServer } from "ws";
2
+ function createWebSocketServer() {
3
+ const wsServer = new WebSocketServer({ port: 18998 });
4
+ wsServer.on("connection", (ws) => {
5
+ console.log("A new client connected.");
6
+ ws.on("message", (data) => {
7
+ const message = data.toString();
8
+ console.log("Received message:", message);
9
+ wsServer.clients.forEach((client) => {
10
+ if (client.readyState === WebSocket.OPEN) {
11
+ client.send(message);
12
+ }
13
+ });
14
+ });
15
+ ws.on("close", () => {
16
+ console.log("A client disconnected.");
17
+ });
18
+ });
19
+ }
20
+ export {
21
+ createWebSocketServer
22
+ };
@@ -0,0 +1,10 @@
1
+ import type { default as RSDWServerModule } from 'react-server-dom-webpack/server.edge';
2
+ type RSDWServerType = typeof RSDWServerModule;
3
+ /**
4
+ * This function ensures we load the version of React that's been imported with
5
+ * the react-server condition.
6
+ */
7
+ export declare function importRscReact(): Promise<any>;
8
+ export declare function importRsdwServer(): Promise<RSDWServerType>;
9
+ export {};
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/rsc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AAEvF,KAAK,cAAc,GAAG,OAAO,gBAAgB,CAAA;AAE7C;;;GAGG;AACH,wBAAsB,cAAc,iBAQnC;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,cAAc,CAAC,CAUhE"}
@@ -0,0 +1,21 @@
1
+ async function importRscReact() {
2
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
3
+ const reactMod = await globalThis.__cedarjs__vite_rsc_runtime.import("react");
4
+ return reactMod.default;
5
+ }
6
+ return import("react");
7
+ }
8
+ async function importRsdwServer() {
9
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
10
+ const rsdwServerMod = await globalThis.__cedarjs__vite_rsc_runtime.import(
11
+ "react-server-dom-webpack/server.edge"
12
+ );
13
+ return rsdwServerMod.default;
14
+ } else {
15
+ return import("react-server-dom-webpack/server.edge");
16
+ }
17
+ }
18
+ export {
19
+ importRscReact,
20
+ importRsdwServer
21
+ };
@@ -5,13 +5,13 @@ import { createServerAdapter } from "@whatwg-node/server";
5
5
  import { config as loadDotEnv } from "dotenv-defaults";
6
6
  import express from "express";
7
7
  import { createProxyMiddleware } from "http-proxy-middleware";
8
- import WebSocket, { WebSocketServer } from "ws";
9
8
  import { getConfig, getPaths } from "@cedarjs/project-config";
10
9
  import { getRscStylesheetLinkGenerator } from "@cedarjs/router/rscCss";
11
10
  import { createPerRequestMap, createServerStorage } from "@cedarjs/server-store";
12
11
  import { registerFwGlobalsAndShims } from "./lib/registerFwGlobalsAndShims.js";
13
12
  import { invoke } from "./middleware/invokeMiddleware.js";
14
13
  import { createMiddlewareRouter } from "./middleware/register.js";
14
+ import { createWebSocketServer } from "./rsc/rscWebSocketServer.js";
15
15
  import { createReactStreamingHandler } from "./streaming/createReactStreamingHandler.js";
16
16
  import { convertExpressHeaders, getFullUrl } from "./utils.js";
17
17
  loadDotEnv({
@@ -86,7 +86,7 @@ async function runFeServer() {
86
86
  const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
87
87
  app.use(
88
88
  "/rw-rsc",
89
- createRscRequestHandler({
89
+ await createRscRequestHandler({
90
90
  getMiddlewareRouter: async () => middlewareRouter
91
91
  })
92
92
  );
@@ -106,25 +106,6 @@ async function runFeServer() {
106
106
  `Started production FE server on http://localhost:${rwConfig.web.port}`
107
107
  );
108
108
  }
109
- function createWebSocketServer() {
110
- const wsServer = new WebSocketServer({ port: 18998 });
111
- wsServer.on("connection", (ws) => {
112
- console.log("A new client connected.");
113
- ws.on("message", (data) => {
114
- const message = data.toString();
115
- console.log("runFeServer.ts: Received message:");
116
- console.log(message.slice(0, 120) + "...");
117
- wsServer.clients.forEach((client) => {
118
- if (client.readyState === WebSocket.OPEN) {
119
- client.send(message);
120
- }
121
- });
122
- });
123
- ws.on("close", () => {
124
- console.log("A client disconnected.");
125
- });
126
- });
127
- }
128
109
  runFeServer();
129
110
  export {
130
111
  runFeServer
@@ -7,6 +7,6 @@ interface CreateReactStreamingHandlerOptions {
7
7
  getStylesheetLinks: (route?: RWRouteManifestItem | RouteSpec) => string[];
8
8
  getMiddlewareRouter: () => Promise<Router.Instance<any>>;
9
9
  }
10
- export declare const createReactStreamingHandler: ({ routes, clientEntryPath, getStylesheetLinks, getMiddlewareRouter, }: CreateReactStreamingHandlerOptions, viteDevServer?: ViteDevServer) => Promise<(req: Request) => Promise<Response>>;
10
+ export declare const createReactStreamingHandler: ({ routes, clientEntryPath, getStylesheetLinks, getMiddlewareRouter, }: CreateReactStreamingHandlerOptions, viteSsrDevServer?: ViteDevServer) => Promise<(req: Request) => Promise<Response>>;
11
11
  export {};
12
12
  //# sourceMappingURL=createReactStreamingHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createReactStreamingHandler.d.ts","sourceRoot":"","sources":["../../src/streaming/createReactStreamingHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAoBvE,UAAU,kCAAkC;IAC1C,MAAM,EAAE,mBAAmB,EAAE,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,SAAS,KAAK,MAAM,EAAE,CAAA;IACzE,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;CACzD;AAOD,eAAO,MAAM,2BAA2B,GACtC,uEAKG,kCAAkC,EACrC,gBAAgB,aAAa,mBAuBV,OAAO,uBA8I3B,CAAA"}
1
+ {"version":3,"file":"createReactStreamingHandler.d.ts","sourceRoot":"","sources":["../../src/streaming/createReactStreamingHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAoBvE,UAAU,kCAAkC;IAC1C,MAAM,EAAE,mBAAmB,EAAE,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,SAAS,KAAK,MAAM,EAAE,CAAA;IACzE,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;CACzD;AAOD,eAAO,MAAM,2BAA2B,GACtC,uEAKG,kCAAkC,EACrC,mBAAmB,aAAa,mBAuBb,OAAO,uBAiJ3B,CAAA"}