@cedarjs/internal 5.0.7-next.336 → 5.0.7-rc.3

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 (153) hide show
  1. package/dist/ast.d.ts +0 -1
  2. package/dist/ast.d.ts.map +1 -1
  3. package/dist/ast.js +0 -21
  4. package/dist/build/api.d.ts +0 -2
  5. package/dist/build/api.d.ts.map +1 -1
  6. package/dist/build/api.js +39 -198
  7. package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
  8. package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
  9. package/dist/build/{esbuild-plugin-handler-als-wrapping.js → esbuild-plugin-cedar-context-wrapping.js} +12 -12
  10. package/dist/cjs/ast.d.ts +26 -0
  11. package/dist/cjs/ast.d.ts.map +1 -0
  12. package/dist/cjs/ast.js +201 -0
  13. package/dist/cjs/build/api.d.ts +7 -0
  14. package/dist/cjs/build/api.d.ts.map +1 -0
  15. package/dist/cjs/build/api.js +251 -0
  16. package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
  17. package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
  18. package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.js +59 -0
  19. package/dist/cjs/cliLogger.d.ts +11 -0
  20. package/dist/cjs/cliLogger.d.ts.map +1 -0
  21. package/dist/cjs/cliLogger.js +36 -0
  22. package/dist/cjs/dev.d.ts +2 -0
  23. package/dist/cjs/dev.d.ts.map +1 -0
  24. package/dist/cjs/dev.js +41 -0
  25. package/dist/cjs/files.d.ts +56 -0
  26. package/dist/cjs/files.d.ts.map +1 -0
  27. package/dist/cjs/files.js +230 -0
  28. package/dist/cjs/generate/clientPreset.d.ts +17 -0
  29. package/dist/cjs/generate/clientPreset.d.ts.map +1 -0
  30. package/dist/cjs/generate/clientPreset.js +84 -0
  31. package/dist/cjs/generate/generate.d.ts +10 -0
  32. package/dist/cjs/generate/generate.d.ts.map +1 -0
  33. package/dist/cjs/generate/generate.js +97 -0
  34. package/dist/cjs/generate/gqlormSchema.d.ts +113 -0
  35. package/dist/cjs/generate/gqlormSchema.d.ts.map +1 -0
  36. package/dist/cjs/generate/gqlormSchema.js +1061 -0
  37. package/dist/cjs/generate/graphqlCodeGen.d.ts +16 -0
  38. package/dist/cjs/generate/graphqlCodeGen.d.ts.map +1 -0
  39. package/dist/cjs/generate/graphqlCodeGen.js +380 -0
  40. package/dist/cjs/generate/graphqlSchema.d.ts +8 -0
  41. package/dist/cjs/generate/graphqlSchema.d.ts.map +1 -0
  42. package/dist/cjs/generate/graphqlSchema.js +157 -0
  43. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts +7 -0
  44. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts.map +1 -0
  45. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.js +65 -0
  46. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts +10 -0
  47. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +1 -0
  48. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.js +92 -0
  49. package/dist/cjs/generate/possibleTypes.d.ts +36 -0
  50. package/dist/cjs/generate/possibleTypes.d.ts.map +1 -0
  51. package/dist/cjs/generate/possibleTypes.js +106 -0
  52. package/dist/cjs/generate/templates/all-currentUser.d.ts.template +30 -0
  53. package/dist/cjs/generate/templates/all-gqlorm.d.ts.template +7 -0
  54. package/dist/cjs/generate/templates/api-globImports.d.ts.template +9 -0
  55. package/dist/cjs/generate/templates/api-globalContext.d.ts.template +7 -0
  56. package/dist/cjs/generate/templates/api-scenarios.d.ts.template +10 -0
  57. package/dist/cjs/generate/templates/api-test-globals.d.ts.template +5 -0
  58. package/dist/cjs/generate/templates/mirror-cell.d.ts.template +13 -0
  59. package/dist/cjs/generate/templates/mirror-directoryNamedModule.d.ts.template +5 -0
  60. package/dist/cjs/generate/templates/web-routerRoutes.d.ts.template +20 -0
  61. package/dist/cjs/generate/templates/web-routesPages.d.ts.template +13 -0
  62. package/dist/cjs/generate/templates/web-test-globals.d.ts.template +7 -0
  63. package/dist/cjs/generate/templates.d.ts +6 -0
  64. package/dist/cjs/generate/templates.d.ts.map +1 -0
  65. package/dist/cjs/generate/templates.js +68 -0
  66. package/dist/cjs/generate/trustedDocuments.d.ts +3 -0
  67. package/dist/cjs/generate/trustedDocuments.d.ts.map +1 -0
  68. package/dist/cjs/generate/trustedDocuments.js +95 -0
  69. package/dist/cjs/generate/typeDefinitions.d.ts +31 -0
  70. package/dist/cjs/generate/typeDefinitions.d.ts.map +1 -0
  71. package/dist/cjs/generate/typeDefinitions.js +372 -0
  72. package/dist/cjs/generate/types.d.ts +6 -0
  73. package/dist/cjs/generate/types.d.ts.map +1 -0
  74. package/dist/cjs/generate/types.js +16 -0
  75. package/dist/cjs/generate/watch.d.ts +3 -0
  76. package/dist/cjs/generate/watch.d.ts.map +1 -0
  77. package/dist/cjs/generate/watch.js +132 -0
  78. package/dist/cjs/gql.d.ts +14 -0
  79. package/dist/cjs/gql.d.ts.map +1 -0
  80. package/dist/cjs/gql.js +108 -0
  81. package/dist/cjs/index.d.ts +11 -0
  82. package/dist/cjs/index.d.ts.map +1 -0
  83. package/dist/cjs/index.js +49 -0
  84. package/dist/cjs/jsx.d.ts +16 -0
  85. package/dist/cjs/jsx.d.ts.map +1 -0
  86. package/dist/cjs/jsx.js +101 -0
  87. package/dist/cjs/jsxAttributeValue.d.ts +2 -0
  88. package/dist/cjs/jsxAttributeValue.d.ts.map +1 -0
  89. package/dist/cjs/jsxAttributeValue.js +129 -0
  90. package/dist/cjs/package.json +1 -0
  91. package/dist/cjs/project.d.ts +8 -0
  92. package/dist/cjs/project.d.ts.map +1 -0
  93. package/dist/cjs/project.js +82 -0
  94. package/dist/cjs/routes.d.ts +42 -0
  95. package/dist/cjs/routes.d.ts.map +1 -0
  96. package/dist/cjs/routes.js +111 -0
  97. package/dist/cjs/ts2js.d.ts +40 -0
  98. package/dist/cjs/ts2js.d.ts.map +1 -0
  99. package/dist/cjs/ts2js.js +159 -0
  100. package/dist/cjs/validateSchema.d.ts +14 -0
  101. package/dist/cjs/validateSchema.d.ts.map +1 -0
  102. package/dist/cjs/validateSchema.js +195 -0
  103. package/dist/generate/clientPreset.d.ts +7 -0
  104. package/dist/generate/clientPreset.d.ts.map +1 -1
  105. package/dist/generate/clientPreset.js +5 -12
  106. package/dist/generate/generate.d.ts.map +1 -1
  107. package/dist/generate/generate.js +0 -6
  108. package/dist/generate/graphqlCodeGen.d.ts.map +1 -1
  109. package/dist/generate/graphqlCodeGen.js +10 -36
  110. package/dist/generate/graphqlSchema.d.ts.map +1 -1
  111. package/dist/generate/templates.d.ts.map +1 -1
  112. package/dist/generate/templates.js +6 -1
  113. package/dist/generate/typeDefinitions.d.ts.map +1 -1
  114. package/dist/generate/typeDefinitions.js +1 -15
  115. package/dist/gql.d.ts +0 -20
  116. package/dist/gql.d.ts.map +1 -1
  117. package/dist/gql.js +0 -24
  118. package/dist/jsx.d.ts.map +1 -1
  119. package/dist/routes.d.ts.map +1 -1
  120. package/package.json +91 -55
  121. package/dist/build/api-graphql-transforms.d.ts +0 -34
  122. package/dist/build/api-graphql-transforms.d.ts.map +0 -1
  123. package/dist/build/api-graphql-transforms.js +0 -129
  124. package/dist/build/auto-import.d.ts +0 -10
  125. package/dist/build/auto-import.d.ts.map +0 -1
  126. package/dist/build/auto-import.js +0 -120
  127. package/dist/build/directory-named-import.d.ts +0 -2
  128. package/dist/build/directory-named-import.d.ts.map +0 -1
  129. package/dist/build/directory-named-import.js +0 -26
  130. package/dist/build/esbuild-plugin-api-graphql.d.ts +0 -6
  131. package/dist/build/esbuild-plugin-api-graphql.d.ts.map +0 -1
  132. package/dist/build/esbuild-plugin-api-graphql.js +0 -78
  133. package/dist/build/esbuild-plugin-cedar-otel-wrapping.d.ts +0 -13
  134. package/dist/build/esbuild-plugin-cedar-otel-wrapping.d.ts.map +0 -1
  135. package/dist/build/esbuild-plugin-cedar-otel-wrapping.js +0 -180
  136. package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts +0 -4
  137. package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts.map +0 -1
  138. package/dist/build/import-dir.d.ts +0 -22
  139. package/dist/build/import-dir.d.ts.map +0 -1
  140. package/dist/build/import-dir.js +0 -54
  141. package/dist/build/import-extensions.d.ts +0 -47
  142. package/dist/build/import-extensions.d.ts.map +0 -1
  143. package/dist/build/import-extensions.js +0 -59
  144. package/dist/build/job-path-injector.d.ts +0 -15
  145. package/dist/build/job-path-injector.d.ts.map +0 -1
  146. package/dist/build/job-path-injector.js +0 -69
  147. package/dist/build/src-alias.d.ts +0 -14
  148. package/dist/build/src-alias.d.ts.map +0 -1
  149. package/dist/build/src-alias.js +0 -17
  150. package/dist/build/tsconfig-paths.d.ts +0 -2
  151. package/dist/build/tsconfig-paths.d.ts.map +0 -1
  152. package/dist/build/tsconfig-paths.js +0 -72
  153. package/dist/generate/templates/mirror-cell-fragment.d.ts.template +0 -18
