@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,106 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var vite_plugin_cedar_gqlorm_inject_exports = {};
30
+ __export(vite_plugin_cedar_gqlorm_inject_exports, {
31
+ cedarGqlormInjectPlugin: () => cedarGqlormInjectPlugin
32
+ });
33
+ module.exports = __toCommonJS(vite_plugin_cedar_gqlorm_inject_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
35
+ var import_node_path = __toESM(require("node:path"), 1);
36
+ var import_project_config = require("@cedarjs/project-config");
37
+ function cedarGqlormInjectPlugin() {
38
+ return {
39
+ name: "cedar-gqlorm-inject",
40
+ transform(code, id) {
41
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
42
+ return null;
43
+ }
44
+ if (code.includes("__gqlorm_sdl__")) {
45
+ return null;
46
+ }
47
+ if (!code.includes("createGraphQLHandler")) {
48
+ return null;
49
+ }
50
+ let config;
51
+ try {
52
+ config = (0, import_project_config.getConfig)();
53
+ } catch {
54
+ return null;
55
+ }
56
+ if (!config.experimental?.gqlorm?.enabled) {
57
+ return null;
58
+ }
59
+ let paths;
60
+ try {
61
+ paths = (0, import_project_config.getPaths)();
62
+ } catch {
63
+ return null;
64
+ }
65
+ const backendPathWithoutExt = import_node_path.default.join(
66
+ paths.generated.base,
67
+ "gqlorm",
68
+ "backend"
69
+ );
70
+ if (!import_node_fs.default.existsSync(backendPathWithoutExt + ".ts")) {
71
+ return null;
72
+ }
73
+ const handlerPattern = /^export\s+const\s+(\w+)\s*=\s*createGraphQLHandler\s*\(/m;
74
+ const handlerMatch = handlerPattern.exec(code);
75
+ if (!handlerMatch) {
76
+ return null;
77
+ }
78
+ const handlerLineStart = code.lastIndexOf("\n", handlerMatch.index) + 1;
79
+ const relPath = (0, import_project_config.importStatementPath)(
80
+ import_node_path.default.relative(import_node_path.default.dirname(id), backendPathWithoutExt)
81
+ ) + ".ts";
82
+ const dbSrcPath = import_node_path.default.join(paths.api.src, "lib", "db");
83
+ const relDbPath = (0, import_project_config.importStatementPath)(import_node_path.default.relative(import_node_path.default.dirname(id), dbSrcPath)) + ".ts";
84
+ const importDb = `import { db as __gqlorm_db__ } from '${relDbPath}'`;
85
+ const importSdl = `import * as __gqlorm_sdl__ from '${relPath}'`;
86
+ const importsToAdd = `${importDb}
87
+ ${importSdl}
88
+ `;
89
+ const sdlsMutation = `Object.assign(sdls, {
90
+ __gqlorm__: {
91
+ schema: __gqlorm_sdl__.schema,
92
+ resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
93
+ },
94
+ })
95
+ `;
96
+ const transformed = importsToAdd + code.slice(0, handlerLineStart) + sdlsMutation + code.slice(handlerLineStart);
97
+ return {
98
+ code: transformed
99
+ };
100
+ }
101
+ };
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ cedarGqlormInjectPlugin
106
+ });
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var vite_plugin_cedar_graphql_options_extract_exports = {};
20
+ __export(vite_plugin_cedar_graphql_options_extract_exports, {
21
+ applyGraphqlOptionsExtract: () => applyGraphqlOptionsExtract,
22
+ cedarGraphqlOptionsExtractPlugin: () => cedarGraphqlOptionsExtractPlugin
23
+ });
24
+ module.exports = __toCommonJS(vite_plugin_cedar_graphql_options_extract_exports);
25
+ var import_oxc_parser = require("oxc-parser");
26
+ function cedarGraphqlOptionsExtractPlugin() {
27
+ return {
28
+ name: "cedar-graphql-options-extract",
29
+ transform(code, id) {
30
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
31
+ return null;
32
+ }
33
+ if (!code.includes("createGraphQLHandler")) {
34
+ return null;
35
+ }
36
+ const transformed = applyGraphqlOptionsExtract(code);
37
+ if (!transformed || transformed === code) {
38
+ return null;
39
+ }
40
+ return {
41
+ code: transformed
42
+ };
43
+ }
44
+ };
45
+ }
46
+ function applyGraphqlOptionsExtract(code) {
47
+ if (code.includes("__cedar_graphqlOptions")) {
48
+ return null;
49
+ }
50
+ const { program } = (0, import_oxc_parser.parseSync)("graphql.ts", code, {
51
+ // lang is only a parse hint; 'ts' also parses JS (the graphql handler can
52
+ // be graphql.js in JS projects), so this is safe for both file types.
53
+ lang: "ts",
54
+ sourceType: "module"
55
+ });
56
+ const importNames = /* @__PURE__ */ new Set();
57
+ for (const node of program.body) {
58
+ if (node.type === "ImportDeclaration") {
59
+ if (node.source.value !== "@cedarjs/graphql-server") {
60
+ continue;
61
+ }
62
+ for (const specifier of node.specifiers) {
63
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
64
+ importNames.add(specifier.local.name);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ if (importNames.size === 0) {
70
+ return null;
71
+ }
72
+ const callExpressionPaths = [];
73
+ new import_oxc_parser.Visitor({
74
+ CallExpression(node) {
75
+ if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
76
+ callExpressionPaths.push(node);
77
+ }
78
+ }
79
+ }).visit(program);
80
+ if (callExpressionPaths.length > 1) {
81
+ return null;
82
+ }
83
+ const callExpression = callExpressionPaths[0];
84
+ if (!callExpression) {
85
+ return null;
86
+ }
87
+ const options = callExpression.arguments[0];
88
+ if (!options) {
89
+ return null;
90
+ }
91
+ if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
92
+ return null;
93
+ }
94
+ const optionsStart = options.start;
95
+ const optionsEnd = options.end;
96
+ const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
97
+ const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
98
+ const indent = indentMatch ? indentMatch[0] : "";
99
+ const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
100
+ optionsStart,
101
+ optionsEnd
102
+ )}
103
+ `;
104
+ const before = code.slice(0, lineStart);
105
+ const between = code.slice(lineStart, optionsStart);
106
+ const after = code.slice(optionsEnd);
107
+ return before + optionsConst + between + "__cedar_graphqlOptions" + after;
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ applyGraphqlOptionsExtract,
112
+ cedarGraphqlOptionsExtractPlugin
113
+ });
@@ -329,7 +329,7 @@ async function generateFunctionModule(distPath) {
329
329
  const ctx = await buildCedarContext(request);
330
330
  // Wrap the handler in an AsyncLocalStorage run so the global
331
331
  // @cedarjs/context is available inside it (and isolated per request).
332
- // Mirrors the GraphQL module above and the cedarContextWrappingPlugin
332
+ // Mirrors the GraphQL module above and the handlerAlsWrappingPlugin
333
333
  // used for non-UD builds.
334
334
  const { getAsyncStoreInstance } = await import(
335
335
  '@cedarjs/context/dist/store'
@@ -26,20 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var vite_plugin_cedar_context_wrapping_exports = {};
30
- __export(vite_plugin_cedar_context_wrapping_exports, {
31
- applyContextWrapping: () => applyContextWrapping,
32
- cedarContextWrappingPlugin: () => cedarContextWrappingPlugin
29
+ var vite_plugin_handler_als_wrapping_exports = {};
30
+ __export(vite_plugin_handler_als_wrapping_exports, {
31
+ applyHandlerAlsWrapping: () => applyHandlerAlsWrapping,
32
+ handlerAlsWrappingPlugin: () => handlerAlsWrappingPlugin
33
33
  });
34
- module.exports = __toCommonJS(vite_plugin_cedar_context_wrapping_exports);
34
+ module.exports = __toCommonJS(vite_plugin_handler_als_wrapping_exports);
35
35
  var import_node_path = __toESM(require("node:path"), 1);
36
36
  var import_vite = require("vite");
37
37
  var import_project_config = require("@cedarjs/project-config");
38
- function cedarContextWrappingPlugin({
38
+ function handlerAlsWrappingPlugin({
39
39
  projectIsEsm = false
40
40
  } = {}) {
41
41
  return {
42
- name: "cedar-context-wrapping",
42
+ name: "handler-als-wrapping",
43
43
  transform(code, id) {
44
44
  let paths;
45
45
  try {
@@ -51,12 +51,12 @@ function cedarContextWrappingPlugin({
51
51
  if (!(0, import_vite.normalizePath)(id).startsWith(functionsDir + "/")) {
52
52
  return null;
53
53
  }
54
- const wrapped = applyContextWrapping(code, { projectIsEsm });
54
+ const wrapped = applyHandlerAlsWrapping(code, { projectIsEsm });
55
55
  return wrapped ? { code: wrapped, map: null } : null;
56
56
  }
57
57
  };
58
58
  }
59
- function applyContextWrapping(code, { projectIsEsm = false } = {}) {
59
+ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
60
60
  const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
61
61
  const handlerMatch = handlerRe.exec(code);
62
62
  if (!handlerMatch) {
@@ -90,6 +90,6 @@ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) =>
90
90
  }
91
91
  // Annotate the CommonJS export names for ESM import in node:
92
92
  0 && (module.exports = {
93
- applyContextWrapping,
94
- cedarContextWrappingPlugin
93
+ applyHandlerAlsWrapping,
94
+ handlerAlsWrappingPlugin
95
95
  });
@@ -44,8 +44,8 @@ function rscSsrRouterImport() {
44
44
  const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
45
45
  return {
46
46
  name: "rsc-ssr-router-import",
47
- transform: async function(code, id) {
48
- if (id !== routesFileId) {
47
+ transform: async function(code, id, options) {
48
+ if (!options?.ssr || id !== routesFileId) {
49
49
  return null;
50
50
  }
51
51
  const ext = import_node_path.default.extname(id);
@@ -41,6 +41,10 @@ function rscTransformUseServerPlugin(outDir, serverEntryFiles) {
41
41
  if (!code.includes("use server")) {
42
42
  return code;
43
43
  }
44
+ if (id.includes("node_modules/.vite") || id.includes("/react-server-dom-webpack/") || id.includes("/react-server-dom-webpack.server")) {
45
+ console.log("vite-plugin-rsc-transform-server.ts: Skipping", id);
46
+ return code;
47
+ }
44
48
  let mod;
45
49
  const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
46
50
  try {
@@ -33,20 +33,28 @@ __export(rscRenderer_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(rscRenderer_exports);
35
35
  var import_node_path = __toESM(require("node:path"), 1);
36
- var import_react = require("react");
37
- var import_server = require("react-server-dom-webpack/server.edge");
38
36
  var import_project_config = require("@cedarjs/project-config");
39
37
  var import_entries = require("../lib/entries.js");
40
38
  var import_StatusError = require("../lib/StatusError.js");
39
+ var import_utils = require("./utils.js");
41
40
  let absoluteClientEntries = {};
42
- function renderRscToStream(input) {
41
+ async function renderRscToStream(input) {
43
42
  return input.rscId ? renderRsc(input) : executeRsa(input);
44
43
  }
45
44
  async function loadServerFile(filePath) {
46
45
  console.log("rscRenderer.ts loadServerFile filePath", filePath);
46
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
47
+ const serverMod = await globalThis.__cedarjs__vite_rsc_runtime.import(filePath);
48
+ return serverMod.default ? serverMod.default : serverMod;
49
+ }
47
50
  return import(`file://${filePath}`);
