@cedarjs/babel-config 8.0.0-canary.3489 → 8.0.0-canary.3493
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.
|
@@ -1 +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;
|
|
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;AAc5C,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAmKzE;AAoCD,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM;;;;;;CA6GxC,CAAA;AAkBD,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;CACtD"}
|
|
@@ -5,6 +5,7 @@ import babelTraverse from "@babel/traverse";
|
|
|
5
5
|
import fg from "fast-glob";
|
|
6
6
|
import { parse as graphqlParse, Kind } from "graphql";
|
|
7
7
|
const traverse = babelTraverse.default || babelTraverse;
|
|
8
|
+
const QUERY_EXPORT_NAME = "QUERY";
|
|
8
9
|
function babel_plugin_redwood_mock_cell_data_default({ types: t }) {
|
|
9
10
|
let nodesToRemove = [];
|
|
10
11
|
let nodesToInsert = [];
|
|
@@ -119,6 +120,23 @@ function babel_plugin_redwood_mock_cell_data_default({ types: t }) {
|
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
}
|
|
123
|
+
const getQueryCallSource = (init) => {
|
|
124
|
+
let expression = init;
|
|
125
|
+
while (expression?.type === "TSAsExpression" || expression?.type === "TSSatisfiesExpression" || expression?.type === "TSNonNullExpression") {
|
|
126
|
+
expression = expression.expression;
|
|
127
|
+
}
|
|
128
|
+
if (expression?.type !== "CallExpression") {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
const [source] = expression.arguments;
|
|
132
|
+
if (source?.type === "StringLiteral") {
|
|
133
|
+
return source.value;
|
|
134
|
+
}
|
|
135
|
+
if (source?.type === "TemplateLiteral" && source.expressions.length === 0) {
|
|
136
|
+
return source.quasis[0].value.raw;
|
|
137
|
+
}
|
|
138
|
+
return void 0;
|
|
139
|
+
};
|
|
122
140
|
const getCellMetadata = (p) => {
|
|
123
141
|
const ast = getCellAst(p);
|
|
124
142
|
let hasDefaultExport = false;
|
|
@@ -146,6 +164,13 @@ const getCellMetadata = (p) => {
|
|
|
146
164
|
return;
|
|
147
165
|
}
|
|
148
166
|
if (declaration.type === "VariableDeclaration") {
|
|
167
|
+
const queryDeclarator = declaration.declarations.find(
|
|
168
|
+
(declarator) => declarator.id.type === "Identifier" && declarator.id.name === QUERY_EXPORT_NAME
|
|
169
|
+
);
|
|
170
|
+
const querySource = getQueryCallSource(queryDeclarator?.init);
|
|
171
|
+
if (querySource !== void 0) {
|
|
172
|
+
operation = querySource;
|
|
173
|
+
}
|
|
149
174
|
const id = declaration.declarations[0].id;
|
|
150
175
|
namedExports.push({
|
|
151
176
|
name: id.name,
|
|
@@ -164,23 +189,28 @@ const getCellMetadata = (p) => {
|
|
|
164
189
|
}
|
|
165
190
|
},
|
|
166
191
|
TaggedTemplateExpression(path2) {
|
|
167
|
-
if (path2.parent?.id?.name !==
|
|
192
|
+
if (path2.parent?.id?.name !== QUERY_EXPORT_NAME) {
|
|
168
193
|
return;
|
|
169
194
|
}
|
|
170
195
|
operation = path2.node.quasi.quasis[0].value.raw;
|
|
171
196
|
}
|
|
172
197
|
});
|
|
173
|
-
const hasQueryExport = namedExports.find(
|
|
198
|
+
const hasQueryExport = namedExports.find(
|
|
199
|
+
({ name }) => name === QUERY_EXPORT_NAME
|
|
200
|
+
);
|
|
174
201
|
const hasAfterQueryExport = namedExports.find(
|
|
175
202
|
({ name }) => name === "afterQuery"
|
|
176
203
|
);
|
|
177
204
|
let operationName = "";
|
|
178
205
|
if (operation) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
206
|
+
try {
|
|
207
|
+
const document = graphqlParse(operation);
|
|
208
|
+
for (const definition of document.definitions) {
|
|
209
|
+
if (definition.kind === Kind.OPERATION_DEFINITION && definition.name?.value) {
|
|
210
|
+
operationName = definition.name.value;
|
|
211
|
+
}
|
|
183
212
|
}
|
|
213
|
+
} catch {
|
|
184
214
|
}
|
|
185
215
|
}
|
|
186
216
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/babel-config",
|
|
3
|
-
"version": "8.0.0-canary.
|
|
3
|
+
"version": "8.0.0-canary.3493",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/preset-react": "7.29.7",
|
|
33
33
|
"@babel/register": "7.29.7",
|
|
34
34
|
"@babel/traverse": "7.29.10",
|
|
35
|
-
"@cedarjs/project-config": "8.0.0-canary.
|
|
35
|
+
"@cedarjs/project-config": "8.0.0-canary.3493",
|
|
36
36
|
"babel-plugin-auto-import": "1.1.0",
|
|
37
37
|
"babel-plugin-graphql-tag": "3.3.0",
|
|
38
38
|
"babel-plugin-module-resolver": "5.0.3",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@babel/core": "^7.26.10",
|
|
45
45
|
"@babel/preset-typescript": "7.29.7",
|
|
46
|
-
"@cedarjs/framework-tools": "8.0.0-canary.
|
|
46
|
+
"@cedarjs/framework-tools": "8.0.0-canary.3493",
|
|
47
47
|
"@types/babel-plugin-tester": "11.0.0",
|
|
48
48
|
"@types/babel__core": "7.20.5",
|
|
49
49
|
"@types/babel__register": "7.17.3",
|