@cedarjs/vite 5.0.6 → 5.0.7-next.219

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 (152) 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 +117 -15
  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 +11 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +51 -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 +16 -6
  22. package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -1
  23. package/dist/lib/registerFwGlobalsAndShims.js +14 -4
  24. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts +13 -0
  25. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts.map +1 -0
  26. package/dist/plugins/vite-plugin-cedar-api-import-guard.js +17 -0
  27. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  28. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  29. package/dist/plugins/vite-plugin-cedar-auto-import.js +8 -1
  30. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  31. package/dist/plugins/vite-plugin-cedar-cell.js +2 -1
  32. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  33. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  34. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  35. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +12 -0
  36. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +1 -0
  37. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +35 -0
  38. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  39. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  40. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  41. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +42 -0
  42. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  43. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +103 -0
  44. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  45. package/dist/plugins/vite-plugin-cedar-import-dir.js +44 -31
  46. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +28 -0
  47. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +1 -0
  48. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +67 -0
  49. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +28 -0
  50. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +1 -0
  51. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +247 -0
  52. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
  53. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
  54. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
  55. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  56. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +92 -90
  57. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +29 -0
  58. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -1
  59. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +63 -81
  60. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  61. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +14 -0
  62. package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +12 -12
  63. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  64. package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +16 -16
  65. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +3 -0
  66. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  67. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  68. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  69. package/dist/rsc/rscBuildForSsr.js +3 -5
  70. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  71. package/dist/streaming/buildForStreamingServer.js +3 -5
  72. package/package.json +41 -52
  73. package/dist/cjs/ClientRouter.d.ts +0 -1
  74. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +0 -37
  75. package/dist/cjs/apiDevMiddleware.js +0 -371
  76. package/dist/cjs/build/build.d.ts +0 -1
  77. package/dist/cjs/build/build.js +0 -58
  78. package/dist/cjs/buildApp.js +0 -306
  79. package/dist/cjs/buildFeServer.d.ts +0 -1
  80. package/dist/cjs/buildFeServer.js +0 -63
  81. package/dist/cjs/buildRouteHooks.js +0 -80
  82. package/dist/cjs/buildRouteManifest.js +0 -92
  83. package/dist/cjs/buildRscClientAndServer.js +0 -54
  84. package/dist/cjs/cedar-unified-dev.js +0 -310
  85. package/dist/cjs/client.d.ts +0 -1
  86. package/dist/cjs/clientSsr.d.ts +0 -1
  87. package/dist/cjs/devFeServer.js +0 -157
  88. package/dist/cjs/index.d.ts +0 -1
  89. package/dist/cjs/index.js +0 -141
  90. package/dist/cjs/lib/StatusError.js +0 -37
  91. package/dist/cjs/lib/entries.js +0 -52
  92. package/dist/cjs/lib/getMergedConfig.js +0 -185
  93. package/dist/cjs/lib/onWarn.js +0 -36
  94. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -102
  95. package/dist/cjs/lib/workspacePackageAliases.js +0 -107
  96. package/dist/cjs/middleware/index.js +0 -22
  97. package/dist/cjs/middleware/invokeMiddleware.js +0 -52
  98. package/dist/cjs/middleware/register.js +0 -105
  99. package/dist/cjs/middleware/types.js +0 -16
  100. package/dist/cjs/package.json +0 -1
  101. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +0 -107
  102. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +0 -183
  103. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +0 -341
  104. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +0 -95
  105. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +0 -107
  106. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +0 -67
  107. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +0 -118
  108. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  109. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +0 -61
  110. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +0 -76
  111. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
  112. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +0 -346
  113. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +0 -134
  114. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +0 -134
  115. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -106
  116. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +0 -42
  117. package/dist/cjs/plugins/vite-plugin-merged-config.js +0 -39
  118. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +0 -104
  119. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +0 -75
  120. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +0 -159
  121. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +0 -125
  122. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +0 -75
  123. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -228
  124. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -398
  125. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +0 -46
  126. package/dist/cjs/rsc/rscBuildAnalyze.js +0 -126
  127. package/dist/cjs/rsc/rscBuildClient.js +0 -91
  128. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +0 -56
  129. package/dist/cjs/rsc/rscBuildEntriesFile.js +0 -115
  130. package/dist/cjs/rsc/rscBuildForServer.js +0 -168
  131. package/dist/cjs/rsc/rscBuildForSsr.js +0 -173
  132. package/dist/cjs/rsc/rscBuildRwEnvVars.js +0 -56
  133. package/dist/cjs/rsc/rscRenderer.js +0 -165
  134. package/dist/cjs/rsc/rscRequestHandler.js +0 -162
  135. package/dist/cjs/rsc/rscStudioHandlers.js +0 -156
  136. package/dist/cjs/runFeServer.js +0 -165
  137. package/dist/cjs/streaming/buildForStreamingServer.js +0 -65
  138. package/dist/cjs/streaming/collectCss.js +0 -52
  139. package/dist/cjs/streaming/createReactStreamingHandler.js +0 -173
  140. package/dist/cjs/streaming/streamHelpers.js +0 -230
  141. package/dist/cjs/streaming/transforms/bufferedTransform.js +0 -61
  142. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +0 -34
  143. package/dist/cjs/streaming/transforms/encode-decode.js +0 -36
  144. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +0 -84
  145. package/dist/cjs/streaming/triggerRouteHooks.js +0 -96
  146. package/dist/cjs/types.js +0 -16
  147. package/dist/cjs/utils.js +0 -92
  148. package/dist/package.json +0 -1
  149. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  150. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  151. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  152. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
