gtx-cli 2.5.11 → 2.5.12
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 +9 -0
- package/dist/react/jsx/utils/constants.d.ts +3 -0
- package/dist/react/jsx/utils/constants.js +26 -0
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +2 -1
- package/dist/react/jsx/utils/getPathsAndAliases.js +5 -5
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +7 -6
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +33 -33
- package/dist/react/jsx/utils/parseAst.d.ts +2 -1
- package/dist/react/jsx/utils/parseAst.js +4 -3
- package/dist/react/parse/createInlineUpdates.d.ts +2 -1
- package/dist/react/parse/createInlineUpdates.js +11 -2
- package/package.json +24 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.5.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#816](https://github.com/generaltranslation/gt/pull/816) [`e42a442`](https://github.com/generaltranslation/gt/commit/e42a44280442e588b82b3fe1aff52f1e53aa8605) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add gt-i18n, a pure js library for translation
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e42a442`](https://github.com/generaltranslation/gt/commit/e42a44280442e588b82b3fe1aff52f1e53aa8605)]:
|
|
10
|
+
- generaltranslation@8.0.4
|
|
11
|
+
|
|
3
12
|
## 2.5.11
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -10,3 +10,6 @@ export declare const VARIABLE_COMPONENTS: string[];
|
|
|
10
10
|
export declare const GT_ATTRIBUTES_WITH_SUGAR: string[];
|
|
11
11
|
export declare const GT_ATTRIBUTES: string[];
|
|
12
12
|
export declare function mapAttributeName(attrName: string): string;
|
|
13
|
+
export declare const GT_LIBRARIES: readonly ["gt-react", "gt-next", "gt-react-native", "gt-i18n", "@generaltranslation/react-core"];
|
|
14
|
+
export type GTLibrary = (typeof GT_LIBRARIES)[number];
|
|
15
|
+
export declare const GT_LIBRARIES_UPSTREAM: Record<GTLibrary, GTLibrary[]>;
|
|
@@ -38,3 +38,29 @@ export function mapAttributeName(attrName) {
|
|
|
38
38
|
return 'context';
|
|
39
39
|
return attrName;
|
|
40
40
|
}
|
|
41
|
+
export const GT_LIBRARIES = [
|
|
42
|
+
'gt-react',
|
|
43
|
+
'gt-next',
|
|
44
|
+
'gt-react-native',
|
|
45
|
+
'gt-i18n',
|
|
46
|
+
'@generaltranslation/react-core',
|
|
47
|
+
];
|
|
48
|
+
export const GT_LIBRARIES_UPSTREAM = {
|
|
49
|
+
'gt-next': [
|
|
50
|
+
'gt-i18n',
|
|
51
|
+
'@generaltranslation/react-core',
|
|
52
|
+
'gt-react',
|
|
53
|
+
'gt-next',
|
|
54
|
+
],
|
|
55
|
+
'gt-react': ['gt-i18n', '@generaltranslation/react-core', 'gt-react'],
|
|
56
|
+
'gt-react-native': [
|
|
57
|
+
'gt-i18n',
|
|
58
|
+
'@generaltranslation/react-core',
|
|
59
|
+
'gt-react-native',
|
|
60
|
+
],
|
|
61
|
+
'@generaltranslation/react-core': [
|
|
62
|
+
'gt-i18n',
|
|
63
|
+
'@generaltranslation/react-core',
|
|
64
|
+
],
|
|
65
|
+
'gt-i18n': ['gt-i18n'],
|
|
66
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
|
+
import { GTLibrary } from '../../jsx/utils/constants.js';
|
|
2
3
|
/**
|
|
3
4
|
* Constructs tracking for gt related variables of interest
|
|
4
5
|
* inlineTranslationPaths: these are string-related translation functions
|
|
5
6
|
* translationComponentPaths: these are just <T> components
|
|
6
7
|
* importAliases: any other GT related imports
|
|
7
8
|
*/
|
|
8
|
-
export declare function getPathsAndAliases(ast: any,
|
|
9
|
+
export declare function getPathsAndAliases(ast: any, pkgs: GTLibrary[]): {
|
|
9
10
|
importAliases: Record<string, string>;
|
|
10
11
|
inlineTranslationPaths: Array<{
|
|
11
12
|
localName: string;
|
|
@@ -9,15 +9,15 @@ const traverse = traverseModule.default || traverseModule;
|
|
|
9
9
|
* translationComponentPaths: these are just <T> components
|
|
10
10
|
* importAliases: any other GT related imports
|
|
11
11
|
*/
|
|
12
|
-
export function getPathsAndAliases(ast,
|
|
12
|
+
export function getPathsAndAliases(ast, pkgs) {
|
|
13
13
|
// First pass: collect imports and process translation functions
|
|
14
14
|
const importAliases = {};
|
|
15
15
|
const inlineTranslationPaths = [];
|
|
16
16
|
const translationComponentPaths = [];
|
|
17
17
|
traverse(ast, {
|
|
18
18
|
ImportDeclaration(path) {
|
|
19
|
-
if (path.node.source.value.startsWith(pkg)) {
|
|
20
|
-
const importName = extractImportName(path.node,
|
|
19
|
+
if (pkgs.some((pkg) => path.node.source.value.startsWith(pkg))) {
|
|
20
|
+
const importName = extractImportName(path.node, pkgs, GT_TRANSLATION_FUNCS);
|
|
21
21
|
for (const name of importName) {
|
|
22
22
|
if (name.original === INLINE_TRANSLATION_HOOK ||
|
|
23
23
|
name.original === INLINE_TRANSLATION_HOOK_ASYNC ||
|
|
@@ -52,10 +52,10 @@ export function getPathsAndAliases(ast, pkg) {
|
|
|
52
52
|
const args = path.node.init.arguments;
|
|
53
53
|
if (args.length === 1 &&
|
|
54
54
|
args[0].type === 'StringLiteral' &&
|
|
55
|
-
args[0].value.startsWith(pkg)) {
|
|
55
|
+
pkgs.some((pkg) => args[0].value.startsWith(pkg))) {
|
|
56
56
|
const parentPath = path.parentPath;
|
|
57
57
|
if (parentPath.isVariableDeclaration()) {
|
|
58
|
-
const importName = extractImportName(parentPath.node,
|
|
58
|
+
const importName = extractImportName(parentPath.node, pkgs, GT_TRANSLATION_FUNCS);
|
|
59
59
|
for (const name of importName) {
|
|
60
60
|
if (name.original === INLINE_TRANSLATION_HOOK ||
|
|
61
61
|
name.original === INLINE_TRANSLATION_HOOK_ASYNC ||
|
|
@@ -4,12 +4,13 @@ import { NodePath } from '@babel/traverse';
|
|
|
4
4
|
import { ParsingConfigOptions } from '../../../../types/parsing.js';
|
|
5
5
|
import traverseModule from '@babel/traverse';
|
|
6
6
|
import { JsxTree } from './types.js';
|
|
7
|
+
import { GTLibrary } from '../constants.js';
|
|
7
8
|
/**
|
|
8
9
|
* Entry point for JSX parsing
|
|
9
10
|
*/
|
|
10
|
-
export declare function parseTranslationComponent({ originalName, importAliases, localName, path, updates, errors, warnings, file, parsingOptions,
|
|
11
|
+
export declare function parseTranslationComponent({ originalName, importAliases, localName, path, updates, errors, warnings, file, parsingOptions, pkgs, }: {
|
|
11
12
|
ast: any;
|
|
12
|
-
|
|
13
|
+
pkgs: GTLibrary[];
|
|
13
14
|
originalName: string;
|
|
14
15
|
importAliases: Record<string, string>;
|
|
15
16
|
path: traverseModule.NodePath<traverseModule.Node>;
|
|
@@ -30,7 +31,7 @@ export declare function parseTranslationComponent({ originalName, importAliases,
|
|
|
30
31
|
* @param insideT - Whether the current node is inside a <T> component
|
|
31
32
|
* @returns The built JSX tree
|
|
32
33
|
*/
|
|
33
|
-
export declare function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap,
|
|
34
|
+
export declare function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkgs, }: {
|
|
34
35
|
importAliases: Record<string, string>;
|
|
35
36
|
node: any;
|
|
36
37
|
callStack: string[];
|
|
@@ -44,13 +45,13 @@ export declare function buildJSXTree({ importAliases, node, unwrappedExpressions
|
|
|
44
45
|
parsingOptions: ParsingConfigOptions;
|
|
45
46
|
scopeNode: NodePath;
|
|
46
47
|
importedFunctionsMap: Map<string, string>;
|
|
47
|
-
|
|
48
|
+
pkgs: GTLibrary[];
|
|
48
49
|
}): JsxTree;
|
|
49
|
-
export declare function parseJSXElement({ importAliases, node, originalName,
|
|
50
|
+
export declare function parseJSXElement({ importAliases, node, originalName, pkgs, updates, errors, warnings, file, parsingOptions, scopeNode, importedFunctionsMap, }: {
|
|
50
51
|
importAliases: Record<string, string>;
|
|
51
52
|
node: t.JSXElement;
|
|
52
53
|
originalName: string;
|
|
53
|
-
|
|
54
|
+
pkgs: GTLibrary[];
|
|
54
55
|
updates: Updates;
|
|
55
56
|
errors: string[];
|
|
56
57
|
warnings: Set<string>;
|
|
@@ -37,7 +37,7 @@ const processFunctionCache = new Map();
|
|
|
37
37
|
/**
|
|
38
38
|
* Entry point for JSX parsing
|
|
39
39
|
*/
|
|
40
|
-
export function parseTranslationComponent({ originalName, importAliases, localName, path, updates, errors, warnings, file, parsingOptions,
|
|
40
|
+
export function parseTranslationComponent({ originalName, importAliases, localName, path, updates, errors, warnings, file, parsingOptions, pkgs, }) {
|
|
41
41
|
// First, collect all imports in this file to track cross-file function calls
|
|
42
42
|
const importedFunctionsMap = buildImportMap(path.scope.getProgramParent().path);
|
|
43
43
|
const referencePaths = path.scope.bindings[localName]?.referencePaths || [];
|
|
@@ -54,7 +54,7 @@ export function parseTranslationComponent({ originalName, importAliases, localNa
|
|
|
54
54
|
parseJSXElement({
|
|
55
55
|
scopeNode: jsxElementPath,
|
|
56
56
|
node: jsxElementPath.node,
|
|
57
|
-
|
|
57
|
+
pkgs,
|
|
58
58
|
originalName,
|
|
59
59
|
importAliases,
|
|
60
60
|
updates,
|
|
@@ -76,7 +76,7 @@ export function parseTranslationComponent({ originalName, importAliases, localNa
|
|
|
76
76
|
* @param insideT - Whether the current node is inside a <T> component
|
|
77
77
|
* @returns The built JSX tree
|
|
78
78
|
*/
|
|
79
|
-
export function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap,
|
|
79
|
+
export function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkgs, }) {
|
|
80
80
|
if (t.isJSXExpressionContainer(node)) {
|
|
81
81
|
// Skip JSX comments
|
|
82
82
|
if (t.isJSXEmptyExpression(node.expression)) {
|
|
@@ -98,7 +98,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
98
98
|
parsingOptions,
|
|
99
99
|
scopeNode,
|
|
100
100
|
importedFunctionsMap,
|
|
101
|
-
|
|
101
|
+
pkgs,
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
const staticAnalysis = isStaticExpression(expr, true);
|
|
@@ -192,7 +192,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
192
192
|
parsingOptions,
|
|
193
193
|
scopeNode,
|
|
194
194
|
importedFunctionsMap,
|
|
195
|
-
|
|
195
|
+
pkgs,
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
}
|
|
@@ -218,7 +218,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
218
218
|
callStack,
|
|
219
219
|
parsingOptions,
|
|
220
220
|
importedFunctionsMap,
|
|
221
|
-
|
|
221
|
+
pkgs,
|
|
222
222
|
props,
|
|
223
223
|
});
|
|
224
224
|
}
|
|
@@ -255,7 +255,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
255
255
|
parsingOptions,
|
|
256
256
|
scopeNode,
|
|
257
257
|
importedFunctionsMap,
|
|
258
|
-
|
|
258
|
+
pkgs,
|
|
259
259
|
}))
|
|
260
260
|
.filter((child) => child !== null && child !== '');
|
|
261
261
|
if (children.length === 1) {
|
|
@@ -289,7 +289,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
289
289
|
parsingOptions,
|
|
290
290
|
scopeNode,
|
|
291
291
|
importedFunctionsMap,
|
|
292
|
-
|
|
292
|
+
pkgs,
|
|
293
293
|
}))
|
|
294
294
|
.filter((child) => child !== null && child !== '');
|
|
295
295
|
const props = {};
|
|
@@ -354,7 +354,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
|
|
|
354
354
|
}
|
|
355
355
|
// end buildJSXTree
|
|
356
356
|
// Parses a JSX element and adds it to the updates array
|
|
357
|
-
export function parseJSXElement({ importAliases, node, originalName,
|
|
357
|
+
export function parseJSXElement({ importAliases, node, originalName, pkgs, updates, errors, warnings, file, parsingOptions, scopeNode, importedFunctionsMap, }) {
|
|
358
358
|
const openingElement = node.openingElement;
|
|
359
359
|
const name = openingElement.name;
|
|
360
360
|
// Only proceed if it's <T> ...
|
|
@@ -381,7 +381,7 @@ export function parseJSXElement({ importAliases, node, originalName, pkg, update
|
|
|
381
381
|
scopeNode,
|
|
382
382
|
visited: null,
|
|
383
383
|
callStack: [],
|
|
384
|
-
|
|
384
|
+
pkgs,
|
|
385
385
|
unwrappedExpressions,
|
|
386
386
|
updates,
|
|
387
387
|
errors: componentErrors,
|
|
@@ -452,7 +452,7 @@ export function parseJSXElement({ importAliases, node, originalName, pkg, update
|
|
|
452
452
|
* {getSubject()}
|
|
453
453
|
* </Static>
|
|
454
454
|
*/
|
|
455
|
-
function resolveStaticComponentChildren({ importAliases, scopeNode, children, unwrappedExpressions, visited, updates, errors, warnings, file, callStack, parsingOptions, importedFunctionsMap,
|
|
455
|
+
function resolveStaticComponentChildren({ importAliases, scopeNode, children, unwrappedExpressions, visited, updates, errors, warnings, file, callStack, parsingOptions, importedFunctionsMap, pkgs, props, }) {
|
|
456
456
|
const result = {
|
|
457
457
|
nodeType: 'element',
|
|
458
458
|
type: STATIC_COMPONENT,
|
|
@@ -504,7 +504,7 @@ function resolveStaticComponentChildren({ importAliases, scopeNode, children, un
|
|
|
504
504
|
errors,
|
|
505
505
|
warnings,
|
|
506
506
|
unwrappedExpressions,
|
|
507
|
-
|
|
507
|
+
pkgs,
|
|
508
508
|
parsingOptions,
|
|
509
509
|
importedFunctionsMap,
|
|
510
510
|
});
|
|
@@ -515,7 +515,7 @@ function resolveStaticComponentChildren({ importAliases, scopeNode, children, un
|
|
|
515
515
|
}
|
|
516
516
|
return result;
|
|
517
517
|
}
|
|
518
|
-
function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBinding, callee, unwrappedExpressions, visited, callStack, file, updates, errors, warnings, parsingOptions, importedFunctionsMap,
|
|
518
|
+
function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBinding, callee, unwrappedExpressions, visited, callStack, file, updates, errors, warnings, parsingOptions, importedFunctionsMap, pkgs, }) {
|
|
519
519
|
function withRecusionGuard({ cb, filename, functionName, }) {
|
|
520
520
|
const cacheKey = `${filename}::${functionName}`;
|
|
521
521
|
if (callStack.includes(cacheKey)) {
|
|
@@ -548,7 +548,7 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
|
|
|
548
548
|
file,
|
|
549
549
|
parsingOptions,
|
|
550
550
|
importedFunctionsMap,
|
|
551
|
-
|
|
551
|
+
pkgs,
|
|
552
552
|
}),
|
|
553
553
|
});
|
|
554
554
|
}
|
|
@@ -569,7 +569,7 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
|
|
|
569
569
|
unwrappedExpressions,
|
|
570
570
|
updates,
|
|
571
571
|
callStack,
|
|
572
|
-
|
|
572
|
+
pkgs,
|
|
573
573
|
errors,
|
|
574
574
|
visited,
|
|
575
575
|
warnings,
|
|
@@ -611,7 +611,7 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
|
|
|
611
611
|
warnings,
|
|
612
612
|
file,
|
|
613
613
|
parsingOptions,
|
|
614
|
-
|
|
614
|
+
pkgs,
|
|
615
615
|
}),
|
|
616
616
|
});
|
|
617
617
|
if (result !== null) {
|
|
@@ -633,7 +633,7 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
|
|
|
633
633
|
*
|
|
634
634
|
* If the function is not found in the file, follows re-exports (export * from './other')
|
|
635
635
|
*/
|
|
636
|
-
function processFunctionInFile({ filePath, functionName, visited, callStack, parsingOptions, updates, errors, warnings, file, unwrappedExpressions,
|
|
636
|
+
function processFunctionInFile({ filePath, functionName, visited, callStack, parsingOptions, updates, errors, warnings, file, unwrappedExpressions, pkgs, }) {
|
|
637
637
|
// Create a custom key for the function call
|
|
638
638
|
const cacheKey = `${filePath}::${functionName}`;
|
|
639
639
|
// Check cache first to avoid redundant parsing
|
|
@@ -652,7 +652,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
652
652
|
sourceType: 'module',
|
|
653
653
|
plugins: ['jsx', 'typescript'],
|
|
654
654
|
});
|
|
655
|
-
const { importAliases } = getPathsAndAliases(ast,
|
|
655
|
+
const { importAliases } = getPathsAndAliases(ast, pkgs);
|
|
656
656
|
// Collect all imports in this file to track cross-file function calls
|
|
657
657
|
let importedFunctionsMap;
|
|
658
658
|
traverse(ast, {
|
|
@@ -677,7 +677,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
677
677
|
unwrappedExpressions,
|
|
678
678
|
callStack,
|
|
679
679
|
visited,
|
|
680
|
-
|
|
680
|
+
pkgs,
|
|
681
681
|
updates,
|
|
682
682
|
errors,
|
|
683
683
|
warnings,
|
|
@@ -701,7 +701,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
701
701
|
functionName,
|
|
702
702
|
path,
|
|
703
703
|
callStack,
|
|
704
|
-
|
|
704
|
+
pkgs,
|
|
705
705
|
updates,
|
|
706
706
|
errors,
|
|
707
707
|
warnings,
|
|
@@ -754,7 +754,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
754
754
|
errors,
|
|
755
755
|
warnings,
|
|
756
756
|
file: filePath,
|
|
757
|
-
|
|
757
|
+
pkgs,
|
|
758
758
|
});
|
|
759
759
|
if (foundResult != null) {
|
|
760
760
|
result = foundResult;
|
|
@@ -777,7 +777,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
777
777
|
* Process a function declaration
|
|
778
778
|
* function getInfo() { ... }
|
|
779
779
|
*/
|
|
780
|
-
function processFunctionDeclarationNodePath({ functionName, path, importAliases, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap,
|
|
780
|
+
function processFunctionDeclarationNodePath({ functionName, path, importAliases, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap, pkgs, }) {
|
|
781
781
|
const result = {
|
|
782
782
|
nodeType: 'multiplication',
|
|
783
783
|
branches: [],
|
|
@@ -794,7 +794,7 @@ function processFunctionDeclarationNodePath({ functionName, path, importAliases,
|
|
|
794
794
|
result.branches.push(processReturnExpression({
|
|
795
795
|
unwrappedExpressions,
|
|
796
796
|
functionName,
|
|
797
|
-
|
|
797
|
+
pkgs,
|
|
798
798
|
callStack,
|
|
799
799
|
scopeNode: returnNodePath,
|
|
800
800
|
expressionNodePath: returnNodePath,
|
|
@@ -820,7 +820,7 @@ function processFunctionDeclarationNodePath({ functionName, path, importAliases,
|
|
|
820
820
|
*
|
|
821
821
|
* IMPORTANT: the RHand value must be the function definition, or this will fail
|
|
822
822
|
*/
|
|
823
|
-
function processVariableDeclarationNodePath({ functionName, path, importAliases, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap,
|
|
823
|
+
function processVariableDeclarationNodePath({ functionName, path, importAliases, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap, pkgs, }) {
|
|
824
824
|
const result = {
|
|
825
825
|
nodeType: 'multiplication',
|
|
826
826
|
branches: [],
|
|
@@ -837,7 +837,7 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
837
837
|
result.branches.push(processReturnExpression({
|
|
838
838
|
unwrappedExpressions,
|
|
839
839
|
functionName,
|
|
840
|
-
|
|
840
|
+
pkgs,
|
|
841
841
|
scopeNode: arrowFunctionPath,
|
|
842
842
|
expressionNodePath: bodyNodePath,
|
|
843
843
|
importAliases,
|
|
@@ -865,7 +865,7 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
865
865
|
result.branches.push(processReturnExpression({
|
|
866
866
|
unwrappedExpressions,
|
|
867
867
|
functionName,
|
|
868
|
-
|
|
868
|
+
pkgs,
|
|
869
869
|
scopeNode: returnPath,
|
|
870
870
|
expressionNodePath: returnNodePath,
|
|
871
871
|
importAliases,
|
|
@@ -890,7 +890,7 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
890
890
|
/**
|
|
891
891
|
* Process a expression being returned from a function
|
|
892
892
|
*/
|
|
893
|
-
function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNodePath, importAliases, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap, functionName,
|
|
893
|
+
function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNodePath, importAliases, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap, functionName, pkgs, }) {
|
|
894
894
|
// // If the node is null, return
|
|
895
895
|
// if (expressionNodePath == null) return null;
|
|
896
896
|
// Remove parentheses if they exist
|
|
@@ -910,7 +910,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
910
910
|
parsingOptions,
|
|
911
911
|
functionName,
|
|
912
912
|
importedFunctionsMap,
|
|
913
|
-
|
|
913
|
+
pkgs,
|
|
914
914
|
});
|
|
915
915
|
}
|
|
916
916
|
else if (t.isCallExpression(expressionNodePath.node) &&
|
|
@@ -934,7 +934,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
934
934
|
updates,
|
|
935
935
|
errors,
|
|
936
936
|
warnings,
|
|
937
|
-
|
|
937
|
+
pkgs,
|
|
938
938
|
parsingOptions,
|
|
939
939
|
importedFunctionsMap,
|
|
940
940
|
});
|
|
@@ -961,7 +961,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
961
961
|
updates,
|
|
962
962
|
errors,
|
|
963
963
|
warnings,
|
|
964
|
-
|
|
964
|
+
pkgs,
|
|
965
965
|
parsingOptions,
|
|
966
966
|
importedFunctionsMap,
|
|
967
967
|
});
|
|
@@ -983,7 +983,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
983
983
|
parsingOptions,
|
|
984
984
|
scopeNode,
|
|
985
985
|
importedFunctionsMap,
|
|
986
|
-
|
|
986
|
+
pkgs,
|
|
987
987
|
});
|
|
988
988
|
}
|
|
989
989
|
else if (t.isConditionalExpression(expressionNodePath.node)) {
|
|
@@ -1007,7 +1007,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
1007
1007
|
parsingOptions,
|
|
1008
1008
|
functionName,
|
|
1009
1009
|
importedFunctionsMap,
|
|
1010
|
-
|
|
1010
|
+
pkgs,
|
|
1011
1011
|
})),
|
|
1012
1012
|
};
|
|
1013
1013
|
return result;
|
|
@@ -1027,7 +1027,7 @@ function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
1027
1027
|
parsingOptions,
|
|
1028
1028
|
scopeNode,
|
|
1029
1029
|
importedFunctionsMap,
|
|
1030
|
-
|
|
1030
|
+
pkgs,
|
|
1031
1031
|
});
|
|
1032
1032
|
}
|
|
1033
1033
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { ParseResult } from '@babel/parser';
|
|
3
3
|
import { ImportDeclaration, VariableDeclaration } from '@babel/types';
|
|
4
|
+
import { GTLibrary } from './constants.js';
|
|
4
5
|
export declare function determineModuleType(ast: ParseResult<t.File>): boolean;
|
|
5
6
|
export type ImportItem = string | {
|
|
6
7
|
local: string;
|
|
@@ -27,4 +28,4 @@ export interface ImportNameResult {
|
|
|
27
28
|
local: string;
|
|
28
29
|
original: string;
|
|
29
30
|
}
|
|
30
|
-
export declare function extractImportName(node: ImportDeclaration | VariableDeclaration,
|
|
31
|
+
export declare function extractImportName(node: ImportDeclaration | VariableDeclaration, pkgs: GTLibrary[], translationFuncs: string[]): ImportNameResult[];
|
|
@@ -199,11 +199,11 @@ export function createImports(ast, needsImport, importMap) {
|
|
|
199
199
|
const importNodes = generateImports(needsImport, isESM, importMap);
|
|
200
200
|
insertImports(ast, importNodes);
|
|
201
201
|
}
|
|
202
|
-
export function extractImportName(node,
|
|
202
|
+
export function extractImportName(node, pkgs, translationFuncs) {
|
|
203
203
|
const results = [];
|
|
204
204
|
if (node.type === 'ImportDeclaration') {
|
|
205
205
|
// Handle ES6 imports
|
|
206
|
-
if (node.source.value.startsWith(pkg)) {
|
|
206
|
+
if (pkgs.some((pkg) => node.source.value.startsWith(pkg))) {
|
|
207
207
|
for (const specifier of node.specifiers) {
|
|
208
208
|
if (specifier.type === 'ImportSpecifier' &&
|
|
209
209
|
'name' in specifier.imported &&
|
|
@@ -224,7 +224,8 @@ export function extractImportName(node, pkg, translationFuncs) {
|
|
|
224
224
|
declaration.init.callee.type === 'Identifier' &&
|
|
225
225
|
declaration.init.callee.name === 'require' &&
|
|
226
226
|
declaration.init.arguments[0]?.type === 'StringLiteral' &&
|
|
227
|
-
|
|
227
|
+
pkgs.some((pkg) => declaration.init
|
|
228
|
+
.arguments[0].value.startsWith(pkg))) {
|
|
228
229
|
// Handle destructuring case: const { T } = require('gt-next')
|
|
229
230
|
if (declaration.id.type === 'ObjectPattern') {
|
|
230
231
|
for (const prop of declaration.id.properties) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Updates } from '../../types/index.js';
|
|
2
2
|
import type { ParsingConfigOptions } from '../../types/parsing.js';
|
|
3
|
-
|
|
3
|
+
import { GTLibrary } from '../jsx/utils/constants.js';
|
|
4
|
+
export declare function createInlineUpdates(pkg: GTLibrary, validate: boolean, filePatterns: string[] | undefined, parsingOptions: ParsingConfigOptions): Promise<{
|
|
4
5
|
updates: Updates;
|
|
5
6
|
errors: string[];
|
|
6
7
|
warnings: string[];
|
|
@@ -7,10 +7,12 @@ import { logger } from '../../console/logger.js';
|
|
|
7
7
|
import { matchFiles } from '../../fs/matchFiles.js';
|
|
8
8
|
import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
|
|
9
9
|
import { getPathsAndAliases } from '../jsx/utils/getPathsAndAliases.js';
|
|
10
|
+
import { GT_LIBRARIES_UPSTREAM } from '../jsx/utils/constants.js';
|
|
10
11
|
export async function createInlineUpdates(pkg, validate, filePatterns, parsingOptions) {
|
|
11
12
|
const updates = [];
|
|
12
13
|
const errors = [];
|
|
13
14
|
const warnings = new Set();
|
|
15
|
+
const pkgs = getUpstreamPackages(pkg);
|
|
14
16
|
// Use the provided app directory or default to the current directory
|
|
15
17
|
const files = matchFiles(process.cwd(), filePatterns || DEFAULT_SRC_PATTERNS);
|
|
16
18
|
for (const file of files) {
|
|
@@ -27,7 +29,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
|
|
|
27
29
|
continue;
|
|
28
30
|
}
|
|
29
31
|
// First pass: collect imports and process translation functions
|
|
30
|
-
const { importAliases, inlineTranslationPaths, translationComponentPaths } = getPathsAndAliases(ast,
|
|
32
|
+
const { importAliases, inlineTranslationPaths, translationComponentPaths } = getPathsAndAliases(ast, pkgs);
|
|
31
33
|
// Process translation functions asynchronously
|
|
32
34
|
for (const { localName: name, originalName, path, } of inlineTranslationPaths) {
|
|
33
35
|
parseStrings(name, originalName, path, updates, errors, warnings, file, parsingOptions);
|
|
@@ -39,7 +41,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
|
|
|
39
41
|
originalName: localName,
|
|
40
42
|
localName,
|
|
41
43
|
ast,
|
|
42
|
-
|
|
44
|
+
pkgs,
|
|
43
45
|
path,
|
|
44
46
|
updates,
|
|
45
47
|
errors,
|
|
@@ -69,3 +71,10 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
|
|
|
69
71
|
}));
|
|
70
72
|
return { updates, errors, warnings: [...warnings] };
|
|
71
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Given a package name, return the upstream packages that it depends on
|
|
76
|
+
* @param pkg
|
|
77
|
+
*/
|
|
78
|
+
function getUpstreamPackages(pkg) {
|
|
79
|
+
return GT_LIBRARIES_UPSTREAM[pkg];
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.12",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -10,37 +10,48 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./dist/index.js"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
14
15
|
},
|
|
15
16
|
"./types": {
|
|
16
|
-
"import": "./dist/types.js"
|
|
17
|
+
"import": "./dist/types.js",
|
|
18
|
+
"types": "./dist/types.d.ts"
|
|
17
19
|
},
|
|
18
20
|
"./updates/*": {
|
|
19
|
-
"import": "./dist/updates/*.js"
|
|
21
|
+
"import": "./dist/updates/*.js",
|
|
22
|
+
"types": "./dist/updates/*.d.ts"
|
|
20
23
|
},
|
|
21
24
|
"./jsx/*": {
|
|
22
|
-
"import": "./dist/jsx/*.js"
|
|
25
|
+
"import": "./dist/jsx/*.js",
|
|
26
|
+
"types": "./dist/jsx/*.d.ts"
|
|
23
27
|
},
|
|
24
28
|
"./fs/*": {
|
|
25
|
-
"import": "./dist/fs/*.js"
|
|
29
|
+
"import": "./dist/fs/*.js",
|
|
30
|
+
"types": "./dist/fs/*.d.ts"
|
|
26
31
|
},
|
|
27
32
|
"./console/*": {
|
|
28
|
-
"import": "./dist/console/*.js"
|
|
33
|
+
"import": "./dist/console/*.js",
|
|
34
|
+
"types": "./dist/console/*.d.ts"
|
|
29
35
|
},
|
|
30
36
|
"./config/*": {
|
|
31
|
-
"import": "./dist/config/*.js"
|
|
37
|
+
"import": "./dist/config/*.js",
|
|
38
|
+
"types": "./dist/config/*.d.ts"
|
|
32
39
|
},
|
|
33
40
|
"./api/*": {
|
|
34
|
-
"import": "./dist/api/*.js"
|
|
41
|
+
"import": "./dist/api/*.js",
|
|
42
|
+
"types": "./dist/api/*.d.ts"
|
|
35
43
|
},
|
|
36
44
|
"./setup/*": {
|
|
37
|
-
"import": "./dist/setup/*.js"
|
|
45
|
+
"import": "./dist/setup/*.js",
|
|
46
|
+
"types": "./dist/setup/*.d.ts"
|
|
38
47
|
},
|
|
39
48
|
"./*": {
|
|
40
|
-
"import": "./dist/*.js"
|
|
49
|
+
"import": "./dist/*.js",
|
|
50
|
+
"types": "./dist/*.d.ts"
|
|
41
51
|
},
|
|
42
52
|
"./utils/*": {
|
|
43
|
-
"import": "./dist/utils/*.js"
|
|
53
|
+
"import": "./dist/utils/*.js",
|
|
54
|
+
"types": "./dist/utils/*.d.ts"
|
|
44
55
|
}
|
|
45
56
|
},
|
|
46
57
|
"repository": {
|
|
@@ -93,7 +104,7 @@
|
|
|
93
104
|
"unified": "^11.0.5",
|
|
94
105
|
"unist-util-visit": "^5.0.0",
|
|
95
106
|
"yaml": "^2.8.0",
|
|
96
|
-
"generaltranslation": "8.0.
|
|
107
|
+
"generaltranslation": "8.0.4"
|
|
97
108
|
},
|
|
98
109
|
"devDependencies": {
|
|
99
110
|
"@babel/types": "^7.28.4",
|