@intlayer/engine 9.5.10 → 9.5.11

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 (188) hide show
  1. package/dist/cjs/docReview/alignBlocks.cjs +53 -36
  2. package/dist/cjs/docReview/alignBlocks.cjs.map +1 -1
  3. package/dist/cjs/docReview/rebuildDocument.cjs +3 -1
  4. package/dist/cjs/docReview/rebuildDocument.cjs.map +1 -1
  5. package/dist/cjs/docReview/segmentDocument.cjs +8 -5
  6. package/dist/cjs/docReview/segmentDocument.cjs.map +1 -1
  7. package/dist/cjs/init/frameworkSetup/nextAppRouter/transforms.cjs +4 -1
  8. package/dist/cjs/init/frameworkSetup/nextAppRouter/transforms.cjs.map +1 -1
  9. package/dist/cjs/installMCP/installMCP.cjs +1 -1
  10. package/dist/cjs/installMCP/installMCP.cjs.map +1 -1
  11. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +3 -1
  12. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
  13. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +1 -1
  14. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
  15. package/dist/cjs/loadDictionaries/log.cjs +1 -1
  16. package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
  17. package/dist/cjs/loadDictionaries/logTypeScriptErrors.cjs +19 -12
  18. package/dist/cjs/loadDictionaries/logTypeScriptErrors.cjs.map +1 -1
  19. package/dist/cjs/scan/analyzeBundleContent.cjs +26 -12
  20. package/dist/cjs/scan/analyzeBundleContent.cjs.map +1 -1
  21. package/dist/cjs/scan/calculateScore.cjs +4 -1
  22. package/dist/cjs/scan/calculateScore.cjs.map +1 -1
  23. package/dist/cjs/scan/checks.cjs +394 -221
  24. package/dist/cjs/scan/checks.cjs.map +1 -1
  25. package/dist/cjs/scan/detection/checkDetails.cjs +56 -0
  26. package/dist/cjs/scan/detection/checkDetails.cjs.map +1 -0
  27. package/dist/cjs/scan/detection/classifyInternalLinks.cjs +47 -0
  28. package/dist/cjs/scan/detection/classifyInternalLinks.cjs.map +1 -0
  29. package/dist/cjs/scan/detection/detectRoutingStrategy.cjs +143 -0
  30. package/dist/cjs/scan/detection/detectRoutingStrategy.cjs.map +1 -0
  31. package/dist/cjs/scan/detection/detectTechnologies.cjs +89 -0
  32. package/dist/cjs/scan/detection/detectTechnologies.cjs.map +1 -0
  33. package/dist/cjs/scan/detection/index.cjs +36 -0
  34. package/dist/cjs/scan/detection/localeCode.cjs +118 -0
  35. package/dist/cjs/scan/detection/localeCode.cjs.map +1 -0
  36. package/dist/cjs/scan/detection/localizedPages.cjs +48 -0
  37. package/dist/cjs/scan/detection/localizedPages.cjs.map +1 -0
  38. package/dist/cjs/scan/detection/technologySignatures.cjs +564 -0
  39. package/dist/cjs/scan/detection/technologySignatures.cjs.map +1 -0
  40. package/dist/cjs/scan/detection/url.cjs +53 -0
  41. package/dist/cjs/scan/detection/url.cjs.map +1 -0
  42. package/dist/cjs/scan/fetchText.cjs +56 -0
  43. package/dist/cjs/scan/fetchText.cjs.map +1 -0
  44. package/dist/cjs/scan/index.cjs +59 -3
  45. package/dist/cjs/scan/parseHtml.cjs +55 -10
  46. package/dist/cjs/scan/parseHtml.cjs.map +1 -1
  47. package/dist/cjs/scan/robots.cjs +65 -0
  48. package/dist/cjs/scan/robots.cjs.map +1 -0
  49. package/dist/cjs/scan/runScanChecks.cjs +89 -0
  50. package/dist/cjs/scan/runScanChecks.cjs.map +1 -0
  51. package/dist/cjs/scan/scanWebsite.cjs +58 -52
  52. package/dist/cjs/scan/scanWebsite.cjs.map +1 -1
  53. package/dist/cjs/scan/sitemap.cjs +109 -0
  54. package/dist/cjs/scan/sitemap.cjs.map +1 -0
  55. package/dist/cjs/utils/chunkJSON.cjs +24 -9
  56. package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
  57. package/dist/cjs/utils/getChunk.cjs +2 -2
  58. package/dist/cjs/utils/getChunk.cjs.map +1 -1
  59. package/dist/cjs/utils/runParallel/index.cjs +1 -1
  60. package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
  61. package/dist/cjs/utils/runParallel/pidTree.cjs +23 -11
  62. package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -1
  63. package/dist/cjs/utils/runParallel/ps.cjs +8 -3
  64. package/dist/cjs/utils/runParallel/ps.cjs.map +1 -1
  65. package/dist/cjs/utils/runParallel/runTask.cjs +2 -1
  66. package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -1
  67. package/dist/cjs/utils/runParallel/wmic.cjs +8 -3
  68. package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -1
  69. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +7 -4
  70. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
  71. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +2 -2
  72. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -1
  73. package/dist/esm/docReview/alignBlocks.mjs +53 -36
  74. package/dist/esm/docReview/alignBlocks.mjs.map +1 -1
  75. package/dist/esm/docReview/rebuildDocument.mjs +3 -1
  76. package/dist/esm/docReview/rebuildDocument.mjs.map +1 -1
  77. package/dist/esm/docReview/segmentDocument.mjs +8 -5
  78. package/dist/esm/docReview/segmentDocument.mjs.map +1 -1
  79. package/dist/esm/init/frameworkSetup/nextAppRouter/transforms.mjs +4 -1
  80. package/dist/esm/init/frameworkSetup/nextAppRouter/transforms.mjs.map +1 -1
  81. package/dist/esm/installMCP/installMCP.mjs +1 -1
  82. package/dist/esm/installMCP/installMCP.mjs.map +1 -1
  83. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +3 -1
  84. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
  85. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +1 -1
  86. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
  87. package/dist/esm/loadDictionaries/log.mjs +1 -1
  88. package/dist/esm/loadDictionaries/log.mjs.map +1 -1
  89. package/dist/esm/loadDictionaries/logTypeScriptErrors.mjs +19 -12
  90. package/dist/esm/loadDictionaries/logTypeScriptErrors.mjs.map +1 -1
  91. package/dist/esm/scan/analyzeBundleContent.mjs +26 -12
  92. package/dist/esm/scan/analyzeBundleContent.mjs.map +1 -1
  93. package/dist/esm/scan/calculateScore.mjs +4 -1
  94. package/dist/esm/scan/calculateScore.mjs.map +1 -1
  95. package/dist/esm/scan/checks.mjs +387 -220
  96. package/dist/esm/scan/checks.mjs.map +1 -1
  97. package/dist/esm/scan/detection/checkDetails.mjs +54 -0
  98. package/dist/esm/scan/detection/checkDetails.mjs.map +1 -0
  99. package/dist/esm/scan/detection/classifyInternalLinks.mjs +46 -0
  100. package/dist/esm/scan/detection/classifyInternalLinks.mjs.map +1 -0
  101. package/dist/esm/scan/detection/detectRoutingStrategy.mjs +141 -0
  102. package/dist/esm/scan/detection/detectRoutingStrategy.mjs.map +1 -0
  103. package/dist/esm/scan/detection/detectTechnologies.mjs +87 -0
  104. package/dist/esm/scan/detection/detectTechnologies.mjs.map +1 -0
  105. package/dist/esm/scan/detection/index.mjs +10 -0
  106. package/dist/esm/scan/detection/localeCode.mjs +108 -0
  107. package/dist/esm/scan/detection/localeCode.mjs.map +1 -0
  108. package/dist/esm/scan/detection/localizedPages.mjs +46 -0
  109. package/dist/esm/scan/detection/localizedPages.mjs.map +1 -0
  110. package/dist/esm/scan/detection/technologySignatures.mjs +563 -0
  111. package/dist/esm/scan/detection/technologySignatures.mjs.map +1 -0
  112. package/dist/esm/scan/detection/url.mjs +47 -0
  113. package/dist/esm/scan/detection/url.mjs.map +1 -0
  114. package/dist/esm/scan/fetchText.mjs +55 -0
  115. package/dist/esm/scan/fetchText.mjs.map +1 -0
  116. package/dist/esm/scan/index.mjs +15 -3
  117. package/dist/esm/scan/parseHtml.mjs +52 -11
  118. package/dist/esm/scan/parseHtml.mjs.map +1 -1
  119. package/dist/esm/scan/robots.mjs +63 -0
  120. package/dist/esm/scan/robots.mjs.map +1 -0
  121. package/dist/esm/scan/runScanChecks.mjs +88 -0
  122. package/dist/esm/scan/runScanChecks.mjs.map +1 -0
  123. package/dist/esm/scan/scanWebsite.mjs +59 -53
  124. package/dist/esm/scan/scanWebsite.mjs.map +1 -1
  125. package/dist/esm/scan/sitemap.mjs +105 -0
  126. package/dist/esm/scan/sitemap.mjs.map +1 -0
  127. package/dist/esm/utils/chunkJSON.mjs +24 -9
  128. package/dist/esm/utils/chunkJSON.mjs.map +1 -1
  129. package/dist/esm/utils/getChunk.mjs +2 -2
  130. package/dist/esm/utils/getChunk.mjs.map +1 -1
  131. package/dist/esm/utils/runParallel/index.mjs +1 -1
  132. package/dist/esm/utils/runParallel/index.mjs.map +1 -1
  133. package/dist/esm/utils/runParallel/pidTree.mjs +23 -11
  134. package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
  135. package/dist/esm/utils/runParallel/ps.mjs +8 -3
  136. package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
  137. package/dist/esm/utils/runParallel/runTask.mjs +2 -1
  138. package/dist/esm/utils/runParallel/runTask.mjs.map +1 -1
  139. package/dist/esm/utils/runParallel/wmic.mjs +8 -3
  140. package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
  141. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs +7 -4
  142. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs.map +1 -1
  143. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +2 -2
  144. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -1
  145. package/dist/types/docReview/rebuildDocument.d.ts.map +1 -1
  146. package/dist/types/docReview/segmentDocument.d.ts.map +1 -1
  147. package/dist/types/init/frameworkSetup/nextAppRouter/transforms.d.ts.map +1 -1
  148. package/dist/types/loadDictionaries/logTypeScriptErrors.d.ts.map +1 -1
  149. package/dist/types/scan/analyzeBundleContent.d.ts.map +1 -1
  150. package/dist/types/scan/calculateScore.d.ts +4 -1
  151. package/dist/types/scan/calculateScore.d.ts.map +1 -1
  152. package/dist/types/scan/checks.d.ts +114 -21
  153. package/dist/types/scan/checks.d.ts.map +1 -1
  154. package/dist/types/scan/detection/checkDetails.d.ts +29 -0
  155. package/dist/types/scan/detection/checkDetails.d.ts.map +1 -0
  156. package/dist/types/scan/detection/classifyInternalLinks.d.ts +44 -0
  157. package/dist/types/scan/detection/classifyInternalLinks.d.ts.map +1 -0
  158. package/dist/types/scan/detection/detectRoutingStrategy.d.ts +60 -0
  159. package/dist/types/scan/detection/detectRoutingStrategy.d.ts.map +1 -0
  160. package/dist/types/scan/detection/detectTechnologies.d.ts +60 -0
  161. package/dist/types/scan/detection/detectTechnologies.d.ts.map +1 -0
  162. package/dist/types/scan/detection/index.d.ts +9 -0
  163. package/dist/types/scan/detection/localeCode.d.ts +49 -0
  164. package/dist/types/scan/detection/localeCode.d.ts.map +1 -0
  165. package/dist/types/scan/detection/localizedPages.d.ts +40 -0
  166. package/dist/types/scan/detection/localizedPages.d.ts.map +1 -0
  167. package/dist/types/scan/detection/technologySignatures.d.ts +48 -0
  168. package/dist/types/scan/detection/technologySignatures.d.ts.map +1 -0
  169. package/dist/types/scan/detection/url.d.ts +27 -0
  170. package/dist/types/scan/detection/url.d.ts.map +1 -0
  171. package/dist/types/scan/fetchText.d.ts +30 -0
  172. package/dist/types/scan/fetchText.d.ts.map +1 -0
  173. package/dist/types/scan/index.d.ts +16 -4
  174. package/dist/types/scan/parseHtml.d.ts +17 -0
  175. package/dist/types/scan/parseHtml.d.ts.map +1 -1
  176. package/dist/types/scan/robots.d.ts +23 -0
  177. package/dist/types/scan/robots.d.ts.map +1 -0
  178. package/dist/types/scan/runScanChecks.d.ts +43 -0
  179. package/dist/types/scan/runScanChecks.d.ts.map +1 -0
  180. package/dist/types/scan/scanWebsite.d.ts.map +1 -1
  181. package/dist/types/scan/sitemap.d.ts +49 -0
  182. package/dist/types/scan/sitemap.d.ts.map +1 -0
  183. package/dist/types/scan/types.d.ts +15 -0
  184. package/dist/types/scan/types.d.ts.map +1 -1
  185. package/dist/types/utils/chunkJSON.d.ts.map +1 -1
  186. package/dist/types/utils/runParallel/pidTree.d.ts.map +1 -1
  187. package/dist/types/writeContentDeclaration/writeMarkdownFile.d.ts.map +1 -1
  188. package/package.json +15 -7
