gtx-cli 2.0.4 → 2.0.5

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,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#467](https://github.com/generaltranslation/gt/pull/467) [`e043f07`](https://github.com/generaltranslation/gt/commit/e043f07decb426c2b275b67ad955b4ddca7d20ee) Thanks [@brian-lou](https://github.com/brian-lou)! - Add async errors for useGT/getGT to translate
8
+
3
9
  ## 2.0.4
4
10
 
5
11
  ### Patch Changes
@@ -13,4 +13,4 @@ import { Updates } from '../../../types/index.js';
13
13
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
14
14
  * - This will parse constants.ts to find translation calls within getInfo function
15
15
  */
16
- export declare function parseStrings(importName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;
16
+ export declare function parseStrings(importName: string, originalName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;
@@ -1,7 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import { isStaticExpression } from '../evaluateJsx.js';
3
3
  import { GT_ATTRIBUTES_WITH_SUGAR, mapAttributeName } from './constants.js';
4
- import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, } from '../../../console/index.js';
4
+ import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, warnAsyncUseGT, warnSyncGetGT, } from '../../../console/index.js';
5
5
  import generateModule from '@babel/generator';
6
6
  import traverseModule from '@babel/traverse';
7
7
  // Handle CommonJS/ESM interop
@@ -343,7 +343,7 @@ function findFunctionInFile(filePath, functionName, argIndex, updates, errors) {
343
343
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
344
344
  * - This will parse constants.ts to find translation calls within getInfo function
345
345
  */
346
- export function parseStrings(importName, path, updates, errors, file) {
346
+ export function parseStrings(importName, originalName, path, updates, errors, file) {
347
347
  // First, collect all imports in this file to track cross-file function calls
348
348
  const importMap = buildImportMap(path.scope.getProgramParent().path);
349
349
  const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
@@ -353,6 +353,16 @@ export function parseStrings(importName, path, updates, errors, file) {
353
353
  if (callExpr) {
354
354
  // Get the parent, handling both await and non-await cases
355
355
  const parentPath = callExpr.parentPath;
356
+ const parentFunction = refPath.getFunctionParent();
357
+ const asyncScope = parentFunction?.node.async;
358
+ if (asyncScope && originalName === 'useGT') {
359
+ errors.push(warnAsyncUseGT(file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
360
+ return;
361
+ }
362
+ else if (!asyncScope && originalName === 'getGT') {
363
+ errors.push(warnSyncGetGT(file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
364
+ return;
365
+ }
356
366
  const effectiveParent = parentPath?.node.type === 'AwaitExpression'
357
367
  ? parentPath.parentPath
358
368
  : parentPath;
@@ -8,7 +8,6 @@ import { parseJSXElement } from '../jsx/utils/parseJsx.js';
8
8
  import { parseStrings } from '../jsx/utils/parseStringFunction.js';
9
9
  import { extractImportName } from '../jsx/utils/parseAst.js';
10
10
  import { logError } from '../../console/logging.js';
11
- import { validateStringFunction } from '../jsx/utils/validateStringFunction.js';
12
11
  import { GT_TRANSLATION_FUNCS } from '../jsx/utils/constants.js';
13
12
  import { matchFiles } from '../../fs/matchFiles.js';
14
13
  import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
@@ -82,8 +81,8 @@ export async function createInlineUpdates(pkg, validate, filePatterns) {
82
81
  },
83
82
  });
84
83
  // Process translation functions asynchronously
85
- for (const { localName: name, path } of translationPaths) {
86
- parseStrings(name, path, updates, errors, file);
84
+ for (const { localName: name, originalName, path } of translationPaths) {
85
+ parseStrings(name, originalName, path, updates, errors, file);
87
86
  }
88
87
  // Parse <T> components
89
88
  traverse(ast, {
@@ -92,11 +91,12 @@ export async function createInlineUpdates(pkg, validate, filePatterns) {
92
91
  },
93
92
  });
94
93
  // Extra validation (for Locadex)
95
- if (validate) {
96
- for (const { localName: name, path, originalName } of translationPaths) {
97
- validateStringFunction(name, path, updates, errors, file, originalName);
98
- }
99
- }
94
+ // Done in parseStrings() atm
95
+ // if (validate) {
96
+ // for (const { localName: name, path, originalName } of translationPaths) {
97
+ // validateStringFunction(name, path, updates, errors, file, originalName);
98
+ // }
99
+ // }
100
100
  }
101
101
  // Post-process to add a hash to each update
102
102
  await Promise.all(updates.map(async (update) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [