@cedarjs/vite 5.0.7-next.338 → 5.0.7

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 (157) hide show
  1. package/bins/cedar-vite-dev.mjs +1 -14
  2. package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
  3. package/dist/api/vite-plugin-cedar-vitest-api-preset.js +0 -4
  4. package/dist/apiDevMiddleware.d.ts.map +1 -1
  5. package/dist/apiDevMiddleware.js +15 -117
  6. package/dist/buildApp.d.ts.map +1 -1
  7. package/dist/buildApp.js +18 -77
  8. package/dist/buildRouteHooks.d.ts.map +1 -1
  9. package/dist/buildRouteHooks.js +4 -36
  10. package/dist/bundled/react-server-dom-webpack.server.js +99 -192
  11. package/dist/cedar-unified-dev.d.ts +0 -19
  12. package/dist/cedar-unified-dev.d.ts.map +1 -1
  13. package/dist/cedar-unified-dev.js +9 -74
  14. package/dist/cjs/ClientRouter.d.ts +1 -0
  15. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +37 -0
  16. package/dist/cjs/apiDevMiddleware.js +371 -0
  17. package/dist/cjs/build/build.d.ts +1 -0
  18. package/dist/cjs/build/build.js +58 -0
  19. package/dist/cjs/buildApp.js +306 -0
  20. package/dist/cjs/buildFeServer.d.ts +1 -0
  21. package/dist/cjs/buildFeServer.js +63 -0
  22. package/dist/cjs/buildRouteHooks.js +80 -0
  23. package/dist/cjs/buildRouteManifest.js +92 -0
  24. package/dist/cjs/buildRscClientAndServer.js +54 -0
  25. package/dist/cjs/cedar-unified-dev.js +310 -0
  26. package/dist/cjs/client.d.ts +1 -0
  27. package/dist/cjs/clientSsr.d.ts +1 -0
  28. package/dist/cjs/devFeServer.js +157 -0
  29. package/dist/cjs/index.d.ts +1 -0
  30. package/dist/cjs/index.js +141 -0
  31. package/dist/cjs/lib/StatusError.js +37 -0
  32. package/dist/cjs/lib/entries.js +52 -0
  33. package/dist/cjs/lib/getMergedConfig.js +185 -0
  34. package/dist/cjs/lib/onWarn.js +36 -0
  35. package/dist/cjs/lib/registerFwGlobalsAndShims.js +102 -0
  36. package/dist/cjs/lib/workspacePackageAliases.js +107 -0
  37. package/dist/cjs/middleware/index.js +22 -0
  38. package/dist/cjs/middleware/invokeMiddleware.js +52 -0
  39. package/dist/cjs/middleware/register.js +105 -0
  40. package/dist/cjs/middleware/types.js +16 -0
  41. package/dist/cjs/package.json +1 -0
  42. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +107 -0
  43. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +183 -0
  44. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +341 -0
  45. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +95 -0
  46. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +107 -0
  47. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +67 -0
  48. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +118 -0
  49. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +43 -0
  50. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
  51. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +76 -0
  52. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
  53. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +346 -0
  54. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +134 -0
  55. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +134 -0
  56. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +106 -0
  57. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +42 -0
  58. package/dist/cjs/plugins/vite-plugin-merged-config.js +39 -0
  59. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +104 -0
  60. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +75 -0
  61. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +159 -0
  62. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +125 -0
  63. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +75 -0
  64. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +228 -0
  65. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +398 -0
  66. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +46 -0
  67. package/dist/cjs/rsc/rscBuildAnalyze.js +126 -0
  68. package/dist/cjs/rsc/rscBuildClient.js +91 -0
  69. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +56 -0
  70. package/dist/cjs/rsc/rscBuildEntriesFile.js +115 -0
  71. package/dist/cjs/rsc/rscBuildForServer.js +168 -0
  72. package/dist/cjs/rsc/rscBuildForSsr.js +173 -0
  73. package/dist/cjs/rsc/rscBuildRwEnvVars.js +56 -0
  74. package/dist/cjs/rsc/rscRenderer.js +165 -0
  75. package/dist/cjs/rsc/rscRequestHandler.js +162 -0
  76. package/dist/cjs/rsc/rscStudioHandlers.js +156 -0
  77. package/dist/cjs/runFeServer.js +165 -0
  78. package/dist/cjs/streaming/buildForStreamingServer.js +65 -0
  79. package/dist/cjs/streaming/collectCss.js +52 -0
  80. package/dist/cjs/streaming/createReactStreamingHandler.js +173 -0
  81. package/dist/cjs/streaming/streamHelpers.js +230 -0
  82. package/dist/cjs/streaming/transforms/bufferedTransform.js +61 -0
  83. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +34 -0
  84. package/dist/cjs/streaming/transforms/encode-decode.js +36 -0
  85. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +84 -0
  86. package/dist/cjs/streaming/triggerRouteHooks.js +96 -0
  87. package/dist/cjs/types.js +16 -0
  88. package/dist/cjs/utils.js +92 -0
  89. package/dist/devFeServer.js +8 -3
  90. package/dist/index.d.ts +4 -11
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +19 -51
  93. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  94. package/dist/lib/getMergedConfig.js +6 -16
  95. package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -1
  96. package/dist/lib/registerFwGlobalsAndShims.js +4 -14
  97. package/dist/package.json +1 -0
  98. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  99. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  100. package/dist/plugins/vite-plugin-cedar-auto-import.js +1 -8
  101. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  102. package/dist/plugins/vite-plugin-cedar-cell.js +1 -2
  103. package/dist/plugins/{vite-plugin-handler-als-wrapping.d.ts → vite-plugin-cedar-context-wrapping.d.ts} +12 -12
  104. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +1 -0
  105. package/dist/plugins/{vite-plugin-handler-als-wrapping.js → vite-plugin-cedar-context-wrapping.js} +16 -16
  106. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  107. package/dist/plugins/vite-plugin-cedar-import-dir.js +31 -44
  108. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +3 -0
  109. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +1 -0
  110. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +19 -0
  111. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  112. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +90 -92
  113. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +0 -29
  114. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -1
  115. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +81 -63
  116. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  117. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -14
  118. package/dist/plugins/vite-plugin-rsc-analyze.js +1 -2
  119. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +0 -3
  120. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  121. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  122. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  123. package/dist/rsc/rscBuildForSsr.js +5 -3
  124. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  125. package/dist/streaming/buildForStreamingServer.js +5 -3
  126. package/package.json +57 -47
  127. package/dist/jobsDevMiddleware.d.ts +0 -17
  128. package/dist/jobsDevMiddleware.d.ts.map +0 -1
  129. package/dist/jobsDevMiddleware.js +0 -106
  130. package/dist/lib/generateDiffSourceMap.d.ts +0 -18
  131. package/dist/lib/generateDiffSourceMap.d.ts.map +0 -1
  132. package/dist/lib/generateDiffSourceMap.js +0 -151
  133. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts +0 -13
  134. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts.map +0 -1
  135. package/dist/plugins/vite-plugin-cedar-api-import-guard.js +0 -17
  136. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +0 -3
  137. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +0 -1
  138. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +0 -43
  139. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +0 -12
  140. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +0 -1
  141. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +0 -35
  142. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +0 -29
  143. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +0 -1
  144. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +0 -76
  145. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +0 -42
  146. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +0 -1
  147. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +0 -103
  148. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +0 -28
  149. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +0 -1
  150. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +0 -67
  151. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +0 -28
  152. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +0 -1
  153. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +0 -247
  154. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +0 -39
  155. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +0 -1
  156. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +0 -200
  157. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +0 -1
