@cedarjs/vite 7.0.0 → 8.0.0-canary.3265
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/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +3 -7
- package/dist/buildRouteHooks.d.ts +7 -13
- package/dist/buildRouteHooks.d.ts.map +1 -1
- package/dist/buildRouteHooks.js +5 -10
- package/dist/bundled/react-server-dom-webpack.server.js +2263 -29124
- package/dist/devFeServer.js +278 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/lib/registerFwGlobalsAndShims.js +9 -0
- package/dist/plugins/vite-plugin-cedar-cell.d.ts +2 -1
- package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-cell.js +30 -11
- package/dist/plugins/vite-plugin-cedar-parsed-scalars.d.ts +20 -0
- package/dist/plugins/vite-plugin-cedar-parsed-scalars.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-parsed-scalars.js +60 -0
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts +2 -6
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-handler-als-wrapping.js +4 -7
- 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 +4 -0
- package/dist/rsc/rscRenderer.d.ts.map +1 -1
- package/dist/rsc/rscRenderer.js +19 -5
- 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/rsc/rscWebSocketServer.d.ts +2 -0
- package/dist/rsc/rscWebSocketServer.d.ts.map +1 -0
- package/dist/rsc/rscWebSocketServer.js +22 -0
- package/dist/rsc/utils.d.ts +10 -0
- package/dist/rsc/utils.d.ts.map +1 -0
- package/dist/rsc/utils.js +21 -0
- package/dist/runFeServer.js +5 -24
- package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
- package/dist/streaming/createReactStreamingHandler.js +13 -10
- package/dist/streaming/streamHelpers.d.ts +8 -3
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +50 -32
- 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 +32 -30
package/dist/devFeServer.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import http from "node:http";
|
|
2
3
|
import { createServerAdapter } from "@whatwg-node/server";
|
|
3
4
|
import express from "express";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createServer as createViteServer,
|
|
7
|
+
createServerModuleRunner,
|
|
8
|
+
defaultServerConditions
|
|
9
|
+
} from "vite";
|
|
5
10
|
import { cjsInterop } from "vite-plugin-cjs-interop";
|
|
6
11
|
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
7
12
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
@@ -10,6 +15,10 @@ import { registerFwGlobalsAndShims } from "./lib/registerFwGlobalsAndShims.js";
|
|
|
10
15
|
import { invoke } from "./middleware/invokeMiddleware.js";
|
|
11
16
|
import { createMiddlewareRouter } from "./middleware/register.js";
|
|
12
17
|
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";
|
|
13
22
|
import { collectCssPaths, componentsModules } from "./streaming/collectCss.js";
|
|
14
23
|
import { createReactStreamingHandler } from "./streaming/createReactStreamingHandler.js";
|
|
15
24
|
import {
|
|
@@ -18,14 +27,17 @@ import {
|
|
|
18
27
|
getFullUrl
|
|
19
28
|
} from "./utils.js";
|
|
20
29
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
30
|
+
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
31
|
+
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
21
32
|
async function createServer() {
|
|
22
33
|
ensureProcessDirWeb();
|
|
23
34
|
registerFwGlobalsAndShims();
|
|
24
35
|
const app = express();
|
|
36
|
+
const server = http.createServer(app);
|
|
25
37
|
const rwPaths = getPaths();
|
|
26
38
|
const rscEnabled = getConfig().experimental.rsc?.enabled ?? false;
|
|
27
39
|
const serverStorage = createServerStorage();
|
|
28
|
-
app.use(
|
|
40
|
+
app.use((req, _res, next) => {
|
|
29
41
|
const fullUrl = getFullUrl(req, rscEnabled);
|
|
30
42
|
const perReqStore = createPerRequestMap({
|
|
31
43
|
// Convert express headers to fetch header
|
|
@@ -44,8 +56,78 @@ async function createServer() {
|
|
|
44
56
|
"Vite config not found. Please set up Vite before running the dev server."
|
|
45
57
|
);
|
|
46
58
|
}
|
|
47
|
-
const
|
|
59
|
+
const viteSsrDevServer = await createViteServer({
|
|
48
60
|
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
|
+
},
|
|
49
131
|
plugins: [
|
|
50
132
|
cjsInterop({
|
|
51
133
|
dependencies: [
|
|
@@ -54,16 +136,186 @@ async function createServer() {
|
|
|
54
136
|
"@cedarjs/prerender/*"
|
|
55
137
|
]
|
|
56
138
|
}),
|
|
57
|
-
rscEnabled && rscRoutesAutoLoader()
|
|
139
|
+
rscEnabled && rscRoutesAutoLoader(),
|
|
140
|
+
rscEnabled && rscSsrRouterImport()
|
|
58
141
|
],
|
|
59
142
|
server: { middlewareMode: true },
|
|
60
143
|
logLevel: "info",
|
|
61
144
|
clearScreen: false,
|
|
62
145
|
appType: "custom"
|
|
63
146
|
});
|
|
147
|
+
globalThis.__cedarjs__vite_ssr_runtime = createServerModuleRunner(
|
|
148
|
+
viteSsrDevServer.environments.ssr
|
|
149
|
+
);
|
|
150
|
+
globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
|
|
151
|
+
globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
|
|
152
|
+
const viteRscServer = await createViteServer({
|
|
153
|
+
envFile: false,
|
|
154
|
+
define: {
|
|
155
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
156
|
+
},
|
|
157
|
+
ssr: {
|
|
158
|
+
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
159
|
+
// inline dependencies in the server build. This gets round runtime
|
|
160
|
+
// importing of "server-only" and other packages with poisoned imports.
|
|
161
|
+
//
|
|
162
|
+
// Files included in `noExternal` are files we want Vite to analyze
|
|
163
|
+
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
164
|
+
noExternal: true,
|
|
165
|
+
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
166
|
+
// What are we missing here? When/why is that a better choice? I know
|
|
167
|
+
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
168
|
+
// we wanted to go that route.
|
|
169
|
+
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
170
|
+
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
171
|
+
// (css pre-init failure)
|
|
172
|
+
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
173
|
+
external: [
|
|
174
|
+
"@prisma/client",
|
|
175
|
+
"@prisma/adapter-better-sqlite3",
|
|
176
|
+
"@prisma/fetch-engine",
|
|
177
|
+
"@prisma/internals",
|
|
178
|
+
"better-sqlite3",
|
|
179
|
+
"@cedarjs/auth-dbauth-api",
|
|
180
|
+
"@cedarjs/cookie-jar",
|
|
181
|
+
"@cedarjs/server-store",
|
|
182
|
+
"@cedarjs/structure",
|
|
183
|
+
"@simplewebauthn/server",
|
|
184
|
+
"graphql-scalars",
|
|
185
|
+
"minimatch",
|
|
186
|
+
"playwright",
|
|
187
|
+
"react-dom"
|
|
188
|
+
],
|
|
189
|
+
resolve: {
|
|
190
|
+
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
191
|
+
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
192
|
+
// dependencies apart from node built-ins.
|
|
193
|
+
// TODO (RSC): What's the difference between `conditions` and
|
|
194
|
+
// `externalConditions`? When is one used over the other?
|
|
195
|
+
// In Vite 6, we must include `defaultServerConditions` alongside
|
|
196
|
+
// `react-server` so that nested condition maps (e.g. the `node`
|
|
197
|
+
// sub-condition inside `react-server-dom-webpack/server`'s exports)
|
|
198
|
+
// can still be resolved. Without `node` (or another environment
|
|
199
|
+
// condition), the resolver throws "No known conditions for
|
|
200
|
+
// './server' specifier in 'react-server-dom-webpack' package".
|
|
201
|
+
conditions: ["react-server", ...defaultServerConditions],
|
|
202
|
+
externalConditions: ["react-server", ...defaultServerConditions]
|
|
203
|
+
},
|
|
204
|
+
optimizeDeps: {
|
|
205
|
+
// We need Vite to optimize these dependencies so that they are resolved
|
|
206
|
+
// with the correct conditions. And so that CJS modules work correctly.
|
|
207
|
+
include: [
|
|
208
|
+
"react/**/*",
|
|
209
|
+
"react-dom/server",
|
|
210
|
+
"react-dom/server.edge",
|
|
211
|
+
"react-server-dom-webpack/server",
|
|
212
|
+
"react-server-dom-webpack/server.edge",
|
|
213
|
+
"react-server-dom-webpack/client",
|
|
214
|
+
"react-server-dom-webpack/client.edge",
|
|
215
|
+
"@apollo/client",
|
|
216
|
+
"@apollo/client/cache",
|
|
217
|
+
"@apollo/client/link/context",
|
|
218
|
+
"@apollo/client/link/persisted-queries",
|
|
219
|
+
"@apollo/client/react",
|
|
220
|
+
"@apollo/client/utilities",
|
|
221
|
+
"rxjs",
|
|
222
|
+
"react-fast-compare",
|
|
223
|
+
"invariant",
|
|
224
|
+
"shallowequal",
|
|
225
|
+
"graphql/language/*",
|
|
226
|
+
"stacktracey",
|
|
227
|
+
"deepmerge",
|
|
228
|
+
"fast-glob",
|
|
229
|
+
"@whatwg-node/fetch",
|
|
230
|
+
"busboy",
|
|
231
|
+
"cookie"
|
|
232
|
+
],
|
|
233
|
+
// Ensure `util` resolves to Node's built-in module and not to
|
|
234
|
+
// Browserify's `node-util` polyfill (which lacks TextEncoder).
|
|
235
|
+
// The polyfill may be hoisted into node_modules by optional
|
|
236
|
+
// dependencies like `@cedarjs/storybook`.
|
|
237
|
+
exclude: ["util"]
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
resolve: {
|
|
241
|
+
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
242
|
+
conditions: ["react-server", ...defaultServerConditions]
|
|
243
|
+
},
|
|
244
|
+
plugins: [
|
|
245
|
+
{
|
|
246
|
+
name: "rsc-record-and-tranform-use-client-plugin",
|
|
247
|
+
transform(code, id, _options) {
|
|
248
|
+
globalThis.__cedarjs__client_references?.delete(id);
|
|
249
|
+
if (!/^(["'])use client\1/.test(code)) {
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
console.log(
|
|
253
|
+
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
254
|
+
id
|
|
255
|
+
);
|
|
256
|
+
globalThis.__cedarjs__client_references?.add(id);
|
|
257
|
+
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
258
|
+
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
259
|
+
const names = [...fns, ...consts].map(([, name]) => name);
|
|
260
|
+
const result = [
|
|
261
|
+
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
262
|
+
"",
|
|
263
|
+
...names.map((name) => {
|
|
264
|
+
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
265
|
+
})
|
|
266
|
+
].join("\n");
|
|
267
|
+
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
268
|
+
console.log(
|
|
269
|
+
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
270
|
+
);
|
|
271
|
+
return { code: result, map: null };
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
rscTransformUseServerPlugin("", {}),
|
|
275
|
+
// The rscTransformUseClientPlugin maps paths like
|
|
276
|
+
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
277
|
+
// to
|
|
278
|
+
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
279
|
+
// That's why it needs the `clientEntryFiles` data
|
|
280
|
+
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
281
|
+
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
282
|
+
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
283
|
+
rscRoutesImports(),
|
|
284
|
+
{
|
|
285
|
+
name: "rsc-hot-update",
|
|
286
|
+
handleHotUpdate(ctx) {
|
|
287
|
+
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
],
|
|
292
|
+
build: {
|
|
293
|
+
ssr: true
|
|
294
|
+
},
|
|
295
|
+
server: {
|
|
296
|
+
// We never call `viteRscServer.listen()`, so we should run this in
|
|
297
|
+
// middleware mode
|
|
298
|
+
middlewareMode: true,
|
|
299
|
+
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
300
|
+
// the other Vite server. So we can either disable it or run it on a
|
|
301
|
+
// different port.
|
|
302
|
+
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
303
|
+
// port
|
|
304
|
+
ws: false
|
|
305
|
+
// hmr: {
|
|
306
|
+
// port: 24679,
|
|
307
|
+
// },
|
|
308
|
+
},
|
|
309
|
+
appType: "custom",
|
|
310
|
+
// Using a unique cache dir here to not clash with our other vite server
|
|
311
|
+
cacheDir: "../node_modules/.vite-rsc"
|
|
312
|
+
});
|
|
313
|
+
globalThis.__cedarjs__vite_rsc_runtime = createServerModuleRunner(
|
|
314
|
+
viteRscServer.environments.ssr
|
|
315
|
+
);
|
|
64
316
|
const handleWithMiddleware = (route) => {
|
|
65
317
|
return createServerAdapter(async (req) => {
|
|
66
|
-
const middlewareRouter = await createMiddlewareRouter(
|
|
318
|
+
const middlewareRouter = await createMiddlewareRouter(viteSsrDevServer);
|
|
67
319
|
const middleware = middlewareRouter.find(
|
|
68
320
|
req.method,
|
|
69
321
|
req.url
|
|
@@ -73,19 +325,22 @@ async function createServer() {
|
|
|
73
325
|
}
|
|
74
326
|
const [mwRes] = await invoke(req, middleware, {
|
|
75
327
|
route,
|
|
76
|
-
|
|
328
|
+
viteSsrDevServer
|
|
77
329
|
});
|
|
78
330
|
return mwRes.toResponse();
|
|
79
331
|
});
|
|
80
332
|
};
|
|
81
|
-
app.use(
|
|
333
|
+
app.use(viteSsrDevServer.middlewares);
|
|
82
334
|
if (rscEnabled) {
|
|
83
|
-
|
|
335
|
+
createWebSocketServer();
|
|
336
|
+
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
337
|
+
new URL("./rsc/rscRequestHandler.js", import.meta.url).pathname
|
|
338
|
+
);
|
|
84
339
|
app.use(
|
|
85
340
|
"/rw-rsc",
|
|
86
|
-
createRscRequestHandler({
|
|
87
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
88
|
-
|
|
341
|
+
await createRscRequestHandler({
|
|
342
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(viteSsrDevServer),
|
|
343
|
+
viteSsrDevServer
|
|
89
344
|
})
|
|
90
345
|
);
|
|
91
346
|
}
|
|
@@ -95,18 +350,22 @@ async function createServer() {
|
|
|
95
350
|
routes,
|
|
96
351
|
clientEntryPath: rwPaths.web.entryClient,
|
|
97
352
|
getStylesheetLinks: (route) => {
|
|
98
|
-
return getCssLinks({
|
|
353
|
+
return getCssLinks({
|
|
354
|
+
rwPaths,
|
|
355
|
+
route,
|
|
356
|
+
viteSsrDevServer
|
|
357
|
+
});
|
|
99
358
|
},
|
|
100
359
|
// Recreate middleware router on each request in dev
|
|
101
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
360
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(viteSsrDevServer)
|
|
102
361
|
},
|
|
103
|
-
|
|
362
|
+
viteSsrDevServer
|
|
104
363
|
);
|
|
105
|
-
app.get("*", createServerAdapter(routeHandler));
|
|
106
|
-
app.post("*", handleWithMiddleware());
|
|
364
|
+
app.get("/{*splat}", createServerAdapter(routeHandler));
|
|
365
|
+
app.post("/{*splat}", handleWithMiddleware());
|
|
107
366
|
const port = getConfig().web.port;
|
|
108
367
|
console.log(`Started server on http://localhost:${port}`);
|
|
109
|
-
return
|
|
368
|
+
return server.listen(port);
|
|
110
369
|
}
|
|
111
370
|
let devApp = createServer();
|
|
112
371
|
process.stdin.on("data", async (data) => {
|
|
@@ -121,11 +380,11 @@ process.stdin.on("data", async (data) => {
|
|
|
121
380
|
function getCssLinks({
|
|
122
381
|
rwPaths,
|
|
123
382
|
route,
|
|
124
|
-
|
|
383
|
+
viteSsrDevServer
|
|
125
384
|
}) {
|
|
126
385
|
const appAndRouteModules = componentsModules(
|
|
127
386
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
128
|
-
|
|
387
|
+
viteSsrDevServer
|
|
129
388
|
);
|
|
130
389
|
const collectedCss = collectCssPaths(appAndRouteModules);
|
|
131
390
|
const cssLinks = Array.from(collectedCss);
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-b
|
|
|
19
19
|
export { cedarjsResolveCedarStyleImportsPlugin } from './plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js';
|
|
20
20
|
export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-path-injector.js';
|
|
21
21
|
export { cedarMockCellDataPlugin } from './plugins/vite-plugin-cedar-mock-cell-data.js';
|
|
22
|
+
export { cedarParsedScalarsPlugin } from './plugins/vite-plugin-cedar-parsed-scalars.js';
|
|
22
23
|
export { cedarMergedConfig } from './plugins/vite-plugin-merged-config.js';
|
|
23
24
|
export { cedarSwapApolloProvider } from './plugins/vite-plugin-swap-apollo-provider.js';
|
|
24
25
|
export { cedarUniversalDeployPlugin } from './plugins/vite-plugin-cedar-universal-deploy.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,sBAAsB,CAAA;AACxD,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,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqCxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAA;AAC3F,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,uBAAuB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAA;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,EACL,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAA;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAC/F,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,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAA;AACxF,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;IACzB,KAAK,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;CACjC,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAgDzE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { cedarDataUriShim } from "./plugins/vite-plugin-cedar-data-uri-shim.js";
|
|
|
20
20
|
import { cedarEntryInjectionPlugin } from "./plugins/vite-plugin-cedar-entry-injection.js";
|
|
21
21
|
import { cedarHtmlEnvPlugin } from "./plugins/vite-plugin-cedar-html-env.js";
|
|
22
22
|
import { cedarMockCellDataPlugin } from "./plugins/vite-plugin-cedar-mock-cell-data.js";
|
|
23
|
+
import { cedarParsedScalarsPlugin } from "./plugins/vite-plugin-cedar-parsed-scalars.js";
|
|
23
24
|
import { cedarRemoveDevFatalErrorPage } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
|
|
24
25
|
import { cedarRemoveFromBundle } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
|
|
25
26
|
import { cedarRoutesAutoLoaderPlugin } from "./plugins/vite-plugin-cedar-routes-auto-loader.js";
|
|
@@ -49,6 +50,7 @@ import { cedarRemoveFromBundle as cedarRemoveFromBundle2 } from "./plugins/vite-
|
|
|
49
50
|
import { cedarjsResolveCedarStyleImportsPlugin as cedarjsResolveCedarStyleImportsPlugin2 } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
|
|
50
51
|
import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-path-injector.js";
|
|
51
52
|
import { cedarMockCellDataPlugin as cedarMockCellDataPlugin2 } from "./plugins/vite-plugin-cedar-mock-cell-data.js";
|
|
53
|
+
import { cedarParsedScalarsPlugin as cedarParsedScalarsPlugin2 } from "./plugins/vite-plugin-cedar-parsed-scalars.js";
|
|
52
54
|
import { cedarMergedConfig as cedarMergedConfig2 } from "./plugins/vite-plugin-merged-config.js";
|
|
53
55
|
import { cedarSwapApolloProvider as cedarSwapApolloProvider2 } from "./plugins/vite-plugin-swap-apollo-provider.js";
|
|
54
56
|
import { cedarUniversalDeployPlugin } from "./plugins/vite-plugin-cedar-universal-deploy.js";
|
|
@@ -79,6 +81,7 @@ function cedar({ mode, babel } = {}) {
|
|
|
79
81
|
cedarMergedConfig(),
|
|
80
82
|
cedarjsResolveCedarStyleImportsPlugin(),
|
|
81
83
|
cedarSwapApolloProvider(),
|
|
84
|
+
cedarParsedScalarsPlugin(),
|
|
82
85
|
cedarCellTransform(),
|
|
83
86
|
cedarRemoveFromBundle(),
|
|
84
87
|
cedarRemoveDevFatalErrorPage(),
|
|
@@ -107,6 +110,7 @@ export {
|
|
|
107
110
|
cedarMergedConfig2 as cedarMergedConfig,
|
|
108
111
|
cedarMockCellDataPlugin2 as cedarMockCellDataPlugin,
|
|
109
112
|
cedarOtelWrappingPlugin,
|
|
113
|
+
cedarParsedScalarsPlugin2 as cedarParsedScalarsPlugin,
|
|
110
114
|
cedarRemoveDevFatalErrorPage2 as cedarRemoveDevFatalErrorPage,
|
|
111
115
|
cedarRemoveFromBundle2 as cedarRemoveFromBundle,
|
|
112
116
|
cedarRoutesAutoLoaderPlugin2 as cedarRoutesAutoLoaderPlugin,
|
|
@@ -65,6 +65,15 @@ function registerFwShims() {
|
|
|
65
65
|
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
66
66
|
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
67
67
|
console.log("registerFwShims chunk load id", id);
|
|
68
|
+
if (globalThis.__cedarjs__vite_ssr_runtime) {
|
|
69
|
+
return globalThis.__cedarjs__vite_ssr_runtime?.import(id).then((mod) => {
|
|
70
|
+
console.log("registerFwShims chunk load mod", mod);
|
|
71
|
+
if (mod.default && typeof mod.default === "object") {
|
|
72
|
+
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
73
|
+
}
|
|
74
|
+
return globalThis.__rw_module_cache__.set(id, mod);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
68
77
|
return import(id).then((mod) => {
|
|
69
78
|
console.log("registerFwShims chunk load mod", mod);
|
|
70
79
|
if (mod.default && typeof mod.default === "object") {
|
|
@@ -16,7 +16,8 @@ import type { Plugin } from 'vite';
|
|
|
16
16
|
* export const QUERY = gql`...`
|
|
17
17
|
* export const Loading = () => <div>Loading...</div>
|
|
18
18
|
* export const Success = ({ data }) => <div>{data}</div>
|
|
19
|
-
*
|
|
19
|
+
* const MyCell = createCell({ QUERY, Loading, Success, displayName: 'MyCell' })
|
|
20
|
+
* export default MyCell
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
export declare function cedarCellTransform(): Plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-cell.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-cell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAqBlC
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-cell.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-cell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAqBlC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAsM3C"}
|
|
@@ -23,6 +23,7 @@ function cedarCellTransform() {
|
|
|
23
23
|
if (!id.match(/Cell\.[jt]sx?$/)) {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
+
const cellComponentName = parsePath(id).name;
|
|
26
27
|
try {
|
|
27
28
|
const ast = parse(code, {
|
|
28
29
|
sourceType: "module",
|
|
@@ -111,20 +112,38 @@ function cedarCellTransform() {
|
|
|
111
112
|
computed: false
|
|
112
113
|
}
|
|
113
114
|
];
|
|
115
|
+
const cellVariableDeclaration = {
|
|
116
|
+
type: "VariableDeclaration",
|
|
117
|
+
kind: "const",
|
|
118
|
+
declarations: [
|
|
119
|
+
{
|
|
120
|
+
type: "VariableDeclarator",
|
|
121
|
+
id: {
|
|
122
|
+
type: "Identifier",
|
|
123
|
+
name: cellComponentName
|
|
124
|
+
},
|
|
125
|
+
init: {
|
|
126
|
+
type: "CallExpression",
|
|
127
|
+
callee: {
|
|
128
|
+
type: "Identifier",
|
|
129
|
+
name: createCellHookName
|
|
130
|
+
},
|
|
131
|
+
arguments: [
|
|
132
|
+
{
|
|
133
|
+
type: "ObjectExpression",
|
|
134
|
+
properties: objectProperties
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
};
|
|
141
|
+
path.node.body.push(cellVariableDeclaration);
|
|
114
142
|
const exportDefaultDeclaration = {
|
|
115
143
|
type: "ExportDefaultDeclaration",
|
|
116
144
|
declaration: {
|
|
117
|
-
type: "
|
|
118
|
-
|
|
119
|
-
type: "Identifier",
|
|
120
|
-
name: createCellHookName
|
|
121
|
-
},
|
|
122
|
-
arguments: [
|
|
123
|
-
{
|
|
124
|
-
type: "ObjectExpression",
|
|
125
|
-
properties: objectProperties
|
|
126
|
-
}
|
|
127
|
-
]
|
|
145
|
+
type: "Identifier",
|
|
146
|
+
name: cellComponentName
|
|
128
147
|
}
|
|
129
148
|
};
|
|
130
149
|
path.node.body.push(exportDefaultDeclaration);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Gives `CedarApolloProvider` the cache config for the scalars in
|
|
4
|
+
* `graphql.parsedScalars` in `cedar.toml`. Does nothing when no scalar is set
|
|
5
|
+
* to be parsed.
|
|
6
|
+
*
|
|
7
|
+
* The config comes from the project's generated GraphQL schema, so it is built
|
|
8
|
+
* into the virtual module `virtual:cedar-parsed-scalars` rather than into the
|
|
9
|
+
* provider, which is a published package that Vite pre-bundles in dev. The
|
|
10
|
+
* module puts the config on `globalThis.__CEDAR__PARSED_SCALARS`, where the
|
|
11
|
+
* provider reads it when it creates the cache, and `App` and the web test
|
|
12
|
+
* setup file import the module so that every entry point that renders the
|
|
13
|
+
* provider has it. The module is a
|
|
14
|
+
* dependency of the generated schema file, so a change to the schema reloads
|
|
15
|
+
* the app. The generated schema is only read, and `graphql` and its schema
|
|
16
|
+
* loader only imported, when the virtual module is actually resolved, so a
|
|
17
|
+
* project that doesn't use this setting doesn't pay for loading them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function cedarParsedScalarsPlugin(): Plugin | undefined;
|
|
20
|
+
//# sourceMappingURL=vite-plugin-cedar-parsed-scalars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-parsed-scalars.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-parsed-scalars.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAclC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,GAAG,SAAS,CA4E7D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { normalizePath } from "vite";
|
|
2
|
+
import { getParsedScalars, getPaths } from "@cedarjs/project-config";
|
|
3
|
+
const VIRTUAL_MODULE_ID = "virtual:cedar-parsed-scalars";
|
|
4
|
+
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
5
|
+
const APP_FILE_REGEXP = /web[\\/]src[\\/]App\.(ts|tsx|js|jsx)$/;
|
|
6
|
+
const VITEST_WEB_SETUP_FILE_REGEXP = /[\\/]vitest-web\.setup\.(ts|js)$/;
|
|
7
|
+
function cedarParsedScalarsPlugin() {
|
|
8
|
+
if (Object.keys(getParsedScalars()).length === 0) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
name: "cedar-parsed-scalars",
|
|
13
|
+
resolveId(id) {
|
|
14
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
15
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
async load(id) {
|
|
20
|
+
if (id !== RESOLVED_VIRTUAL_MODULE_ID) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
this.addWatchFile(getPaths().generated.schema);
|
|
24
|
+
const { loadParsedScalarsCacheConfig } = await import("@cedarjs/internal/dist/generate/parsedScalars.js");
|
|
25
|
+
const config = loadParsedScalarsCacheConfig();
|
|
26
|
+
return `globalThis.__CEDAR__PARSED_SCALARS = ${JSON.stringify(config)}`;
|
|
27
|
+
},
|
|
28
|
+
transform(code, id) {
|
|
29
|
+
if (!APP_FILE_REGEXP.test(id) && !VITEST_WEB_SETUP_FILE_REGEXP.test(id)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return `import '${VIRTUAL_MODULE_ID}'
|
|
33
|
+
${code}`;
|
|
34
|
+
},
|
|
35
|
+
// `this.addWatchFile` in `load` only reruns the virtual module for a
|
|
36
|
+
// change to a file it has already watched. The schema doesn't exist yet
|
|
37
|
+
// on a clean `cedar dev` (the web server and `cedar-gen-watch` start
|
|
38
|
+
// concurrently), so its first appearance is a 'create' event on a path
|
|
39
|
+
// nothing has watched yet, and reaches here without an `addWatchFile`
|
|
40
|
+
// call ever having registered it. Reload the virtual module for exactly
|
|
41
|
+
// that file, on every event type, so the app picks up the first schema
|
|
42
|
+
// once `cedar-gen-watch` writes it, the same way it already does for a
|
|
43
|
+
// later edit.
|
|
44
|
+
hotUpdate(options) {
|
|
45
|
+
if (options.file !== normalizePath(getPaths().generated.schema)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const moduleGraph = this.environment.moduleGraph;
|
|
49
|
+
const module = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
50
|
+
if (!module) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
moduleGraph.invalidateModule(module);
|
|
54
|
+
return [module];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
cedarParsedScalarsPlugin
|
|
60
|
+
};
|
|
@@ -25,9 +25,7 @@ import type { Plugin } from 'vite';
|
|
|
25
25
|
* This replaces `babel-plugin-handler-als-wrapping` for Vite builds.
|
|
26
26
|
* The babel plugin is still used for Jest and prerender.
|
|
27
27
|
*/
|
|
28
|
-
export declare function handlerAlsWrappingPlugin(
|
|
29
|
-
projectIsEsm?: boolean;
|
|
30
|
-
}): Plugin;
|
|
28
|
+
export declare function handlerAlsWrappingPlugin(): Plugin;
|
|
31
29
|
/**
|
|
32
30
|
* Wraps the `handler` export of an API function file with an async context
|
|
33
31
|
* store guard. Returns the transformed code, or `null` if the file does not
|
|
@@ -38,7 +36,5 @@ export declare function handlerAlsWrappingPlugin({ projectIsEsm, }?: {
|
|
|
38
36
|
* function so it can be applied from build pipelines that don't go through
|
|
39
37
|
* Vite's plugin pipeline (e.g. the legacy esbuild API build).
|
|
40
38
|
*/
|
|
41
|
-
export declare function applyHandlerAlsWrapping(code: string
|
|
42
|
-
projectIsEsm?: boolean;
|
|
43
|
-
}): string | null;
|
|
39
|
+
export declare function applyHandlerAlsWrapping(code: string): string | null;
|
|
44
40
|
//# sourceMappingURL=vite-plugin-handler-als-wrapping.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"vite-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAuBjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkDnE"}
|