@intlayer/cli 9.3.0 → 9.3.1

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.
Files changed (135) hide show
  1. package/README.md +24 -24
  2. package/dist/cjs/IntlayerEventListener.cjs +2 -6
  3. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  4. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  5. package/dist/cjs/_virtual/_utils_asset.cjs +2 -1
  6. package/dist/cjs/auth/login.cjs.map +1 -1
  7. package/dist/cjs/auth/sessionToken.cjs.map +1 -1
  8. package/dist/cjs/build.cjs.map +1 -1
  9. package/dist/cjs/bundle.cjs +0 -1
  10. package/dist/cjs/bundle.cjs.map +1 -1
  11. package/dist/cjs/ci.cjs.map +1 -1
  12. package/dist/cjs/cli.cjs.map +1 -1
  13. package/dist/cjs/config.cjs.map +1 -1
  14. package/dist/cjs/editor.cjs +3 -1
  15. package/dist/cjs/editor.cjs.map +1 -1
  16. package/dist/cjs/extract.cjs.map +1 -1
  17. package/dist/cjs/fill/deepMergeContent.cjs +0 -1
  18. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  19. package/dist/cjs/fill/extractTranslatableContent.cjs +0 -1
  20. package/dist/cjs/fill/extractTranslatableContent.cjs.map +1 -1
  21. package/dist/cjs/fill/fill.cjs +4 -2
  22. package/dist/cjs/fill/fill.cjs.map +1 -1
  23. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +4 -1
  24. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  25. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  26. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +0 -1
  27. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  28. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +0 -1
  29. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  30. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  31. package/dist/cjs/fill/translateDictionary.cjs +7 -6
  32. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  34. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  35. package/dist/cjs/init.cjs +3 -2
  36. package/dist/cjs/init.cjs.map +1 -1
  37. package/dist/cjs/initBuildOptimization.cjs.map +1 -1
  38. package/dist/cjs/initCompiler.cjs.map +1 -1
  39. package/dist/cjs/initMCP.cjs.map +1 -1
  40. package/dist/cjs/initSkills.cjs +2 -1
  41. package/dist/cjs/initSkills.cjs.map +1 -1
  42. package/dist/cjs/listContentDeclaration.cjs +2 -1
  43. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  44. package/dist/cjs/listProjects.cjs.map +1 -1
  45. package/dist/cjs/liveSync.cjs.map +1 -1
  46. package/dist/cjs/pull.cjs.map +1 -1
  47. package/dist/cjs/push/pullLog.cjs.map +1 -1
  48. package/dist/cjs/push/push.cjs +2 -1
  49. package/dist/cjs/push/push.cjs.map +1 -1
  50. package/dist/cjs/pushConfig.cjs.map +1 -1
  51. package/dist/cjs/pushLog.cjs.map +1 -1
  52. package/dist/cjs/reviewDoc/reviewDoc.cjs +4 -2
  53. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  54. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +4 -2
  55. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  56. package/dist/cjs/reviewDoc/reviewDocLog.cjs +6 -3
  57. package/dist/cjs/reviewDoc/reviewDocLog.cjs.map +1 -1
  58. package/dist/cjs/reviewDoc/reviewDocProgress.cjs.map +1 -1
  59. package/dist/cjs/reviewDoc/reviewDocSynthesis.cjs.map +1 -1
  60. package/dist/cjs/scan.cjs +2 -1
  61. package/dist/cjs/scan.cjs.map +1 -1
  62. package/dist/cjs/searchDoc.cjs.map +1 -1
  63. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  64. package/dist/cjs/test/test.cjs.map +1 -1
  65. package/dist/cjs/translateDoc/translateDoc.cjs +3 -2
  66. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  67. package/dist/cjs/translateDoc/translateFile.cjs +6 -3
  68. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  69. package/dist/cjs/translateDoc/validation.cjs +0 -1
  70. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  71. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  72. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  73. package/dist/cjs/utils/checkConfigConsistency.cjs +0 -1
  74. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  75. package/dist/cjs/utils/checkFileModifiedRange.cjs +3 -2
  76. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  77. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  78. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  79. package/dist/cjs/utils/fixChunkStartEndChars.cjs +0 -1
  80. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  81. package/dist/cjs/utils/formatLineRanges.cjs +0 -1
  82. package/dist/cjs/utils/formatLineRanges.cjs.map +1 -1
  83. package/dist/cjs/utils/formatTimeDiff.cjs +0 -1
  84. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  85. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  86. package/dist/cjs/utils/getOutputFilePath.cjs +2 -1
  87. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  88. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  89. package/dist/cjs/utils/listSpecialChars.cjs +0 -1
  90. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  91. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  92. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  93. package/dist/cjs/utils/selectCmsEnvironment.cjs +2 -1
  94. package/dist/cjs/utils/selectCmsEnvironment.cjs.map +1 -1
  95. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  96. package/dist/cjs/watch.cjs.map +1 -1
  97. package/dist/esm/IntlayerEventListener.mjs +2 -6
  98. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  99. package/dist/esm/_virtual/_utils_asset.mjs +2 -1
  100. package/dist/esm/cli.mjs.map +1 -1
  101. package/dist/esm/editor.mjs +3 -1
  102. package/dist/esm/editor.mjs.map +1 -1
  103. package/dist/esm/fill/fill.mjs +4 -2
  104. package/dist/esm/fill/fill.mjs.map +1 -1
  105. package/dist/esm/fill/formatAutoFilledFilePath.mjs +4 -1
  106. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  107. package/dist/esm/fill/translateDictionary.mjs +7 -6
  108. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  109. package/dist/esm/init.mjs +3 -2
  110. package/dist/esm/init.mjs.map +1 -1
  111. package/dist/esm/initSkills.mjs +2 -1
  112. package/dist/esm/initSkills.mjs.map +1 -1
  113. package/dist/esm/listContentDeclaration.mjs +2 -1
  114. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  115. package/dist/esm/push/push.mjs +2 -1
  116. package/dist/esm/push/push.mjs.map +1 -1
  117. package/dist/esm/reviewDoc/reviewDoc.mjs +4 -2
  118. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  119. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +4 -2
  120. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  121. package/dist/esm/reviewDoc/reviewDocLog.mjs +6 -3
  122. package/dist/esm/reviewDoc/reviewDocLog.mjs.map +1 -1
  123. package/dist/esm/scan.mjs +2 -1
  124. package/dist/esm/scan.mjs.map +1 -1
  125. package/dist/esm/translateDoc/translateDoc.mjs +3 -2
  126. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  127. package/dist/esm/translateDoc/translateFile.mjs +6 -3
  128. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  129. package/dist/esm/utils/checkFileModifiedRange.mjs +3 -2
  130. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  131. package/dist/esm/utils/getOutputFilePath.mjs +2 -1
  132. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  133. package/dist/esm/utils/selectCmsEnvironment.mjs +2 -1
  134. package/dist/esm/utils/selectCmsEnvironment.mjs.map +1 -1
  135. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocSynthesis.cjs","names":["ANSIColors"],"sources":["../../../src/reviewDoc/reviewDocSynthesis.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n type ANSIColorsType,\n colorize,\n colorizeNumber,\n} from '@intlayer/config/logger';\nimport type { ReviewReportSummary } from '@intlayer/engine/docReview';\nimport { formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * The outcome of reviewing one base document against one target locale.\n *\n * - `upToDate`: the translation matches the base document, nothing to do.\n * - `toEdit`: at least one block diverges (to review, to add, or to delete).\n * - `skipped`: the pair was not reviewed (already exists, modification range…).\n */\nexport type ReviewOutcome = 'upToDate' | 'toEdit' | 'skipped';\n\n/** The result of reviewing a single base document / target locale pair. */\nexport type ReviewFileResult = {\n /** Path of the base document, as matched by the doc pattern. */\n docPath: string;\n /** The reviewed target locale. */\n locale: Locale;\n /** What the review concluded for this pair. */\n outcome: ReviewOutcome;\n /** Per-action block counts, when the document was actually compared. */\n summary?: ReviewReportSummary;\n};\n\nexport type FormatReviewSynthesisOptions = {\n /**\n * When `true`, the diverging blocks were fixed during the run, so the section\n * is labelled `Updated` instead of `To edit`.\n */\n hasAppliedChanges?: boolean;\n};\n\n/** Group results by base document path, preserving the first-seen order. */\nconst groupResultsByDocPath = (\n results: ReviewFileResult[]\n): Map<string, ReviewFileResult[]> => {\n const grouped = new Map<string, ReviewFileResult[]>();\n\n for (const result of results) {\n const existingResults = grouped.get(result.docPath);\n\n if (existingResults) existingResults.push(result);\n else grouped.set(result.docPath, [result]);\n }\n\n return grouped;\n};\n\n/** Render the per-action counts of a document, omitting the zeroed ones. */\nconst formatBlockCounts = (summary?: ReviewReportSummary): string => {\n if (!summary) return '';\n\n const countEntries: [label: string, count: number][] = [\n ['review', summary.review],\n ['new', summary.insertNew],\n ['delete', summary.delete],\n ];\n\n const formattedCounts = countEntries\n .filter(([, count]) => count > 0)\n .map(([label, count]) => `${label}=${colorizeNumber(count)}`);\n\n if (formattedCounts.length === 0) return '';\n\n return colorize(` (${formattedCounts.join(', ')})`, ANSIColors.GREY);\n};\n\n/** Render one outcome section: a title line followed by one line per document. */\nconst formatSection = (\n title: string,\n icon: string,\n color: ANSIColorsType,\n results: ReviewFileResult[],\n withBlockCounts: boolean\n): string[] => {\n if (results.length === 0) return [];\n\n const lines: string[] = [\n `${colorize(icon, color)} ${colorize(title, color)} (${colorizeNumber(results.length)})`,\n ];\n\n for (const [docPath, docResults] of groupResultsByDocPath(results)) {\n lines.push(` ${formatPath(docPath)}`);\n\n if (withBlockCounts) {\n for (const result of docResults) {\n lines.push(\n ` ${colorize(result.locale, color)}${formatBlockCounts(result.summary)}`\n );\n }\n continue;\n }\n\n const localeCodes = docResults.map((result) => result.locale).join(', ');\n lines.push(` ${colorize(localeCodes, color)}`);\n }\n\n return lines;\n};\n\n/**\n * Render the end-of-run synthesis: which documents are aligned with their base\n * document and which ones still have blocks to edit.\n *\n * @param results - One entry per reviewed base document / target locale pair.\n * @param options - Rendering options.\n * @returns A multi-line string, ready to be logged.\n */\nexport const formatReviewSynthesis = (\n results: ReviewFileResult[],\n options?: FormatReviewSynthesisOptions\n): string => {\n const upToDateResults = results.filter(\n (result) => result.outcome === 'upToDate'\n );\n const toEditResults = results.filter((result) => result.outcome === 'toEdit');\n const skippedResults = results.filter(\n (result) => result.outcome === 'skipped'\n );\n\n const documentCount = new Set(results.map((result) => result.docPath)).size;\n\n const header = [\n colorize('Review synthesis: ', ANSIColors.BEIGE),\n colorizeNumber(documentCount),\n colorize(' document(s), ', ANSIColors.BEIGE),\n colorizeNumber(results.length),\n colorize(' locale pair(s) — ', ANSIColors.BEIGE),\n colorizeNumber(upToDateResults.length),\n colorize(' up to date, ', ANSIColors.BEIGE),\n colorizeNumber(toEditResults.length),\n colorize(\n options?.hasAppliedChanges ? ' updated, ' : ' to edit, ',\n ANSIColors.BEIGE\n ),\n colorizeNumber(skippedResults.length),\n colorize(' skipped.', ANSIColors.BEIGE),\n ].join('');\n\n return [\n header,\n ...formatSection(\n options?.hasAppliedChanges ? 'Updated' : 'To edit',\n '✎',\n ANSIColors.ORANGE,\n toEditResults,\n true\n ),\n ...formatSection(\n 'Up to date',\n '✔',\n ANSIColors.GREEN,\n upToDateResults,\n false\n ),\n ...formatSection('Skipped', '⊘', ANSIColors.YELLOW, skippedResults, false),\n ].join('\\n');\n};\n"],"mappings":";;;;;;;;;AAwCA,MAAM,yBACJ,YACoC;CACpC,MAAM,0BAAU,IAAI,IAAgC;CAEpD,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,kBAAkB,QAAQ,IAAI,OAAO,OAAO;EAElD,IAAI,iBAAiB,gBAAgB,KAAK,MAAM;OAC3C,QAAQ,IAAI,OAAO,SAAS,CAAC,MAAM,CAAC;CAC3C;CAEA,OAAO;AACT;;AAGA,MAAM,qBAAqB,YAA0C;CACnE,IAAI,CAAC,SAAS,OAAO;CAQrB,MAAM,kBAAkB;EALtB,CAAC,UAAU,QAAQ,MAAM;EACzB,CAAC,OAAO,QAAQ,SAAS;EACzB,CAAC,UAAU,QAAQ,MAAM;CAGQ,CAAC,CACjC,QAAQ,GAAG,WAAW,QAAQ,CAAC,CAAC,CAChC,KAAK,CAAC,OAAO,WAAW,GAAG,MAAM,+CAAkB,KAAK,GAAG;CAE9D,IAAI,gBAAgB,WAAW,GAAG,OAAO;CAEzC,6CAAgB,KAAK,gBAAgB,KAAK,IAAI,EAAE,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EAGA;EACL,GAAG,cACD,SAAS,oBAAoB,YAAY,WACzC,KACAA,wBAAW,QACX,eACA,IACF;EACA,GAAG,cACD,cACA,KACAA,wBAAW,OACX,iBACA,KACF;EACA,GAAG,cAAc,WAAW,KAAKA,wBAAW,QAAQ,gBAAgB,KAAK;CAC3E,CAAC,CAAC,KAAK,IAAI;AACb"}
1
+ {"version":3,"file":"reviewDocSynthesis.cjs","names":["colorizeNumber","colorize","ANSIColors","formatPath"],"sources":["../../../src/reviewDoc/reviewDocSynthesis.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n type ANSIColorsType,\n colorize,\n colorizeNumber,\n} from '@intlayer/config/logger';\nimport type { ReviewReportSummary } from '@intlayer/engine/docReview';\nimport { formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * The outcome of reviewing one base document against one target locale.\n *\n * - `upToDate`: the translation matches the base document, nothing to do.\n * - `toEdit`: at least one block diverges (to review, to add, or to delete).\n * - `skipped`: the pair was not reviewed (already exists, modification range…).\n */\nexport type ReviewOutcome = 'upToDate' | 'toEdit' | 'skipped';\n\n/** The result of reviewing a single base document / target locale pair. */\nexport type ReviewFileResult = {\n /** Path of the base document, as matched by the doc pattern. */\n docPath: string;\n /** The reviewed target locale. */\n locale: Locale;\n /** What the review concluded for this pair. */\n outcome: ReviewOutcome;\n /** Per-action block counts, when the document was actually compared. */\n summary?: ReviewReportSummary;\n};\n\nexport type FormatReviewSynthesisOptions = {\n /**\n * When `true`, the diverging blocks were fixed during the run, so the section\n * is labelled `Updated` instead of `To edit`.\n */\n hasAppliedChanges?: boolean;\n};\n\n/** Group results by base document path, preserving the first-seen order. */\nconst groupResultsByDocPath = (\n results: ReviewFileResult[]\n): Map<string, ReviewFileResult[]> => {\n const grouped = new Map<string, ReviewFileResult[]>();\n\n for (const result of results) {\n const existingResults = grouped.get(result.docPath);\n\n if (existingResults) existingResults.push(result);\n else grouped.set(result.docPath, [result]);\n }\n\n return grouped;\n};\n\n/** Render the per-action counts of a document, omitting the zeroed ones. */\nconst formatBlockCounts = (summary?: ReviewReportSummary): string => {\n if (!summary) return '';\n\n const countEntries: [label: string, count: number][] = [\n ['review', summary.review],\n ['new', summary.insertNew],\n ['delete', summary.delete],\n ];\n\n const formattedCounts = countEntries\n .filter(([, count]) => count > 0)\n .map(([label, count]) => `${label}=${colorizeNumber(count)}`);\n\n if (formattedCounts.length === 0) return '';\n\n return colorize(` (${formattedCounts.join(', ')})`, ANSIColors.GREY);\n};\n\n/** Render one outcome section: a title line followed by one line per document. */\nconst formatSection = (\n title: string,\n icon: string,\n color: ANSIColorsType,\n results: ReviewFileResult[],\n withBlockCounts: boolean\n): string[] => {\n if (results.length === 0) return [];\n\n const lines: string[] = [\n `${colorize(icon, color)} ${colorize(title, color)} (${colorizeNumber(results.length)})`,\n ];\n\n for (const [docPath, docResults] of groupResultsByDocPath(results)) {\n lines.push(` ${formatPath(docPath)}`);\n\n if (withBlockCounts) {\n for (const result of docResults) {\n lines.push(\n ` ${colorize(result.locale, color)}${formatBlockCounts(result.summary)}`\n );\n }\n continue;\n }\n\n const localeCodes = docResults.map((result) => result.locale).join(', ');\n lines.push(` ${colorize(localeCodes, color)}`);\n }\n\n return lines;\n};\n\n/**\n * Render the end-of-run synthesis: which documents are aligned with their base\n * document and which ones still have blocks to edit.\n *\n * @param results - One entry per reviewed base document / target locale pair.\n * @param options - Rendering options.\n * @returns A multi-line string, ready to be logged.\n */\nexport const formatReviewSynthesis = (\n results: ReviewFileResult[],\n options?: FormatReviewSynthesisOptions\n): string => {\n const upToDateResults = results.filter(\n (result) => result.outcome === 'upToDate'\n );\n const toEditResults = results.filter((result) => result.outcome === 'toEdit');\n const skippedResults = results.filter(\n (result) => result.outcome === 'skipped'\n );\n\n const documentCount = new Set(results.map((result) => result.docPath)).size;\n\n const header = [\n colorize('Review synthesis: ', ANSIColors.BEIGE),\n colorizeNumber(documentCount),\n colorize(' document(s), ', ANSIColors.BEIGE),\n colorizeNumber(results.length),\n colorize(' locale pair(s) — ', ANSIColors.BEIGE),\n colorizeNumber(upToDateResults.length),\n colorize(' up to date, ', ANSIColors.BEIGE),\n colorizeNumber(toEditResults.length),\n colorize(\n options?.hasAppliedChanges ? ' updated, ' : ' to edit, ',\n ANSIColors.BEIGE\n ),\n colorizeNumber(skippedResults.length),\n colorize(' skipped.', ANSIColors.BEIGE),\n ].join('');\n\n return [\n header,\n ...formatSection(\n options?.hasAppliedChanges ? 'Updated' : 'To edit',\n '✎',\n ANSIColors.ORANGE,\n toEditResults,\n true\n ),\n ...formatSection(\n 'Up to date',\n '✔',\n ANSIColors.GREEN,\n upToDateResults,\n false\n ),\n ...formatSection('Skipped', '⊘', ANSIColors.YELLOW, skippedResults, false),\n ].join('\\n');\n};\n"],"mappings":";;;;;;;;;AAwCA,MAAM,yBACJ,YACoC;CACpC,MAAM,0BAAU,IAAI,IAAgC;CAEpD,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,kBAAkB,QAAQ,IAAI,OAAO,OAAO;EAElD,IAAI,iBAAiB,gBAAgB,KAAK,MAAM;OAC3C,QAAQ,IAAI,OAAO,SAAS,CAAC,MAAM,CAAC;CAC3C;CAEA,OAAO;AACT;;AAGA,MAAM,qBAAqB,YAA0C;CACnE,IAAI,CAAC,SAAS,OAAO;CAQrB,MAAM,kBAAkB;EALtB,CAAC,UAAU,QAAQ,MAAM;EACzB,CAAC,OAAO,QAAQ,SAAS;EACzB,CAAC,UAAU,QAAQ,MAAM;CAGQ,CAAC,CACjC,QAAQ,GAAG,WAAW,QAAQ,CAAC,CAAC,CAChC,KAAK,CAAC,OAAO,WAAW,GAAG,MAAM,OAAGA,wCAAe,KAAK,GAAG;CAE9D,IAAI,gBAAgB,WAAW,GAAG,OAAO;CAEzC,WAAOC,kCAAS,KAAK,gBAAgB,KAAK,IAAI,EAAE,IAAIC,wBAAW,IAAI;AACrE;;AAGA,MAAM,iBACJ,OACA,MACA,OACA,SACA,oBACa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aAAaC,wBAAW,KAAK;EACxC,CAAC,CAAC,KAAK,EAGA;EACL,GAAG,cACD,SAAS,oBAAoB,YAAY,WACzC,KACAA,wBAAW,QACX,eACA,IACF;EACA,GAAG,cACD,cACA,KACAA,wBAAW,OACX,iBACA,KACF;EACA,GAAG,cAAc,WAAW,KAAKA,wBAAW,QAAQ,gBAAgB,KAAK;CAC3E,CAAC,CAAC,KAAK,IAAI;AACb"}
package/dist/cjs/scan.cjs CHANGED
@@ -45,7 +45,8 @@ const scoreColor = (score) => {
45
45
  * ```
46
46
  */
47
47
  const scan = async (url, options = {}) => {
48
- const appLogger = (0, _intlayer_config_logger.getAppLogger)((0, _intlayer_config_node.getConfiguration)(options.configOptions));
48
+ const configuration = (0, _intlayer_config_node.getConfiguration)(options.configOptions);
49
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration);
49
50
  const result = await (0, _intlayer_engine_scan.scanWebsite)(url, { deep: options.deep });
50
51
  if (options.json) {
51
52
  appLogger(JSON.stringify(result, null, 2));
@@ -1 +1 @@
1
- {"version":3,"file":"scan.cjs","names":["ANSIColors"],"sources":["../../src/scan.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { formatSize, type ScanEvent, scanWebsite } from '@intlayer/engine/scan';\nimport type { ConfigurationOptions } from './cli';\n\n/** Options accepted by the {@link scan} command. */\nexport type ScanCommandOptions = {\n /** Disable the deeper puppeteer-based render scan. */\n deep?: boolean;\n /** Output the raw {@link ScanResult} as JSON instead of formatted text. */\n json?: boolean;\n configOptions?: ConfigurationOptions;\n};\n\n/** Human-readable labels for each scorable check type. */\nconst checkLabels: Record<string, string> = {\n robots_robotsPresent: 'robots.txt present',\n robots_noLocalizedUrlsForgotten: 'robots.txt keeps locale paths crawlable',\n sitemap_sitemapPresent: 'sitemap.xml present',\n sitemap_noLocalizedUrlsForgotten: 'sitemap lists every locale',\n sitemap_hasAlternates: 'sitemap has alternate links',\n sitemap_hasXDefault: 'sitemap has x-default',\n url_htmlLang: 'html lang attribute',\n url_htmlDir: 'html dir attribute',\n url_hasCanonical: 'canonical link',\n url_hreflang: 'hreflang tags',\n url_hasLocalizedLinks: 'localized internal links',\n url_hasXDefault: 'x-default hreflang',\n url_allAnchorsLocalized: 'all internal links localized',\n url_currentLocale: 'current locale detected',\n url_unusedBundleContent: 'unused bundle locale content',\n};\n\nconst statusIcon = (status: ScanEvent['status']): string => {\n if (status === 'success') return colorize('✓', ANSIColors.GREEN);\n if (status === 'warning') return colorize('⚠', ANSIColors.YELLOW);\n return colorize('✗', ANSIColors.RED);\n};\n\nconst scoreColor = (score: number) => {\n if (score >= 80) return ANSIColors.GREEN;\n if (score >= 50) return ANSIColors.YELLOW;\n return ANSIColors.RED;\n};\n\n/**\n * Scan a website for i18n/SEO health and bundle weight, printing a formatted\n * report (or JSON with `--json`).\n *\n * @example\n * ```sh\n * npx intlayer scan https://intlayer.org\n * ```\n */\nexport const scan = async (\n url: string,\n options: ScanCommandOptions = {}\n): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const result = await scanWebsite(url, { deep: options.deep });\n\n if (options.json) {\n appLogger(JSON.stringify(result, null, 2));\n return;\n }\n\n appLogger(\n `\\n🔍 Scanned ${colorize(result.url, ANSIColors.GREY_LIGHT)} ${colorize(\n `(${result.mode} mode)`,\n ANSIColors.GREY\n )}\\n`\n );\n\n appLogger(\n `Score: ${colorize(`${result.score}/100`, scoreColor(result.score))}`\n );\n appLogger(\n `Page size: ${colorize(formatSize(result.totalPageSize), ANSIColors.BLUE)} ${colorize(\n `(HTML ${formatSize(result.htmlSize)})`,\n ANSIColors.GREY\n )}`\n );\n if (result.locales.length > 0) {\n appLogger(\n `Locales: ${colorize(result.locales.join(', '), ANSIColors.GREEN)}`\n );\n }\n\n appLogger('\\nChecks:');\n for (const event of result.events) {\n const type = event.type.split('\\\\')[0];\n\n if (!type) continue;\n\n const label = checkLabels[type] ?? type;\n appLogger(` ${statusIcon(event.status)} ${label}`);\n }\n\n if (result.bundle && result.bundle.totalLocaleSize > 0) {\n const { bundle } = result;\n appLogger('\\nBundle locale weight:');\n appLogger(\n ` Translations shipped: ${colorize(formatSize(bundle.totalLocaleSize), ANSIColors.BLUE)}`\n );\n appLogger(\n ` Unused (other locales): ${colorize(\n `${formatSize(bundle.totalUnusedLocaleSize)} (${bundle.unusedPercentOfLocale}%)`,\n bundle.unusedPercentOfLocale > 30\n ? ANSIColors.RED\n : bundle.unusedPercentOfLocale > 0\n ? ANSIColors.YELLOW\n : ANSIColors.GREEN\n )}`\n );\n }\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,cAAsC;CAC1C,sBAAsB;CACtB,iCAAiC;CACjC,wBAAwB;CACxB,kCAAkC;CAClC,uBAAuB;CACvB,qBAAqB;CACrB,cAAc;CACd,aAAa;CACb,kBAAkB;CAClB,cAAc;CACd,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,mBAAmB;CACnB,yBAAyB;AAC3B;AAEA,MAAM,cAAc,WAAwC;CAC1D,IAAI,WAAW,WAAW,6CAAgB,KAAKA,wBAAW,KAAK;CAC/D,IAAI,WAAW,WAAW,6CAAgB,KAAKA,wBAAW,MAAM;CAChE,6CAAgB,KAAKA,wBAAW,GAAG;AACrC;AAEA,MAAM,cAAc,UAAkB;CACpC,IAAI,SAAS,IAAI,OAAOA,wBAAW;CACnC,IAAI,SAAS,IAAI,OAAOA,wBAAW;CACnC,OAAOA,wBAAW;AACpB;;;;;;;;;;AAWA,MAAa,OAAO,OAClB,KACA,UAA8B,CAAC,MACb;CAElB,MAAM,kGADiC,QAAQ,aACJ,CAAC;CAE5C,MAAM,SAAS,6CAAkB,KAAK,EAAE,MAAM,QAAQ,KAAK,CAAC;CAE5D,IAAI,QAAQ,MAAM;EAChB,UAAU,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;EACzC;CACF;CAEA,UACE,sDAAyB,OAAO,KAAKA,wBAAW,UAAU,EAAE,yCAC1D,IAAI,OAAO,KAAK,SAChBA,wBAAW,IACb,EAAE,GACJ;CAEA,UACE,gDAAmB,GAAG,OAAO,MAAM,OAAO,WAAW,OAAO,KAAK,CAAC,GACpE;CACA,UACE,0FAAkC,OAAO,aAAa,GAAGA,wBAAW,IAAI,EAAE,yCACxE,+CAAoB,OAAO,QAAQ,EAAE,IACrCA,wBAAW,IACb,GACF;CACA,IAAI,OAAO,QAAQ,SAAS,GAC1B,UACE,kDAAqB,OAAO,QAAQ,KAAK,IAAI,GAAGA,wBAAW,KAAK,GAClE;CAGF,UAAU,WAAW;CACrB,KAAK,MAAM,SAAS,OAAO,QAAQ;EACjC,MAAM,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC;EAEpC,IAAI,CAAC,MAAM;EAEX,MAAM,QAAQ,YAAY,SAAS;EACnC,UAAU,KAAK,WAAW,MAAM,MAAM,EAAE,GAAG,OAAO;CACpD;CAEA,IAAI,OAAO,UAAU,OAAO,OAAO,kBAAkB,GAAG;EACtD,MAAM,EAAE,WAAW;EACnB,UAAU,yBAAyB;EACnC,UACE,uGAA+C,OAAO,eAAe,GAAGA,wBAAW,IAAI,GACzF;EACA,UACE,mEACE,yCAAc,OAAO,qBAAqB,EAAE,IAAI,OAAO,sBAAsB,KAC7E,OAAO,wBAAwB,KAC3BA,wBAAW,MACX,OAAO,wBAAwB,IAC7BA,wBAAW,SACXA,wBAAW,KACnB,GACF;CACF;AACF"}
1
+ {"version":3,"file":"scan.cjs","names":["colorize","ANSIColors","getConfiguration","getAppLogger","scanWebsite","formatSize"],"sources":["../../src/scan.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { formatSize, type ScanEvent, scanWebsite } from '@intlayer/engine/scan';\nimport type { ConfigurationOptions } from './cli';\n\n/** Options accepted by the {@link scan} command. */\nexport type ScanCommandOptions = {\n /** Disable the deeper puppeteer-based render scan. */\n deep?: boolean;\n /** Output the raw {@link ScanResult} as JSON instead of formatted text. */\n json?: boolean;\n configOptions?: ConfigurationOptions;\n};\n\n/** Human-readable labels for each scorable check type. */\nconst checkLabels: Record<string, string> = {\n robots_robotsPresent: 'robots.txt present',\n robots_noLocalizedUrlsForgotten: 'robots.txt keeps locale paths crawlable',\n sitemap_sitemapPresent: 'sitemap.xml present',\n sitemap_noLocalizedUrlsForgotten: 'sitemap lists every locale',\n sitemap_hasAlternates: 'sitemap has alternate links',\n sitemap_hasXDefault: 'sitemap has x-default',\n url_htmlLang: 'html lang attribute',\n url_htmlDir: 'html dir attribute',\n url_hasCanonical: 'canonical link',\n url_hreflang: 'hreflang tags',\n url_hasLocalizedLinks: 'localized internal links',\n url_hasXDefault: 'x-default hreflang',\n url_allAnchorsLocalized: 'all internal links localized',\n url_currentLocale: 'current locale detected',\n url_unusedBundleContent: 'unused bundle locale content',\n};\n\nconst statusIcon = (status: ScanEvent['status']): string => {\n if (status === 'success') return colorize('✓', ANSIColors.GREEN);\n if (status === 'warning') return colorize('⚠', ANSIColors.YELLOW);\n return colorize('✗', ANSIColors.RED);\n};\n\nconst scoreColor = (score: number) => {\n if (score >= 80) return ANSIColors.GREEN;\n if (score >= 50) return ANSIColors.YELLOW;\n return ANSIColors.RED;\n};\n\n/**\n * Scan a website for i18n/SEO health and bundle weight, printing a formatted\n * report (or JSON with `--json`).\n *\n * @example\n * ```sh\n * npx intlayer scan https://intlayer.org\n * ```\n */\nexport const scan = async (\n url: string,\n options: ScanCommandOptions = {}\n): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const result = await scanWebsite(url, { deep: options.deep });\n\n if (options.json) {\n appLogger(JSON.stringify(result, null, 2));\n return;\n }\n\n appLogger(\n `\\n🔍 Scanned ${colorize(result.url, ANSIColors.GREY_LIGHT)} ${colorize(\n `(${result.mode} mode)`,\n ANSIColors.GREY\n )}\\n`\n );\n\n appLogger(\n `Score: ${colorize(`${result.score}/100`, scoreColor(result.score))}`\n );\n appLogger(\n `Page size: ${colorize(formatSize(result.totalPageSize), ANSIColors.BLUE)} ${colorize(\n `(HTML ${formatSize(result.htmlSize)})`,\n ANSIColors.GREY\n )}`\n );\n if (result.locales.length > 0) {\n appLogger(\n `Locales: ${colorize(result.locales.join(', '), ANSIColors.GREEN)}`\n );\n }\n\n appLogger('\\nChecks:');\n for (const event of result.events) {\n const type = event.type.split('\\\\')[0];\n\n if (!type) continue;\n\n const label = checkLabels[type] ?? type;\n appLogger(` ${statusIcon(event.status)} ${label}`);\n }\n\n if (result.bundle && result.bundle.totalLocaleSize > 0) {\n const { bundle } = result;\n appLogger('\\nBundle locale weight:');\n appLogger(\n ` Translations shipped: ${colorize(formatSize(bundle.totalLocaleSize), ANSIColors.BLUE)}`\n );\n appLogger(\n ` Unused (other locales): ${colorize(\n `${formatSize(bundle.totalUnusedLocaleSize)} (${bundle.unusedPercentOfLocale}%)`,\n bundle.unusedPercentOfLocale > 30\n ? ANSIColors.RED\n : bundle.unusedPercentOfLocale > 0\n ? ANSIColors.YELLOW\n : ANSIColors.GREEN\n )}`\n );\n }\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,cAAsC;CAC1C,sBAAsB;CACtB,iCAAiC;CACjC,wBAAwB;CACxB,kCAAkC;CAClC,uBAAuB;CACvB,qBAAqB;CACrB,cAAc;CACd,aAAa;CACb,kBAAkB;CAClB,cAAc;CACd,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,mBAAmB;CACnB,yBAAyB;AAC3B;AAEA,MAAM,cAAc,WAAwC;CAC1D,IAAI,WAAW,WAAW,WAAOA,kCAAS,KAAKC,wBAAW,KAAK;CAC/D,IAAI,WAAW,WAAW,WAAOD,kCAAS,KAAKC,wBAAW,MAAM;CAChE,WAAOD,kCAAS,KAAKC,wBAAW,GAAG;AACrC;AAEA,M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OAAO,eAAe,GAAGJ,wBAAW,IAAI,GACzF;EACA,UACE,iCAA6BD,kCAC3B,OAAGK,kCAAW,OAAO,qBAAqB,EAAE,IAAI,OAAO,sBAAsB,KAC7E,OAAO,wBAAwB,KAC3BJ,wBAAW,MACX,OAAO,wBAAwB,IAC7BA,wBAAW,SACXA,wBAAW,KACnB,GACF;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport {\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { logConfigDetails } from '@intlayer/engine/cli';\n\ninterface SearchDocOptions {\n query: string;\n limit?: number;\n configOptions?: GetConfigurationOptions;\n}\n\nexport const searchDoc = async ({\n query,\n limit = 10,\n configOptions,\n}: SearchDocOptions) => {\n const config = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(config);\n\n try {\n const { searchDoc } = getSearchAPI(undefined, config);\n const response = await searchDoc({\n input: query,\n limit: limit.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n appLogger('No relevant chunks found.');\n return;\n }\n\n const chunks = response.data;\n\n appLogger(`Found ${colorizeNumber(chunks.length)} relevant chunks:`);\n\n chunks.forEach((chunk: any) => {\n appLogger('---');\n appLogger(`${colorizeKey('File')}: ${chunk.fileKey}`);\n appLogger(`${colorizeKey('Title')}: ${chunk.docName}`);\n appLogger(`${colorizeKey('URL')}: ${chunk.docUrl}`);\n appLogger(`${colorizeKey('Chunk')}: ${chunk.chunkNumber}`);\n appLogger(`${colorizeKey('Content')}:`);\n appLogger(chunk.content);\n });\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n appLogger(`Search failed: ${errorMessage}`, { level: 'error' });\n }\n};\n"],"mappings":";;;;;;;AAkBA,MAAa,YAAY,OAAO,EAC9B,OACA,QAAQ,IACR,oBACsB;CACtB,MAAM,qDAA0B,aAAa;CAC7C,2CAAiB,aAAa;CAE9B,MAAM,sDAAyB,MAAM;CAErC,IAAI;EACF,MAAM,EAAE,8CAA2B,QAAW,MAAM;EACpD,MAAM,WAAW,MAAM,UAAU;GAC/B,OAAO;GACP,OAAO,MAAM,SAAS;GACtB,eAAe;EACjB,CAAC;EAED,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,QAAQ,SAAS,IAAI,GAAG;GACnD,UAAU,2BAA2B;GACrC;EACF;EAEA,MAAM,SAAS,SAAS;EAExB,UAAU,qDAAwB,OAAO,MAAM,EAAE,kBAAkB;EAEnE,OAAO,SAAS,UAAe;GAC7B,UAAU,KAAK;GACf,UAAU,4CAAe,MAAM,EAAE,IAAI,MAAM,SAAS;GACpD,UAAU,4CAAe,OAAO,EAAE,IAAI,MAAM,SAAS;GACrD,UAAU,4CAAe,KAAK,EAAE,IAAI,MAAM,QAAQ;GAClD,UAAU,4CAAe,OAAO,EAAE,IAAI,MAAM,aAAa;GACzD,UAAU,4CAAe,SAAS,EAAE,EAAE;GACtC,UAAU,MAAM,OAAO;EACzB,CAAC;CACH,SAAS,OAAO;EAGd,UAAU,kBADR,iBAAiB,QAAQ,MAAM,UAAU,+BACC,EAAE,OAAO,QAAQ,CAAC;CAChE;AACF"}
1
+ {"version":3,"file":"searchDoc.cjs","names":["getConfiguration","getAppLogger","getSearchAPI","colorizeNumber","colorizeKey"],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport {\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { logConfigDetails } from '@intlayer/engine/cli';\n\ninterface SearchDocOptions {\n query: string;\n limit?: number;\n configOptions?: GetConfigurationOptions;\n}\n\nexport const searchDoc = async ({\n query,\n limit = 10,\n configOptions,\n}: SearchDocOptions) => {\n const config = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(config);\n\n try {\n const { searchDoc } = getSearchAPI(undefined, config);\n const response = await searchDoc({\n input: query,\n limit: limit.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n appLogger('No relevant chunks found.');\n return;\n }\n\n const chunks = response.data;\n\n appLogger(`Found ${colorizeNumber(chunks.length)} relevant chunks:`);\n\n chunks.forEach((chunk: any) => {\n appLogger('---');\n appLogger(`${colorizeKey('File')}: ${chunk.fileKey}`);\n appLogger(`${colorizeKey('Title')}: ${chunk.docName}`);\n appLogger(`${colorizeKey('URL')}: ${chunk.docUrl}`);\n appLogger(`${colorizeKey('Chunk')}: ${chunk.chunkNumber}`);\n appLogger(`${colorizeKey('Content')}:`);\n appLogger(chunk.content);\n });\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n appLogger(`Search failed: ${errorMessage}`, { level: 'error' });\n }\n};\n"],"mappings":";;;;;;;AAkBA,MAAa,YAAY,OAAO,EAC9B,OACA,QAAQ,IACR,oBACsB;CACtB,MAAM,aAASA,wCAAiB,aAAa;CAC7C,2CAAiB,aAAa;CAE9B,MAAM,gBAAYC,sCAAa,MAAM;CAErC,IAAI;EACF,MAAM,EAAE,kBAAcC,4BAAa,QAAW,MAAM;EACpD,MAAM,WAAW,MAAM,UAAU;GAC/B,OAAO;GACP,OAAO,MAAM,SAAS;GACtB,eAAe;EACjB,CAAC;EAED,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,QAAQ,SAAS,IAAI,GAAG;GACnD,UAAU,2BAA2B;GACrC;EACF;EAEA,MAAM,SAAS,SAAS;EAExB,UAAU,aAASC,wCAAe,OAAO,MAAM,EAAE,kBAAkB;EAEnE,OAAO,SAAS,UAAe;GAC7B,UAAU,KAAK;GACf,UAAU,OAAGC,qCAAY,MAAM,EAAE,IAAI,MAAM,SAAS;GACpD,UAAU,OAAGA,qCAAY,OAAO,EAAE,IAAI,MAAM,SAAS;GACrD,UAAU,OAAGA,qCAAY,KAAK,EAAE,IAAI,MAAM,QAAQ;GAClD,UAAU,OAAGA,qCAAY,OAAO,EAAE,IAAI,MAAM,aAAa;GACzD,UAAU,OAAGA,qCAAY,SAAS,EAAE,EAAE;GACtC,UAAU,MAAM,OAAO;EACzB,CAAC;CACH,SAAS,OAAO;EAGd,UAAU,kBADR,iBAAiB,QAAQ,MAAM,UAAU,+BACC,EAAE,OAAO,QAAQ,CAAC;CAChE;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey] ?? [];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n // If there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\n }\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap(\n (missingTranslation) => missingTranslation.locales\n )\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAA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CAAE;AACvE;AAEA,MAAa,2BACX,yBACG;CACH,MAAM,4DAAiC,oBAAoB;CAC3D,2CAAiB,oBAAoB;CAErC,OAAO,kCAAkC,aAAa;AACxD"}
1
+ {"version":3,"file":"listMissingTranslations.cjs","names":["getUnmergedDictionaries","getDictionaries","getMissingLocalesContentFromDictionary","getConfiguration"],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey] ?? [];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n // If there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\n }\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap(\n (missingTranslation) => missingTranslation.locales\n )\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAAM,iCAA6BA,+DAAwB,aAAa;CACxE,MAAM,yBAAqBC,8CAAgB,aAAa;CAExD,MAAM,sBAKA,CAAC;CAEP,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,MAAM,mCAAmB,IAAI,IAAI,CAC/B,GAAG,OAAO,KAAK,0BAA0B,GACzC,GAAG,OA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file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { listMissingTranslations } from './listMissingTranslations';\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n\n if (result.missingRequiredLocales.length > 0) {\n process.exit(1);\n }\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,qDAA0B,SAAS,aAAa;CACtD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,sDAAyB,MAAM;CAErC,IAAI,SAAS,UAAU,MACrB,kDAAsB,QAAQ,EAAE,UAAU,KAAK,CAAC;MAC3C,IAAI,OAAO,SAAS,UAAU,aACnC,kDAAsB,MAAM;CAG9B,MAAM,SAASA,6DAAwB,SAAS,aAAa;CAE7D,MAAM,gBAAgB,OAAO,oBAC1B,KAAK,MAAM,MAAM,EAAE,KAAK,CAAC,CACzB,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;CAChD,MAAM,oBAAoB,OAAO,oBAC9B,KAAK,+CAAmB,EAAE,SAAS,KAAK,CAAC,CAAC,CAC1C,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;CAEhD,MAAM,+BAA+B,OAAO,oBAAoB,KAC7D,gBACC;qCACQ,+CAAkB,YAAY,GAAG,KAAK;GAC1C,SAAS;GACT,SAAS;EACX,CAAC;EACD;8EACmB,YAAY,SAASC,wBAAW,GAAG,GAAG;GACvD,SAAS;GACT,SAAS;EACX,CAAC;EAED,YAAY,WAAW,6CAAiB,YAAY,QAAQ,MAAM;EAClE,YAAY,KAAK,cAAc;CACjC,CAAC,CAAC,KAAK,EAAE,CACb;CAEA,UAAU,yBAAyB,EACjC,OAAO,OACT,CAAC;CAED,6BAA6B,SAAS,MAAM;EAC1C,UAAU,GAAG,EACX,OAAO,OACT,CAAC;CACH,CAAC;CAED,UAAU,qDAAyB,OAAO,GAAG;CAC7C,UAAU,8DAAkC,mBAAmB,OAAO,GAAG;CACzE,UACE,oBAAoB,OAAO,eAAe,WAAW,0CAAa,KAAKA,wBAAW,KAAK,6CAAiB,OAAO,gBAAgBA,wBAAW,GAAG,GAC/I;CAEA,UACE,6BAA6B,OAAO,uBAAuB,WAAW,0CAAa,KAAKA,wBAAW,KAAK,6CAAiB,OAAO,wBAAwBA,wBAAW,GAAG,GACxK;CACA,UACE,sEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CAAC,GACH;CACA,UACE,+EACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CACF,GACF;CAEA,IAAI,OAAO,uBAAuB,SAAS,GACzC,QAAQ,KAAK,CAAC;AAElB"}
1
+ {"version":3,"file":"test.cjs","names":["getConfiguration","getAppLogger","prepareIntlayer","listMissingTranslations","formatLocale","colon","colorizeKey","ANSIColors","formatPath","colorize","colorizeNumber"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { listMissingTranslations } from './listMissingTranslations';\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n\n if (result.missingRequiredLocales.length > 0) {\n process.exit(1);\n }\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,aAASA,wCAAiB,SAAS,aAAa;CACtD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,gBAAYC,sCAAa,MAAM;CAErC,IAAI,SAAS,UAAU,MACrB,UAAMC,wCAAgB,QAAQ,EAAE,UAAU,KAAK,CAAC;MAC3C,IAAI,OAAO,SAAS,UAAU,aACnC,UAAMA,wCAAgB,MAAM;CAG9B,MAAM,SAASC,6DAAwB,SAAS,aAAa;CAE7D,MAAM,gBAAgB,OAAO,oBAC1B,KAAK,MAAM,MAAM,EAAE,KAAK,CAAC,CACzB,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;CAChD,MAAM,oBAAoB,OAAO,oBAC9B,KAAK,UAAMC,qCAAa,EAAE,SAAS,KAAK,CAAC,CAAC,CAC1C,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;CAEhD,MAAM,+BAA+B,OAAO,oBAAoB,KAC7D,gBACC;MACEC,+BAAM,UAAMC,qCAAY,YAAY,GAAG,KAAK;GAC1C,SAAS;GACT,SAAS;EACX,CAAC;EACD;MACAD,mCAAMD,qCAAa,YAAY,SAASG,wBAAW,GAAG,GAAG;GACvD,SAAS;GACT,SAAS;EACX,CAAC;EAED,YAAY,WAAW,UAAMC,mCAAW,YAAY,QAAQ,MAAM;EAClE,YAAY,KAAK,cAAc;CACjC,CAAC,CAAC,KAAK,EAAE,CACb;CAEA,UAAU,yBAAyB,EACjC,OAAO,OACT,CAAC;CAED,6BAA6B,SAAS,MAAM;EAC1C,UAAU,GAAG,EACX,OAAO,OACT,CAAC;CACH,CAAC;CAED,UAAU,gBAAYJ,qCAAa,OAAO,GAAG;CAC7C,UAAU,yBAAqBA,qCAAa,mBAAmB,OAAO,GAAG;CACzE,UACE,oBAAoB,OAAO,eAAe,WAAW,QAAIK,kCAAS,KAAKF,wBAAW,KAAK,QAAIH,qCAAa,OAAO,gBAAgBG,wBAAW,GAAG,GAC/I;CAEA,UACE,6BAA6B,OAAO,uBAAuB,WAAW,QAAIE,kCAAS,KAAKF,wBAAW,KAAK,QAAIH,qCAAa,OAAO,wBAAwBG,wBAAW,GAAG,GACxK;CACA,UACE,8BAA0BG,wCAAe,OAAO,eAAe,QAAQ;EACrE,KAAKH,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CAAC,GACH;CACA,UACE,uCAAmCG,wCACjC,OAAO,uBAAuB,QAC9B;EACE,KAAKH,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CACF,GACF;CAEA,IAAI,OAAO,uBAAuB,SAAS,GACzC,QAAQ,KAAK,CAAC;AAElB"}
@@ -45,7 +45,7 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
45
45
  maxErrors: 5,
46
46
  shouldStop: false
47
47
  };
48
- await (0, _intlayer_engine_utils.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
48
+ const allTasks = docList.flatMap((docPath) => locales.map((locale) => async () => {
49
49
  if (errorState.shouldStop) return;
50
50
  const absoluteBaseFilePath = (0, node_path.join)(configuration.system.baseDir, docPath);
51
51
  const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
@@ -76,7 +76,8 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
76
76
  flushStrategy,
77
77
  limit: globalChunkLimiter
78
78
  });
79
- })), (task) => task(), 50);
79
+ }));
80
+ await (0, _intlayer_engine_utils.parallelize)(allTasks, (task) => task(), 50);
80
81
  const batchDuration = ((node_perf_hooks.performance.now() - batchStartTime) / 1e3).toFixed(2);
