@cedarjs/vite 4.0.0 → 4.0.1-next.67

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 (55) hide show
  1. package/dist/apiDevServer.d.ts +18 -0
  2. package/dist/apiDevServer.d.ts.map +1 -0
  3. package/dist/apiDevServer.js +335 -0
  4. package/dist/buildUDApiServer.d.ts +22 -0
  5. package/dist/buildUDApiServer.d.ts.map +1 -0
  6. package/dist/buildUDApiServer.js +59 -0
  7. package/dist/bundled/react-server-dom-webpack.server.js +28528 -1231
  8. package/dist/cedar-unified-dev.d.ts +3 -0
  9. package/dist/cedar-unified-dev.d.ts.map +1 -0
  10. package/dist/cedar-unified-dev.js +65 -0
  11. package/dist/cjs/apiDevServer.js +366 -0
  12. package/dist/cjs/buildUDApiServer.js +93 -0
  13. package/dist/cjs/cedar-unified-dev.js +88 -0
  14. package/dist/cjs/index.js +9 -0
  15. package/dist/cjs/lib/getMergedConfig.js +5 -0
  16. package/dist/cjs/lib/workspacePackageAliases.js +113 -0
  17. package/dist/cjs/plugins/vite-plugin-cedar-dev-dispatcher.js +223 -0
  18. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +63 -0
  19. package/dist/cjs/rsc/rscBuildAnalyze.js +2 -0
  20. package/dist/cjs/rsc/rscBuildForServer.js +2 -0
  21. package/dist/cjs/rsc/rscBuildForSsr.js +2 -0
  22. package/dist/cjs/rsc/rscStudioHandlers.js +2 -1
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +6 -0
  26. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  27. package/dist/lib/getMergedConfig.js +5 -0
  28. package/dist/lib/workspacePackageAliases.d.ts +18 -0
  29. package/dist/lib/workspacePackageAliases.d.ts.map +1 -0
  30. package/dist/lib/workspacePackageAliases.js +79 -0
  31. package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts +3 -0
  32. package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts.map +1 -0
  33. package/dist/plugins/vite-plugin-cedar-dev-dispatcher.js +189 -0
  34. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts +6 -0
  35. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -0
  36. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +39 -0
  37. package/dist/rsc/rscBuildAnalyze.d.ts.map +1 -1
  38. package/dist/rsc/rscBuildAnalyze.js +2 -0
  39. package/dist/rsc/rscBuildForServer.d.ts.map +1 -1
  40. package/dist/rsc/rscBuildForServer.js +2 -0
  41. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  42. package/dist/rsc/rscBuildForSsr.js +2 -0
  43. package/dist/rsc/rscStudioHandlers.d.ts.map +1 -1
  44. package/dist/rsc/rscStudioHandlers.js +2 -1
  45. package/package.json +39 -19
  46. package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
  47. package/dist/cjs/rsc/utils.js +0 -56
  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
  54. /package/bins/{rw-vite-build.mjs → cedar-vite-build.mjs} +0 -0
  55. /package/bins/{rw-vite-dev.mjs → cedar-vite-dev.mjs} +0 -0