48
51
  }
49
52
  const getRoutesComponent = async () => {
53
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
54
+ const routesPath2 = (0, import_project_config.getPaths)().web.routes;
55
+ const routesMod = await globalThis.__cedarjs__vite_rsc_runtime.import(routesPath2);
56
+ return routesMod.default;
57
+ }
50
58
  const serverEntries = await (0, import_entries.getEntriesFromDist)();
51
59
  console.log("rscRenderer.ts serverEntries", serverEntries);
52
60
  const routesPath = import_node_path.default.join(
@@ -87,10 +95,12 @@ function getBundlerConfig() {
87
95
  {},
88
96
  {
89
97
  get(_target, encodedId) {
90
- console.log("Proxy get encodedId", encodedId);
98
+ console.log("rscRenderer.ts Proxy get encodedId", encodedId);
91
99
  const [filePath, name] = encodedId.split("#");
100
+ console.log("filePath", filePath);
101
+ console.log("name", name);
92
102
  const filePathSlash = filePath.replaceAll("\\", "/");
93
- const id = absoluteClientEntries[filePathSlash];
103
+ const id = globalThis.__cedarjs__vite_rsc_runtime ? filePath : absoluteClientEntries[filePathSlash];
94
104
  console.log("absoluteClientEntries", absoluteClientEntries);
95
105
  console.log("filePath", filePathSlash);
96
106
  if (!id) {
@@ -113,12 +123,14 @@ async function renderRsc(input) {
113
123
  throw new Error("Unexpected input. Missing rscId or props.");
114
124
  }
115
125
  console.log("renderRsc input", input);
126
+ const { createElement } = await (0, import_utils.importRscReact)();
127
+ const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
116
128
  const serverRoutes = await getRoutesComponent();
117
129
  const model = {
118
- __cedarjs__Routes: (0, import_react.createElement)(serverRoutes)
130
+ __cedarjs__Routes: createElement(serverRoutes)
119
131
  };
120
132
  console.log("rscRenderer.ts renderRsc model", model);
121
- return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
133
+ return renderToReadableStream(model, getBundlerConfig());
122
134
  }
123
135
  function isSerializedFormData(data) {
124
136
  return !!data && data?.__formData__;
@@ -149,14 +161,16 @@ async function executeRsa(input) {
149
161
  console.log("rscRenderer.ts args", ...input.args);
150
162
  const data = await method(...input.args);
151
163
  console.log("rscRenderer.ts rsa return data", data);
164
+ const { createElement } = await (0, import_utils.importRscReact)();
165
+ const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
152
166
  const serverRoutes = await getRoutesComponent();
153
167
  console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
154
168
  const model = {
155
- __cedarjs__Routes: (0, import_react.createElement)(serverRoutes),
169
+ __cedarjs__Routes: createElement(serverRoutes),
156
170
  __cedarjs__rsa_data: data
157
171
  };
158
172
  console.log("rscRenderer.ts executeRsa model", model);
159
- return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
173
+ return renderToReadableStream(model, getBundlerConfig());
160
174
  }
161
175
  // Annotate the CommonJS export names for ESM import in node:
162
176
  0 && (module.exports = {
@@ -38,10 +38,10 @@ var import_busboy = __toESM(require("busboy"), 1);
38
38
  var import_react_server_dom_webpack_server = require("../bundled/react-server-dom-webpack.server.js");
39
39
  var import_StatusError = require("../lib/StatusError.js");
40
40
  var import_invokeMiddleware = require("../middleware/invokeMiddleware.js");
41
- var import_rscRenderer = require("./rscRenderer.js");
42
- var import_rscStudioHandlers = require("./rscStudioHandlers.js");
43
41
  const BASE_PATH = "/rw-rsc/";
44
- function createRscRequestHandler(options) {
42
+ async function createRscRequestHandler(options) {
43
+ const { renderRscToStream } = await import("./rscRenderer.js");
44
+ const { sendRscFlightToStudio } = await import("./rscStudioHandlers.js");
45
45
  return async (req, res, next) => {
46
46
  console.log("BASE_PATH", BASE_PATH);
47
47
  console.log("req.originalUrl", req.originalUrl, "req.url", req.url);
@@ -56,7 +56,7 @@ function createRscRequestHandler(options) {
56
56
  matchedMw?.handler,
57
57
  {
58
58
  params: matchedMw?.params,
59
- viteDevServer: options.viteDevServer
59
+ viteSsrDevServer: options.viteSsrDevServer
60
60
  }
61
61
  );
62
62
  const webRes = mwResponse.toResponse();
@@ -101,9 +101,9 @@ function createRscRequestHandler(options) {
101
101
  res.end(String(err));
102
102
  };
103
103
  try {
104
- const readable = await (0, import_rscRenderer.renderRscToStream)({ rscId, rsaId, args });
104
+ const readable = await renderRscToStream({ rscId, rsaId, args });
105
105
  import_node_stream.Readable.fromWeb(readable).pipe(res);
106
- await (0, import_rscStudioHandlers.sendRscFlightToStudio)({
106
+ await sendRscFlightToStudio({
107
107
  rscId,
108
108
  rsaId,
109
109
  args,
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rscWebSocketServer_exports = {};
30
+ __export(rscWebSocketServer_exports, {
31
+ createWebSocketServer: () => createWebSocketServer
32
+ });
33
+ module.exports = __toCommonJS(rscWebSocketServer_exports);
34
+ var import_ws = __toESM(require("ws"), 1);
35
+ function createWebSocketServer() {
36
+ const wsServer = new import_ws.WebSocketServer({ port: 18998 });
37
+ wsServer.on("connection", (ws) => {
38
+ console.log("A new client connected.");
39
+ ws.on("message", (data) => {
40
+ const message = data.toString();
41
+ console.log("Received message:", message);
42
+ wsServer.clients.forEach((client) => {
43
+ if (client.readyState === import_ws.default.OPEN) {
44
+ client.send(message);
45
+ }
46
+ });
47
+ });
48
+ ws.on("close", () => {
49
+ console.log("A client disconnected.");
50
+ });
51
+ });
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ createWebSocketServer
56
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ importRscReact: () => importRscReact,
32
+ importRsdwServer: () => importRsdwServer
33
+ });
34
+ module.exports = __toCommonJS(utils_exports);
35
+ async function importRscReact() {
36
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
37
+ const reactMod = await globalThis.__cedarjs__vite_rsc_runtime.import("react");
38
+ return reactMod.default;
39
+ }
40
+ return import("react");
41
+ }
42
+ async function importRsdwServer() {
43
+ if (globalThis.__cedarjs__vite_rsc_runtime) {
44
+ const rsdwServerMod = await globalThis.__cedarjs__vite_rsc_runtime.import(
45
+ "react-server-dom-webpack/server.edge"
46
+ );
47
+ return rsdwServerMod.default;
48
+ } else {
49
+ return import("react-server-dom-webpack/server.edge");
50
+ }
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ importRscReact,
55
+ importRsdwServer
56
+ });
@@ -38,13 +38,13 @@ var import_server = require("@whatwg-node/server");
38
38
  var import_dotenv_defaults = require("dotenv-defaults");
39
39
  var import_express = __toESM(require("express"), 1);
40
40
  var import_http_proxy_middleware = require("http-proxy-middleware");
41
- var import_ws = __toESM(require("ws"), 1);
42
41
  var import_project_config = require("@cedarjs/project-config");
43
42
  var import_rscCss = require("@cedarjs/router/rscCss");
44
43
  var import_server_store = require("@cedarjs/server-store");
45
44
  var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.js");
46
45
  var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
47
46
  var import_register = require("./middleware/register.js");
47
+ var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
48
48
  var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
49
49
  var import_utils = require("./utils.js");
50
50
  (0, import_dotenv_defaults.config)({
@@ -60,7 +60,7 @@ async function runFeServer() {
60
60
  (0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
61
61
  if (rscEnabled) {
62
62
  const { setClientEntries } = await import("./rsc/rscRenderer.js");
63
- createWebSocketServer();
63
+ (0, import_rscWebSocketServer.createWebSocketServer)();
64
64
  try {
65
65
  await setClientEntries();
66
66
  } catch (e) {
@@ -119,7 +119,7 @@ async function runFeServer() {
119
119
  const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
120
120
  app.use(
121
121
  "/rw-rsc",
122
- createRscRequestHandler({
122
+ await createRscRequestHandler({
123
123
  getMiddlewareRouter: async () => middlewareRouter
124
124
  })
125
125
  );
@@ -139,25 +139,6 @@ async function runFeServer() {
139
139
  `Started production FE server on http://localhost:${rwConfig.web.port}`
140
140
  );
141
141
  }
142
- function createWebSocketServer() {
143
- const wsServer = new import_ws.WebSocketServer({ port: 18998 });
144
- wsServer.on("connection", (ws) => {
145
- console.log("A new client connected.");
146
- ws.on("message", (data) => {
147
- const message = data.toString();
148
- console.log("runFeServer.ts: Received message:");
149
- console.log(message.slice(0, 120) + "...");
150
- wsServer.clients.forEach((client) => {
151
- if (client.readyState === import_ws.default.OPEN) {
152
- client.send(message);
153
- }
154
- });
155
- });
156
- ws.on("close", () => {
157
- console.log("A client disconnected.");
158
- });
159
- });
160
- }
161
142
  runFeServer();
162
143
  // Annotate the CommonJS export names for ESM import in node:
163
144
  0 && (module.exports = {
@@ -50,10 +50,10 @@ const createReactStreamingHandler = async ({
50
50
  clientEntryPath,
51
51
  getStylesheetLinks,
52
52
  getMiddlewareRouter
53
- }, viteDevServer) => {
53
+ }, viteSsrDevServer) => {
54
54
  const rwPaths = (0, import_project_config.getPaths)();
55
55
  const rwConfig = (0, import_project_config.getConfig)();
56
- const isProd = !viteDevServer;
56
+ const isProd = !viteSsrDevServer;
57
57
  const middlewareRouter = await getMiddlewareRouter();
58
58
  let entryServerImport;
59
59
  let fallbackDocumentImport;
@@ -97,7 +97,7 @@ const createReactStreamingHandler = async ({
97
97
  route: currentRoute,
98
98
  cssPaths: cssLinks,
99
99
  params: matchedMw?.params,
100
- viteDevServer
100
+ viteSsrDevServer
101
101
  }
102
102
  );
103
103
  if (mwResponse.isRedirect() || mwResponse.body) {
@@ -116,8 +116,8 @@ const createReactStreamingHandler = async ({
116
116
  });
117
117
  }
118
118
  if (!isProd) {
119
- entryServerImport = await (0, import_utils.ssrLoadEntryServer)(viteDevServer);
120
- fallbackDocumentImport = await viteDevServer.ssrLoadModule(
119
+ entryServerImport = await (0, import_utils.ssrLoadEntryServer)(viteSsrDevServer);
120
+ fallbackDocumentImport = await viteSsrDevServer.ssrLoadModule(
121
121
  rwPaths.web.document
122
122
  );
123
123
  }
@@ -134,10 +134,12 @@ const createReactStreamingHandler = async ({
134
134
  req,
135
135
  parsedParams
136
136
  },
137
- viteDevServer
137
+ viteSsrDevServer
138
138
  });
139
139
  metaTags = routeHookOutput.meta;
140
- const jsBundles = [viteDevServer ? clientEntryPath : "/" + clientEntryPath];
140
+ const jsBundles = [
141
+ viteSsrDevServer ? clientEntryPath : "/" + clientEntryPath
142
+ ];
141
143
  if (currentRoute.bundle) {
142
144
  jsBundles.push("/" + currentRoute.bundle);
143
145
  }
@@ -157,12 +159,13 @@ const createReactStreamingHandler = async ({
157
159
  {
158
160
  waitForAllReady: isSeoCrawler,
159
161
  onError: (err) => {
160
- if (!isProd && viteDevServer) {
161
- viteDevServer.ssrFixStacktrace(err);
162
+ if (!isProd && viteSsrDevServer) {
163
+ viteSsrDevServer.ssrFixStacktrace(err);
162
164
  }
163
165
  console.error(err);
164
166
  }
165
- }
167
+ },
168
+ viteSsrDevServer
166
169
  );
167
170
  return reactResponse;
168
171
  };