@cedarjs/vite 5.0.6 → 5.0.7-next.186

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