@@ -1 +1 @@
1
- {"version":3,"file":"analyzeBundleContent.mjs","names":[],"sources":["../../../src/scan/analyzeBundleContent.ts"],"sourcesContent":["import { ALL_LOCALES } from '@intlayer/types/allLocales';\nimport { byteLength, extractVisibleTextStrings } from './parseHtml';\nimport type {\n BundleChunkInput,\n BundleContentAnalysis,\n ChunkAnalysis,\n} from './types';\n\n/**\n * Detect and measure localized (i18n) content embedded in JavaScript bundles.\n *\n * This is a dependency-free port of the hosted backend bundle analyzer: it\n * estimates how many translation strings ship in each chunk and, of those, how\n * many belong to locales other than the one currently rendered (i.e. dead\n * weight that a build-time optimization could strip).\n */\n\nconst allLocaleValues = new Set(Object.values(ALL_LOCALES) as string[]);\n\nconst isLocaleCode = (key: string): boolean =>\n allLocaleValues.has(key) || /^[a-z]{2}(-[A-Z]{2,4})?$/.test(key);\n\n/** Find the end index of the value following a `locale:` key. */\nconst extractValueEnd = (text: string, valueStart: number): number => {\n let cursor = valueStart;\n while (cursor < text.length && ' \\t\\n\\r'.includes(text[cursor])) cursor++;\n if (cursor >= text.length) return valueStart;\n\n const char = text[cursor];\n if (char === '{' || char === '[') {\n const endChar = char === '{' ? '}' : ']';\n let depth = 1;\n cursor++;\n while (cursor < text.length && depth > 0) {\n if (text[cursor] === char) depth++;\n else if (text[cursor] === endChar) depth--;\n else if (text[cursor] === '\"' || text[cursor] === '`') {\n const quote = text[cursor];\n cursor++;\n while (cursor < text.length) {\n if (text[cursor] === '\\\\') {\n cursor += 2;\n continue;\n }\n if (text[cursor] === quote) break;\n cursor++;\n }\n }\n cursor++;\n }\n return cursor;\n }\n if (char === '\"' || char === '`') {\n const quote = char;\n cursor++;\n while (cursor < text.length) {\n if (text[cursor] === '\\\\') {\n cursor += 2;\n continue;\n }\n if (text[cursor] === quote) {\n cursor++;\n break;\n }\n cursor++;\n }\n return cursor;\n }\n const endMatch = text.slice(cursor).search(/[,}\\]\\s]/);\n return endMatch === -1 ? text.length : cursor + endMatch;\n};\n\n// Matches both quoted (\"en\":) and unquoted (en:) locale keys followed by {\n// Works for any i18n solution — intlayer, i18next, vue-i18n, FormatJS, etc.\nconst LOCALE_KEY_PATTERN =\n /(?:\"([a-z]{2}(?:-[A-Z]{2,4})?)\"|\\b([a-z]{2}(?:-[A-Z]{2,4})?)\\b)\\s*:\\s*(?=\\{)/g;\n\n// Maximum character gap between two locale key positions to consider them\n// part of the same i18n object. Large enough for big translation objects.\nconst LOCALE_CLUSTER_WINDOW = 10_000;\n\n// Returns false when a candidate value is clearly not i18n text:\n// - contains hex/control escape sequences (ANSI codes, binary data)\nconst looksLikeI18nContent = (valueText: string): boolean => {\n if (/\\\\x[0-9a-fA-F]{2}/.test(valueText)) return false;\n if (/\\\\u00[01][0-9a-fA-F]/.test(valueText)) return false;\n return true;\n};\n\ntype LocaleMatch = {\n locale: string;\n position: number;\n valueStart: number;\n valueEnd: number;\n valueSize: number;\n};\n\nconst analyzeChunkLocaleContent = (\n text: string,\n baseCurrent: string\n): {\n unusedLocaleSize: number;\n usedLocaleSize: number;\n dictionariesFound: number;\n} => {\n // Step 1: collect all candidate locale key matches\n const candidates: LocaleMatch[] = [];\n const regex = new RegExp(LOCALE_KEY_PATTERN.source, 'g');\n let match = regex.exec(text);\n\n while (match !== null) {\n const locale = match[1] ?? match[2];\n if (isLocaleCode(locale)) {\n const valueStart = match.index + match[0].length;\n const valueEnd = extractValueEnd(text, valueStart);\n const valueSize = valueEnd - valueStart;\n const valueText = text.slice(valueStart, valueEnd);\n if (valueSize >= 5 && looksLikeI18nContent(valueText)) {\n candidates.push({\n locale,\n position: match.index,\n valueStart,\n valueEnd,\n valueSize,\n });\n }\n }\n match = regex.exec(text);\n }\n\n // Step 2: a locale key is i18n content only if another locale key with a\n // DIFFERENT locale code exists within LOCALE_CLUSTER_WINDOW chars.\n const isI18nMatch = (idx: number): boolean => {\n const base = candidates[idx].locale.split('-')[0].toLowerCase();\n for (let j = 0; j < candidates.length; j++) {\n if (j === idx) continue;\n const dist = Math.abs(candidates[j].position - candidates[idx].position);\n if (dist > LOCALE_CLUSTER_WINDOW) continue;\n if (candidates[j].locale.split('-')[0].toLowerCase() !== base)\n return true;\n }\n return false;\n };\n\n let unusedLocaleSize = 0;\n let usedLocaleSize = 0;\n let dictionariesFound = 0;\n\n for (let i = 0; i < candidates.length; i++) {\n if (!isI18nMatch(i)) continue;\n\n const { locale, valueSize } = candidates[i];\n dictionariesFound++;\n\n if (locale.split('-')[0].toLowerCase() === baseCurrent) {\n usedLocaleSize += valueSize;\n } else {\n unusedLocaleSize += valueSize;\n }\n }\n\n return { unusedLocaleSize, usedLocaleSize, dictionariesFound };\n};\n\n/**\n * Analyze the locale weight of a page's JavaScript bundles.\n *\n * @param chunks - The fetched JavaScript chunks (main + lazy).\n * @param htmlContent - The page HTML, used to estimate rendered content size.\n * @param currentLocale - The locale currently rendered by the page.\n * @param totalPageSize - The total transferred bytes measured for the page.\n * @returns The aggregated {@link BundleContentAnalysis}.\n */\nexport const analyzeBundleContent = (\n chunks: BundleChunkInput[],\n htmlContent: string,\n currentLocale: string,\n totalPageSize: number\n): BundleContentAnalysis => {\n const empty: BundleContentAnalysis = {\n currentLocale,\n totalPageSize,\n renderedContentSize: 0,\n contentSize: 0,\n totalLocaleSize: 0,\n totalUnusedLocaleSize: 0,\n unusedPercentOfLocale: 0,\n mainBundleChunks: [],\n lazyBundleChunks: [],\n };\n\n if (!chunks.length && !htmlContent) return empty;\n\n // Rendered content size from HTML visible text (deduplicated).\n const pageStrings = new Set(extractVisibleTextStrings(htmlContent));\n\n let renderedContentSize = 0;\n pageStrings.forEach((text) => {\n renderedContentSize += byteLength(text);\n });\n\n const baseCurrent = currentLocale.split('-')[0].toLowerCase();\n\n const mainBundleChunks: ChunkAnalysis[] = [];\n const lazyBundleChunks: ChunkAnalysis[] = [];\n\n for (const chunk of chunks) {\n const { unusedLocaleSize, usedLocaleSize, dictionariesFound } =\n analyzeChunkLocaleContent(chunk.content, baseCurrent);\n\n const totalLocaleSize = unusedLocaleSize + usedLocaleSize;\n const analysis: ChunkAnalysis = {\n url: chunk.url,\n fileSize: byteLength(chunk.content),\n totalLocaleSize,\n unusedLocaleSize,\n usedLocaleSize,\n dictionariesFound,\n unusedPercent:\n totalLocaleSize > 0\n ? Math.round((unusedLocaleSize / totalLocaleSize) * 100)\n : 0,\n };\n\n if (chunk.isMainBundle) {\n mainBundleChunks.push(analysis);\n } else if (dictionariesFound > 0) {\n lazyBundleChunks.push(analysis);\n }\n }\n\n const totalUnusedLocaleSize =\n mainBundleChunks.reduce((sum, c) => sum + c.unusedLocaleSize, 0) +\n lazyBundleChunks.reduce((sum, c) => sum + c.unusedLocaleSize, 0);\n const totalLocaleSize =\n mainBundleChunks.reduce((sum, c) => sum + c.totalLocaleSize, 0) +\n lazyBundleChunks.reduce((sum, c) => sum + c.totalLocaleSize, 0);\n const contentSize = renderedContentSize + totalLocaleSize;\n\n const unusedPercentOfLocale =\n totalLocaleSize > 0\n ? Math.round((totalUnusedLocaleSize / totalLocaleSize) * 100)\n : 0;\n\n return {\n currentLocale,\n totalPageSize,\n renderedContentSize,\n contentSize,\n totalLocaleSize,\n totalUnusedLocaleSize,\n unusedPercentOfLocale,\n mainBundleChunks,\n lazyBundleChunks,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,kBAAkB,IAAI,IAAI,OAAO,OAAO,WAAW,CAAa;AAEtE,MAAM,gBAAgB,QACpB,gBAAgB,IAAI,GAAG,KAAK,2BAA2B,KAAK,GAAG;;AAGjE,MAAM,mBAAmB,MAAc,eAA+B;CACpE,IAAI,SAAS;CACb,OAAO,SAAS,KAAK,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analyzeBundleContent.ts"],"sourcesContent":["import { ALL_LOCALES } from '@intlayer/types/allLocales';\nimport { byteLength, extractVisibleTextStrings } from './parseHtml';\nimport type {\n BundleChunkInput,\n BundleContentAnalysis,\n ChunkAnalysis,\n} from './types';\n\n/**\n * Detect and measure localized (i18n) content embedded in JavaScript bundles.\n *\n * This is a dependency-free port of the hosted backend bundle analyzer: it\n * estimates how many translation strings ship in each chunk and, of those, how\n * many belong to locales other than the one currently rendered (i.e. dead\n * weight that a build-time optimization could strip).\n */\n\nconst allLocaleValues = new Set(Object.values(ALL_LOCALES) as string[]);\n\nconst isLocaleCode = (key: string): boolean =>\n allLocaleValues.has(key) || /^[a-z]{2}(-[A-Z]{2,4})?$/.test(key);\n\n/** Find the end index of the value following a `locale:` key. */\nconst extractValueEnd = (text: string, valueStart: number): number => {\n let cursor = valueStart;\n\n while (cursor < text.length && ' \\t\\n\\r'.includes(text[cursor] ?? ''))\n cursor++;\n\n if (cursor >= text.length) return valueStart;\n\n const char = text[cursor];\n\n if (!char) return valueStart;\n\n if (char === '{' || char === '[') {\n const endChar = char === '{' ? '}' : ']';\n let depth = 1;\n cursor++;\n while (cursor < text.length && depth > 0) {\n const c = text[cursor];\n\n if (c === char) depth++;\n else if (c === endChar) depth--;\n else if (c === '\"' || c === '`') {\n const quote = c;\n cursor++;\n while (cursor < text.length) {\n if (text[cursor] === '\\\\') {\n cursor += 2;\n continue;\n }\n\n if (text[cursor] === quote) break;\n cursor++;\n }\n }\n cursor++;\n }\n return cursor;\n }\n\n if (char === '\"' || char === '`') {\n const quote = char;\n cursor++;\n while (cursor < text.length) {\n if (text[cursor] === '\\\\') {\n cursor += 2;\n continue;\n }\n\n if (text[cursor] === quote) {\n cursor++;\n break;\n }\n cursor++;\n }\n return cursor;\n }\n const endMatch = text.slice(cursor).search(/[,}\\]\\s]/);\n return endMatch === -1 ? text.length : cursor + endMatch;\n};\n\n// Matches both quoted (\"en\":) and unquoted (en:) locale keys followed by {\n// Works for any i18n solution — intlayer, i18next, vue-i18n, FormatJS, etc.\nconst LOCALE_KEY_PATTERN =\n /(?:\"([a-z]{2}(?:-[A-Z]{2,4})?)\"|\\b([a-z]{2}(?:-[A-Z]{2,4})?)\\b)\\s*:\\s*(?=\\{)/g;\n\n// Maximum character gap between two locale key positions to consider them\n// part of the same i18n object. Large enough for big translation objects.\nconst LOCALE_CLUSTER_WINDOW = 10_000;\n\n// Returns false when a candidate value is clearly not i18n text:\n// - contains hex/control escape sequences (ANSI codes, binary data)\nconst looksLikeI18nContent = (valueText: string): boolean => {\n if (/\\\\x[0-9a-fA-F]{2}/.test(valueText)) return false;\n\n if (/\\\\u00[01][0-9a-fA-F]/.test(valueText)) return false;\n return true;\n};\n\ntype LocaleMatch = {\n locale: string;\n position: number;\n valueStart: number;\n valueEnd: number;\n valueSize: number;\n};\n\nconst analyzeChunkLocaleContent = (\n text: string,\n baseCurrent: string\n): {\n unusedLocaleSize: number;\n usedLocaleSize: number;\n dictionariesFound: number;\n} => {\n // Step 1: collect all candidate locale key matches\n const candidates: LocaleMatch[] = [];\n const regex = new RegExp(LOCALE_KEY_PATTERN.source, 'g');\n let match = regex.exec(text);\n\n while (match !== null) {\n const locale = match[1] ?? match[2];\n\n if (locale && isLocaleCode(locale)) {\n const valueStart = match.index + match[0].length;\n const valueEnd = extractValueEnd(text, valueStart);\n const valueSize = valueEnd - valueStart;\n const valueText = text.slice(valueStart, valueEnd);\n\n if (valueSize >= 5 && looksLikeI18nContent(valueText)) {\n candidates.push({\n locale,\n position: match.index,\n valueStart,\n valueEnd,\n valueSize,\n });\n }\n }\n match = regex.exec(text);\n }\n\n // Step 2: a locale key is i18n content only if, within\n // LOCALE_CLUSTER_WINDOW chars, another locale key with a DIFFERENT language\n // exists AND the rendered locale is part of the cluster. The second rule\n // discards minified object keys that happen to be locale codes (`id:{`,\n // `as:{`, `to:{`…), which never come with the page locale next to them.\n const languageOf = (candidate: LocaleMatch): string =>\n (candidate.locale.split('-')[0] ?? '').toLowerCase();\n\n const isI18nMatch = (idx: number): boolean => {\n const currentCandidate = candidates[idx];\n\n if (!currentCandidate) return false;\n const base = languageOf(currentCandidate);\n let hasOtherLanguage = false;\n let hasCurrentLanguage = base === baseCurrent;\n for (let j = 0; j < candidates.length; j++) {\n if (j === idx) continue;\n const neighbor = candidates[j];\n\n if (!neighbor) continue;\n const dist = Math.abs(neighbor.position - currentCandidate.position);\n\n if (dist > LOCALE_CLUSTER_WINDOW) continue;\n const neighborLanguage = languageOf(neighbor);\n\n if (neighborLanguage !== base) hasOtherLanguage = true;\n\n if (neighborLanguage === baseCurrent) hasCurrentLanguage = true;\n\n if (hasOtherLanguage && hasCurrentLanguage) return true;\n }\n return false;\n };\n\n let unusedLocaleSize = 0;\n let usedLocaleSize = 0;\n let dictionariesFound = 0;\n\n for (let i = 0; i < candidates.length; i++) {\n if (!isI18nMatch(i)) continue;\n\n const candidate = candidates[i];\n\n if (!candidate) continue;\n const { locale, valueSize } = candidate;\n dictionariesFound++;\n\n if ((locale.split('-')[0] ?? '').toLowerCase() === baseCurrent) {\n usedLocaleSize += valueSize;\n } else {\n unusedLocaleSize += valueSize;\n }\n }\n\n return { unusedLocaleSize, usedLocaleSize, dictionariesFound };\n};\n\n/**\n * Analyze the locale weight of a page's JavaScript bundles.\n *\n * @param chunks - The fetched JavaScript chunks (main + lazy).\n * @param htmlContent - The page HTML, used to estimate rendered content size.\n * @param currentLocale - The locale currently rendered by the page.\n * @param totalPageSize - The total transferred bytes measured for the page.\n * @returns The aggregated {@link BundleContentAnalysis}.\n */\nexport const analyzeBundleContent = (\n chunks: BundleChunkInput[],\n htmlContent: string,\n currentLocale: string,\n totalPageSize: number\n): BundleContentAnalysis => {\n const empty: BundleContentAnalysis = {\n currentLocale,\n totalPageSize,\n renderedContentSize: 0,\n contentSize: 0,\n totalLocaleSize: 0,\n totalUnusedLocaleSize: 0,\n unusedPercentOfLocale: 0,\n mainBundleChunks: [],\n lazyBundleChunks: [],\n };\n\n if (!chunks.length && !htmlContent) return empty;\n\n // Rendered content size from HTML visible text (deduplicated).\n const pageStrings = new Set(extractVisibleTextStrings(htmlContent));\n\n let renderedContentSize = 0;\n pageStrings.forEach((text) => {\n renderedContentSize += byteLength(text);\n });\n\n const baseCurrent = (currentLocale.split('-')[0] ?? '').toLowerCase();\n\n const mainBundleChunks: ChunkAnalysis[] = [];\n const lazyBundleChunks: ChunkAnalysis[] = [];\n\n for (const chunk of chunks) {\n const { unusedLocaleSize, usedLocaleSize, dictionariesFound } =\n analyzeChunkLocaleContent(chunk.content, baseCurrent);\n\n const totalLocaleSize = unusedLocaleSize + usedLocaleSize;\n const analysis: ChunkAnalysis = {\n url: chunk.url,\n fileSize: byteLength(chunk.content),\n totalLocaleSize,\n unusedLocaleSize,\n usedLocaleSize,\n dictionariesFound,\n unusedPercent:\n totalLocaleSize > 0\n ? Math.round((unusedLocaleSize / totalLocaleSize) * 100)\n : 0,\n };\n\n if (chunk.isMainBundle) {\n mainBundleChunks.push(analysis);\n } else if (dictionariesFound > 0) {\n lazyBundleChunks.push(analysis);\n }\n }\n\n const totalUnusedLocaleSize =\n mainBundleChunks.reduce((sum, c) => sum + c.unusedLocaleSize, 0) +\n lazyBundleChunks.reduce((sum, c) => sum + c.unusedLocaleSize, 0);\n const totalLocaleSize =\n mainBundleChunks.reduce((sum, c) => sum + c.totalLocaleSize, 0) +\n lazyBundleChunks.reduce((sum, c) => sum + c.totalLocaleSize, 0);\n const contentSize = renderedContentSize + totalLocaleSize;\n\n const unusedPercentOfLocale =\n totalLocaleSize > 0\n ? Math.round((totalUnusedLocaleSize / totalLocaleSize) * 100)\n : 0;\n\n return {\n currentLocale,\n totalPageSize,\n renderedContentSize,\n contentSize,\n totalLocaleSize,\n totalUnusedLocaleSize,\n unusedPercentOfLocale,\n mainBundleChunks,\n lazyBundleChunks,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,kBAAkB,IAAI,IAAI,OAAO,OAAO,WAAW,CAAa;AAEtE,MAAM,gBA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,MAAM,EAAE,kBAAkB,CAAC,IAC/D,iBAAiB,QAAQ,KAAK,MAAM,MAAM,EAAE,kBAAkB,CAAC;CACjE,MAAM,kBACJ,iBAAiB,QAAQ,KAAK,MAAM,MAAM,EAAE,iBAAiB,CAAC,IAC9D,iBAAiB,QAAQ,KAAK,MAAM,MAAM,EAAE,iBAAiB,CAAC;CAChE,MAAM,cAAc,sBAAsB;CAE1C,MAAM,wBACJ,kBAAkB,IACd,KAAK,MAAO,wBAAwB,kBAAmB,GAAG,IAC1D;CAEN,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -22,10 +22,13 @@ const scoreRecord = {
22
22
  url_htmlDir: 3,
23
23
  url_hasCanonical: 10,
24
24
  url_hreflang: 9,
25
+ url_hreflangReciprocal: 8,
25
26
  url_hasLocalizedLinks: 8,
26
27
  url_hasXDefault: 7,
27
28
  url_allAnchorsLocalized: 6,
28
- url_currentLocale: 3,
29
+ url_hasLangSelector: 6,
30
+ url_currentLocale: 5,
31
+ url_ogLocale: 3,
29
32
  url_unusedBundleContent: 8
30
33
  };
31
34
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"calculateScore.mjs","names":[],"sources":["../../../src/scan/calculateScore.ts"],"sourcesContent":["/**\n * Mutualized SEO/i18n scoring logic.\n *\n * This module is the single source of truth for turning audit/scan events into\n * a weighted score. It is consumed both by the hosted backend SEO audit\n * (`apps/backend`) and by the `intlayer scan` CLI command, so it must stay free\n * of any server-only dependency (no Fastify, no Cheerio, no logger coupling).\n */\n\n/** Accumulated score across all checks that ran. */\nexport type Score = {\n /** Sum of points obtained (success = full, warning = half, error = none). */\n score: number;\n /** Maximum achievable points for the checks that ran. */\n totalScore: number;\n};\n\n/**\n * Minimal shape of an event needed to contribute to the score.\n *\n * The `type` is the check identifier. URL-scoped checks are suffixed with the\n * URL using a backslash separator (e.g. `url_htmlLang\\https://example.com`), so\n * only the part before the first backslash is used to look up the weight.\n */\nexport type ScorableEvent = {\n type?: string;\n status?: string;\n};\n\n/**\n * Resolve how many points an event contributes based on its status.\n * - `warning` → half of the weight\n * - `error` → none\n * - anything else (`success`, `started`, `done`, …) → full weight\n */\nconst scoreCheck = (score: number, event: ScorableEvent): number => {\n if (event.status === 'warning') return score / 2;\n if (event.status === 'error') return 0;\n return score;\n};\n\n/** Weight (in points) of every scorable check. */\nexport const scoreRecord = {\n robots_robotsPresent: 10,\n robots_noLocalizedUrlsForgotten: 8,\n sitemap_sitemapPresent: 10,\n sitemap_noLocalizedUrlsForgotten: 9,\n sitemap_hasAlternates: 8,\n sitemap_hasXDefault: 7,\n url_htmlLang: 9,\n url_htmlDir: 3,\n url_hasCanonical: 10,\n url_hreflang: 9,\n url_hasLocalizedLinks: 8,\n url_hasXDefault: 7,\n url_allAnchorsLocalized: 6,\n url_currentLocale: 3,\n url_unusedBundleContent: 8,\n} as const;\n\n/** Identifier of a scorable check (without the URL suffix). */\nexport type ScoreCheckType = keyof typeof scoreRecord;\n\n/**\n * Apply a single event to the running score, returning a new {@link Score}.\n * Unknown check types are ignored so the function is safe to call on every\n * emitted event.\n *\n * @param score - The current accumulated score.\n * @param event - The event to fold into the score.\n * @returns A new score with the event applied.\n */\nexport const mutateScore = (score: Score, event: ScorableEvent): Score => {\n const newScore: Score = { ...score };\n\n const typeWithoutUrl = event.type?.split('\\\\')[0];\n\n if (!typeWithoutUrl) {\n return newScore;\n }\n\n const scoreValue = scoreRecord[typeWithoutUrl as ScoreCheckType];\n\n if (typeof scoreValue === 'number') {\n newScore.score += scoreCheck(scoreValue, event);\n newScore.totalScore += scoreValue;\n }\n\n return newScore;\n};\n\n/**\n * Convert a raw {@link Score} into a 0–100 percentage.\n *\n * @param score - The accumulated score.\n * @returns The rounded percentage, or 0 when no check ran.\n */\nexport const toScorePercent = (score: Score): number =>\n Math.round(score.totalScore > 0 ? (score.score / score.totalScore) * 100 : 0);\n"],"mappings":";;;;;;;AAmCA,MAAM,cAAc,OAAe,UAAiC;CAClE,IAAI,MAAM,WAAW,WAAW,OAAO,QAAQ;CAC/C,IAAI,MAAM,WAAW,SAAS,OAAO;CACrC,OAAO;AACT;;AAGA,MAAa,cAAc;CACzB,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;;;;;;;;;;AAcA,MAAa,eAAe,OAAc,UAAgC;CACxE,MAAM,WAAkB,EAAE,GAAG,MAAM;CAEnC,MAAM,iBAAiB,MAAM,MAAM,MAAM,IAAI,CAAC,CAAC;CAE/C,IAAI,CAAC,gBACH,OAAO;CAGT,MAAM,aAAa,YAAY;CAE/B,IAAI,OAAO,eAAe,UAAU;EAClC,SAAS,SAAS,WAAW,YAAY,KAAK;EAC9C,SAAS,cAAc;CACzB;CAEA,OAAO;AACT;;;;;;;AAQA,MAAa,kBAAkB,UAC7B,KAAK,MAAM,MAAM,aAAa,IAAK,MAAM,QAAQ,MAAM,aAAc,MAAM,CAAC"}
1
+ {"version":3,"file":"calculateScore.mjs","names":[],"sources":["../../../src/scan/calculateScore.ts"],"sourcesContent":["/**\n * Mutualized SEO/i18n scoring logic.\n *\n * This module is the single source of truth for turning audit/scan events into\n * a weighted score. It is consumed both by the hosted backend SEO audit\n * (`apps/backend`) and by the `intlayer scan` CLI command, so it must stay free\n * of any server-only dependency (no Fastify, no Cheerio, no logger coupling).\n */\n\n/** Accumulated score across all checks that ran. */\nexport type Score = {\n /** Sum of points obtained (success = full, warning = half, error = none). */\n score: number;\n /** Maximum achievable points for the checks that ran. */\n totalScore: number;\n};\n\n/**\n * Minimal shape of an event needed to contribute to the score.\n *\n * The `type` is the check identifier. URL-scoped checks are suffixed with the\n * URL using a backslash separator (e.g. `url_htmlLang\\https://example.com`), so\n * only the part before the first backslash is used to look up the weight.\n */\nexport type ScorableEvent = {\n type?: string;\n status?: string;\n};\n\n/**\n * Resolve how many points an event contributes based on its status.\n * - `warning` → half of the weight\n * - `error` → none\n * - anything else (`success`, `started`, `done`, …) → full weight\n */\nconst scoreCheck = (score: number, event: ScorableEvent): number => {\n if (event.status === 'warning') return score / 2;\n if (event.status === 'error') return 0;\n return score;\n};\n\n/** Weight (in points) of every scorable check. */\nexport const scoreRecord = {\n robots_robotsPresent: 10,\n robots_noLocalizedUrlsForgotten: 8,\n sitemap_sitemapPresent: 10,\n sitemap_noLocalizedUrlsForgotten: 9,\n sitemap_hasAlternates: 8,\n sitemap_hasXDefault: 7,\n url_htmlLang: 9,\n url_htmlDir: 3,\n url_hasCanonical: 10,\n url_hreflang: 9,\n url_hreflangReciprocal: 8,\n url_hasLocalizedLinks: 8,\n url_hasXDefault: 7,\n url_allAnchorsLocalized: 6,\n url_hasLangSelector: 6,\n url_currentLocale: 5,\n url_ogLocale: 3,\n url_unusedBundleContent: 8,\n} as const;\n\n/** Identifier of a scorable check (without the URL suffix). */\nexport type ScoreCheckType = keyof typeof scoreRecord;\n\n/**\n * Apply a single event to the running score, returning a new {@link Score}.\n * Unknown check types are ignored so the function is safe to call on every\n * emitted event.\n *\n * @param score - The current accumulated score.\n * @param event - The event to fold into the score.\n * @returns A new score with the event applied.\n */\nexport const mutateScore = (score: Score, event: ScorableEvent): Score => {\n const newScore: Score = { ...score };\n\n const typeWithoutUrl = event.type?.split('\\\\')[0];\n\n if (!typeWithoutUrl) {\n return newScore;\n }\n\n const scoreValue = scoreRecord[typeWithoutUrl as ScoreCheckType];\n\n if (typeof scoreValue === 'number') {\n newScore.score += scoreCheck(scoreValue, event);\n newScore.totalScore += scoreValue;\n }\n\n return newScore;\n};\n\n/**\n * Convert a raw {@link Score} into a 0–100 percentage.\n *\n * @param score - The accumulated score.\n * @returns The rounded percentage, or 0 when no check ran.\n */\nexport const toScorePercent = (score: Score): number =>\n Math.round(score.totalScore > 0 ? (score.score / score.totalScore) * 100 : 0);\n"],"mappings":";;;;;;;AAmCA,MAAM,cAAc,OAAe,UAAiC;CAClE,IAAI,MAAM,WAAW,WAAW,OAAO,QAAQ;CAC/C,IAAI,MAAM,WAAW,SAAS,OAAO;CACrC,OAAO;AACT;;AAGA,MAAa,cAAc;CACzB,sBAAsB;CACtB,iCAAiC;CACjC,wBAAwB;CACxB,kCAAkC;CAClC,uBAAuB;CACvB,qBAAqB;CACrB,cAAc;CACd,aAAa;CACb,kBAAkB;CAClB,cAAc;CACd,wBAAwB;CACxB,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,qBAAqB;CACrB,mBAAmB;CACnB,cAAc;CACd,yBAAyB;AAC3B;;;;;;;;;;AAcA,MAAa,eAAe,OAAc,UAAgC;CACxE,MAAM,WAAkB,EAAE,GAAG,MAAM;CAEnC,MAAM,iBAAiB,MAAM,MAAM,MAAM,IAAI,CAAC,CAAC;CAE/C,IAAI,CAAC,gBACH,OAAO;CAGT,MAAM,aAAa,YAAY;CAE/B,IAAI,OAAO,eAAe,UAAU;EAClC,SAAS,SAAS,WAAW,YAAY,KAAK;EAC9C,SAAS,cAAc;CACzB;CAEA,OAAO;AACT;;;;;;;AAQA,MAAa,kBAAkB,UAC7B,KAAK,MAAM,MAAM,aAAa,IAAK,MAAM,QAAQ,MAAM,aAAc,MAAM,CAAC"}