@intlayer/cli 9.3.0 → 9.3.2

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 (136) 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 +14 -133
  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 +15 -134
  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/dist/types/init.d.ts.map +1 -1
  136. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","chunkInference","ENGLISH","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/reviewDoc/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { retryManager } from '@intlayer/config/utils';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n type PlannedAction,\n type ReviewReportSummary,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { AIClient } from '../utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n *\n * 1. Segments both base and target documents into semantic blocks.\n * 2. Aligns blocks using structure (special chars, numbers) and context.\n * 3. Detects which blocks changed, were added, or deleted.\n * 4. Applies deletions immediately without AI.\n * 5. Sends changed/new blocks to AI in bottom-up order (last block first), so\n * line numbers of earlier blocks are not shifted by edits below them.\n * 6. Rewrites the file after each block so progress is persisted incrementally.\n *\n * @returns The per-action block counts of the alignment plan, so the caller can\n * synthesize what was reused and what had to be edited.\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ReviewReportSummary> => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger({\n log: { ...configuration.log, prefix: '' },\n });\n\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_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 filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { baseBlocks, targetBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n baseText,\n targetText,\n changedLines,\n });\n\n const countActions = (kind: PlannedAction['kind']): number =>\n plan.actions.filter((action: PlannedAction) => action.kind === kind).length;\n\n const reviewSummary: ReviewReportSummary = {\n reuse: countActions('reuse'),\n review: countActions('review'),\n insertNew: countActions('insert_new'),\n delete: countActions('delete'),\n };\n\n const deleteCount = reviewSummary.delete;\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: base=${colorizeNumber(baseBlocks.length)}, target=${colorizeNumber(targetBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(reviewSummary.reuse)}, review=${colorizeNumber(reviewSummary.review)}, new=${colorizeNumber(reviewSummary.insertNew)}, delete=${colorizeNumber(deleteCount)}`\n );\n\n // Map shared across the entire run: each entry overrides the default behavior\n // of mergeReviewedSegments for that action index.\n const reviewedSegmentsMap = new Map<number, string>();\n\n // --- Step 1: apply deletions immediately (no AI needed) ---\n for (const [actionIndex, action] of plan.actions.entries()) {\n if (action.kind === 'delete') {\n reviewedSegmentsMap.set(actionIndex, '');\n }\n }\n\n const writeCurrentState = (): void => {\n const output = mergeReviewedSegments(\n plan,\n targetBlocks,\n reviewedSegmentsMap\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, output);\n };\n\n if (deleteCount > 0) {\n writeCurrentState();\n applicationLogger(\n `${filePrefix}${colorizeNumber(deleteCount)} block(s) deleted without AI.`\n );\n }\n\n if (segmentsToReview.length === 0) {\n if (deleteCount === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n writeCurrentState();\n }\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no AI changes needed).`\n );\n return reviewSummary;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)} (processing bottom-up)`\n );\n\n // --- Step 2: process AI segments in bottom-up order ---\n // Reversing ensures edits near the end of the file don't shift line numbers\n // that matter for blocks higher up, and each intermediate file write is valid.\n const segmentsBottomUp = segmentsToReview\n .map((segment, originalIndex) => ({\n segment,\n displayNumber: originalIndex + 1,\n }))\n .reverse();\n\n for (const { segment, displayNumber } of segmentsBottomUp) {\n const baseBlock = segment.baseBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n baseBlock.content +\n `///chunksEnd///`;\n\n const getTargetChunkPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.targetBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getTargetChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, ENGLISH)} (${locale}).`,\n },\n ],\n [{ role: 'user', content: baseBlock.content }],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n baseBlock.content\n );\n processedChunk = fixChunkStartEndChars(processedChunk, baseBlock.content);\n\n const isValid = validateTranslation(\n baseBlock.content,\n processedChunk,\n applicationLogger\n );\n\n if (!isValid) {\n throw new Error(\n 'Validation failed for chunk (structure or length mismatch). Retrying...'\n );\n }\n\n return processedChunk;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n\n // Rewrite the file after every block so progress is never lost.\n writeCurrentState();\n }\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputF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,KAAK,EAAE,2BAEzH,QAAQ,mBAAmB,MAC5B;EAEF,MAAM,sBAAsB,+CAAmB,YAAY;GACzD,MAAM,SAAS,MAAMC,4CACnB;IACE;KAAE,MAAM;KAAU,SAAS;IAAW;IACtC;KAAE,MAAM;KAAU,SAAS,0BAA0B;IAAE;IACvD;KAAE,MAAM;KAAU,SAAS,qBAAqB;IAAE;IAClD;KACE,MAAM;KACN,SAAS,yFAA4D,aAAa,EAAE,kDAAqB,iBAAiB,MAAM,EAAE,iFAAgD,QAAQC,+BAAO,EAAE,IAAI,OAAO;IAChN;GACF,GACA,CAAC;IAAE,MAAM;IAAQ,SAAS,UAAU;GAAQ,CAAC,GAC7C,WACA,eACA,UACA,QACF;GAEA,kBACE,GAAG,qDAAwB,OAAO,SAAS,EAAE,mEAAsC,aAAa,EAAE,kDAAqB,iBAAiB,MAAM,GAChJ;GAEA,IAAI,iBAAiBC,8CACnB,QAAQ,aACR,UAAU,OACZ;GACA,iBAAiBC,0DAAsB,gBAAgB,UAAU,OAAO;GAQxE,IAAI,CANYC,oDACd,UAAU,SACV,gBACA,iBAGS,GACT,MAAM,IAAI,MACR,yEACF;GAGF,OAAO;EACT,CAAC,CAAC,CAAC;EAEH,oBAAoB,IAAI,QAAQ,aAAa,mBAAmB;EAGhE,kBAAkB;CACpB;CAEA,kBACE,yCAAY,KAAKL,wBAAW,KAAK,EAAE,+CAAmB,cAAc,EAAE,+BACxE;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"reviewDocBlockAware.cjs","names":["getConfiguration","getAppLogger","readFile","readAsset","formatLocale","ANSIColors","formatPath","colon","buildAlignmentPlan","colorizeNumber","mergeReviewedSegments","dirname","colorize","retryManager","chunkInference","getLocaleName","ENGLISH","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/reviewDoc/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { retryManager } from '@intlayer/config/utils';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n type PlannedAction,\n type ReviewReportSummary,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { AIClient } from '../utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n *\n * 1. Segments both base and target documents into semantic blocks.\n * 2. Aligns blocks using structure (special chars, numbers) and context.\n * 3. Detects which blocks changed, were added, or deleted.\n * 4. Applies deletions immediately without AI.\n * 5. Sends changed/new blocks to AI in bottom-up order (last block first), so\n * line numbers of earlier blocks are not shifted by edits below them.\n * 6. Rewrites the file after each block so progress is persisted incrementally.\n *\n * @returns The per-action block counts of the alignment plan, so the caller can\n * synthesize what was reused and what had to be edited.\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ReviewReportSummary> => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger({\n log: { ...configuration.log, prefix: '' },\n });\n\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_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 filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { baseBlocks, targetBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n baseText,\n targetText,\n changedLines,\n });\n\n const countActions = (kind: PlannedAction['kind']): number =>\n plan.actions.filter((action: PlannedAction) => action.kind === kind).length;\n\n const reviewSummary: ReviewReportSummary = {\n reuse: countActions('reuse'),\n review: countActions('review'),\n insertNew: countActions('insert_new'),\n delete: countActions('delete'),\n };\n\n const deleteCount = reviewSummary.delete;\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: base=${colorizeNumber(baseBlocks.length)}, target=${colorizeNumber(targetBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(reviewSummary.reuse)}, review=${colorizeNumber(reviewSummary.review)}, new=${colorizeNumber(reviewSummary.insertNew)}, delete=${colorizeNumber(deleteCount)}`\n );\n\n // Map shared across the entire run: each entry overrides the default behavior\n // of mergeReviewedSegments for that action index.\n const reviewedSegmentsMap = new Map<number, string>();\n\n // --- Step 1: apply deletions immediately (no AI needed) ---\n for (const [actionIndex, action] of plan.actions.entries()) {\n if (action.kind === 'delete') {\n reviewedSegmentsMap.set(actionIndex, '');\n }\n }\n\n const writeCurrentState = (): void => {\n const output = mergeReviewedSegments(\n plan,\n targetBlocks,\n reviewedSegmentsMap\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, output);\n };\n\n if (deleteCount > 0) {\n writeCurrentState();\n applicationLogger(\n `${filePrefix}${colorizeNumber(deleteCount)} block(s) deleted without AI.`\n );\n }\n\n if (segmentsToReview.length === 0) {\n if (deleteCount === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n writeCurrentState();\n }\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no AI changes needed).`\n );\n return reviewSummary;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)} (processing bottom-up)`\n );\n\n // --- Step 2: process AI segments in bottom-up order ---\n // Reversing ensures edits near the end of the file don't shift line numbers\n // that matter for blocks higher up, and each intermediate file write is valid.\n const segmentsBottomUp = segmentsToReview\n .map((segment, originalIndex) => ({\n segment,\n displayNumber: originalIndex + 1,\n }))\n .reverse();\n\n for (const { segment, displayNumber } of segmentsBottomUp) {\n const baseBlock = segment.baseBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n baseBlock.content +\n `///chunksEnd///`;\n\n const getTargetChunkPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.targetBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getTargetChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, ENGLISH)} (${locale}).`,\n },\n ],\n [{ role: 'user', content: baseBlock.content }],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n baseBlock.content\n );\n processedChunk = fixChunkStartEndChars(processedChunk, baseBlock.content);\n\n const isValid = validateTranslation(\n baseBlock.content,\n processedChunk,\n applicationLogger\n );\n\n if (!isValid) {\n throw new Error(\n 'Validation failed for chunk (structure or length mismatch). Retrying...'\n );\n }\n\n return processedChunk;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n\n // Rewrite the file after every block so progress is never lost.\n writeCurrentState();\n }\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n\n return reviewSummary;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,uBAAuB,OAClC,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,aACiC;CACjC,MAAM,oBAAgBA,wCAAiB,aAAa;CACpD,MAAM,wBAAoBC,sCAAa,EACrC,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;CAAG,EAC1C,CAAC;CAED,MAAM,WAAW,UAAMC,2BAAS,cAAc,OAAO;CACrD,MAAM,aAAa,UAAMA,2BAAS,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE;CAEzE,MAAM,aAAaC,+BAAU,8BAA8B,OAAO,CAAC,CAChE,WAAW,kBAAkB,OAAGC,qCAAa,QAAQ,KAAK,GAAG,CAAC,CAC9D,WAAW,sBAAsB,OAAGA,qCAAa,YAAY,KAAK,GAAG,CAAC,C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C,+BAAO,EAAE,IAAI,OAAO;IAChN;GACF,GACA,CAAC;IAAE,MAAM;IAAQ,SAAS,UAAU;GAAQ,CAAC,GAC7C,WACA,eACA,UACA,QACF;GAEA,kBACE,GAAG,aAASP,wCAAe,OAAO,SAAS,EAAE,2BAAuBA,wCAAe,aAAa,EAAE,UAAMA,wCAAe,iBAAiB,MAAM,GAChJ;GAEA,IAAI,iBAAiBQ,8CACnB,QAAQ,aACR,UAAU,OACZ;GACA,iBAAiBC,0DAAsB,gBAAgB,UAAU,OAAO;GAQxE,IAAI,CANYC,oDACd,UAAU,SACV,gBACA,iBAGS,GACT,MAAM,IAAI,MACR,yEACF;GAGF,OAAO;EACT,CAAC,CAAC,CAAC;EAEH,oBAAoB,IAAI,QAAQ,aAAa,mBAAmB;EAGhE,kBAAkB;CACpB;CAEA,kBACE,OAAGP,kCAAS,KAAKP,wBAAW,KAAK,EAAE,YAAQC,mCAAW,cAAc,EAAE,+BACxE;CAEA,OAAO;AACT"}
@@ -16,9 +16,11 @@ let _intlayer_engine_docReview = require("@intlayer/engine/docReview");
16
16
  * @returns The structured review report.
17
17
  */
18
18
  const buildFileReviewReport = async (baseFilePath, outputFilePath, changedLines) => {
19
+ const baseText = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
20
+ const targetText = (0, node_fs.existsSync)(outputFilePath) ? await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "") : "";
19
21
  return (0, _intlayer_engine_docReview.buildReviewReport)({
20
- baseText: await (0, node_fs_promises.readFile)(baseFilePath, "utf-8"),
21
- targetText: (0, node_fs.existsSync)(outputFilePath) ? await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "") : "",
22
+ baseText,
23
+ targetText,
22
24
  changedLines
23
25
  });
24
26
  };
@@ -34,8 +36,9 @@ const buildFileReviewReport = async (baseFilePath, outputFilePath, changedLines)
34
36
  * @param configOptions - Optional Intlayer configuration overrides.
35
37
  */
36
38
  const logReviewFileBlocks = (report, baseFilePath, locale, baseLocale, configOptions) => {
39
+ const configuration = (0, _intlayer_config_node.getConfiguration)(configOptions);
37
40
  const appLogger = (0, _intlayer_config_logger.getAppLogger)({ log: {
38
- ...(0, _intlayer_config_node.getConfiguration)(configOptions).log,
41
+ ...configuration.log,
39
42
  prefix: ""
40
43
  } });
41
44
  const formatted = (0, _intlayer_engine_docReview.formatReviewReport)(report, {
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocLog.cjs","names":[],"sources":["../../../src/reviewDoc/reviewDocLog.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n buildReviewReport,\n formatReviewReport,\n type ReviewReport,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Compare a base document with its translation without calling any AI.\n *\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param outputFilePath - Absolute path of the target (translated) document.\n * @param changedLines - 1-based base line numbers that changed (from git), if any.\n * @returns The structured review report.\n */\nexport const buildFileReviewReport = async (\n baseFilePath: string,\n outputFilePath: string,\n changedLines?: number[]\n): Promise<ReviewReport> => {\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = existsSync(outputFilePath)\n ? await readFile(outputFilePath, 'utf-8').catch(() => '')\n : '';\n\n return buildReviewReport({ baseText, targetText, changedLines });\n};\n\n/**\n * Log the blocks that need attention (with their line ranges and content) for a\n * single file/locale pair, so another agent or a human can generate the missing\n * translations.\n *\n * @param report - The report built by {@link buildFileReviewReport}.\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param locale - The target locale being reviewed.\n * @param baseLocale - The base locale used as reference.\n * @param configOptions - Optional Intlayer configuration overrides.\n */\nexport const logReviewFileBlocks = (\n report: ReviewReport,\n baseFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configOptions?: GetConfigurationOptions\n): void => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger({ log: { ...configuration.log, prefix: '' } });\n\n const formatted = formatReviewReport(report, {\n baseLabel: formatLocale(baseLocale),\n targetLabel: formatLocale(locale),\n });\n\n appLogger(`${formatPath(baseFilePath)} → ${formatLocale(locale)}`);\n for (const line of formatted.split('\\n')) {\n appLogger(line);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB,OACnC,cACA,gBACA,iBAC0B;CAM1B,yDAAyB;EAAE,+CALK,cAAc,OAAO;EAKhB,oCAJP,cAAc,IACxC,qCAAe,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE,IACtD;EAE6C;CAAa,CAAC;AACjE;;;;;;;;;;;;AAaA,MAAa,uBACX,QACA,cACA,QACA,YACA,kBACS;CAET,MAAM,sDAAyB,EAAE,KAAK;EAAE,+CADD,aACgB,CAAC,CAAC;EAAK,QAAQ;CAAG,EAAE,CAAC;CAE5E,MAAM,+DAA+B,QAAQ;EAC3C,oDAAwB,UAAU;EAClC,sDAA0B,MAAM;CAClC,CAAC;CAED,UAAU,0CAAc,YAAY,EAAE,8CAAkB,MAAM,GAAG;CACjE,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GACrC,UAAU,IAAI;AAElB"}
1
+ {"version":3,"file":"reviewDocLog.cjs","names":["readFile","existsSync","buildReviewReport","getConfiguration","getAppLogger","formatReviewReport","formatLocale","formatPath"],"sources":["../../../src/reviewDoc/reviewDocLog.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n buildReviewReport,\n formatReviewReport,\n type ReviewReport,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Compare a base document with its translation without calling any AI.\n *\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param outputFilePath - Absolute path of the target (translated) document.\n * @param changedLines - 1-based base line numbers that changed (from git), if any.\n * @returns The structured review report.\n */\nexport const buildFileReviewReport = async (\n baseFilePath: string,\n outputFilePath: string,\n changedLines?: number[]\n): Promise<ReviewReport> => {\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = existsSync(outputFilePath)\n ? await readFile(outputFilePath, 'utf-8').catch(() => '')\n : '';\n\n return buildReviewReport({ baseText, targetText, changedLines });\n};\n\n/**\n * Log the blocks that need attention (with their line ranges and content) for a\n * single file/locale pair, so another agent or a human can generate the missing\n * translations.\n *\n * @param report - The report built by {@link buildFileReviewReport}.\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param locale - The target locale being reviewed.\n * @param baseLocale - The base locale used as reference.\n * @param configOptions - Optional Intlayer configuration overrides.\n */\nexport const logReviewFileBlocks = (\n report: ReviewReport,\n baseFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configOptions?: GetConfigurationOptions\n): void => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger({ log: { ...configuration.log, prefix: '' } });\n\n const formatted = formatReviewReport(report, {\n baseLabel: formatLocale(baseLocale),\n targetLabel: formatLocale(locale),\n });\n\n appLogger(`${formatPath(baseFilePath)} → ${formatLocale(locale)}`);\n for (const line of formatted.split('\\n')) {\n appLogger(line);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB,OACnC,cACA,gBACA,iBAC0B;CAC1B,MAAM,WAAW,UAAMA,2BAAS,cAAc,OAAO;CACrD,MAAM,iBAAaC,oBAAW,cAAc,IACxC,UAAMD,2BAAS,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE,IACtD;CAEJ,WAAOE,8CAAkB;EAAE;EAAU;EAAY;CAAa,CAAC;AACjE;;;;;;;;;;;;AAaA,MAAa,uBACX,QACA,cACA,QACA,YACA,kBACS;CACT,MAAM,oBAAgBC,wCAAiB,aAAa;CACpD,MAAM,gBAAYC,sCAAa,EAAE,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;CAAG,EAAE,CAAC;CAE5E,MAAM,gBAAYC,+CAAmB,QAAQ;EAC3C,eAAWC,qCAAa,UAAU;EAClC,iBAAaA,qCAAa,MAAM;CAClC,CAAC;CAED,UAAU,OAAGC,mCAAW,YAAY,EAAE,SAAKD,qCAAa,MAAM,GAAG;CACjE,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GACrC,UAAU,IAAI;AAElB"}
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocProgress.cjs","names":["spinnerFrames","ANSIColors"],"sources":["../../../src/reviewDoc/reviewDocProgress.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n spinnerFrames,\n} from '@intlayer/config/logger';\n\n/** Refresh rate of the spinner, in milliseconds. */\nconst SPINNER_INTERVAL_MS = 100;\n\nexport type ReviewProgressLogger = {\n /** Show the progress line and start animating the spinner. */\n start: () => void;\n /** Count one processed document/locale pair and refresh the progress line. */\n increment: () => void;\n /** Stop the spinner and erase the progress line. */\n stop: () => void;\n};\n\n/**\n * Single-line progress indicator used while the documents are compared with\n * their translations.\n *\n * The line is rewritten in place on an interactive terminal, then erased so the\n * final synthesis is printed on a clean line. On a non-interactive output (a\n * file, a CI log) a single static line is printed instead of the animation, to\n * avoid flooding the log with escape sequences.\n *\n * @param totalCount - Number of document/locale pairs to process.\n * @returns The progress logger handles.\n */\nexport const createReviewProgressLogger = (\n totalCount: number\n): ReviewProgressLogger => {\n const isInteractive = Boolean(process.stdout.isTTY);\n\n let spinnerTimer: NodeJS.Timeout | null = null;\n let spinnerIndex = 0;\n let processedCount = 0;\n // Until `start` is called the logger stays silent, so the caller can create it\n // unconditionally and only display it when relevant.\n let isStarted = false;\n\n const render = (): void => {\n const frame = spinnerFrames[spinnerIndex] ?? '';\n\n process.stdout.write(\n `\\r\\x1b[2K${colorize(frame, ANSIColors.BLUE)} Processing ${colorizeNumber(processedCount)}/${colorizeNumber(totalCount)}…`\n );\n };\n\n const start = (): void => {\n isStarted = true;\n\n if (!isInteractive) {\n process.stdout.write(\n `Processing ${colorizeNumber(totalCount)} document/locale pair(s)…\\n`\n );\n return;\n }\n\n if (spinnerTimer) return;\n\n render();\n\n spinnerTimer = setInterval(() => {\n spinnerIndex = (spinnerIndex + 1) % spinnerFrames.length;\n render();\n }, SPINNER_INTERVAL_MS);\n };\n\n const increment = (): void => {\n processedCount += 1;\n\n if (isStarted && isInteractive) render();\n };\n\n const stop = (): void => {\n if (spinnerTimer) {\n clearInterval(spinnerTimer);\n spinnerTimer = null;\n }\n\n if (isStarted && isInteractive) process.stdout.write('\\r\\x1b[2K');\n\n isStarted = false;\n };\n\n return { start, increment, stop };\n};\n"],"mappings":";;;;;;;;AAQA,MAAM,sBAAsB;;;;;;;;;;;;;AAuB5B,MAAa,8BACX,eACyB;CACzB,MAAM,gBAAgB,QAAQ,QAAQ,OAAO,KAAK;CAElD,IAAI,eAAsC;CAC1C,IAAI,eAAe;CACnB,IAAI,iBAAiB;CAGrB,IAAI,YAAY;CAEhB,MAAM,eAAqB;EACzB,MAAM,QAAQA,sCAAc,iBAAiB;EAE7C,QAAQ,OAAO,MACb,kDAAqB,OAAOC,wBAAW,IAAI,EAAE,0DAA6B,cAAc,EAAE,+CAAkB,UAAU,EAAE,EAC1H;CACF;CAEA,MAAM,cAAoB;EACxB,YAAY;EAEZ,IAAI,CAAC,eAAe;GAClB,QAAQ,OAAO,MACb,0DAA6B,UAAU,EAAE,4BAC3C;GACA;EACF;EAEA,IAAI,cAAc;EAElB,OAAO;EAEP,eAAe,kBAAkB;GAC/B,gBAAgB,eAAe,KAAKD,sCAAc;GAClD,OAAO;EACT,GAAG,mBAAmB;CACxB;CAEA,MAAM,kBAAwB;EAC5B,kBAAkB;EAElB,IAAI,aAAa,eAAe,OAAO;CACzC;CAEA,MAAM,aAAmB;EACvB,IAAI,cAAc;GAChB,cAAc,YAAY;GAC1B,eAAe;EACjB;EAEA,IAAI,aAAa,eAAe,QAAQ,OAAO,MAAM,WAAW;EAEhE,YAAY;CACd;CAEA,OAAO;EAAE;EAAO;EAAW;CAAK;AAClC"}
1
+ {"version":3,"file":"reviewDocProgress.cjs","names":["spinnerFrames","colorize","ANSIColors","colorizeNumber"],"sources":["../../../src/reviewDoc/reviewDocProgress.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n spinnerFrames,\n} from '@intlayer/config/logger';\n\n/** Refresh rate of the spinner, in milliseconds. */\nconst SPINNER_INTERVAL_MS = 100;\n\nexport type ReviewProgressLogger = {\n /** Show the progress line and start animating the spinner. */\n start: () => void;\n /** Count one processed document/locale pair and refresh the progress line. */\n increment: () => void;\n /** Stop the spinner and erase the progress line. */\n stop: () => void;\n};\n\n/**\n * Single-line progress indicator used while the documents are compared with\n * their translations.\n *\n * The line is rewritten in place on an interactive terminal, then erased so the\n * final synthesis is printed on a clean line. On a non-interactive output (a\n * file, a CI log) a single static line is printed instead of the animation, to\n * avoid flooding the log with escape sequences.\n *\n * @param totalCount - Number of document/locale pairs to process.\n * @returns The progress logger handles.\n */\nexport const createReviewProgressLogger = (\n totalCount: number\n): ReviewProgressLogger => {\n const isInteractive = Boolean(process.stdout.isTTY);\n\n let spinnerTimer: NodeJS.Timeout | null = null;\n let spinnerIndex = 0;\n let processedCount = 0;\n // Until `start` is called the logger stays silent, so the caller can create it\n // unconditionally and only display it when relevant.\n let isStarted = false;\n\n const render = (): void => {\n const frame = spinnerFrames[spinnerIndex] ?? '';\n\n process.stdout.write(\n `\\r\\x1b[2K${colorize(frame, ANSIColors.BLUE)} Processing ${colorizeNumber(processedCount)}/${colorizeNumber(totalCount)}…`\n );\n };\n\n const start = (): void => {\n isStarted = true;\n\n if (!isInteractive) {\n process.stdout.write(\n `Processing ${colorizeNumber(totalCount)} document/locale pair(s)…\\n`\n );\n return;\n }\n\n if (spinnerTimer) return;\n\n render();\n\n spinnerTimer = setInterval(() => {\n spinnerIndex = (spinnerIndex + 1) % spinnerFrames.length;\n render();\n }, SPINNER_INTERVAL_MS);\n };\n\n const increment = (): void => {\n processedCount += 1;\n\n if (isStarted && isInteractive) render();\n };\n\n const stop = (): void => {\n if (spinnerTimer) {\n clearInterval(spinnerTimer);\n spinnerTimer = null;\n }\n\n if (isStarted && isInteractive) process.stdout.write('\\r\\x1b[2K');\n\n isStarted = false;\n };\n\n return { start, increment, stop };\n};\n"],"mappings":";;;;;;;;AAQA,MAAM,sBAAsB;;;;;;;;;;;;;AAuB5B,MAAa,8BACX,eACyB;CACzB,MAAM,gBAAgB,QAAQ,QAAQ,OAAO,KAAK;CAElD,IAAI,eAAsC;CAC1C,IAAI,eAAe;CACnB,IAAI,iBAAiB;CAGrB,IAAI,YAAY;CAEhB,MAAM,eAAqB;EACzB,MAAM,QAAQA,sCAAc,iBAAiB;EAE7C,QAAQ,OAAO,MACb,gBAAYC,kCAAS,OAAOC,wBAAW,IAAI,EAAE,kBAAcC,wCAAe,cAAc,EAAE,OAAGA,wCAAe,UAAU,EAAE,EAC1H;CACF;CAEA,MAAM,cAAoB;EACxB,YAAY;EAEZ,IAAI,CAAC,eAAe;GAClB,QAAQ,OAAO,MACb,kBAAcA,wCAAe,UAAU,EAAE,4BAC3C;GACA;EACF;EAEA,IAAI,cAAc;EAElB,OAAO;EAEP,eAAe,kBAAkB;GAC/B,gBAAgB,eAAe,KAAKH,sCAAc;GAClD,OAAO;EACT,GAAG,mBAAmB;CACxB;CAEA,MAAM,kBAAwB;EAC5B,kBAAkB;EAElB,IAAI,aAAa,eAAe,OAAO;CACzC;CAEA,MAAM,aAAmB;EACvB,IAAI,cAAc;GAChB,cAAc,YAAY;GAC1B,eAAe;EACjB;EAEA,IAAI,aAAa,eAAe,QAAQ,OAAO,MAAM,WAAW;EAEhE,YAAY;CACd;CAEA,OAAO;EAAE;EAAO;EAAW;CAAK;AAClC"}
@@ -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,IAAIA,wBAAW,IAAI;AACrE;;AAGA,MAAM,iBACJ,OACA,MACA,OACA,SACA,oBACa;CACb,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,QAAkB,CACtB,yCAAY,MAAM,KAAK,EAAE,yCAAY,OAAO,KAAK,EAAE,gDAAmB,QAAQ,MAAM,EAAE,EACxF;CAEA,KAAK,MAAM,CAAC,SAAS,eAAe,sBAAsB,OAAO,GAAG;EA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","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;CACb,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,QAAkB,CACtB,OAAGD,kCAAS,MAAM,KAAK,EAAE,OAAGA,kCAAS,OAAO,KAAK,EAAE,QAAID,wCAAe,QAAQ,MAAM,EAAE,EACxF;CAEA,KAAK,MAAM,CAAC,SAAS,eAAe,sBAAsB,OAAO,GAAG;EAClE,MAAM,KAAK,UAAMG,mCAAW,OAAO,GAAG;EAEtC,IA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js 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,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;CAClB,MAAM,oBAAgBC,wCAAiB,QAAQ,aAAa;CAC5D,MAAM,gBAAYC,sCAAa,aAAa;CAE5C,MAAM,SAAS,UAAMC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":["../../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,MAAM,gGAAqD,aAAa;CACxE,MAAM,uEAAqC,aAAa;CAExD,MAAM,sBAKA,CAAC;CAEP,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,MAAM,mCAAmB,IAAI,IAAI,CAC/B,GAAG,OAAO,KAAK,0BAA0B,GACzC,GAAG,OAAO,KAAK,kBAAkB,CACnC,CAAC;CAED,KAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAM,eACJ,2BAA2B,kBAAkB,CAAC;EAEhD,MAAM,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,MAC9B;EAGA,KAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAM,oFACJ,YACA,OACF;GAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAAS;GACX,CAAC;EAEL;EAEA,MAAM,sBAAoC,aAAa,QACpD,eAAe,WAAW,MAC7B;EAKA,IAAI,aAAa,WAAW,GAAG;GAC7B,MAAM,mBAAmB,mBAAmB;GAE5C,IAAI,kBAAkB;IACpB,MAAM,oFACJ,kBACA,OACF;IAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;KACvB,KAAK;KACL,IAAI,iBAAiB;KACrB,UAAU,iBAAiB;KAC3B,SAAS;IACX,CAAC;GAEL;GAEA;EACF;EAEA,IAAI,oBAAoB,WAAW,GACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAM,oFACJ,kBACA,OACF;EAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;GACvB,KAAK;GACL,SAAS;EACX,CAAC;CAEL;CAEA,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SACjB,uBAAuB,mBAAmB,OAC7C,CACF;CACA,MAAM,iBAAiB,MAAM,KAAK,iBAAiB;CAMnD,OAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,QAAO,CAAE,SAAS,MAAM,CAGqB;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,OAAO,KAAK,kBAAkB,CACnC,CAAC;CAED,KAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAM,eACJ,2BAA2B,kBAAkB,CAAC;EAEhD,MAAM,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,MAC9B;EAGA,KAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAM,qBAAiBC,+DACrB,YACA,OACF;GAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAAS;GACX,CAAC;EAEL;EAEA,MAAM,sBAAoC,aAAa,QACpD,eAAe,WAAW,MAC7B;EAKA,IAAI,aAAa,WAAW,GAAG;GAC7B,MAAM,mBAAmB,mBAAmB;GAE5C,IAAI,kBAAkB;IACpB,MAAM,qBAAiBA,+DACrB,kBACA,OACF;IAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;KACvB,KAAK;KACL,IAAI,iBAAiB;KACrB,UAAU,iBAAiB;KAC3B,SAAS;IACX,CAAC;GAEL;GAEA;EACF;EAEA,IAAI,oBAAoB,WAAW,GACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAM,qBAAiBA,+DACrB,kBACA,OACF;EAEA,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;GACvB,KAAK;GACL,SAAS;EACX,CAAC;CAEL;CAEA,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SACjB,uBAAuB,mBAAmB,OAC7C,CACF;CACA,MAAM,iBAAiB,MAAM,KAAK,iBAAiB;CAMnD,OAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,QAAO,CAAE,SAAS,MAAM,CAGqB;CAAE;AACvE;AAEA,MAAa,2BACX,yBACG;CACH,MAAM,oBAAgBC,wCAAiB,oBAAoB;CAC3D,2CAAiB,oBAAoB;CAErC,OAAO,kCAAkC,aAAa;AACxD"}
@@ -1 +1 @@
1
- {"version":3,"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,SAA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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;C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;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: ${error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qB,gBAClB,MAAM,GAAG,IAAI,CAAC,CAAC,CACf,OAAO,MAAM,KAAK,MAAM,EAEZ,GAAG;KAChB,IAAI,SAAS;KACb,OACE,SAAS,eACT,gBAAgB,WAChB,gBAAgB,YAAY,IAE5B;KAEF,MAAM,iBAAiB,gBAAgB,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,EAAE;KAE/D,yDAAoB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;KACxD,sCAAgB,gBAAgB,cAAc;IAChD;;GAGF,YACE,CACE,+CAAkB,MAAM,EAAE,gBAC1B,GAAGE,wBAAW,UAAU,iDAAoB,aAAa,EAAE,IAAIA,wBAAW,OAC5E,CAAC,CAAC,KAAK,EAAE,CACX;EACF,CAAC,CACH;EAGA,MAAM,QAAQ,IAAI,KAAK;EAGvB,MAAM,cAAc,gBAAgB,KAAK,EAAE;EAC3C,IAAI,kBAAkB,SAAS,kBAAkB,eAAe;GAC9D,yDAAoB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACxD,sCAAgB,gBAAgB,WAAW;EAC7C;EAGA,MAAM,kBADcF,4BAAY,IACE,IAAI,iBAAiB,IAAI,CAAE,QAAQ,CAAC;EACtE,MAAM,uCAAwB,cAAc,OAAO,SAAS,cAAc;EAE1E,UACE,yCAAY,KAAKE,wBAAW,KAAK,EAAE,+CAAmB,YAAY,EAAE,4DAA+B,aAAa,EAAE,GACpH;EAEA,OAAO;CACT,SAAS,OAAY;EACnB,WAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,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,GAAGA,wBAAW,UAAU,OAAGC,mCAAW,YAAY,IAAID,wBAAW,UAAU,QAAIG,qCAAa,MAAM,IAAIH,wBAAW,UAAU;EAC9I,MAAM,SAAS,OAAGE,+BAAM,YAAY,EAAE,SAAS,GAAG,CAAC,IAAIF,wBAAW;EAElE,UACE,GAAG,WAAW,iBAAaI,wCAAe,WAAW,EAAE,oBACzD;EAEA,MAAM,aAAaC,+BAAU,iCAAiC,OAAO,CAAC,CAC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AE,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,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
+ {"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(' 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B;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,WAAW,UAAU;GACrB,YAAY,gBAAgB;EAC9B;EAEA,IAAI,IAAI,SAAS,KAAK;EACtB,OAAO;CACT,GACA,CAAC,CAIiD,CAAC,CAAC,SAAS,SAAS;EACtE,MAAM,QAA2B,CAAC;EAElC,IAAI,KAAK,QAAQ,UAAU,kBAAkB;GAC3C,MAAM,KAAK,IAAI;GACf,OAAO;EACT;EAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK,kBAAkB;GAC9D,MAAM,gBAAgB,KAAK,QAAQ,MAAM,GAAG,IAAI,gBAAgB;GAChE,MAAM,KAAK;IACT,SAAS;IACT,WAAW,KAAK;IAChB,YAAY;IACZ,WAAW,KAAK,YAAY;IAC5B,YAAY,cAAc;GAC5B,CAAC;EACH;EACA,OAAO;CACT,CAAC;CAED,IAAI,iBAAiB,GAAG,OAAO;CAE/B,MAAM,gBACJ,cAAc,SAAS,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC;CAEnD,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,6DAAiC,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,6DAAiC,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
+ {"version":3,"file":"calculateChunks.cjs","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,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,OAA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I,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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,yBAAM,EAAE,WAAW,MAAM,CAAC;GAChC,OAAO,aAAa,eAAe,8BAA8B,KAAK;EACxE;EAEA,UACE;GACE;yCACS,sBAAsBD,wBAAW,IAAI;GAC9C;yCACS,sBAAsBA,wBAAW,IAAI;GAC9C;yCACS,0BAA0BA,wBAAW,IAAI;GAClD;yCACS,aAAaA,wBAAW,UAAU;yCAClC,wCAAwCA,wBAAW,SAAS;yCAC5D,KAAKA,wBAAW,UAAU;GACnC;EACF,GACA,EAAE,OAAO,QAAQ,CACnB;EAEA,OAAO;CACT;CAEA,MAAM,qDAAkC,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,0DADoC,KACpB,GAAG,EAAE,OAAO,QAAQ,CAAC;EACrC,UACE;GACE;yCACS,sBAAsBA,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
+ {"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,QAAQ;EACN,UACE;GACE;GACA;OACAC,kCAAS,mCAAmCC,wBAAW,IAAI;OAC3DD,kCAAS,aAAaC,wBAAW,UAAU;OAC3CD,kCACE,6CACAC,wBAAW,SACb;OACAD,kCAAS,KAAKC,wBAAW,UAAU;GACnC;EACF,GACA,EAAE,OAAO,OAAO,CAClB;CACF;AACF;AAEA,MAAa,eAAe,OAC1B,eACA,+BAAwC,MACxC,kBAA2B,SACN;CACrB,MAA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,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"}