@@ -1,78 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import {
4
- getApiSideBabelConfigPath,
5
- getApiSideBabelPluginsForVite,
6
- transformWithBabel
7
- } from "@cedarjs/babel-config";
8
- import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
9
- import {
10
- applyGqlormInject,
11
- applyGraphqlOptionsExtract
12
- } from "./api-graphql-transforms.js";
13
- import { applyAutoImports } from "./auto-import.js";
14
- import { applyDirectoryNamedImport } from "./directory-named-import.js";
15
- import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
16
- import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
17
- import { applyImportDir } from "./import-dir.js";
18
- import { applyImportExtensions } from "./import-extensions.js";
19
- import { applySrcAlias } from "./src-alias.js";
20
- import { applyTsconfigPaths } from "./tsconfig-paths.js";
21
- const cedarApiGraphqlPlugin = {
22
- name: "cedar-api-graphql",
23
- setup(build) {
24
- build.onLoad({ filter: /[/\\]graphql\.(ts|js)$/ }, async (args) => {
25
- const cedarConfig = getConfig();
26
- let fileContents = await fs.promises.readFile(args.path, "utf-8");
27
- fileContents = applySrcAlias(
28
- fileContents,
29
- path.dirname(
30
- path.relative(build.initialOptions.absWorkingDir + "/src", args.path)
31
- )
32
- );
33
- fileContents = applyTsconfigPaths(
34
- fileContents,
35
- args.path,
36
- getPaths().api.base
37
- );
38
- fileContents = applyDirectoryNamedImport(fileContents, args.path);
39
- fileContents = applyGraphqlOptionsExtract(fileContents) ?? fileContents;
40
- fileContents = applyGqlormInject(fileContents, args.path, ".js") ?? fileContents;
41
- fileContents = applyAutoImports(fileContents);
42
- fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
43
- const apiBabelConfigPath = getApiSideBabelConfigPath();
44
- let code = fileContents;
45
- if (apiBabelConfigPath) {
46
- const transformedCode = await transformWithBabel(
47
- fileContents,
48
- args.path,
49
- getApiSideBabelPluginsForVite(),
50
- "inline",
51
- true
52
- );
53
- if (!transformedCode?.code) {
54
- throw new Error(`Could not transform file: ${args.path}`);
55
- }
56
- code = transformedCode.code;
57
- }
58
- code = applyImportExtensions(code, args.path);
59
- if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
60
- code = applyOtelWrapping(code, args.path, getPaths().api.src) ?? code;
61
- }
62
- code = applyHandlerAlsWrapping(code, {
63
- projectIsEsm: projectSideIsEsm("api")
64
- }) ?? code;
65
- return {
66
- contents: code,
67
- // Babel output is always plain JS. Without Babel the contents are
68
- // still TypeScript when the source file is graphql.ts, so pick the
69
- // matching loader and let esbuild do the stripping. (The onLoad
70
- // filter only matches .ts and .js files.)
71
- loader: !apiBabelConfigPath && args.path.endsWith(".ts") ? "ts" : "js"
72
- };
73
- });
74
- }
75
- };
76
- export {
77
- cedarApiGraphqlPlugin
78
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * Standalone esbuild equivalent of the Vite cedarOtelWrappingPlugin. Applied
3
- * inline in the esbuild API build and the standalone-Vite API build so neither
4
- * path depends on a Babel OTel plugin.
5
- *
6
- * For each `export const fn = (async?) (...) => {...}` in an API file, this
7
- * wraps it with an OpenTelemetry span.
8
- *
9
- * Keep this in sync with
10
- * packages/vite/src/plugins/vite-plugin-cedar-otel-wrapping.ts.
11
- */
12
- export declare function applyOtelWrapping(code: string, filename: string, apiSrc: string): string | null;
13
- //# sourceMappingURL=esbuild-plugin-cedar-otel-wrapping.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"esbuild-plugin-cedar-otel-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-cedar-otel-wrapping.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AAEH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAmFf"}
@@ -1,180 +0,0 @@
1
- import path from "node:path";
2
- import { parseSync } from "oxc-parser";
3
- function applyOtelWrapping(code, filename, apiSrc) {
4
- const relative = path.relative(apiSrc, filename);
5
- const apiFolder = relative.split(path.sep)[0] ?? "?";
6
- const parseResult = parseSync(filename, code, { sourceType: "module" });
7
- const replacements = [];
8
- for (const node of parseResult.program.body) {
9
- if (node.type !== "ExportNamedDeclaration") {
10
- continue;
11
- }
12
- const decl = node.declaration;
13
- if (decl?.type !== "VariableDeclaration") {
14
- continue;
15
- }
16
- const declarator = decl.declarations[0];
17
- if (!declarator) {
18
- continue;
19
- }
20
- const fn = declarator.init;
21
- if (fn?.type !== "ArrowFunctionExpression") {
22
- continue;
23
- }
24
- if (declarator.id.type !== "Identifier") {
25
- continue;
26
- }
27
- const fnName = declarator.id.name;
28
- const innerArgs = buildInnerArgs(fn.params);
29
- if (innerArgs === null) {
30
- continue;
31
- }
32
- const fnHeader = code.slice(fn.start, fn.body.start);
33
- const originalFnSrc = code.slice(fn.start, fn.end);
34
- const isAsync = fn.async;
35
- const awaitKw = isAsync ? "await " : "";
36
- const asyncKw = isAsync ? "async " : "";
37
- replacements.push({
38
- start: node.start,
39
- end: node.end,
40
- src: buildWrappedExport(
41
- fnName,
42
- fnHeader,
43
- originalFnSrc,
44
- innerArgs,
45
- awaitKw,
46
- asyncKw,
47
- apiFolder,
48
- filename
49
- )
50
- });
51
- }
52
- if (replacements.length === 0) {
53
- return null;
54
- }
55
- let output = code;
56
- for (let i = replacements.length - 1; i >= 0; i--) {
57
- const r = replacements[i];
58
- output = output.slice(0, r.start) + r.src + output.slice(r.end);
59
- }
60
- return `import { trace as OTEL_TRACE } from '@opentelemetry/api'
61
- ` + output;
62
- }
63
- function buildInnerArgs(params) {
64
- const args = [];
65
- for (const param of params) {
66
- if (param.type === "RestElement" || param.type === "ArrayPattern" || param.type === "TSParameterProperty") {
67
- return null;
68
- }
69
- if (param.type === "Identifier") {
70
- args.push(param.name);
71
- continue;
72
- }
73
- if (param.type === "ObjectPattern") {
74
- for (const prop of param.properties) {
75
- if (prop.type === "RestElement") {
76
- return null;
77
- }
78
- if (prop.key.type !== "Identifier") {
79
- return null;
80
- }
81
- const value = prop.value;
82
- if (value.type !== "Identifier" && value.type !== "AssignmentPattern" && value.type !== "ObjectPattern") {
83
- return null;
84
- }
85
- if (value.type === "AssignmentPattern") {
86
- if (value.left.type !== "Identifier" && value.left.type !== "ObjectPattern") {
87
- return null;
88
- }
89
- }
90
- }
91
- const obj = buildObjectCallArg(param);
92
- if (obj === null) {
93
- return null;
94
- }
95
- args.push(obj);
96
- continue;
97
- }
98
- if (param.type === "AssignmentPattern") {
99
- const ap = param;
100
- if (ap.left.type === "Identifier") {
101
- args.push(ap.left.name);
102
- } else if (ap.left.type === "ObjectPattern") {
103
- const obj = buildObjectCallArg(ap.left);
104
- if (obj === null) {
105
- return null;
106
- }
107
- args.push(obj);
108
- } else {
109
- return null;
110
- }
111
- continue;
112
- }
113
- return null;
114
- }
115
- return args.join(", ");
116
- }
117
- function buildObjectCallArg(pattern) {
118
- const keys = [];
119
- for (const prop of pattern.properties) {
120
- if (prop.type === "RestElement") {
121
- return null;
122
- }
123
- if (prop.key.type !== "Identifier") {
124
- return null;
125
- }
126
- const keyName = prop.key.name;
127
- let valueName = null;
128
- if (prop.value.type === "Identifier") {
129
- valueName = prop.value.name;
130
- } else if (prop.value.type === "AssignmentPattern") {
131
- if (prop.value.left.type === "Identifier") {
132
- valueName = prop.value.left.name;
133
- } else {
134
- return null;
135
- }
136
- } else {
137
- return null;
138
- }
139
- if (valueName !== keyName) {
140
- keys.push(`${keyName}: ${valueName}`);
141
- } else {
142
- keys.push(keyName);
143
- }
144
- }
145
- return `{ ${keys.join(", ")} }`;
146
- }
147
- function buildWrappedExport(fnName, fnHeader, originalFnSrc, innerArgs, awaitKw, asyncKw, apiFolder, filename) {
148
- const privateName = `__${fnName}`;
149
- const spanName = `redwoodjs:api:${apiFolder}:${fnName}`;
150
- return `export const ${fnName} = ${fnHeader}{
151
- const ${privateName} = ${originalFnSrc}
152
- const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
153
- const OTEL_RESULT = ${awaitKw}OTEL_TRACER.startActiveSpan(
154
- '${spanName}',
155
- ${asyncKw}(span) => {
156
- span.setAttribute('code.function', '${fnName}')
157
- span.setAttribute('code.filepath', ${JSON.stringify(filename)})
158
- try {
159
- const OTEL_INNER_RESULT = ${awaitKw}${privateName}(${innerArgs})
160
- span.end()
161
- return OTEL_INNER_RESULT
162
- } catch (error) {
163
- span.recordException(error)
164
- span.setStatus({
165
- code: 2,
166
- message:
167
- error?.message?.split('\\n')[0] ??
168
- error?.toString()?.split('\\n')[0],
169
- })
170
- span.end()
171
- throw error
172
- }
173
- }
174
- )
175
- return OTEL_RESULT
176
- }`;
177
- }
178
- export {
179
- applyOtelWrapping
180
- };
@@ -1,4 +0,0 @@
1
- export declare function applyHandlerAlsWrapping(code: string, { projectIsEsm }?: {
2
- projectIsEsm?: boolean;
3
- }): string | null;
4
- //# sourceMappingURL=esbuild-plugin-handler-als-wrapping.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"esbuild-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CA0Cf"}
@@ -1,22 +0,0 @@
1
- import type { SourceMap } from 'magic-string';
2
- /**
3
- * Expands glob directory imports such as:
4
- * import services from 'src/services/**\/*.{js,ts}'
5
- * into individual namespace imports:
6
- * let services = {}
7
- * import * as services_a from 'src/services/a'
8
- * services.a = services_a
9
- *
10
- * This is the esbuild-path equivalent of:
11
- * - babel-plugin-redwood-import-dir (kept for Jest / console / data-migrate)
12
- * - cedarImportDirPlugin (Vite plugin, for Vite build paths)
13
- *
14
- * Code duplication between the two non-Babel plugins is intentional.
15
- *
16
- * Returns the transformed source code, or null if no glob imports were found.
17
- */
18
- export declare function applyImportDir(code: string, filePath: string): {
19
- code: string;
20
- map?: SourceMap;
21
- } | null;
22
- //# sourceMappingURL=import-dir.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"import-dir.d.ts","sourceRoot":"","sources":["../../src/build/import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAI7C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAyE1C"}
@@ -1,54 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import MagicString from "magic-string";
4
- import { getPaths, importStatementPath } from "@cedarjs/project-config";
5
- function applyImportDir(code, filePath) {
6
- if (!code.includes("**")) {
7
- return null;
8
- }
9
- const GLOB_IMPORT_RE = /^import\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;
10
- const s = new MagicString(code);
11
- let hasTransformations = false;
12
- for (const match of code.matchAll(GLOB_IMPORT_RE)) {
13
- const importName = match[1];
14
- const sourceValue = match[2];
15
- if (!sourceValue.includes("**")) {
16
- continue;
17
- }
18
- const importGlob = importStatementPath(sourceValue);
19
- const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(filePath);
20
- let dirFiles;
21
- try {
22
- dirFiles = fs.globSync(importGlob, {
23
- cwd,
24
- exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
25
- });
26
- } catch {
27
- continue;
28
- }
29
- const staticGlob = importGlob.split("*")[0];
30
- const filePathToVarName = (fp) => fp.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
31
- hasTransformations = true;
32
- let replacement = `let ${importName} = {};
33
- `;
34
- for (const fp of dirFiles) {
35
- const { dir: fileDir, name: fileName } = path.parse(fp);
36
- const normalizedDir = importStatementPath(fileDir);
37
- const varName = filePathToVarName(fp);
38
- const nsImport = `${importName}_${varName}`;
39
- replacement += `import * as ${nsImport} from '${normalizedDir}/${fileName}';
40
- `;
41
- replacement += `${importName}.${varName} = ${nsImport};
42
- `;
43
- }
44
- s.overwrite(
45
- match.index,
46
- match.index + match[0].length,
47
- replacement.trimEnd()
48
- );
49
- }
50
- return hasTransformations ? { code: s.toString(), map: s.generateMap({ hires: true }) } : null;
51
- }
52
- export {
53
- applyImportDir
54
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * Rewrites relative import specifiers so they point at the compiled `.js`
3
- * output files instead of the TypeScript/JSX source files:
4
- *
5
- * - Extensionless imports (`from '../lib/db'`) get `.js` appended so that
6
- * Node's ESM resolver can locate the compiled output at runtime. Node's
7
- * CJS resolver appends the extension itself, so for CJS output this
8
- * rewrite is behavior-neutral.
9
- * - Explicit TypeScript-extension imports (`from './hello.ts'`, allowed by
10
- * `allowImportingTsExtensions` in the project tsconfig) are rewritten to
11
- * `.js`, since the file on disk after compilation is `hello.js`. This is
12
- * required for both CJS and ESM output — neither Node resolver maps a
13
- * `.ts` specifier to a `.js` file.
14
- *
15
- * Handles static imports/re-exports (`from '../lib/db'`), side-effect
16
- * imports (`import '../lib/setup'`), dynamic imports (`import('../lib/db')`),
17
- * and `require('../lib/db')` calls (emitted when a custom api/babel.config.js
18
- * lowers ESM to CommonJS before this function runs).
19
- *
20
- * Always outputs `.js` because both build pipelines compile every source
21
- * file (`.ts`, `.tsx`, `.jsx`) to `.js` output. For a source file
22
- * `api/src/lib/db.ts` or `api/src/lib/db.tsx`, the output is always
23
- * `api/dist/lib/db.js`, so all import specifiers must use `.js` at runtime.
24
- *
25
- * For the standalone esbuild build path (`runCedarBabelTransformsPlugin`)
26
- * this replaces the `resolvePath` hook in `babel-plugin-module-resolver`,
27
- * which is not part of `getApiSideBabelPluginsForVite()`.
28
- *
29
- * It is a plain function called inline — not an esbuild plugin — following
30
- * the same pattern as `applySrcAlias`, `applyTsconfigPaths`, etc.
31
- *
32
- * Also handles Cedar SDL files whose names include a compound extension:
33
- * `contacts.sdl.ts` compiles to `contacts.sdl.js`, so an import specifier
34
- * `../graphql/contacts.sdl` (generated by applyImportDir's glob expansion)
35
- * is rewritten to `../graphql/contacts.sdl.js`.
36
- *
37
- * Example: in `api/src/functions/graphql.ts` importing `../lib/db`, this
38
- * rewrites it to `../lib/db.js` when `api/src/lib/db.ts` (or `db.tsx`)
39
- * exists on disk.
40
- *
41
- * Files under the generated data directory (`.cedar/` or `.redwood/`) are
42
- * excluded from rewriting: generated artifacts such as the gqlorm backend
43
- * (`.cedar/gqlorm/backend.ts`) are never compiled to `.js`, so an explicit
44
- * `.ts` import pointing there must stay `.ts` at runtime.
45
- */
46
- export declare function applyImportExtensions(code: string, fromFile: string): string;
47
- //# sourceMappingURL=import-extensions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"import-extensions.d.ts","sourceRoot":"","sources":["../../src/build/import-extensions.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA+G5E"}
@@ -1,59 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { getPaths } from "@cedarjs/project-config";
4
- function applyImportExtensions(code, fromFile) {
5
- const fromDir = path.dirname(fromFile);
6
- const generatedBase = getPaths().generated.base;
7
- const rewriteImportPath = (importPath, preservePrefix, preserveSuffix) => {
8
- const existingExt = path.extname(importPath);
9
- const absImport = path.join(fromDir, importPath);
10
- const relativeToGeneratedBase = path.relative(generatedBase, absImport);
11
- if (relativeToGeneratedBase === "" || !relativeToGeneratedBase.startsWith("..") && !path.isAbsolute(relativeToGeneratedBase)) {
12
- return preservePrefix + importPath + preserveSuffix;
13
- }
14
- if ((existingExt === ".ts" || existingExt === ".tsx") && fs.existsSync(absImport)) {
15
- const base2 = importPath.slice(0, -existingExt.length);
16
- return preservePrefix + base2 + ".js" + preserveSuffix;
17
- }
18
- if (existingExt && existingExt !== ".js" && existingExt !== ".jsx") {
19
- if (fs.existsSync(absImport + ".ts") || fs.existsSync(absImport + ".js") || fs.existsSync(absImport + ".tsx") || fs.existsSync(absImport + ".jsx")) {
20
- return preservePrefix + importPath + ".js" + preserveSuffix;
21
- }
22
- return preservePrefix + importPath + preserveSuffix;
23
- }
24
- const base = existingExt ? importPath.slice(0, -existingExt.length) : importPath;
25
- const absBase = path.join(fromDir, base);
26
- if (fs.existsSync(absBase + ".ts") || fs.existsSync(absBase + ".js") || fs.existsSync(absBase + ".tsx") || fs.existsSync(absBase + ".jsx")) {
27
- return preservePrefix + base + ".js" + preserveSuffix;
28
- }
29
- return preservePrefix + importPath + preserveSuffix;
30
- };
31
- let result = code.replace(
32
- /\bfrom\s+(['"])(\.\.?\/[^'"]+)\1/g,
33
- (match, quote, importPath) => {
34
- return `from ${rewriteImportPath(importPath, quote, quote)}`;
35
- }
36
- );
37
- result = result.replace(
38
- /(^[ \t]*|;\s*)import\s+(['"])(\.\.?\/[^'"]+)\2/gm,
39
- (match, prefix, quote, importPath) => {
40
- return `${prefix}import ${rewriteImportPath(importPath, quote, quote)}`;
41
- }
42
- );
43
- result = result.replace(
44
- /\bimport\s*\(\s*(['"])(\.\.?\/[^'"]+)\1\s*\)/g,
45
- (match, quote, importPath) => {
46
- return `import(${rewriteImportPath(importPath, quote, quote)})`;
47
- }
48
- );
49
- result = result.replace(
50
- /\brequire\s*\(\s*(['"])(\.\.?\/[^'"]+)\1\s*\)/g,
51
- (match, quote, importPath) => {
52
- return `require(${rewriteImportPath(importPath, quote, quote)})`;
53
- }
54
- );
55
- return result;
56
- }
57
- export {
58
- applyImportExtensions
59
- };
@@ -1,15 +0,0 @@
1
- /**
2
- * Injects `path` and `name` properties into `createJob()` definitions so the
3
- * jobs runner can locate and identify the job's module at runtime.
4
- *
5
- * Standalone equivalent of the Vite cedarjsJobPathInjectorPlugin (used by
6
- * buildApp and apiDevMiddleware) and the Babel pluginRedwoodJobPathInjector
7
- * override they replaced. Applied inline in the esbuild API build and the
8
- * standalone-Vite API build so neither path depends on Babel for job path
9
- * injection.
10
- *
11
- * Keep this in sync with
12
- * packages/vite/src/plugins/vite-plugin-cedarjs-job-path-injector.ts.
13
- */
14
- export declare function applyJobPathInjector(code: string, filePath: string, jobsDir: string): string | null;
15
- //# sourceMappingURL=job-path-injector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job-path-injector.d.ts","sourceRoot":"","sources":["../../src/build/job-path-injector.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CA8Ff"}
@@ -1,69 +0,0 @@
1
- import path from "node:path";
2
- import { parseSync } from "oxc-parser";
3
- function applyJobPathInjector(code, filePath, jobsDir) {
4
- if (!code.includes("createJob")) {
5
- return null;
6
- }
7
- let program;
8
- try {
9
- program = parseSync(filePath, code, { sourceType: "module" }).program;
10
- } catch (error) {
11
- console.warn("Failed to parse file:", filePath);
12
- console.warn(error);
13
- return null;
14
- }
15
- const importPath = path.relative(jobsDir, filePath);
16
- const importPathWithoutExtension = importPath.replace(/\.[^/.]+$/, "");
17
- const insertions = [];
18
- for (const node of program.body) {
19
- if (node.type !== "ExportNamedDeclaration") {
20
- continue;
21
- }
22
- const decl = node.declaration;
23
- if (decl?.type !== "VariableDeclaration") {
24
- continue;
25
- }
26
- for (const declarator of decl.declarations) {
27
- if (declarator.id.type !== "Identifier") {
28
- continue;
29
- }
30
- const init = declarator.init;
31
- if (init?.type !== "CallExpression") {
32
- continue;
33
- }
34
- const callee = init.callee;
35
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "createJob") {
36
- continue;
37
- }
38
- const configArg = init.arguments[0];
39
- if (configArg?.type !== "ObjectExpression") {
40
- continue;
41
- }
42
- const pathProperty = `path: ${JSON.stringify(importPathWithoutExtension)}`;
43
- const nameProperty = `name: ${JSON.stringify(declarator.id.name)}`;
44
- const lastProperty = configArg.properties.at(-1);
45
- if (lastProperty) {
46
- insertions.push({
47
- pos: lastProperty.end,
48
- text: `, ${pathProperty}, ${nameProperty}`
49
- });
50
- } else {
51
- insertions.push({
52
- pos: configArg.start + 1,
53
- text: `${pathProperty}, ${nameProperty}`
54
- });
55
- }
56
- }
57
- }
58
- if (insertions.length === 0) {
59
- return null;
60
- }
61
- let result = code;
62
- for (const { pos, text } of insertions.sort((a, b) => b.pos - a.pos)) {
63
- result = result.slice(0, pos) + text + result.slice(pos);
64
- }
65
- return result;
66
- }
67
- export {
68
- applyJobPathInjector
69
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * Rewrites `src/` bare specifiers in source code to relative paths, so that the
3
- * esbuild API build (with `bundle: false`) produces output files with
4
- * resolvable import paths at runtime.
5
- *
6
- * This replaces the `babel-plugin-module-resolver` `src: './src'` alias for the
7
- * esbuild build paths. It is a plain function called inline from the existing
8
- * esbuild `onLoad` handlers — not an esbuild plugin itself.
9
- *
10
- * For a file at `api/src/functions/graphql.ts` importing `src/lib/db`, this
11
- * rewrites it to `../lib/db`.
12
- */
13
- export declare function applySrcAlias(code: string, fromDirRelativeToApiSrc: string): string;
14
- //# sourceMappingURL=src-alias.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-alias.d.ts","sourceRoot":"","sources":["../../src/build/src-alias.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAEH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,uBAAuB,EAAE,MAAM,GAC9B,MAAM,CAWR"}
@@ -1,17 +0,0 @@
1
- import path from "node:path";
2
- import { importStatementPath } from "@cedarjs/project-config";
3
- function applySrcAlias(code, fromDirRelativeToApiSrc) {
4
- return code.replace(
5
- /from\s+['"]src\/(.+?)['"]/g,
6
- (_match, rest) => {
7
- const target = path.relative(fromDirRelativeToApiSrc, rest);
8
- const formatted = importStatementPath(
9
- target.startsWith(".") ? target : "./" + target
10
- );
11
- return `from '${formatted}'`;
12
- }
13
- );
14
- }
15
- export {
16
- applySrcAlias
17
- };
@@ -1,2 +0,0 @@
1
- export declare function applyTsconfigPaths(code: string, filePath: string, cwd: string): string;
2
- //# sourceMappingURL=tsconfig-paths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tsconfig-paths.d.ts","sourceRoot":"","sources":["../../src/build/tsconfig-paths.ts"],"names":[],"mappings":"AA8FA,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACV,MAAM,CAyCR"}