@cedarjs/vite 5.0.3 → 5.0.4-next.167

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 +4 -0
  3. package/dist/apiDevMiddleware.d.ts.map +1 -1
  4. package/dist/apiDevMiddleware.js +105 -9
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +79 -18
  7. package/dist/buildRouteHooks.d.ts.map +1 -1
  8. package/dist/buildRouteHooks.js +36 -4
  9. package/dist/bundled/react-server-dom-webpack.server.js +192 -99
  10. package/dist/cedar-unified-dev.d.ts +18 -0
  11. package/dist/cedar-unified-dev.d.ts.map +1 -1
  12. package/dist/cedar-unified-dev.js +39 -5
  13. package/dist/devFeServer.js +3 -8
  14. package/dist/index.d.ts +10 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +45 -19
  17. package/dist/lib/generateDiffSourceMap.d.ts +18 -0
  18. package/dist/lib/generateDiffSourceMap.d.ts.map +1 -0
  19. package/dist/lib/generateDiffSourceMap.js +151 -0
  20. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  21. package/dist/lib/getMergedConfig.js +4 -0
  22. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  23. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  24. package/dist/plugins/vite-plugin-cedar-auto-import.js +8 -1
  25. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  26. package/dist/plugins/vite-plugin-cedar-cell.js +2 -1
  27. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  28. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  29. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  30. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +12 -0
  31. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +1 -0
  32. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +35 -0
  33. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  34. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  35. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  36. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +42 -0
  37. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  38. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +93 -0
  39. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  40. package/dist/plugins/vite-plugin-cedar-import-dir.js +33 -15
  41. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +28 -0
  42. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +1 -0
  43. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +67 -0
  44. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +28 -0
  45. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +1 -0
  46. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +247 -0
  47. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
  48. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
  49. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
  50. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
  51. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  52. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +14 -0
  53. package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +12 -12
  54. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  55. package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +16 -16
  56. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +3 -0
  57. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  58. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  59. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  60. package/dist/rsc/rscBuildForSsr.js +3 -5
  61. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  62. package/dist/streaming/buildForStreamingServer.js +3 -5
  63. package/package.json +42 -52
  64. package/dist/cjs/ClientRouter.d.ts +0 -1
  65. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +0 -37
  66. package/dist/cjs/apiDevMiddleware.js +0 -371
  67. package/dist/cjs/build/build.d.ts +0 -1
  68. package/dist/cjs/build/build.js +0 -58
  69. package/dist/cjs/buildApp.js +0 -306
  70. package/dist/cjs/buildFeServer.d.ts +0 -1
  71. package/dist/cjs/buildFeServer.js +0 -63
  72. package/dist/cjs/buildRouteHooks.js +0 -80
  73. package/dist/cjs/buildRouteManifest.js +0 -92
  74. package/dist/cjs/buildRscClientAndServer.js +0 -54
  75. package/dist/cjs/cedar-unified-dev.js +0 -310
  76. package/dist/cjs/client.d.ts +0 -1
  77. package/dist/cjs/clientSsr.d.ts +0 -1
  78. package/dist/cjs/devFeServer.js +0 -157
  79. package/dist/cjs/index.d.ts +0 -1
  80. package/dist/cjs/index.js +0 -141
  81. package/dist/cjs/lib/StatusError.js +0 -37
  82. package/dist/cjs/lib/entries.js +0 -52
  83. package/dist/cjs/lib/getMergedConfig.js +0 -185
  84. package/dist/cjs/lib/onWarn.js +0 -36
  85. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -102
  86. package/dist/cjs/lib/workspacePackageAliases.js +0 -107
  87. package/dist/cjs/middleware/index.js +0 -22
  88. package/dist/cjs/middleware/invokeMiddleware.js +0 -52
  89. package/dist/cjs/middleware/register.js +0 -105
  90. package/dist/cjs/middleware/types.js +0 -16
  91. package/dist/cjs/package.json +0 -1
  92. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +0 -107
  93. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +0 -183
  94. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +0 -341
  95. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +0 -95
  96. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +0 -107
  97. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +0 -67
  98. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +0 -118
  99. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  100. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +0 -61
  101. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +0 -76
  102. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
  103. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +0 -346
  104. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +0 -134
  105. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +0 -134
  106. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -106
  107. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +0 -42
  108. package/dist/cjs/plugins/vite-plugin-merged-config.js +0 -39
  109. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +0 -104
  110. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +0 -75
  111. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +0 -159
  112. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +0 -125
  113. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +0 -75
  114. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -228
  115. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -398
  116. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +0 -46
  117. package/dist/cjs/rsc/rscBuildAnalyze.js +0 -126
  118. package/dist/cjs/rsc/rscBuildClient.js +0 -91
  119. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +0 -56
  120. package/dist/cjs/rsc/rscBuildEntriesFile.js +0 -115
  121. package/dist/cjs/rsc/rscBuildForServer.js +0 -168
  122. package/dist/cjs/rsc/rscBuildForSsr.js +0 -173
  123. package/dist/cjs/rsc/rscBuildRwEnvVars.js +0 -56
  124. package/dist/cjs/rsc/rscRenderer.js +0 -165
  125. package/dist/cjs/rsc/rscRequestHandler.js +0 -162
  126. package/dist/cjs/rsc/rscStudioHandlers.js +0 -156
  127. package/dist/cjs/runFeServer.js +0 -165
  128. package/dist/cjs/streaming/buildForStreamingServer.js +0 -65
  129. package/dist/cjs/streaming/collectCss.js +0 -52
  130. package/dist/cjs/streaming/createReactStreamingHandler.js +0 -173
  131. package/dist/cjs/streaming/streamHelpers.js +0 -230
  132. package/dist/cjs/streaming/transforms/bufferedTransform.js +0 -61
  133. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +0 -34
  134. package/dist/cjs/streaming/transforms/encode-decode.js +0 -36
  135. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +0 -84
  136. package/dist/cjs/streaming/triggerRouteHooks.js +0 -96
  137. package/dist/cjs/types.js +0 -16
  138. package/dist/cjs/utils.js +0 -92
  139. package/dist/package.json +0 -1
  140. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  141. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  142. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  143. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
