@cedarjs/internal 6.0.0-canary.2771 → 6.0.0-canary.2772

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 (125) hide show
  1. package/package.json +23 -80
  2. package/dist/cjs/ast.d.ts +0 -27
  3. package/dist/cjs/ast.d.ts.map +0 -1
  4. package/dist/cjs/ast.js +0 -223
  5. package/dist/cjs/build/api-graphql-transforms.d.ts +0 -34
  6. package/dist/cjs/build/api-graphql-transforms.d.ts.map +0 -1
  7. package/dist/cjs/build/api-graphql-transforms.js +0 -150
  8. package/dist/cjs/build/api.d.ts +0 -9
  9. package/dist/cjs/build/api.d.ts.map +0 -1
  10. package/dist/cjs/build/api.js +0 -407
  11. package/dist/cjs/build/auto-import.d.ts +0 -10
  12. package/dist/cjs/build/auto-import.d.ts.map +0 -1
  13. package/dist/cjs/build/auto-import.js +0 -144
  14. package/dist/cjs/build/directory-named-import.d.ts +0 -2
  15. package/dist/cjs/build/directory-named-import.d.ts.map +0 -1
  16. package/dist/cjs/build/directory-named-import.js +0 -60
  17. package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts +0 -6
  18. package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts.map +0 -1
  19. package/dist/cjs/build/esbuild-plugin-api-graphql.js +0 -107
  20. package/dist/cjs/build/esbuild-plugin-cedar-otel-wrapping.d.ts +0 -13
  21. package/dist/cjs/build/esbuild-plugin-cedar-otel-wrapping.d.ts.map +0 -1
  22. package/dist/cjs/build/esbuild-plugin-cedar-otel-wrapping.js +0 -214
  23. package/dist/cjs/build/esbuild-plugin-handler-als-wrapping.d.ts +0 -4
  24. package/dist/cjs/build/esbuild-plugin-handler-als-wrapping.d.ts.map +0 -1
  25. package/dist/cjs/build/esbuild-plugin-handler-als-wrapping.js +0 -59
  26. package/dist/cjs/build/esm-extensions.d.ts +0 -33
  27. package/dist/cjs/build/esm-extensions.d.ts.map +0 -1
  28. package/dist/cjs/build/esm-extensions.js +0 -71
  29. package/dist/cjs/build/import-dir.d.ts +0 -22
  30. package/dist/cjs/build/import-dir.d.ts.map +0 -1
  31. package/dist/cjs/build/import-dir.js +0 -88
  32. package/dist/cjs/build/job-path-injector.d.ts +0 -15
  33. package/dist/cjs/build/job-path-injector.d.ts.map +0 -1
  34. package/dist/cjs/build/job-path-injector.js +0 -103
  35. package/dist/cjs/build/src-alias.d.ts +0 -14
  36. package/dist/cjs/build/src-alias.d.ts.map +0 -1
  37. package/dist/cjs/build/src-alias.js +0 -51
  38. package/dist/cjs/build/tsconfig-paths.d.ts +0 -2
  39. package/dist/cjs/build/tsconfig-paths.d.ts.map +0 -1
  40. package/dist/cjs/build/tsconfig-paths.js +0 -106
  41. package/dist/cjs/cliLogger.d.ts +0 -11
  42. package/dist/cjs/cliLogger.d.ts.map +0 -1
  43. package/dist/cjs/cliLogger.js +0 -36
  44. package/dist/cjs/dev.d.ts +0 -2
  45. package/dist/cjs/dev.d.ts.map +0 -1
  46. package/dist/cjs/dev.js +0 -41
  47. package/dist/cjs/files.d.ts +0 -56
  48. package/dist/cjs/files.d.ts.map +0 -1
  49. package/dist/cjs/files.js +0 -230
  50. package/dist/cjs/generate/clientPreset.d.ts +0 -17
  51. package/dist/cjs/generate/clientPreset.d.ts.map +0 -1
  52. package/dist/cjs/generate/clientPreset.js +0 -101
  53. package/dist/cjs/generate/generate.d.ts +0 -10
  54. package/dist/cjs/generate/generate.d.ts.map +0 -1
  55. package/dist/cjs/generate/generate.js +0 -97
  56. package/dist/cjs/generate/gqlormSchema.d.ts +0 -113
  57. package/dist/cjs/generate/gqlormSchema.d.ts.map +0 -1
  58. package/dist/cjs/generate/gqlormSchema.js +0 -1061
  59. package/dist/cjs/generate/graphqlCodeGen.d.ts +0 -16
  60. package/dist/cjs/generate/graphqlCodeGen.d.ts.map +0 -1
  61. package/dist/cjs/generate/graphqlCodeGen.js +0 -380
  62. package/dist/cjs/generate/graphqlSchema.d.ts +0 -8
  63. package/dist/cjs/generate/graphqlSchema.d.ts.map +0 -1
  64. package/dist/cjs/generate/graphqlSchema.js +0 -157
  65. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts +0 -7
  66. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts.map +0 -1
  67. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.js +0 -65
  68. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts +0 -10
  69. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +0 -1
  70. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.js +0 -92
  71. package/dist/cjs/generate/possibleTypes.d.ts +0 -36
  72. package/dist/cjs/generate/possibleTypes.d.ts.map +0 -1
  73. package/dist/cjs/generate/possibleTypes.js +0 -106
  74. package/dist/cjs/generate/templates/all-currentUser.d.ts.template +0 -30
  75. package/dist/cjs/generate/templates/all-gqlorm.d.ts.template +0 -7
  76. package/dist/cjs/generate/templates/api-globImports.d.ts.template +0 -9
  77. package/dist/cjs/generate/templates/api-globalContext.d.ts.template +0 -7
  78. package/dist/cjs/generate/templates/api-scenarios.d.ts.template +0 -10
  79. package/dist/cjs/generate/templates/api-test-globals.d.ts.template +0 -5
  80. package/dist/cjs/generate/templates/mirror-cell-fragment.d.ts.template +0 -18
  81. package/dist/cjs/generate/templates/mirror-cell.d.ts.template +0 -13
  82. package/dist/cjs/generate/templates/mirror-directoryNamedModule.d.ts.template +0 -5
  83. package/dist/cjs/generate/templates/web-routerRoutes.d.ts.template +0 -20
  84. package/dist/cjs/generate/templates/web-routesPages.d.ts.template +0 -13
  85. package/dist/cjs/generate/templates/web-test-globals.d.ts.template +0 -7
  86. package/dist/cjs/generate/templates.d.ts +0 -6
  87. package/dist/cjs/generate/templates.d.ts.map +0 -1
  88. package/dist/cjs/generate/templates.js +0 -68
  89. package/dist/cjs/generate/trustedDocuments.d.ts +0 -3
  90. package/dist/cjs/generate/trustedDocuments.d.ts.map +0 -1
  91. package/dist/cjs/generate/trustedDocuments.js +0 -95
  92. package/dist/cjs/generate/typeDefinitions.d.ts +0 -31
  93. package/dist/cjs/generate/typeDefinitions.d.ts.map +0 -1
  94. package/dist/cjs/generate/typeDefinitions.js +0 -381
  95. package/dist/cjs/generate/types.d.ts +0 -6
  96. package/dist/cjs/generate/types.d.ts.map +0 -1
  97. package/dist/cjs/generate/types.js +0 -16
  98. package/dist/cjs/generate/watch.d.ts +0 -3
  99. package/dist/cjs/generate/watch.d.ts.map +0 -1
  100. package/dist/cjs/generate/watch.js +0 -132
  101. package/dist/cjs/gql.d.ts +0 -34
  102. package/dist/cjs/gql.d.ts.map +0 -1
  103. package/dist/cjs/gql.js +0 -134
  104. package/dist/cjs/index.d.ts +0 -11
  105. package/dist/cjs/index.d.ts.map +0 -1
  106. package/dist/cjs/index.js +0 -49
  107. package/dist/cjs/jsx.d.ts +0 -16
  108. package/dist/cjs/jsx.d.ts.map +0 -1
  109. package/dist/cjs/jsx.js +0 -101
  110. package/dist/cjs/jsxAttributeValue.d.ts +0 -2
  111. package/dist/cjs/jsxAttributeValue.d.ts.map +0 -1
  112. package/dist/cjs/jsxAttributeValue.js +0 -129
  113. package/dist/cjs/package.json +0 -1
  114. package/dist/cjs/project.d.ts +0 -8
  115. package/dist/cjs/project.d.ts.map +0 -1
  116. package/dist/cjs/project.js +0 -82
  117. package/dist/cjs/routes.d.ts +0 -42
  118. package/dist/cjs/routes.d.ts.map +0 -1
  119. package/dist/cjs/routes.js +0 -111
  120. package/dist/cjs/ts2js.d.ts +0 -40
  121. package/dist/cjs/ts2js.d.ts.map +0 -1
  122. package/dist/cjs/ts2js.js +0 -159
  123. package/dist/cjs/validateSchema.d.ts +0 -14
  124. package/dist/cjs/validateSchema.d.ts.map +0 -1
  125. package/dist/cjs/validateSchema.js +0 -195