81
82
  if (errorState.count > 0) appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);
82
83
  else appLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} Batch completed successfully in ${(0, _intlayer_config_logger.colorizeNumber)(batchDuration)}s.`);
@@ -1 +1 @@
1
- {"version":3,"file":"translateDoc.cjs","names":["setupAI","x","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { listGitFiles, logConfigDetails } from '@intlayer/engine/cli';\nimport { parallelize, pLimit } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,4DAAiC,aAAa;CACpD,2CAAiB,aAAa;CAE9B,MAAM,sDAAyB,aAAa;CAK5C,MAAM,sBAAsB;CAC5B,MAAM,wDAA4B,mBAAmB;CAErD,IAAI,UAAoB,6BAAS,YAAY,EAC3C,QAAQ,oBACV,CAAC;CAED,MAAM,WAAW,MAAMA,8BAAQ,eAAe,SAAS;CACvD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,QAAQ;EACvE,IAAI,CAAC,aAAa;GAChB,UAAU,GAAGC,0BAAE,GAAG,OAAO;GACzB;EACF;CACF;CAEA,IAAI,YAAY;EACd,MAAM,kBAAkB,6CAAmB,UAAU;EACrD,IAAI,iBACF,UAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gCAAiB,QAAQ,IAAI,GAAG,IAAI,MAAM,OAAO,CACzE;CAEJ;CAEA,MAAM,iBAAiBC,4BAAY,IAAI;CAEvC,UACE,2DAA8B,QAAQ,MAAM,EAAE,wDAA2B,QAAQ,MAAM,EAAE,8EACjD,mBAAmB,EAAE,qBAC/D;CAEA,MAAM,aAAyB;EAC7B,OAAO;EACP,WAAW;EACX,YAAY;CACd;CAyDA,8CArDiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;EAClC,IAAI,WAAW,YAAY;EAE3B,MAAM,2CAA4B,cAAc,OAAO,SAAS,OAAO;EACvE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,UACF;EAGA,IAAI,wCAA2B,cAAc,GAAG;EAEhD,IAAI,kBAAkB,iBAAiB,yBAAY,cAAc,GAAG;GAClE,8CAAkB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACtD,2BAAc,gBAAgB,EAAE;EAClC;EAEA,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;EACF,CAAC;EAED,IAAI,qBAAqB,WAAW;GAClC,UAAU,qBAAqB,OAAO;GACtC;EACF;EAGA,MAAMC,iDAAc;GAClB,cAAc;GACd;GACQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;EACT,CAAC;CACH,CAAC,CASsB,IAAI,SAAS,KAAK,GAAG,EAAe;CAG7D,MAAM,kBADeH,4BAAY,IACE,IAAI,kBAAkB,IAAI,CAAE,QAAQ,CAAC;CAExE,IAAI,WAAW,QAAQ,GACrB,UAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,GAAG;MAE1E,UACE,yCAAY,KAAKI,wBAAW,KAAK,EAAE,+EAAkD,aAAa,EAAE,GACtG;AAEJ"}
1
+ {"version":3,"file":"translateDoc.cjs","names":["getConfiguration","getAppLogger","pLimit","fg","setupAI","x","listGitFiles","join","performance","colorizeNumber","getOutputFilePath","existsSync","dirname","checkFileModifiedRange","translateFile","parallelize","colorize","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { listGitFiles, logConfigDetails } from '@intlayer/engine/cli';\nimport { parallelize, pLimit } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,oBAAgBA,wCAAiB,aAAa;CACpD,2CAAiB,aAAa;CAE9B,MAAM,gBAAYC,sCAAa,aAAa;CAK5C,MAAM,sBAAsB;CAC5B,MAAM,yBAAqBC,+BAAO,mBAAmB;CAErD,IAAI,UAAoB,UAAMC,mBAAG,YAAY,EAC3C,QAAQ,oBACV,CAAC;CAED,MAAM,WAAW,MAAMC,8BAAQ,eAAe,SAAS;CACvD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,QAAQ;EACvE,IAAI,CAAC,aAAa;GAChB,UAAU,GAAGC,0BAAE,GAAG,OAAO;GACzB;EACF;CACF;CAEA,IAAI,YAAY;EACd,MAAM,kBAAkB,UAAMC,mCAAa,UAAU;EACrD,IAAI,iBACF,UAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gBAAYC,gBAAK,QAAQ,IAAI,GAAG,IAAI,MAAM,OAAO,CACzE;CAEJ;CAEA,MAAM,iBAAiBC,4BAAY,IAAI;CAEvC,UACE,mBAAeC,wCAAe,QAAQ,MAAM,EAAE,gBAAYA,wCAAe,QAAQ,MAAM,EAAE,sCAChEA,wCAAe,mBAAmB,EAAE,qBAC/D;CAEA,MAAM,aAAyB;EAC7B,OAAO;EACP,WAAW;EACX,YAAY;CACd;CAIA,MAAM,WAAW,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;EAClC,IAAI,WAAW,YAAY;EAE3B,MAAM,2BAAuBF,gBAAK,cAAc,OAAO,SAAS,OAAO;EACvE,MAAM,iBAAiBG,kDACrB,sBACA,QACA,UACF;EAGA,IAAI,oBAAgBC,oBAAW,cAAc,GAAG;EAEhD,IAAI,kBAAkB,iBAAiB,KAACA,oBAAW,cAAc,GAAG;GAClE,2BAAUC,mBAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACtD,2BAAc,gBAAgB,EAAE;EAClC;EAEA,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;EACF,CAAC;EAED,IAAI,qBAAqB,WAAW;GAClC,UAAU,qBAAqB,OAAO;GACtC;EACF;EAGA,MAAMC,iDAAc;GAClB,cAAc;GACd;GACQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;EACT,CAAC;CACH,CAAC,CACH;CAQA,UAAMC,oCAAY,WAAW,SAAS,KAAK,GAAG,EAAe;CAG7D,MAAM,kBADeP,4BAAY,IACE,IAAI,kBAAkB,IAAI,CAAE,QAAQ,CAAC;CAExE,IAAI,WAAW,QAAQ,GACrB,UAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,GAAG;MAE1E,UACE,OAAGQ,kCAAS,KAAKC,wBAAW,KAAK,EAAE,uCAAmCR,wCAAe,aAAa,EAAE,GACtG;AAEJ"}
@@ -20,10 +20,13 @@ const translateFile = async ({ baseFilePath, outputFilePath, locale, baseLocale,
20
20
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration, { config: { prefix: "" } });
21
21
  const fileStartTime = node_perf_hooks.performance.now();
22
22
  try {
23
- const chunks = require_utils_calculateChunks.chunkText(await (0, node_fs_promises.readFile)(baseFilePath, "utf-8"));
23
+ const fileContent = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
24
+ const chunks = require_utils_calculateChunks.chunkText(fileContent);
24
25
  const totalChunks = chunks.length;
25
- const filePrefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
26
- const prefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}][${(0, _intlayer_engine_utils.formatLocale)(locale)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
26
+ const filePrefixText = `${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}] `;
27
+ const filePrefix = `${(0, _intlayer_config_logger.colon)(filePrefixText, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
28
+ const prefixText = `${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}][${(0, _intlayer_engine_utils.formatLocale)(locale)}${_intlayer_config_colors.GREY_DARK}] `;
29
+ const prefix = `${(0, _intlayer_config_logger.colon)(prefixText, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
27
30
  appLogger(`${filePrefix}Split into ${(0, _intlayer_config_logger.colorizeNumber)(totalChunks)} chunks. Queuing...`);
28
31
  const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_engine_utils.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_engine_utils.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
29
32
  const translatedParts = new Array(totalChunks).fill("");
@@ -1 +1 @@
1
- {"version":3,"file":"translateFile.cjs","names":["performance","chunkText","ANSIColors","readAsset","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA,gBAAgB,eAChB,gBACA,YACkD;CAClD,IAAI,WAAW,YAAY,OAAO;CAElC,MAAM,sDAAyB,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,EAAE,CAAC;CACxE,MAAM,gBAAgBA,4BAAY,IAAI;CAEtC,IAAI;EAEF,MAAM,SAASC,wCAAU,qCADU,cAAc,OAAO,CACpB;EACpC,MAAM,cAAc,OAAO;EAG3B,MAAM,aAAa,sCAAS,GADFC,wBAAW,UAAU,0CAAc,YAAY,IAAIA,wBAAW,UAAU,KACtD,EAAE,SAAS,GAAG,CAAC,IAAIA,wBAAW;EAE1E,MAAM,SAAS,sCAAS,GADFA,wBAAW,UAAU,0CAAc,YAAY,IAAIA,wBAAW,UAAU,6CAAiB,MAAM,IAAIA,wBAAW,UAAU,KAC1G,EAAE,SAAS,GAAG,CAAC,IAAIA,wBAAW;EAElE,UACE,GAAG,WAAW,yDAA4B,WAAW,EAAE,oBACzD;EAEA,MAAM,aAAaC,+BAAU,iCAAiC,OAAO,CAAC,CACnE,WAAW,kBAAkB,4CAAgB,QAAQ,KAAK,GAAG,CAAC,CAC9D,WAAW,sBAAsB,4CAAgB,YAAY,KAAK,GAAG,CAAC,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB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AK,UAAU,KAAK;EAC3D,UAAU,yCAAY,KAAKA,wBAAW,GAAG,EAAE,UAAU,cAAc;EACnE,IAAI,WAAW,SAAS,WAAW,WAAW,WAAW,aAAa;EACtE,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"translateFile.cjs","names":["getAppLogger","performance","readFile","chunkText","ANSIColors","formatPath","colon","formatLocale","colorizeNumber","readAsset","retryManager","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation","mkdir","dirname","writeFile","relative","colorize"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA,gBAAgB,eAChB,gBACA,YACkD;CAClD,IAAI,WAAW,YAAY,OAAO;CAElC,MAAM,gBAAYA,sCAAa,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,EAAE,CAAC;CACxE,MAAM,gBAAgBC,4BAAY,IAAI;CAEtC,IAAI;EACF,MAAM,cAAc,UAAMC,2BAAS,cAAc,OAAO;EACxD,MAAM,SAASC,wCAAU,WAAW;EACpC,MAAM,cAAc,OAAO;EAE3B,MAAM,iBAAiB,GAAGC,wBAAW,UAAU,OAAGC,mCAAW,YAAY,IAAID,wBAAW,UAAU;EAClG,MAAM,aAAa,OAAGE,+BAAM,gBAAgB,EAAE,SAAS,GAAG,CAAC,IAAIF,wBAAW;EAC1E,MAAM,aAAa,GAA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,CACH;EAGA,MAAM,QAAQ,IAAI,KAAK;EAGvB,MAAM,cAAc,gBAAgB,KAAK,EAAE;EAC3C,IAAI,kBAAkB,SAAS,kBAAkB,eAAe;GAC9D,UAAMW,4BAAMC,mBAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACxD,UAAMC,4BAAU,gBAAgB,WAAW;EAC7C;EAGA,MAAM,kBADchB,4BAAY,IACE,IAAI,iBAAiB,IAAI,CAAE,QAAQ,CAAC;EACtE,MAAM,mBAAeiB,oBAAS,cAAc,OAAO,SAAS,cAAc;EAE1E,UACE,OAAGC,kCAAS,KAAKf,wBAAW,KAAK,EAAE,YAAQC,mCAAW,YAAY,EAAE,oBAAgBG,wCAAe,aAAa,EAAE,GACpH;EAEA,OAAO;CACT,SAAS,OAAY;EACnB,WAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,UAAU,KAAK;EAC3D,UAAU,OAAGW,kCAAS,KAAKf,wBAAW,GAAG,EAAE,UAAU,cAAc;EACnE,IAAI,WAAW,SAAS,WAAW,WAAW,WAAW,aAAa;EACtE,OAAO;CACT;AACF"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/translateDoc/validation.ts
4
3
  /**
5
4
  * Validates that the translated content matches the structure of the original.
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","names":[],"sources":["../../../src/translateDoc/validation.ts"],"sourcesContent":["import type { Logger } from '@intlayer/config/logger';\n\n/**\n * Validates that the translated content matches the structure of the original.\n * Throws an error if a mismatch is found, triggering a retry.\n */\nexport const validateTranslation = (\n original: string,\n translated: string,\n logger: Logger\n): boolean => {\n const errors: string[] = [];\n\n // YAML Frontmatter Integrity (CRITICAL)\n if (original.trimStart().startsWith('---')) {\n if (!translated.trimStart().startsWith('---')) {\n errors.push(\n 'YAML Frontmatter missing: Input starts with \"---\", output does not.'\n );\n }\n const originalDashes = (original.match(/^---$/gm) || []).length;\n const translatedDashes = (translated.match(/^---$/gm) || []).length;\n if (originalDashes >= 2 && translatedDashes < 2) {\n errors.push(\n 'YAML Frontmatter unclosed: Input has closing \"---\", output is missing it.'\n );\n }\n }\n\n // Code Fence Check\n const fenceRegex = /^\\s*```/gm;\n const originalFences = (original.match(fenceRegex) || []).length;\n const translatedFences = (translated.match(fenceRegex) || []).length;\n\n if (originalFences !== translatedFences) {\n errors.push(\n `Code fence mismatch: Input has ${originalFences}, output has ${translatedFences}`\n );\n }\n\n // Length/Duplication Check\n const ratio = translated.length / (original.length || 1);\n const isTooLong = ratio > 2.5;\n const isSignificantLength = original.length > 50;\n\n if (isTooLong && isSignificantLength) {\n errors.push(\n `Length deviation: Output is ${translated.length} chars vs Input ${original.length} (${ratio.toFixed(1)}x). Likely included context.`\n );\n }\n\n // Line Count Heuristic\n const originalLines = original.split('\\n').length;\n const translatedLines = translated.split('\\n').length;\n\n if (originalLines > 5) {\n if (translatedLines < originalLines * 0.4) {\n errors.push(\n `Line count deviation: Output has ${translatedLines} lines, Input has ${originalLines}. Likely content deletion.`\n );\n }\n }\n\n if (errors.length > 0) {\n logger(`Validation Failed: ${errors.join(', ')}`);\n return false;\n }\n\n return true;\n};\n\n/**\n * Clean common AI artifacts\n */\nexport const sanitizeChunk = (translated: string, original: string): string => {\n let cleaned = translated;\n const wrapRegex = /^```(?:markdown|md|txt)?\\n([\\s\\S]*?)\\n```$/i;\n const match = cleaned.match(wrapRegex);\n if (match) cleaned = match[1];\n\n if (!original.startsWith('\\n') && cleaned.startsWith('\\n')) {\n cleaned = cleaned.replace(/^\\n+/, '');\n }\n if (!original.startsWith(' ') && cleaned.startsWith(' ')) {\n cleaned = cleaned.trimStart();\n }\n return cleaned;\n};\n"],"mappings":";;;;;;;AAMA,MAAa,uBACX,UACA,YACA,WACY;CACZ,MAAM,SAAmB,CAAC;CAG1B,IAAI,SAAS,UAAU,CAAC,CAAC,WAAW,KAAK,GAAG;EAC1C,IAAI,CAAC,WAAW,UAAU,C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I,CAAC,SAAS,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GACrD,UAAU,QAAQ,UAAU;CAE9B,OAAO;AACT"}
1
+ {"version":3,"file":"validation.cjs","names":[],"sources":["../../../src/translateDoc/validation.ts"],"sourcesContent":["import type { Logger } from '@intlayer/config/logger';\n\n/**\n * Validates that the translated content matches the structure of the original.\n * Throws an error if a mismatch is found, triggering a retry.\n */\nexport const validateTranslation = (\n original: string,\n translated: string,\n logger: Logger\n): boolean => {\n const errors: string[] = [];\n\n // YAML Frontmatter Integrity (CRITICAL)\n if (original.trimStart().startsWith('---')) {\n if (!translated.trimStart().startsWith('---')) {\n errors.push(\n 'YAML Frontmatter missing: Input starts with \"---\", output does not.'\n );\n }\n const originalDashes = (original.match(/^---$/gm) || []).length;\n const translatedDashes = (translated.match(/^---$/gm) || []).length;\n if (originalDashes >= 2 && translatedDashes < 2) {\n errors.push(\n 'YAML Frontmatter unclosed: Input has closing \"---\", output is missing it.'\n );\n }\n }\n\n // Code Fence Check\n const fenceRegex = /^\\s*```/gm;\n const originalFences = (original.match(fenceRegex) || []).length;\n const translatedFences = (translated.match(fenceRegex) || []).length;\n\n if (originalFences !== translatedFences) {\n errors.push(\n `Code fence mismatch: Input has ${originalFences}, output has ${translatedFences}`\n );\n }\n\n // Length/Duplication Check\n const ratio = translated.length / (original.length || 1);\n const isTooLong = ratio > 2.5;\n const isSignificantLength = original.length > 50;\n\n if (isTooLong && isSignificantLength) {\n errors.push(\n `Length deviation: Output is ${translated.length} chars vs Input ${original.length} (${ratio.toFixed(1)}x). Likely included context.`\n );\n }\n\n // Line Count Heuristic\n const originalLines = original.split('\\n').length;\n const translatedLines = translated.split('\\n').length;\n\n if (originalLines > 5) {\n if (translatedLines < originalLines * 0.4) {\n errors.push(\n `Line count deviation: Output has ${translatedLines} lines, Input has ${originalLines}. Likely content deletion.`\n );\n }\n }\n\n if (errors.length > 0) {\n logger(`Validation Failed: ${errors.join(', ')}`);\n return false;\n }\n\n return true;\n};\n\n/**\n * Clean common AI artifacts\n */\nexport const sanitizeChunk = (translated: string, original: string): string => {\n let cleaned = translated;\n const wrapRegex = /^```(?:markdown|md|txt)?\\n([\\s\\S]*?)\\n```$/i;\n const match = cleaned.match(wrapRegex);\n if (match) cleaned = match[1];\n\n if (!original.startsWith('\\n') && cleaned.startsWith('\\n')) {\n cleaned = cleaned.replace(/^\\n+/, '');\n }\n if (!original.startsWith(' ') && cleaned.startsWith(' ')) {\n cleaned = cleaned.trimStart();\n }\n return cleaned;\n};\n"],"mappings":";;;;;;AAMA,MAAa,uBACX,UACA,YACA,WACY;CACZ,MAAM,SAAmB,CAAC;CAG1B,IAAI,SAAS,UAAU,CAAC,CAAC,WAAW,KAAK,GAAG;EAC1C,IAAI,CAAC,WAAW,UAAU,CAAC,CAAC,WAAW,KAAK,GAC1C,OAAO,KACL,uEACF;EAEF,MAAM,kBAAkB,SAAS,MAAM,SAAS,KAAK,CAAC,EAAC,CAAE;EACzD,MAAM,oBAAoB,WAAW,MAAM,SAAS,KAAK,CAAC,EAAC,CAAE;EAC7D,IAAI,kBAAkB,KAAK,mBAAmB,GAC5C,OAAO,KACL,6EACF;CAEJ;CAGA,MAAM,aAAa;CACnB,MAAM,kBAAkB,SAAS,MAAM,UAAU,KAAK,CAAC,EAAC,CAAE;CAC1D,MAAM,oBAAoB,WAAW,MAAM,UAAU,KAAK,CAAC,EAAC,CAAE;CAE9D,IAAI,mBAAmB,kBACrB,OAAO,KACL,kCAAkC,eAAe,eAAe,kBAClE;CAIF,MAAM,QAAQ,WAAW,UAAU,SAAS,UAAU;CACtD,MAAM,YAAY,QAAQ;CAC1B,MAAM,sBAAsB,SAAS,SAAS;CAE9C,IAAI,aAAa,qBACf,OAAO,KACL,+BAA+B,WAAW,OAAO,kBAAkB,SAAS,OAAO,IAAI,MAAM,QAAQ,CAAC,EAAE,6BAC1G;CAIF,MAAM,gBAAgB,SAAS,MAAM,IAAI,CAAC,CAAC;CAC3C,MAAM,kBAAkB,WAAW,MAAM,IAAI,CAAC,CAAC;CAE/C,IAAI,gBAAgB,GAClB;MAAI,kBAAkB,gBAAgB,IACpC,OAAO,KACL,oCAAoC,gBAAgB,oBAAoB,cAAc,2BACxF;CACF;CAGF,IAAI,OAAO,SAAS,GAAG;EACrB,OAAO,sBAAsB,OAAO,KAAK,IAAI,GAAG;EAChD,OAAO;CACT;CAEA,OAAO;AACT;;;;AAKA,MAAa,iBAAiB,YAAoB,aAA6B;CAC7E,IAAI,UAAU;CAEd,MAAM,QAAQ,QAAQ,MAAM,6CAAS;CACrC,IAAI,OAAO,UAAU,MAAM;CAE3B,IAAI,CAAC,SAAS,WAAW,IAAI,KAAK,QAAQ,WAAW,IAAI,GACvD,UAAU,QAAQ,QAAQ,QAAQ,EAAE;CAEtC,IAAI,CAAC,SAAS,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GACrD,UAAU,QAAQ,UAAU;CAE9B,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"calculateChunks.cjs","names":[],"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/engine/utils';\n\nexport type ChunkLineResult = {\n lineStart: number;\n lineLength: number;\n charStart: number;\n charLength: number;\n content: string;\n};\n\nconst DEFAULT_MAX_CHARS_PER_CHUNK = 800;\nconst DEFAULT_OVERLAP_CHARS = 0;\n\nexport const chunkText = (\n text: string,\n maxCharsPerChunk: number = DEFAULT_MAX_CHARS_PER_CHUNK,\n overlapChars: number = DEFAULT_OVERLAP_CHARS\n): ChunkLineResult[] => {\n if (maxCharsPerChunk <= 0) {\n throw new Error('maxCharsPerChunk must be greater than 0');\n }\n\n const splittedText = splitTextByLines(text);\n\n // Split text into lines to facilitate the translation\n const lines: ChunkLineResult[] = [];\n let charStartAcc = 0;\n\n splittedText.forEach((line, index) => {\n lines.push({\n content: line,\n lineStart: index,\n lineLength: 1,\n charStart: charStartAcc,\n charLength: line.length,\n });\n charStartAcc += line.length;\n });\n\n // Group lines\n // as long as the chunk length is less than maxCharsPerChunk\n // if a line longer than maxCharsPerChunk, keep it alone\n // if a line is not longer than maxCharsPerChunk, it is grouped\n const groupedLines: ChunkLineResult[] = lines.reduce(\n (acc: ChunkLineResult[], line) => {\n // If this line alone exceeds maxCharsPerChunk, keep it separate\n if (line.content.length > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // If we have no chunks yet, start with this line\n if (acc.length === 0) {\n acc.push(line);\n return acc;\n }\n\n // Get the last chunk\n const lastChunk = acc[acc.length - 1];\n\n // Calculate what the combined length would be (including newline character)\n const combinedLength = lastChunk.content.length + line.content.length;\n\n // If combining would exceed the limit, start a new chunk\n if (combinedLength > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // Otherwise, combine with the last chunk\n const combinedContent = lastChunk.content + line.content;\n const updatedChunk = {\n content: combinedContent,\n lineStart: lastChunk.lineStart,\n lineLength: lastChunk.lineLength + line.lineLength,\n charStart: lastChunk.charStart,\n charLength: combinedContent.length,\n };\n\n acc[acc.length - 1] = updatedChunk;\n return acc;\n },\n []\n );\n\n // If one line is longer than maxCharsPerChunk, split it into multiple chunks\n const splittedLines: ChunkLineResult[] = groupedLines.flatMap((line) => {\n const chunk: ChunkLineResult[] = [];\n\n if (line.content.length <= maxCharsPerChunk) {\n chunk.push(line);\n return chunk;\n }\n\n for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {\n const slicedContent = line.content.slice(i, i + maxCharsPerChunk);\n chunk.push({\n content: slicedContent,\n lineStart: line.lineStart,\n lineLength: 1,\n charStart: line.charStart + i,\n charLength: slicedContent.length,\n });\n }\n return chunk;\n });\n\n if (overlapChars === 0) return splittedLines;\n\n const overlapChunks: ChunkLineResult[] =\n splittedLines.length > 0 ? [splittedLines[0]] : [];\n\n for (let i = 1; i < splittedLines.length; i++) {\n const previousChunk = splittedLines[i - 1];\n const chunk = splittedLines[i];\n\n const overlapContent = previousChunk.content.slice(-overlapChars);\n const overlapLineNb = splitTextByLines(overlapContent).length;\n\n const overlapContentWithoutPartialLine = overlapContent.slice(\n overlapLineNb > 1 ? overlapContent.indexOf('\\n') + 1 : 0,\n overlapContent.length\n );\n\n const newContent = overlapContentWithoutPartialLine + chunk.content;\n const newLineLength = splitTextByLines(newContent).length;\n const lineDiff = chunk.lineLength - newLineLength;\n\n const overlappedChunk = {\n content: newContent,\n lineStart: chunk.lineStart + lineDiff,\n lineLength: chunk.lineLength - lineDiff,\n charStart: chunk.charStart - overlapContentWithoutPartialLine.length,\n charLength: newContent.length,\n };\n\n overlapChunks.push(overlappedChunk);\n }\n\n return overlapChunks;\n};\n"],"mappings":";;;;AAUA,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAE9B,MAAa,aACX,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;CACtB,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,yCAAyC;CAG3D,MAAM,4DAAgC,IAAI;CAG1C,MAAM,QAA2B,CAAC;CAClC,IAAI,eAAe;CAEnB,aAAa,SAAS,MAAM,UAAU;EACpC,MAAM,KAAK;GACT,SAAS;GACT,WAAW;GACX,YAAY;GACZ,WAAW;GACX,YAAY,KAAK;EACnB,CAAC;EACD,gBAAgB,KAAK;CACvB,CAAC;CAiDD,MAAM,gBA3CkC,MAAM,QAC3C,KAAwB,SAAS;EAEhC,IAAI,KAAK,QAAQ,SAAS,kBAAkB;GAC1C,IAAI,KAAK,IAAI;GACb,OAAO;EACT;EAGA,IAAI,IAAI,WAAW,GAAG;GACpB,IAAI,KAAK,IAAI;GACb,OAAO;EACT;EAGA,MAAM,YAAY,IAAI,IAAI,SAAS;EAMnC,IAHuB,UAAU,QAAQ,SAAS,KAAK,QAAQ,SAG1C,kBAAkB;GACrC,IAAI,KAAK,IAAI;GACb,OAAO;EACT;EAGA,MAAM,kBAAkB,UAAU,UAAU,KAAK;EACjD,MAAM,eAAe;GACnB,SAAS;GACT,WAAW,UAAU;GACrB,YAAY,UAAU,aAAa,KAAK;GACxC,WA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names":["splitTextByLines"],"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/engine/utils';\n\nexport type ChunkLineResult = {\n lineStart: number;\n lineLength: number;\n charStart: number;\n charLength: number;\n content: string;\n};\n\nconst DEFAULT_MAX_CHARS_PER_CHUNK = 800;\nconst DEFAULT_OVERLAP_CHARS = 0;\n\nexport const chunkText = (\n text: string,\n maxCharsPerChunk: number = DEFAULT_MAX_CHARS_PER_CHUNK,\n overlapChars: number = DEFAULT_OVERLAP_CHARS\n): ChunkLineResult[] => {\n if (maxCharsPerChunk <= 0) {\n throw new Error('maxCharsPerChunk must be greater than 0');\n }\n\n const splittedText = splitTextByLines(text);\n\n // Split text into lines to facilitate the translation\n const lines: ChunkLineResult[] = [];\n let charStartAcc = 0;\n\n splittedText.forEach((line, index) => {\n lines.push({\n content: line,\n lineStart: index,\n lineLength: 1,\n charStart: charStartAcc,\n charLength: line.length,\n });\n charStartAcc += line.length;\n });\n\n // Group lines\n // as long as the chunk length is less than maxCharsPerChunk\n // if a line longer than maxCharsPerChunk, keep it alone\n // if a line is not longer than maxCharsPerChunk, it is grouped\n const groupedLines: ChunkLineResult[] = lines.reduce(\n (acc: ChunkLineResult[], line) => {\n // If this line alone exceeds maxCharsPerChunk, keep it separate\n if (line.content.length > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // If we have no chunks yet, start with this line\n if (acc.length === 0) {\n acc.push(line);\n return acc;\n }\n\n // Get the last chunk\n const lastChunk = acc[acc.length - 1];\n\n // Calculate what the combined length would be (including newline character)\n const combinedLength = lastChunk.content.length + line.content.length;\n\n // If combining would exceed the limit, start a new chunk\n if (combinedLength > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // Otherwise, combine with the last chunk\n const combinedContent = lastChunk.content + line.content;\n const updatedChunk = {\n content: combinedContent,\n lineStart: lastChunk.lineStart,\n lineLength: lastChunk.lineLength + line.lineLength,\n charStart: lastChunk.charStart,\n charLength: combinedContent.length,\n };\n\n acc[acc.length - 1] = updatedChunk;\n return acc;\n },\n []\n );\n\n // If one line is longer than maxCharsPerChunk, split it into multiple chunks\n const splittedLines: ChunkLineResult[] = groupedLines.flatMap((line) => {\n const chunk: ChunkLineResult[] = [];\n\n if (line.content.length <= maxCharsPerChunk) {\n chunk.push(line);\n return chunk;\n }\n\n for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {\n const slicedContent = line.content.slice(i, i + maxCharsPerChunk);\n chunk.push({\n content: slicedContent,\n lineStart: line.lineStart,\n lineLength: 1,\n charStart: line.charStart + i,\n charLength: slicedContent.length,\n });\n }\n return chunk;\n });\n\n if (overlapChars === 0) return splittedLines;\n\n const overlapChunks: ChunkLineResult[] =\n splittedLines.length > 0 ? [splittedLines[0]] : [];\n\n for (let i = 1; i < splittedLines.length; i++) {\n const previousChunk = splittedLines[i - 1];\n const chunk = splittedLines[i];\n\n const overlapContent = previousChunk.content.slice(-overlapChars);\n const overlapLineNb = splitTextByLines(overlapContent).length;\n\n const overlapContentWithoutPartialLine = overlapContent.slice(\n overlapLineNb > 1 ? overlapContent.indexOf('\\n') + 1 : 0,\n overlapContent.length\n );\n\n const newContent = overlapContentWithoutPartialLine + chunk.content;\n const newLineLength = splitTextByLines(newContent).length;\n const lineDiff = chunk.lineLength - newLineLength;\n\n const overlappedChunk = {\n content: newContent,\n lineStart: chunk.lineStart + lineDiff,\n lineLength: chunk.lineLength - lineDiff,\n charStart: chunk.charStart - overlapContentWithoutPartialLine.length,\n charLength: newContent.length,\n };\n\n overlapChunks.push(overlappedChunk);\n }\n\n return overlapChunks;\n};\n"],"mappings":";;;;AAUA,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAE9B,MAAa,aACX,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;CACtB,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,yCAAyC;CAG3D,MAAM,mBAAeA,yCAAiB,IAAI;CAG1C,MAAM,QAA2B,CAAC;CAClC,IAAI,e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D,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,gBAAgB,cAAc,IAAI;EACxC,MAAM,QAAQ,cAAc;EAE5B,MAAM,iBAAiB,cAAc,QAAQ,MAAM,CAAC,YAAY;EAChE,MAAM,oBAAgBA,yCAAiB,cAAc,CAAC,CAAC;EAEvD,MAAM,mCAAmC,eAAe,MACtD,gBAAgB,IAAI,eAAe,QAAQ,IAAI,IAAI,IAAI,GACvD,eAAe,MACjB;EAEA,MAAM,aAAa,mCAAmC,MAAM;EAC5D,MAAM,oBAAgBA,yCAAiB,UAAU,CAAC,CAAC;EACnD,MAAM,WAAW,MAAM,aAAa;EAEpC,MAAM,kBAAkB;GACtB,SAAS;GACT,WAAW,MAAM,YAAY;GAC7B,YAAY,MAAM,aAAa;GAC/B,WAAW,MAAM,YAAY,iCAAiC;GAC9D,YAAY,WAAW;EACzB;EAEA,cAAc,KAAK,eAAe;CACpC;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkAccess.cjs","names":["readCliSessionToken","ANSIColors","login"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions, IntlayerAPIProxy } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { login } from '../auth/login';\nimport { type CliSessionData, readCliSessionToken } from '../auth/sessionToken';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const getAuthenticatedAPI = async (\n configuration?: IntlayerConfig\n): Promise<IntlayerAPIProxy> => {\n let sessionData: CliSessionData | null = null;\n\n // First use session data if it exists\n if (configuration) {\n sessionData = await readCliSessionToken(configuration);\n }\n\n return getIntlayerAPIProxy(undefined, configuration, sessionData?.token);\n};\n\nconst checkProjectConfigConsistency = (\n project: { configuration?: any } | null | undefined,\n configuration: IntlayerConfig,\n appLogger: ReturnType<typeof getAppLogger>\n): void => {\n if (!project?.configuration) return;\n\n try {\n let remoteConfigToCheck = project.configuration;\n\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n remoteConfigToCheck = { ...remoteConfigToCheck, ai: restAi };\n }\n\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_LIGHT),\n colorize(\n 'https://intlayer.org/doc/concept/cli/push',\n ANSIColors.GREY_DARK\n ),\n colorize(')', ANSIColors.GREY_LIGHT),\n '.',\n ],\n { level: 'warn' }\n );\n }\n};\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true,\n shouldAutoLogin: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n // Try CLI session token first (short-lived 2h token stored in tempDir)\n const sessionData = await readCliSessionToken(configuration);\n if (sessionData) {\n const intlayerAPI = getIntlayerAPIProxy(\n undefined,\n configuration,\n sessionData.token\n );\n\n try {\n const result = await intlayerAPI.oAuth.getCliSessionMe();\n const project = result.data?.project;\n\n if (project && shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n\n return true;\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n appLogger(\n [\n 'Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to set up a new session.',\n ],\n { level: 'error' }\n );\n return false;\n }\n }\n\n // Fall back to client_credentials (access key)\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n if (shouldAutoLogin) {\n appLogger(\n [\n 'No credentials found. Starting login...',\n colorize('( Set', ANSIColors.GREY_LIGHT),\n colorize('INTLAYER_CLIENT_ID', ANSIColors.BLUE),\n colorize('and', ANSIColors.GREY_LIGHT),\n colorize('INTLAYER_CLIENT_SECRET', ANSIColors.BLUE),\n colorize('in your .env to skip this step)', ANSIColors.GREY_LIGHT),\n ],\n { level: 'warn' }\n );\n await login({ exitAfter: false });\n return checkCMSAuth(configuration, shouldCheckConfigConsistency, false);\n }\n\n appLogger(\n [\n 'CMS auth not provided. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to authenticate, or set',\n colorize('INTLAYER_CLIENT_ID', ANSIColors.BLUE),\n 'and',\n colorize('INTLAYER_CLIENT_SECRET', ANSIColors.BLUE),\n 'in your .env file',\n colorize('(see doc:', ANSIColors.GREY_LIGHT),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY_DARK),\n colorize(')', ANSIColors.GREY_LIGHT),\n '.',\n ],\n { level: 'error' }\n );\n\n return false;\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n return true;\n }\n\n if (shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n appLogger(\n [\n 'Your access keys appear to be invalid. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to set up new access keys.',\n ],\n { level: 'error' }\n );\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // No local AI key — delegate to CMS auth check (which will auto-login if needed)\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,sBAAsB,OACjC,kBAC8B;CAC9B,IAAI,cAAqC;CAGzC,IAAI,eACF,cAAc,MAAMA,8CAAoB,aAAa;CAGvD,8CAA2B,QAAW,eAAe,aAAa,KAAK;AACzE;AAEA,MAAM,iCACJ,SACA,eACA,cACS;CACT,IAAI,CAAC,SAAS,eAAe;CAE7B,IAAI;EACF,IAAI,sBAAsB,QAAQ;EAElC,IACE,oBAAoB,MACpB,sBAAsB,oBAAoB,IAC1C;GACA,MAAM,EAAE,kBAAkB,GAAG,WAAW,oBAAoB;GAC5D,sBAAsB;IAAE,GAAG;IAAqB,IAAI;GAAO;EAC7D;EAEA,4DAAuB,qBAAqB,aAAa;CAC3D,QAAQ;EACN,UACE;GACE;GACA;yCACS,mCAAmCC,wBAAW,IAAI;yCAClD,aAAaA,wBAAW,UAAU;yCAEzC,6CACAA,wBAAW,SACb;yCACS,KAAKA,wBAAW,UAAU;GACnC;EACF,GACA,EAAE,OAAO,OAAO,CAClB;CACF;AACF;AAEA,MAAa,eAAe,OAC1B,eACA,+BAAwC,MACxC,kBAA2B,SACN;CACrB,MAAM,sDAAyB,aAAa;CAG5C,MAAM,cAAc,MAAMD,8CAAoB,aAAa;CAC3D,IAAI,aAAa;EACf,MAAM,qDACJ,QACA,eACA,YAAY,KACd;EAEA,IAAI;GAEF,MAAM,WAAU,MADK,YAAY,MAAM,gBAAgB,EACjC,CAAC,MAAM;GAE7B,IAAI,WAAW,8BACb,8BAA8B,SAAS,eAAe,SAAS;GAGjE,OAAO;EACT,SAAS,OAAO;GAEd,0DADoC,KACpB,GAAG,EAAE,OAAO,QAAQ,CAAC;GACrC,UACE;IACE;0CACS,sBAAsBC,wBAAW,IAAI;IAC9C;GACF,GACA,EAAE,OAAO,QAAQ,CACnB;GACA,OAAO;EACT;C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,eAAe,4BAA4B;AACvE"}
1
+ {"version":3,"file":"checkAccess.cjs","names":["readCliSessionToken","getIntlayerAPIProxy","colorize","ANSIColors","getAppLogger","extractErrorMessage","login"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions, IntlayerAPIProxy } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { login } from '../auth/login';\nimport { type CliSessionData, readCliSessionToken } from '../auth/sessionToken';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const getAuthenticatedAPI = async (\n configuration?: IntlayerConfig\n): Promise<IntlayerAPIProxy> => {\n let sessionData: CliSessionData | null = null;\n\n // First use session data if it exists\n if (configuration) {\n sessionData = await readCliSessionToken(configuration);\n }\n\n return getIntlayerAPIProxy(undefined, configuration, sessionData?.token);\n};\n\nconst checkProjectConfigConsistency = (\n project: { configuration?: any } | null | undefined,\n configuration: IntlayerConfig,\n appLogger: ReturnType<typeof getAppLogger>\n): void => {\n if (!project?.configuration) return;\n\n try {\n let remoteConfigToCheck = project.configuration;\n\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n remoteConfigToCheck = { ...remoteConfigToCheck, ai: restAi };\n }\n\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_LIGHT),\n colorize(\n 'https://intlayer.org/doc/concept/cli/push',\n ANSIColors.GREY_DARK\n ),\n colorize(')', ANSIColors.GREY_LIGHT),\n '.',\n ],\n { level: 'warn' }\n );\n }\n};\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true,\n shouldAutoLogin: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n // Try CLI session token first (short-lived 2h token stored in tempDir)\n const sessionData = await readCliSessionToken(configuration);\n if (sessionData) {\n const intlayerAPI = getIntlayerAPIProxy(\n undefined,\n configuration,\n sessionData.token\n );\n\n try {\n const result = await intlayerAPI.oAuth.getCliSessionMe();\n const project = result.data?.project;\n\n if (project && shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n\n return true;\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n appLogger(\n [\n 'Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to set up a new session.',\n ],\n { level: 'error' }\n );\n return false;\n }\n }\n\n // Fall back to client_credentials (access key)\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n if (shouldAutoLogin) {\n appLogger(\n [\n 'No credentials found. Starting login...',\n colorize('( Set', ANSIColors.GREY_LIGHT),\n colorize('INTLAYER_CLIENT_ID', ANSIColors.BLUE),\n colorize('and', ANSIColors.GREY_LIGHT),\n colorize('INTLAYER_CLIENT_SECRET', ANSIColors.BLUE),\n colorize('in your .env to skip this step)', ANSIColors.GREY_LIGHT),\n ],\n { level: 'warn' }\n );\n await login({ exitAfter: false });\n return checkCMSAuth(configuration, shouldCheckConfigConsistency, false);\n }\n\n appLogger(\n [\n 'CMS auth not provided. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to authenticate, or set',\n colorize('INTLAYER_CLIENT_ID', ANSIColors.BLUE),\n 'and',\n colorize('INTLAYER_CLIENT_SECRET', ANSIColors.BLUE),\n 'in your .env file',\n colorize('(see doc:', ANSIColors.GREY_LIGHT),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY_DARK),\n colorize(')', ANSIColors.GREY_LIGHT),\n '.',\n ],\n { level: 'error' }\n );\n\n return false;\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n return true;\n }\n\n if (shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n appLogger(\n [\n 'Your access keys appear to be invalid. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to set up new access keys.',\n ],\n { level: 'error' }\n );\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // No local AI key — delegate to CMS auth check (which will auto-login if needed)\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,sBAAsB,OACjC,kBAC8B;CAC9B,IAAI,cAAqC;CAGzC,IAAI,eACF,cAAc,MAAMA,8CAAoB,aAAa;CAGvD,WAAOC,mCAAoB,QAAW,eAAe,aAAa,KAAK;AACzE;AAEA,MAAM,iCACJ,SACA,eACA,cACS;CACT,IAAI,CAAC,SAAS,eAAe;CAE7B,IAAI;EACF,IAAI,sBAAsB,QAAQ;EAElC,IACE,oBAAoB,MACpB,sBAAsB,oBAAoB,IAC1C;GACA,MAAM,EAAE,kBAAkB,GAAG,WAAW,oBAAoB;GAC5D,sBAAsB;IAAE,GAAG;IAAqB,IAAI;GAAO;EAC7D;EAEA,4DAAuB,qBAAqB,aAAa;CAC3D,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AC9C;OACAD,kCAAS,0BAA0BC,wBAAW,IAAI;GAClD;OACAD,kCAAS,aAAaC,wBAAW,UAAU;OAC3CD,kCAAS,wCAAwCC,wBAAW,SAAS;OACrED,kCAAS,KAAKC,wBAAW,UAAU;GACnC;EACF,GACA,EAAE,OAAO,QAAQ,CACnB;EAEA,OAAO;CACT;CAEA,MAAM,kBAAcF,mCAAoB,QAAW,aAAa;CAEhE,IAAI;EAGF,MAAM,WAAU,MAFK,YAAY,MAAM,qBAAqB,EAEtC,CAAC,MAAM;EAE7B,IAAI,CAAC,SAAS;GACZ,UAAU,mBAAmB;GAC7B,OAAO;EACT;EAEA,IAAI,8BACF,8BAA8B,SAAS,eAAe,SAAS;CAEnE,SAAS,OAAO;EAEd,cADgBI,4CAAoB,KACpB,GAAG,EAAE,OAAO,QAAQ,CAAC;EACrC,UACE;GACE;OACAH,kCAAS,sBAAsBC,wBAAW,IAAI;GAC9C;EACF,GACA,EAAE,OAAO,QAAQ,CACnB;EACA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,MAAa,gBAAgB,OAC3B,eACA,WACA,+BAAwC,SACnB;CACrB,MAAM,WACJ,cAAc,IAAI,aAAa,YAAY,WAAW,aAAa;CAKrE,IAJ0B,QACxB,cAAc,IAAI,UAAU,WAAW,MAGrB,KAAK,UACvB,OAAO;CAIT,OAAO,MAAM,aAAa,eAAe,4BAA4B;AACvE"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/checkConfigConsistency.ts
4
3
  const checkConfigConsistency = (subset, superset) => {
5
4
  for (const key in subset) {
@@ -1 +1 @@
1
- {"version":3,"file":"checkConfigConsistency.cjs","names":[],"sources":["../../../src/utils/checkConfigConsistency.ts"],"sourcesContent":["export const checkConfigConsistency = (subset: any, superset: any) => {\n for (const key in subset) {\n const val1 = subset[key];\n const val2 = superset[key];\n\n if (Array.isArray(val1) && Array.isArray(val2)) {\n // Check if arrays are identical in content\n if (JSON.stringify(val1) !== JSON.stringify(val2)) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n } else if (typeof val1 === 'object' && val1 !== null) {\n checkConfigConsistency(val1, val2);\n } else if (val1 !== val2) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n }\n};\n"],"mappings":";;;AAAA,MAAa,0BAA0B,QAAa,aAAkB;CACpE,KAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,OAAO,OAAO;EACpB,MAAM,OAAO,SAAS;EAEtB,IAAI,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,IAAI,GAE3C;OAAI,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,IAAI,GAC9C,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;EAC1D,OACK,IAAI,OAAO,SAAS,YAAY,SAAS,MAC9C,uBAAuB,MAAM,IAAI;OAC5B,IAAI,SAAS,MAClB,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;CAE5D;AACF"}
1
+ {"version":3,"file":"checkConfigConsistency.cjs","names":[],"sources":["../../../src/utils/checkConfigConsistency.ts"],"sourcesContent":["export const checkConfigConsistency = (subset: any, superset: any) => {\n for (const key in subset) {\n const val1 = subset[key];\n const val2 = superset[key];\n\n if (Array.isArray(val1) && Array.isArray(val2)) {\n // Check if arrays are identical in content\n if (JSON.stringify(val1) !== JSON.stringify(val2)) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n } else if (typeof val1 === 'object' && val1 !== null) {\n checkConfigConsistency(val1, val2);\n } else if (val1 !== val2) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n }\n};\n"],"mappings":";;AAAA,MAAa,0BAA0B,QAAa,aAAkB;CACpE,KAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,OAAO,OAAO;EACpB,MAAM,OAAO,SAAS;EAEtB,IAAI,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,IAAI,GAE3C;OAAI,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,IAAI,GAC9C,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;EAC1D,OACK,IAAI,OAAO,SAAS,YAAY,SAAS,MAC9C,uBAAuB,MAAM,IAAI;OAC5B,IAAI,SAAS,MAClB,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;CAE5D;AACF"}
@@ -9,7 +9,7 @@ const require_utils_formatTimeDiff = require('./formatTimeDiff.cjs');
9
9
  * 50 years expressed in milliseconds is far greater than any reasonable
10
10
  * "relative" duration we expect the helper to receive (e.g. a couple of years).
11
11
  */
12
- const TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1e3;
12
+ const TIMESTAMP_THRESHOLD_MS = 15768e8;
13
13
  /**
14
14
  * Normalises the input date representation into a pair:
15
15
  * 1. `relativeTime` – a Date instance whose epoch-time equals the duration
@@ -66,9 +66,10 @@ const checkFileModifiedRange = (filePath, options) => {
66
66
  else if (maxDate) shouldSkip = fileLastUpdateTime >= maxDate;
67
67
  if (shouldSkip) {
68
68
  const referenceDate = minDate && maxDate ? new Date(Math.abs(maxDate.getTime() - minDate.getTime())) : minDate ?? maxDate;
69
+ const relativeTime = new Date(now.getTime() - referenceDate.getTime());
69
70
  return {
70
71
  isSkipped: true,
71
- message: `Skipping file because it has been modified within the last ${require_utils_formatTimeDiff.formatTimeDiff(new Date(now.getTime() - referenceDate.getTime()))} - ${filePath}`
72
+ message: `Skipping file because it has been modified within the last ${require_utils_formatTimeDiff.formatTimeDiff(relativeTime)} - ${filePath}`
72
73
  };
73
74
  }
74
75
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"checkFileModifiedRange.cjs","names":["checkLastUpdateTime","formatTimeDiff"],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;;;;;;;;;;;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J,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,QAAQ,IAAI,QAAQ,QAAQ,CAAC,CAAC,IACvD,WAAW;EAKlB,OAAO;GACL,WAAW;GACX,SAAS,8DAA8DC,4CAAe,IAJ/D,KAAK,IAAI,QAAQ,IAAI,cAAc,QAAQ,CAI+B,CAAC,EAAE,KAAK;EAC3G;CACF;CAEA,OAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;CAClD;AACF"}
1
+ {"version":3,"file":"checkFileModifiedRange.cjs","names":["checkLastUpdateTime","formatTimeDiff"],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,yBAAyB;;;;;;;;;;;;;;;;AAiB/B,MAAM,sBACJ,MACA,sBAAY,IAAI,KAAK,MACE;CAEvB,IAAI,gBAAgB,MAClB,OAAO;EACL,cAAc;EACd,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACvD;CAIF,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,OAAO,wBAAwB;GAEjC,MAAM,eAAe,IAAI,KAAK,IAAI;GAClC,OAAO;IACL;IACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;GAC/D;EACF;EAGA,MAAM,aAAa;EACnB,OAAO;GAEL,cAAc,IAAI,KAAK,UAAU;GAEjC,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,UAAU;EACnD;CACF;CAGA,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,eAAe,IAAI,KAAK,IAAI;EAClC,IAAI,OAAO,MAAM,aAAa,QAAQ,CAAC,GACrC,MAAM,IAAI,MAAM,iCAAiC,MAAM;EAGzD,OAAO;GACL;GACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;EAC/D;CACF;CAEA,MAAM,IAAI,MAAM,4BAA4B,MAAM;AACpD;AAYA,MAAa,0BACX,UACA,YACiC;CACjC,MAAM,qBAAqBA,sDAAoB,QAAQ;CACvD,MAAM,EAAE,sBAAsB,wBAAwB;CAGtD,MAAM,sBAAM,IAAI,KAAK;CACrB,MAAM,UAAU,uBACZ,mBAAmB,sBAAsB,GAAG,CAAC,CAAC,eAC9C;CACJ,MAAM,UAAU,sBACZ,mBAAmB,qBAAqB,GAAG,CAAC,CAAC,eAC7C;CAGJ,IAAI,aAAa;CAEjB,IAAI,mBAAmB,QAAQ,mBAAmB,MAEhD,aAAa,sBAAsB,WAAW,sBAAsB;MAC/D,IAAI,mBAAmB,MAE5B,aAAa,sBAAsB;MAC9B,IAAI,SAET,aAAa,sBAAsB;CAGrC,IAAI,YAAY;EAGd,MAAM,gBACJ,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,QAAQ,IAAI,QAAQ,QAAQ,CAAC,CAAC,IACvD,WAAW;EAGlB,MAAM,eAAe,IAAI,KAAK,IAAI,QAAQ,IAAI,cAAc,QAAQ,CAAC;EAErE,OAAO;GACL,WAAW;GACX,SAAS,8DAA8DC,4CAAe,YAAY,EAAE,KAAK;EAC3G;CACF;CAEA,OAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;CAClD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkLastUpdateTime.cjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAa,uBAAuB,aAA2B;CAC7D,MAAM,8BAAiB,QAAQ;CAC/B,OAAO,IAAI,KAAK,MAAM,KAAK;AAC7B"}
1
+ {"version":3,"file":"checkLastUpdateTime.cjs","names":["statSync"],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAa,uBAAuB,aAA2B;CAC7D,MAAM,YAAQA,kBAAS,QAAQ;CAC/B,OAAO,IAAI,KAAK,MAAM,KAAK;AAC7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"chunkInference.cjs","names":["getAuthenticatedAPI"],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type {\n AIConfig,\n AIOptions,\n Messages,\n SystemMessage,\n} from '@intlayer/ai';\nimport { retryManager } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getAuthenticatedAPI } from './checkAccess';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n system: SystemMessage,\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n system,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = await getAuthenticatedAPI(configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":";;;;;;;;;AAoBA,MAAa,iBAAiB,OAC5B,QACA,UACA,WACA,eACA,UACA,aACkC;CAClC,IAAI;CAEJ,+CAAmB,YAAY;EAC7B,IAAI,YAAY,UAAU;GACxB,MAAM,WAAW,MAAM,SAAS,YAAY;IAC1C;IACA;IACA;GACF,CAAC;GAED,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,yBAAyB;GAG3C,MAAM,EAAE,aAAa,cAAc;GAEnC,aAAa;IACX,aAAa,eAAe,WAAW;IACvC;GACF;GAEA;EACF;EAIA,MAAM,WAAW,OAAM,MAFLA,8CAAoB,aAAa,EAEzB,CAAC,GAAG,YAAY;GACxC;GACA;EACF,CAAC;EAED,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,EAAE,aAAa,cAAc,SAAS;EAE5C,aAAa;GACX,aAAa,eAAe,WAAW;GACvC;EACF;CACF,CAAC,CAAC,CAAC;CAEH,OAAO;AACT;AAEA,MAAM,kBAAkB,YAAoB;CAC1C,OAAO,QACJ,WAAW,qBAAqB,EAAE,CAAC,CACnC,WAAW,oBAAoB,EAAE,CAAC,CAClC,WAAW,mBAAmB,EAAE,CAAC,CACjC,WAAW,kBAAkB,EAAE,CAAC,CAChC,WAAW,qBAAqB,EAAE,CAAC,CACnC,WAAW,iBAAiB,EAAE,CAAC,CAC/B,WAAW,gBAAgB,EAAE,CAAC,CAC9B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,kBAAkB,EAAE,CAAC,CAChC,WAAW,iBAAiB,EAAE,CAAC,CAC/B,WAAW,gBAAgB,EAAE,CAAC,CAC9B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,cAAc,EAAE,CAAC,CAC5B,WAAW,aAAa,EAAE,CAAC,CAC3B,WAAW,YAAY,EAAE;AAC9B"}
1
+ {"version":3,"file":"chunkInference.cjs","names":["retryManager","getAuthenticatedAPI"],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type {\n AIConfig,\n AIOptions,\n Messages,\n SystemMessage,\n} from '@intlayer/ai';\nimport { retryManager } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getAuthenticatedAPI } from './checkAccess';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n system: SystemMessage,\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n system,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = await getAuthenticatedAPI(configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":";;;;;;;;;AAoBA,MAAa,iBAAiB,OAC5B,QACA,UACA,WACA,eACA,UACA,aACkC;CAClC,IAAI;CAEJ,UAAMA,qCAAa,YAAY;EAC7B,IAAI,YAAY,UAAU;GACxB,MAAM,WAAW,MAAM,SAAS,YAAY;IAC1C;IACA;IACA;GACF,CAAC;GAED,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,yBAAyB;GAG3C,MAAM,EAAE,aAAa,cAAc;GAEnC,aAAa;IACX,aAAa,eAAe,WAAW;IACvC;GACF;GAEA;EACF;EAIA,MAAM,WAAW,OAAM,MAFLC,8CAAoB,aAAa,EAEzB,CAAC,GAAG,YAAY;GACxC;GACA;EACF,CAAC;EAED,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,EAAE,aAAa,cAAc,SAAS;EAE5C,aAAa;GACX,aAAa,eAAe,WAAW;GACvC;EACF;CACF,CAAC,CAAC,CAAC;CAEH,OAAO;AACT;AAEA,MAAM,kBAAkB,YAAoB;CAC1C,OAAO,QACJ,WAAW,qBAAqB,EAAE,CAAC,CACnC,WAAW,oBAAoB,EAAE,CAAC,CAClC,WAAW,mBAAmB,EAAE,CAAC,CACjC,WAAW,kBAAkB,EAAE,CAAC,CAChC,WAAW,qBAAqB,EAAE,CAAC,CACnC,WAAW,iBAAiB,EAAE,CAAC,CAC/B,WAAW,gBAAgB,EAAE,CAAC,CAC9B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,kBAAkB,EAAE,CAAC,CAChC,WAAW,iBAAiB,EAAE,CAAC,CAC/B,WAAW,gBAAgB,EAAE,CAAC,CAC9B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,eAAe,EAAE,CAAC,CAC7B,WAAW,cAAc,EAAE,CAAC,CAC5B,WAAW,aAAa,EAAE,CAAC,CAC3B,WAAW,YAAY,EAAE;AAC9B"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/fixChunkStartEndChars.ts
4
3
  const CHAR_TO_CHECK_FORMATTING = [
5
4
  "```",
@@ -1 +1 @@
1
- {"version":3,"file":"fixChunkStartEndChars.cjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":";;;AAAA,MAAM,2BAA2B;CAAC;CAAO;CAAQ;CAAM;CAAO;CAAM;AAAI;AAGxE,MAAM,mBAAmB,QACvB,IAAI,QAAQ,uBAAuB,MAAM,CAAC,CAAC,QAAQ,OAAO,KAAK;AAIjE,MAAM,0BAA0B,MAAM,yBAAyB,IAAI,eAAe,CAAC,CAAC,KAAK,GAAG,EAAE;AAC9F,MAAM,2BAA2B,IAAI,OAAO,IAAI,yBAAyB;AACzE,MAAM,4BAA4B,IAAI,OAAO,GAAG,wBAAwB,EAAE;AAE1E,MAAa,yBACX,qBACA,qBACG;CACH,IAAI,SAAS;CAEb,MAAM,cACJ,iBAAiB,MAAM,wBAAwB,CAAC,GAAG,MAAM;CAC3D,MAAM,eACJ,iBAAiB,MAAM,yBAAyB,CAAC,GAAG,MAAM;CAE5D,MAAM,gBAAgB,OAAO,MAAM,wBAAwB,CAAC,GAAG,MAAM;CACrE,MAAM,iBAAiB,OAAO,MAAM,yBAAyB,CAAC,GAAG,MAAM;CAGvE,IAAI,gBAAgB,eAElB,SAAS,cAAc,OAAO,MAAM,cAAc,MAAM;CAI1D,IAAI,iBAAiB,gBAEnB,SACE,OAAO,MAAM,GAAG,OAAO,SAAS,eAAe,MAAM,IAAI;CAG7D,OAAO;AACT"}
1
+ {"version":3,"file":"fixChunkStartEndChars.cjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":";;AAAA,MAAM,2BAA2B;CAAC;CAAO;CAAQ;CAAM;CAAO;CAAM;AAAI;AAGxE,MAAM,mBAAmB,QACvB,IAAI,QAAQ,uBAAuB,MAAM,CAAC,CAAC,QAAQ,OAAO,KAAK;AAIjE,MAAM,0BAA0B,MAAM,yBAAyB,IAAI,eAAe,CAAC,CAAC,KAAK,GAAG,EAAE;AAC9F,MAAM,2BAA2B,IAAI,OAAO,IAAI,yBAAyB;AACzE,MAAM,4BAA4B,IAAI,OAAO,GAAG,wBAAwB,EAAE;AAE1E,MAAa,yBACX,qBACA,qBACG;CACH,IAAI,SAAS;CAEb,MAAM,cACJ,iBAAiB,MAAM,wBAAwB,CAAC,GAAG,MAAM;CAC3D,MAAM,eACJ,iBAAiB,MAAM,yBAAyB,CAAC,GAAG,MAAM;CAE5D,MAAM,gBAAgB,OAAO,MAAM,wBAAwB,CAAC,GAAG,MAAM;CACrE,MAAM,iBAAiB,OAAO,MAAM,yBAAyB,CAAC,GAAG,MAAM;CAGvE,IAAI,gBAAgB,eAElB,SAAS,cAAc,OAAO,MAAM,cAAc,MAAM;CAI1D,IAAI,iBAAiB,gBAEnB,SACE,OAAO,MAAM,GAAG,OAAO,SAAS,eAAe,MAAM,IAAI;CAG7D,OAAO;AACT"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/formatLineRanges.ts
4
3
  /**
5
4
  * Formats a list of line numbers into a compact, human-readable string where
@@ -1 +1 @@
1
- {"version":3,"file":"formatLineRanges.cjs","names":[],"sources":["../../../src/utils/formatLineRanges.ts"],"sourcesContent":["/**\n * Formats a list of line numbers into a compact, human-readable string where\n * runs of consecutive lines are collapsed into ranges.\n *\n * The input is sorted and de-duplicated first, so callers don't need to\n * pre-process it. A run of a single line is printed as the bare number; a run\n * of two or more consecutive lines is printed as `start-end`.\n *\n * @example\n * formatLineRanges([2, 3, 4, 5, 333, 412, 413, 414]);\n * // → '2-5, 333, 412-414'\n *\n * @param lineNumbers - The (possibly unsorted, possibly duplicated) line numbers.\n * @param separator - String inserted between groups. Defaults to `', '`.\n * @returns The grouped string, or an empty string when no lines are provided.\n */\nexport const formatLineRanges = (\n lineNumbers: number[],\n separator = ', '\n): string => {\n const sortedUniqueLines = [...new Set(lineNumbers)].sort((a, b) => a - b);\n\n if (sortedUniqueLines.length === 0) return '';\n\n const groups: string[] = [];\n let rangeStart = sortedUniqueLines[0]!;\n let rangeEnd = rangeStart;\n\n const pushGroup = (): void => {\n groups.push(\n rangeStart === rangeEnd ? `${rangeStart}` : `${rangeStart}-${rangeEnd}`\n );\n };\n\n for (const lineNumber of sortedUniqueLines.slice(1)) {\n if (lineNumber === rangeEnd + 1) {\n // Still inside the current consecutive run.\n rangeEnd = lineNumber;\n continue;\n }\n\n // Gap detected: close the current run and start a new one.\n pushGroup();\n rangeStart = lineNumber;\n rangeEnd = lineNumber;\n }\n\n pushGroup();\n\n return groups.join(separator);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,oBACX,aACA,YAAY,SACD;CACX,MAAM,oBAAoB,CAAC,GAAG,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;CAExE,IAAI,kBAAkB,WAAW,GAAG,OAAO;CAE3C,MAAM,SAAmB,CAAC;CAC1B,IAAI,aAAa,kBAAkB;CACnC,IAAI,WAAW;CAEf,MAAM,kBAAwB;EAC5B,OAAO,KACL,eAAe,WAAW,GAAG,eAAe,GAAG,WAAW,GAAG,UAC/D;CACF;CAEA,KAAK,MAAM,cAAc,kBAAkB,MAAM,CAAC,GAAG;EACnD,IAAI,eAAe,WAAW,GAAG;GAE/B,WAAW;GACX;EACF;EAGA,UAAU;EACV,aAAa;EACb,WAAW;CACb;CAEA,UAAU;CAEV,OAAO,OAAO,KAAK,SAAS;AAC9B"}
1
+ {"version":3,"file":"formatLineRanges.cjs","names":[],"sources":["../../../src/utils/formatLineRanges.ts"],"sourcesContent":["/**\n * Formats a list of line numbers into a compact, human-readable string where\n * runs of consecutive lines are collapsed into ranges.\n *\n * The input is sorted and de-duplicated first, so callers don't need to\n * pre-process it. A run of a single line is printed as the bare number; a run\n * of two or more consecutive lines is printed as `start-end`.\n *\n * @example\n * formatLineRanges([2, 3, 4, 5, 333, 412, 413, 414]);\n * // → '2-5, 333, 412-414'\n *\n * @param lineNumbers - The (possibly unsorted, possibly duplicated) line numbers.\n * @param separator - String inserted between groups. Defaults to `', '`.\n * @returns The grouped string, or an empty string when no lines are provided.\n */\nexport const formatLineRanges = (\n lineNumbers: number[],\n separator = ', '\n): string => {\n const sortedUniqueLines = [...new Set(lineNumbers)].sort((a, b) => a - b);\n\n if (sortedUniqueLines.length === 0) return '';\n\n const groups: string[] = [];\n let rangeStart = sortedUniqueLines[0]!;\n let rangeEnd = rangeStart;\n\n const pushGroup = (): void => {\n groups.push(\n rangeStart === rangeEnd ? `${rangeStart}` : `${rangeStart}-${rangeEnd}`\n );\n };\n\n for (const lineNumber of sortedUniqueLines.slice(1)) {\n if (lineNumber === rangeEnd + 1) {\n // Still inside the current consecutive run.\n rangeEnd = lineNumber;\n continue;\n }\n\n // Gap detected: close the current run and start a new one.\n pushGroup();\n rangeStart = lineNumber;\n rangeEnd = lineNumber;\n }\n\n pushGroup();\n\n return groups.join(separator);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,oBACX,aACA,YAAY,SACD;CACX,MAAM,oBAAoB,CAAC,GAAG,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;CAExE,IAAI,kBAAkB,WAAW,GAAG,OAAO;CAE3C,MAAM,SAAmB,CAAC;CAC1B,IAAI,aAAa,kBAAkB;CACnC,IAAI,WAAW;CAEf,MAAM,kBAAwB;EAC5B,OAAO,KACL,eAAe,WAAW,GAAG,eAAe,GAAG,WAAW,GAAG,UAC/D;CACF;CAEA,KAAK,MAAM,cAAc,kBAAkB,MAAM,CAAC,GAAG;EACnD,IAAI,eAAe,WAAW,GAAG;GAE/B,WAAW;GACX;EACF;EAGA,UAAU;EACV,aAAa;EACb,WAAW;CACb;CAEA,UAAU;CAEV,OAAO,OAAO,KAAK,SAAS;AAC9B"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/formatTimeDiff.ts
4
3
  const formatTimeDiff = (realtiveTime) => {
5
4
  const diff = realtiveTime.getTime();