@redmix/babel-config 0.0.1

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/__tests__/api.test.d.ts +2 -0
  4. package/dist/__tests__/api.test.d.ts.map +1 -0
  5. package/dist/__tests__/common.test.d.ts +2 -0
  6. package/dist/__tests__/common.test.d.ts.map +1 -0
  7. package/dist/__tests__/prebuildApiFile.test.d.ts +6 -0
  8. package/dist/__tests__/prebuildApiFile.test.d.ts.map +1 -0
  9. package/dist/__tests__/tsconfigParsing.test.d.ts +2 -0
  10. package/dist/__tests__/tsconfigParsing.test.d.ts.map +1 -0
  11. package/dist/api.d.ts +37 -0
  12. package/dist/api.d.ts.map +1 -0
  13. package/dist/api.js +258 -0
  14. package/dist/common.d.ts +50 -0
  15. package/dist/common.d.ts.map +1 -0
  16. package/dist/common.js +145 -0
  17. package/dist/index.d.ts +5 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +70 -0
  20. package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts +2 -0
  21. package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts.map +1 -0
  22. package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts +2 -0
  23. package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts.map +1 -0
  24. package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts +2 -0
  25. package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts.map +1 -0
  26. package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts +2 -0
  27. package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts.map +1 -0
  28. package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts +2 -0
  29. package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts.map +1 -0
  30. package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts +2 -0
  31. package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts.map +1 -0
  32. package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts +2 -0
  33. package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts.map +1 -0
  34. package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts +2 -0
  35. package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts.map +1 -0
  36. package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts +2 -0
  37. package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts.map +1 -0
  38. package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts +2 -0
  39. package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts.map +1 -0
  40. package/dist/plugins/babel-plugin-redwood-cell.d.ts +5 -0
  41. package/dist/plugins/babel-plugin-redwood-cell.d.ts.map +1 -0
  42. package/dist/plugins/babel-plugin-redwood-cell.js +115 -0
  43. package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts +7 -0
  44. package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts.map +1 -0
  45. package/dist/plugins/babel-plugin-redwood-context-wrapping.js +134 -0
  46. package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts +5 -0
  47. package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts.map +1 -0
  48. package/dist/plugins/babel-plugin-redwood-directory-named-import.js +94 -0
  49. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts +5 -0
  50. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts.map +1 -0
  51. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.js +88 -0
  52. package/dist/plugins/babel-plugin-redwood-import-dir.d.ts +23 -0
  53. package/dist/plugins/babel-plugin-redwood-import-dir.d.ts.map +1 -0
  54. package/dist/plugins/babel-plugin-redwood-import-dir.js +98 -0
  55. package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts +5 -0
  56. package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts.map +1 -0
  57. package/dist/plugins/babel-plugin-redwood-job-path-injector.js +118 -0
  58. package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts +18 -0
  59. package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts.map +1 -0
  60. package/dist/plugins/babel-plugin-redwood-mock-cell-data.js +244 -0
  61. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts +5 -0
  62. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts.map +1 -0
  63. package/dist/plugins/babel-plugin-redwood-otel-wrapping.js +329 -0
  64. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts +5 -0
  65. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts.map +1 -0
  66. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.js +41 -0
  67. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts +23 -0
  68. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts.map +1 -0
  69. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.js +182 -0
  70. package/dist/plugins/babel-plugin-redwood-src-alias.d.ts +8 -0
  71. package/dist/plugins/babel-plugin-redwood-src-alias.d.ts.map +1 -0
  72. package/dist/plugins/babel-plugin-redwood-src-alias.js +72 -0
  73. package/dist/web.d.ts +21 -0
  74. package/dist/web.d.ts.map +1 -0
  75. package/dist/web.js +239 -0
  76. package/package.json +60 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-job-path-injector.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-job-path-injector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAQjE,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,UAAU,CAAA;CAAE,GAAG,SAAS,CAmG3E"}
@@ -0,0 +1,118 @@
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 babel_plugin_redwood_job_path_injector_exports = {};
30
+ __export(babel_plugin_redwood_job_path_injector_exports, {
31
+ default: () => babel_plugin_redwood_job_path_injector_default
32
+ });
33
+ module.exports = __toCommonJS(babel_plugin_redwood_job_path_injector_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_project_config = require("@redmix/project-config");
36
+ function babel_plugin_redwood_job_path_injector_default({ types }) {
37
+ const paths = (0, import_project_config.getPaths)();
38
+ return {
39
+ name: "babel-plugin-redwood-job-path-injector",
40
+ visitor: {
41
+ ExportNamedDeclaration(path, state) {
42
+ const declaration = path.node.declaration;
43
+ if (!declaration) {
44
+ return;
45
+ }
46
+ if (declaration.type !== "VariableDeclaration") {
47
+ return;
48
+ }
49
+ const declarator = declaration.declarations[0];
50
+ if (!declarator) {
51
+ return;
52
+ }
53
+ if (declarator.type !== "VariableDeclarator") {
54
+ return;
55
+ }
56
+ const init = declarator.init;
57
+ if (!init) {
58
+ return;
59
+ }
60
+ if (init.type !== "CallExpression") {
61
+ return;
62
+ }
63
+ const callee = init.callee;
64
+ if (!callee) {
65
+ return;
66
+ }
67
+ if (callee.type !== "MemberExpression") {
68
+ return;
69
+ }
70
+ const property = callee.property;
71
+ if (!property) {
72
+ return;
73
+ }
74
+ if (property.type !== "Identifier") {
75
+ return;
76
+ }
77
+ if (property.name !== "createJob") {
78
+ return;
79
+ }
80
+ const id = declarator.id;
81
+ if (!id) {
82
+ return;
83
+ }
84
+ if (id.type !== "Identifier") {
85
+ return;
86
+ }
87
+ const filepath = state.file.opts.filename;
88
+ if (!filepath) {
89
+ throw new Error("No file path was found in the state");
90
+ }
91
+ const importName = id.name;
92
+ const importPath = import_node_path.default.relative(paths.api.jobs, filepath);
93
+ const importPathWithoutExtension = importPath.replace(/\.[^/.]+$/, "");
94
+ const firstArg = init.arguments[0];
95
+ if (!firstArg) {
96
+ throw new Error("No first argument found in the createJob call");
97
+ }
98
+ if (firstArg.type !== "ObjectExpression") {
99
+ throw new Error(
100
+ "The first argument of the createJob call is not an object expression"
101
+ );
102
+ }
103
+ firstArg.properties.push(
104
+ types.objectProperty(
105
+ types.identifier("path"),
106
+ types.stringLiteral(importPathWithoutExtension)
107
+ )
108
+ );
109
+ firstArg.properties.push(
110
+ types.objectProperty(
111
+ types.identifier("name"),
112
+ types.stringLiteral(importName)
113
+ )
114
+ );
115
+ }
116
+ }
117
+ };
118
+ }
@@ -0,0 +1,18 @@
1
+ import type { types } from '@babel/core';
2
+ import type { PluginObj } from '@babel/core';
3
+ export default function ({ types: t }: {
4
+ types: typeof types;
5
+ }): PluginObj;
6
+ export declare const getCellMetadata: (p: string) => {
7
+ hasDefaultExport: boolean;
8
+ namedExports: NamedExports[];
9
+ hasQueryExport: NamedExports | undefined;
10
+ hasAfterQueryExport: NamedExports | undefined;
11
+ operationName: string;
12
+ };
13
+ interface NamedExports {
14
+ name: string;
15
+ type: 're-export' | 'variable' | 'function' | 'class';
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=babel-plugin-redwood-mock-cell-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-mock-cell-data.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-mock-cell-data.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAO5C,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAmKzE;AAED,eAAO,MAAM,eAAe,MAAO,MAAM;;;;;;CA0FxC,CAAA;AAkBD,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;CACtD"}
@@ -0,0 +1,244 @@
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 babel_plugin_redwood_mock_cell_data_exports = {};
30
+ __export(babel_plugin_redwood_mock_cell_data_exports, {
31
+ default: () => babel_plugin_redwood_mock_cell_data_default,
32
+ getCellMetadata: () => getCellMetadata
33
+ });
34
+ module.exports = __toCommonJS(babel_plugin_redwood_mock_cell_data_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_parser = require("@babel/parser");
38
+ var import_traverse = __toESM(require("@babel/traverse"));
39
+ var import_fast_glob = __toESM(require("fast-glob"));
40
+ var import_graphql = require("graphql");
41
+ function babel_plugin_redwood_mock_cell_data_default({ types: t }) {
42
+ let nodesToRemove = [];
43
+ let nodesToInsert = [];
44
+ const createExportStandard = (ex) => t.exportNamedDeclaration(
45
+ t.variableDeclaration("const", [
46
+ t.variableDeclarator(t.identifier("standard"), ex)
47
+ ])
48
+ );
49
+ return {
50
+ name: "babel-plugin-redwood-mock-cell-data",
51
+ visitor: {
52
+ Program: {
53
+ enter() {
54
+ nodesToRemove = [];
55
+ nodesToInsert = [];
56
+ },
57
+ exit(p) {
58
+ for (const n of nodesToRemove) {
59
+ n.remove();
60
+ }
61
+ p.node.body.unshift(...nodesToInsert);
62
+ }
63
+ },
64
+ ExportNamedDeclaration(p, state) {
65
+ const d = p.node.declaration;
66
+ let mockFunction;
67
+ switch (d?.type) {
68
+ case "VariableDeclaration":
69
+ {
70
+ const standardMockExport = d.declarations[0];
71
+ const id = standardMockExport.id;
72
+ const exportName = id?.name;
73
+ if (exportName !== "standard") {
74
+ return;
75
+ }
76
+ const mockFunctionMaybe = standardMockExport?.init;
77
+ if (!mockFunctionMaybe) {
78
+ return;
79
+ }
80
+ if (mockFunctionMaybe.type !== "ArrowFunctionExpression" && mockFunctionMaybe.type !== "FunctionExpression") {
81
+ throw new Error(
82
+ `
83
+
84
+ Mock Error: You must export your standard mock as a function
85
+
86
+ `
87
+ );
88
+ }
89
+ mockFunction = mockFunctionMaybe;
90
+ }
91
+ break;
92
+ case "FunctionDeclaration":
93
+ {
94
+ const exportName = d.id?.name;
95
+ if (exportName !== "standard") {
96
+ return;
97
+ }
98
+ mockFunction = t.arrowFunctionExpression(d.params, d.body);
99
+ }
100
+ break;
101
+ default:
102
+ return;
103
+ }
104
+ const dirname = import_path.default.dirname(state.file.opts.filename);
105
+ const cellName = import_path.default.basename(dirname);
106
+ const [cellPath] = import_fast_glob.default.sync(`${cellName}.{js,jsx,ts,tsx}`, {
107
+ cwd: dirname,
108
+ absolute: true,
109
+ ignore: ["node_modules"]
110
+ });
111
+ if (!cellPath) {
112
+ return;
113
+ }
114
+ const cellMetadata = getCellMetadata(cellPath);
115
+ if (cellMetadata.hasDefaultExport || !cellMetadata.hasQueryExport) {
116
+ return;
117
+ }
118
+ const mockGraphQLCall = t.callExpression(
119
+ t.identifier("mockGraphQLQuery"),
120
+ [t.stringLiteral(cellMetadata.operationName), mockFunction]
121
+ );
122
+ nodesToRemove = [...nodesToRemove, p];
123
+ if (cellMetadata.hasAfterQueryExport) {
124
+ const importAfterQuery = t.importDeclaration(
125
+ [
126
+ t.importSpecifier(
127
+ t.identifier("afterQuery"),
128
+ t.identifier("afterQuery")
129
+ )
130
+ ],
131
+ t.stringLiteral(`./${import_path.default.basename(cellPath)}`)
132
+ );
133
+ nodesToInsert = [
134
+ ...nodesToInsert,
135
+ importAfterQuery,
136
+ createExportStandard(
137
+ t.arrowFunctionExpression(
138
+ [],
139
+ t.callExpression(t.identifier("afterQuery"), [
140
+ t.callExpression(mockGraphQLCall, [])
141
+ ])
142
+ )
143
+ )
144
+ ];
145
+ } else {
146
+ nodesToInsert = [
147
+ ...nodesToInsert,
148
+ createExportStandard(mockGraphQLCall)
149
+ ];
150
+ }
151
+ }
152
+ }
153
+ };
154
+ }
155
+ const getCellMetadata = (p) => {
156
+ const ast = getCellAst(p);
157
+ let hasDefaultExport = false;
158
+ const namedExports = [];
159
+ let operation;
160
+ (0, import_traverse.default)(ast, {
161
+ ExportDefaultDeclaration() {
162
+ hasDefaultExport = true;
163
+ return;
164
+ },
165
+ ExportNamedDeclaration(path2) {
166
+ const specifiers = path2.node?.specifiers;
167
+ if (specifiers.length) {
168
+ for (const s of specifiers) {
169
+ const id = s.exported;
170
+ namedExports.push({
171
+ name: id.name,
172
+ type: "re-export"
173
+ });
174
+ }
175
+ return;
176
+ }
177
+ const declaration = path2.node.declaration;
178
+ if (!declaration) {
179
+ return;
180
+ }
181
+ if (declaration.type === "VariableDeclaration") {
182
+ const id = declaration.declarations[0].id;
183
+ namedExports.push({
184
+ name: id.name,
185
+ type: "variable"
186
+ });
187
+ } else if (declaration.type === "FunctionDeclaration") {
188
+ namedExports.push({
189
+ name: declaration?.id?.name,
190
+ type: "function"
191
+ });
192
+ } else if (declaration.type === "ClassDeclaration") {
193
+ namedExports.push({
194
+ name: declaration?.id?.name,
195
+ type: "class"
196
+ });
197
+ }
198
+ },
199
+ TaggedTemplateExpression(path2) {
200
+ if (path2.parent?.id?.name !== "QUERY") {
201
+ return;
202
+ }
203
+ operation = path2.node.quasi.quasis[0].value.raw;
204
+ }
205
+ });
206
+ const hasQueryExport = namedExports.find(({ name }) => name === "QUERY");
207
+ const hasAfterQueryExport = namedExports.find(
208
+ ({ name }) => name === "afterQuery"
209
+ );
210
+ let operationName = "";
211
+ if (operation) {
212
+ const document = (0, import_graphql.parse)(operation);
213
+ for (const definition of document.definitions) {
214
+ if (definition.kind === import_graphql.Kind.OPERATION_DEFINITION && definition.name?.value) {
215
+ operationName = definition.name.value;
216
+ }
217
+ }
218
+ }
219
+ return {
220
+ hasDefaultExport,
221
+ namedExports,
222
+ hasQueryExport,
223
+ hasAfterQueryExport,
224
+ operationName
225
+ };
226
+ };
227
+ function getCellAst(filePath) {
228
+ const code = import_fs.default.readFileSync(filePath, "utf-8");
229
+ const plugins = ["typescript", "jsx"].filter(Boolean);
230
+ try {
231
+ return (0, import_parser.parse)(code, {
232
+ sourceType: "module",
233
+ plugins
234
+ });
235
+ } catch (e) {
236
+ console.error(`Error parsing: ${filePath}`);
237
+ console.error(e);
238
+ throw new Error(e?.message);
239
+ }
240
+ }
241
+ // Annotate the CommonJS export names for ESM import in node:
242
+ 0 && (module.exports = {
243
+ getCellMetadata
244
+ });
@@ -0,0 +1,5 @@
1
+ import type { PluginObj, types } from '@babel/core';
2
+ export default function ({ types: t }: {
3
+ types: typeof types;
4
+ }): PluginObj;
5
+ //# sourceMappingURL=babel-plugin-redwood-otel-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-otel-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-otel-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,SAAS,EAAc,KAAK,EAAE,MAAM,aAAa,CAAA;AA2VzE,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAYzE"}