@cedarjs/vite 5.0.4-next.167 → 5.0.4

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 (143) hide show
  1. package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
  2. package/dist/api/vite-plugin-cedar-vitest-api-preset.js +0 -4
  3. package/dist/apiDevMiddleware.d.ts.map +1 -1
  4. package/dist/apiDevMiddleware.js +9 -105
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +18 -79
  7. package/dist/buildRouteHooks.d.ts.map +1 -1
  8. package/dist/buildRouteHooks.js +4 -36
  9. package/dist/bundled/react-server-dom-webpack.server.js +99 -192
  10. package/dist/cedar-unified-dev.d.ts +0 -18
  11. package/dist/cedar-unified-dev.d.ts.map +1 -1
  12. package/dist/cedar-unified-dev.js +5 -39
  13. package/dist/cjs/ClientRouter.d.ts +1 -0
  14. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +37 -0
  15. package/dist/cjs/apiDevMiddleware.js +371 -0
  16. package/dist/cjs/build/build.d.ts +1 -0
  17. package/dist/cjs/build/build.js +58 -0
  18. package/dist/cjs/buildApp.js +306 -0
  19. package/dist/cjs/buildFeServer.d.ts +1 -0
  20. package/dist/cjs/buildFeServer.js +63 -0
  21. package/dist/cjs/buildRouteHooks.js +80 -0
  22. package/dist/cjs/buildRouteManifest.js +92 -0
  23. package/dist/cjs/buildRscClientAndServer.js +54 -0
  24. package/dist/cjs/cedar-unified-dev.js +310 -0
  25. package/dist/cjs/client.d.ts +1 -0
  26. package/dist/cjs/clientSsr.d.ts +1 -0
  27. package/dist/cjs/devFeServer.js +157 -0
  28. package/dist/cjs/index.d.ts +1 -0
  29. package/dist/cjs/index.js +141 -0
  30. package/dist/cjs/lib/StatusError.js +37 -0
  31. package/dist/cjs/lib/entries.js +52 -0
  32. package/dist/cjs/lib/getMergedConfig.js +185 -0
  33. package/dist/cjs/lib/onWarn.js +36 -0
  34. package/dist/cjs/lib/registerFwGlobalsAndShims.js +102 -0
  35. package/dist/cjs/lib/workspacePackageAliases.js +107 -0
  36. package/dist/cjs/middleware/index.js +22 -0
  37. package/dist/cjs/middleware/invokeMiddleware.js +52 -0
  38. package/dist/cjs/middleware/register.js +105 -0
  39. package/dist/cjs/middleware/types.js +16 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +107 -0
  42. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +183 -0
  43. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +341 -0
  44. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +95 -0
  45. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +107 -0
  46. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +67 -0
  47. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +118 -0
  48. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +43 -0
  49. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
  50. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +76 -0
  51. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
  52. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +346 -0
  53. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +134 -0
  54. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +134 -0
  55. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +106 -0
  56. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +42 -0
  57. package/dist/cjs/plugins/vite-plugin-merged-config.js +39 -0
  58. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +104 -0
  59. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +75 -0
  60. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +159 -0
  61. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +125 -0
  62. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +75 -0
  63. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +228 -0
  64. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +398 -0
  65. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +46 -0
  66. package/dist/cjs/rsc/rscBuildAnalyze.js +126 -0
  67. package/dist/cjs/rsc/rscBuildClient.js +91 -0
  68. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +56 -0
  69. package/dist/cjs/rsc/rscBuildEntriesFile.js +115 -0
  70. package/dist/cjs/rsc/rscBuildForServer.js +168 -0
  71. package/dist/cjs/rsc/rscBuildForSsr.js +173 -0
  72. package/dist/cjs/rsc/rscBuildRwEnvVars.js +56 -0
  73. package/dist/cjs/rsc/rscRenderer.js +165 -0
  74. package/dist/cjs/rsc/rscRequestHandler.js +162 -0
  75. package/dist/cjs/rsc/rscStudioHandlers.js +156 -0
  76. package/dist/cjs/runFeServer.js +165 -0
  77. package/dist/cjs/streaming/buildForStreamingServer.js +65 -0
  78. package/dist/cjs/streaming/collectCss.js +52 -0
  79. package/dist/cjs/streaming/createReactStreamingHandler.js +173 -0
  80. package/dist/cjs/streaming/streamHelpers.js +230 -0
  81. package/dist/cjs/streaming/transforms/bufferedTransform.js +61 -0
  82. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +34 -0
  83. package/dist/cjs/streaming/transforms/encode-decode.js +36 -0
  84. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +84 -0
  85. package/dist/cjs/streaming/triggerRouteHooks.js +96 -0
  86. package/dist/cjs/types.js +16 -0
  87. package/dist/cjs/utils.js +92 -0
  88. package/dist/devFeServer.js +8 -3
  89. package/dist/index.d.ts +4 -10
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +19 -45
  92. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  93. package/dist/lib/getMergedConfig.js +0 -4
  94. package/dist/package.json +1 -0
  95. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  96. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  97. package/dist/plugins/vite-plugin-cedar-auto-import.js +1 -8
  98. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  99. package/dist/plugins/vite-plugin-cedar-cell.js +1 -2
  100. package/dist/plugins/{vite-plugin-handler-als-wrapping.d.ts → vite-plugin-cedar-context-wrapping.d.ts} +12 -12
  101. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +1 -0
  102. package/dist/plugins/{vite-plugin-handler-als-wrapping.js → vite-plugin-cedar-context-wrapping.js} +16 -16
  103. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  104. package/dist/plugins/vite-plugin-cedar-import-dir.js +15 -33
  105. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +3 -0
  106. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +1 -0
  107. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +19 -0
  108. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
  109. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  110. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -14
  111. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +0 -3
  112. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  113. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  114. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  115. package/dist/rsc/rscBuildForSsr.js +5 -3
  116. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  117. package/dist/streaming/buildForStreamingServer.js +5 -3
  118. package/package.json +52 -42
  119. package/dist/lib/generateDiffSourceMap.d.ts +0 -18
  120. package/dist/lib/generateDiffSourceMap.d.ts.map +0 -1
  121. package/dist/lib/generateDiffSourceMap.js +0 -151
  122. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +0 -3
  123. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +0 -1
  124. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +0 -43
  125. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +0 -12
  126. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +0 -1
  127. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +0 -35
  128. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +0 -29
  129. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +0 -1
  130. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +0 -76
  131. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +0 -42
  132. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +0 -1
  133. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +0 -93
  134. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +0 -28
  135. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +0 -1
  136. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +0 -67
  137. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +0 -28
  138. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +0 -1
  139. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +0 -247
  140. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +0 -39
  141. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +0 -1
  142. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +0 -200
  143. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +0 -1
@@ -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
+ });