@cedarjs/vite 5.0.0 → 6.0.0-canary.2615
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apiDevMiddleware.d.ts.map +1 -1
- package/dist/apiDevMiddleware.js +8 -1
- package/dist/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +6 -2
- package/dist/bundled/react-server-dom-webpack.server.js +1224 -28521
- package/dist/cjs/apiDevMiddleware.js +8 -1
- package/dist/cjs/buildApp.js +6 -2
- package/dist/cjs/devFeServer.js +268 -15
- package/dist/cjs/index.js +19 -13
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +9 -0
- package/dist/cjs/plugins/vite-plugin-cedar-data-uri-shim.js +67 -0
- package/dist/cjs/plugins/vite-plugin-cedar-gqlorm-inject.js +106 -0
- package/dist/cjs/plugins/vite-plugin-cedar-graphql-options-extract.js +113 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
- package/dist/cjs/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +11 -11
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +4 -0
- package/dist/cjs/rsc/rscRenderer.js +23 -9
- package/dist/cjs/rsc/rscRequestHandler.js +6 -6
- package/dist/cjs/rsc/rscWebSocketServer.js +56 -0
- package/dist/cjs/rsc/utils.js +56 -0
- package/dist/cjs/runFeServer.js +3 -22
- package/dist/cjs/streaming/createReactStreamingHandler.js +13 -10
- package/dist/cjs/streaming/streamHelpers.js +49 -32
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +272 -16
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -9
- package/dist/lib/registerFwGlobalsAndShims.js +9 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +38 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +88 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
- package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +5 -5
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
- package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +6 -6
- 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 +2 -21
- 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 +2 -2
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +49 -31
- 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 -19
- package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
- package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
|
@@ -44,8 +44,10 @@ var import_runtime = require("@cedarjs/api/runtime");
|
|
|
44
44
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
45
45
|
var import_store = require("@cedarjs/context/dist/store");
|
|
46
46
|
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
47
|
+
var import_api_graphql_transforms = require("@cedarjs/internal/dist/build/api-graphql-transforms.js");
|
|
47
48
|
var import_project_config = require("@cedarjs/project-config");
|
|
48
49
|
var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
|
|
50
|
+
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
49
51
|
const LAMBDA_FUNCTIONS = {};
|
|
50
52
|
let graphqlYoga = null;
|
|
51
53
|
let loadApiFunctionsInFlight = null;
|
|
@@ -188,8 +190,13 @@ async function createApiViteServer() {
|
|
|
188
190
|
return null;
|
|
189
191
|
}
|
|
190
192
|
try {
|
|
193
|
+
let sourceCode = code;
|
|
194
|
+
if ((0, import_vite.normalizePath)(id).endsWith("/graphql.ts") || (0, import_vite.normalizePath)(id).endsWith("/graphql.js")) {
|
|
195
|
+
sourceCode = (0, import_vite_plugin_cedar_graphql_options_extract.applyGraphqlOptionsExtract)(sourceCode) ?? sourceCode;
|
|
196
|
+
sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
|
|
197
|
+
}
|
|
191
198
|
const result = await (0, import_babel_config.transformWithBabel)(
|
|
192
|
-
|
|
199
|
+
sourceCode,
|
|
193
200
|
id,
|
|
194
201
|
babelPlugins,
|
|
195
202
|
true
|
package/dist/cjs/buildApp.js
CHANGED
|
@@ -40,7 +40,9 @@ var import_babel_config = require("@cedarjs/babel-config");
|
|
|
40
40
|
var import_files = require("@cedarjs/internal/dist/files.js");
|
|
41
41
|
var import_project_config = require("@cedarjs/project-config");
|
|
42
42
|
var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
|
|
43
|
-
var
|
|
43
|
+
var import_vite_plugin_cedar_gqlorm_inject = require("./plugins/vite-plugin-cedar-gqlorm-inject.js");
|
|
44
|
+
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
45
|
+
var import_vite_plugin_handler_als_wrapping = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
44
46
|
function resolveWithExtensions(id) {
|
|
45
47
|
if (import_node_fs.default.existsSync(id)) {
|
|
46
48
|
return id;
|
|
@@ -254,8 +256,10 @@ async function buildCedarApp({
|
|
|
254
256
|
});
|
|
255
257
|
}
|
|
256
258
|
if (workspace.includes("api")) {
|
|
259
|
+
plugins.push((0, import_vite_plugin_cedar_graphql_options_extract.cedarGraphqlOptionsExtractPlugin)());
|
|
260
|
+
plugins.push((0, import_vite_plugin_cedar_gqlorm_inject.cedarGqlormInjectPlugin)());
|
|
257
261
|
plugins.push(
|
|
258
|
-
(0,
|
|
262
|
+
(0, import_vite_plugin_handler_als_wrapping.handlerAlsWrappingPlugin)({ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api") })
|
|
259
263
|
);
|
|
260
264
|
}
|
|
261
265
|
if (babelPlugins) {
|
package/dist/cjs/devFeServer.js
CHANGED
|
@@ -22,6 +22,7 @@ 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);
|
|
25
26
|
var import_server = require("@whatwg-node/server");
|
|
26
27
|
var import_express = __toESM(require("express"), 1);
|
|
27
28
|
var import_vite = require("vite");
|
|
@@ -33,14 +34,22 @@ var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.
|
|
|
33
34
|
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
34
35
|
var import_register = require("./middleware/register.js");
|
|
35
36
|
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");
|
|
36
41
|
var import_collectCss = require("./streaming/collectCss.js");
|
|
37
42
|
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
38
43
|
var import_utils = require("./utils.js");
|
|
44
|
+
const import_meta = {};
|
|
39
45
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
46
|
+
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
47
|
+
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
40
48
|
async function createServer() {
|
|
41
49
|
(0, import_utils.ensureProcessDirWeb)();
|
|
42
50
|
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
43
51
|
const app = (0, import_express.default)();
|
|
52
|
+
const server = import_node_http.default.createServer(app);
|
|
44
53
|
const rwPaths = (0, import_project_config.getPaths)();
|
|
45
54
|
const rscEnabled = (0, import_project_config.getConfig)().experimental.rsc?.enabled ?? false;
|
|
46
55
|
const serverStorage = (0, import_server_store.createServerStorage)();
|
|
@@ -63,8 +72,78 @@ async function createServer() {
|
|
|
63
72
|
"Vite config not found. Please set up Vite before running the dev server."
|
|
64
73
|
);
|
|
65
74
|
}
|
|
66
|
-
const
|
|
75
|
+
const viteSsrDevServer = await (0, import_vite.createServer)({
|
|
67
76
|
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
|
+
},
|
|
68
147
|
plugins: [
|
|
69
148
|
(0, import_vite_plugin_cjs_interop.cjsInterop)({
|
|
70
149
|
dependencies: [
|
|
@@ -78,16 +157,183 @@ async function createServer() {
|
|
|
78
157
|
"@cedarjs/auth-!(dbauth)-web"
|
|
79
158
|
]
|
|
80
159
|
}),
|
|
81
|
-
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
|
|
160
|
+
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)(),
|
|
161
|
+
rscEnabled && (0, import_vite_plugin_rsc_ssr_router_import.rscSsrRouterImport)()
|
|
82
162
|
],
|
|
83
163
|
server: { middlewareMode: true },
|
|
84
164
|
logLevel: "info",
|
|
85
165
|
clearScreen: false,
|
|
86
166
|
appType: "custom"
|
|
87
167
|
});
|
|
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
|
+
// Ensure `util` resolves to Node's built-in module and not to
|
|
252
|
+
// Browserify's `node-util` polyfill (which lacks TextEncoder).
|
|
253
|
+
// The polyfill may be hoisted into node_modules by optional
|
|
254
|
+
// dependencies like `@cedarjs/storybook`.
|
|
255
|
+
exclude: ["util"]
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
resolve: {
|
|
259
|
+
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
260
|
+
conditions: ["react-server", ...import_vite.defaultServerConditions]
|
|
261
|
+
},
|
|
262
|
+
plugins: [
|
|
263
|
+
{
|
|
264
|
+
name: "rsc-record-and-tranform-use-client-plugin",
|
|
265
|
+
transform(code, id, _options) {
|
|
266
|
+
globalThis.__cedarjs__client_references?.delete(id);
|
|
267
|
+
if (!/^(["'])use client\1/.test(code)) {
|
|
268
|
+
return void 0;
|
|
269
|
+
}
|
|
270
|
+
console.log(
|
|
271
|
+
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
272
|
+
id
|
|
273
|
+
);
|
|
274
|
+
globalThis.__cedarjs__client_references?.add(id);
|
|
275
|
+
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
276
|
+
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
277
|
+
const names = [...fns, ...consts].map(([, name]) => name);
|
|
278
|
+
const result = [
|
|
279
|
+
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
280
|
+
"",
|
|
281
|
+
...names.map((name) => {
|
|
282
|
+
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
283
|
+
})
|
|
284
|
+
].join("\n");
|
|
285
|
+
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
286
|
+
console.log(
|
|
287
|
+
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
288
|
+
);
|
|
289
|
+
return { code: result, map: null };
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
(0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
|
|
293
|
+
// The rscTransformUseClientPlugin maps paths like
|
|
294
|
+
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
295
|
+
// to
|
|
296
|
+
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
297
|
+
// That's why it needs the `clientEntryFiles` data
|
|
298
|
+
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
299
|
+
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
300
|
+
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
301
|
+
(0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
|
|
302
|
+
{
|
|
303
|
+
name: "rsc-hot-update",
|
|
304
|
+
handleHotUpdate(ctx) {
|
|
305
|
+
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
build: {
|
|
311
|
+
ssr: true
|
|
312
|
+
},
|
|
313
|
+
server: {
|
|
314
|
+
// We never call `viteRscServer.listen()`, so we should run this in
|
|
315
|
+
// middleware mode
|
|
316
|
+
middlewareMode: true,
|
|
317
|
+
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
318
|
+
// the other Vite server. So we can either disable it or run it on a
|
|
319
|
+
// different port.
|
|
320
|
+
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
321
|
+
// port
|
|
322
|
+
ws: false
|
|
323
|
+
// hmr: {
|
|
324
|
+
// port: 24679,
|
|
325
|
+
// },
|
|
326
|
+
},
|
|
327
|
+
appType: "custom",
|
|
328
|
+
// Using a unique cache dir here to not clash with our other vite server
|
|
329
|
+
cacheDir: "../node_modules/.vite-rsc"
|
|
330
|
+
});
|
|
331
|
+
globalThis.__cedarjs__vite_rsc_runtime = (0, import_vite.createServerModuleRunner)(
|
|
332
|
+
viteRscServer.environments.ssr
|
|
333
|
+
);
|
|
88
334
|
const handleWithMiddleware = (route) => {
|
|
89
335
|
return (0, import_server.createServerAdapter)(async (req) => {
|
|
90
|
-
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(
|
|
336
|
+
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(viteSsrDevServer);
|
|
91
337
|
const middleware = middlewareRouter.find(
|
|
92
338
|
req.method,
|
|
93
339
|
req.url
|
|
@@ -97,19 +343,22 @@ async function createServer() {
|
|
|
97
343
|
}
|
|
98
344
|
const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
|
|
99
345
|
route,
|
|
100
|
-
|
|
346
|
+
viteSsrDevServer
|
|
101
347
|
});
|
|
102
348
|
return mwRes.toResponse();
|
|
103
349
|
});
|
|
104
350
|
};
|
|
105
|
-
app.use(
|
|
351
|
+
app.use(viteSsrDevServer.middlewares);
|
|
106
352
|
if (rscEnabled) {
|
|
107
|
-
|
|
353
|
+
(0, import_rscWebSocketServer.createWebSocketServer)();
|
|
354
|
+
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
355
|
+
new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
|
|
356
|
+
);
|
|
108
357
|
app.use(
|
|
109
358
|
"/rw-rsc",
|
|
110
|
-
createRscRequestHandler({
|
|
111
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
112
|
-
|
|
359
|
+
await createRscRequestHandler({
|
|
360
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer),
|
|
361
|
+
viteSsrDevServer
|
|
113
362
|
})
|
|
114
363
|
);
|
|
115
364
|
}
|
|
@@ -119,18 +368,22 @@ async function createServer() {
|
|
|
119
368
|
routes,
|
|
120
369
|
clientEntryPath: rwPaths.web.entryClient,
|
|
121
370
|
getStylesheetLinks: (route) => {
|
|
122
|
-
return getCssLinks({
|
|
371
|
+
return getCssLinks({
|
|
372
|
+
rwPaths,
|
|
373
|
+
route,
|
|
374
|
+
viteSsrDevServer
|
|
375
|
+
});
|
|
123
376
|
},
|
|
124
377
|
// Recreate middleware router on each request in dev
|
|
125
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
378
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer)
|
|
126
379
|
},
|
|
127
|
-
|
|
380
|
+
viteSsrDevServer
|
|
128
381
|
);
|
|
129
382
|
app.get("*", (0, import_server.createServerAdapter)(routeHandler));
|
|
130
383
|
app.post("*", handleWithMiddleware());
|
|
131
384
|
const port = (0, import_project_config.getConfig)().web.port;
|
|
132
385
|
console.log(`Started server on http://localhost:${port}`);
|
|
133
|
-
return
|
|
386
|
+
return server.listen(port);
|
|
134
387
|
}
|
|
135
388
|
let devApp = createServer();
|
|
136
389
|
process.stdin.on("data", async (data) => {
|
|
@@ -145,11 +398,11 @@ process.stdin.on("data", async (data) => {
|
|
|
145
398
|
function getCssLinks({
|
|
146
399
|
rwPaths,
|
|
147
400
|
route,
|
|
148
|
-
|
|
401
|
+
viteSsrDevServer
|
|
149
402
|
}) {
|
|
150
403
|
const appAndRouteModules = (0, import_collectCss.componentsModules)(
|
|
151
404
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
152
|
-
|
|
405
|
+
viteSsrDevServer
|
|
153
406
|
);
|
|
154
407
|
const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
|
|
155
408
|
const cssLinks = Array.from(collectedCss);
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,17 +28,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var index_exports = {};
|
|
30
30
|
__export(index_exports, {
|
|
31
|
-
|
|
31
|
+
applyHandlerAlsWrapping: () => import_vite_plugin_handler_als_wrapping2.applyHandlerAlsWrapping,
|
|
32
32
|
cedar: () => cedar,
|
|
33
33
|
cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
|
|
34
34
|
cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
|
|
35
35
|
cedarCjsCompatPlugin: () => import_vite_plugin_cedar_cjs_compat.cedarCjsCompatPlugin,
|
|
36
|
-
|
|
36
|
+
cedarDataUriShim: () => import_vite_plugin_cedar_data_uri_shim2.cedarDataUriShim,
|
|
37
37
|
cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
|
|
38
|
+
cedarGqlormInjectPlugin: () => import_vite_plugin_cedar_gqlorm_inject.cedarGqlormInjectPlugin,
|
|
39
|
+
cedarGraphqlOptionsExtractPlugin: () => import_vite_plugin_cedar_graphql_options_extract.cedarGraphqlOptionsExtractPlugin,
|
|
38
40
|
cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
|
|
39
41
|
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
40
42
|
cedarMergedConfig: () => import_vite_plugin_merged_config2.cedarMergedConfig,
|
|
41
|
-
cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
|
|
42
43
|
cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
|
|
43
44
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
44
45
|
cedarRoutesAutoLoaderPlugin: () => import_vite_plugin_cedar_routes_auto_loader2.cedarRoutesAutoLoaderPlugin,
|
|
@@ -48,7 +49,8 @@ __export(index_exports, {
|
|
|
48
49
|
cedarWaitForApiServer: () => import_vite_plugin_cedar_wait_for_api_server2.cedarWaitForApiServer,
|
|
49
50
|
cedarjsJobPathInjectorPlugin: () => import_vite_plugin_cedarjs_job_path_injector.cedarjsJobPathInjectorPlugin,
|
|
50
51
|
cedarjsResolveCedarStyleImportsPlugin: () => import_vite_plugin_cedarjs_resolve_cedar_style_imports2.cedarjsResolveCedarStyleImportsPlugin,
|
|
51
|
-
default: () => index_default
|
|
52
|
+
default: () => index_default,
|
|
53
|
+
handlerAlsWrappingPlugin: () => import_vite_plugin_handler_als_wrapping.handlerAlsWrappingPlugin
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(index_exports);
|
|
54
56
|
var import_plugin_react = __toESM(require("@vitejs/plugin-react"), 1);
|
|
@@ -56,9 +58,9 @@ var import_babel_config = require("@cedarjs/babel-config");
|
|
|
56
58
|
var import_project_config = require("@cedarjs/project-config");
|
|
57
59
|
var import_vitest = require("@cedarjs/testing/web/vitest");
|
|
58
60
|
var import_vite_plugin_cedar_cell = require("./plugins/vite-plugin-cedar-cell.js");
|
|
61
|
+
var import_vite_plugin_cedar_data_uri_shim = require("./plugins/vite-plugin-cedar-data-uri-shim.js");
|
|
59
62
|
var import_vite_plugin_cedar_entry_injection = require("./plugins/vite-plugin-cedar-entry-injection.js");
|
|
60
63
|
var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
61
|
-
var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
62
64
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
63
65
|
var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
64
66
|
var import_vite_plugin_cedar_routes_auto_loader = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
@@ -70,12 +72,14 @@ var import_vite_plugin_swap_apollo_provider = require("./plugins/vite-plugin-swa
|
|
|
70
72
|
var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
|
|
71
73
|
var import_vite_plugin_cedar_cjs_compat = require("./plugins/vite-plugin-cedar-cjs-compat.js");
|
|
72
74
|
var import_vite_plugin_cedar_cell2 = require("./plugins/vite-plugin-cedar-cell.js");
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
+
var import_vite_plugin_cedar_gqlorm_inject = require("./plugins/vite-plugin-cedar-gqlorm-inject.js");
|
|
76
|
+
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
77
|
+
var import_vite_plugin_handler_als_wrapping = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
78
|
+
var import_vite_plugin_handler_als_wrapping2 = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
75
79
|
var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-cedar-entry-injection.js");
|
|
76
80
|
var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
77
81
|
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
78
|
-
var
|
|
82
|
+
var import_vite_plugin_cedar_data_uri_shim2 = require("./plugins/vite-plugin-cedar-data-uri-shim.js");
|
|
79
83
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page2 = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
80
84
|
var import_vite_plugin_cedar_routes_auto_loader2 = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
81
85
|
var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
@@ -100,7 +104,7 @@ function cedar({ mode } = {}) {
|
|
|
100
104
|
mode === "test" && (0, import_vitest.createAuthImportTransformPlugin)(),
|
|
101
105
|
mode === "test" && (0, import_vitest.autoImportsPlugin)(),
|
|
102
106
|
(0, import_vite_plugin_cedar_wait_for_api_server.cedarWaitForApiServer)(),
|
|
103
|
-
(0,
|
|
107
|
+
(0, import_vite_plugin_cedar_data_uri_shim.cedarDataUriShim)(),
|
|
104
108
|
(0, import_vite_plugin_cedar_html_env.cedarHtmlEnvPlugin)(),
|
|
105
109
|
(0, import_vite_plugin_cedar_entry_injection.cedarEntryInjectionPlugin)(),
|
|
106
110
|
(0, import_vite_plugin_merged_config.cedarMergedConfig)(),
|
|
@@ -118,17 +122,18 @@ function cedar({ mode } = {}) {
|
|
|
118
122
|
var index_default = cedar;
|
|
119
123
|
// Annotate the CommonJS export names for ESM import in node:
|
|
120
124
|
0 && (module.exports = {
|
|
121
|
-
|
|
125
|
+
applyHandlerAlsWrapping,
|
|
122
126
|
cedar,
|
|
123
127
|
cedarAutoImportsPlugin,
|
|
124
128
|
cedarCellTransform,
|
|
125
129
|
cedarCjsCompatPlugin,
|
|
126
|
-
|
|
130
|
+
cedarDataUriShim,
|
|
127
131
|
cedarEntryInjectionPlugin,
|
|
132
|
+
cedarGqlormInjectPlugin,
|
|
133
|
+
cedarGraphqlOptionsExtractPlugin,
|
|
128
134
|
cedarHtmlEnvPlugin,
|
|
129
135
|
cedarImportDirPlugin,
|
|
130
136
|
cedarMergedConfig,
|
|
131
|
-
cedarNodePolyfills,
|
|
132
137
|
cedarRemoveDevFatalErrorPage,
|
|
133
138
|
cedarRemoveFromBundle,
|
|
134
139
|
cedarRoutesAutoLoaderPlugin,
|
|
@@ -137,5 +142,6 @@ var index_default = cedar;
|
|
|
137
142
|
cedarUniversalDeployPlugin,
|
|
138
143
|
cedarWaitForApiServer,
|
|
139
144
|
cedarjsJobPathInjectorPlugin,
|
|
140
|
-
cedarjsResolveCedarStyleImportsPlugin
|
|
145
|
+
cedarjsResolveCedarStyleImportsPlugin,
|
|
146
|
+
handlerAlsWrappingPlugin
|
|
141
147
|
});
|
|
@@ -79,6 +79,15 @@ 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
|
+
}
|
|
82
91
|
return import(id).then((mod) => {
|
|
83
92
|
console.log("registerFwShims chunk load mod", mod);
|
|
84
93
|
if (mod.default && typeof mod.default === "object") {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var vite_plugin_cedar_data_uri_shim_exports = {};
|
|
20
|
+
__export(vite_plugin_cedar_data_uri_shim_exports, {
|
|
21
|
+
cedarDataUriShim: () => cedarDataUriShim
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(vite_plugin_cedar_data_uri_shim_exports);
|
|
24
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
25
|
+
function dataUriToBuffer(uri) {
|
|
26
|
+
const match = uri.match(/^data:(.*?)(;(.*?))?(,(.*))$/);
|
|
27
|
+
if (!match) {
|
|
28
|
+
throw new Error("Invalid data URI");
|
|
29
|
+
}
|
|
30
|
+
const mediaType = match[1] || "text/plain";
|
|
31
|
+
const params = match[3] || "";
|
|
32
|
+
const data = match[5];
|
|
33
|
+
const [type] = mediaType.split(";");
|
|
34
|
+
const typeFull = params ? mediaType + ";" + params : mediaType;
|
|
35
|
+
const lowerParams = params.toLowerCase();
|
|
36
|
+
const isBase64 = lowerParams.includes("base64");
|
|
37
|
+
const charset = lowerParams.startsWith("charset=") ? lowerParams.slice(8) : "";
|
|
38
|
+
const bytes = isBase64 ? Uint8Array.from(atob(data), (c) => c.charCodeAt(0)) : new TextEncoder().encode(decodeURIComponent(data));
|
|
39
|
+
const decoder = new TextDecoder();
|
|
40
|
+
bytes.toString = () => decoder.decode(bytes);
|
|
41
|
+
return Object.assign(bytes, { type, typeFull, charset });
|
|
42
|
+
}
|
|
43
|
+
function cedarDataUriShim() {
|
|
44
|
+
if ((0, import_project_config.getConfig)().experimental?.rsc?.enabled) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
name: "cedar-data-uri-shim",
|
|
49
|
+
apply: "serve",
|
|
50
|
+
resolveId(id) {
|
|
51
|
+
if (id === "data-uri-to-buffer") {
|
|
52
|
+
return "\0cedar-data-uri-to-buffer";
|
|
53
|
+
}
|
|
54
|
+
return void 0;
|
|
55
|
+
},
|
|
56
|
+
load(id) {
|
|
57
|
+
if (id === "\0cedar-data-uri-to-buffer") {
|
|
58
|
+
return "export default " + dataUriToBuffer.toString();
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
cedarDataUriShim
|
|
67
|
+
});
|