@cedarjs/vite 9.0.0-canary.1784 → 9.0.0-canary.3124

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 (215) hide show
  1. package/bins/cedar-unified-dev.mjs +7 -0
  2. package/bins/{rw-vite-dev.mjs → cedar-vite-dev.mjs} +14 -1
  3. package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
  4. package/dist/api/vite-plugin-cedar-vitest-api-preset.js +6 -2
  5. package/dist/apiDevMiddleware.d.ts +15 -0
  6. package/dist/apiDevMiddleware.d.ts.map +1 -0
  7. package/dist/apiDevMiddleware.js +435 -0
  8. package/dist/build/build.d.ts +1 -1
  9. package/dist/build/build.d.ts.map +1 -1
  10. package/dist/build/build.js +2 -0
  11. package/dist/buildApp.d.ts +16 -0
  12. package/dist/buildApp.d.ts.map +1 -0
  13. package/dist/buildApp.js +330 -0
  14. package/dist/buildFeServer.d.ts.map +1 -1
  15. package/dist/buildFeServer.js +1 -1
  16. package/dist/buildRouteHooks.d.ts +17 -0
  17. package/dist/buildRouteHooks.d.ts.map +1 -1
  18. package/dist/buildRouteHooks.js +90 -35
  19. package/dist/buildRouteManifest.d.ts.map +1 -1
  20. package/dist/buildRouteManifest.js +3 -13
  21. package/dist/bundled/react-server-dom-webpack.server.js +280 -173
  22. package/dist/cedar-unified-dev.d.ts +33 -0
  23. package/dist/cedar-unified-dev.d.ts.map +1 -0
  24. package/dist/cedar-unified-dev.js +339 -0
  25. package/dist/devFeServer.d.ts +1 -0
  26. package/dist/devFeServer.js +51 -45
  27. package/dist/index.d.ts +17 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +71 -27
  30. package/dist/jobsDevMiddleware.d.ts +17 -0
  31. package/dist/jobsDevMiddleware.d.ts.map +1 -0
  32. package/dist/jobsDevMiddleware.js +106 -0
  33. package/dist/lib/StatusError.js +1 -0
  34. package/dist/lib/entries.d.ts.map +1 -1
  35. package/dist/lib/entries.js +3 -4
  36. package/dist/lib/generateDiffSourceMap.d.ts +18 -0
  37. package/dist/lib/generateDiffSourceMap.d.ts.map +1 -0
  38. package/dist/lib/generateDiffSourceMap.js +151 -0
  39. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  40. package/dist/lib/getMergedConfig.js +32 -14
  41. package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -1
  42. package/dist/lib/registerFwGlobalsAndShims.js +18 -6
  43. package/dist/lib/workspacePackageAliases.d.ts +18 -0
  44. package/dist/lib/workspacePackageAliases.d.ts.map +1 -0
  45. package/dist/lib/workspacePackageAliases.js +73 -0
  46. package/dist/middleware/types.d.ts +4 -1
  47. package/dist/middleware/types.d.ts.map +1 -1
  48. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts +13 -0
  49. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts.map +1 -0
  50. package/dist/plugins/vite-plugin-cedar-api-import-guard.js +17 -0
  51. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  52. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  53. package/dist/plugins/vite-plugin-cedar-auto-import.js +8 -1
  54. package/dist/plugins/vite-plugin-cedar-cell.d.ts +2 -1
  55. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  56. package/dist/plugins/vite-plugin-cedar-cell.js +32 -12
  57. package/dist/plugins/vite-plugin-cedar-cjs-compat.d.ts +23 -0
  58. package/dist/plugins/vite-plugin-cedar-cjs-compat.d.ts.map +1 -0
  59. package/dist/plugins/vite-plugin-cedar-cjs-compat.js +307 -0
  60. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  61. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  62. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  63. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +12 -0
  64. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +1 -0
  65. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +35 -0
  66. package/dist/plugins/vite-plugin-cedar-entry-injection.d.ts.map +1 -1
  67. package/dist/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  68. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  69. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  70. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  71. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +42 -0
  72. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  73. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +103 -0
  74. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  75. package/dist/plugins/vite-plugin-cedar-import-dir.js +44 -31
  76. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +28 -0
  77. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +1 -0
  78. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +67 -0
  79. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +28 -0
  80. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +1 -0
  81. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +247 -0
  82. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
  83. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
  84. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
  85. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts +15 -0
  86. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
  87. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +37 -0
  88. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +24 -0
  89. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +1 -0
  90. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +98 -0
  91. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts +6 -0
  92. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -0
  93. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +312 -0
  94. package/dist/plugins/vite-plugin-cedar-wait-for-api-server.d.ts.map +1 -1
  95. package/dist/plugins/vite-plugin-cedar-wait-for-api-server.js +2 -1
  96. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +29 -0
  97. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -1
  98. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +63 -81
  99. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts +3 -0
  100. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -0
  101. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +86 -0
  102. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts +40 -0
  103. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  104. package/dist/plugins/vite-plugin-handler-als-wrapping.js +57 -0
  105. package/dist/plugins/vite-plugin-rsc-analyze.js +2 -1
  106. package/dist/plugins/vite-plugin-rsc-routes-auto-loader.js +3 -3
  107. package/dist/plugins/vite-plugin-rsc-routes-imports.js +3 -3
  108. package/dist/plugins/vite-plugin-rsc-transform-client.js +1 -0
  109. package/dist/plugins/vite-plugin-rsc-transform-server.js +3 -2
  110. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +3 -0
  111. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  112. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  113. package/dist/rsc/rscBuildAnalyze.d.ts.map +1 -1
  114. package/dist/rsc/rscBuildAnalyze.js +12 -2
  115. package/dist/rsc/rscBuildClient.js +1 -1
  116. package/dist/rsc/rscBuildEntriesFile.js +2 -2
  117. package/dist/rsc/rscBuildForServer.d.ts.map +1 -1
  118. package/dist/rsc/rscBuildForServer.js +14 -3
  119. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  120. package/dist/rsc/rscBuildForSsr.js +15 -13
  121. package/dist/rsc/rscRenderer.js +10 -10
  122. package/dist/rsc/rscStudioHandlers.d.ts.map +1 -1
  123. package/dist/rsc/rscStudioHandlers.js +2 -1
  124. package/dist/rsc/utils.js +4 -4
  125. package/dist/runFeServer.d.ts +1 -0
  126. package/dist/runFeServer.d.ts.map +1 -1
  127. package/dist/runFeServer.js +5 -4
  128. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  129. package/dist/streaming/buildForStreamingServer.js +3 -5
  130. package/dist/streaming/streamHelpers.d.ts +6 -1
  131. package/dist/streaming/streamHelpers.d.ts.map +1 -1
  132. package/dist/streaming/streamHelpers.js +17 -17
  133. package/dist/utils.d.ts.map +1 -1
  134. package/dist/utils.js +4 -3
  135. package/package.json +80 -65
  136. package/LICENSE +0 -21
  137. package/dist/cjs/ClientRouter.d.ts +0 -1
  138. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +0 -37
  139. package/dist/cjs/build/build.d.ts +0 -1
  140. package/dist/cjs/build/build.js +0 -55
  141. package/dist/cjs/buildFeServer.d.ts +0 -1
  142. package/dist/cjs/buildFeServer.js +0 -63
  143. package/dist/cjs/buildRouteHooks.js +0 -66
  144. package/dist/cjs/buildRouteManifest.js +0 -92
  145. package/dist/cjs/buildRscClientAndServer.js +0 -54
  146. package/dist/cjs/client.d.ts +0 -1
  147. package/dist/cjs/clientSsr.d.ts +0 -1
  148. package/dist/cjs/devFeServer.js +0 -406
  149. package/dist/cjs/index.d.ts +0 -1
  150. package/dist/cjs/index.js +0 -118
  151. package/dist/cjs/lib/StatusError.js +0 -36
  152. package/dist/cjs/lib/entries.js +0 -53
  153. package/dist/cjs/lib/getMergedConfig.js +0 -172
  154. package/dist/cjs/lib/onWarn.js +0 -36
  155. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -108
  156. package/dist/cjs/middleware/index.js +0 -22
  157. package/dist/cjs/middleware/invokeMiddleware.js +0 -52
  158. package/dist/cjs/middleware/register.js +0 -105
  159. package/dist/cjs/middleware/types.js +0 -16
  160. package/dist/cjs/package.json +0 -1
  161. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +0 -107
  162. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +0 -183
  163. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +0 -92
  164. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +0 -67
  165. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +0 -118
  166. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  167. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +0 -76
  168. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +0 -133
  169. package/dist/cjs/plugins/vite-plugin-cedarjs-directory-named-import.js +0 -82
  170. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +0 -134
  171. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +0 -42
  172. package/dist/cjs/plugins/vite-plugin-merged-config.js +0 -39
  173. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +0 -104
  174. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +0 -75
  175. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +0 -159
  176. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +0 -125
  177. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +0 -75
  178. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -227
  179. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -401
  180. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +0 -46
  181. package/dist/cjs/rsc/rscBuildAnalyze.js +0 -116
  182. package/dist/cjs/rsc/rscBuildClient.js +0 -91
  183. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +0 -56
  184. package/dist/cjs/rsc/rscBuildEntriesFile.js +0 -115
  185. package/dist/cjs/rsc/rscBuildForServer.js +0 -157
  186. package/dist/cjs/rsc/rscBuildForSsr.js +0 -169
  187. package/dist/cjs/rsc/rscBuildRwEnvVars.js +0 -56
  188. package/dist/cjs/rsc/rscRenderer.js +0 -179
  189. package/dist/cjs/rsc/rscRequestHandler.js +0 -162
  190. package/dist/cjs/rsc/rscStudioHandlers.js +0 -155
  191. package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
  192. package/dist/cjs/rsc/utils.js +0 -56
  193. package/dist/cjs/runFeServer.js +0 -145
  194. package/dist/cjs/streaming/buildForStreamingServer.js +0 -65
  195. package/dist/cjs/streaming/collectCss.js +0 -52
  196. package/dist/cjs/streaming/createReactStreamingHandler.js +0 -176
  197. package/dist/cjs/streaming/streamHelpers.js +0 -247
  198. package/dist/cjs/streaming/transforms/bufferedTransform.js +0 -61
  199. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +0 -34
  200. package/dist/cjs/streaming/transforms/encode-decode.js +0 -36
  201. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +0 -84
  202. package/dist/cjs/streaming/triggerRouteHooks.js +0 -96
  203. package/dist/cjs/types.js +0 -16
  204. package/dist/cjs/utils.js +0 -91
  205. package/dist/package.json +0 -1
  206. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  207. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  208. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
  209. package/dist/plugins/vite-plugin-cedarjs-directory-named-import.d.ts +0 -3
  210. package/dist/plugins/vite-plugin-cedarjs-directory-named-import.d.ts.map +0 -1
  211. package/dist/plugins/vite-plugin-cedarjs-directory-named-import.js +0 -48
  212. package/dist/plugins/vite-plugin-jsx-loader.d.ts +0 -6
  213. package/dist/plugins/vite-plugin-jsx-loader.d.ts.map +0 -1
  214. package/dist/plugins/vite-plugin-jsx-loader.js +0 -18
  215. /package/bins/{rw-vite-build.mjs → cedar-vite-build.mjs} +0 -0
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { startUnifiedDevServer } from '../dist/cedar-unified-dev.js'
3
+
4
+ startUnifiedDevServer().catch((err) => {
5
+ console.error('Failed to start unified dev server:', err)
6
+ process.exit(1)
7
+ })
@@ -16,15 +16,28 @@ const startDevServer = async () => {
16
16
  // Tries to maintain the same options as vite's dev cli
17
17
  // See here: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/cli.ts#L103
18
18
  // e.g. yarn cedar dev web --fwd="--force"
19
+ //
20
+ // `force` and `debug` aren't Vite server options, so pull those out.
21
+ // Everything else yargs-parser picks out of argv (e.g. `open`, `port`,
22
+ // `https`, `strictPort`, `cors`) is a forwarded server option and gets
23
+ // passed straight through to Vite's `server` config.
19
24
  const {
20
25
  force: forceOptimize,
21
- forwardedServerArgs,
22
26
  debug,
27
+ _: _positional,
28
+ ...forwardedServerArgs
23
29
  } = yargsParser(process.argv.slice(2), {
24
30
  boolean: ['https', 'open', 'strictPort', 'force', 'cors', 'debug'],
25
31
  number: ['port'],
26
32
  })
27
33
 
34
+ // Default to not auto-opening a browser when there's no interactive
35
+ // terminal attached (CI, AI coding agents, etc.), unless the user
36
+ // explicitly forwarded --open.
37
+ if (forwardedServerArgs.open === undefined && !process.stdout.isTTY) {
38
+ forwardedServerArgs.open = false
39
+ }
40
+
28
41
  const devServer = await createServer({
29
42
  configFile,
30
43
  envFile: false, // env file is handled by plugins in the redwood-vite plugin
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-vitest-api-preset.d.ts","sourceRoot":"","sources":["../../src/api/vite-plugin-cedar-vitest-api-preset.ts"],"names":[],"mappings":"AAQA,wBAAgB,iBAAiB,kEAOhC"}
1
+ {"version":3,"file":"vite-plugin-cedar-vitest-api-preset.d.ts","sourceRoot":"","sources":["../../src/api/vite-plugin-cedar-vitest-api-preset.ts"],"names":[],"mappings":"AAUA,wBAAgB,iBAAiB,kEAShC"}
@@ -3,12 +3,16 @@ import {
3
3
  cedarVitestApiConfigPlugin,
4
4
  trackDbImportsPlugin
5
5
  } from "@cedarjs/testing/api/vitest";
6
- import { cedarjsDirectoryNamedImportPlugin } from "../plugins/vite-plugin-cedarjs-directory-named-import.js";
6
+ import { cedarImportDirPlugin } from "../plugins/vite-plugin-cedar-import-dir.js";
7
+ import { cedarjsJobPathInjectorPlugin } from "../plugins/vite-plugin-cedarjs-job-path-injector.js";
8
+ import { cedarjsResolveCedarStyleImportsPlugin } from "../plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
7
9
  function cedarVitestPreset() {
8
10
  return [
11
+ cedarImportDirPlugin(),
12
+ cedarjsJobPathInjectorPlugin(),
9
13
  cedarVitestApiConfigPlugin(),
10
14
  autoImportsPlugin(),
11
- cedarjsDirectoryNamedImportPlugin(),
15
+ cedarjsResolveCedarStyleImportsPlugin(),
12
16
  trackDbImportsPlugin()
13
17
  ];
14
18
  }
@@ -0,0 +1,15 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ export declare function loadApiFunctions(viteServer: ViteDevServer): Promise<void>;
3
+ export declare function createApiViteServer(): Promise<ViteDevServer>;
4
+ export declare function setupHmrHandlers(viteServer: ViteDevServer): void;
5
+ /**
6
+ * Creates a fetch-native handler for API requests.
7
+ * Routes GraphQL to Yoga and Lambda functions to their handlers.
8
+ */
9
+ export declare function createApiFetchHandler(): (request: Request) => Promise<Response>;
10
+ export declare function startApiDevMiddleware(): Promise<{
11
+ viteServer: ViteDevServer;
12
+ close: () => Promise<void>;
13
+ handler: (request: Request) => Promise<Response>;
14
+ }>;
15
+ //# sourceMappingURL=apiDevMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiDevMiddleware.d.ts","sourceRoot":"","sources":["../src/apiDevMiddleware.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAsB,aAAa,EAAE,MAAM,MAAM,CAAA;AAoE7D,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,aAAa,iBAe/D;AA8GD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAyMlE;AA0BD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,CA0EhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,KAIrB,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAiGnD;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,UAAU,EAAE,aAAa,CAAA;IACzB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACjD,CAAC,CAcD"}
@@ -0,0 +1,435 @@
1
+ import fs from "node:fs";
2
+ import { glob } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import ansis from "ansis";
6
+ import { normalizePath } from "vite";
7
+ import { gqlPlugin as gqlTagPlugin } from "vite-plugin-graphql-tag";
8
+ import tsPathsMod from "vite-tsconfig-paths";
9
+ const tsconfigPaths = (
10
+ // @ts-expect-error – .default only exists at runtime in CJS double-wrap
11
+ // interop
12
+ tsPathsMod.default?.default || tsPathsMod.default || tsPathsMod
13
+ );
14
+ import { buildCedarContext, wrapLegacyHandler } from "@cedarjs/api/runtime";
15
+ import {
16
+ getApiSideBabelConfigPath,
17
+ getApiSideBabelPluginsForVite,
18
+ transformWithBabel
19
+ } from "@cedarjs/babel-config";
20
+ import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
21
+ import { createGraphQLYoga } from "@cedarjs/graphql-server";
22
+ import { applyGqlormInject } from "@cedarjs/internal/dist/build/api-graphql-transforms.js";
23
+ import { getConfig, getPaths } from "@cedarjs/project-config";
24
+ import { generateDiffSourceMap } from "./lib/generateDiffSourceMap.js";
25
+ import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
26
+ import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
27
+ import { cedarDirectoryNamedImportPlugin } from "./plugins/vite-plugin-cedar-directory-named-import.js";
28
+ import { applyGraphqlOptionsExtract } from "./plugins/vite-plugin-cedar-graphql-options-extract.js";
29
+ import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
30
+ import { cedarApiLogFormatterDevPlugin } from "./plugins/vite-plugin-cedar-log-formatter-dev.js";
31
+ import { applyOtelWrapping } from "./plugins/vite-plugin-cedar-otel-wrapping.js";
32
+ import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-path-injector.js";
33
+ function resolveWithExtensions(id) {
34
+ if (fs.existsSync(id) && fs.statSync(id).isFile()) {
35
+ return id;
36
+ }
37
+ for (const ext of [".js", ".ts", ".jsx", ".tsx", ".mjs", ".mts"]) {
38
+ const withExt = id + ext;
39
+ if (fs.existsSync(withExt)) {
40
+ return withExt;
41
+ }
42
+ }
43
+ return id;
44
+ }
45
+ const LAMBDA_FUNCTIONS = {};
46
+ let loadedGraphqlServer = null;
47
+ let loadApiFunctionsInFlight = null;
48
+ let needsReloadAfterInFlight = false;
49
+ async function loadApiFunctions(viteServer) {
50
+ if (loadApiFunctionsInFlight) {
51
+ needsReloadAfterInFlight = true;
52
+ return;
53
+ }
54
+ do {
55
+ needsReloadAfterInFlight = false;
56
+ loadApiFunctionsInFlight = internalLoadApiFunctions(viteServer);
57
+ try {
58
+ await loadApiFunctionsInFlight;
59
+ } finally {
60
+ loadApiFunctionsInFlight = null;
61
+ }
62
+ } while (needsReloadAfterInFlight);
63
+ }
64
+ async function internalLoadApiFunctions(viteServer) {
65
+ const cedarPaths = getPaths();
66
+ for (const key of Object.keys(LAMBDA_FUNCTIONS)) {
67
+ delete LAMBDA_FUNCTIONS[key];
68
+ }
69
+ let srcFunctions = [];
70
+ try {
71
+ srcFunctions = await Array.fromAsync(
72
+ glob("**/*.{ts,tsx,js,jsx}", {
73
+ cwd: cedarPaths.api.functions,
74
+ exclude: [
75
+ "**/*.test.{ts,tsx,js,jsx}",
76
+ "**/*.scenarios.{ts,tsx,js,jsx}",
77
+ "**/*.fixtures.{ts,tsx,js,jsx}",
78
+ "**/*.d.ts"
79
+ ]
80
+ }),
81
+ (entry) => path.join(cedarPaths.api.functions, entry)
82
+ );
83
+ } catch {
84
+ srcFunctions = [];
85
+ }
86
+ console.log(ansis.dim.italic("Importing Server Functions... "));
87
+ const tsImport = Date.now();
88
+ let extractedGraphqlOptions = null;
89
+ const imports = srcFunctions.map(async (fnPath) => {
90
+ const ts = Date.now();
91
+ const routeName = path.basename(fnPath).replace(/\.(ts|tsx|js|jsx)$/, "");
92
+ try {
93
+ const mod = await viteServer.ssrLoadModule(pathToFileURL(fnPath).href);
94
+ const cedarHandler = (() => {
95
+ if ("handleRequest" in mod) {
96
+ return mod.handleRequest;
97
+ }
98
+ if ("default" in mod && mod.default && "handleRequest" in mod.default) {
99
+ return mod.default.handleRequest;
100
+ }
101
+ let legacyHandler;
102
+ if ("handler" in mod) {
103
+ legacyHandler = mod.handler;
104
+ } else if ("default" in mod && mod.default && "handler" in mod.default) {
105
+ legacyHandler = mod.default.handler;
106
+ }
107
+ if (legacyHandler) {
108
+ return wrapLegacyHandler(legacyHandler);
109
+ }
110
+ return void 0;
111
+ })();
112
+ if (cedarHandler) {
113
+ LAMBDA_FUNCTIONS[routeName] = cedarHandler;
114
+ console.log(
115
+ ansis.magenta("/" + routeName),
116
+ ansis.dim.italic(Date.now() - ts + " ms")
117
+ );
118
+ } else {
119
+ console.warn(
120
+ `[apiDevMiddleware] No handler or handleRequest export found in function: ${fnPath}`
121
+ );
122
+ }
123
+ if (routeName === "graphql" && "__cedar_graphqlOptions" in mod) {
124
+ extractedGraphqlOptions = mod.__cedar_graphqlOptions;
125
+ }
126
+ } catch (err) {
127
+ viteServer.ssrFixStacktrace(err);
128
+ console.error(
129
+ `[apiDevMiddleware] Failed to load function "${routeName}" from ${fnPath}:`,
130
+ err
131
+ );
132
+ }
133
+ });
134
+ await Promise.all(imports);
135
+ if (extractedGraphqlOptions) {
136
+ loadedGraphqlServer = await createGraphQLYoga(extractedGraphqlOptions);
137
+ } else {
138
+ loadedGraphqlServer = null;
139
+ }
140
+ console.log(
141
+ ansis.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
142
+ );
143
+ }
144
+ async function createApiViteServer() {
145
+ const cedarPaths = getPaths();
146
+ const cedarConfig = getConfig();
147
+ const normalizedBase = normalizePath(cedarPaths.base);
148
+ const babelPlugins = getApiSideBabelConfigPath() ? getApiSideBabelPluginsForVite() : null;
149
+ const workspacePkgSourceMap = Object.fromEntries(
150
+ Object.entries(getWorkspacePackageAliases(cedarPaths, cedarConfig)).map(
151
+ ([name, sourceFile]) => [name, normalizePath(sourceFile)]
152
+ )
153
+ );
154
+ const { createServer: createViteServer } = await import("vite");
155
+ return createViteServer({
156
+ configFile: false,
157
+ root: cedarPaths.api.base,
158
+ appType: "custom",
159
+ clearScreen: false,
160
+ logLevel: "warn",
161
+ server: {
162
+ middlewareMode: true
163
+ },
164
+ resolve: {
165
+ alias: workspacePkgSourceMap
166
+ },
167
+ plugins: [
168
+ // tsconfigPaths resolves user-defined tsconfig.json `paths` aliases; it
169
+ // replaces the Babel module-resolver's tsconfig-paths handling for dev.
170
+ tsconfigPaths(),
171
+ cedarApiLogFormatterDevPlugin(),
172
+ {
173
+ name: "cedar-api-src-redirect",
174
+ enforce: "pre",
175
+ resolveId(id, importer) {
176
+ const normalizedImporter = importer && normalizePath(importer);
177
+ const normalizedApiSrc = normalizePath(cedarPaths.api.src);
178
+ if (!normalizedImporter?.startsWith(`${normalizedApiSrc}/`)) {
179
+ return null;
180
+ }
181
+ if (id.startsWith("src/")) {
182
+ return resolveWithExtensions(
183
+ path.join(cedarPaths.api.src, id.slice(4))
184
+ );
185
+ }
186
+ return null;
187
+ }
188
+ },
189
+ cedarImportDirPlugin(),
190
+ cedarDirectoryNamedImportPlugin(),
191
+ cedarAutoImportsPlugin(),
192
+ cedarjsJobPathInjectorPlugin(),
193
+ (() => {
194
+ const p = gqlTagPlugin();
195
+ p.enforce = "post";
196
+ return p;
197
+ })(),
198
+ {
199
+ name: "cedar-api-babel-transform",
200
+ enforce: "pre",
201
+ async transform(code, id) {
202
+ if (!/\.(ts|tsx|js|jsx)$/.test(id)) {
203
+ return null;
204
+ }
205
+ if (id.includes("node_modules")) {
206
+ return null;
207
+ }
208
+ if (!id.startsWith(normalizedBase)) {
209
+ return null;
210
+ }
211
+ let sourceCode = code;
212
+ let sourceMap = null;
213
+ if (normalizePath(id).endsWith("/graphql.ts") || normalizePath(id).endsWith("/graphql.js")) {
214
+ const extracted = applyGraphqlOptionsExtract(sourceCode);
215
+ if (extracted) {
216
+ sourceCode = extracted.code;
217
+ sourceMap = extracted.map;
218
+ }
219
+ const injected = applyGqlormInject(sourceCode, id);
220
+ if (injected) {
221
+ sourceCode = injected;
222
+ sourceMap = null;
223
+ }
224
+ }
225
+ try {
226
+ if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
227
+ const relativePath = normalizePath(id).slice(
228
+ normalizedBase.length + "/api/src/".length
229
+ );
230
+ const apiFolder = relativePath.split("/")[0] ?? "?";
231
+ const wrapped = applyOtelWrapping(sourceCode, id, apiFolder);
232
+ if (wrapped) {
233
+ sourceCode = wrapped;
234
+ sourceMap = null;
235
+ }
236
+ }
237
+ if (!babelPlugins) {
238
+ if (sourceCode === code) {
239
+ return null;
240
+ }
241
+ return {
242
+ code: sourceCode,
243
+ map: sourceMap ?? generateDiffSourceMap(code, sourceCode)
244
+ };
245
+ }
246
+ const inputSourceMap = sourceCode === code ? null : sourceMap ?? generateDiffSourceMap(code, sourceCode);
247
+ if (inputSourceMap) {
248
+ inputSourceMap.sources = [id];
249
+ }
250
+ const result = await transformWithBabel(
251
+ sourceCode,
252
+ id,
253
+ babelPlugins,
254
+ true,
255
+ true,
256
+ inputSourceMap ?? void 0
257
+ );
258
+ if (!result?.code) {
259
+ return null;
260
+ }
261
+ return {
262
+ code: result.code,
263
+ map: result.map ?? null
264
+ };
265
+ } catch (err) {
266
+ this.warn(
267
+ `[cedar-api-babel-transform] Failed to transform ${id}: ${String(err)}`
268
+ );
269
+ return null;
270
+ }
271
+ }
272
+ }
273
+ ]
274
+ });
275
+ }
276
+ function invalidateApiModules(viteServer, normalizedApiSrc) {
277
+ const invalidated = /* @__PURE__ */ new Set();
278
+ const invalidateWithImporters = (mod) => {
279
+ if (!mod || invalidated.has(mod.id ?? mod.url)) {
280
+ return;
281
+ }
282
+ invalidated.add(mod.id ?? mod.url);
283
+ viteServer.moduleGraph.invalidateModule(mod);
284
+ for (const importer of mod.importers) {
285
+ invalidateWithImporters(importer);
286
+ }
287
+ };
288
+ for (const mod of viteServer.moduleGraph.idToModuleMap.values()) {
289
+ if (mod.id?.startsWith(normalizedApiSrc)) {
290
+ invalidateWithImporters(mod);
291
+ }
292
+ }
293
+ }
294
+ function setupHmrHandlers(viteServer) {
295
+ const cedarPaths = getPaths();
296
+ const normalizedApiSrc = normalizePath(cedarPaths.api.src);
297
+ const normalizedApiBase = normalizePath(cedarPaths.api.base);
298
+ viteServer.watcher.on("change", async (filePath) => {
299
+ const normalizedFilePath = normalizePath(filePath);
300
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
301
+ return;
302
+ }
303
+ const displayPath = path.relative(normalizedApiBase, normalizedFilePath);
304
+ console.log(ansis.dim(`[change] ${displayPath}`));
305
+ const fileUrl = pathToFileURL(normalizedFilePath).href;
306
+ const mod = viteServer.moduleGraph.getModuleById(normalizedFilePath) ?? viteServer.moduleGraph.getModuleById(fileUrl);
307
+ if (mod) {
308
+ const invalidated = /* @__PURE__ */ new Set();
309
+ const invalidateWithImporters = (m) => {
310
+ if (!m || invalidated.has(m.id ?? m.url)) {
311
+ return;
312
+ }
313
+ invalidated.add(m.id ?? m.url);
314
+ viteServer.moduleGraph.invalidateModule(m);
315
+ for (const importer of m.importers) {
316
+ invalidateWithImporters(importer);
317
+ }
318
+ };
319
+ invalidateWithImporters(mod);
320
+ }
321
+ await loadApiFunctions(viteServer);
322
+ });
323
+ viteServer.watcher.on("add", async (filePath) => {
324
+ const normalizedFilePath = normalizePath(filePath);
325
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
326
+ return;
327
+ }
328
+ console.log(
329
+ ansis.dim(
330
+ `[add] ${path.relative(normalizedApiBase, normalizedFilePath)}`
331
+ )
332
+ );
333
+ invalidateApiModules(viteServer, normalizedApiSrc);
334
+ await loadApiFunctions(viteServer);
335
+ });
336
+ viteServer.watcher.on("unlink", async (filePath) => {
337
+ const normalizedFilePath = normalizePath(filePath);
338
+ if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
339
+ return;
340
+ }
341
+ console.log(
342
+ ansis.dim(
343
+ `[unlink] ${path.relative(normalizedApiBase, normalizedFilePath)}`
344
+ )
345
+ );
346
+ invalidateApiModules(viteServer, normalizedApiSrc);
347
+ await loadApiFunctions(viteServer);
348
+ });
349
+ }
350
+ function createApiFetchHandler() {
351
+ const cedarConfig = getConfig();
352
+ const apiUrlPrefix = cedarConfig.web.apiUrl.replace(/\/$/, "");
353
+ return async (request) => {
354
+ const url = new URL(request.url);
355
+ let pathname = url.pathname;
356
+ if (pathname.startsWith(apiUrlPrefix + "/")) {
357
+ pathname = pathname.slice(apiUrlPrefix.length);
358
+ } else if (pathname === apiUrlPrefix) {
359
+ pathname = "/";
360
+ }
361
+ if (pathname === "/graphql" || pathname.startsWith("/graphql/")) {
362
+ const graphqlServer = loadedGraphqlServer;
363
+ if (!graphqlServer) {
364
+ return new Response(
365
+ JSON.stringify({ error: "GraphQL Yoga instance not initialized" }),
366
+ { status: 503, headers: { "Content-Type": "application/json" } }
367
+ );
368
+ }
369
+ return getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), async () => {
370
+ try {
371
+ const cedarContext = await graphqlServer.buildRequestContext(request);
372
+ return await graphqlServer.yoga.handle(request, {
373
+ request,
374
+ cedarContext
375
+ });
376
+ } catch (e) {
377
+ if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
378
+ return new Response(null, { status: 499 });
379
+ }
380
+ throw e;
381
+ }
382
+ });
383
+ }
384
+ const match = pathname.match(/^\/([^/]+)(?:\/.*)?$/);
385
+ if (!match) {
386
+ return new Response("Not Found", { status: 404 });
387
+ }
388
+ const routeName = match[1];
389
+ const handler = LAMBDA_FUNCTIONS[routeName];
390
+ if (!handler) {
391
+ return new Response(
392
+ JSON.stringify({
393
+ error: `Function "${routeName}" was not found.`,
394
+ availableFunctions: Object.keys(LAMBDA_FUNCTIONS)
395
+ }),
396
+ { status: 404, headers: { "Content-Type": "application/json" } }
397
+ );
398
+ }
399
+ try {
400
+ const ctx = await buildCedarContext(request, {
401
+ params: { routeName }
402
+ });
403
+ return await handler(request, ctx);
404
+ } catch (err) {
405
+ console.error(
406
+ `[apiDevMiddleware] Error handling function "${routeName}":`,
407
+ err
408
+ );
409
+ return new Response(
410
+ JSON.stringify({
411
+ error: err instanceof Error ? err.message : "Internal Server Error"
412
+ }),
413
+ { status: 500, headers: { "Content-Type": "application/json" } }
414
+ );
415
+ }
416
+ };
417
+ }
418
+ async function startApiDevMiddleware() {
419
+ const viteServer = await createApiViteServer();
420
+ console.log(ansis.dim.italic("Starting API dev server..."));
421
+ await loadApiFunctions(viteServer);
422
+ setupHmrHandlers(viteServer);
423
+ const close = async () => {
424
+ await viteServer.close();
425
+ };
426
+ const handler = createApiFetchHandler();
427
+ return { viteServer, close, handler };
428
+ }
429
+ export {
430
+ createApiFetchHandler,
431
+ createApiViteServer,
432
+ loadApiFunctions,
433
+ setupHmrHandlers,
434
+ startApiDevMiddleware
435
+ };
@@ -1,3 +1,4 @@
1
+ export { buildCedarApp } from '../buildApp.js';
1
2
  interface BuildOptions {
2
3
  verbose?: boolean;
3
4
  }