@@ -0,0 +1,29 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that injects the auto-generated gqlorm backend into
4
+ * `api/src/functions/graphql.ts` at build time.
5
+ *
6
+ * When `experimental.gqlorm.enabled = true` and `.cedar/gqlorm/backend.ts`
7
+ * exists, this plugin:
8
+ *
9
+ * 1. Adds imports at the top of graphql.ts:
10
+ * import * as __gqlorm_sdl__ from '../../../.cedar/gqlorm/backend'
11
+ * import { db as __gqlorm_db__ } from 'src/lib/db'
12
+ *
13
+ * 2. Inserts a statement immediately before the `createGraphQLHandler` call:
14
+ * Object.assign(sdls, {
15
+ * __gqlorm__: {
16
+ * schema: __gqlorm_sdl__.schema,
17
+ * resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
18
+ * },
19
+ * })
20
+ *
21
+ * The `sdls` variable is already a `let` binding because
22
+ * `vite-plugin-cedar-import-dir` transforms the glob import
23
+ * `import sdls from 'src/graphql/**\/*.sdl.{js,ts}'` into `let sdls = {}`.
24
+ *
25
+ * This plugin is a no-op when gqlorm is disabled or the backend file does
26
+ * not exist.
27
+ */
28
+ export declare function cedarGqlormInjectPlugin(): Plugin;
29
+ //# sourceMappingURL=vite-plugin-cedar-gqlorm-inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-gqlorm-inject.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-gqlorm-inject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAQlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAgHhD"}
@@ -0,0 +1,76 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import {
4
+ getConfig,
5
+ getPaths,
6
+ importStatementPath
7
+ } from "@cedarjs/project-config";
8
+ function cedarGqlormInjectPlugin() {
9
+ return {
10
+ name: "cedar-gqlorm-inject",
11
+ transform(code, id) {
12
+ if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
13
+ return null;
14
+ }
15
+ if (code.includes("__gqlorm_sdl__")) {
16
+ return null;
17
+ }
18
+ if (!code.includes("createGraphQLHandler")) {
19
+ return null;
20
+ }
21
+ let config;
22
+ try {
23
+ config = getConfig();
24
+ } catch {
25
+ return null;
26
+ }
27
+ if (!config.experimental?.gqlorm?.enabled) {
28
+ return null;
29
+ }
30
+ let paths;
31
+ try {
32
+ paths = getPaths();
33
+ } catch {
34
+ return null;
35
+ }
36
+ const backendPathWithoutExt = path.join(
37
+ paths.generated.base,
38
+ "gqlorm",
39
+ "backend"
40
+ );
41
+ if (!fs.existsSync(backendPathWithoutExt + ".ts")) {
42
+ return null;
43
+ }
44
+ const handlerPattern = /^export\s+const\s+(\w+)\s*=\s*createGraphQLHandler\s*\(/m;
45
+ const handlerMatch = handlerPattern.exec(code);
46
+ if (!handlerMatch) {
47
+ return null;
48
+ }
49
+ const handlerLineStart = code.lastIndexOf("\n", handlerMatch.index) + 1;
50
+ const relPath = importStatementPath(
51
+ path.relative(path.dirname(id), backendPathWithoutExt)
52
+ ) + ".ts";
53
+ const dbSrcPath = path.join(paths.api.src, "lib", "db");
54
+ const relDbPath = importStatementPath(path.relative(path.dirname(id), dbSrcPath)) + ".ts";
55
+ const importDb = `import { db as __gqlorm_db__ } from '${relDbPath}'`;
56
+ const importSdl = `import * as __gqlorm_sdl__ from '${relPath}'`;
57
+ const importsToAdd = `${importDb}
58
+ ${importSdl}
59
+ `;
60
+ const sdlsMutation = `Object.assign(sdls, {
61
+ __gqlorm__: {
62
+ schema: __gqlorm_sdl__.schema,
63
+ resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
64
+ },
65
+ })
66
+ `;
67
+ const transformed = importsToAdd + code.slice(0, handlerLineStart) + sdlsMutation + code.slice(handlerLineStart);
68
+ return {
69
+ code: transformed
70
+ };
71
+ }
72
+ };
73
+ }
74
+ export {
75
+ cedarGqlormInjectPlugin
76
+ };
@@ -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;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAiHzC"}
@@ -0,0 +1,103 @@
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
+ const GRAPHQL_OPTIONS_ERROR_PREFIX = "Could not read the GraphQL options in api/src/functions/graphql. Cedar needs to statically extract them so the api server can serve /graphql and its health endpoint. ";
25
+ const GRAPHQL_OPTIONS_ERROR_SUFFIX = " Expected a single `createGraphQLHandler({ ... })` call with the options passed directly as an object, an identifier, a call, or a ternary.";
26
+ function applyGraphqlOptionsExtract(code) {
27
+ if (code.includes("__cedar_graphqlOptions")) {
28
+ return null;
29
+ }
30
+ const { program } = parseSync("graphql.ts", code, {
31
+ // lang is only a parse hint; 'ts' also parses JS (the graphql handler can
32
+ // be graphql.js in JS projects), so this is safe for both file types.
33
+ lang: "ts",
34
+ sourceType: "module"
35
+ });
36
+ const importNames = /* @__PURE__ */ new Set();
37
+ for (const node of program.body) {
38
+ if (node.type === "ImportDeclaration") {
39
+ if (node.source.value !== "@cedarjs/graphql-server") {
40
+ continue;
41
+ }
42
+ for (const specifier of node.specifiers) {
43
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
44
+ importNames.add(specifier.local.name);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ if (importNames.size === 0) {
50
+ return null;
51
+ }
52
+ const callExpressionPaths = [];
53
+ new Visitor({
54
+ CallExpression(node) {
55
+ if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
56
+ callExpressionPaths.push(node);
57
+ }
58
+ }
59
+ }).visit(program);
60
+ if (callExpressionPaths.length > 1) {
61
+ throw new Error(
62
+ GRAPHQL_OPTIONS_ERROR_PREFIX + "Found more than one call to createGraphQLHandler." + GRAPHQL_OPTIONS_ERROR_SUFFIX
63
+ );
64
+ }
65
+ const callExpression = callExpressionPaths[0];
66
+ if (!callExpression) {
67
+ throw new Error(
68
+ GRAPHQL_OPTIONS_ERROR_PREFIX + "createGraphQLHandler is imported but never called." + GRAPHQL_OPTIONS_ERROR_SUFFIX
69
+ );
70
+ }
71
+ const options = callExpression.arguments[0];
72
+ if (!options) {
73
+ throw new Error(
74
+ GRAPHQL_OPTIONS_ERROR_PREFIX + "createGraphQLHandler was called without any options." + GRAPHQL_OPTIONS_ERROR_SUFFIX
75
+ );
76
+ }
77
+ if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
78
+ throw new Error(
79
+ GRAPHQL_OPTIONS_ERROR_PREFIX + `The options argument is a ${options.type}, which can't be read statically.` + GRAPHQL_OPTIONS_ERROR_SUFFIX
80
+ );
81
+ }
82
+ const optionsStart = options.start;
83
+ const optionsEnd = options.end;
84
+ const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
85
+ const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
86
+ const indent = indentMatch ? indentMatch[0] : "";
87
+ const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
88
+ optionsStart,
89
+ optionsEnd
90
+ )}
91
+ `;
92
+ const s = new MagicString(code);
93
+ s.prependLeft(lineStart, optionsConst);
94
+ s.overwrite(optionsStart, optionsEnd, "__cedar_graphqlOptions");
95
+ return {
96
+ code: s.toString(),
97
+ map: s.generateMap({ hires: true })
98
+ };
99
+ }
100
+ export {
101
+ applyGraphqlOptionsExtract,
102
+ cedarGraphqlOptionsExtractPlugin
103
+ };
@@ -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,CA4H7C"}
@@ -1,6 +1,8 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
- import { parse, Lang } from "@ast-grep/napi";
3
- import fg from "fast-glob";
3
+ import MagicString from "magic-string";
4
+ import { parseSync } from "oxc-parser";
5
+ import { normalizePath } from "vite";
4
6
  import { importStatementPath, getPaths } from "@cedarjs/project-config";
5
7
  function cedarImportDirPlugin() {
6
8
  return {
@@ -10,51 +12,64 @@ function cedarImportDirPlugin() {
10
12
  if (!code.includes("/**/")) {
11
13
  return null;
12
14
  }
13
- const ext = path.extname(id);
14
- const language = ext === ".ts" || ext === ".tsx" ? Lang.TypeScript : Lang.JavaScript;
15
- let ast;
15
+ let program;
16
16
  try {
17
- ast = parse(language, code);
17
+ program = parseSync(id, code).program;
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();
24
23
  let hasTransformations = false;
25
- const edits = [];
26
- const globImports = root.findAll({
27
- rule: {
28
- pattern: "import $DEFAULT_IMPORT from $SOURCE"
24
+ const s = new MagicString(code);
25
+ for (const node of program.body) {
26
+ if (node.type !== "ImportDeclaration") {
27
+ continue;
29
28
  }
30
- });
31
- for (const importNode of globImports) {
32
- const sourceNode = importNode.getMatch("SOURCE");
33
- const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
34
- if (!sourceNode || !defaultImportNode) {
29
+ const defaultSpecifier = node.specifiers.find(
30
+ (specifier) => specifier.type === "ImportDefaultSpecifier"
31
+ );
32
+ if (!defaultSpecifier) {
35
33
  continue;
36
34
  }
37
- const sourceValue = sourceNode.text().slice(1, -1);
35
+ const sourceValue = node.source.value;
38
36
  if (!sourceValue.includes("/**/")) {
39
37
  continue;
40
38
  }
41
39
  hasTransformations = true;
42
- const importName = defaultImportNode.text();
40
+ const importName = defaultSpecifier.local.name;
43
41
  const importGlob = importStatementPath(sourceValue);
44
- const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(id);
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
+ }
45
55
  try {
46
- const dirFiles = fg.sync(importGlob, { cwd }).filter(
47
- (n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
48
- );
56
+ const dirFiles = fs.globSync(importGlob, {
57
+ cwd,
58
+ exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
59
+ });
49
60
  const staticGlob = importGlob.split("*")[0];
50
61
  const filePathToVarName = (filePath) => {
51
- return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
62
+ const normalizedPath = normalizePath(filePath);
63
+ return normalizedPath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
52
64
  };
53
65
  let replacement = `let ${importName} = {};
54
66
  `;
55
67
  for (const filePath of dirFiles) {
56
- const { dir: fileDir, name: fileName } = path.parse(filePath);
57
- const fileImportPath = fileDir + "/" + fileName;
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;
58
73
  const filePathVarName = filePathToVarName(filePath);
59
74
  const namespaceImportName = `${importName}_${filePathVarName}`;
60
75
  replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
@@ -62,17 +77,15 @@ function cedarImportDirPlugin() {
62
77
  replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
63
78
  `;
64
79
  }
65
- edits.push(importNode.replace(replacement.trim()));
80
+ s.overwrite(node.start, node.end, replacement.trim());
66
81
  } catch (error) {
67
82
  console.warn(`Failed to process glob import: ${sourceValue}`, error);
68
83
  }
69
84
  }
70
- if (hasTransformations && edits.length > 0) {
71
- const transformedCode = root.commitEdits(edits);
85
+ if (hasTransformations) {
72
86
  return {
73
- code: transformedCode,
74
- map: null
75
- // For simplicity, not generating source maps
87
+ code: s.toString(),
88
+ map: s.generateMap({ hires: true })
76
89
  };
77
90
  }
78
91
  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"}