@cedarjs/vite 5.0.0-canary.2595 → 5.0.0-rc.261
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.
- package/dist/bundled/react-server-dom-webpack.server.js +28528 -1231
- package/dist/cjs/devFeServer.js +15 -280
- package/dist/cjs/index.js +8 -7
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/cjs/rsc/rscRenderer.js +9 -23
- package/dist/cjs/rsc/rscRequestHandler.js +6 -6
- package/dist/cjs/runFeServer.js +22 -3
- package/dist/cjs/streaming/createReactStreamingHandler.js +10 -13
- package/dist/cjs/streaming/streamHelpers.js +32 -49
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +16 -284
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/rsc/rscRenderer.d.ts.map +1 -1
- package/dist/rsc/rscRenderer.js +5 -19
- package/dist/rsc/rscRequestHandler.d.ts +2 -2
- package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
- package/dist/rsc/rscRequestHandler.js +4 -4
- package/dist/runFeServer.js +21 -2
- package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
- package/dist/streaming/createReactStreamingHandler.js +10 -13
- package/dist/streaming/streamHelpers.d.ts +2 -2
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +31 -49
- package/dist/streaming/triggerRouteHooks.d.ts +2 -2
- package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
- package/dist/streaming/triggerRouteHooks.js +3 -3
- package/package.json +18 -18
- package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
- package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
- package/dist/cjs/rsc/utils.js +0 -56
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +0 -24
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -98
- package/dist/rsc/rscWebSocketServer.d.ts +0 -2
- package/dist/rsc/rscWebSocketServer.d.ts.map +0 -1
- package/dist/rsc/rscWebSocketServer.js +0 -22
- package/dist/rsc/utils.d.ts +0 -10
- package/dist/rsc/utils.d.ts.map +0 -1
- package/dist/rsc/utils.js +0 -21
package/dist/cjs/devFeServer.js
CHANGED
|
@@ -22,7 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
|
-
var import_node_http = __toESM(require("node:http"), 1);
|
|
26
25
|
var import_server = require("@whatwg-node/server");
|
|
27
26
|
var import_express = __toESM(require("express"), 1);
|
|
28
27
|
var import_vite = require("vite");
|
|
@@ -34,22 +33,14 @@ var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.
|
|
|
34
33
|
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
35
34
|
var import_register = require("./middleware/register.js");
|
|
36
35
|
var import_vite_plugin_rsc_routes_auto_loader = require("./plugins/vite-plugin-rsc-routes-auto-loader.js");
|
|
37
|
-
var import_vite_plugin_rsc_routes_imports = require("./plugins/vite-plugin-rsc-routes-imports.js");
|
|
38
|
-
var import_vite_plugin_rsc_ssr_router_import = require("./plugins/vite-plugin-rsc-ssr-router-import.js");
|
|
39
|
-
var import_vite_plugin_rsc_transform_server = require("./plugins/vite-plugin-rsc-transform-server.js");
|
|
40
|
-
var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
|
|
41
36
|
var import_collectCss = require("./streaming/collectCss.js");
|
|
42
37
|
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
43
38
|
var import_utils = require("./utils.js");
|
|
44
|
-
const import_meta = {};
|
|
45
39
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
46
|
-
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
47
|
-
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
48
40
|
async function createServer() {
|
|
49
41
|
(0, import_utils.ensureProcessDirWeb)();
|
|
50
42
|
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
51
43
|
const app = (0, import_express.default)();
|
|
52
|
-
const server = import_node_http.default.createServer(app);
|
|
53
44
|
const rwPaths = (0, import_project_config.getPaths)();
|
|
54
45
|
const rscEnabled = (0, import_project_config.getConfig)().experimental.rsc?.enabled ?? false;
|
|
55
46
|
const serverStorage = (0, import_server_store.createServerStorage)();
|
|
@@ -72,78 +63,8 @@ async function createServer() {
|
|
|
72
63
|
"Vite config not found. Please set up Vite before running the dev server."
|
|
73
64
|
);
|
|
74
65
|
}
|
|
75
|
-
const
|
|
66
|
+
const vite = await (0, import_vite.createServer)({
|
|
76
67
|
configFile: rwPaths.web.viteConfig,
|
|
77
|
-
envFile: false,
|
|
78
|
-
define: {
|
|
79
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
80
|
-
},
|
|
81
|
-
ssr: {
|
|
82
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
83
|
-
// inline dependencies in the server build. This gets round runtime
|
|
84
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
85
|
-
//
|
|
86
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
87
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
88
|
-
// noExternal: true,
|
|
89
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
90
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
91
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
92
|
-
// we wanted to go that route.
|
|
93
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
94
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
95
|
-
// (css pre-init failure)
|
|
96
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
97
|
-
external: [
|
|
98
|
-
"@prisma/client",
|
|
99
|
-
"@prisma/adapter-better-sqlite3",
|
|
100
|
-
"@prisma/fetch-engine",
|
|
101
|
-
"@prisma/internals",
|
|
102
|
-
"better-sqlite3",
|
|
103
|
-
"@cedarjs/auth-dbauth-api",
|
|
104
|
-
"@cedarjs/cookie-jar",
|
|
105
|
-
"@cedarjs/server-store",
|
|
106
|
-
"@simplewebauthn/server",
|
|
107
|
-
"graphql-scalars",
|
|
108
|
-
"minimatch",
|
|
109
|
-
"playwright",
|
|
110
|
-
"react-dom"
|
|
111
|
-
],
|
|
112
|
-
resolve: {
|
|
113
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
114
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
115
|
-
// dependencies apart from node built-ins.
|
|
116
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
117
|
-
// `externalConditions`? When is one used over the other?
|
|
118
|
-
// conditions: ['react-server'],
|
|
119
|
-
// externalConditions: ['react-server'],
|
|
120
|
-
},
|
|
121
|
-
optimizeDeps: {
|
|
122
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
123
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
124
|
-
// include: [
|
|
125
|
-
// 'react/**/*',
|
|
126
|
-
// 'react-dom/server',
|
|
127
|
-
// 'react-dom/server.edge',
|
|
128
|
-
// 'rehackt',
|
|
129
|
-
// 'react-server-dom-webpack/server',
|
|
130
|
-
// 'react-server-dom-webpack/client',
|
|
131
|
-
// '@apollo/client/cache/*',
|
|
132
|
-
// '@apollo/client/utilities/*',
|
|
133
|
-
// '@apollo/client/react/hooks/*',
|
|
134
|
-
// 'react-fast-compare',
|
|
135
|
-
// 'invariant',
|
|
136
|
-
// 'shallowequal',
|
|
137
|
-
// 'graphql/language/*',
|
|
138
|
-
// 'stacktracey',
|
|
139
|
-
// 'deepmerge',
|
|
140
|
-
// 'fast-glob',
|
|
141
|
-
// ],
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
resolve: {
|
|
145
|
-
// conditions: ['react-server'],
|
|
146
|
-
},
|
|
147
68
|
plugins: [
|
|
148
69
|
(0, import_vite_plugin_cjs_interop.cjsInterop)({
|
|
149
70
|
dependencies: [
|
|
@@ -157,195 +78,16 @@ async function createServer() {
|
|
|
157
78
|
"@cedarjs/auth-!(dbauth)-web"
|
|
158
79
|
]
|
|
159
80
|
}),
|
|
160
|
-
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
|
|
161
|
-
rscEnabled && (0, import_vite_plugin_rsc_ssr_router_import.rscSsrRouterImport)()
|
|
81
|
+
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
|
|
162
82
|
],
|
|
163
83
|
server: { middlewareMode: true },
|
|
164
84
|
logLevel: "info",
|
|
165
85
|
clearScreen: false,
|
|
166
86
|
appType: "custom"
|
|
167
87
|
});
|
|
168
|
-
globalThis.__cedarjs__vite_ssr_runtime = (0, import_vite.createServerModuleRunner)(
|
|
169
|
-
viteSsrDevServer.environments.ssr
|
|
170
|
-
);
|
|
171
|
-
globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
|
|
172
|
-
globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
|
|
173
|
-
const viteRscServer = await (0, import_vite.createServer)({
|
|
174
|
-
envFile: false,
|
|
175
|
-
define: {
|
|
176
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
177
|
-
},
|
|
178
|
-
ssr: {
|
|
179
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
180
|
-
// inline dependencies in the server build. This gets round runtime
|
|
181
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
182
|
-
//
|
|
183
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
184
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
185
|
-
noExternal: true,
|
|
186
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
187
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
188
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
189
|
-
// we wanted to go that route.
|
|
190
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
191
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
192
|
-
// (css pre-init failure)
|
|
193
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
194
|
-
external: [
|
|
195
|
-
"@prisma/client",
|
|
196
|
-
"@prisma/adapter-better-sqlite3",
|
|
197
|
-
"@prisma/fetch-engine",
|
|
198
|
-
"@prisma/internals",
|
|
199
|
-
"better-sqlite3",
|
|
200
|
-
"@cedarjs/auth-dbauth-api",
|
|
201
|
-
"@cedarjs/cookie-jar",
|
|
202
|
-
"@cedarjs/server-store",
|
|
203
|
-
"@cedarjs/structure",
|
|
204
|
-
"@simplewebauthn/server",
|
|
205
|
-
"graphql-scalars",
|
|
206
|
-
"minimatch",
|
|
207
|
-
"playwright",
|
|
208
|
-
"react-dom"
|
|
209
|
-
],
|
|
210
|
-
resolve: {
|
|
211
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
212
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
213
|
-
// dependencies apart from node built-ins.
|
|
214
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
215
|
-
// `externalConditions`? When is one used over the other?
|
|
216
|
-
// In Vite 6, we must include `defaultServerConditions` alongside
|
|
217
|
-
// `react-server` so that nested condition maps (e.g. the `node`
|
|
218
|
-
// sub-condition inside `react-server-dom-webpack/server`'s exports)
|
|
219
|
-
// can still be resolved. Without `node` (or another environment
|
|
220
|
-
// condition), the resolver throws "No known conditions for
|
|
221
|
-
// './server' specifier in 'react-server-dom-webpack' package".
|
|
222
|
-
conditions: ["react-server", ...import_vite.defaultServerConditions],
|
|
223
|
-
externalConditions: ["react-server", ...import_vite.defaultServerConditions]
|
|
224
|
-
},
|
|
225
|
-
optimizeDeps: {
|
|
226
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
227
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
228
|
-
include: [
|
|
229
|
-
"react/**/*",
|
|
230
|
-
"react-dom/server",
|
|
231
|
-
"react-dom/server.edge",
|
|
232
|
-
"rehackt",
|
|
233
|
-
"react-server-dom-webpack/server",
|
|
234
|
-
"react-server-dom-webpack/server.edge",
|
|
235
|
-
"react-server-dom-webpack/client",
|
|
236
|
-
"react-server-dom-webpack/client.edge",
|
|
237
|
-
"@apollo/client/cache/*",
|
|
238
|
-
"@apollo/client/utilities/*",
|
|
239
|
-
"@apollo/client/react/hooks/*",
|
|
240
|
-
"react-fast-compare",
|
|
241
|
-
"invariant",
|
|
242
|
-
"shallowequal",
|
|
243
|
-
"graphql/language/*",
|
|
244
|
-
"stacktracey",
|
|
245
|
-
"deepmerge",
|
|
246
|
-
"fast-glob",
|
|
247
|
-
"@whatwg-node/fetch",
|
|
248
|
-
"busboy",
|
|
249
|
-
"cookie"
|
|
250
|
-
],
|
|
251
|
-
// Without excluding `util` we get "TypeError: util.TextEncoder is not
|
|
252
|
-
// a constructor" in react-server-dom-webpack.server because it'll try
|
|
253
|
-
// to use Browserify's `util` instead of Node's. And Browserify's
|
|
254
|
-
// polyfill is missing TextEncoder+TextDecoder. The reason it's using
|
|
255
|
-
// the Browserify polyfill is because we have
|
|
256
|
-
// `vite-plugin-node-polyfills` as a dependency, and that'll add
|
|
257
|
-
// Browserify's `node-util` to `node_modules`, so when Vite goes to
|
|
258
|
-
// resolve `import { TextEncoder } from 'util` it'll find the one in
|
|
259
|
-
// `node_modules` instead of Node's internal version.
|
|
260
|
-
// We only see this in dev, and not in prod. I'm not entirely sure why
|
|
261
|
-
// but I have two guesses: 1. When RSC is enabled we don't actually use
|
|
262
|
-
// `vite-plugin-node-polyfill`, so some kind of tree shaking is
|
|
263
|
-
// happening, which prevents the issue from occurring. 2. In prod we
|
|
264
|
-
// only use Node's dependency resolution. Vite is not involved. And
|
|
265
|
-
// that difference in resolution is what prevents the issue from
|
|
266
|
-
// occurring.
|
|
267
|
-
exclude: ["util"]
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
resolve: {
|
|
271
|
-
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
272
|
-
conditions: ["react-server", ...import_vite.defaultServerConditions]
|
|
273
|
-
},
|
|
274
|
-
plugins: [
|
|
275
|
-
{
|
|
276
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
277
|
-
transform(code, id, _options) {
|
|
278
|
-
globalThis.__cedarjs__client_references?.delete(id);
|
|
279
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
280
|
-
return void 0;
|
|
281
|
-
}
|
|
282
|
-
console.log(
|
|
283
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
284
|
-
id
|
|
285
|
-
);
|
|
286
|
-
globalThis.__cedarjs__client_references?.add(id);
|
|
287
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
288
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
289
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
290
|
-
const result = [
|
|
291
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
292
|
-
"",
|
|
293
|
-
...names.map((name) => {
|
|
294
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
295
|
-
})
|
|
296
|
-
].join("\n");
|
|
297
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
298
|
-
console.log(
|
|
299
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
300
|
-
);
|
|
301
|
-
return { code: result, map: null };
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
(0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
|
|
305
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
306
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
307
|
-
// to
|
|
308
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
309
|
-
// That's why it needs the `clientEntryFiles` data
|
|
310
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
311
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
312
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
313
|
-
(0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
|
|
314
|
-
{
|
|
315
|
-
name: "rsc-hot-update",
|
|
316
|
-
handleHotUpdate(ctx) {
|
|
317
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
318
|
-
return [];
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
],
|
|
322
|
-
build: {
|
|
323
|
-
ssr: true
|
|
324
|
-
},
|
|
325
|
-
server: {
|
|
326
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
327
|
-
// middleware mode
|
|
328
|
-
middlewareMode: true,
|
|
329
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
330
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
331
|
-
// different port.
|
|
332
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
333
|
-
// port
|
|
334
|
-
ws: false
|
|
335
|
-
// hmr: {
|
|
336
|
-
// port: 24679,
|
|
337
|
-
// },
|
|
338
|
-
},
|
|
339
|
-
appType: "custom",
|
|
340
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
341
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
342
|
-
});
|
|
343
|
-
globalThis.__cedarjs__vite_rsc_runtime = (0, import_vite.createServerModuleRunner)(
|
|
344
|
-
viteRscServer.environments.ssr
|
|
345
|
-
);
|
|
346
88
|
const handleWithMiddleware = (route) => {
|
|
347
89
|
return (0, import_server.createServerAdapter)(async (req) => {
|
|
348
|
-
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(
|
|
90
|
+
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(vite);
|
|
349
91
|
const middleware = middlewareRouter.find(
|
|
350
92
|
req.method,
|
|
351
93
|
req.url
|
|
@@ -355,22 +97,19 @@ async function createServer() {
|
|
|
355
97
|
}
|
|
356
98
|
const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
|
|
357
99
|
route,
|
|
358
|
-
|
|
100
|
+
viteDevServer: vite
|
|
359
101
|
});
|
|
360
102
|
return mwRes.toResponse();
|
|
361
103
|
});
|
|
362
104
|
};
|
|
363
|
-
app.use(
|
|
105
|
+
app.use(vite.middlewares);
|
|
364
106
|
if (rscEnabled) {
|
|
365
|
-
(
|
|
366
|
-
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
367
|
-
new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
|
|
368
|
-
);
|
|
107
|
+
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
369
108
|
app.use(
|
|
370
109
|
"/rw-rsc",
|
|
371
|
-
|
|
372
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
373
|
-
|
|
110
|
+
createRscRequestHandler({
|
|
111
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite),
|
|
112
|
+
viteDevServer: vite
|
|
374
113
|
})
|
|
375
114
|
);
|
|
376
115
|
}
|
|
@@ -380,22 +119,18 @@ async function createServer() {
|
|
|
380
119
|
routes,
|
|
381
120
|
clientEntryPath: rwPaths.web.entryClient,
|
|
382
121
|
getStylesheetLinks: (route) => {
|
|
383
|
-
return getCssLinks({
|
|
384
|
-
rwPaths,
|
|
385
|
-
route,
|
|
386
|
-
viteSsrDevServer
|
|
387
|
-
});
|
|
122
|
+
return getCssLinks({ rwPaths, route, vite });
|
|
388
123
|
},
|
|
389
124
|
// Recreate middleware router on each request in dev
|
|
390
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
125
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite)
|
|
391
126
|
},
|
|
392
|
-
|
|
127
|
+
vite
|
|
393
128
|
);
|
|
394
129
|
app.get("*", (0, import_server.createServerAdapter)(routeHandler));
|
|
395
130
|
app.post("*", handleWithMiddleware());
|
|
396
131
|
const port = (0, import_project_config.getConfig)().web.port;
|
|
397
132
|
console.log(`Started server on http://localhost:${port}`);
|
|
398
|
-
return
|
|
133
|
+
return app.listen(port);
|
|
399
134
|
}
|
|
400
135
|
let devApp = createServer();
|
|
401
136
|
process.stdin.on("data", async (data) => {
|
|
@@ -410,11 +145,11 @@ process.stdin.on("data", async (data) => {
|
|
|
410
145
|
function getCssLinks({
|
|
411
146
|
rwPaths,
|
|
412
147
|
route,
|
|
413
|
-
|
|
148
|
+
vite
|
|
414
149
|
}) {
|
|
415
150
|
const appAndRouteModules = (0, import_collectCss.componentsModules)(
|
|
416
151
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
417
|
-
|
|
152
|
+
vite
|
|
418
153
|
);
|
|
419
154
|
const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
|
|
420
155
|
const cssLinks = Array.from(collectedCss);
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,7 +39,6 @@ __export(index_exports, {
|
|
|
39
39
|
cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
|
|
40
40
|
cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
|
|
41
41
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
42
|
-
cedarRoutesAutoLoaderPlugin: () => import_vite_plugin_cedar_routes_auto_loader2.cedarRoutesAutoLoaderPlugin,
|
|
43
42
|
cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
|
|
44
43
|
cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
|
|
45
44
|
cedarUniversalDeployPlugin: () => import_vite_plugin_cedar_universal_deploy.cedarUniversalDeployPlugin,
|
|
@@ -59,7 +58,6 @@ var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-htm
|
|
|
59
58
|
var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
60
59
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
61
60
|
var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
62
|
-
var import_vite_plugin_cedar_routes_auto_loader = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
63
61
|
var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
|
|
64
62
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
65
63
|
var import_vite_plugin_jsx_loader = require("./plugins/vite-plugin-jsx-loader.js");
|
|
@@ -73,7 +71,6 @@ var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-ht
|
|
|
73
71
|
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
74
72
|
var import_vite_plugin_cedar_node_polyfills2 = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
75
73
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page2 = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
76
|
-
var import_vite_plugin_cedar_routes_auto_loader2 = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
77
74
|
var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
78
75
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports2 = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
79
76
|
var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugin-cedarjs-job-path-injector.js");
|
|
@@ -89,7 +86,14 @@ function cedar({ mode } = {}) {
|
|
|
89
86
|
forVite: true
|
|
90
87
|
});
|
|
91
88
|
const babelConfig = {
|
|
92
|
-
...webSideDefaultBabelConfig
|
|
89
|
+
...webSideDefaultBabelConfig,
|
|
90
|
+
// For RSC we don't want to include the routes auto-loader plugin as we
|
|
91
|
+
// handle that differently in each specific RSC build stage
|
|
92
|
+
overrides: rscEnabled ? webSideDefaultBabelConfig.overrides.filter((override) => {
|
|
93
|
+
return !override.plugins?.some((plugin) => {
|
|
94
|
+
return Array.isArray(plugin) && plugin[2] === "babel-plugin-redwood-routes-auto-loader";
|
|
95
|
+
});
|
|
96
|
+
}) : webSideDefaultBabelConfig.overrides
|
|
93
97
|
};
|
|
94
98
|
return [
|
|
95
99
|
mode === "test" && (0, import_vitest.cedarJsRouterImportTransformPlugin)(),
|
|
@@ -106,8 +110,6 @@ function cedar({ mode } = {}) {
|
|
|
106
110
|
(0, import_vite_plugin_jsx_loader.cedarTransformJsAsJsx)(),
|
|
107
111
|
(0, import_vite_plugin_cedar_remove_from_bundle.cedarRemoveFromBundle)(),
|
|
108
112
|
(0, import_vite_plugin_cedar_remove_dev_fatal_error_page.cedarRemoveDevFatalErrorPage)(),
|
|
109
|
-
// RSC handles route auto-loading differently in each build stage
|
|
110
|
-
!rscEnabled && (0, import_vite_plugin_cedar_routes_auto_loader.cedarRoutesAutoLoaderPlugin)(),
|
|
111
113
|
(0, import_plugin_react.default)({ babel: babelConfig })
|
|
112
114
|
];
|
|
113
115
|
}
|
|
@@ -125,7 +127,6 @@ var index_default = cedar;
|
|
|
125
127
|
cedarNodePolyfills,
|
|
126
128
|
cedarRemoveDevFatalErrorPage,
|
|
127
129
|
cedarRemoveFromBundle,
|
|
128
|
-
cedarRoutesAutoLoaderPlugin,
|
|
129
130
|
cedarSwapApolloProvider,
|
|
130
131
|
cedarTransformJsAsJsx,
|
|
131
132
|
cedarUniversalDeployPlugin,
|
|
@@ -79,15 +79,6 @@ function registerFwShims() {
|
|
|
79
79
|
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
80
80
|
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
81
81
|
console.log("registerFwShims chunk load id", id);
|
|
82
|
-
if (globalThis.__cedarjs__vite_ssr_runtime) {
|
|
83
|
-
return globalThis.__cedarjs__vite_ssr_runtime?.import(id).then((mod) => {
|
|
84
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
85
|
-
if (mod.default && typeof mod.default === "object") {
|
|
86
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
87
|
-
}
|
|
88
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
82
|
return import(id).then((mod) => {
|
|
92
83
|
console.log("registerFwShims chunk load mod", mod);
|
|
93
84
|
if (mod.default && typeof mod.default === "object") {
|
|
@@ -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 (
|
|
47
|
+
transform: async function(code, id) {
|
|
48
|
+
if (id !== routesFileId) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const ext = import_node_path.default.extname(id);
|
|
@@ -41,10 +41,6 @@ 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
|
-
}
|
|
48
44
|
let mod;
|
|
49
45
|
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
50
46
|
try {
|
|
@@ -33,28 +33,20 @@ __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");
|
|
36
38
|
var import_project_config = require("@cedarjs/project-config");
|
|
37
39
|
var import_entries = require("../lib/entries.js");
|
|
38
40
|
var import_StatusError = require("../lib/StatusError.js");
|
|
39
|
-
var import_utils = require("./utils.js");
|
|
40
41
|
let absoluteClientEntries = {};
|
|
41
|
-
|
|
42
|
+
function renderRscToStream(input) {
|
|
42
43
|
return input.rscId ? renderRsc(input) : executeRsa(input);
|
|
43
44
|
}
|
|
44
45
|
async function loadServerFile(filePath) {
|
|
45
46
|
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
|
-
}
|
|
50
47
|
return import(`file://${filePath}`);
|
|
51
48
|
}
|
|
52
49
|
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
|
-
}
|
|
58
50
|
const serverEntries = await (0, import_entries.getEntriesFromDist)();
|
|
59
51
|
console.log("rscRenderer.ts serverEntries", serverEntries);
|
|
60
52
|
const routesPath = import_node_path.default.join(
|
|
@@ -95,12 +87,10 @@ function getBundlerConfig() {
|
|
|
95
87
|
{},
|
|
96
88
|
{
|
|
97
89
|
get(_target, encodedId) {
|
|
98
|
-
console.log("
|
|
90
|
+
console.log("Proxy get encodedId", encodedId);
|
|
99
91
|
const [filePath, name] = encodedId.split("#");
|
|
100
|
-
console.log("filePath", filePath);
|
|
101
|
-
console.log("name", name);
|
|
102
92
|
const filePathSlash = filePath.replaceAll("\\", "/");
|
|
103
|
-
const id =
|
|
93
|
+
const id = absoluteClientEntries[filePathSlash];
|
|
104
94
|
console.log("absoluteClientEntries", absoluteClientEntries);
|
|
105
95
|
console.log("filePath", filePathSlash);
|
|
106
96
|
if (!id) {
|
|
@@ -123,14 +113,12 @@ async function renderRsc(input) {
|
|
|
123
113
|
throw new Error("Unexpected input. Missing rscId or props.");
|
|
124
114
|
}
|
|
125
115
|
console.log("renderRsc input", input);
|
|
126
|
-
const { createElement } = await (0, import_utils.importRscReact)();
|
|
127
|
-
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
128
116
|
const serverRoutes = await getRoutesComponent();
|
|
129
117
|
const model = {
|
|
130
|
-
__cedarjs__Routes: createElement(serverRoutes)
|
|
118
|
+
__cedarjs__Routes: (0, import_react.createElement)(serverRoutes)
|
|
131
119
|
};
|
|
132
120
|
console.log("rscRenderer.ts renderRsc model", model);
|
|
133
|
-
return renderToReadableStream(model, getBundlerConfig());
|
|
121
|
+
return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
|
|
134
122
|
}
|
|
135
123
|
function isSerializedFormData(data) {
|
|
136
124
|
return !!data && data?.__formData__;
|
|
@@ -161,16 +149,14 @@ async function executeRsa(input) {
|
|
|
161
149
|
console.log("rscRenderer.ts args", ...input.args);
|
|
162
150
|
const data = await method(...input.args);
|
|
163
151
|
console.log("rscRenderer.ts rsa return data", data);
|
|
164
|
-
const { createElement } = await (0, import_utils.importRscReact)();
|
|
165
|
-
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
166
152
|
const serverRoutes = await getRoutesComponent();
|
|
167
153
|
console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
|
|
168
154
|
const model = {
|
|
169
|
-
__cedarjs__Routes: createElement(serverRoutes),
|
|
155
|
+
__cedarjs__Routes: (0, import_react.createElement)(serverRoutes),
|
|
170
156
|
__cedarjs__rsa_data: data
|
|
171
157
|
};
|
|
172
158
|
console.log("rscRenderer.ts executeRsa model", model);
|
|
173
|
-
return renderToReadableStream(model, getBundlerConfig());
|
|
159
|
+
return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
|
|
174
160
|
}
|
|
175
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
176
162
|
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");
|
|
41
43
|
const BASE_PATH = "/rw-rsc/";
|
|
42
|
-
|
|
43
|
-
const { renderRscToStream } = await import("./rscRenderer.js");
|
|
44
|
-
const { sendRscFlightToStudio } = await import("./rscStudioHandlers.js");
|
|
44
|
+
function createRscRequestHandler(options) {
|
|
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 @@ async function createRscRequestHandler(options) {
|
|
|
56
56
|
matchedMw?.handler,
|
|
57
57
|
{
|
|
58
58
|
params: matchedMw?.params,
|
|
59
|
-
|
|
59
|
+
viteDevServer: options.viteDevServer
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
62
|
const webRes = mwResponse.toResponse();
|
|
@@ -101,9 +101,9 @@ async function createRscRequestHandler(options) {
|
|
|
101
101
|
res.end(String(err));
|
|
102
102
|
};
|
|
103
103
|
try {
|
|
104
|
-
const readable = await renderRscToStream({ rscId, rsaId, args });
|
|
104
|
+
const readable = await (0, import_rscRenderer.renderRscToStream)({ rscId, rsaId, args });
|
|
105
105
|
import_node_stream.Readable.fromWeb(readable).pipe(res);
|
|
106
|
-
await sendRscFlightToStudio({
|
|
106
|
+
await (0, import_rscStudioHandlers.sendRscFlightToStudio)({
|
|
107
107
|
rscId,
|
|
108
108
|
rsaId,
|
|
109
109
|
args,
|
package/dist/cjs/runFeServer.js
CHANGED
|
@@ -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);
|
|
41
42
|
var import_project_config = require("@cedarjs/project-config");
|
|
42
43
|
var import_rscCss = require("@cedarjs/router/rscCss");
|
|
43
44
|
var import_server_store = require("@cedarjs/server-store");
|
|
44
45
|
var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.js");
|
|
45
46
|
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
46
47
|
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
|
-
|
|
63
|
+
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
|
-
|
|
122
|
+
createRscRequestHandler({
|
|
123
123
|
getMiddlewareRouter: async () => middlewareRouter
|
|
124
124
|
})
|
|
125
125
|
);
|
|
@@ -139,6 +139,25 @@ 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
|
+
}
|
|
142
161
|
runFeServer();
|
|
143
162
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
163
|
0 && (module.exports = {
|