@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
@@ -8,24 +8,24 @@ import type { Plugin } from 'vite';
8
8
  * For each file in `api/src/functions/` that exports a `handler`, this plugin:
9
9
  *
10
10
  * 1. Adds an import at the top of the file:
11
- * import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
11
+ * import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
12
12
  *
13
13
  * 2. Renames the original handler:
14
- * const __cedar_handler = <original handler value>
14
+ * const __rw_handler = <original handler value>
15
15
  *
16
16
  * 3. Replaces the handler export with a wrapper that checks context isolation:
17
- * export const handler = (__cedar_event, __cedar_context) => {
18
- * const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
19
- * if (__cedar_contextStore === undefined) {
20
- * return __cedar_getAsyncStoreInstance().run(new Map(), __cedar_handler, __cedar_event, __cedar_context)
17
+ * export const handler = (__rw_event, __rw__context) => {
18
+ * const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
19
+ * if (__rw_contextStore === undefined) {
20
+ * return __rw_getAsyncStoreInstance().run(new Map(), __rw_handler, __rw_event, __rw__context)
21
21
  * }
22
- * return __cedar_handler(__cedar_event, __cedar_context)
22
+ * return __rw_handler(__rw_event, __rw__context)
23
23
  * }
24
24
  *
25
- * This replaces `babel-plugin-handler-als-wrapping` for Vite builds.
25
+ * This replaces `babel-plugin-redwood-context-wrapping` for Vite builds.
26
26
  * The babel plugin is still used for Jest and prerender.
27
27
  */
28
- export declare function handlerAlsWrappingPlugin({ projectIsEsm, }?: {
28
+ export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
29
29
  projectIsEsm?: boolean;
30
30
  }): Plugin;
31
31
  /**
@@ -34,11 +34,11 @@ export declare function handlerAlsWrappingPlugin({ projectIsEsm, }?: {
34
34
  * export a `handler`.
35
35
  *
36
36
  * This is the context-isolation safeguard that used to be performed by
37
- * `babel-plugin-handler-als-wrapping`. It is exported as a standalone
37
+ * `babel-plugin-redwood-context-wrapping`. It is exported as a standalone
38
38
  * function so it can be applied from build pipelines that don't go through
39
39
  * Vite's plugin pipeline (e.g. the legacy esbuild API build).
40
40
  */
41
- export declare function applyHandlerAlsWrapping(code: string, { projectIsEsm }?: {
41
+ export declare function applyContextWrapping(code: string, { projectIsEsm }?: {
42
42
  projectIsEsm?: boolean;
43
43
  }): string | null;
44
- //# sourceMappingURL=vite-plugin-handler-als-wrapping.d.ts.map
44
+ //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CAuBd;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CAsDf"}
@@ -1,11 +1,11 @@
1
1
  import path from "node:path";
2
2
  import { normalizePath } from "vite";
3
3
  import { getPaths } from "@cedarjs/project-config";
4
- function handlerAlsWrappingPlugin({
4
+ function cedarContextWrappingPlugin({
5
5
  projectIsEsm = false
6
6
  } = {}) {
7
7
  return {
8
- name: "handler-als-wrapping",
8
+ name: "cedar-context-wrapping",
9
9
  transform(code, id) {
10
10
  let paths;
11
11
  try {
@@ -17,12 +17,12 @@ function handlerAlsWrappingPlugin({
17
17
  if (!normalizePath(id).startsWith(functionsDir + "/")) {
18
18
  return null;
19
19
  }
20
- const wrapped = applyHandlerAlsWrapping(code, { projectIsEsm });
20
+ const wrapped = applyContextWrapping(code, { projectIsEsm });
21
21
  return wrapped ? { code: wrapped, map: null } : null;
22
22
  }
23
23
  };
24
24
  }
25
- function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
25
+ function applyContextWrapping(code, { projectIsEsm = false } = {}) {
26
26
  const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
27
27
  const handlerMatch = handlerRe.exec(code);
28
28
  if (!handlerMatch) {
@@ -31,30 +31,30 @@ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
31
31
  const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
32
32
  const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
33
33
  const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
34
- const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '${storePath}'
34
+ const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
35
35
  `;
36
36
  const handlerStart = handlerMatch.index;
37
37
  const before = code.slice(0, handlerStart);
38
38
  const after = code.slice(handlerStart);
39
- const renamed = after.replace(handlerRe, "const __cedar_handler =");
39
+ const renamed = after.replace(handlerRe, "const __rw_handler =");
40
40
  const wrappedHandler = `
41
- export const handler = ${isAsync ? "async " : ""}(__cedar_event, __cedar_context) => {
41
+ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
42
42
  // The store will be undefined if no context isolation has been performed yet
43
- const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
44
- if (__cedar_contextStore === undefined) {
45
- return __cedar_getAsyncStoreInstance().run(
43
+ const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
44
+ if (__rw_contextStore === undefined) {
45
+ return __rw_getAsyncStoreInstance().run(
46
46
  new Map(),
47
- __cedar_handler,
48
- __cedar_event,
49
- __cedar_context
47
+ __rw_handler,
48
+ __rw_event,
49
+ __rw__context
50
50
  )
51
51
  }
52
- return __cedar_handler(__cedar_event, __cedar_context)
52
+ return __rw_handler(__rw_event, __rw__context)
53
53
  }
54
54
  `;
55
55
  return before + importStatement + renamed + wrappedHandler;
56
56
  }
57
57
  export {
58
- applyHandlerAlsWrapping,
59
- handlerAlsWrappingPlugin
58
+ applyContextWrapping,
59
+ cedarContextWrappingPlugin
60
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-import-dir.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-import-dir.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA4H7C"}
1
+ {"version":3,"file":"vite-plugin-cedar-import-dir.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAgH7C"}
@@ -1,8 +1,6 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
- import MagicString from "magic-string";
4
- import { parseSync } from "oxc-parser";
5
- import { normalizePath } from "vite";
2
+ import { parse, Lang } from "@ast-grep/napi";
3
+ import fg from "fast-glob";
6
4
  import { importStatementPath, getPaths } from "@cedarjs/project-config";
7
5
  function cedarImportDirPlugin() {
8
6
  return {
@@ -12,64 +10,51 @@ function cedarImportDirPlugin() {
12
10
  if (!code.includes("/**/")) {
13
11
  return null;
14
12
  }
15
- let program;
13
+ const ext = path.extname(id);
14
+ const language = ext === ".ts" || ext === ".tsx" ? Lang.TypeScript : Lang.JavaScript;
15
+ let ast;
16
16
  try {
17
- program = parseSync(id, code).program;
17
+ ast = parse(language, code);
18
18
  } catch (error) {
19
19
  console.warn("Failed to parse file:", id);
20
20
  console.warn(error);
21
21
  return null;
22
22
  }
23
+ const root = ast.root();
23
24
  let hasTransformations = false;
24
- const s = new MagicString(code);
25
- for (const node of program.body) {
26
- if (node.type !== "ImportDeclaration") {
27
- continue;
25
+ const edits = [];
26
+ const globImports = root.findAll({
27
+ rule: {
28
+ pattern: "import $DEFAULT_IMPORT from $SOURCE"
28
29
  }
29
- const defaultSpecifier = node.specifiers.find(
30
- (specifier) => specifier.type === "ImportDefaultSpecifier"
31
- );
32
- if (!defaultSpecifier) {
30
+ });
31
+ for (const importNode of globImports) {
32
+ const sourceNode = importNode.getMatch("SOURCE");
33
+ const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
34
+ if (!sourceNode || !defaultImportNode) {
33
35
  continue;
34
36
  }
35
- const sourceValue = node.source.value;
37
+ const sourceValue = sourceNode.text().slice(1, -1);
36
38
  if (!sourceValue.includes("/**/")) {
37
39
  continue;
38
40
  }
39
41
  hasTransformations = true;
40
- const importName = defaultSpecifier.local.name;
42
+ const importName = defaultImportNode.text();
41
43
  const importGlob = importStatementPath(sourceValue);
42
- let cwd = path.dirname(id);
43
- if (importGlob.startsWith("src/")) {
44
- const normalizedId = normalizePath(id);
45
- const apiBase = normalizePath(getPaths().api.base);
46
- const webBase = normalizePath(getPaths().web.base);
47
- if (normalizedId.startsWith(apiBase)) {
48
- cwd = getPaths().api.base;
49
- } else if (normalizedId.startsWith(webBase)) {
50
- cwd = getPaths().web.base;
51
- } else {
52
- throw new Error(`Unexpected file location: ${id}`);
53
- }
54
- }
44
+ const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(id);
55
45
  try {
56
- const dirFiles = fs.globSync(importGlob, {
57
- cwd,
58
- exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
59
- });
46
+ const dirFiles = fg.sync(importGlob, { cwd }).filter(
47
+ (n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
48
+ );
60
49
  const staticGlob = importGlob.split("*")[0];
61
50
  const filePathToVarName = (filePath) => {
62
- const normalizedPath = normalizePath(filePath);
63
- return normalizedPath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
51
+ return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
64
52
  };
65
53
  let replacement = `let ${importName} = {};
66
54
  `;
67
55
  for (const filePath of dirFiles) {
68
- const normalizedPath = normalizePath(filePath);
69
- const lastSlash = normalizedPath.lastIndexOf("/");
70
- const fileDir = lastSlash >= 0 ? normalizedPath.slice(0, lastSlash) : "";
71
- const fileName = normalizedPath.slice(lastSlash + 1).replace(/\.\w+$/, "");
72
- const fileImportPath = fileDir ? fileDir + "/" + fileName : fileName;
56
+ const { dir: fileDir, name: fileName } = path.parse(filePath);
57
+ const fileImportPath = fileDir + "/" + fileName;
73
58
  const filePathVarName = filePathToVarName(filePath);
74
59
  const namespaceImportName = `${importName}_${filePathVarName}`;
75
60
  replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
@@ -77,15 +62,17 @@ function cedarImportDirPlugin() {
77
62
  replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
78
63
  `;
79
64
  }
80
- s.overwrite(node.start, node.end, replacement.trim());
65
+ edits.push(importNode.replace(replacement.trim()));
81
66
  } catch (error) {
82
67
  console.warn(`Failed to process glob import: ${sourceValue}`, error);
83
68
  }
84
69
  }
85
- if (hasTransformations) {
70
+ if (hasTransformations && edits.length > 0) {
71
+ const transformedCode = root.commitEdits(edits);
86
72
  return {
87
- code: s.toString(),
88
- map: s.generateMap({ hires: true })
73
+ code: transformedCode,
74
+ map: null
75
+ // For simplicity, not generating source maps
89
76
  };
90
77
  }
91
78
  return null;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function cedarNodePolyfills(): Plugin | undefined;
3
+ //# sourceMappingURL=vite-plugin-cedar-node-polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-node-polyfills.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-node-polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAiBvD"}
@@ -0,0 +1,19 @@
1
+ import { nodePolyfills } from "vite-plugin-node-polyfills";
2
+ import { getConfig } from "@cedarjs/project-config";
3
+ function cedarNodePolyfills() {
4
+ if (getConfig().experimental?.rsc?.enabled) {
5
+ return void 0;
6
+ }
7
+ return {
8
+ ...nodePolyfills({
9
+ include: ["buffer"],
10
+ globals: {
11
+ Buffer: true
12
+ }
13
+ }),
14
+ apply: "serve"
15
+ };
16
+ }
17
+ export {
18
+ cedarNodePolyfills
19
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAalC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA0GR"}
1
+ {"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA0GR"}
@@ -190,15 +190,66 @@ async function generateGraphQLModule(distPath) {
190
190
  include: ["__cedar_graphqlOptions"]
191
191
  });
192
192
  return `
193
- import { buildCedarContext, requestToLegacyEvent } from '@cedarjs/api/runtime';
193
+ import { buildCedarContext, noopAuthDecoder, requestToLegacyEvent } from '@cedarjs/api/runtime';
194
194
  import { createGraphQLYoga } from '@cedarjs/graphql-server';
195
195
 
196
196
  // Inlined bundle of ${path.basename(distPath)} (node_modules kept external)
197
197
  ${bundledCode}
198
198
 
199
- ${createGraphQLFetch.toString()}
199
+ let yogaInitPromise = null;
200
200
 
201
- export default { fetch: createGraphQLFetch(__cedar_graphqlOptions) };
201
+ function getYoga() {
202
+ if (!yogaInitPromise) {
203
+ yogaInitPromise = createGraphQLYoga(__cedar_graphqlOptions).then(
204
+ ({ yoga }) => ({ yoga, graphqlOptions: __cedar_graphqlOptions })
205
+ );
206
+ }
207
+ return yogaInitPromise;
208
+ }
209
+
210
+ export default {
211
+ async fetch(request) {
212
+ const { yoga, graphqlOptions } = await getYoga();
213
+ const cedarContext = await buildCedarContext(request, {
214
+ authDecoder: graphqlOptions?.authDecoder ?? noopAuthDecoder,
215
+ });
216
+ const event = await requestToLegacyEvent(request, cedarContext);
217
+ // Wrap yoga.handle in an AsyncLocalStorage run so directive
218
+ // validators can read from the global @cedarjs/context. Without
219
+ // this, the auth plugin's setContext() call writes to a store
220
+ // that's only visible inside the plugin's own callback \u2014 not
221
+ // during directive validation.
222
+ const { getAsyncStoreInstance } = await import('@cedarjs/context/dist/store')
223
+ const store = getAsyncStoreInstance()
224
+
225
+ return store.run(new Map(), () => {
226
+ return yoga.handle(request, {
227
+ request,
228
+ cedarContext,
229
+ event,
230
+ requestContext: undefined,
231
+ })
232
+ }).then((response) => {
233
+ // GraphQL Yoga returns a PonyfillResponse from @whatwg-node/fetch
234
+ // which is not an instanceof the native Response class. Netlify's
235
+ // bootstrap checks instanceof Response, so we wrap it.
236
+ return new Response(response.body, {
237
+ status: response.status,
238
+ statusText: response.statusText,
239
+ headers: response.headers,
240
+ })
241
+ }).catch((e) => {
242
+ if (e?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
243
+ // Client disconnected while the request was being processed (e.g.,
244
+ // page navigation, tab close). Return a 499 so the runtime doesn't
245
+ // treat this as a 500.
246
+ return new Response(null, { status: 499 })
247
+ }
248
+
249
+ throw e
250
+ })
251
+ }
252
+ };
202
253
  `;
203
254
  }
204
255
  async function generateFunctionModule(distPath) {
@@ -212,103 +263,50 @@ async function generateFunctionModule(distPath) {
212
263
  // Inlined bundle of ${path.basename(distPath)} (node_modules kept external)
213
264
  ${bundledCode}
214
265
 
215
- ${resolveNativeHandler.toString()}
266
+ const nativeHandler = (() => {
267
+ // Prefer named handleRequest export
268
+ if (typeof handleRequest !== 'undefined') { return handleRequest; }
269
+ // Handle export default { handleRequest } pattern
270
+ if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handleRequest === 'function') {
271
+ return __cedar_default.handleRequest;
272
+ }
273
+ // Handle plain default-exported async function: export default async (req) => Response
274
+ if (typeof __cedar_default !== 'undefined' && typeof __cedar_default === 'function') {
275
+ return __cedar_default;
276
+ }
277
+ return undefined;
278
+ })();
216
279
 
217
- ${resolveLegacyHandler.toString()}
280
+ const legacyFn = (() => {
281
+ if (typeof handler !== 'undefined') { return handler; }
282
+ if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handler === 'function') {
283
+ return __cedar_default.handler;
284
+ }
285
+ return undefined;
286
+ })();
218
287
 
219
- ${resolveCedarHandler.toString()}
288
+ if (!nativeHandler && !legacyFn) {
289
+ throw new Error(${notFoundMsg});
290
+ }
220
291
 
221
- ${createFunctionFetch.toString()}
292
+ const _handler = nativeHandler ?? wrapLegacyHandler(legacyFn);
222
293
 
223
294
  export default {
224
- fetch: createFunctionFetch(resolveCedarHandler(${notFoundMsg})),
295
+ async fetch(request) {
296
+ const ctx = await buildCedarContext(request);
297
+ // Wrap the handler in an AsyncLocalStorage run so the global
298
+ // @cedarjs/context is available inside it (and isolated per request).
299
+ // Mirrors the GraphQL module above and the cedarContextWrappingPlugin
300
+ // used for non-UD builds.
301
+ const { getAsyncStoreInstance } = await import(
302
+ '@cedarjs/context/dist/store'
303
+ );
304
+ const store = getAsyncStoreInstance();
305
+ return store.run(new Map(), () => _handler(request, ctx));
306
+ }
225
307
  };
226
308
  `;
227
309
  }
228
- function resolveNativeHandler() {
229
- if (typeof handleRequest !== "undefined") {
230
- return handleRequest;
231
- }
232
- if (typeof __cedar_default === "undefined" || !__cedar_default) {
233
- return void 0;
234
- }
235
- if (typeof __cedar_default === "object" && typeof __cedar_default.handleRequest === "function") {
236
- return __cedar_default.handleRequest;
237
- }
238
- if (typeof __cedar_default === "function") {
239
- return __cedar_default;
240
- }
241
- return void 0;
242
- }
243
- function resolveLegacyHandler() {
244
- if (typeof handler !== "undefined") {
245
- return handler;
246
- }
247
- if (typeof __cedar_default === "undefined" || !__cedar_default) {
248
- return void 0;
249
- }
250
- if (typeof __cedar_default === "object" && typeof __cedar_default.handler === "function") {
251
- return __cedar_default.handler;
252
- }
253
- return void 0;
254
- }
255
- function resolveCedarHandler(notFoundMessage) {
256
- const nativeHandler = resolveNativeHandler();
257
- if (nativeHandler) {
258
- return nativeHandler;
259
- }
260
- const legacyFn = resolveLegacyHandler();
261
- if (!legacyFn) {
262
- throw new Error(notFoundMessage);
263
- }
264
- return wrapLegacyHandler(legacyFn);
265
- }
266
- function createFunctionFetch(cedarHandler) {
267
- return async function fetch(request) {
268
- const ctx = await buildCedarContext(request);
269
- const { getAsyncStoreInstance } = await import("@cedarjs/context/dist/store");
270
- const store = getAsyncStoreInstance();
271
- return store.run(/* @__PURE__ */ new Map(), () => cedarHandler(request, ctx));
272
- };
273
- }
274
- function createGraphQLFetch(graphqlOptions) {
275
- let yogaInitPromise = null;
276
- function getYoga() {
277
- if (!yogaInitPromise) {
278
- yogaInitPromise = createGraphQLYoga(graphqlOptions);
279
- }
280
- return yogaInitPromise;
281
- }
282
- return async function fetch(request) {
283
- const { yoga } = await getYoga();
284
- const cedarContext = await buildCedarContext(request, {
285
- authDecoder: graphqlOptions?.authDecoder
286
- });
287
- const event = await requestToLegacyEvent(request, cedarContext);
288
- const { getAsyncStoreInstance } = await import("@cedarjs/context/dist/store");
289
- const store = getAsyncStoreInstance();
290
- try {
291
- const response = await store.run(/* @__PURE__ */ new Map(), () => {
292
- return yoga.handle(request, {
293
- request,
294
- cedarContext,
295
- event,
296
- requestContext: void 0
297
- });
298
- });
299
- return new Response(response.body, {
300
- status: response.status,
301
- statusText: response.statusText,
302
- headers: response.headers
303
- });
304
- } catch (e) {
305
- if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
306
- return new Response(null, { status: 499 });
307
- }
308
- throw e;
309
- }
310
- };
311
- }
312
310
  export {
313
311
  cedarUniversalDeployPlugin
314
312
  };
@@ -1,32 +1,3 @@
1
- import type { SourceMap } from 'magic-string';
2
1
  import type { Plugin } from 'vite';
3
- /**
4
- * Vite plugin that injects `path` and `name` properties into `createJob()`
5
- * definitions so the jobs runner can locate and identify the job's module at
6
- * runtime.
7
- *
8
- * Transforms:
9
- * export const myJob = jobs.createJob({ perform: ... })
10
- * into:
11
- * export const myJob = jobs.createJob({ perform: ..., path: "...", name: "myJob" })
12
- *
13
- * The extraction uses an oxc-parser AST walk so the transform is robust
14
- * against nested object properties, aliased imports, and TypeScript syntax.
15
- * The same logic is duplicated in `@cedarjs/internal`
16
- * (`applyJobPathInjector`) for the standalone esbuild API build.
17
- */
18
2
  export declare function cedarjsJobPathInjectorPlugin(): Plugin;
19
- /**
20
- * Injects `path` and `name` properties into `createJob()` definitions.
21
- * Returns the transformed code with a sourcemap, or null if no
22
- * transformation was needed.
23
- *
24
- * Duplicate of `@cedarjs/internal`'s `applyJobPathInjector` so this logic can
25
- * run inside the Vite plugin pipeline without depending on internal's build
26
- * output.
27
- */
28
- export declare function applyJobPathInjector(code: string, filePath: string, jobsDir: string): {
29
- code: string;
30
- map: SourceMap;
31
- } | null;
32
3
  //# sourceMappingURL=vite-plugin-cedarjs-job-path-injector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedarjs-job-path-injector.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedarjs-job-path-injector.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAoBrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAiFzC"}
1
+ {"version":3,"file":"vite-plugin-cedarjs-job-path-injector.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedarjs-job-path-injector.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC,wBAAgB,4BAA4B,IAAI,MAAM,CAqHrD"}