gtx-cli 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#564](https://github.com/generaltranslation/gt/pull/564) [`7251fc5`](https://github.com/generaltranslation/gt/commit/7251fc5d2474ad71b2da9ae5b71e37aed8199bce) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix CLI validation (used to error for {<JSX/>} inside <T>)
|
|
8
|
+
|
|
9
|
+
## 2.1.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#562](https://github.com/generaltranslation/gt/pull/562) [`8461c5e`](https://github.com/generaltranslation/gt/commit/8461c5ee2ca25cf50d4e366cb4d1e765107851fd) Thanks [@SamEggert](https://github.com/SamEggert)! - localStaticImports gracefully handles invalid MDX
|
|
14
|
+
|
|
3
15
|
## 2.1.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
|
+
import generateModule from '@babel/generator';
|
|
3
|
+
// Handle CommonJS/ESM interop
|
|
4
|
+
const generate = generateModule.default || generateModule;
|
|
2
5
|
const MEANINGFUL_REGEX = /[\p{L}\p{N}]/u;
|
|
3
6
|
/**
|
|
4
7
|
* Checks if a node is meaningful. Does not recurse into children.
|
|
@@ -44,23 +47,10 @@ export function isStaticExpression(expr) {
|
|
|
44
47
|
if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {
|
|
45
48
|
return { isStatic: true, value: expr.quasis[0].value.raw };
|
|
46
49
|
}
|
|
47
|
-
//
|
|
50
|
+
// Binary expressions are not static
|
|
48
51
|
if (t.isBinaryExpression(expr)) {
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
return { isStatic: false };
|
|
52
|
-
}
|
|
53
|
-
// Type guard to ensure we only process Expression types
|
|
54
|
-
if (t.isExpression(expr.left) && t.isExpression(expr.right)) {
|
|
55
|
-
const left = isStaticExpression(expr.left);
|
|
56
|
-
const right = isStaticExpression(expr.right);
|
|
57
|
-
if (left.isStatic &&
|
|
58
|
-
right.isStatic &&
|
|
59
|
-
left.value !== undefined &&
|
|
60
|
-
right.value !== undefined) {
|
|
61
|
-
return { isStatic: true, value: left.value + right.value };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
52
|
+
// Not a static expression
|
|
53
|
+
return { isStatic: false };
|
|
64
54
|
}
|
|
65
55
|
// Handle parenthesized expressions
|
|
66
56
|
if (t.isParenthesizedExpression(expr)) {
|
|
@@ -25,6 +25,9 @@ export function buildJSXTree(importAliases, node, unwrappedExpressions, updates,
|
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
const expr = node.expression;
|
|
28
|
+
if (t.isJSXElement(expr)) {
|
|
29
|
+
return buildJSXTree(importAliases, expr, unwrappedExpressions, updates, errors, warnings, file, insideT);
|
|
30
|
+
}
|
|
28
31
|
const staticAnalysis = isStaticExpression(expr);
|
|
29
32
|
if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
|
|
30
33
|
// Preserve the exact whitespace for static string expressions
|
|
@@ -221,12 +221,24 @@ function transformMdxImports(mdxContent, defaultLocale, targetLocale, hideDefaul
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
// Parse the MDX content into an AST
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
let processedAst;
|
|
225
|
+
try {
|
|
226
|
+
const parseProcessor = unified()
|
|
227
|
+
.use(remarkParse)
|
|
228
|
+
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
229
|
+
.use(remarkMdx);
|
|
230
|
+
const ast = parseProcessor.parse(mdxContent);
|
|
231
|
+
processedAst = parseProcessor.runSync(ast);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.warn(`Failed to parse MDX content: ${error instanceof Error ? error.message : String(error)}`);
|
|
235
|
+
console.warn('Returning original content unchanged due to parsing error.');
|
|
236
|
+
return {
|
|
237
|
+
content: mdxContent,
|
|
238
|
+
hasChanges: false,
|
|
239
|
+
transformedImports: [],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
230
242
|
// Visit only mdxjsEsm nodes (import/export statements)
|
|
231
243
|
visit(processedAst, 'mdxjsEsm', (node) => {
|
|
232
244
|
if (node.value && node.value.includes(patternHead.replace(/\/$/, ''))) {
|
|
@@ -282,11 +294,23 @@ function transformMdxImports(mdxContent, defaultLocale, targetLocale, hideDefaul
|
|
|
282
294
|
}
|
|
283
295
|
});
|
|
284
296
|
// Convert the modified AST back to MDX string
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
297
|
+
let content;
|
|
298
|
+
try {
|
|
299
|
+
const stringifyProcessor = unified()
|
|
300
|
+
.use(remarkStringify)
|
|
301
|
+
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
302
|
+
.use(remarkMdx);
|
|
303
|
+
content = stringifyProcessor.stringify(processedAst);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.warn(`Failed to stringify MDX content: ${error instanceof Error ? error.message : String(error)}`);
|
|
307
|
+
console.warn('Returning original content unchanged due to stringify error.');
|
|
308
|
+
return {
|
|
309
|
+
content: mdxContent,
|
|
310
|
+
hasChanges: false,
|
|
311
|
+
transformedImports: [],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
290
314
|
// Handle newline formatting to match original input
|
|
291
315
|
if (content.endsWith('\n') && !mdxContent.endsWith('\n')) {
|
|
292
316
|
content = content.slice(0, -1);
|