@cedarjs/internal 0.6.1-next.0 → 0.6.1-next.51

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 (127) hide show
  1. package/dist/ast.d.ts.map +1 -1
  2. package/dist/ast.js +28 -64
  3. package/dist/build/api.js +22 -56
  4. package/dist/cjs/ast.d.ts +26 -0
  5. package/dist/cjs/ast.d.ts.map +1 -0
  6. package/dist/cjs/ast.js +201 -0
  7. package/dist/cjs/build/api.d.ts +6 -0
  8. package/dist/cjs/build/api.d.ts.map +1 -0
  9. package/dist/cjs/build/api.js +109 -0
  10. package/dist/cjs/cliLogger.d.ts +11 -0
  11. package/dist/cjs/cliLogger.d.ts.map +1 -0
  12. package/dist/cjs/cliLogger.js +36 -0
  13. package/dist/cjs/dev.d.ts +2 -0
  14. package/dist/cjs/dev.d.ts.map +1 -0
  15. package/dist/cjs/dev.js +41 -0
  16. package/dist/cjs/files.d.ts +56 -0
  17. package/dist/cjs/files.d.ts.map +1 -0
  18. package/dist/cjs/files.js +230 -0
  19. package/dist/cjs/generate/clientPreset.d.ts +17 -0
  20. package/dist/cjs/generate/clientPreset.d.ts.map +1 -0
  21. package/dist/cjs/generate/clientPreset.js +85 -0
  22. package/dist/cjs/generate/generate.d.ts +10 -0
  23. package/dist/cjs/generate/generate.d.ts.map +1 -0
  24. package/dist/cjs/generate/generate.js +91 -0
  25. package/dist/cjs/generate/graphqlCodeGen.d.ts +16 -0
  26. package/dist/cjs/generate/graphqlCodeGen.d.ts.map +1 -0
  27. package/dist/cjs/generate/graphqlCodeGen.js +346 -0
  28. package/dist/cjs/generate/graphqlSchema.d.ts +8 -0
  29. package/dist/cjs/generate/graphqlSchema.d.ts.map +1 -0
  30. package/dist/cjs/generate/graphqlSchema.js +154 -0
  31. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts +7 -0
  32. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts.map +1 -0
  33. package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.js +65 -0
  34. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts +9 -0
  35. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +1 -0
  36. package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.js +84 -0
  37. package/dist/cjs/generate/possibleTypes.d.ts +36 -0
  38. package/dist/cjs/generate/possibleTypes.d.ts.map +1 -0
  39. package/dist/cjs/generate/possibleTypes.js +106 -0
  40. package/dist/cjs/generate/templates/all-currentUser.d.ts.template +30 -0
  41. package/dist/cjs/generate/templates/api-globImports.d.ts.template +9 -0
  42. package/dist/cjs/generate/templates/api-globalContext.d.ts.template +7 -0
  43. package/dist/cjs/generate/templates/api-scenarios.d.ts.template +10 -0
  44. package/dist/cjs/generate/templates/api-test-globals.d.ts.template +5 -0
  45. package/dist/cjs/generate/templates/mirror-cell.d.ts.template +13 -0
  46. package/dist/cjs/generate/templates/mirror-directoryNamedModule.d.ts.template +5 -0
  47. package/dist/cjs/generate/templates/web-routerRoutes.d.ts.template +20 -0
  48. package/dist/cjs/generate/templates/web-routesPages.d.ts.template +13 -0
  49. package/dist/cjs/generate/templates/web-test-globals.d.ts.template +7 -0
  50. package/dist/cjs/generate/templates.d.ts +6 -0
  51. package/dist/cjs/generate/templates.d.ts.map +1 -0
  52. package/dist/cjs/generate/templates.js +68 -0
  53. package/dist/cjs/generate/trustedDocuments.d.ts +3 -0
  54. package/dist/cjs/generate/trustedDocuments.d.ts.map +1 -0
  55. package/dist/cjs/generate/trustedDocuments.js +95 -0
  56. package/dist/cjs/generate/typeDefinitions.d.ts +30 -0
  57. package/dist/cjs/generate/typeDefinitions.d.ts.map +1 -0
  58. package/dist/cjs/generate/typeDefinitions.js +369 -0
  59. package/dist/cjs/generate/types.d.ts +6 -0
  60. package/dist/cjs/generate/types.d.ts.map +1 -0
  61. package/dist/cjs/generate/types.js +16 -0
  62. package/dist/cjs/generate/watch.d.ts +3 -0
  63. package/dist/cjs/generate/watch.d.ts.map +1 -0
  64. package/dist/cjs/generate/watch.js +124 -0
  65. package/dist/cjs/gql.d.ts +14 -0
  66. package/dist/cjs/gql.d.ts.map +1 -0
  67. package/dist/cjs/gql.js +108 -0
  68. package/dist/cjs/index.d.ts +11 -0
  69. package/dist/cjs/index.d.ts.map +1 -0
  70. package/dist/cjs/index.js +49 -0
  71. package/dist/cjs/jsx.d.ts +16 -0
  72. package/dist/cjs/jsx.d.ts.map +1 -0
  73. package/dist/cjs/jsx.js +101 -0
  74. package/dist/cjs/jsxAttributeValue.d.ts +2 -0
  75. package/dist/cjs/jsxAttributeValue.d.ts.map +1 -0
  76. package/dist/cjs/jsxAttributeValue.js +129 -0
  77. package/dist/cjs/package.json +1 -0
  78. package/dist/cjs/project.d.ts +8 -0
  79. package/dist/cjs/project.d.ts.map +1 -0
  80. package/dist/cjs/project.js +82 -0
  81. package/dist/cjs/routes.d.ts +42 -0
  82. package/dist/cjs/routes.d.ts.map +1 -0
  83. package/dist/cjs/routes.js +111 -0
  84. package/dist/cjs/ts2js.d.ts +40 -0
  85. package/dist/cjs/ts2js.d.ts.map +1 -0
  86. package/dist/cjs/ts2js.js +159 -0
  87. package/dist/cjs/validateSchema.d.ts +14 -0
  88. package/dist/cjs/validateSchema.d.ts.map +1 -0
  89. package/dist/cjs/validateSchema.js +194 -0
  90. package/dist/cliLogger.js +4 -28
  91. package/dist/dev.js +4 -38
  92. package/dist/files.d.ts.map +1 -1
  93. package/dist/files.js +46 -95
  94. package/dist/generate/clientPreset.js +17 -39
  95. package/dist/generate/generate.js +14 -39
  96. package/dist/generate/graphqlCodeGen.d.ts.map +1 -1
  97. package/dist/generate/graphqlCodeGen.js +49 -79
  98. package/dist/generate/graphqlSchema.d.ts.map +1 -1
  99. package/dist/generate/graphqlSchema.js +26 -59
  100. package/dist/generate/plugins/rw-typescript-resolvers/index.d.ts +4 -3
  101. package/dist/generate/plugins/rw-typescript-resolvers/index.d.ts.map +1 -1
  102. package/dist/generate/plugins/rw-typescript-resolvers/index.js +11 -35
  103. package/dist/generate/plugins/rw-typescript-resolvers/visitor.js +10 -31
  104. package/dist/generate/possibleTypes.js +19 -53
  105. package/dist/generate/templates.d.ts.map +1 -1
  106. package/dist/generate/templates.js +14 -42
  107. package/dist/generate/trustedDocuments.js +13 -48
  108. package/dist/generate/typeDefinitions.d.ts +2 -2
  109. package/dist/generate/typeDefinitions.d.ts.map +1 -1
  110. package/dist/generate/typeDefinitions.js +83 -123
  111. package/dist/generate/types.js +0 -16
  112. package/dist/generate/watch.js +55 -63
  113. package/dist/gql.js +16 -42
  114. package/dist/index.d.ts +8 -8
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +13 -47
  117. package/dist/jsx.d.ts.map +1 -1
  118. package/dist/jsx.js +7 -40
  119. package/dist/jsxAttributeValue.js +2 -26
  120. package/dist/project.js +21 -58
  121. package/dist/routes.d.ts +1 -1
  122. package/dist/routes.d.ts.map +1 -1
  123. package/dist/routes.js +12 -48
  124. package/dist/ts2js.d.ts +1 -1
  125. package/dist/ts2js.js +33 -73
  126. package/dist/validateSchema.js +19 -47
  127. package/package.json +91 -31