@@ -0,0 +1,42 @@
1
+ import type { SourceMap } from 'magic-string';
2
+ import type { Plugin } from 'vite';
3
+ /**
4
+ * Vite plugin that extracts options passed to createGraphQLHandler into an
5
+ * exported variable.
6
+ *
7
+ * Transforms:
8
+ * export const handler = createGraphQLHandler({ options })
9
+ * into:
10
+ * export const __cedar_graphqlOptions = { options }
11
+ * export const handler = createGraphQLHandler(__cedar_graphqlOptions)
12
+ *
13
+ * This allows options to be imported elsewhere and enables the gqlorm-inject
14
+ * plugin to mutate the sdls object in-place before the call.
15
+ *
16
+ * The extraction uses an oxc-parser AST walk (see `applyGraphqlOptionsExtract`
17
+ * below) so the transform is robust against aliased imports, nested calls, and
18
+ * string escapes. The same logic is duplicated in
19
+ * `@cedarjs/internal` (`applyGraphqlOptionsExtract`) for the standalone esbuild
20
+ * API build
21
+ */
22
+ export declare function cedarGraphqlOptionsExtractPlugin(): Plugin;
23
+ /**
24
+ * Extracts the options argument from createGraphQLHandler calls and stores
25
+ * them in an exported variable. Returns the transformed code with a sourcemap,
26
+ * or null if no transformation was needed.
27
+ *
28
+ * Transforms:
29
+ * export const handler = createGraphQLHandler({ options })
30
+ * into:
31
+ * export const __cedar_graphqlOptions = { options }
32
+ * export const handler = createGraphQLHandler(__cedar_graphqlOptions)
33
+ *
34
+ * Duplicate of `@cedarjs/internal`'s `applyGraphqlOptionsExtract` so this
35
+ * logic can run inside the Vite plugin pipeline without depending on internal's
36
+ * build output.
37
+ */
38
+ export declare function applyGraphqlOptionsExtract(code: string): {
39
+ code: string;
40
+ map: SourceMap;
41
+ } | null;
42
+ //# sourceMappingURL=vite-plugin-cedar-graphql-options-extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-graphql-options-extract.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-graphql-options-extract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAG7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gCAAgC,IAAI,MAAM,CA2BzD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAgGzC"}
@@ -0,0 +1,93 @@
1
+ import MagicString from "magic-string";
2
+ import { parseSync, Visitor } from "oxc-parser";
3
+ function cedarGraphqlOptionsExtractPlugin() {
4
+ return {
5
+ name: "cedar-graphql-options-extract",
6
+ transform(code, id) {
7
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
8
+ return null;
9
+ }
10
+ if (!code.includes("createGraphQLHandler")) {
11
+ return null;
12
+ }
13
+ const result = applyGraphqlOptionsExtract(code);
14
+ if (!result) {
15
+ return null;
16
+ }
17
+ return {
18
+ code: result.code,
19
+ map: result.map
20
+ };
21
+ }
22
+ };
23
+ }
24
+ function applyGraphqlOptionsExtract(code) {
25
+ if (code.includes("__cedar_graphqlOptions")) {
26
+ return null;
27
+ }
28
+ const { program } = parseSync("graphql.ts", code, {
29
+ // lang is only a parse hint; 'ts' also parses JS (the graphql handler can
30
+ // be graphql.js in JS projects), so this is safe for both file types.
31
+ lang: "ts",
32
+ sourceType: "module"
33
+ });
34
+ const importNames = /* @__PURE__ */ new Set();
35
+ for (const node of program.body) {
36
+ if (node.type === "ImportDeclaration") {
37
+ if (node.source.value !== "@cedarjs/graphql-server") {
38
+ continue;
39
+ }
40
+ for (const specifier of node.specifiers) {
41
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
42
+ importNames.add(specifier.local.name);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ if (importNames.size === 0) {
48
+ return null;
49
+ }
50
+ const callExpressionPaths = [];
51
+ new Visitor({
52
+ CallExpression(node) {
53
+ if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
54
+ callExpressionPaths.push(node);
55
+ }
56
+ }
57
+ }).visit(program);
58
+ if (callExpressionPaths.length > 1) {
59
+ return null;
60
+ }
61
+ const callExpression = callExpressionPaths[0];
62
+ if (!callExpression) {
63
+ return null;
64
+ }
65
+ const options = callExpression.arguments[0];
66
+ if (!options) {
67
+ return null;
68
+ }
69
+ if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
70
+ return null;
71
+ }
72
+ const optionsStart = options.start;
73
+ const optionsEnd = options.end;
74
+ const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
75
+ const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
76
+ const indent = indentMatch ? indentMatch[0] : "";
77
+ const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
78
+ optionsStart,
79
+ optionsEnd
80
+ )}
81
+ `;
82
+ const s = new MagicString(code);
83
+ s.prependLeft(lineStart, optionsConst);
84
+ s.overwrite(optionsStart, optionsEnd, "__cedar_graphqlOptions");
85
+ return {
86
+ code: s.toString(),
87
+ map: s.generateMap({ hires: true })
88
+ };
89
+ }
90
+ export {
91
+ applyGraphqlOptionsExtract,
92
+ cedarGraphqlOptionsExtractPlugin
93
+ };
@@ -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":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAgH7C"}
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,CAqI7C"}
@@ -1,6 +1,8 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { parse, Lang } from "@ast-grep/napi";
3
- import fg from "fast-glob";
4
+ import MagicString from "magic-string";
5
+ import { normalizePath } from "vite";
4
6
  import { importStatementPath, getPaths } from "@cedarjs/project-config";
5
7
  function cedarImportDirPlugin() {
6
8
  return {
@@ -22,7 +24,7 @@ function cedarImportDirPlugin() {
22
24
  }
23
25
  const root = ast.root();
24
26
  let hasTransformations = false;
25
- const edits = [];
27
+ const s = new MagicString(code);
26
28
  const globImports = root.findAll({
27
29
  rule: {
28
30
  pattern: "import $DEFAULT_IMPORT from $SOURCE"
@@ -41,20 +43,37 @@ function cedarImportDirPlugin() {
41
43
  hasTransformations = true;
42
44
  const importName = defaultImportNode.text();
43
45
  const importGlob = importStatementPath(sourceValue);
44
- const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(id);
46
+ let cwd = path.dirname(id);
47
+ if (importGlob.startsWith("src/")) {
48
+ const normalizedId = normalizePath(id);
49
+ const apiBase = normalizePath(getPaths().api.base);
50
+ const webBase = normalizePath(getPaths().web.base);
51
+ if (normalizedId.startsWith(apiBase)) {
52
+ cwd = getPaths().api.base;
53
+ } else if (normalizedId.startsWith(webBase)) {
54
+ cwd = getPaths().web.base;
55
+ } else {
56
+ throw new Error(`Unexpected file location: ${id}`);
57
+ }
58
+ }
45
59
  try {
46
- const dirFiles = fg.sync(importGlob, { cwd }).filter(
47
- (n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
48
- );
60
+ const dirFiles = fs.globSync(importGlob, {
61
+ cwd,
62
+ exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
63
+ });
49
64
  const staticGlob = importGlob.split("*")[0];
50
65
  const filePathToVarName = (filePath) => {
51
- return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
66
+ const normalizedPath = normalizePath(filePath);
67
+ return normalizedPath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
52
68
  };
53
69
  let replacement = `let ${importName} = {};
