@cedarjs/vite 4.0.1-next.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.
- package/dist/apiDevServer.d.ts +18 -0
- package/dist/apiDevServer.d.ts.map +1 -0
- package/dist/apiDevServer.js +335 -0
- package/dist/buildUDApiServer.d.ts +22 -0
- package/dist/buildUDApiServer.d.ts.map +1 -0
- package/dist/buildUDApiServer.js +59 -0
- package/dist/cedar-unified-dev.d.ts +3 -0
- package/dist/cedar-unified-dev.d.ts.map +1 -0
- package/dist/cedar-unified-dev.js +65 -0
- package/dist/cjs/apiDevServer.js +366 -0
- package/dist/cjs/buildUDApiServer.js +93 -0
- package/dist/cjs/cedar-unified-dev.js +88 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/lib/getMergedConfig.js +5 -0
- package/dist/cjs/lib/workspacePackageAliases.js +113 -0
- package/dist/cjs/plugins/vite-plugin-cedar-dev-dispatcher.js +223 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +63 -0
- package/dist/cjs/rsc/rscBuildAnalyze.js +2 -0
- package/dist/cjs/rsc/rscBuildForServer.js +2 -0
- package/dist/cjs/rsc/rscBuildForSsr.js +2 -0
- package/dist/cjs/rsc/rscStudioHandlers.js +2 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/lib/getMergedConfig.d.ts.map +1 -1
- package/dist/lib/getMergedConfig.js +5 -0
- package/dist/lib/workspacePackageAliases.d.ts +18 -0
- package/dist/lib/workspacePackageAliases.d.ts.map +1 -0
- package/dist/lib/workspacePackageAliases.js +79 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.js +189 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts +6 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +39 -0
- package/dist/rsc/rscBuildAnalyze.d.ts.map +1 -1
- package/dist/rsc/rscBuildAnalyze.js +2 -0
- package/dist/rsc/rscBuildForServer.d.ts.map +1 -1
- package/dist/rsc/rscBuildForServer.js +2 -0
- package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
- package/dist/rsc/rscBuildForSsr.js +2 -0
- package/dist/rsc/rscStudioHandlers.d.ts.map +1 -1
- package/dist/rsc/rscStudioHandlers.js +2 -1
- package/package.json +39 -19
- /package/bins/{rw-vite-build.mjs → cedar-vite-build.mjs} +0 -0
- /package/bins/{rw-vite-dev.mjs → cedar-vite-dev.mjs} +0 -0
|
@@ -0,0 +1,366 @@
|
|
|
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 apiDevServer_exports = {};
|
|
30
|
+
__export(apiDevServer_exports, {
|
|
31
|
+
startApiDevServer: () => startApiDevServer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(apiDevServer_exports);
|
|
34
|
+
var import_promises = require("node:fs/promises");
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_node_url = require("node:url");
|
|
37
|
+
var import_url_data = __toESM(require("@fastify/url-data"), 1);
|
|
38
|
+
var import_ansis = __toESM(require("ansis"), 1);
|
|
39
|
+
var import_fastify = __toESM(require("fastify"), 1);
|
|
40
|
+
var import_fastify_raw_body = __toESM(require("fastify-raw-body"), 1);
|
|
41
|
+
var import_vite = require("vite");
|
|
42
|
+
var import_requestHandlers = require("@cedarjs/api-server/requestHandlers");
|
|
43
|
+
var import_babel_config = require("@cedarjs/babel-config");
|
|
44
|
+
var import_store = require("@cedarjs/context/dist/store");
|
|
45
|
+
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
46
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
47
|
+
var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
|
|
48
|
+
const LAMBDA_FUNCTIONS = {};
|
|
49
|
+
let graphqlYoga = null;
|
|
50
|
+
let loadApiFunctionsInFlight = null;
|
|
51
|
+
let needsReloadAfterInFlight = false;
|
|
52
|
+
async function loadApiFunctions(viteServer) {
|
|
53
|
+
if (loadApiFunctionsInFlight) {
|
|
54
|
+
needsReloadAfterInFlight = true;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
do {
|
|
58
|
+
needsReloadAfterInFlight = false;
|
|
59
|
+
loadApiFunctionsInFlight = internalLoadApiFunctions(viteServer);
|
|
60
|
+
try {
|
|
61
|
+
await loadApiFunctionsInFlight;
|
|
62
|
+
} finally {
|
|
63
|
+
loadApiFunctionsInFlight = null;
|
|
64
|
+
}
|
|
65
|
+
} while (needsReloadAfterInFlight);
|
|
66
|
+
}
|
|
67
|
+
async function internalLoadApiFunctions(viteServer) {
|
|
68
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
69
|
+
for (const key of Object.keys(LAMBDA_FUNCTIONS)) {
|
|
70
|
+
delete LAMBDA_FUNCTIONS[key];
|
|
71
|
+
}
|
|
72
|
+
let srcFunctions = [];
|
|
73
|
+
try {
|
|
74
|
+
srcFunctions = await Array.fromAsync(
|
|
75
|
+
(0, import_promises.glob)("**/*.{ts,tsx,js,jsx}", {
|
|
76
|
+
cwd: cedarPaths.api.functions,
|
|
77
|
+
exclude: [
|
|
78
|
+
"**/*.test.{ts,tsx,js,jsx}",
|
|
79
|
+
"**/*.scenarios.{ts,tsx,js,jsx}",
|
|
80
|
+
"**/*.fixtures.{ts,tsx,js,jsx}",
|
|
81
|
+
"**/*.d.ts"
|
|
82
|
+
]
|
|
83
|
+
}),
|
|
84
|
+
(entry) => import_node_path.default.join(cedarPaths.api.functions, entry)
|
|
85
|
+
);
|
|
86
|
+
} catch {
|
|
87
|
+
srcFunctions = [];
|
|
88
|
+
}
|
|
89
|
+
const graphqlFunctionIndex = srcFunctions.findIndex(
|
|
90
|
+
(f) => import_node_path.default.basename(f).startsWith("graphql.")
|
|
91
|
+
);
|
|
92
|
+
if (graphqlFunctionIndex > 0) {
|
|
93
|
+
const [graphqlFn] = srcFunctions.splice(graphqlFunctionIndex, 1);
|
|
94
|
+
srcFunctions.unshift(graphqlFn);
|
|
95
|
+
}
|
|
96
|
+
console.log(import_ansis.default.dim.italic("Importing Server Functions... "));
|
|
97
|
+
const tsImport = Date.now();
|
|
98
|
+
let extractedGraphqlOptions = null;
|
|
99
|
+
const imports = srcFunctions.map(async (fnPath) => {
|
|
100
|
+
const ts = Date.now();
|
|
101
|
+
const routeName = import_node_path.default.basename(fnPath).replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
102
|
+
try {
|
|
103
|
+
const mod = await viteServer.ssrLoadModule((0, import_node_url.pathToFileURL)(fnPath).href);
|
|
104
|
+
const handler = (() => {
|
|
105
|
+
if ("handler" in mod) {
|
|
106
|
+
return mod.handler;
|
|
107
|
+
}
|
|
108
|
+
if ("default" in mod && mod.default && "handler" in mod.default) {
|
|
109
|
+
return mod.default.handler;
|
|
110
|
+
}
|
|
111
|
+
return void 0;
|
|
112
|
+
})();
|
|
113
|
+
if (handler) {
|
|
114
|
+
LAMBDA_FUNCTIONS[routeName] = handler;
|
|
115
|
+
console.log(
|
|
116
|
+
import_ansis.default.magenta("/" + routeName),
|
|
117
|
+
import_ansis.default.dim.italic(Date.now() - ts + " ms")
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
console.warn(
|
|
121
|
+
`[apiDevServer] No handler export found in function: ${fnPath}`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
if (routeName === "graphql" && "__rw_graphqlOptions" in mod) {
|
|
125
|
+
extractedGraphqlOptions = mod.__rw_graphqlOptions;
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
viteServer.ssrFixStacktrace(err);
|
|
129
|
+
console.error(
|
|
130
|
+
`[apiDevServer] Failed to load function "${routeName}" from ${fnPath}:`,
|
|
131
|
+
err
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
await Promise.all(imports);
|
|
136
|
+
if (extractedGraphqlOptions) {
|
|
137
|
+
const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(extractedGraphqlOptions);
|
|
138
|
+
graphqlYoga = yoga;
|
|
139
|
+
}
|
|
140
|
+
console.log(
|
|
141
|
+
import_ansis.default.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function createFetchRequestFromFastify(req) {
|
|
145
|
+
const requestBody = req.method === "GET" || req.method === "HEAD" ? void 0 : typeof req.body === "string" ? req.body : req.body ? JSON.stringify(req.body) : void 0;
|
|
146
|
+
const href = `${req.protocol}://${req.host}${req.raw.url ?? "/"}`;
|
|
147
|
+
return new Request(href, {
|
|
148
|
+
method: req.method,
|
|
149
|
+
headers: req.headers,
|
|
150
|
+
body: requestBody
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function startApiDevServer(port) {
|
|
154
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
155
|
+
const cedarConfig = (0, import_project_config.getConfig)();
|
|
156
|
+
const apiPort = port || cedarConfig.api.port || 8911;
|
|
157
|
+
const apiHost = cedarConfig.api.host || "::";
|
|
158
|
+
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
159
|
+
const normalizedBase = (0, import_vite.normalizePath)(cedarPaths.base);
|
|
160
|
+
const normalizedApiSrc = (0, import_vite.normalizePath)(cedarPaths.api.src);
|
|
161
|
+
const normalizedApiBase = (0, import_vite.normalizePath)(cedarPaths.api.base);
|
|
162
|
+
const viteServer = await createViteDevServer(
|
|
163
|
+
cedarPaths,
|
|
164
|
+
cedarConfig,
|
|
165
|
+
isEsm,
|
|
166
|
+
normalizedBase
|
|
167
|
+
);
|
|
168
|
+
console.log(import_ansis.default.dim.italic("Starting API dev server..."));
|
|
169
|
+
await loadApiFunctions(viteServer);
|
|
170
|
+
setupHmrHandlers(viteServer, normalizedApiSrc, normalizedApiBase);
|
|
171
|
+
const app = await createFastifyApp(apiPort, apiHost);
|
|
172
|
+
const close = async () => {
|
|
173
|
+
await app.close();
|
|
174
|
+
await viteServer.close();
|
|
175
|
+
};
|
|
176
|
+
return { viteServer, close };
|
|
177
|
+
}
|
|
178
|
+
async function createViteDevServer(cedarPaths, cedarConfig, projectIsEsm, normalizedBase) {
|
|
179
|
+
const babelPlugins = (0, import_babel_config.getApiSideBabelPlugins)({
|
|
180
|
+
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
181
|
+
projectIsEsm
|
|
182
|
+
});
|
|
183
|
+
const workspacePkgSourceMap = Object.fromEntries(
|
|
184
|
+
Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
|
|
185
|
+
([name, sourceFile]) => [name, (0, import_vite.normalizePath)(sourceFile)]
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
const viteServer = await (0, import_vite.createServer)({
|
|
189
|
+
configFile: false,
|
|
190
|
+
root: cedarPaths.api.base,
|
|
191
|
+
appType: "custom",
|
|
192
|
+
clearScreen: false,
|
|
193
|
+
logLevel: "warn",
|
|
194
|
+
server: {
|
|
195
|
+
middlewareMode: true
|
|
196
|
+
},
|
|
197
|
+
resolve: {
|
|
198
|
+
// Map workspace package names directly to their TypeScript source entry
|
|
199
|
+
// files. This is processed by Vite's built-in alias plugin (enforce:
|
|
200
|
+
// 'pre') which runs before vite:resolve and correctly intercepts imports
|
|
201
|
+
// in the SSR module runner context.
|
|
202
|
+
alias: workspacePkgSourceMap
|
|
203
|
+
},
|
|
204
|
+
plugins: [
|
|
205
|
+
{
|
|
206
|
+
name: "cedar-api-babel-transform",
|
|
207
|
+
async transform(_code, id) {
|
|
208
|
+
if (!/\.(ts|tsx|js|jsx)$/.test(id)) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (id.includes("node_modules")) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
if (!id.startsWith(normalizedBase)) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const result = await (0, import_babel_config.transformWithBabel)(id, babelPlugins);
|
|
219
|
+
if (!result?.code) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
code: result.code,
|
|
224
|
+
map: result.map ?? null
|
|
225
|
+
};
|
|
226
|
+
} catch (err) {
|
|
227
|
+
this.warn(
|
|
228
|
+
`[cedar-api-babel-transform] Failed to transform ${id}: ${String(err)}`
|
|
229
|
+
);
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
});
|
|
236
|
+
return viteServer;
|
|
237
|
+
}
|
|
238
|
+
function invalidateApiModules(viteServer, normalizedApiSrc) {
|
|
239
|
+
const invalidated = /* @__PURE__ */ new Set();
|
|
240
|
+
const invalidateWithImporters = (mod) => {
|
|
241
|
+
if (!mod || invalidated.has(mod.id ?? mod.url)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
invalidated.add(mod.id ?? mod.url);
|
|
245
|
+
viteServer.moduleGraph.invalidateModule(mod);
|
|
246
|
+
for (const importer of mod.importers) {
|
|
247
|
+
invalidateWithImporters(importer);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
for (const mod of viteServer.moduleGraph.idToModuleMap.values()) {
|
|
251
|
+
if (mod.id?.startsWith(normalizedApiSrc)) {
|
|
252
|
+
invalidateWithImporters(mod);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function setupHmrHandlers(viteServer, normalizedApiSrc, normalizedApiBase) {
|
|
257
|
+
viteServer.watcher.on("change", async (filePath) => {
|
|
258
|
+
const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
|
|
259
|
+
if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const displayPath = import_node_path.default.relative(normalizedApiBase, normalizedFilePath);
|
|
263
|
+
console.log(import_ansis.default.dim(`[change] ${displayPath}`));
|
|
264
|
+
const fileUrl = (0, import_node_url.pathToFileURL)(normalizedFilePath).href;
|
|
265
|
+
const mod = viteServer.moduleGraph.getModuleById(normalizedFilePath) ?? viteServer.moduleGraph.getModuleById(fileUrl);
|
|
266
|
+
if (mod) {
|
|
267
|
+
const invalidated = /* @__PURE__ */ new Set();
|
|
268
|
+
const invalidateWithImporters = (m) => {
|
|
269
|
+
if (!m || invalidated.has(m.id ?? m.url)) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
invalidated.add(m.id ?? m.url);
|
|
273
|
+
viteServer.moduleGraph.invalidateModule(m);
|
|
274
|
+
for (const importer of m.importers) {
|
|
275
|
+
invalidateWithImporters(importer);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
invalidateWithImporters(mod);
|
|
279
|
+
}
|
|
280
|
+
await loadApiFunctions(viteServer);
|
|
281
|
+
});
|
|
282
|
+
viteServer.watcher.on("add", async (filePath) => {
|
|
283
|
+
const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
|
|
284
|
+
if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
console.log(
|
|
288
|
+
import_ansis.default.dim(
|
|
289
|
+
`[add] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
invalidateApiModules(viteServer, normalizedApiSrc);
|
|
293
|
+
await loadApiFunctions(viteServer);
|
|
294
|
+
});
|
|
295
|
+
viteServer.watcher.on("unlink", async (filePath) => {
|
|
296
|
+
const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
|
|
297
|
+
if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
console.log(
|
|
301
|
+
import_ansis.default.dim(
|
|
302
|
+
`[unlink] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
invalidateApiModules(viteServer, normalizedApiSrc);
|
|
306
|
+
await loadApiFunctions(viteServer);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async function createFastifyApp(apiPort, apiHost) {
|
|
310
|
+
const logLevel = process.env.NODE_ENV === "development" ? "debug" : "info";
|
|
311
|
+
const app = (0, import_fastify.default)({ logger: { level: logLevel } });
|
|
312
|
+
await app.register(import_fastify_raw_body.default);
|
|
313
|
+
app.register(import_url_data.default);
|
|
314
|
+
app.addContentTypeParser(
|
|
315
|
+
["application/x-www-form-urlencoded", "multipart/form-data"],
|
|
316
|
+
{ parseAs: "string" },
|
|
317
|
+
app.defaultTextParser
|
|
318
|
+
);
|
|
319
|
+
const lambdaRequestHandler = async (req, reply) => {
|
|
320
|
+
const { routeName } = req.params;
|
|
321
|
+
const handler = LAMBDA_FUNCTIONS[routeName];
|
|
322
|
+
if (!handler) {
|
|
323
|
+
const errorMessage = `Function "${routeName}" was not found.`;
|
|
324
|
+
req.log.error(errorMessage);
|
|
325
|
+
reply.status(404);
|
|
326
|
+
reply.send({
|
|
327
|
+
error: errorMessage,
|
|
328
|
+
availableFunctions: Object.keys(LAMBDA_FUNCTIONS)
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
return (0, import_requestHandlers.requestHandler)(req, reply, handler);
|
|
333
|
+
};
|
|
334
|
+
const graphqlHandler = async (req, reply) => {
|
|
335
|
+
if (!graphqlYoga) {
|
|
336
|
+
return reply.status(503).send({ error: "GraphQL Yoga instance not initialized" });
|
|
337
|
+
}
|
|
338
|
+
const request = createFetchRequestFromFastify(req);
|
|
339
|
+
const yoga = graphqlYoga;
|
|
340
|
+
const response = await (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), async () => {
|
|
341
|
+
return yoga.handle(request, { req, reply });
|
|
342
|
+
});
|
|
343
|
+
return response;
|
|
344
|
+
};
|
|
345
|
+
app.all("/graphql", graphqlHandler);
|
|
346
|
+
app.all("/graphql/*", graphqlHandler);
|
|
347
|
+
app.all("/:routeName", lambdaRequestHandler);
|
|
348
|
+
app.all("/:routeName/*", lambdaRequestHandler);
|
|
349
|
+
app.addHook("onListen", (done) => {
|
|
350
|
+
const addr = app.server.address();
|
|
351
|
+
const listenPort = addr && typeof addr === "object" ? addr.port : apiPort;
|
|
352
|
+
console.log(
|
|
353
|
+
`API dev server listening at ${import_ansis.default.magenta(`http://localhost:${listenPort}/`)}`
|
|
354
|
+
);
|
|
355
|
+
console.log(
|
|
356
|
+
`GraphQL endpoint at ${import_ansis.default.magenta(`http://localhost:${listenPort}/graphql`)}`
|
|
357
|
+
);
|
|
358
|
+
done();
|
|
359
|
+
});
|
|
360
|
+
await app.listen({ port: apiPort, host: apiHost });
|
|
361
|
+
return app;
|
|
362
|
+
}
|
|
363
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
364
|
+
0 && (module.exports = {
|
|
365
|
+
startApiDevServer
|
|
366
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
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 buildUDApiServer_exports = {};
|
|
30
|
+
__export(buildUDApiServer_exports, {
|
|
31
|
+
buildUDApiServer: () => buildUDApiServer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(buildUDApiServer_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
36
|
+
const buildUDApiServer = async ({
|
|
37
|
+
verbose = false,
|
|
38
|
+
apiRootPath
|
|
39
|
+
} = {}) => {
|
|
40
|
+
const { build } = await import("vite");
|
|
41
|
+
const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
42
|
+
const { node } = await import("@universal-deploy/node/vite");
|
|
43
|
+
const rwPaths = (0, import_project_config.getPaths)();
|
|
44
|
+
const outDir = import_node_path.default.join(rwPaths.api.dist, "ud");
|
|
45
|
+
await build({
|
|
46
|
+
// No configFile — we configure everything inline so this build is
|
|
47
|
+
// self-contained and does not require a vite.config.ts in api/.
|
|
48
|
+
configFile: false,
|
|
49
|
+
envFile: false,
|
|
50
|
+
logLevel: verbose ? "info" : "warn",
|
|
51
|
+
plugins: [
|
|
52
|
+
// Registers virtual:cedar-api with @universal-deploy/store and resolves
|
|
53
|
+
// virtual:ud:catch-all → virtual:cedar-api → Cedar's aggregate fetchable.
|
|
54
|
+
cedarUniversalDeployPlugin({ apiRootPath }),
|
|
55
|
+
// Emits a self-contained Node server entry (api/dist/ud/index.js) that
|
|
56
|
+
// imports virtual:ud:catch-all and starts an srvx HTTP server.
|
|
57
|
+
// This is a Vite server-build concern, not Cedar HTML SSR.
|
|
58
|
+
...node()
|
|
59
|
+
],
|
|
60
|
+
// The ssr environment is the Vite mechanism for server-side builds.
|
|
61
|
+
// Reminder: "ssr" here means "server-side module execution", NOT
|
|
62
|
+
// Cedar HTML SSR / streaming / RSC.
|
|
63
|
+
environments: {
|
|
64
|
+
ssr: {
|
|
65
|
+
build: {
|
|
66
|
+
outDir,
|
|
67
|
+
// Ensure @universal-deploy/node is bundled into the output so the
|
|
68
|
+
// emitted entry is self-contained.
|
|
69
|
+
rollupOptions: {
|
|
70
|
+
output: {
|
|
71
|
+
// Produce a single-file entry where possible; srvx chunks are
|
|
72
|
+
// split by the node() plugin automatically.
|
|
73
|
+
entryFileNames: "[name].js"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
resolve: {
|
|
78
|
+
// Do not externalise @universal-deploy/node — the node() plugin
|
|
79
|
+
// requires it to be bundled into the server entry.
|
|
80
|
+
noExternal: ["@universal-deploy/node"]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
build: {
|
|
85
|
+
// This is a server (Node) build, not a browser build.
|
|
86
|
+
ssr: true
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
buildUDApiServer
|
|
93
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var import_vite = require("vite");
|
|
26
|
+
var import_yargs_parser = __toESM(require("yargs-parser"), 1);
|
|
27
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
28
|
+
var import_apiDevServer = require("./apiDevServer.js");
|
|
29
|
+
const startUnifiedDevServer = async () => {
|
|
30
|
+
const rwPaths = (0, import_project_config.getPaths)();
|
|
31
|
+
const cedarConfig = (0, import_project_config.getConfig)();
|
|
32
|
+
const configFile = rwPaths.web.viteConfig;
|
|
33
|
+
if (!configFile) {
|
|
34
|
+
throw new Error("Could not locate your web/vite.config.{js,ts} file");
|
|
35
|
+
}
|
|
36
|
+
const {
|
|
37
|
+
force: forceOptimize,
|
|
38
|
+
debug,
|
|
39
|
+
port: portArg,
|
|
40
|
+
apiPort: apiPortArg,
|
|
41
|
+
_: _positional,
|
|
42
|
+
...serverArgs
|
|
43
|
+
} = (0, import_yargs_parser.default)(process.argv.slice(2), {
|
|
44
|
+
boolean: ["https", "open", "strictPort", "force", "cors", "debug"],
|
|
45
|
+
number: ["port", "apiPort"]
|
|
46
|
+
});
|
|
47
|
+
const webPort = portArg ?? cedarConfig.web.port ?? 8910;
|
|
48
|
+
const apiPort = apiPortArg ?? cedarConfig.api.port ?? 8911;
|
|
49
|
+
const { close: closeApi } = await (0, import_apiDevServer.startApiDevServer)(apiPort);
|
|
50
|
+
const devServer = await (0, import_vite.createServer)({
|
|
51
|
+
configFile,
|
|
52
|
+
// env file is handled by Cedar's plugins
|
|
53
|
+
envFile: false,
|
|
54
|
+
optimizeDeps: {
|
|
55
|
+
// This is the only value that isn't a server option
|
|
56
|
+
force: forceOptimize
|
|
57
|
+
},
|
|
58
|
+
server: {
|
|
59
|
+
port: webPort,
|
|
60
|
+
...serverArgs
|
|
61
|
+
},
|
|
62
|
+
logLevel: debug ? "info" : void 0
|
|
63
|
+
});
|
|
64
|
+
await devServer.listen();
|
|
65
|
+
process.stdin.on("data", async (data) => {
|
|
66
|
+
const str = data.toString().trim().toLowerCase();
|
|
67
|
+
if (str === "rs" || str === "restart") {
|
|
68
|
+
await devServer.restart(true);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
devServer.printUrls();
|
|
72
|
+
if (debug) {
|
|
73
|
+
console.log("~~~ Vite Server Config ~~~");
|
|
74
|
+
console.log(JSON.stringify(devServer.config, null, 2));
|
|
75
|
+
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
76
|
+
}
|
|
77
|
+
const shutdown = async () => {
|
|
78
|
+
await devServer.close();
|
|
79
|
+
await closeApi();
|
|
80
|
+
process.exit(0);
|
|
81
|
+
};
|
|
82
|
+
process.on("SIGINT", shutdown);
|
|
83
|
+
process.on("SIGTERM", shutdown);
|
|
84
|
+
};
|
|
85
|
+
startUnifiedDevServer().catch((err) => {
|
|
86
|
+
console.error("Failed to start unified dev server:", err);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
cedar: () => cedar,
|
|
32
32
|
cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
|
|
33
33
|
cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
|
|
34
|
+
cedarDevDispatcherPlugin: () => import_vite_plugin_cedar_dev_dispatcher.cedarDevDispatcherPlugin,
|
|
34
35
|
cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
|
|
35
36
|
cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
|
|
36
37
|
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
@@ -39,6 +40,8 @@ __export(index_exports, {
|
|
|
39
40
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
40
41
|
cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
|
|
41
42
|
cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
|
|
43
|
+
cedarUniversalDeployPlugin: () => import_vite_plugin_cedar_universal_deploy.cedarUniversalDeployPlugin,
|
|
44
|
+
cedarWaitForApiServer: () => import_vite_plugin_cedar_wait_for_api_server2.cedarWaitForApiServer,
|
|
42
45
|
cedarjsJobPathInjectorPlugin: () => import_vite_plugin_cedarjs_job_path_injector.cedarjsJobPathInjectorPlugin,
|
|
43
46
|
cedarjsResolveCedarStyleImportsPlugin: () => import_vite_plugin_cedarjs_resolve_cedar_style_imports2.cedarjsResolveCedarStyleImportsPlugin,
|
|
44
47
|
default: () => index_default
|
|
@@ -70,6 +73,9 @@ var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugi
|
|
|
70
73
|
var import_vite_plugin_jsx_loader2 = require("./plugins/vite-plugin-jsx-loader.js");
|
|
71
74
|
var import_vite_plugin_merged_config2 = require("./plugins/vite-plugin-merged-config.js");
|
|
72
75
|
var import_vite_plugin_swap_apollo_provider2 = require("./plugins/vite-plugin-swap-apollo-provider.js");
|
|
76
|
+
var import_vite_plugin_cedar_universal_deploy = require("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
77
|
+
var import_vite_plugin_cedar_dev_dispatcher = require("./plugins/vite-plugin-cedar-dev-dispatcher.js");
|
|
78
|
+
var import_vite_plugin_cedar_wait_for_api_server2 = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
|
|
73
79
|
function cedar({ mode } = {}) {
|
|
74
80
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
75
81
|
const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
|
|
@@ -109,6 +115,7 @@ var index_default = cedar;
|
|
|
109
115
|
cedar,
|
|
110
116
|
cedarAutoImportsPlugin,
|
|
111
117
|
cedarCellTransform,
|
|
118
|
+
cedarDevDispatcherPlugin,
|
|
112
119
|
cedarEntryInjectionPlugin,
|
|
113
120
|
cedarHtmlEnvPlugin,
|
|
114
121
|
cedarImportDirPlugin,
|
|
@@ -117,6 +124,8 @@ var index_default = cedar;
|
|
|
117
124
|
cedarRemoveFromBundle,
|
|
118
125
|
cedarSwapApolloProvider,
|
|
119
126
|
cedarTransformJsAsJsx,
|
|
127
|
+
cedarUniversalDeployPlugin,
|
|
128
|
+
cedarWaitForApiServer,
|
|
120
129
|
cedarjsJobPathInjectorPlugin,
|
|
121
130
|
cedarjsResolveCedarStyleImportsPlugin
|
|
122
131
|
});
|
|
@@ -34,8 +34,10 @@ module.exports = __toCommonJS(getMergedConfig_exports);
|
|
|
34
34
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
35
|
var import_vite = require("vite");
|
|
36
36
|
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
var import_workspacePackageAliases = require("./workspacePackageAliases.js");
|
|
37
38
|
function getMergedConfig(cedarConfig, cedarPaths) {
|
|
38
39
|
return (userConfig, env) => {
|
|
40
|
+
const workspaceAliases = env.command === "serve" ? (0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig) : {};
|
|
39
41
|
let apiHost = process.env.REDWOOD_API_HOST;
|
|
40
42
|
apiHost ??= cedarConfig.api.host;
|
|
41
43
|
apiHost ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "127.0.0.1";
|
|
@@ -49,6 +51,9 @@ function getMergedConfig(cedarConfig, cedarPaths) {
|
|
|
49
51
|
}
|
|
50
52
|
const defaultCedarViteConfig = {
|
|
51
53
|
root: cedarPaths.web.src,
|
|
54
|
+
resolve: {
|
|
55
|
+
alias: workspaceAliases
|
|
56
|
+
},
|
|
52
57
|
// @MARK: when we have these aliases, the warnings from the FE server go
|
|
53
58
|
// away BUT, if you have imports like this:
|
|
54
59
|
// ```
|