@@ -6,5 +7,4 @@ interface BuildOptions {
6
7
  * because we want to set the process.cwd to web.base
7
8
  */
8
9
  export declare const buildWeb: ({ verbose }: BuildOptions) => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
9
- export {};
10
10
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAU,aAAa,YAAY,8GAoBvD,CAAA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAU,aAAa,YAAY,8GAoBvD,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { getPaths } from "@cedarjs/project-config";
2
+ import { buildCedarApp } from "../buildApp.js";
2
3
  const buildWeb = async ({ verbose }) => {
3
4
  const { build } = await import("vite");
4
5
  const viteConfig = getPaths().web.viteConfig;
@@ -17,5 +18,6 @@ const buildWeb = async ({ verbose }) => {
17
18
  });
18
19
  };
19
20
  export {
21
+ buildCedarApp,
20
22
  buildWeb
21
23
  };
@@ -0,0 +1,16 @@
1
+ export interface BuildCedarAppOptions {
2
+ verbose?: boolean;
3
+ workspace?: string[];
4
+ ud?: boolean;
5
+ }
6
+ /**
7
+ * Unified build for Cedar apps using Vite's builder API.
8
+ *
9
+ * Declares `client` and `api` environments and builds them in a single
10
+ * orchestrated pass. The web client is built from the project's web Vite
11
+ * config. The API is built as an SSR environment with Babel transforms and
12
+ * `src/` import redirection so it resolves correctly even though the builder
13
+ * root is the web source directory.
14
+ */
15
+ export declare function buildCedarApp({ verbose, workspace, ud, }?: BuildCedarAppOptions): Promise<void>;
16
+ //# sourceMappingURL=buildApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AA6DA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBAsa3B"}