@@ -3,39 +3,6 @@ import { createServer } from "vite";
3
3
  import yargsParser from "yargs-parser";
4
4
  import { getPaths, getConfig } from "@cedarjs/project-config";
5
5
  import { startApiDevMiddleware } from "./apiDevMiddleware.js";
6
- import { startJobsDevWorkers } from "./jobsDevMiddleware.js";
7
- const SHUTDOWN_TIMEOUT_MS = 5e3;
8
- function createShutdownHandler({
9
- close,
10
- timeoutMs = SHUTDOWN_TIMEOUT_MS,
11
- exit = (code) => process.exit(code),
12
- logger = console
13
- }) {
14
- let shuttingDown = false;
15
- return async function shutdown() {
16
- if (shuttingDown) {
17
- exit(0);
18
- return;
19
- }
20
- shuttingDown = true;
21
- const forceExitTimer = setTimeout(() => {
22
- logger.warn(
23
- `Dev server did not shut down within ${timeoutMs}ms. Forcing exit.`
24
- );
25
- exit(0);
26
- }, timeoutMs);
27
- forceExitTimer.unref();
28
- try {
29
- await close();
30
- } catch (e) {
31
- const message = e instanceof Error ? e.message : String(e);
32
- logger.error(`Error while shutting down the dev server: ${message}`);
33
- } finally {
34
- clearTimeout(forceExitTimer);
35
- }
36
- exit(0);
37
- };
38
- }
39
6
  function isViteInternalRequest(url) {
40
7
  const pathname = url.split("?")[0];
41
8
  return pathname.startsWith("/@") || pathname.startsWith("/__vite") || pathname.startsWith("/__hmr");
@@ -51,7 +18,6 @@ function parseCliArgs(argv = process.argv) {
51
18
  apiPort: _apiPortArg,
52
19
  "debug-port": debugPort,
53
20
  "debug-brk": debugBrk,
54
- jobs: jobsArg,
55
21
  _: _positional,
56
22
  ...serverArgs
57
23
  } = yargsParser(argv.slice(2), {
@@ -62,20 +28,11 @@ function parseCliArgs(argv = process.argv) {
62
28
  "force",
63
29
  "cors",
64
30
  "debug",
65
- "debug-brk",
66
- "jobs"
31
+ "debug-brk"
67
32
  ],
68
33
  number: ["port", "apiPort", "debug-port"]
69
34
  });
70
- return {
71
- forceOptimize,
72
- debug,
73
- portArg,
74
- debugPort,
75
- debugBrk,
76
- jobsArg,
77
- serverArgs
78
- };
35
+ return { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs };
79
36
  }
