@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
|
@@ -50,10 +50,10 @@ const createReactStreamingHandler = async ({
|
|
|
50
50
|
clientEntryPath,
|
|
51
51
|
getStylesheetLinks,
|
|
52
52
|
getMiddlewareRouter
|
|
53
|
-
},
|
|
53
|
+
}, viteDevServer) => {
|
|
54
54
|
const rwPaths = (0, import_project_config.getPaths)();
|
|
55
55
|
const rwConfig = (0, import_project_config.getConfig)();
|
|
56
|
-
const isProd = !
|
|
56
|
+
const isProd = !viteDevServer;
|
|
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
|
-
|
|
100
|
+
viteDevServer
|
|
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)(
|
|
120
|
-
fallbackDocumentImport = await
|
|
119
|
+
entryServerImport = await (0, import_utils.ssrLoadEntryServer)(viteDevServer);
|
|
120
|
+
fallbackDocumentImport = await viteDevServer.ssrLoadModule(
|
|
121
121
|
rwPaths.web.document
|
|
122
122
|
);
|
|
123
123
|
}
|
|
@@ -134,12 +134,10 @@ const createReactStreamingHandler = async ({
|
|
|
134
134
|
req,
|
|
135
135
|
parsedParams
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
viteDevServer
|
|
138
138
|
});
|
|
139
139
|
metaTags = routeHookOutput.meta;
|
|
140
|
-
const jsBundles = [
|
|
141
|
-
viteSsrDevServer ? clientEntryPath : "/" + clientEntryPath
|
|
142
|
-
];
|
|
140
|
+
const jsBundles = [viteDevServer ? clientEntryPath : "/" + clientEntryPath];
|
|
143
141
|
if (currentRoute.bundle) {
|
|
144
142
|
jsBundles.push("/" + currentRoute.bundle);
|
|
145
143
|
}
|
|
@@ -159,13 +157,12 @@ const createReactStreamingHandler = async ({
|
|
|
159
157
|
{
|
|
160
158
|
waitForAllReady: isSeoCrawler,
|
|
161
159
|
onError: (err) => {
|
|
162
|
-
if (!isProd &&
|
|
163
|
-
|
|
160
|
+
if (!isProd && viteDevServer) {
|
|
161
|
+
viteDevServer.ssrFixStacktrace(err);
|
|
164
162
|
}
|
|
165
163
|
console.error(err);
|
|
166
164
|
}
|
|
167
|
-
}
|
|
168
|
-
viteSsrDevServer
|
|
165
|
+
}
|
|
169
166
|
);
|
|
170
167
|
return reactResponse;
|
|
171
168
|
};
|
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var streamHelpers_exports = {};
|
|
30
30
|
__export(streamHelpers_exports, {
|
|
31
|
+
importModule: () => importModule,
|
|
31
32
|
reactRenderToStreamResponse: () => reactRenderToStreamResponse
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(streamHelpers_exports);
|
|
@@ -61,7 +62,7 @@ globalThis.__webpack_require__ ||= (id) => {
|
|
|
61
62
|
return globalThis.__rw_module_cache__.get(id)
|
|
62
63
|
};
|
|
63
64
|
`;
|
|
64
|
-
async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions
|
|
65
|
+
async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions) {
|
|
65
66
|
const { waitForAllReady = false } = streamOptions;
|
|
66
67
|
const {
|
|
67
68
|
ServerEntry,
|
|
@@ -83,13 +84,13 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
83
84
|
meta: metaTags
|
|
84
85
|
});
|
|
85
86
|
const rscEnabled = (0, import_project_config.getConfig)().experimental?.rsc?.enabled;
|
|
86
|
-
const { createElement } = rscEnabled ? await importModule("__cedarjs__react"
|
|
87
|
+
const { createElement } = rscEnabled ? await importModule("__cedarjs__react") : await import("react");
|
|
87
88
|
const {
|
|
88
89
|
createInjector,
|
|
89
90
|
ServerHtmlProvider,
|
|
90
91
|
ServerInjectedHtml
|
|
91
|
-
} = rscEnabled ? await importModule("__cedarjs__server_inject"
|
|
92
|
-
const { renderToString } = rscEnabled ? await importModule("rd-server"
|
|
92
|
+
} = rscEnabled ? await importModule("__cedarjs__server_inject") : await import("@cedarjs/web/serverInject");
|
|
93
|
+
const { renderToString } = rscEnabled ? await importModule("rd-server") : await import("react-dom/server");
|
|
93
94
|
const { injectionState, injectToPage } = createInjector();
|
|
94
95
|
const bufferTransform = (0, import_bufferedTransform.createBufferedTransformStream)();
|
|
95
96
|
const serverInjectionTransform = (0, import_serverInjectionTransform.createServerInjectionTransform)({
|
|
@@ -104,8 +105,8 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
104
105
|
controller.abort();
|
|
105
106
|
}, 1e4);
|
|
106
107
|
const timeoutTransform = (0, import_cancelTimeoutTransform.createTimeoutTransform)(timeoutHandle);
|
|
107
|
-
const { ServerAuthProvider } = rscEnabled ? await importModule("__cedarjs__server_auth_provider"
|
|
108
|
-
const { LocationProvider } = rscEnabled ? await importModule("__cedarjs__location"
|
|
108
|
+
const { ServerAuthProvider } = rscEnabled ? await importModule("__cedarjs__server_auth_provider") : await import("@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js");
|
|
109
|
+
const { LocationProvider } = rscEnabled ? await importModule("__cedarjs__location") : await import("@cedarjs/router/location");
|
|
109
110
|
const renderRoot = (url) => {
|
|
110
111
|
return createElement(
|
|
111
112
|
ServerAuthProvider,
|
|
@@ -137,7 +138,7 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
137
138
|
),
|
|
138
139
|
bootstrapModules: jsBundles
|
|
139
140
|
};
|
|
140
|
-
const { renderToReadableStream } = rscEnabled ? await importModule("rd-server"
|
|
141
|
+
const { renderToReadableStream } = rscEnabled ? await importModule("rd-server") : await import("react-dom/server.edge");
|
|
141
142
|
try {
|
|
142
143
|
let didErrorOutsideShell = false;
|
|
143
144
|
const renderToStreamOptions = {
|
|
@@ -196,52 +197,34 @@ function applyStreamTransforms(reactStream, transformsToApply) {
|
|
|
196
197
|
}
|
|
197
198
|
return outputStream;
|
|
198
199
|
}
|
|
199
|
-
async function importModule(mod
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
import_node_path.default.join(distSsr, "__cedarjs__location.mjs")
|
|
223
|
-
);
|
|
224
|
-
const serverAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
225
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_auth_provider.mjs")
|
|
226
|
-
);
|
|
227
|
-
const serverInjectPath = (0, import_utils.makeFilePath)(
|
|
228
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_inject.mjs")
|
|
229
|
-
);
|
|
230
|
-
if (mod === "rd-server") {
|
|
231
|
-
return (await import(rdServerPath)).default;
|
|
232
|
-
} else if (mod === "__cedarjs__react") {
|
|
233
|
-
return (await import(reactPath)).default;
|
|
234
|
-
} else if (mod === "__cedarjs__location") {
|
|
235
|
-
return await import(locationPath);
|
|
236
|
-
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
237
|
-
return await import(serverAuthProviderPath);
|
|
238
|
-
} else if (mod === "__cedarjs__server_inject") {
|
|
239
|
-
return await import(serverInjectPath);
|
|
240
|
-
}
|
|
200
|
+
async function importModule(mod) {
|
|
201
|
+
const distSsr = (0, import_project_config.getPaths)().web.distSsr;
|
|
202
|
+
const rdServerPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "rd-server.mjs"));
|
|
203
|
+
const reactPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "__cedarjs__react.mjs"));
|
|
204
|
+
const locationPath = (0, import_utils.makeFilePath)(
|
|
205
|
+
import_node_path.default.join(distSsr, "__cedarjs__location.mjs")
|
|
206
|
+
);
|
|
207
|
+
const ServerAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
208
|
+
import_node_path.default.join(distSsr, "__cedarjs__server_auth_provider.mjs")
|
|
209
|
+
);
|
|
210
|
+
const ServerInjectPath = (0, import_utils.makeFilePath)(
|
|
211
|
+
import_node_path.default.join(distSsr, "__cedarjs__server_inject.mjs")
|
|
212
|
+
);
|
|
213
|
+
if (mod === "rd-server") {
|
|
214
|
+
return (await import(rdServerPath)).default;
|
|
215
|
+
} else if (mod === "__cedarjs__react") {
|
|
216
|
+
return (await import(reactPath)).default;
|
|
217
|
+
} else if (mod === "__cedarjs__location") {
|
|
218
|
+
return await import(locationPath);
|
|
219
|
+
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
220
|
+
return await import(ServerAuthProviderPath);
|
|
221
|
+
} else if (mod === "__cedarjs__server_inject") {
|
|
222
|
+
return await import(ServerInjectPath);
|
|
241
223
|
}
|
|
242
224
|
throw new Error("Unknown module " + mod);
|
|
243
225
|
}
|
|
244
226
|
// Annotate the CommonJS export names for ESM import in node:
|
|
245
227
|
0 && (module.exports = {
|
|
228
|
+
importModule,
|
|
246
229
|
reactRenderToStreamResponse
|
|
247
230
|
});
|
|
@@ -55,11 +55,11 @@ const defaultRouteHookOutput = {
|
|
|
55
55
|
const loadAndRunRouteHooks = async ({
|
|
56
56
|
paths = [],
|
|
57
57
|
reqMeta,
|
|
58
|
-
|
|
58
|
+
viteDevServer,
|
|
59
59
|
previousOutput = defaultRouteHookOutput
|
|
60
60
|
}) => {
|
|
61
61
|
const loadModule = async (path) => {
|
|
62
|
-
return
|
|
62
|
+
return viteDevServer ? viteDevServer.ssrLoadModule(path) : import(path);
|
|
63
63
|
};
|
|
64
64
|
let currentRouteHooks;
|
|
65
65
|
let rhOutput = defaultRouteHookOutput;
|
|
@@ -79,7 +79,7 @@ const loadAndRunRouteHooks = async ({
|
|
|
79
79
|
paths,
|
|
80
80
|
reqMeta,
|
|
81
81
|
previousOutput: rhOutput,
|
|
82
|
-
|
|
82
|
+
viteDevServer
|
|
83
83
|
});
|
|
84
84
|
} else {
|
|
85
85
|
return rhOutput;
|
package/dist/devFeServer.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import http from "node:http";
|
|
3
2
|
import { createServerAdapter } from "@whatwg-node/server";
|
|
4
3
|
import express from "express";
|
|
5
|
-
import {
|
|
6
|
-
createServer as createViteServer,
|
|
7
|
-
createServerModuleRunner,
|
|
8
|
-
defaultServerConditions
|
|
9
|
-
} from "vite";
|
|
4
|
+
import { createServer as createViteServer } from "vite";
|
|
10
5
|
import { cjsInterop } from "vite-plugin-cjs-interop";
|
|
11
6
|
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
12
7
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
@@ -15,10 +10,6 @@ import { registerFwGlobalsAndShims } from "./lib/registerFwGlobalsAndShims.js";
|
|
|
15
10
|
import { invoke } from "./middleware/invokeMiddleware.js";
|
|
16
11
|
import { createMiddlewareRouter } from "./middleware/register.js";
|
|
17
12
|
import { rscRoutesAutoLoader } from "./plugins/vite-plugin-rsc-routes-auto-loader.js";
|
|
18
|
-
import { rscRoutesImports } from "./plugins/vite-plugin-rsc-routes-imports.js";
|
|
19
|
-
import { rscSsrRouterImport } from "./plugins/vite-plugin-rsc-ssr-router-import.js";
|
|
20
|
-
import { rscTransformUseServerPlugin } from "./plugins/vite-plugin-rsc-transform-server.js";
|
|
21
|
-
import { createWebSocketServer } from "./rsc/rscWebSocketServer.js";
|
|
22
13
|
import { collectCssPaths, componentsModules } from "./streaming/collectCss.js";
|
|
23
14
|
import { createReactStreamingHandler } from "./streaming/createReactStreamingHandler.js";
|
|
24
15
|
import {
|
|
@@ -27,13 +18,10 @@ import {
|
|
|
27
18
|
getFullUrl
|
|
28
19
|
} from "./utils.js";
|
|
29
20
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
30
|
-
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
31
|
-
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
32
21
|
async function createServer() {
|
|
33
22
|
ensureProcessDirWeb();
|
|
34
23
|
registerFwGlobalsAndShims();
|
|
35
24
|
const app = express();
|
|
36
|
-
const server = http.createServer(app);
|
|
37
25
|
const rwPaths = getPaths();
|
|
38
26
|
const rscEnabled = getConfig().experimental.rsc?.enabled ?? false;
|
|
39
27
|
const serverStorage = createServerStorage();
|
|
@@ -56,78 +44,8 @@ async function createServer() {
|
|
|
56
44
|
"Vite config not found. Please set up Vite before running the dev server."
|
|
57
45
|
);
|
|
58
46
|
}
|
|
59
|
-
const
|
|
47
|
+
const vite = await createViteServer({
|
|
60
48
|
configFile: rwPaths.web.viteConfig,
|
|
61
|
-
envFile: false,
|
|
62
|
-
define: {
|
|
63
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
64
|
-
},
|
|
65
|
-
ssr: {
|
|
66
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
67
|
-
// inline dependencies in the server build. This gets round runtime
|
|
68
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
69
|
-
//
|
|
70
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
71
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
72
|
-
// noExternal: true,
|
|
73
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
74
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
75
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
76
|
-
// we wanted to go that route.
|
|
77
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
78
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
79
|
-
// (css pre-init failure)
|
|
80
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
81
|
-
external: [
|
|
82
|
-
"@prisma/client",
|
|
83
|
-
"@prisma/adapter-better-sqlite3",
|
|
84
|
-
"@prisma/fetch-engine",
|
|
85
|
-
"@prisma/internals",
|
|
86
|
-
"better-sqlite3",
|
|
87
|
-
"@cedarjs/auth-dbauth-api",
|
|
88
|
-
"@cedarjs/cookie-jar",
|
|
89
|
-
"@cedarjs/server-store",
|
|
90
|
-
"@simplewebauthn/server",
|
|
91
|
-
"graphql-scalars",
|
|
92
|
-
"minimatch",
|
|
93
|
-
"playwright",
|
|
94
|
-
"react-dom"
|
|
95
|
-
],
|
|
96
|
-
resolve: {
|
|
97
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
98
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
99
|
-
// dependencies apart from node built-ins.
|
|
100
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
101
|
-
// `externalConditions`? When is one used over the other?
|
|
102
|
-
// conditions: ['react-server'],
|
|
103
|
-
// externalConditions: ['react-server'],
|
|
104
|
-
},
|
|
105
|
-
optimizeDeps: {
|
|
106
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
107
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
108
|
-
// include: [
|
|
109
|
-
// 'react/**/*',
|
|
110
|
-
// 'react-dom/server',
|
|
111
|
-
// 'react-dom/server.edge',
|
|
112
|
-
// 'rehackt',
|
|
113
|
-
// 'react-server-dom-webpack/server',
|
|
114
|
-
// 'react-server-dom-webpack/client',
|
|
115
|
-
// '@apollo/client/cache/*',
|
|
116
|
-
// '@apollo/client/utilities/*',
|
|
117
|
-
// '@apollo/client/react/hooks/*',
|
|
118
|
-
// 'react-fast-compare',
|
|
119
|
-
// 'invariant',
|
|
120
|
-
// 'shallowequal',
|
|
121
|
-
// 'graphql/language/*',
|
|
122
|
-
// 'stacktracey',
|
|
123
|
-
// 'deepmerge',
|
|
124
|
-
// 'fast-glob',
|
|
125
|
-
// ],
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
resolve: {
|
|
129
|
-
// conditions: ['react-server'],
|
|
130
|
-
},
|
|
131
49
|
plugins: [
|
|
132
50
|
cjsInterop({
|
|
133
51
|
dependencies: [
|
|
@@ -141,195 +59,16 @@ async function createServer() {
|
|
|
141
59
|
"@cedarjs/auth-!(dbauth)-web"
|
|
142
60
|
]
|
|
143
61
|
}),
|
|
144
|
-
rscEnabled && rscRoutesAutoLoader()
|
|
145
|
-
rscEnabled && rscSsrRouterImport()
|
|
62
|
+
rscEnabled && rscRoutesAutoLoader()
|
|
146
63
|
],
|
|
147
64
|
server: { middlewareMode: true },
|
|
148
65
|
logLevel: "info",
|
|
149
66
|
clearScreen: false,
|
|
150
67
|
appType: "custom"
|
|
151
68
|
});
|
|
152
|
-
globalThis.__cedarjs__vite_ssr_runtime = createServerModuleRunner(
|
|
153
|
-
viteSsrDevServer.environments.ssr
|
|
154
|
-
);
|
|
155
|
-
globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
|
|
156
|
-
globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
|
|
157
|
-
const viteRscServer = await createViteServer({
|
|
158
|
-
envFile: false,
|
|
159
|
-
define: {
|
|
160
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
161
|
-
},
|
|
162
|
-
ssr: {
|
|
163
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
164
|
-
// inline dependencies in the server build. This gets round runtime
|
|
165
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
166
|
-
//
|
|
167
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
168
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
169
|
-
noExternal: true,
|
|
170
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
171
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
172
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
173
|
-
// we wanted to go that route.
|
|
174
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
175
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
176
|
-
// (css pre-init failure)
|
|
177
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
178
|
-
external: [
|
|
179
|
-
"@prisma/client",
|
|
180
|
-
"@prisma/adapter-better-sqlite3",
|
|
181
|
-
"@prisma/fetch-engine",
|
|
182
|
-
"@prisma/internals",
|
|
183
|
-
"better-sqlite3",
|
|
184
|
-
"@cedarjs/auth-dbauth-api",
|
|
185
|
-
"@cedarjs/cookie-jar",
|
|
186
|
-
"@cedarjs/server-store",
|
|
187
|
-
"@cedarjs/structure",
|
|
188
|
-
"@simplewebauthn/server",
|
|
189
|
-
"graphql-scalars",
|
|
190
|
-
"minimatch",
|
|
191
|
-
"playwright",
|
|
192
|
-
"react-dom"
|
|
193
|
-
],
|
|
194
|
-
resolve: {
|
|
195
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
196
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
197
|
-
// dependencies apart from node built-ins.
|
|
198
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
199
|
-
// `externalConditions`? When is one used over the other?
|
|
200
|
-
// In Vite 6, we must include `defaultServerConditions` alongside
|
|
201
|
-
// `react-server` so that nested condition maps (e.g. the `node`
|
|
202
|
-
// sub-condition inside `react-server-dom-webpack/server`'s exports)
|
|
203
|
-
// can still be resolved. Without `node` (or another environment
|
|
204
|
-
// condition), the resolver throws "No known conditions for
|
|
205
|
-
// './server' specifier in 'react-server-dom-webpack' package".
|
|
206
|
-
conditions: ["react-server", ...defaultServerConditions],
|
|
207
|
-
externalConditions: ["react-server", ...defaultServerConditions]
|
|
208
|
-
},
|
|
209
|
-
optimizeDeps: {
|
|
210
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
211
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
212
|
-
include: [
|
|
213
|
-
"react/**/*",
|
|
214
|
-
"react-dom/server",
|
|
215
|
-
"react-dom/server.edge",
|
|
216
|
-
"rehackt",
|
|
217
|
-
"react-server-dom-webpack/server",
|
|
218
|
-
"react-server-dom-webpack/server.edge",
|
|
219
|
-
"react-server-dom-webpack/client",
|
|
220
|
-
"react-server-dom-webpack/client.edge",
|
|
221
|
-
"@apollo/client/cache/*",
|
|
222
|
-
"@apollo/client/utilities/*",
|
|
223
|
-
"@apollo/client/react/hooks/*",
|
|
224
|
-
"react-fast-compare",
|
|
225
|
-
"invariant",
|
|
226
|
-
"shallowequal",
|
|
227
|
-
"graphql/language/*",
|
|
228
|
-
"stacktracey",
|
|
229
|
-
"deepmerge",
|
|
230
|
-
"fast-glob",
|
|
231
|
-
"@whatwg-node/fetch",
|
|
232
|
-
"busboy",
|
|
233
|
-
"cookie"
|
|
234
|
-
],
|
|
235
|
-
// Without excluding `util` we get "TypeError: util.TextEncoder is not
|
|
236
|
-
// a constructor" in react-server-dom-webpack.server because it'll try
|
|
237
|
-
// to use Browserify's `util` instead of Node's. And Browserify's
|
|
238
|
-
// polyfill is missing TextEncoder+TextDecoder. The reason it's using
|
|
239
|
-
// the Browserify polyfill is because we have
|
|
240
|
-
// `vite-plugin-node-polyfills` as a dependency, and that'll add
|
|
241
|
-
// Browserify's `node-util` to `node_modules`, so when Vite goes to
|
|
242
|
-
// resolve `import { TextEncoder } from 'util` it'll find the one in
|
|
243
|
-
// `node_modules` instead of Node's internal version.
|
|
244
|
-
// We only see this in dev, and not in prod. I'm not entirely sure why
|
|
245
|
-
// but I have two guesses: 1. When RSC is enabled we don't actually use
|
|
246
|
-
// `vite-plugin-node-polyfill`, so some kind of tree shaking is
|
|
247
|
-
// happening, which prevents the issue from occurring. 2. In prod we
|
|
248
|
-
// only use Node's dependency resolution. Vite is not involved. And
|
|
249
|
-
// that difference in resolution is what prevents the issue from
|
|
250
|
-
// occurring.
|
|
251
|
-
exclude: ["util"]
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
resolve: {
|
|
255
|
-
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
256
|
-
conditions: ["react-server", ...defaultServerConditions]
|
|
257
|
-
},
|
|
258
|
-
plugins: [
|
|
259
|
-
{
|
|
260
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
261
|
-
transform(code, id, _options) {
|
|
262
|
-
globalThis.__cedarjs__client_references?.delete(id);
|
|
263
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
264
|
-
return void 0;
|
|
265
|
-
}
|
|
266
|
-
console.log(
|
|
267
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
268
|
-
id
|
|
269
|
-
);
|
|
270
|
-
globalThis.__cedarjs__client_references?.add(id);
|
|
271
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
272
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
273
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
274
|
-
const result = [
|
|
275
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
276
|
-
"",
|
|
277
|
-
...names.map((name) => {
|
|
278
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
279
|
-
})
|
|
280
|
-
].join("\n");
|
|
281
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
282
|
-
console.log(
|
|
283
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
284
|
-
);
|
|
285
|
-
return { code: result, map: null };
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
rscTransformUseServerPlugin("", {}),
|
|
289
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
290
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
291
|
-
// to
|
|
292
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
293
|
-
// That's why it needs the `clientEntryFiles` data
|
|
294
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
295
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
296
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
297
|
-
rscRoutesImports(),
|
|
298
|
-
{
|
|
299
|
-
name: "rsc-hot-update",
|
|
300
|
-
handleHotUpdate(ctx) {
|
|
301
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
302
|
-
return [];
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
],
|
|
306
|
-
build: {
|
|
307
|
-
ssr: true
|
|
308
|
-
},
|
|
309
|
-
server: {
|
|
310
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
311
|
-
// middleware mode
|
|
312
|
-
middlewareMode: true,
|
|
313
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
314
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
315
|
-
// different port.
|
|
316
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
317
|
-
// port
|
|
318
|
-
ws: false
|
|
319
|
-
// hmr: {
|
|
320
|
-
// port: 24679,
|
|
321
|
-
// },
|
|
322
|
-
},
|
|
323
|
-
appType: "custom",
|
|
324
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
325
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
326
|
-
});
|
|
327
|
-
globalThis.__cedarjs__vite_rsc_runtime = createServerModuleRunner(
|
|
328
|
-
viteRscServer.environments.ssr
|
|
329
|
-
);
|
|
330
69
|
const handleWithMiddleware = (route) => {
|
|
331
70
|
return createServerAdapter(async (req) => {
|
|
332
|
-
const middlewareRouter = await createMiddlewareRouter(
|
|
71
|
+
const middlewareRouter = await createMiddlewareRouter(vite);
|
|
333
72
|
const middleware = middlewareRouter.find(
|
|
334
73
|
req.method,
|
|
335
74
|
req.url
|
|
@@ -339,22 +78,19 @@ async function createServer() {
|
|
|
339
78
|
}
|
|
340
79
|
const [mwRes] = await invoke(req, middleware, {
|
|
341
80
|
route,
|
|
342
|
-
|
|
81
|
+
viteDevServer: vite
|
|
343
82
|
});
|
|
344
83
|
return mwRes.toResponse();
|
|
345
84
|
});
|
|
346
85
|
};
|
|
347
|
-
app.use(
|
|
86
|
+
app.use(vite.middlewares);
|
|
348
87
|
if (rscEnabled) {
|
|
349
|
-
|
|
350
|
-
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
351
|
-
new URL("./rsc/rscRequestHandler.js", import.meta.url).pathname
|
|
352
|
-
);
|
|
88
|
+
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
353
89
|
app.use(
|
|
354
90
|
"/rw-rsc",
|
|
355
|
-
|
|
356
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
357
|
-
|
|
91
|
+
createRscRequestHandler({
|
|
92
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite),
|
|
93
|
+
viteDevServer: vite
|
|
358
94
|
})
|
|
359
95
|
);
|
|
360
96
|
}
|
|
@@ -364,22 +100,18 @@ async function createServer() {
|
|
|
364
100
|
routes,
|
|
365
101
|
clientEntryPath: rwPaths.web.entryClient,
|
|
366
102
|
getStylesheetLinks: (route) => {
|
|
367
|
-
return getCssLinks({
|
|
368
|
-
rwPaths,
|
|
369
|
-
route,
|
|
370
|
-
viteSsrDevServer
|
|
371
|
-
});
|
|
103
|
+
return getCssLinks({ rwPaths, route, vite });
|
|
372
104
|
},
|
|
373
105
|
// Recreate middleware router on each request in dev
|
|
374
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
106
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite)
|
|
375
107
|
},
|
|
376
|
-
|
|
108
|
+
vite
|
|
377
109
|
);
|
|
378
110
|
app.get("*", createServerAdapter(routeHandler));
|
|
379
111
|
app.post("*", handleWithMiddleware());
|
|
380
112
|
const port = getConfig().web.port;
|
|
381
113
|
console.log(`Started server on http://localhost:${port}`);
|
|
382
|
-
return
|
|
114
|
+
return app.listen(port);
|
|
383
115
|
}
|
|
384
116
|
let devApp = createServer();
|
|
385
117
|
process.stdin.on("data", async (data) => {
|
|
@@ -394,11 +126,11 @@ process.stdin.on("data", async (data) => {
|
|
|
394
126
|
function getCssLinks({
|
|
395
127
|
rwPaths,
|
|
396
128
|
route,
|
|
397
|
-
|
|
129
|
+
vite
|
|
398
130
|
}) {
|
|
399
131
|
const appAndRouteModules = componentsModules(
|
|
400
132
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
401
|
-
|
|
133
|
+
vite
|
|
402
134
|
);
|
|
403
135
|
const collectedCss = collectCssPaths(appAndRouteModules);
|
|
404
136
|
const cssLinks = Array.from(collectedCss);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
|
|
|
7
7
|
export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
|
|
8
8
|
export { cedarNodePolyfills } from './plugins/vite-plugin-cedar-node-polyfills.js';
|
|
9
9
|
export { cedarRemoveDevFatalErrorPage } from './plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js';
|
|
10
|
-
export { cedarRoutesAutoLoaderPlugin } from './plugins/vite-plugin-cedar-routes-auto-loader.js';
|
|
11
10
|
export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-bundle.js';
|
|
12
11
|
export { cedarjsResolveCedarStyleImportsPlugin } from './plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js';
|
|
13
12
|
export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-path-injector.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAsBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CA0ClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|