package/dist/ast.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnC,eAAO,MAAM,SAAS,aAAc,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,QAAS,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,cA4B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAS,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,QAC9B,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,aAAc,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,QAAS,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAS,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,QAC9B,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
package/dist/ast.js CHANGED
@@ -1,52 +1,15 @@
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 ast_exports = {};
30
- __export(ast_exports, {
31
- fileToAst: () => fileToAst,
32
- getCellGqlQuery: () => getCellGqlQuery,
33
- getDefaultExportLocation: () => getDefaultExportLocation,
34
- getGqlQueries: () => getGqlQueries,
35
- getNamedExports: () => getNamedExports,
36
- hasDefaultExport: () => hasDefaultExport
37
- });
38
- module.exports = __toCommonJS(ast_exports);
39
- var import_fs = __toESM(require("fs"));
40
- var import_path = __toESM(require("path"));
41
- var import_core = require("@babel/core");
42
- var import_parser = require("@babel/parser");
43
- var import_traverse = __toESM(require("@babel/traverse"));
44
- var import_project_config = require("@cedarjs/project-config");
45
- var import_files = require("./files");
46
- const ansis = require("ansis");
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { types } from "@babel/core";
4
+ import { parse as babelParse } from "@babel/parser";
5
+ import babelTraverse from "@babel/traverse";
6
+ import ansis from "ansis";
7
+ import { getPaths } from "@cedarjs/project-config";
8
+ import { isFileInsideFolder } from "./files.js";
9
+ const traverse = babelTraverse.default || babelTraverse;
47
10
  const fileToAst = (filePath) => {
48
- const code = import_fs.default.readFileSync(filePath, "utf-8");
49
- const isJsxFile = import_path.default.extname(filePath).match(/[jt]sx$/) || (0, import_files.isFileInsideFolder)(filePath, (0, import_project_config.getPaths)().web.base);
11
+ const code = fs.readFileSync(filePath, "utf-8");
12
+ const isJsxFile = path.extname(filePath).match(/[jt]sx$/) || isFileInsideFolder(filePath, getPaths().web.base);
50
13
  const plugins = [
51
14
  "typescript",
52
15
  "nullishCoalescingOperator",
@@ -54,7 +17,7 @@ const fileToAst = (filePath) => {
54
17
  isJsxFile && "jsx"
55
18
  ].filter(Boolean);
56
19
  try {
57
- return (0, import_parser.parse)(code, {
20
+ return babelParse(code, {
58
21
  sourceType: "module",
59
22
  plugins
60
23
  });
@@ -66,7 +29,7 @@ const fileToAst = (filePath) => {
66
29
  };
67
30
  const getNamedExports = (ast) => {
68
31
  const namedExports = [];
69
- (0, import_traverse.default)(ast, {
32
+ traverse(ast, {
70
33
  ExportNamedDeclaration(path2) {
71
34
  const specifiers = path2.node?.specifiers;
72
35
  if (specifiers.length) {
@@ -122,7 +85,7 @@ const getNamedExports = (ast) => {
122
85
  };
123
86
  const getGqlQueries = (ast) => {
124
87
  const gqlQueries = [];
125
- (0, import_traverse.default)(ast, {
88
+ traverse(ast, {
126
89
  TaggedTemplateExpression(path2) {
127
90
  const gqlTag = path2.node.tag;
128
91
  if (gqlTag.type === "Identifier" && gqlTag.name === "gql") {
@@ -134,12 +97,14 @@ const getGqlQueries = (ast) => {
134
97
  };
135
98
  const getCellGqlQuery = (ast) => {
136
99
  let cellQuery = void 0;
137
- (0, import_traverse.default)(ast, {
100
+ traverse(ast, {
138
101
  ExportNamedDeclaration({ node }) {
139
- if (node.exportKind === "value" && import_core.types.isVariableDeclaration(node.declaration)) {
140
- const exportedQueryNode = node.declaration.declarations.find((d) => {
141
- return import_core.types.isIdentifier(d.id) && d.id.name === "QUERY" && import_core.types.isTaggedTemplateExpression(d.init);
142
- });
102
+ if (node.exportKind === "value" && types.isVariableDeclaration(node.declaration)) {
103
+ const exportedQueryNode = node.declaration.declarations.find(
104
+ (d) => {
105
+ return types.isIdentifier(d.id) && d.id.name === "QUERY" && types.isTaggedTemplateExpression(d.init);
106
+ }
107
+ );
143
108
  if (exportedQueryNode) {
144
109
  const templateExpression = exportedQueryNode.init;
145
110
  cellQuery = templateExpression.quasi.quasis[0].value.raw;
@@ -152,7 +117,7 @@ const getCellGqlQuery = (ast) => {
152
117
  };
153
118
  const hasDefaultExport = (ast) => {
154
119
  let exported = false;
155
- (0, import_traverse.default)(ast, {
120
+ traverse(ast, {
156
121
  ExportDefaultDeclaration() {
157
122
  exported = true;
158
123
  return;
@@ -162,7 +127,7 @@ const hasDefaultExport = (ast) => {
162
127
  };
163
128
  const getDefaultExportLocation = (ast) => {
164
129
  let defaultExport;
165
- (0, import_traverse.default)(ast, {
130
+ traverse(ast, {
166
131
  ExportDefaultDeclaration(path2) {
167
132
  defaultExport = path2.node;
168
133
  }
@@ -170,11 +135,11 @@ const getDefaultExportLocation = (ast) => {
170
135
  if (!defaultExport) {
171
136
  return null;
172
137
  }
173
- if (import_core.types.isIdentifier(defaultExport.declaration) && import_core.types.isFile(ast)) {
138
+ if (types.isIdentifier(defaultExport.declaration) && types.isFile(ast)) {
174
139
  const exportedName = defaultExport.declaration.name;
175
140
  const declaration = ast.program.body.find((node) => {
176
- return import_core.types.isVariableDeclaration(node) && node.declarations.find((d) => {
177
- return import_core.types.isVariableDeclarator(d) && import_core.types.isIdentifier(d.id) && d.id.name === exportedName;
141
+ return types.isVariableDeclaration(node) && node.declarations.find((d) => {
142
+ return types.isVariableDeclarator(d) && types.isIdentifier(d.id) && d.id.name === exportedName;
178
143
  });
179
144
  });
180
145
  return {
@@ -187,12 +152,11 @@ const getDefaultExportLocation = (ast) => {
187
152
  column: defaultExport.loc?.start.column ?? 0
188
153
  };
189
154
  };
190
- // Annotate the CommonJS export names for ESM import in node:
191
- 0 && (module.exports = {
155
+ export {
192
156
  fileToAst,
193
157
  getCellGqlQuery,
194
158
  getDefaultExportLocation,
195
159
  getGqlQueries,
196
160
  getNamedExports,
197
161
  hasDefaultExport
198
- });
162
+ };
package/dist/build/api.js CHANGED
@@ -1,71 +1,38 @@
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
- buildApi: () => buildApi,
32
- cleanApiBuild: () => cleanApiBuild,
33
- rebuildApi: () => rebuildApi,
34
- transpileApi: () => transpileApi
35
- });
36
- module.exports = __toCommonJS(api_exports);
37
- var import_esbuild = require("esbuild");
38
- var import_fs_extra = __toESM(require("fs-extra"));
39
- var import_babel_config = require("@cedarjs/babel-config");
40
- var import_project_config = require("@cedarjs/project-config");
41
- var import_files = require("../files");
1
+ import { build, context } from "esbuild";
2
+ import fs from "fs-extra";
3
+ import {
4
+ getApiSideBabelPlugins,
5
+ transformWithBabel
6
+ } from "@cedarjs/babel-config";
7
+ import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
8
+ import { findApiFiles } from "../files.js";
42
9
  let BUILD_CTX = null;
43
10
  const buildApi = async () => {
44
11
  BUILD_CTX?.dispose();
45
12
  BUILD_CTX = null;
46
- return transpileApi((0, import_files.findApiFiles)());
13
+ return transpileApi(findApiFiles());
47
14
  };
48
15
  const rebuildApi = async () => {
49
- const apiFiles = (0, import_files.findApiFiles)();
16
+ const apiFiles = findApiFiles();
50
17
  if (!BUILD_CTX) {
51
- BUILD_CTX = await (0, import_esbuild.context)(getEsbuildOptions(apiFiles));
18
+ BUILD_CTX = await context(getEsbuildOptions(apiFiles));
52
19
  }
53
20
  return BUILD_CTX.rebuild();
54
21
  };
55
22
  const cleanApiBuild = async () => {
56
- const rwjsPaths = (0, import_project_config.getPaths)();
57
- return import_fs_extra.default.remove(rwjsPaths.api.dist);
23
+ const rwjsPaths = getPaths();
24
+ return fs.remove(rwjsPaths.api.dist);
58
25
  };
59
26
  const runRwBabelTransformsPlugin = {
60
27
  name: "rw-esbuild-babel-transform",
61
28
  setup(build2) {
62
- const rwjsConfig = (0, import_project_config.getConfig)();
29
+ const rwjsConfig = getConfig();
63
30
  build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
64
- const transformedCode = await (0, import_babel_config.transformWithBabel)(
31
+ const transformedCode = await transformWithBabel(
65
32
  args.path,
66
- (0, import_babel_config.getApiSideBabelPlugins)({
33
+ getApiSideBabelPlugins({
67
34
  openTelemetry: rwjsConfig.experimental.opentelemetry.enabled && rwjsConfig.experimental.opentelemetry.wrapApi,
68
- projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
35
+ projectIsEsm: projectSideIsEsm("api")
69
36
  })
70
37
  );
71
38
  if (transformedCode?.code) {
@@ -79,11 +46,11 @@ const runRwBabelTransformsPlugin = {
79
46
  }
80
47
  };
81
48
  const transpileApi = async (files) => {
82
- return (0, import_esbuild.build)(getEsbuildOptions(files));
49
+ return build(getEsbuildOptions(files));
83
50
  };
84
51
  function getEsbuildOptions(files) {
85
- const rwjsPaths = (0, import_project_config.getPaths)();
86
- const format = (0, import_project_config.projectSideIsEsm)("api") ? "esm" : "cjs";
52
+ const rwjsPaths = getPaths();
53
+ const format = projectSideIsEsm("api") ? "esm" : "cjs";
87
54
  return {
88
55
  absWorkingDir: rwjsPaths.api.base,
89
56
  entryPoints: files,
@@ -100,10 +67,9 @@ function getEsbuildOptions(files) {
100
67
  sourcemap: true
101
68
  };
102
69
  }
103
- // Annotate the CommonJS export names for ESM import in node:
104
- 0 && (module.exports = {
70
+ export {
105
71
  buildApi,
106
72
  cleanApiBuild,
107
73
  rebuildApi,
108
74
  transpileApi
109
- });
75
+ };
@@ -0,0 +1,26 @@
1
+ import { types } from '@babel/core';
2
+ export declare const fileToAst: (filePath: string) => types.Node;
3
+ interface NamedExports {
4
+ name: string;
5
+ type: 're-export' | 'variable' | 'function' | 'class';
6
+ location: {
7
+ line: number;
8
+ column: number;
9
+ };
10
+ }
11
+ /**
12
+ * get all the named exports in a given piece of code.
13
+ */
14
+ export declare const getNamedExports: (ast: types.Node) => NamedExports[];
15
+ /**
16
+ * get all the gql queries from the supplied code
17
+ */
18
+ export declare const getGqlQueries: (ast: types.Node) => string[];
19
+ export declare const getCellGqlQuery: (ast: types.Node) => undefined;
20
+ export declare const hasDefaultExport: (ast: types.Node) => boolean;
21
+ export declare const getDefaultExportLocation: (ast: types.Node) => {
22
+ line: number;
23
+ column: number;
24
+ } | null;
25
+ export {};
26
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,aAAc,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,QAAS,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,QAAS,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAS,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,QAC9B,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
@@ -0,0 +1,201 @@
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 ast_exports = {};
30
+ __export(ast_exports, {
31
+ fileToAst: () => fileToAst,
32
+ getCellGqlQuery: () => getCellGqlQuery,
33
+ getDefaultExportLocation: () => getDefaultExportLocation,
34
+ getGqlQueries: () => getGqlQueries,
35
+ getNamedExports: () => getNamedExports,
36
+ hasDefaultExport: () => hasDefaultExport
37
+ });
38
+ module.exports = __toCommonJS(ast_exports);
39
+ var import_fs = __toESM(require("fs"), 1);
40
+ var import_path = __toESM(require("path"), 1);
41
+ var import_core = require("@babel/core");
42
+ var import_parser = require("@babel/parser");
43
+ var import_traverse = __toESM(require("@babel/traverse"), 1);
44
+ var import_ansis = __toESM(require("ansis"), 1);
45
+ var import_project_config = require("@cedarjs/project-config");
46
+ var import_files = require("./files.js");
47
+ const traverse = import_traverse.default.default || import_traverse.default;
48
+ const fileToAst = (filePath) => {
49
+ const code = import_fs.default.readFileSync(filePath, "utf-8");
50
+ const isJsxFile = import_path.default.extname(filePath).match(/[jt]sx$/) || (0, import_files.isFileInsideFolder)(filePath, (0, import_project_config.getPaths)().web.base);
51
+ const plugins = [
52
+ "typescript",
53
+ "nullishCoalescingOperator",
54
+ "objectRestSpread",
55
+ isJsxFile && "jsx"
56
+ ].filter(Boolean);
57
+ try {
58
+ return (0, import_parser.parse)(code, {
59
+ sourceType: "module",
60
+ plugins
61
+ });
62
+ } catch (e) {
63
+ console.error(import_ansis.default.red(`Error parsing: ${filePath}`));
64
+ console.error(e);
65
+ throw new Error(e?.message);
66
+ }
67
+ };
68
+ const getNamedExports = (ast) => {
69
+ const namedExports = [];
70
+ traverse(ast, {
71
+ ExportNamedDeclaration(path2) {
72
+ const specifiers = path2.node?.specifiers;
73
+ if (specifiers.length) {
74
+ for (const s of specifiers) {
75
+ const id = s.exported;
76
+ namedExports.push({
77
+ name: id.name,
78
+ type: "re-export",
79
+ location: {
80
+ line: id.loc?.start.line ?? 1,
81
+ column: id.loc?.start.column ?? 0
82
+ }
83
+ });
84
+ }
85
+ return;
86
+ }
87
+ const declaration = path2.node.declaration;
88
+ if (!declaration) {
89
+ return;
90
+ }
91
+ if (declaration.type === "VariableDeclaration") {
92
+ const id = declaration.declarations[0].id;
93
+ namedExports.push({
94
+ name: id.name,
95
+ type: "variable",
96
+ location: {
97
+ line: id.loc?.start.line ?? 1,
98
+ column: id.loc?.start.column ?? 0
99
+ }
100
+ });
101
+ } else if (declaration.type === "FunctionDeclaration") {
102
+ namedExports.push({
103
+ name: declaration?.id?.name,
104
+ type: "function",
105
+ location: {
106
+ line: declaration?.id?.loc?.start.line ?? 1,
107
+ column: declaration?.id?.loc?.start.column ?? 0
108
+ }
109
+ });
110
+ } else if (declaration.type === "ClassDeclaration") {
111
+ namedExports.push({
112
+ name: declaration?.id?.name,
113
+ type: "class",
114
+ location: {
115
+ line: declaration?.id?.loc?.start.line ?? 1,
116
+ column: declaration?.id?.loc?.start.column ?? 0
117
+ }
118
+ });
119
+ }
120
+ }
121
+ });
122
+ return namedExports;
123
+ };
124
+ const getGqlQueries = (ast) => {
125
+ const gqlQueries = [];
126
+ traverse(ast, {
127
+ TaggedTemplateExpression(path2) {
128
+ const gqlTag = path2.node.tag;
129
+ if (gqlTag.type === "Identifier" && gqlTag.name === "gql") {
130
+ gqlQueries.push(path2.node.quasi.quasis[0].value.raw);
131
+ }
132
+ }
133
+ });
134
+ return gqlQueries;
135
+ };
136
+ const getCellGqlQuery = (ast) => {
137
+ let cellQuery = void 0;
138
+ traverse(ast, {
139
+ ExportNamedDeclaration({ node }) {
140
+ if (node.exportKind === "value" && import_core.types.isVariableDeclaration(node.declaration)) {
141
+ const exportedQueryNode = node.declaration.declarations.find(
142
+ (d) => {
143
+ return import_core.types.isIdentifier(d.id) && d.id.name === "QUERY" && import_core.types.isTaggedTemplateExpression(d.init);
144
+ }
145
+ );
146
+ if (exportedQueryNode) {
147
+ const templateExpression = exportedQueryNode.init;
148
+ cellQuery = templateExpression.quasi.quasis[0].value.raw;
149
+ }
150
+ }
151
+ return;
152
+ }
153
+ });
154
+ return cellQuery;
155
+ };
156
+ const hasDefaultExport = (ast) => {
157
+ let exported = false;
158
+ traverse(ast, {
159
+ ExportDefaultDeclaration() {
160
+ exported = true;
161
+ return;
162
+ }
163
+ });
164
+ return exported;
165
+ };
166
+ const getDefaultExportLocation = (ast) => {
167
+ let defaultExport;
168
+ traverse(ast, {
169
+ ExportDefaultDeclaration(path2) {
170
+ defaultExport = path2.node;
171
+ }
172
+ });
173
+ if (!defaultExport) {
174
+ return null;
175
+ }
176
+ if (import_core.types.isIdentifier(defaultExport.declaration) && import_core.types.isFile(ast)) {
177
+ const exportedName = defaultExport.declaration.name;
178
+ const declaration = ast.program.body.find((node) => {
179
+ return import_core.types.isVariableDeclaration(node) && node.declarations.find((d) => {
180
+ return import_core.types.isVariableDeclarator(d) && import_core.types.isIdentifier(d.id) && d.id.name === exportedName;
181
+ });
182
+ });
183
+ return {
184
+ line: declaration?.loc?.start.line ?? 1,
185
+ column: declaration?.loc?.start.column ?? 0
186
+ };
187
+ }
188
+ return {
189
+ line: defaultExport.loc?.start.line ?? 1,
190
+ column: defaultExport.loc?.start.column ?? 0
191
+ };
192
+ };
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ fileToAst,
196
+ getCellGqlQuery,
197
+ getDefaultExportLocation,
198
+ getGqlQueries,
199
+ getNamedExports,
200
+ hasDefaultExport
201
+ });
@@ -0,0 +1,6 @@
1
+ import type { BuildOptions } from 'esbuild';
2
+ export declare const buildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
3
+ export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
4
+ export declare const cleanApiBuild: () => Promise<void>;
5
+ export declare const transpileApi: (files: string[]) => Promise<import("esbuild").BuildResult<BuildOptions>>;
6
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AActE,eAAO,MAAM,QAAQ,4DAOpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAQtB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AAiCD,eAAO,MAAM,YAAY,UAAiB,MAAM,EAAE,yDAEjD,CAAA"}
@@ -0,0 +1,109 @@
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
+ buildApi: () => buildApi,
32
+ cleanApiBuild: () => cleanApiBuild,
33
+ rebuildApi: () => rebuildApi,
34
+ transpileApi: () => transpileApi
35
+ });
36
+ module.exports = __toCommonJS(api_exports);
37
+ var import_esbuild = require("esbuild");
38
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
39
+ var import_babel_config = require("@cedarjs/babel-config");
40
+ var import_project_config = require("@cedarjs/project-config");
41
+ var import_files = require("../files.js");
42
+ let BUILD_CTX = null;
43
+ const buildApi = async () => {
44
+ BUILD_CTX?.dispose();
45
+ BUILD_CTX = null;
46
+ return transpileApi((0, import_files.findApiFiles)());
47
+ };
48
+ const rebuildApi = async () => {
49
+ const apiFiles = (0, import_files.findApiFiles)();
50
+ if (!BUILD_CTX) {
51
+ BUILD_CTX = await (0, import_esbuild.context)(getEsbuildOptions(apiFiles));
52
+ }
53
+ return BUILD_CTX.rebuild();
54
+ };
55
+ const cleanApiBuild = async () => {
56
+ const rwjsPaths = (0, import_project_config.getPaths)();
57
+ return import_fs_extra.default.remove(rwjsPaths.api.dist);
58
+ };
59
+ const runRwBabelTransformsPlugin = {
60
+ name: "rw-esbuild-babel-transform",
61
+ setup(build2) {
62
+ const rwjsConfig = (0, import_project_config.getConfig)();
63
+ build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
64
+ const transformedCode = await (0, import_babel_config.transformWithBabel)(
65
+ args.path,
66
+ (0, import_babel_config.getApiSideBabelPlugins)({
67
+ openTelemetry: rwjsConfig.experimental.opentelemetry.enabled && rwjsConfig.experimental.opentelemetry.wrapApi,
68
+ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
69
+ })
70
+ );
71
+ if (transformedCode?.code) {
72
+ return {
73
+ contents: transformedCode.code,
74
+ loader: "js"
75
+ };
76
+ }
77
+ throw new Error(`Could not transform file: ${args.path}`);
78
+ });
79
+ }
80
+ };
81
+ const transpileApi = async (files) => {
82
+ return (0, import_esbuild.build)(getEsbuildOptions(files));
83
+ };
84
+ function getEsbuildOptions(files) {
85
+ const rwjsPaths = (0, import_project_config.getPaths)();
86
+ const format = (0, import_project_config.projectSideIsEsm)("api") ? "esm" : "cjs";
87
+ return {
88
+ absWorkingDir: rwjsPaths.api.base,
89
+ entryPoints: files,
90
+ platform: "node",
91
+ target: "node20",
92
+ format,
93
+ allowOverwrite: true,
94
+ bundle: false,
95
+ plugins: [runRwBabelTransformsPlugin],
96
+ outdir: rwjsPaths.api.dist,
97
+ // setting this to 'true' will generate an external sourcemap x.js.map
98
+ // AND set the sourceMappingURL comment
99
+ // (setting it to 'external' will ONLY generate the file, but won't add the comment)
100
+ sourcemap: true
101
+ };
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ buildApi,
106
+ cleanApiBuild,
107
+ rebuildApi,
108
+ transpileApi
109
+ });
@@ -0,0 +1,11 @@
1
+ type CLog = (typeof console)['log'];
2
+ /**
3
+ * An alternative to createLogger which supports the same logging levels
4
+ * but allows for full ANSI when printing to the console.
5
+ */
6
+ export declare const cliLogger: CLog & {
7
+ trace: CLog;
8
+ debug: CLog;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=cliLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliLogger.d.ts","sourceRoot":"","sources":["../../src/cliLogger.ts"],"names":[],"mappings":"AAIA,KAAK,IAAI,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA;AAEnC;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,IAAI,GAAG;IAC7B,KAAK,EAAE,IAAI,CAAA;IACX,KAAK,EAAE,IAAI,CAAA;CAGZ,CAAA"}