@@ -1,407 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var api_exports = {};
30
- __export(api_exports, {
31
- applyEsmExtensions: () => import_esm_extensions2.applyEsmExtensions,
32
- applySrcAlias: () => import_src_alias2.applySrcAlias,
33
- buildApi: () => buildApi,
34
- buildApiWithVite: () => buildApiWithVite,
35
- cleanApiBuild: () => cleanApiBuild,
36
- fixSourceMaps: () => fixSourceMaps,
37
- rebuildApi: () => rebuildApi
38
- });
39
- module.exports = __toCommonJS(api_exports);
40
- var import_node_fs = __toESM(require("node:fs"), 1);
41
- var import_node_path = __toESM(require("node:path"), 1);
42
- var import_esbuild = require("esbuild");
43
- var import_magic_string = __toESM(require("magic-string"), 1);
44
- var import_vite = require("vite");
45
- var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
46
- var import_babel_config = require("@cedarjs/babel-config");
47
- var import_project_config = require("@cedarjs/project-config");
48
- var import_files = require("../files.js");
49
- var import_api_graphql_transforms = require("./api-graphql-transforms.js");
50
- var import_auto_import = require("./auto-import.js");
51
- var import_directory_named_import = require("./directory-named-import.js");
52
- var import_esbuild_plugin_api_graphql = require("./esbuild-plugin-api-graphql.js");
53
- var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-otel-wrapping.js");
54
- var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
55
- var import_esm_extensions = require("./esm-extensions.js");
56
- var import_import_dir = require("./import-dir.js");
57
- var import_job_path_injector = require("./job-path-injector.js");
58
- var import_src_alias = require("./src-alias.js");
59
- var import_tsconfig_paths = require("./tsconfig-paths.js");
60
- var import_src_alias2 = require("./src-alias.js");
61
- var import_esm_extensions2 = require("./esm-extensions.js");
62
- const tsconfigPaths = (
63
- // @ts-expect-error – .default only exists at runtime in CJS double-wrap
64
- // interop
65
- import_vite_tsconfig_paths.default.default?.default || import_vite_tsconfig_paths.default.default || import_vite_tsconfig_paths.default
66
- );
67
- let BUILD_CTX = null;
68
- const buildApi = async () => {
69
- BUILD_CTX?.dispose();
70
- BUILD_CTX = null;
71
- return transpileApi((0, import_files.findApiFiles)());
72
- };
73
- const rebuildApi = async () => {
74
- const apiFiles = (0, import_files.findApiFiles)();
75
- if (!BUILD_CTX) {
76
- BUILD_CTX = await (0, import_esbuild.context)(getEsbuildOptions(apiFiles));
77
- }
78
- const result = await BUILD_CTX.rebuild();
79
- const cedarPaths = (0, import_project_config.getPaths)();
80
- await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
81
- return result;
82
- };
83
- const cleanApiBuild = async () => {
84
- const cedarPaths = (0, import_project_config.getPaths)();
85
- return import_node_fs.default.promises.rm(cedarPaths.api.dist, { recursive: true, force: true });
86
- };
87
- const runCedarBabelTransformsPlugin = {
88
- name: "cedar-esbuild-babel-transform",
89
- setup(build2) {
90
- build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
91
- let fileContents = await import_node_fs.default.promises.readFile(args.path, "utf-8");
92
- fileContents = (0, import_src_alias.applySrcAlias)(
93
- fileContents,
94
- import_node_path.default.dirname(
95
- import_node_path.default.relative(build2.initialOptions.absWorkingDir + "/src", args.path)
96
- )
97
- );
98
- fileContents = (0, import_tsconfig_paths.applyTsconfigPaths)(
99
- fileContents,
100
- args.path,
101
- (0, import_project_config.getPaths)().api.base
102
- );
103
- fileContents = (0, import_directory_named_import.applyDirectoryNamedImport)(fileContents, args.path);
104
- fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
105
- fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
106
- fileContents = (0, import_job_path_injector.applyJobPathInjector)(fileContents, args.path, (0, import_project_config.getPaths)().api.jobs) ?? fileContents;
107
- const normalizedPath = (0, import_vite.normalizePath)(args.path);
108
- const cedarPaths = (0, import_project_config.getPaths)();
109
- const isEsm = (0, import_project_config.projectSideIsEsm)("api");
110
- const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
111
- let code = fileContents;
112
- if (apiBabelConfigPath) {
113
- const transformedCode = await (0, import_babel_config.transformWithBabel)(
114
- fileContents,
115
- args.path,
116
- (0, import_babel_config.getApiSideBabelPluginsForVite)(),
117
- "inline",
118
- true
119
- );
120
- if (!transformedCode?.code) {
121
- throw new Error(`Could not transform file: ${args.path}`);
122
- }
123
- code = transformedCode.code;
124
- }
125
- if (isEsm) {
126
- code = (0, import_esm_extensions.applyEsmExtensions)(code, args.path);
127
- }
128
- const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
129
- if (normalizedPath.startsWith(functionsDir + "/")) {
130
- code = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(code, {
131
- projectIsEsm: isEsm
132
- }) ?? code;
133
- }
134
- if (normalizedPath.startsWith((0, import_vite.normalizePath)(cedarPaths.api.src) + "/")) {
135
- code = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(code, args.path, cedarPaths.api.src) ?? code;
136
- }
137
- return {
138
- contents: code,
139
- // Babel output is always plain JS. Without Babel the contents are
140
- // still TypeScript/JSX, so pick the loader matching the file's
141
- // extension and let esbuild do the stripping.
142
- loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
143
- };
144
- });
145
- }
146
- };
147
- function getEsbuildLoader(filePath) {
148
- switch (import_node_path.default.extname(filePath)) {
149
- case ".ts":
150
- return "ts";
151
- case ".tsx":
152
- return "tsx";
153
- case ".jsx":
154
- return "jsx";
155
- default:
156
- return "js";
157
- }
158
- }
159
- function createImportDirVitePlugin() {
160
- return {
161
- name: "cedar-internal-import-dir",
162
- enforce: "pre",
163
- transform(code, id) {
164
- if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
165
- return null;
166
- }
167
- if (id.includes("node_modules")) {
168
- return null;
169
- }
170
- const result = (0, import_import_dir.applyImportDir)(code, id);
171
- if (!result) {
172
- return null;
173
- }
174
- return { code: result.code, map: result.map };
175
- }
176
- };
177
- }
178
- function createDirectoryNamedImportVitePlugin() {
179
- return {
180
- name: "cedar-internal-directory-named-import",
181
- enforce: "pre",
182
- resolveId(id, importer) {
183
- if (!id.startsWith(".") || !importer) {
184
- return null;
185
- }
186
- if (importer.includes("node_modules")) {
187
- return null;
188
- }
189
- const absolutePath = import_node_path.default.resolve(import_node_path.default.dirname(importer), id);
190
- if ((0, import_project_config.resolveFile)(absolutePath)) {
191
- return null;
192
- }
193
- const indexPath = import_node_path.default.join(absolutePath, "index");
194
- const resolvedIndex = (0, import_project_config.resolveFile)(indexPath);
195
- if (resolvedIndex) {
196
- return (0, import_vite.normalizePath)(resolvedIndex);
197
- }
198
- const basename = import_node_path.default.basename(absolutePath);
199
- const dirNamedPath = import_node_path.default.join(absolutePath, basename);
200
- const resolvedDirNamed = (0, import_project_config.resolveFile)(dirNamedPath);
201
- if (resolvedDirNamed) {
202
- return (0, import_vite.normalizePath)(resolvedDirNamed);
203
- }
204
- return null;
205
- }
206
- };
207
- }
208
- function createCedarViteApiPlugin() {
209
- const cedarConfig = (0, import_project_config.getConfig)();
210
- const isEsm = (0, import_project_config.projectSideIsEsm)("api");
211
- return {
212
- name: "cedar-vite-api-babel-transform",
213
- enforce: "pre",
214
- async transform(code, id) {
215
- if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
216
- return null;
217
- }
218
- if (id.includes("node_modules")) {
219
- return null;
220
- }
221
- const cedarPaths = (0, import_project_config.getPaths)();
222
- if (!(0, import_vite.normalizePath)(id).startsWith((0, import_vite.normalizePath)(cedarPaths.api.base))) {
223
- return null;
224
- }
225
- let sourceCode = code;
226
- const normalizedId = (0, import_vite.normalizePath)(id);
227
- sourceCode = (0, import_src_alias.applySrcAlias)(
228
- sourceCode,
229
- import_node_path.default.dirname(import_node_path.default.relative(cedarPaths.api.src, id))
230
- );
231
- sourceCode = (0, import_auto_import.applyAutoImports)(sourceCode);
232
- sourceCode = (0, import_job_path_injector.applyJobPathInjector)(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
233
- if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
234
- sourceCode = (0, import_api_graphql_transforms.applyGraphqlOptionsExtract)(sourceCode) ?? sourceCode;
235
- sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
236
- }
237
- const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
238
- const transformedCode = apiBabelConfigPath ? await (0, import_babel_config.transformWithBabel)(
239
- sourceCode,
240
- id,
241
- (0, import_babel_config.getApiSideBabelPluginsForVite)(),
242
- true,
243
- true
244
- ) : null;
245
- if (apiBabelConfigPath && !transformedCode?.code) {
246
- throw new Error(`Could not transform file: ${id}`);
247
- }
248
- let outputCode = transformedCode?.code ?? sourceCode;
249
- if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
250
- outputCode = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(outputCode, id, cedarPaths.api.src) ?? outputCode;
251
- }
252
- if (isEsm) {
253
- outputCode = (0, import_esm_extensions.applyEsmExtensions)(outputCode, id);
254
- }
255
- const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
256
- if (normalizedId.startsWith(functionsDir + "/")) {
257
- outputCode = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(outputCode, {
258
- projectIsEsm: isEsm
259
- }) ?? outputCode;
260
- }
261
- if (!transformedCode) {
262
- if (outputCode === code) {
263
- return null;
264
- }
265
- return {
266
- code: outputCode,
267
- map: new import_magic_string.default(code).generateMap({ hires: true })
268
- };
269
- }
270
- return {
271
- code: outputCode,
272
- map: transformedCode.map ?? null
273
- };
274
- }
275
- };
276
- }
277
- const buildApiWithVite = async () => {
278
- const cedarPaths = (0, import_project_config.getPaths)();
279
- const isEsm = (0, import_project_config.projectSideIsEsm)("api");
280
- const format = isEsm ? "es" : "cjs";
281
- const apiFiles = (0, import_files.findApiFiles)();
282
- const input = {};
283
- for (const f of apiFiles) {
284
- const key = import_node_path.default.relative(cedarPaths.api.src, f).replace(/\.(ts|tsx|mts|js|jsx|mjs)$/, "");
285
- input[key] = f;
286
- }
287
- return (0, import_vite.build)({
288
- root: cedarPaths.api.base,
289
- logLevel: "warn",
290
- build: {
291
- ssr: true,
292
- sourcemap: true,
293
- outDir: cedarPaths.api.dist,
294
- rollupOptions: {
295
- input,
296
- output: {
297
- format,
298
- preserveModules: true,
299
- preserveModulesRoot: cedarPaths.api.src,
300
- entryFileNames: "[name].js",
301
- // Directives (and other entry modules) intentionally use both named
302
- // and default exports (e.g. `export const schema` + `export default`).
303
- // Tell Rollup to expect this so it doesn't warn about mixed exports.
304
- exports: "named"
305
- },
306
- external: (id) => {
307
- if (id.startsWith("node:")) {
308
- return true;
309
- }
310
- if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
311
- return true;
312
- }
313
- return false;
314
- }
315
- }
316
- },
317
- // cedarImportDirPlugin must run before the Babel transform so glob imports
318
- // are expanded before Babel sees the code. The Babel import-dir plugin is
319
- // not part of getApiSideBabelPluginsForVite(); this inline Vite plugin is
320
- // its replacement for this code path (both CJS and ESM output via Rollup).
321
- // tsconfigPaths resolves user-defined tsconfig.json `paths` aliases; it
322
- // replaces the Babel module-resolver's tsconfig-paths handling for this
323
- // code path.
324
- plugins: [
325
- tsconfigPaths(),
326
- createImportDirVitePlugin(),
327
- createDirectoryNamedImportVitePlugin(),
328
- createCedarViteApiPlugin()
329
- ]
330
- });
331
- };
332
- const transpileApi = async (files) => {
333
- const result = await (0, import_esbuild.build)(getEsbuildOptions(files));
334
- const cedarPaths = (0, import_project_config.getPaths)();
335
- await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
336
- return result;
337
- };
338
- async function fixSourceMaps(distDir, srcDir) {
339
- let entries;
340
- try {
341
- entries = await import_node_fs.default.promises.readdir(distDir, {
342
- recursive: true,
343
- withFileTypes: true
344
- });
345
- } catch {
346
- return;
347
- }
348
- const mapFiles = entries.filter((e) => e.isFile() && e.name.endsWith(".js.map")).map((e) => import_node_path.default.join(e.parentPath ?? e.path, e.name));
349
- await Promise.all(
350
- mapFiles.map(async (mapFile) => {
351
- try {
352
- const raw = await import_node_fs.default.promises.readFile(mapFile, "utf8");
353
- const map = JSON.parse(raw);
354
- if (!Array.isArray(map.sources) || map.sources.length === 0) {
355
- return;
356
- }
357
- const jsFile = mapFile.slice(0, -4);
358
- const baseName = import_node_path.default.relative(distDir, jsFile).replace(/\.js$/, "");
359
- const srcFile = [".ts", ".tsx", ".jsx", ".js"].map((ext) => import_node_path.default.join(srcDir, baseName + ext)).find((f) => import_node_fs.default.existsSync(f));
360
- if (!srcFile) {
361
- return;
362
- }
363
- const correctRelPath = (0, import_vite.normalizePath)(
364
- import_node_path.default.relative(import_node_path.default.dirname(mapFile), srcFile)
365
- );
366
- if (map.sources[0] === correctRelPath) {
367
- return;
368
- }
369
- map.sources = [correctRelPath];
370
- await import_node_fs.default.promises.writeFile(mapFile, JSON.stringify(map), "utf8");
371
- } catch {
372
- }
373
- })
374
- );
375
- }
376
- function getEsbuildOptions(files) {
377
- const cedarPaths = (0, import_project_config.getPaths)();
378
- const format = (0, import_project_config.projectSideIsEsm)("api") ? "esm" : "cjs";
379
- return {
380
- absWorkingDir: cedarPaths.api.base,
381
- entryPoints: files,
382
- platform: "node",
383
- target: "node24",
384
- format,
385
- allowOverwrite: true,
386
- bundle: false,
387
- // Registration order matters: cedarApiGraphqlPlugin (narrow filter) must
388
- // come first so it claims graphql.ts before runCedarBabelTransformsPlugin
389
- // (broad filter) can. See the NOTE on cedarApiGraphqlPlugin.
390
- plugins: [import_esbuild_plugin_api_graphql.cedarApiGraphqlPlugin, runCedarBabelTransformsPlugin],
391
- outdir: cedarPaths.api.dist,
392
- // setting this to 'true' will generate an external sourcemap x.js.map
393
- // AND set the sourceMappingURL comment
394
- // (setting it to 'external' will ONLY generate the file, but won't add the comment)
395
- sourcemap: true
396
- };
397
- }
398
- // Annotate the CommonJS export names for ESM import in node:
399
- 0 && (module.exports = {
400
- applyEsmExtensions,
401
- applySrcAlias,
402
- buildApi,
403
- buildApiWithVite,
404
- cleanApiBuild,
405
- fixSourceMaps,
406
- rebuildApi
407
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * Injects imports for `gql` and `context` into API source files that reference
3
- * them without importing them. Uses an oxc-parser AST walk to check bindings,
4
- * so local declarations never receive a conflicting import.
5
- *
6
- * This replaces `babel-plugin-auto-import` for the esbuild API build path,
7
- * matching the behavior of `cedarAutoImportsPlugin` in Vite builds.
8
- */
9
- export declare function applyAutoImports(code: string): string;
10
- //# sourceMappingURL=auto-import.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto-import.d.ts","sourceRoot":"","sources":["../../../src/build/auto-import.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoBrD"}
@@ -1,144 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var auto_import_exports = {};
20
- __export(auto_import_exports, {
21
- applyAutoImports: () => applyAutoImports
22
- });
23
- module.exports = __toCommonJS(auto_import_exports);
24
- var import_oxc_parser = require("oxc-parser");
25
- function applyAutoImports(code) {
26
- const result = (0, import_oxc_parser.parseSync)("temp.ts", code, {
27
- lang: "ts",
28
- sourceType: "module"
29
- });
30
- const needsGql = checkNeeds("gql", result.program, code);
31
- const needsContext = checkNeeds("context", result.program, code);
32
- let resultCode = code;
33
- if (needsGql) {
34
- resultCode = "import gql from 'graphql-tag'\n" + resultCode;
35
- }
36
- if (needsContext) {
37
- resultCode = "import { context } from '@cedarjs/context'\n" + resultCode;
38
- }
39
- return resultCode;
40
- }
41
- function bindingInDeclarators(name, declarations) {
42
- for (const decl of declarations) {
43
- if (bindingPatternContains(decl.id, name)) {
44
- return true;
45
- }
46
- }
47
- return false;
48
- }
49
- function bindingPatternContains(pattern, name) {
50
- if (pattern.type === "Identifier") {
51
- return pattern.name === name;
52
- }
53
- if (pattern.type === "ObjectPattern") {
54
- for (const prop of pattern.properties) {
55
- if (prop.type === "RestElement") {
56
- if (bindingPatternContains(prop.argument, name)) {
57
- return true;
58
- }
59
- } else {
60
- if (bindingPatternContains(prop.value, name)) {
61
- return true;
62
- }
63
- }
64
- }
65
- return false;
66
- }
67
- if (pattern.type === "ArrayPattern") {
68
- for (const el of pattern.elements) {
69
- if (el) {
70
- if (el.type === "RestElement") {
71
- if (bindingPatternContains(el.argument, name)) {
72
- return true;
73
- }
74
- } else if (bindingPatternContains(el, name)) {
75
- return true;
76
- }
77
- }
78
- }
79
- return false;
80
- }
81
- if (pattern.type === "AssignmentPattern") {
82
- return bindingPatternContains(pattern.left, name);
83
- }
84
- return false;
85
- }
86
- function checkNeeds(name, program, code) {
87
- if (!code.includes(name)) {
88
- return false;
89
- }
90
- let isBound = false;
91
- let hasUsage = false;
92
- for (const node of program.body) {
93
- if (node.type === "ImportDeclaration") {
94
- for (const specifier of node.specifiers) {
95
- if (specifier.type === "ImportSpecifier") {
96
- if (specifier.imported.type === "Identifier" && specifier.imported.name === name || specifier.local.name === name) {
97
- isBound = true;
98
- break;
99
- }
100
- } else if (specifier.type === "ImportDefaultSpecifier") {
101
- if (specifier.local.name === name) {
102
- isBound = true;
103
- break;
104
- }
105
- } else if (specifier.type === "ImportNamespaceSpecifier") {
106
- if (specifier.local.name === name) {
107
- isBound = true;
108
- break;
109
- }
110
- }
111
- }
112
- }
113
- if (node.type === "VariableDeclaration") {
114
- if (bindingInDeclarators(name, node.declarations)) {
115
- isBound = true;
116
- }
117
- }
118
- if (node.type === "FunctionDeclaration" && node.id?.name === name) {
119
- isBound = true;
120
- }
121
- if (node.type === "ExportNamedDeclaration" && node.declaration) {
122
- if (node.declaration.type === "VariableDeclaration") {
123
- if (bindingInDeclarators(name, node.declaration.declarations)) {
124
- isBound = true;
125
- }
126
- }
127
- }
128
- }
129
- if (isBound) {
130
- return false;
131
- }
132
- new import_oxc_parser.Visitor({
133
- Identifier(node) {
134
- if (node.name === name) {
135
- hasUsage = true;
136
- }
137
- }
138
- }).visit(program);
139
- return hasUsage;
140
- }
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- applyAutoImports
144
- });
@@ -1,2 +0,0 @@
1
- export declare function applyDirectoryNamedImport(code: string, filePath: string): string;
2
- //# sourceMappingURL=directory-named-import.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directory-named-import.d.ts","sourceRoot":"","sources":["../../../src/build/directory-named-import.ts"],"names":[],"mappings":"AAiCA,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,MAAM,CAyBR"}
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var directory_named_import_exports = {};
30
- __export(directory_named_import_exports, {
31
- applyDirectoryNamedImport: () => applyDirectoryNamedImport
32
- });
33
- module.exports = __toCommonJS(directory_named_import_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var import_project_config = require("@cedarjs/project-config");
36
- const RELATIVE_IMPORT_RE = /^(\s*(?:import|export)\s[^'"]*?)(['"])(\.\.?\/[^'"]+)\2/gm;
37
- function applyDirectoryNamedImport(code, filePath) {
38
- const fileDir = import_node_path.default.dirname(filePath);
39
- return code.replace(
40
- RELATIVE_IMPORT_RE,
41
- (match, prefix, quote, importPath) => {
42
- const absolutePath = import_node_path.default.join(fileDir, importPath);
43
- if ((0, import_project_config.resolveFile)(absolutePath)) {
44
- return match;
45
- }
46
- if ((0, import_project_config.resolveFile)(import_node_path.default.join(absolutePath, "index"))) {
47
- return `${prefix}${quote}${(0, import_project_config.importStatementPath)(importPath + "/index")}${quote}`;
48
- }
49
- const basename = import_node_path.default.basename(absolutePath);
50
- if ((0, import_project_config.resolveFile)(import_node_path.default.join(absolutePath, basename))) {
51
- return `${prefix}${quote}${(0, import_project_config.importStatementPath)(importPath + "/" + basename)}${quote}`;
52
- }
53
- return match;
54
- }
55
- );
56
- }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- applyDirectoryNamedImport
60
- });
@@ -1,6 +0,0 @@
1
- import type { PluginBuild } from 'esbuild';
2
- export declare const cedarApiGraphqlPlugin: {
3
- name: string;
4
- setup(build: PluginBuild): void;
5
- };
6
- //# sourceMappingURL=esbuild-plugin-api-graphql.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CAiHzB,CAAA"}