80
37
  async function clearPendingPause() {
81
38
  const inspector = await import("node:inspector");
@@ -223,29 +180,13 @@ async function startUnifiedDevServer() {
223
180
  if (!configFile) {
224
181
  throw new Error("Could not locate your web/vite.config.{js,ts} file");
225
182
  }
226
- const {
227
- forceOptimize,
228
- debug,
229
- portArg,
230
- debugPort,
231
- debugBrk,
232
- jobsArg,
233
- serverArgs
234
- } = parseCliArgs();
235
- if (serverArgs.open === void 0 && !process.stdout.isTTY) {
236
- serverArgs.open = false;
237
- }
183
+ const { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs } = parseCliArgs();
238
184
  if (debugPort !== void 0) {
239
185
  await openDebugger(debugPort, debugBrk);
240
186
  }
241
187
  const webPort = portArg ?? cedarConfig.web.port ?? 8910;
242
- const {
243
- viteServer: apiViteServer,
244
- close: closeApi,
245
- handler: apiHandler
246
- } = await startApiDevMiddleware();
188
+ const { close: closeApi, handler: apiHandler } = await startApiDevMiddleware();
247
189
  const apiAdapter = createServerAdapter(apiHandler);
248
- const jobsWorkerPool = jobsArg === false ? null : await startJobsDevWorkers(apiViteServer);
249
190
  const devServer = await createServer({
250
191
  configFile,
251
192
  // env file is handled by Cedar's plugins
@@ -318,21 +259,15 @@ async function startUnifiedDevServer() {
318
259
  console.log(JSON.stringify(devServer.config, null, 2));
319
260
  console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~");
320
261
  }
321
- const shutdown = createShutdownHandler({
322
- close: async () => {
323
- await devServer.close();
324
- try {
325
- await jobsWorkerPool?.stop();
326
- } finally {
327
- await closeApi();
328
- }
329
- }
330
- });
262
+ const shutdown = async () => {
263
+ await devServer.close();
264
+ await closeApi();
265
+ process.exit(0);
266
+ };
331
267
  process.on("SIGINT", shutdown);
332
268
  process.on("SIGTERM", shutdown);
333
269
  }
334
270
  export {
335
- createShutdownHandler,
336
271
  openDebugger,
337
272
  parseCliArgs,
338
273
  startUnifiedDevServer
@@ -0,0 +1 @@
1
+ export type * from "../ClientRouter.d.ts"
@@ -0,0 +1,37 @@
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_vitest_api_preset_exports = {};
20
+ __export(vite_plugin_cedar_vitest_api_preset_exports, {
21
+ cedarVitestPreset: () => cedarVitestPreset
22
+ });
23
+ module.exports = __toCommonJS(vite_plugin_cedar_vitest_api_preset_exports);
24
+ var import_vitest = require("@cedarjs/testing/api/vitest");
25
+ var import_vite_plugin_cedarjs_resolve_cedar_style_imports = require("../plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
26
+ function cedarVitestPreset() {
27
+ return [
28
+ (0, import_vitest.cedarVitestApiConfigPlugin)(),
29
+ (0, import_vitest.autoImportsPlugin)(),
30
+ (0, import_vite_plugin_cedarjs_resolve_cedar_style_imports.cedarjsResolveCedarStyleImportsPlugin)(),
31
+ (0, import_vitest.trackDbImportsPlugin)()
32
+ ];
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ cedarVitestPreset
37
+ });
@@ -0,0 +1,371 @@
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 apiDevMiddleware_exports = {};
30
+ __export(apiDevMiddleware_exports, {
31
+ createApiFetchHandler: () => createApiFetchHandler,
32
+ createApiViteServer: () => createApiViteServer,
33
+ loadApiFunctions: () => loadApiFunctions,
34
+ setupHmrHandlers: () => setupHmrHandlers,
35
+ startApiDevMiddleware: () => startApiDevMiddleware
36
+ });
37
+ module.exports = __toCommonJS(apiDevMiddleware_exports);
38
+ var import_promises = require("node:fs/promises");
39
+ var import_node_path = __toESM(require("node:path"), 1);
40
+ var import_node_url = require("node:url");
41
+ var import_ansis = __toESM(require("ansis"), 1);
42
+ var import_vite = require("vite");
43
+ var import_runtime = require("@cedarjs/api/runtime");
44
+ var import_babel_config = require("@cedarjs/babel-config");
45
+ var import_store = require("@cedarjs/context/dist/store");
46
+ var import_graphql_server = require("@cedarjs/graphql-server");
47
+ var import_project_config = require("@cedarjs/project-config");
48
+ var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
49
+ const LAMBDA_FUNCTIONS = {};
50
+ let graphqlYoga = null;
51
+ let loadApiFunctionsInFlight = null;
52
+ let needsReloadAfterInFlight = false;
53
+ async function loadApiFunctions(viteServer) {
54
+ if (loadApiFunctionsInFlight) {
55
+ needsReloadAfterInFlight = true;
56
+ return;
57
+ }
58
+ do {
59
+ needsReloadAfterInFlight = false;
60
+ loadApiFunctionsInFlight = internalLoadApiFunctions(viteServer);
61
+ try {
62
+ await loadApiFunctionsInFlight;
63
+ } finally {
64
+ loadApiFunctionsInFlight = null;
65
+ }
66
+ } while (needsReloadAfterInFlight);
67
+ }
68
+ async function internalLoadApiFunctions(viteServer) {
69
+ const cedarPaths = (0, import_project_config.getPaths)();
70
+ for (const key of Object.keys(LAMBDA_FUNCTIONS)) {
71
+ delete LAMBDA_FUNCTIONS[key];
72
+ }
73
+ let srcFunctions = [];
74
+ try {
75
+ srcFunctions = await Array.fromAsync(
76
+ (0, import_promises.glob)("**/*.{ts,tsx,js,jsx}", {
77
+ cwd: cedarPaths.api.functions,
78
+ exclude: [
79
+ "**/*.test.{ts,tsx,js,jsx}",
80
+ "**/*.scenarios.{ts,tsx,js,jsx}",
81
+ "**/*.fixtures.{ts,tsx,js,jsx}",
82
+ "**/*.d.ts"
83
+ ]
84
+ }),
85
+ (entry) => import_node_path.default.join(cedarPaths.api.functions, entry)
86
+ );
87
+ } catch {
88
+ srcFunctions = [];
89
+ }
90
+ console.log(import_ansis.default.dim.italic("Importing Server Functions... "));
91
+ const tsImport = Date.now();
92
+ let extractedGraphqlOptions = null;
93
+ const imports = srcFunctions.map(async (fnPath) => {
94
+ const ts = Date.now();
95
+ const routeName = import_node_path.default.basename(fnPath).replace(/\.(ts|tsx|js|jsx)$/, "");
96
+ try {
97
+ const mod = await viteServer.ssrLoadModule((0, import_node_url.pathToFileURL)(fnPath).href);
98
+ const cedarHandler = (() => {
99
+ if ("handleRequest" in mod) {
100
+ return mod.handleRequest;
101
+ }
102
+ if ("default" in mod && mod.default && "handleRequest" in mod.default) {
103
+ return mod.default.handleRequest;
104
+ }
105
+ let legacyHandler;
106
+ if ("handler" in mod) {
107
+ legacyHandler = mod.handler;
108
+ } else if ("default" in mod && mod.default && "handler" in mod.default) {
109
+ legacyHandler = mod.default.handler;
110
+ }
111
+ if (legacyHandler) {
112
+ return (0, import_runtime.wrapLegacyHandler)(legacyHandler);
113
+ }
114
+ return void 0;
115
+ })();
116
+ if (cedarHandler) {
117
+ LAMBDA_FUNCTIONS[routeName] = cedarHandler;
118
+ console.log(
119
+ import_ansis.default.magenta("/" + routeName),
120
+ import_ansis.default.dim.italic(Date.now() - ts + " ms")
121
+ );
122
+ } else {
123
+ console.warn(
124
+ `[apiDevMiddleware] No handler or handleRequest export found in function: ${fnPath}`
125
+ );
126
+ }
127
+ if (routeName === "graphql" && "__cedar_graphqlOptions" in mod) {
128
+ extractedGraphqlOptions = mod.__cedar_graphqlOptions;
129
+ }
130
+ } catch (err) {
131
+ viteServer.ssrFixStacktrace(err);
132
+ console.error(
133
+ `[apiDevMiddleware] Failed to load function "${routeName}" from ${fnPath}:`,
134
+ err
135
+ );
136
+ }
137
+ });
138
+ await Promise.all(imports);
139
+ if (extractedGraphqlOptions) {
140
+ const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(extractedGraphqlOptions);
141
+ graphqlYoga = yoga;
142
+ } else {
143
+ graphqlYoga = null;
144
+ }
145
+ console.log(
146
+ import_ansis.default.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
147
+ );
148
+ }
149
+ async function createApiViteServer() {
150
+ const cedarPaths = (0, import_project_config.getPaths)();
151
+ const cedarConfig = (0, import_project_config.getConfig)();
152
+ const isEsm = (0, import_project_config.projectSideIsEsm)("api");
153
+ const normalizedBase = (0, import_vite.normalizePath)(cedarPaths.base);
154
+ const babelPlugins = (0, import_babel_config.getApiSideBabelPlugins)({
155
+ openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
156
+ projectIsEsm: isEsm
157
+ });
158
+ const workspacePkgSourceMap = Object.fromEntries(
159
+ Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
160
+ ([name, sourceFile]) => [name, (0, import_vite.normalizePath)(sourceFile)]
161
+ )
162
+ );
163
+ const { createServer: createViteServer } = await import("vite");
164
+ return createViteServer({
165
+ configFile: false,
166
+ root: cedarPaths.api.base,
167
+ appType: "custom",
168
+ clearScreen: false,
169
+ logLevel: "warn",
170
+ server: {
171
+ middlewareMode: true
172
+ },
173
+ resolve: {
174
+ alias: workspacePkgSourceMap
175
+ },
176
+ plugins: [
177
+ {
178
+ name: "cedar-api-babel-transform",
179
+ enforce: "pre",
180
+ async transform(code, id) {
181
+ if (!/\.(ts|tsx|js|jsx)$/.test(id)) {
182
+ return null;
183
+ }
184
+ if (id.includes("node_modules")) {
185
+ return null;
186
+ }
187
+ if (!id.startsWith(normalizedBase)) {
188
+ return null;
189
+ }
190
+ try {
191
+ const result = await (0, import_babel_config.transformWithBabel)(
192
+ code,
193
+ id,
194
+ babelPlugins,
195
+ true
196
+ );
197
+ if (!result?.code) {
198
+ return null;
199
+ }
200
+ return {
201
+ code: result.code,
202
+ map: result.map ?? null
203
+ };
204
+ } catch (err) {
205
+ this.warn(
206
+ `[cedar-api-babel-transform] Failed to transform ${id}: ${String(err)}`
207
+ );
208
+ return null;
209
+ }
210
+ }
211
+ }
212
+ ]
213
+ });
214
+ }
215
+ function invalidateApiModules(viteServer, normalizedApiSrc) {
216
+ const invalidated = /* @__PURE__ */ new Set();
217
+ const invalidateWithImporters = (mod) => {
218
+ if (!mod || invalidated.has(mod.id ?? mod.url)) {
219
+ return;
220
+ }
221
+ invalidated.add(mod.id ?? mod.url);
222
+ viteServer.moduleGraph.invalidateModule(mod);
223
+ for (const importer of mod.importers) {
224
+ invalidateWithImporters(importer);
225
+ }
226
+ };
227
+ for (const mod of viteServer.moduleGraph.idToModuleMap.values()) {
228
+ if (mod.id?.startsWith(normalizedApiSrc)) {
229
+ invalidateWithImporters(mod);
230
+ }
231
+ }
232
+ }
233
+ function setupHmrHandlers(viteServer) {
234
+ const cedarPaths = (0, import_project_config.getPaths)();
235
+ const normalizedApiSrc = (0, import_vite.normalizePath)(cedarPaths.api.src);
236
+ const normalizedApiBase = (0, import_vite.normalizePath)(cedarPaths.api.base);
237
+ viteServer.watcher.on("change", async (filePath) => {
238
+ const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
239
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
240
+ return;
241
+ }
242
+ const displayPath = import_node_path.default.relative(normalizedApiBase, normalizedFilePath);
243
+ console.log(import_ansis.default.dim(`[change] ${displayPath}`));
244
+ const fileUrl = (0, import_node_url.pathToFileURL)(normalizedFilePath).href;
245
+ const mod = viteServer.moduleGraph.getModuleById(normalizedFilePath) ?? viteServer.moduleGraph.getModuleById(fileUrl);
246
+ if (mod) {
247
+ const invalidated = /* @__PURE__ */ new Set();
248
+ const invalidateWithImporters = (m) => {
249
+ if (!m || invalidated.has(m.id ?? m.url)) {
250
+ return;
251
+ }
252
+ invalidated.add(m.id ?? m.url);
253
+ viteServer.moduleGraph.invalidateModule(m);
254
+ for (const importer of m.importers) {
255
+ invalidateWithImporters(importer);
256
+ }
257
+ };
258
+ invalidateWithImporters(mod);
259
+ }
260
+ await loadApiFunctions(viteServer);
261
+ });
262
+ viteServer.watcher.on("add", async (filePath) => {
263
+ const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
264
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
265
+ return;
266
+ }
267
+ console.log(
268
+ import_ansis.default.dim(
269
+ `[add] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
270
+ )
271
+ );
272
+ invalidateApiModules(viteServer, normalizedApiSrc);
273
+ await loadApiFunctions(viteServer);
274
+ });
275
+ viteServer.watcher.on("unlink", async (filePath) => {
276
+ const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
277
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
278
+ return;
279
+ }
280
+ console.log(
281
+ import_ansis.default.dim(
282
+ `[unlink] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
283
+ )
284
+ );
285
+ invalidateApiModules(viteServer, normalizedApiSrc);
286
+ await loadApiFunctions(viteServer);
287
+ });
288
+ }
289
+ function createApiFetchHandler() {
290
+ const cedarConfig = (0, import_project_config.getConfig)();
291
+ const apiUrlPrefix = cedarConfig.web.apiUrl.replace(/\/$/, "");
292
+ return async (request) => {
293
+ const url = new URL(request.url);
294
+ let pathname = url.pathname;
295
+ if (pathname.startsWith(apiUrlPrefix + "/")) {
296
+ pathname = pathname.slice(apiUrlPrefix.length);
297
+ } else if (pathname === apiUrlPrefix) {
298
+ pathname = "/";
299
+ }
300
+ if (pathname === "/graphql" || pathname.startsWith("/graphql/")) {
301
+ if (!graphqlYoga) {
302
+ return new Response(
303
+ JSON.stringify({ error: "GraphQL Yoga instance not initialized" }),
304
+ { status: 503, headers: { "Content-Type": "application/json" } }
305
+ );
306
+ }
307
+ const yoga = graphqlYoga;
308
+ return (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), async () => {
309
+ try {
310
+ return await yoga.handle(request, { request });
311
+ } catch (e) {
312
+ if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
313
+ return new Response(null, { status: 499 });
314
+ }
315
+ throw e;
316
+ }
317
+ });
318
+ }
319
+ const match = pathname.match(/^\/([^/]+)(?:\/.*)?$/);
320
+ if (!match) {
321
+ return new Response("Not Found", { status: 404 });
322
+ }
323
+ const routeName = match[1];
324
+ const handler = LAMBDA_FUNCTIONS[routeName];
325
+ if (!handler) {
326
+ return new Response(
327
+ JSON.stringify({
328
+ error: `Function "${routeName}" was not found.`,
329
+ availableFunctions: Object.keys(LAMBDA_FUNCTIONS)
330
+ }),
331
+ { status: 404, headers: { "Content-Type": "application/json" } }
332
+ );
333
+ }
334
+ try {
335
+ const ctx = await (0, import_runtime.buildCedarContext)(request, {
336
+ params: { routeName }
337
+ });
338
+ return await handler(request, ctx);
339
+ } catch (err) {
340
+ console.error(
341
+ `[apiDevMiddleware] Error handling function "${routeName}":`,
342
+ err
343
+ );
344
+ return new Response(
345
+ JSON.stringify({
346
+ error: err instanceof Error ? err.message : "Internal Server Error"
347
+ }),
348
+ { status: 500, headers: { "Content-Type": "application/json" } }
349
+ );
350
+ }
351
+ };
352
+ }
353
+ async function startApiDevMiddleware() {
354
+ const viteServer = await createApiViteServer();
355
+ console.log(import_ansis.default.dim.italic("Starting API dev server..."));
356
+ await loadApiFunctions(viteServer);
357
+ setupHmrHandlers(viteServer);
358
+ const close = async () => {
359
+ await viteServer.close();
360
+ };
361
+ const handler = createApiFetchHandler();
362
+ return { viteServer, close, handler };
363
+ }
364
+ // Annotate the CommonJS export names for ESM import in node:
365
+ 0 && (module.exports = {
366
+ createApiFetchHandler,
367
+ createApiViteServer,
368
+ loadApiFunctions,
369
+ setupHmrHandlers,
370
+ startApiDevMiddleware
371
+ });
@@ -0,0 +1 @@
1
+ export type * from "../../build/build.d.ts"
@@ -0,0 +1,58 @@
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 build_exports = {};
30
+ __export(build_exports, {
31
+ buildCedarApp: () => import_buildApp.buildCedarApp,
32
+ buildWeb: () => buildWeb
33
+ });
34
+ module.exports = __toCommonJS(build_exports);
35
+ var import_project_config = require("@cedarjs/project-config");
36
+ var import_buildApp = require("../buildApp.js");
37
+ const buildWeb = async ({ verbose }) => {
38
+ const { build } = await import("vite");
39
+ const viteConfig = (0, import_project_config.getPaths)().web.viteConfig;
40
+ if (process.cwd() !== (0, import_project_config.getPaths)().web.base) {
41
+ throw new Error(
42
+ "Looks like you are running the command from the wrong dir, this can lead to unintended consequences on CSS processing"
43
+ );
44
+ }
45
+ if (!viteConfig) {
46
+ throw new Error("Could not locate your web/vite.config.{js,ts} file");
47
+ }
48
+ return build({
49
+ configFile: viteConfig,
50
+ envFile: false,
51
+ logLevel: verbose ? "info" : "warn"
52
+ });
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ buildCedarApp,
57
+ buildWeb
58
+ });