54
70
  `;
55
71
  for (const filePath of dirFiles) {
56
- const { dir: fileDir, name: fileName } = path.parse(filePath);
57
- const fileImportPath = fileDir + "/" + fileName;
72
+ const normalizedPath = normalizePath(filePath);
73
+ const lastSlash = normalizedPath.lastIndexOf("/");
74
+ const fileDir = lastSlash >= 0 ? normalizedPath.slice(0, lastSlash) : "";
75
+ const fileName = normalizedPath.slice(lastSlash + 1).replace(/\.\w+$/, "");
76
+ const fileImportPath = fileDir ? fileDir + "/" + fileName : fileName;
58
77
  const filePathVarName = filePathToVarName(filePath);
59
78
  const namespaceImportName = `${importName}_${filePathVarName}`;
60
79
  replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
@@ -62,17 +81,16 @@ function cedarImportDirPlugin() {
62
81
  replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
63
82
  `;
64
83
  }
65
- edits.push(importNode.replace(replacement.trim()));
84
+ const range = importNode.range();
85
+ s.overwrite(range.start.index, range.end.index, replacement.trim());
66
86
  } catch (error) {
67
87
  console.warn(`Failed to process glob import: ${sourceValue}`, error);
68
88
  }
69
89
  }
70
- if (hasTransformations && edits.length > 0) {
71
- const transformedCode = root.commitEdits(edits);
90
+ if (hasTransformations) {
72
91
  return {
73
- code: transformedCode,
74
- map: null
75
- // For simplicity, not generating source maps
92
+ code: s.toString(),
93
+ map: s.generateMap({ hires: true })
76
94
  };
77
95
  }
78
96
  return null;
@@ -0,0 +1,28 @@
1
+ import type { Plugin } from 'vite';
2
+ import type * as apiLogger from '@cedarjs/api/logger';
3
+ /**
4
+ * Dev-only Vite plugin that makes the api's pino logger pretty-print
5
+ * through the same formatter plain `yarn cedar dev` gets via its
6
+ * `... | cedar-log-formatter` shell pipe.
7
+ *
8
+ * `--ud` mode runs the api in-process as Vite SSR middleware, so there's no
9
+ * separate api process whose stdout a shell pipe could format externally,
10
+ * and pino's default destination writes straight to file descriptor 1
11
+ * (bypassing `process.stdout.write`), so patching stdout wouldn't see the
12
+ * log lines either. Instead, this intercepts resolution of
13
+ * `@cedarjs/api/logger` and swaps in a wrapped `createLogger` that injects
14
+ * a formatting `destination` whenever the caller (the app's own
15
+ * `api/src/lib/logger.ts`) doesn't already supply one.
16
+ *
17
+ * Only registered in `createApiViteServer()`'s dev-only Vite instance —
18
+ * never touched by any production build path — so this has no effect on
19
+ * (and no dependency footprint added to) a deployed api.
20
+ */
21
+ export declare function cedarApiLogFormatterDevPlugin(): Plugin;
22
+ export declare function createFormattingDestination(): {
23
+ write(chunk: string): void;
24
+ };
25
+ type CreateLoggerParams = Parameters<typeof apiLogger.createLogger>[0];
26
+ export declare function createLogger(params?: CreateLoggerParams): apiLogger.Logger;
27
+ export {};
28
+ //# sourceMappingURL=vite-plugin-cedar-log-formatter-dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-log-formatter-dev.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-log-formatter-dev.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,OAAO,KAAK,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAOrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,CAoCtD;AAED,wBAAgB,2BAA2B;iBAK1B,MAAM;EAYtB;AAED,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAUtE,wBAAgB,YAAY,CAAC,MAAM,GAAE,kBAAuB,oBAS3D"}
@@ -0,0 +1,67 @@
1
+ import { LogFormatter } from "@cedarjs/api-server/logFormatter";
2
+ const INTERCEPTED_SPECIFIER = "@cedarjs/api/logger";
3
+ const VIRTUAL_MODULE_ID = "virtual:cedar-api-logger-dev";
4
+ const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
5
+ function cedarApiLogFormatterDevPlugin() {
6
+ return {
7
+ name: "cedar-api-log-formatter-dev",
8
+ enforce: "pre",
9
+ resolveId(id, importer) {
10
+ if (id === INTERCEPTED_SPECIFIER && importer !== RESOLVED_VIRTUAL_MODULE_ID) {
11
+ return RESOLVED_VIRTUAL_MODULE_ID;
12
+ }
13
+ return null;
14
+ },
15
+ load(id) {
16
+ if (id !== RESOLVED_VIRTUAL_MODULE_ID) {
17
+ return null;
18
+ }
19
+ return `
20
+ import * as realLogger from ${JSON.stringify(INTERCEPTED_SPECIFIER)}
21
+ import { LogFormatter } from '@cedarjs/api-server/logFormatter'
22
+
23
+ export * from ${JSON.stringify(INTERCEPTED_SPECIFIER)}
24
+
25
+ ${createFormattingDestination.toString()}
26
+
27
+ // toString() doesn't include the 'export' keyword
28
+ export ${createLogger.toString()}
29
+ `;
30
+ }
31
+ };
32
+ }
33
+ function createFormattingDestination() {
34
+ const format = LogFormatter();
35
+ let buffered = "";
36
+ return {
37
+ write(chunk) {
38
+ buffered += chunk;
39
+ const lines = buffered.split("\n");
40
+ buffered = lines.pop() ?? "";
41
+ for (const line of lines) {
42
+ if (line.length > 0) {
43
+ process.stdout.write(format(line));
44
+ }
45
+ }
46
+ }
47
+ };
48
+ }
49
+ const realLogger = {
50
+ createLogger: (_params) => {
51
+ return {};
52
+ }
53
+ };
54
+ function createLogger(params = {}) {
55
+ if (params.destination) {
56
+ return realLogger.createLogger(params);
57
+ }
58
+ return realLogger.createLogger({
59
+ ...params,
60
+ destination: createFormattingDestination()
61
+ });
62
+ }
63
+ export {
64
+ cedarApiLogFormatterDevPlugin,
65
+ createFormattingDestination,
66
+ createLogger
67
+ };
@@ -0,0 +1,28 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that automatically wraps the `standard` export in Cell mock files
4
+ * with `mockGraphQLQuery`.
5
+ *
6
+ * Only active in non-production environments (for Storybook and Jest).
7
+ *
8
+ * Transforms `*.Cell.mock.[js,ts]` files by:
9
+ * 1. Determining the query operation name from the adjacent Cell's QUERY export
10
+ * 2. Wrapping the `standard` function export in `mockGraphQLQuery(operationName, fn)`
11
+ * 3. If the Cell has an `afterQuery` export, also wraps with `afterQuery(fn())`
12
+ *
13
+ * This is a 1:1 port of `babel-plugin-redwood-mock-cell-data`.
14
+ */
15
+ export declare function cedarMockCellDataPlugin(): Plugin;
16
+ export declare const getCellMetadata: (p: string) => {
17
+ hasDefaultExport: boolean;
18
+ namedExports: NamedExports[];
19
+ hasQueryExport: NamedExports | undefined;
20
+ hasAfterQueryExport: NamedExports | undefined;
21
+ operationName: string;
22
+ };
23
+ interface NamedExports {
24
+ name: string;
25
+ type: 're-export' | 'variable' | 'function' | 'class';
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=vite-plugin-cedar-mock-cell-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-mock-cell-data.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-mock-cell-data.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CA2KhD;AAcD,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM;;;;;;CAoFxC,CAAA;AAgCD,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;CACtD"}
@@ -0,0 +1,247 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import babelGenerator from "@babel/generator";
4
+ import { parse as babelParse } from "@babel/parser";
5
+ import babelTraverse from "@babel/traverse";
6
+ import * as t from "@babel/types";
7
+ import fg from "fast-glob";
8
+ import { parse as graphqlParse, Kind } from "graphql";
9
+ const traverse = babelTraverse.default ?? babelTraverse;
10
+ const generate = babelGenerator.default ?? babelGenerator;
11
+ function cedarMockCellDataPlugin() {
12
+ return {
13
+ name: "cedar-mock-cell-data",
14
+ transform(code, id) {
15
+ if (!id.endsWith("Cell.mock.js") && !id.endsWith("Cell.mock.ts")) {
16
+ return null;
17
+ }
18
+ if (process.env.NODE_ENV === "production") {
19
+ return null;
20
+ }
21
+ const ast = parse(id, code);
22
+ if (!ast) {
23
+ return null;
24
+ }
25
+ let pathsToRemove = [];
26
+ const nodesToInsert = [];
27
+ const createVisitors = (addWatchFile) => ({
28
+ ExportNamedDeclaration(p) {
29
+ const d = p.node.declaration;
30
+ let mockFunction = null;
31
+ switch (d?.type) {
32
+ case "VariableDeclaration": {
33
+ const standardMockExport = d.declarations[0];
34
+ const exportId = standardMockExport.id;
35
+ const exportName = exportId?.name;
36
+ if (exportName !== "standard") {
37
+ return;
38
+ }
39
+ const mockFunctionMaybe = standardMockExport?.init;
40
+ if (!mockFunctionMaybe) {
41
+ return;
42
+ }
43
+ if (mockFunctionMaybe.type !== "ArrowFunctionExpression" && mockFunctionMaybe.type !== "FunctionExpression") {
44
+ throw new Error(
45
+ `
46
+
47
+ Mock Error: You must export your standard mock as a function
48
+
49
+ `
50
+ );
51
+ }
52
+ mockFunction = mockFunctionMaybe;
53
+ break;
54
+ }
55
+ case "FunctionDeclaration": {
56
+ const exportName = d.id?.name;
57
+ if (exportName !== "standard") {
58
+ return;
59
+ }
60
+ mockFunction = t.arrowFunctionExpression(d.params, d.body);
61
+ break;
62
+ }
63
+ default:
64
+ return;
65
+ }
66
+ const dirname = path.dirname(id);
67
+ const cellName = path.basename(dirname);
68
+ const [cellPath] = fg.sync(`${cellName}.{js,jsx,ts,tsx}`, {
69
+ cwd: dirname,
70
+ absolute: true,
71
+ ignore: ["node_modules"]
72
+ });
73
+ if (!cellPath) {
74
+ return;
75
+ }
76
+ addWatchFile?.(cellPath);
77
+ const cellMetadata = getCellMetadata(cellPath);
78
+ if (cellMetadata.hasDefaultExport || !cellMetadata.hasQueryExport) {
79
+ return;
80
+ }
81
+ if (!cellMetadata.operationName) {
82
+ console.warn(
83
+ `[cedar-mock-cell-data] Cell ${cellPath} has an unnamed GraphQL operation. The mock for ${id} will not work. Ensure the QUERY is named, e.g., "query GetUser { ... }"`
84
+ );
85
+ return;
86
+ }
87
+ const mockGraphQLCall = t.callExpression(
88
+ t.identifier("mockGraphQLQuery"),
89
+ [
90
+ t.stringLiteral(cellMetadata.operationName),
91
+ mockFunction
92
+ ]
93
+ );
94
+ pathsToRemove = [...pathsToRemove, p];
95
+ if (cellMetadata.hasAfterQueryExport) {
96
+ const importAfterQuery = t.importDeclaration(
97
+ [
98
+ t.importSpecifier(
99
+ t.identifier("afterQuery"),
100
+ t.identifier("afterQuery")
101
+ )
102
+ ],
103
+ t.stringLiteral(`./${path.basename(cellPath)}`)
104
+ );
105
+ nodesToInsert.push(
106
+ importAfterQuery,
107
+ createExportStandard(
108
+ t,
109
+ t.arrowFunctionExpression(
110
+ [],
111
+ t.callExpression(t.identifier("afterQuery"), [
112
+ t.callExpression(mockGraphQLCall, [])
113
+ ])
114
+ )
115
+ )
116
+ );
117
+ } else {
118
+ nodesToInsert.push(createExportStandard(t, mockGraphQLCall));
119
+ }
120
+ }
121
+ });
122
+ traverse(ast, createVisitors(this.addWatchFile?.bind(this)));
123
+ if (nodesToInsert.length === 0) {
124
+ return null;
125
+ }
126
+ for (const p of pathsToRemove) {
127
+ p.remove();
128
+ }
129
+ ;
130
+ ast.program.body.unshift(...nodesToInsert);
131
+ const result = generate(ast, { retainLines: false }, code);
132
+ return {
133
+ code: result.code,
134
+ map: result.map
135
+ };
136
+ }
137
+ };
138
+ }
139
+ function createExportStandard(babelTypes, ex) {
140
+ return babelTypes.exportNamedDeclaration(
141
+ babelTypes.variableDeclaration("const", [
142
+ babelTypes.variableDeclarator(babelTypes.identifier("standard"), ex)
143
+ ])
144
+ );
145
+ }
146
+ const getCellMetadata = (p) => {
147
+ const ast = getCellAst(p);
148
+ let hasDefaultExport = false;
149
+ const namedExports = [];
150
+ let operation;
151
+ traverse(ast, {
152
+ ExportDefaultDeclaration() {
153
+ hasDefaultExport = true;
154
+ },
155
+ ExportNamedDeclaration(path2) {
156
+ const specifiers = path2.node?.specifiers;
157
+ if (specifiers.length) {
158
+ for (const s of specifiers) {
159
+ const id = s.exported;
160
+ namedExports.push({
161
+ name: id.name,
162
+ type: "re-export"
163
+ });
164
+ }
165
+ return;
166
+ }
167
+ const declaration = path2.node.declaration;
168
+ if (!declaration) {
169
+ return;
170
+ }
171
+ if (declaration.type === "VariableDeclaration") {
172
+ const id = declaration.declarations[0].id;
173
+ namedExports.push({
174
+ name: id.name,
175
+ type: "variable"
176
+ });
177
+ } else if (declaration.type === "FunctionDeclaration") {
178
+ namedExports.push({
179
+ name: declaration?.id?.name,
180
+ type: "function"
181
+ });
182
+ } else if (declaration.type === "ClassDeclaration") {
183
+ namedExports.push({
184
+ name: declaration?.id?.name,
185
+ type: "class"
186
+ });
187
+ }
188
+ },
189
+ TaggedTemplateExpression(path2) {
190
+ if (path2.parent?.id?.name !== "QUERY") {
191
+ return;
192
+ }
193
+ operation = path2.node.quasi.quasis[0].value.raw;
194
+ }
195
+ });
196
+ const hasQueryExport = namedExports.find(({ name }) => name === "QUERY");
197
+ const hasAfterQueryExport = namedExports.find(
198
+ ({ name }) => name === "afterQuery"
199
+ );
200
+ let operationName = "";
201
+ if (operation) {
202
+ const document = graphqlParse(operation);
203
+ for (const definition of document.definitions) {
204
+ if (definition.kind === Kind.OPERATION_DEFINITION && definition.name?.value) {
205
+ operationName = definition.name.value;
206
+ }
207
+ }
208
+ }
209
+ return {
210
+ hasDefaultExport,
211
+ namedExports,
212
+ hasQueryExport,
213
+ hasAfterQueryExport,
214
+ operationName
215
+ };
216
+ };
217
+ function getCellAst(filePath) {
218
+ const code = fs.readFileSync(filePath, "utf-8");
219
+ const plugins = ["typescript", "jsx"].filter(Boolean);
220
+ try {
221
+ return babelParse(code, {
222
+ sourceType: "module",
223
+ plugins
224
+ });
225
+ } catch (e) {
226
+ console.error(`Error parsing: ${filePath}`);
227
+ console.error(e);
228
+ throw new Error(e?.message);
229
+ }
230
+ }
231
+ function parse(filePath, code) {
232
+ const plugins = ["typescript", "jsx"].filter(Boolean);
233
+ try {
234
+ return babelParse(code, {
235
+ sourceType: "module",
236
+ plugins
237
+ });
238
+ } catch (e) {
239
+ console.error(`Error parsing: ${filePath}`);
240
+ console.error(e);
241
+ return null;
242
+ }
243
+ }
244
+ export {
245
+ cedarMockCellDataPlugin,
246
+ getCellMetadata
247
+ };
@@ -0,0 +1,39 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that wraps exported API functions with OpenTelemetry spans to
4
+ * provide automatic tracing in your Cedar API.
5
+ *
6
+ * For each `export const fn = (async?) (...) => {...}` declaration in an API
7
+ * file this plugin:
8
+ *
9
+ * 1. Adds an import at the top of the file:
10
+ * import { trace as OTEL_TRACE } from '@opentelemetry/api'
11
+ *
12
+ * 2. Wraps the original export with an OTel span:
13
+ * export const fn = (async?) (...params) => {
14
+ * const __fn = (async?) (...params) => { ...original body... }
15
+ * const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
16
+ * const OTEL_RESULT = (await?) OTEL_TRACER.startActiveSpan(
17
+ * 'redwoodjs:api:<folder>:<fnName>',
18
+ * (async?) (span) => { ... }
19
+ * )
20
+ * return OTEL_RESULT
21
+ * }
22
+ *
23
+ * This replaces `babel-plugin-redwood-otel-wrapping` for all Vite and esbuild
24
+ * builds. The previous Babel plugin has been removed entirely; Jest transforms
25
+ * through the Vite SSR pipeline.
26
+ *
27
+ * NOTE: Known limitation. Spans will close before a Promise settles if a
28
+ * synchronous function returns a Promise. To trace async work correctly, mark
29
+ * the function as `async` if it returns or awaits Promises.
30
+ */
31
+ export declare function cedarOtelWrappingPlugin(): Plugin;
32
+ /**
33
+ * Applies OpenTelemetry span wrapping to API source files.
34
+ *
35
+ * Exported as a standalone function so it can be tested without a Vite context.
36
+ * Returns the transformed code string, or `null` if nothing was changed.
37
+ */
38
+ export declare function applyOtelWrapping(code: string, filename: string, apiFolder: string): string | null;
39
+ //# sourceMappingURL=vite-plugin-cedar-otel-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-otel-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-otel-wrapping.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAwBhD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CA+Ef"}