@cedarjs/vite 5.0.0-canary.2596 → 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.
Files changed (53) hide show
  1. package/dist/bundled/react-server-dom-webpack.server.js +28528 -1231
  2. package/dist/cjs/devFeServer.js +15 -280
  3. package/dist/cjs/index.js +8 -7
  4. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -9
  5. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  6. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -4
  7. package/dist/cjs/rsc/rscRenderer.js +9 -23
  8. package/dist/cjs/rsc/rscRequestHandler.js +6 -6
  9. package/dist/cjs/runFeServer.js +22 -3
  10. package/dist/cjs/streaming/createReactStreamingHandler.js +10 -13
  11. package/dist/cjs/streaming/streamHelpers.js +32 -49
  12. package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
  13. package/dist/devFeServer.js +16 -284
  14. package/dist/index.d.ts +0 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -6
  17. package/dist/lib/registerFwGlobalsAndShims.js +0 -9
  18. package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
  19. package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  20. package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
  21. package/dist/plugins/vite-plugin-rsc-transform-server.js +0 -4
  22. package/dist/rsc/rscRenderer.d.ts.map +1 -1
  23. package/dist/rsc/rscRenderer.js +5 -19
  24. package/dist/rsc/rscRequestHandler.d.ts +2 -2
  25. package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
  26. package/dist/rsc/rscRequestHandler.js +4 -4
  27. package/dist/runFeServer.js +21 -2
  28. package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
  29. package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
  30. package/dist/streaming/createReactStreamingHandler.js +10 -13
  31. package/dist/streaming/streamHelpers.d.ts +2 -2
  32. package/dist/streaming/streamHelpers.d.ts.map +1 -1
  33. package/dist/streaming/streamHelpers.js +31 -49
  34. package/dist/streaming/triggerRouteHooks.d.ts +2 -2
  35. package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
  36. package/dist/streaming/triggerRouteHooks.js +3 -3
  37. package/package.json +18 -18
  38. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +0 -92
  39. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
  40. package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
  41. package/dist/cjs/rsc/utils.js +0 -56
  42. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts +0 -31
  43. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  44. package/dist/plugins/vite-plugin-cedar-context-wrapping.js +0 -58
  45. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +0 -24
  46. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +0 -1
  47. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -98
  48. package/dist/rsc/rscWebSocketServer.d.ts +0 -2
  49. package/dist/rsc/rscWebSocketServer.d.ts.map +0 -1
  50. package/dist/rsc/rscWebSocketServer.js +0 -22
  51. package/dist/rsc/utils.d.ts +0 -10
  52. package/dist/rsc/utils.d.ts.map +0 -1
  53. package/dist/rsc/utils.js +0 -21
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var vite_plugin_cedar_context_wrapping_exports = {};
30
- __export(vite_plugin_cedar_context_wrapping_exports, {
31
- cedarContextWrappingPlugin: () => cedarContextWrappingPlugin
32
- });
33
- module.exports = __toCommonJS(vite_plugin_cedar_context_wrapping_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var import_vite = require("vite");
36
- var import_project_config = require("@cedarjs/project-config");
37
- function cedarContextWrappingPlugin({
38
- projectIsEsm = false
39
- } = {}) {
40
- const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
41
- return {
42
- name: "cedar-context-wrapping",
43
- transform(code, id) {
44
- let paths;
45
- try {
46
- paths = (0, import_project_config.getPaths)();
47
- } catch {
48
- return null;
49
- }
50
- const functionsDir = (0, import_vite.normalizePath)(import_node_path.default.join(paths.api.src, "functions"));
51
- if (!(0, import_vite.normalizePath)(id).startsWith(functionsDir + "/")) {
52
- return null;
53
- }
54
- const handlerMatch = handlerRe.exec(code);
55
- if (!handlerMatch) {
56
- return null;
57
- }
58
- const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
59
- const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
60
- const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
61
- const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
62
- `;
63
- const handlerStart = handlerMatch.index;
64
- const before = code.slice(0, handlerStart);
65
- const after = code.slice(handlerStart);
66
- const renamed = after.replace(handlerRe, "const __rw_handler =");
67
- const wrappedHandler = `
68
- export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
69
- // The store will be undefined if no context isolation has been performed yet
70
- const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
71
- if (__rw_contextStore === undefined) {
72
- return __rw_getAsyncStoreInstance().run(
73
- new Map(),
74
- __rw_handler,
75
- __rw_event,
76
- __rw__context
77
- )
78
- }
79
- return __rw_handler(__rw_event, __rw__context)
80
- }
81
- `;
82
- return {
83
- code: before + importStatement + renamed + wrappedHandler,
84
- map: null
85
- };
86
- }
87
- };
88
- }
89
- // Annotate the CommonJS export names for ESM import in node:
90
- 0 && (module.exports = {
91
- cedarContextWrappingPlugin
92
- });
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var vite_plugin_cedar_routes_auto_loader_exports = {};
30
- __export(vite_plugin_cedar_routes_auto_loader_exports, {
31
- cedarRoutesAutoLoaderPlugin: () => cedarRoutesAutoLoaderPlugin
32
- });
33
- module.exports = __toCommonJS(vite_plugin_cedar_routes_auto_loader_exports);
34
- var import_node_fs = __toESM(require("node:fs"), 1);
35
- var import_node_path = __toESM(require("node:path"), 1);
36
- var import_vite = require("vite");
37
- var import_project_config = require("@cedarjs/project-config");
38
- function getPathRelativeToSrc(maybeAbsolutePath) {
39
- const withoutExt = maybeAbsolutePath.replace(/\.[^/.]+$/, "");
40
- if (withoutExt.startsWith("src/")) {
41
- const basePath = import_node_path.default.join((0, import_project_config.getPaths)().web.base, withoutExt);
42
- const resolved = (0, import_project_config.resolveFile)(basePath) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, "index")) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, import_node_path.default.basename(basePath)));
43
- if (resolved) {
44
- const resolvedWithoutExt = resolved.replace(/\.[^/.]+$/, "");
45
- return "./" + import_node_path.default.relative((0, import_project_config.getPaths)().web.src, resolvedWithoutExt);
46
- }
47
- return "./" + withoutExt.slice("src/".length);
48
- }
49
- if (!import_node_path.default.isAbsolute(withoutExt)) {
50
- return withoutExt;
51
- }
52
- return `./${import_node_path.default.relative((0, import_project_config.getPaths)().web.src, withoutExt)}`;
53
- }
54
- function withRelativeImports(page) {
55
- return {
56
- ...page,
57
- relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
58
- };
59
- }
60
- function cedarRoutesAutoLoaderPlugin() {
61
- const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
62
- const initialPages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
63
- const duplicatePageImportNames = /* @__PURE__ */ new Set();
64
- const sortedPageImportNames = initialPages.map((page) => page.importName).sort();
65
- for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
66
- if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
67
- duplicatePageImportNames.add(sortedPageImportNames[i]);
68
- }
69
- }
70
- if (duplicatePageImportNames.size > 0) {
71
- const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
72
- throw new Error(
73
- `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
74
- );
75
- }
76
- return {
77
- name: "cedar-routes-auto-loader",
78
- transform(code, id) {
79
- if ((0, import_vite.normalizePath)(id) !== routesFileId) {
80
- return null;
81
- }
82
- let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
83
- const importRe = /^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm;
84
- const appPath = (0, import_project_config.resolveFile)(import_node_path.default.join((0, import_project_config.getPaths)().web.src, "App"));
85
- if (appPath) {
86
- const appSource = import_node_fs.default.readFileSync(appPath, "utf8");
87
- let appMatch;
88
- while ((appMatch = importRe.exec(appSource)) !== null) {
89
- const rel = (0, import_project_config.ensurePosixPath)(
90
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(appMatch[1]))
91
- );
92
- pages = pages.filter((page) => page.relativeImport !== rel);
93
- }
94
- }
95
- importRe.lastIndex = 0;
96
- let routesMatch;
97
- while ((routesMatch = importRe.exec(code)) !== null) {
98
- const rel = (0, import_project_config.ensurePosixPath)(
99
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(routesMatch[1]))
100
- );
101
- pages = pages.filter((page) => page.relativeImport !== rel);
102
- }
103
- if (pages.length === 0) {
104
- return null;
105
- }
106
- const lines = [`import { lazy } from 'react'`];
107
- for (const { importName, relativeImport } of pages) {
108
- lines.push(
109
- `const ${importName} = {`,
110
- ` name: "${importName}",`,
111
- ` prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),`,
112
- ` LazyComponent: lazy(() => import("${relativeImport}")),`,
113
- `}`
114
- );
115
- }
116
- return {
117
- code: lines.join("\n") + "\n\n" + code,
118
- map: null
119
- };
120
- }
121
- };
122
- }
123
- // Annotate the CommonJS export names for ESM import in node:
124
- 0 && (module.exports = {
125
- cedarRoutesAutoLoaderPlugin
126
- });
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var rscWebSocketServer_exports = {};
30
- __export(rscWebSocketServer_exports, {
31
- createWebSocketServer: () => createWebSocketServer
32
- });
33
- module.exports = __toCommonJS(rscWebSocketServer_exports);
34
- var import_ws = __toESM(require("ws"), 1);
35
- function createWebSocketServer() {
36
- const wsServer = new import_ws.WebSocketServer({ port: 18998 });
37
- wsServer.on("connection", (ws) => {
38
- console.log("A new client connected.");
39
- ws.on("message", (data) => {
40
- const message = data.toString();
41
- console.log("Received message:", message);
42
- wsServer.clients.forEach((client) => {
43
- if (client.readyState === import_ws.default.OPEN) {
44
- client.send(message);
45
- }
46
- });
47
- });
48
- ws.on("close", () => {
49
- console.log("A client disconnected.");
50
- });
51
- });
52
- }
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- createWebSocketServer
56
- });
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var utils_exports = {};
30
- __export(utils_exports, {
31
- importRscReact: () => importRscReact,
32
- importRsdwServer: () => importRsdwServer
33
- });
34
- module.exports = __toCommonJS(utils_exports);
35
- async function importRscReact() {
36
- if (globalThis.__cedarjs__vite_rsc_runtime) {
37
- const reactMod = await globalThis.__cedarjs__vite_rsc_runtime.import("react");
38
- return reactMod.default;
39
- }
40
- return import("react");
41
- }
42
- async function importRsdwServer() {
43
- if (globalThis.__cedarjs__vite_rsc_runtime) {
44
- const rsdwServerMod = await globalThis.__cedarjs__vite_rsc_runtime.import(
45
- "react-server-dom-webpack/server.edge"
46
- );
47
- return rsdwServerMod.default;
48
- } else {
49
- return import("react-server-dom-webpack/server.edge");
50
- }
51
- }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- importRscReact,
55
- importRsdwServer
56
- });
@@ -1,31 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * Vite plugin that wraps user API functions to ensure context isolation has
4
- * been performed. This should already be done at the request level but in
5
- * serverless environments like Netlify we need to do this at the function
6
- * level as a safeguard.
7
- *
8
- * For each file in `api/src/functions/` that exports a `handler`, this plugin:
9
- *
10
- * 1. Adds an import at the top of the file:
11
- * import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
12
- *
13
- * 2. Renames the original handler:
14
- * const __rw_handler = <original handler value>
15
- *
16
- * 3. Replaces the handler export with a wrapper that checks context isolation:
17
- * export const handler = (__rw_event, __rw__context) => {
18
- * const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
19
- * if (__rw_contextStore === undefined) {
20
- * return __rw_getAsyncStoreInstance().run(new Map(), __rw_handler, __rw_event, __rw__context)
21
- * }
22
- * return __rw_handler(__rw_event, __rw__context)
23
- * }
24
- *
25
- * This replaces `babel-plugin-redwood-context-wrapping` for Vite builds.
26
- * The babel plugin is still used for Jest and prerender.
27
- */
28
- export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
29
- projectIsEsm?: boolean;
30
- }): Plugin;
31
- //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CA6Ed"}
@@ -1,58 +0,0 @@
1
- import path from "node:path";
2
- import { normalizePath } from "vite";
3
- import { getPaths } from "@cedarjs/project-config";
4
- function cedarContextWrappingPlugin({
5
- projectIsEsm = false
6
- } = {}) {
7
- const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
8
- return {
9
- name: "cedar-context-wrapping",
10
- transform(code, id) {
11
- let paths;
12
- try {
13
- paths = getPaths();
14
- } catch {
15
- return null;
16
- }
17
- const functionsDir = normalizePath(path.join(paths.api.src, "functions"));
18
- if (!normalizePath(id).startsWith(functionsDir + "/")) {
19
- return null;
20
- }
21
- const handlerMatch = handlerRe.exec(code);
22
- if (!handlerMatch) {
23
- return null;
24
- }
25
- const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
26
- const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
27
- const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
28
- const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
29
- `;
30
- const handlerStart = handlerMatch.index;
31
- const before = code.slice(0, handlerStart);
32
- const after = code.slice(handlerStart);
33
- const renamed = after.replace(handlerRe, "const __rw_handler =");
34
- const wrappedHandler = `
35
- export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
36
- // The store will be undefined if no context isolation has been performed yet
37
- const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
38
- if (__rw_contextStore === undefined) {
39
- return __rw_getAsyncStoreInstance().run(
40
- new Map(),
41
- __rw_handler,
42
- __rw_event,
43
- __rw__context
44
- )
45
- }
46
- return __rw_handler(__rw_event, __rw__context)
47
- }
48
- `;
49
- return {
50
- code: before + importStatement + renamed + wrappedHandler,
51
- map: null
52
- };
53
- }
54
- };
55
- }
56
- export {
57
- cedarContextWrappingPlugin
58
- };
@@ -1,24 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * Vite plugin to auto-load page components into the Routes file.
4
- *
5
- * For each page found in `web/src/pages` that is not already explicitly
6
- * imported in Routes.tsx, this plugin prepends a lazy-loaded declaration:
7
- *
8
- * ```js
9
- * const PageName = {
10
- * name: "PageName",
11
- * prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),
12
- * LazyComponent: lazy(() => import("./pages/PageName/PageName")),
13
- * }
14
- * ```
15
- *
16
- * Pages already imported by App.tsx are also excluded to avoid Vite's
17
- * "dynamically imported by Routes.tsx but also statically imported by App.tsx"
18
- * warning.
19
- *
20
- * This replaces `babel-plugin-redwood-routes-auto-loader` for Vite builds.
21
- * The babel plugin is still used for Jest and prerender.
22
- */
23
- export declare function cedarRoutesAutoLoaderPlugin(): Plugin;
24
- //# sourceMappingURL=vite-plugin-cedar-routes-auto-loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-cedar-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAqDlC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAsFpD"}
@@ -1,98 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { normalizePath } from "vite";
4
- import {
5
- ensurePosixPath,
6
- getPaths,
7
- importStatementPath,
8
- processPagesDir,
9
- resolveFile
10
- } from "@cedarjs/project-config";
11
- function getPathRelativeToSrc(maybeAbsolutePath) {
12
- const withoutExt = maybeAbsolutePath.replace(/\.[^/.]+$/, "");
13
- if (withoutExt.startsWith("src/")) {
14
- const basePath = path.join(getPaths().web.base, withoutExt);
15
- const resolved = resolveFile(basePath) || resolveFile(path.join(basePath, "index")) || resolveFile(path.join(basePath, path.basename(basePath)));
16
- if (resolved) {
17
- const resolvedWithoutExt = resolved.replace(/\.[^/.]+$/, "");
18
- return "./" + path.relative(getPaths().web.src, resolvedWithoutExt);
19
- }
20
- return "./" + withoutExt.slice("src/".length);
21
- }
22
- if (!path.isAbsolute(withoutExt)) {
23
- return withoutExt;
24
- }
25
- return `./${path.relative(getPaths().web.src, withoutExt)}`;
26
- }
27
- function withRelativeImports(page) {
28
- return {
29
- ...page,
30
- relativeImport: ensurePosixPath(getPathRelativeToSrc(page.importPath))
31
- };
32
- }
33
- function cedarRoutesAutoLoaderPlugin() {
34
- const routesFileId = normalizePath(getPaths().web.routes);
35
- const initialPages = processPagesDir().map(withRelativeImports);
36
- const duplicatePageImportNames = /* @__PURE__ */ new Set();
37
- const sortedPageImportNames = initialPages.map((page) => page.importName).sort();
38
- for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
39
- if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
40
- duplicatePageImportNames.add(sortedPageImportNames[i]);
41
- }
42
- }
43
- if (duplicatePageImportNames.size > 0) {
44
- const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
45
- throw new Error(
46
- `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
47
- );
48
- }
49
- return {
50
- name: "cedar-routes-auto-loader",
51
- transform(code, id) {
52
- if (normalizePath(id) !== routesFileId) {
53
- return null;
54
- }
55
- let pages = processPagesDir().map(withRelativeImports);
56
- const importRe = /^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm;
57
- const appPath = resolveFile(path.join(getPaths().web.src, "App"));
58
- if (appPath) {
59
- const appSource = fs.readFileSync(appPath, "utf8");
60
- let appMatch;
61
- while ((appMatch = importRe.exec(appSource)) !== null) {
62
- const rel = ensurePosixPath(
63
- getPathRelativeToSrc(importStatementPath(appMatch[1]))
64
- );
65
- pages = pages.filter((page) => page.relativeImport !== rel);
66
- }
67
- }
68
- importRe.lastIndex = 0;
69
- let routesMatch;
70
- while ((routesMatch = importRe.exec(code)) !== null) {
71
- const rel = ensurePosixPath(
72
- getPathRelativeToSrc(importStatementPath(routesMatch[1]))
73
- );
74
- pages = pages.filter((page) => page.relativeImport !== rel);
75
- }
76
- if (pages.length === 0) {
77
- return null;
78
- }
79
- const lines = [`import { lazy } from 'react'`];
80
- for (const { importName, relativeImport } of pages) {
81
- lines.push(
82
- `const ${importName} = {`,
83
- ` name: "${importName}",`,
84
- ` prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),`,
85
- ` LazyComponent: lazy(() => import("${relativeImport}")),`,
86
- `}`
87
- );
88
- }
89
- return {
90
- code: lines.join("\n") + "\n\n" + code,
91
- map: null
92
- };
93
- }
94
- };
95
- }
96
- export {
97
- cedarRoutesAutoLoaderPlugin
98
- };
@@ -1,2 +0,0 @@
1
- export declare function createWebSocketServer(): void;
2
- //# sourceMappingURL=rscWebSocketServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rscWebSocketServer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscWebSocketServer.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,SAwBpC"}
@@ -1,22 +0,0 @@
1
- import WebSocket, { WebSocketServer } from "ws";
2
- function createWebSocketServer() {
3
- const wsServer = new WebSocketServer({ port: 18998 });
4
- wsServer.on("connection", (ws) => {
5
- console.log("A new client connected.");
6
- ws.on("message", (data) => {
7
- const message = data.toString();
8
- console.log("Received message:", message);
9
- wsServer.clients.forEach((client) => {
10
- if (client.readyState === WebSocket.OPEN) {
11
- client.send(message);
12
- }
13
- });
14
- });
15
- ws.on("close", () => {
16
- console.log("A client disconnected.");
17
- });
18
- });
19
- }
20
- export {
21
- createWebSocketServer
22
- };
@@ -1,10 +0,0 @@
1
- import type { default as RSDWServerModule } from 'react-server-dom-webpack/server.edge';
2
- type RSDWServerType = typeof RSDWServerModule;
3
- /**
4
- * This function ensures we load the version of React that's been imported with
5
- * the react-server condition.
6
- */
7
- export declare function importRscReact(): Promise<any>;
8
- export declare function importRsdwServer(): Promise<RSDWServerType>;
9
- export {};
10
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/rsc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AAEvF,KAAK,cAAc,GAAG,OAAO,gBAAgB,CAAA;AAE7C;;;GAGG;AACH,wBAAsB,cAAc,iBAQnC;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,cAAc,CAAC,CAUhE"}
package/dist/rsc/utils.js DELETED
@@ -1,21 +0,0 @@
1
- async function importRscReact() {
2
- if (globalThis.__cedarjs__vite_rsc_runtime) {
3
- const reactMod = await globalThis.__cedarjs__vite_rsc_runtime.import("react");
4
- return reactMod.default;
5
- }
6
- return import("react");
7
- }
8
- async function importRsdwServer() {
9
- if (globalThis.__cedarjs__vite_rsc_runtime) {
10
- const rsdwServerMod = await globalThis.__cedarjs__vite_rsc_runtime.import(
11
- "react-server-dom-webpack/server.edge"
12
- );
13
- return rsdwServerMod.default;
14
- } else {
15
- return import("react-server-dom-webpack/server.edge");
16
- }
17
- }
18
- export {
19
- importRscReact,
20
- importRsdwServer
21
- };