@@ -0,0 +1,113 @@
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 workspacePackageAliases_exports = {};
30
+ __export(workspacePackageAliases_exports, {
31
+ getWorkspacePackageAliases: () => getWorkspacePackageAliases
32
+ });
33
+ module.exports = __toCommonJS(workspacePackageAliases_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
+ function findSourceEntry(pkgDir, pkgJson) {
38
+ let distEntry = null;
39
+ if (typeof pkgJson.main === "string") {
40
+ distEntry = pkgJson.main;
41
+ } else if (pkgJson.exports) {
42
+ const root = pkgJson.exports["."];
43
+ if (typeof root === "string") {
44
+ distEntry = root;
45
+ } else if (root && typeof root === "object") {
46
+ const rootObj = root;
47
+ if (typeof rootObj["default"] === "string") {
48
+ distEntry = rootObj["default"];
49
+ }
50
+ }
51
+ }
52
+ if (!distEntry) {
53
+ return null;
54
+ }
55
+ const withoutLeadingDot = distEntry.replace(/^\.\//, "");
56
+ const withoutExt = withoutLeadingDot.replace(/\.(js|cjs|mjs)$/, "");
57
+ const srcBase = withoutExt.replace(/^dist\//, "src/");
58
+ for (const ext of [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs"]) {
59
+ const candidate = import_node_path.default.join(pkgDir, srcBase + ext);
60
+ if (import_node_fs.default.existsSync(candidate)) {
61
+ return (0, import_vite.normalizePath)(candidate);
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+ function getWorkspacePackageAliases(cedarPaths, cedarConfig) {
67
+ if (!cedarConfig.experimental?.packagesWorkspace?.enabled) {
68
+ return {};
69
+ }
70
+ if (!cedarPaths.packages || !import_node_fs.default.existsSync(cedarPaths.packages)) {
71
+ return {};
72
+ }
73
+ try {
74
+ const rootPkgPath = import_node_path.default.join(cedarPaths.base, "package.json");
75
+ const rootPkg = JSON.parse(import_node_fs.default.readFileSync(rootPkgPath, "utf-8"));
76
+ if (!Array.isArray(rootPkg.workspaces) || rootPkg.workspaces.length <= 2) {
77
+ return {};
78
+ }
79
+ const nonApiWebWorkspaces = rootPkg.workspaces.filter(
80
+ (w) => w !== "api" && w !== "web"
81
+ );
82
+ if (nonApiWebWorkspaces.length === 0) {
83
+ return {};
84
+ }
85
+ const entries = import_node_fs.default.readdirSync(cedarPaths.packages, { withFileTypes: true });
86
+ const aliases = {};
87
+ for (const entry of entries) {
88
+ if (!entry.isDirectory()) {
89
+ continue;
90
+ }
91
+ const pkgDir = import_node_path.default.join(cedarPaths.packages, entry.name);
92
+ const pkgJsonPath = import_node_path.default.join(pkgDir, "package.json");
93
+ if (!import_node_fs.default.existsSync(pkgJsonPath)) {
94
+ continue;
95
+ }
96
+ const pkgJson = JSON.parse(import_node_fs.default.readFileSync(pkgJsonPath, "utf-8"));
97
+ if (!pkgJson.name) {
98
+ continue;
99
+ }
100
+ const sourceEntry = findSourceEntry(pkgDir, pkgJson);
101
+ if (sourceEntry) {
102
+ aliases[pkgJson.name] = sourceEntry;
103
+ }
104
+ }
105
+ return aliases;
106
+ } catch {
107
+ return {};
108
+ }
109
+ }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ getWorkspacePackageAliases
113
+ });
@@ -0,0 +1,223 @@
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_dev_dispatcher_exports = {};
30
+ __export(vite_plugin_cedar_dev_dispatcher_exports, {
31
+ cedarDevDispatcherPlugin: () => cedarDevDispatcherPlugin
32
+ });
33
+ module.exports = __toCommonJS(vite_plugin_cedar_dev_dispatcher_exports);
34
+ var import_node_net = __toESM(require("node:net"), 1);
35
+ var import_node_path = __toESM(require("node:path"), 1);
36
+ var import_project_config = require("@cedarjs/project-config");
37
+ let cachedDispatcher = null;
38
+ let dispatcherGeneration = 0;
39
+ let buildPromise = null;
40
+ async function getDispatcher() {
41
+ if (cachedDispatcher !== null) {
42
+ return cachedDispatcher;
43
+ }
44
+ if (buildPromise !== null) {
45
+ await buildPromise;
46
+ return cachedDispatcher ?? getDispatcher();
47
+ }
48
+ const generationAtStart = dispatcherGeneration;
49
+ buildPromise = (async () => {
50
+ try {
51
+ const { rebuildApi, buildApi } = await import("@cedarjs/internal/dist/build/api");
52
+ try {
53
+ await rebuildApi();
54
+ } catch {
55
+ await buildApi();
56
+ }
57
+ } catch (err) {
58
+ console.warn(
59
+ "[cedar-dev-dispatcher] API compilation failed; serving with last-known-good dist:",
60
+ err
61
+ );
62
+ }
63
+ const { buildCedarDispatcher } = await import("@cedarjs/api-server/udDispatcher");
64
+ const { fetchable } = await buildCedarDispatcher({ cacheBust: Date.now() });
65
+ if (generationAtStart === dispatcherGeneration) {
66
+ cachedDispatcher = fetchable;
67
+ }
68
+ return fetchable;
69
+ })();
70
+ try {
71
+ await buildPromise;
72
+ } finally {
73
+ if (generationAtStart === dispatcherGeneration) {
74
+ buildPromise = null;
75
+ }
76
+ }
77
+ if (cachedDispatcher !== null) {
78
+ return cachedDispatcher;
79
+ }
80
+ return getDispatcher();
81
+ }
82
+ function invalidateDispatcher() {
83
+ cachedDispatcher = null;
84
+ buildPromise = null;
85
+ dispatcherGeneration++;
86
+ }
87
+ function isViteInternalRequest(url) {
88
+ return url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/__hmr") || url.includes("?import") || url.includes("?t=") || url.includes("?v=");
89
+ }
90
+ async function nodeRequestToFetch(req) {
91
+ const host = req.headers.host ?? "localhost";
92
+ const url = `http://${host}${req.url ?? "/"}`;
93
+ const headers = new Headers();
94
+ for (const [key, value] of Object.entries(req.headers)) {
95
+ if (value === void 0) {
96
+ continue;
97
+ }
98
+ if (Array.isArray(value)) {
99
+ for (const v of value) {
100
+ headers.append(key, v);
101
+ }
102
+ } else {
103
+ headers.set(key, value);
104
+ }
105
+ }
106
+ const method = (req.method ?? "GET").toUpperCase();
107
+ const hasBody = ["POST", "PUT", "PATCH", "DELETE"].includes(method);
108
+ let body;
109
+ if (hasBody) {
110
+ body = await new Promise((resolve, reject) => {
111
+ const chunks = [];
112
+ req.on("data", (chunk) => chunks.push(chunk));
113
+ req.on("end", () => resolve(Buffer.concat(chunks)));
114
+ req.on("error", reject);
115
+ });
116
+ }
117
+ return new Request(url, {
118
+ method,
119
+ headers,
120
+ body: hasBody && body && body.length > 0 ? new Uint8Array(body) : void 0
121
+ });
122
+ }
123
+ async function fetchResponseToNode(fetchRes, res) {
124
+ res.statusCode = fetchRes.status;
125
+ fetchRes.headers.forEach((value, key) => {
126
+ res.setHeader(key, value);
127
+ });
128
+ const bodyBuffer = await fetchRes.arrayBuffer();
129
+ if (bodyBuffer.byteLength > 0) {
130
+ res.end(Buffer.from(bodyBuffer));
131
+ } else {
132
+ res.end();
133
+ }
134
+ }
135
+ let apiServerIsUp;
136
+ async function checkApiPort(host, port) {
137
+ return new Promise((resolve) => {
138
+ const socket = new import_node_net.default.Socket();
139
+ socket.setTimeout(100);
140
+ socket.on("connect", () => {
141
+ socket.destroy();
142
+ resolve(true);
143
+ });
144
+ socket.on("timeout", () => {
145
+ socket.destroy();
146
+ resolve(false);
147
+ });
148
+ socket.on("error", () => {
149
+ socket.destroy();
150
+ resolve(false);
151
+ });
152
+ socket.connect(port, host);
153
+ });
154
+ }
155
+ function cedarDevDispatcherPlugin() {
156
+ return {
157
+ name: "cedar-dev-dispatcher",
158
+ apply: "serve",
159
+ configureServer(server) {
160
+ const cedarConfig = (0, import_project_config.getConfig)();
161
+ const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
162
+ const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
163
+ const apiPort = cedarConfig.api.port;
164
+ const apiHost = cedarConfig.api.host || "127.0.0.1";
165
+ function isApiRequest(url) {
166
+ return url === apiUrl || url.startsWith(apiUrl + "/") || url.startsWith(apiUrl + "?") || url === apiGqlUrl || url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?");
167
+ }
168
+ server.watcher.on("change", (filePath) => {
169
+ if (filePath.startsWith((0, import_project_config.getPaths)().api.src + import_node_path.default.sep)) {
170
+ invalidateDispatcher();
171
+ }
172
+ });
173
+ server.middlewares.use(
174
+ async (req, res, next) => {
175
+ const url = req.url ?? "/";
176
+ if (isViteInternalRequest(url)) {
177
+ return next();
178
+ }
179
+ if (!isApiRequest(url)) {
180
+ return next();
181
+ }
182
+ if (apiServerIsUp === void 0) {
183
+ apiServerIsUp = await checkApiPort(apiHost, apiPort);
184
+ }
185
+ if (apiServerIsUp) {
186
+ return next();
187
+ }
188
+ try {
189
+ const dispatcher = await getDispatcher();
190
+ const fetchRequest = await nodeRequestToFetch(req);
191
+ const fetchResponse = await dispatcher.fetch(fetchRequest);
192
+ await fetchResponseToNode(fetchResponse, res);
193
+ } catch (err) {
194
+ console.error(
195
+ "[cedar-dev-dispatcher] Error handling API request:",
196
+ err
197
+ );
198
+ if (!res.headersSent) {
199
+ res.writeHead(500, { "Content-Type": "application/json" });
200
+ }
201
+ res.end(
202
+ JSON.stringify(
203
+ {
204
+ errors: [
205
+ {
206
+ message: err instanceof Error ? err.message : "Internal Server Error"
207
+ }
208
+ ]
209
+ },
210
+ null,
211
+ 2
212
+ )
213
+ );
214
+ }
215
+ }
216
+ );
217
+ }
218
+ };
219
+ }
220
+ // Annotate the CommonJS export names for ESM import in node:
221
+ 0 && (module.exports = {
222
+ cedarDevDispatcherPlugin
223
+ });
@@ -0,0 +1,63 @@
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_universal_deploy_exports = {};
20
+ __export(vite_plugin_cedar_universal_deploy_exports, {
21
+ cedarUniversalDeployPlugin: () => cedarUniversalDeployPlugin
22
+ });
23
+ module.exports = __toCommonJS(vite_plugin_cedar_universal_deploy_exports);
24
+ var import_store = require("@universal-deploy/store");
25
+ const VIRTUAL_CEDAR_API = "virtual:cedar-api";
26
+ const RESOLVED_VIRTUAL_CEDAR_API = "\0virtual:cedar-api";
27
+ function cedarUniversalDeployPlugin(options = {}) {
28
+ const { apiRootPath } = options;
29
+ return {
30
+ name: "cedar-universal-deploy",
31
+ apply: "build",
32
+ buildStart() {
33
+ (0, import_store.addEntry)({
34
+ id: VIRTUAL_CEDAR_API,
35
+ route: "/**"
36
+ });
37
+ },
38
+ resolveId(id) {
39
+ if (id === import_store.catchAllEntry) {
40
+ return RESOLVED_VIRTUAL_CEDAR_API;
41
+ }
42
+ if (id === VIRTUAL_CEDAR_API) {
43
+ return RESOLVED_VIRTUAL_CEDAR_API;
44
+ }
45
+ return void 0;
46
+ },
47
+ load(id) {
48
+ if (id !== RESOLVED_VIRTUAL_CEDAR_API) {
49
+ return void 0;
50
+ }
51
+ const apiRootPathArg = apiRootPath !== void 0 ? `{ apiRootPath: ${JSON.stringify(apiRootPath)} }` : "undefined";
52
+ return `
53
+ import { buildCedarDispatcher } from '@cedarjs/api-server/udDispatcher';
54
+ const { fetchable } = await buildCedarDispatcher(${apiRootPathArg});
55
+ export default fetchable;
56
+ `;
57
+ }
58
+ };
59
+ }
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ cedarUniversalDeployPlugin
63
+ });
@@ -66,6 +66,7 @@ async function rscBuildAnalyze() {
66
66
  "better-sqlite3",
67
67
  "@cedarjs/auth-dbauth-api",
68
68
  "@cedarjs/cookie-jar",
69
+ "@cedarjs/realtime",
69
70
  "@cedarjs/server-store",
70
71
  "@simplewebauthn/server",
71
72
  "graphql-scalars",
@@ -95,6 +96,7 @@ async function rscBuildAnalyze() {
95
96
  ssr: true,
96
97
  rollupOptions: {
97
98
  onwarn: import_onWarn.onWarn,
99
+ external: ["@cedarjs/realtime"],
98
100
  input: (0, import_entries.getEntries)()
99
101
  }
100
102
  }
@@ -68,6 +68,7 @@ async function rscBuildForServer(clientEntryFiles, serverEntryFiles, customModul
68
68
  "better-sqlite3",
69
69
  "@cedarjs/auth-dbauth-api",
70
70
  "@cedarjs/cookie-jar",
71
+ "@cedarjs/realtime",
71
72
  "@cedarjs/server-store",
72
73
  "@simplewebauthn/server",
73
74
  "graphql-scalars",
@@ -114,6 +115,7 @@ async function rscBuildForServer(clientEntryFiles, serverEntryFiles, customModul
114
115
  manifest: "server-build-manifest.json",
115
116
  rollupOptions: {
116
117
  onwarn: import_onWarn.onWarn,
118
+ external: ["@cedarjs/realtime"],
117
119
  input: {
118
120
  ...entryFiles,
119
121
  ...clientEntryFiles,
@@ -73,6 +73,7 @@ async function rscBuildForSsr({
73
73
  "better-sqlite3",
74
74
  "@cedarjs/auth-dbauth-api",
75
75
  "@cedarjs/cookie-jar",
76
+ "@cedarjs/realtime",
76
77
  "@cedarjs/server-store",
77
78
  "@simplewebauthn/server",
78
79
  "graphql-scalars",
@@ -102,6 +103,7 @@ async function rscBuildForSsr({
102
103
  // Needed because `outDir` is not inside `root`
103
104
  rollupOptions: {
104
105
  onwarn: import_onWarn.onWarn,
106
+ external: ["@cedarjs/realtime"],
105
107
  input: {
106
108
  // @MARK: temporary hack to find the entry client so we can get the
107
109
  // index.css bundle but we don't actually want this on an rsc page!
@@ -79,10 +79,11 @@ const postFlightToStudio = (payload, metadata) => {
79
79
  encodedMetadata
80
80
  }
81
81
  });
82
+ const apiUrl = (0, import_project_config.getConfig)().web.apiUrl.replace(/\/$/, "");
82
83
  const options = {
83
84
  hostname: "localhost",
84
85
  port: getStudioPort(),
85
- path: "/.redwood/functions/rsc-flight",
86
+ path: `${apiUrl}/rsc-flight`,
86
87
  method: "POST",
87
88
  headers: {
88
89
  "Content-Type": "application/json",
package/dist/index.d.ts CHANGED
@@ -11,6 +11,9 @@ export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-
11
11
  export { cedarTransformJsAsJsx } from './plugins/vite-plugin-jsx-loader.js';
12
12
  export { cedarMergedConfig } from './plugins/vite-plugin-merged-config.js';
13
13
  export { cedarSwapApolloProvider } from './plugins/vite-plugin-swap-apollo-provider.js';
14
+ export { cedarUniversalDeployPlugin } from './plugins/vite-plugin-cedar-universal-deploy.js';
15
+ export { cedarDevDispatcherPlugin } from './plugins/vite-plugin-cedar-dev-dispatcher.js';
16
+ export { cedarWaitForApiServer } from './plugins/vite-plugin-cedar-wait-for-api-server.js';
14
17
  type PluginOptions = {
15
18
  mode?: string | undefined;
16
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AAEvF,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAyClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAA;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAyClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
package/dist/index.js CHANGED
@@ -28,6 +28,9 @@ import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-
28
28
  import { cedarTransformJsAsJsx as cedarTransformJsAsJsx2 } from "./plugins/vite-plugin-jsx-loader.js";
29
29
  import { cedarMergedConfig as cedarMergedConfig2 } from "./plugins/vite-plugin-merged-config.js";
30
30
  import { cedarSwapApolloProvider as cedarSwapApolloProvider2 } from "./plugins/vite-plugin-swap-apollo-provider.js";
31
+ import { cedarUniversalDeployPlugin } from "./plugins/vite-plugin-cedar-universal-deploy.js";
32
+ import { cedarDevDispatcherPlugin } from "./plugins/vite-plugin-cedar-dev-dispatcher.js";
33
+ import { cedarWaitForApiServer as cedarWaitForApiServer2 } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
31
34
  function cedar({ mode } = {}) {
32
35
  const cedarConfig = getConfig();
33
36
  const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
@@ -66,6 +69,7 @@ export {
66
69
  cedar,
67
70
  cedarAutoImportsPlugin,
68
71
  cedarCellTransform2 as cedarCellTransform,
72
+ cedarDevDispatcherPlugin,
69
73
  cedarEntryInjectionPlugin2 as cedarEntryInjectionPlugin,
70
74
  cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
71
75
  cedarImportDirPlugin,
@@ -74,6 +78,8 @@ export {
74
78
  cedarRemoveFromBundle2 as cedarRemoveFromBundle,
75
79
  cedarSwapApolloProvider2 as cedarSwapApolloProvider,
76
80
  cedarTransformJsAsJsx2 as cedarTransformJsAsJsx,
81
+ cedarUniversalDeployPlugin,
82
+ cedarWaitForApiServer2 as cedarWaitForApiServer,
77
83
  cedarjsJobPathInjectorPlugin,
78
84
  cedarjsResolveCedarStyleImportsPlugin2 as cedarjsResolveCedarStyleImportsPlugin,
79
85
  index_default as default
@@ -1 +1 @@
1
- {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CA0GpE"}
1
+ {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CAqHpE"}
@@ -5,8 +5,10 @@ import {
5
5
  getEnvVarDefinitions,
6
6
  getPaths
7
7
  } from "@cedarjs/project-config";
8
+ import { getWorkspacePackageAliases } from "./workspacePackageAliases.js";
8
9
  function getMergedConfig(cedarConfig, cedarPaths) {
9
10
  return (userConfig, env) => {
11
+ const workspaceAliases = env.command === "serve" ? getWorkspacePackageAliases(cedarPaths, cedarConfig) : {};
10
12
  let apiHost = process.env.REDWOOD_API_HOST;
11
13
  apiHost ??= cedarConfig.api.host;
12
14
  apiHost ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "127.0.0.1";
@@ -20,6 +22,9 @@ function getMergedConfig(cedarConfig, cedarPaths) {
20
22
  }
21
23
  const defaultCedarViteConfig = {
22
24
  root: cedarPaths.web.src,
25
+ resolve: {
26
+ alias: workspaceAliases
27
+ },
23
28
  // @MARK: when we have these aliases, the warnings from the FE server go
24
29
  // away BUT, if you have imports like this:
25
30
  // ```
@@ -0,0 +1,18 @@
1
+ import type { Config, Paths } from '@cedarjs/project-config';
2
+ /**
3
+ * Mirrors the logic used in buildHandler.ts / buildPackagesTask.js:
4
+ * - Only runs when `experimental.packagesWorkspace.enabled` is true
5
+ * - Reads the root package.json workspaces array to find non-api/web entries
6
+ * - Enumerates the packages/ directory to get each package's name and
7
+ * inferred TypeScript source entry
8
+ *
9
+ * Returns a map of package name → absolute source file path suitable for use
10
+ * as Vite `resolve.alias` entries. This allows the Vite dev server to resolve
11
+ * workspace package imports directly to their TypeScript source without
12
+ * requiring a prior build step (i.e. without needing `dist/` to exist).
13
+ *
14
+ * This is intentionally synchronous so it can be used in contexts such as
15
+ * `getMergedConfig` which are called synchronously by Vite.
16
+ */
17
+ export declare function getWorkspacePackageAliases(cedarPaths: Paths, cedarConfig: Config): Record<string, string>;
18
+ //# sourceMappingURL=workspacePackageAliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspacePackageAliases.d.ts","sourceRoot":"","sources":["../../src/lib/workspacePackageAliases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AA2D5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,KAAK,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiExB"}
@@ -0,0 +1,79 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { normalizePath } from "vite";
4
+ function findSourceEntry(pkgDir, pkgJson) {
5
+ let distEntry = null;
6
+ if (typeof pkgJson.main === "string") {
7
+ distEntry = pkgJson.main;
8
+ } else if (pkgJson.exports) {
9
+ const root = pkgJson.exports["."];
10
+ if (typeof root === "string") {
11
+ distEntry = root;
12
+ } else if (root && typeof root === "object") {
13
+ const rootObj = root;
14
+ if (typeof rootObj["default"] === "string") {
15
+ distEntry = rootObj["default"];
16
+ }
17
+ }
18
+ }
19
+ if (!distEntry) {
20
+ return null;
21
+ }
22
+ const withoutLeadingDot = distEntry.replace(/^\.\//, "");
23
+ const withoutExt = withoutLeadingDot.replace(/\.(js|cjs|mjs)$/, "");
24
+ const srcBase = withoutExt.replace(/^dist\//, "src/");
25
+ for (const ext of [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs"]) {
26
+ const candidate = path.join(pkgDir, srcBase + ext);
27
+ if (fs.existsSync(candidate)) {
28
+ return normalizePath(candidate);
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ function getWorkspacePackageAliases(cedarPaths, cedarConfig) {
34
+ if (!cedarConfig.experimental?.packagesWorkspace?.enabled) {
35
+ return {};
36
+ }
37
+ if (!cedarPaths.packages || !fs.existsSync(cedarPaths.packages)) {
38
+ return {};
39
+ }
40
+ try {
41
+ const rootPkgPath = path.join(cedarPaths.base, "package.json");
42
+ const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
43
+ if (!Array.isArray(rootPkg.workspaces) || rootPkg.workspaces.length <= 2) {
44
+ return {};
45
+ }
46
+ const nonApiWebWorkspaces = rootPkg.workspaces.filter(
47
+ (w) => w !== "api" && w !== "web"
48
+ );
49
+ if (nonApiWebWorkspaces.length === 0) {
50
+ return {};
51
+ }
52
+ const entries = fs.readdirSync(cedarPaths.packages, { withFileTypes: true });
53
+ const aliases = {};
54
+ for (const entry of entries) {
55
+ if (!entry.isDirectory()) {
56
+ continue;
57
+ }
58
+ const pkgDir = path.join(cedarPaths.packages, entry.name);
59
+ const pkgJsonPath = path.join(pkgDir, "package.json");
60
+ if (!fs.existsSync(pkgJsonPath)) {
61
+ continue;
62
+ }
63
+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
64
+ if (!pkgJson.name) {
65
+ continue;
66
+ }
67
+ const sourceEntry = findSourceEntry(pkgDir, pkgJson);
68
+ if (sourceEntry) {
69
+ aliases[pkgJson.name] = sourceEntry;
70
+ }
71
+ }
72
+ return aliases;
73
+ } catch {
74
+ return {};
75
+ }
76
+ }
77
+ export {
78
+ getWorkspacePackageAliases
79
+ };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function cedarDevDispatcherPlugin(): Plugin;
3
+ //# sourceMappingURL=vite-plugin-cedar-dev-dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-dev-dispatcher.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-dev-dispatcher.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AA+LjD,wBAAgB,wBAAwB,IAAI,MAAM,CA4FjD"}