gtx-cli 2.5.14 → 2.5.15

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.5.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [#838](https://github.com/generaltranslation/gt/pull/838) [`3a3d45b`](https://github.com/generaltranslation/gt/commit/3a3d45be0b454fb017ad4b75a772df1c8aaee65e) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Adding fallback when localizing static imports
8
+
3
9
  ## 2.5.14
4
10
 
5
11
  ### Patch Changes
@@ -293,12 +293,8 @@ function transformMdxImports(mdxContent, defaultLocale, targetLocale, hideDefaul
293
293
  }
294
294
  catch (error) {
295
295
  console.warn(`Failed to parse MDX content: ${error instanceof Error ? error.message : String(error)}`);
296
- console.warn('Returning original content unchanged due to parsing error.');
297
- return {
298
- content: mdxContent,
299
- hasChanges: false,
300
- transformedImports: [],
301
- };
296
+ console.warn('Falling back to string-based import localization.');
297
+ return transformImportsStringFallback(mdxContent, defaultLocale, targetLocale, hideDefaultLocale, pattern, exclude, currentFilePath, options);
302
298
  }
303
299
  let content = mdxContent;
304
300
  // Visit only mdxjsEsm nodes (import/export statements) to collect replacements
@@ -358,6 +354,40 @@ function transformMdxImports(mdxContent, defaultLocale, targetLocale, hideDefaul
358
354
  transformedImports,
359
355
  };
360
356
  }
357
+ /**
358
+ * String-based fallback for import localization when MDX parsing fails (e.g., on .md files)
359
+ */
360
+ function transformImportsStringFallback(mdxContent, defaultLocale, targetLocale, hideDefaultLocale, pattern = '/[locale]', exclude = [], currentFilePath, options) {
361
+ const transformedImports = [];
362
+ if (!pattern.startsWith('/') && !pattern.startsWith('.')) {
363
+ pattern = '/' + pattern;
364
+ }
365
+ const patternHead = pattern.split('[locale]')[0];
366
+ let content = mdxContent;
367
+ const importRegex = /import\s+[^'"]*['"]([^'"]+)['"]\s*;?/g;
368
+ let match;
369
+ while ((match = importRegex.exec(mdxContent)) !== null) {
370
+ const fullMatch = match[0];
371
+ const importPath = match[1];
372
+ if (!shouldProcessImportPath(importPath, patternHead, targetLocale, defaultLocale)) {
373
+ continue;
374
+ }
375
+ if (isImportPathExcluded(importPath, exclude, defaultLocale)) {
376
+ continue;
377
+ }
378
+ const newPath = transformImportPath(importPath, patternHead, targetLocale, defaultLocale, hideDefaultLocale, currentFilePath, process.cwd(), options?.docsImportRewrites);
379
+ if (!newPath)
380
+ continue;
381
+ const updatedImport = fullMatch.replace(importPath, newPath);
382
+ content = content.replace(fullMatch, updatedImport);
383
+ transformedImports.push({ originalPath: importPath, newPath });
384
+ }
385
+ return {
386
+ content,
387
+ hasChanges: transformedImports.length > 0,
388
+ transformedImports,
389
+ };
390
+ }
361
391
  /**
362
392
  * AST-based transformation for MDX files only
363
393
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.14",
3
+ "version": "2.5.15",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [