ai-localize-reporting 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # ai-localize-reporting
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - **Bug fix — `report` crashed with `RangeError: Invalid count value`**: The CLI reporter
8
+ computed translation coverage as `(totalUniqueKeys - missingKeys.length) / totalUniqueKeys * 100`.
9
+ Because `missingKeys` are recorded per-language (e.g. 5 unique keys × 2 target languages = 10
10
+ entries), coverage went negative when all keys were untranslated, causing `String.prototype.repeat()`
11
+ to throw. Three fixes applied to `printCliSummary()`:
12
+ - Coverage now counts **distinct** missing key names (`new Set(missingKeys.map(mk => mk.key)).size`)
13
+ instead of raw array length, giving the correct per-key missing count.
14
+ - `coveragePct` is clamped to `[0, 100]` with `Math.max(0, Math.min(100, …))`.
15
+ - `progressBar()`, `miniBar()`, and the `renderTable()` center-align branch all guard
16
+ `filled`, `empty`, and padding values with `Math.max(0, …)` to prevent negative repeats.
17
+ (`packages/reporting/src/cli-reporter.ts`)
18
+
19
+ ## 2.0.4
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+ - ai-localize-shared@2.0.4
25
+
3
26
  ## 2.0.3
4
27
 
5
28
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1697,17 +1697,18 @@ function badge2(text, ok) {
1697
1697
  return ok ? c("bgGreen", c("black", ` ${text} `)) : c("bgRed", c("white", ` ${text} `));
1698
1698
  }
1699
1699
  function miniBar(value, max, width = 20, color = "cyan") {
1700
- const filled = max > 0 ? Math.round(value / max * width) : 0;
1700
+ const filled = max > 0 ? Math.max(0, Math.min(width, Math.round(value / max * width))) : 0;
1701
1701
  const empty = width - filled;
1702
1702
  const bar = c(color, "\u2588".repeat(filled)) + dim("\u2591".repeat(empty));
1703
1703
  return "[" + bar + "]";
1704
1704
  }
1705
1705
  function progressBar(pct, width = 24) {
1706
- const filled = Math.round(pct / 100 * width);
1706
+ const safePct = Math.max(0, Math.min(100, pct));
1707
+ const filled = Math.max(0, Math.min(width, Math.round(safePct / 100 * width)));
1707
1708
  const empty = width - filled;
1708
1709
  let color = "brightGreen";
1709
- if (pct < 50) color = "brightRed";
1710
- else if (pct < 80) color = "brightYellow";
1710
+ if (safePct < 50) color = "brightRed";
1711
+ else if (safePct < 80) color = "brightYellow";
1711
1712
  const bar = c(color, "\u2588".repeat(filled)) + dim("\u2591".repeat(empty));
1712
1713
  return "[" + bar + "]";
1713
1714
  }
@@ -1738,8 +1739,10 @@ function renderTable(columns, rows) {
1738
1739
  if (isHeader) s = bold(strip(s));
1739
1740
  if (col?.align === "right") s = padStart(s, w);
1740
1741
  else if (col?.align === "center") {
1741
- const p = Math.floor((w - visLen(s)) / 2);
1742
- s = " ".repeat(p) + s + " ".repeat(w - visLen(s) - p);
1742
+ const visibleLen = visLen(s);
1743
+ const p = Math.max(0, Math.floor((w - visibleLen) / 2));
1744
+ const q = Math.max(0, w - visibleLen - p);
1745
+ s = " ".repeat(p) + s + " ".repeat(q);
1743
1746
  } else {
1744
1747
  s = padEnd(s, w);
1745
1748
  }
@@ -1760,7 +1763,8 @@ function renderTable(columns, rows) {
1760
1763
  function computeCliInsights(report) {
1761
1764
  const { details } = report;
1762
1765
  const totalUniqueKeys = new Set(details.detectedTexts.map((d) => d.suggestedKey)).size;
1763
- const coveragePct = totalUniqueKeys > 0 ? Math.round((totalUniqueKeys - details.missingKeys.length) / totalUniqueKeys * 100) : 100;
1766
+ const missingUniqueKeys = new Set(details.missingKeys.map((mk) => mk.key)).size;
1767
+ const coveragePct = totalUniqueKeys > 0 ? Math.max(0, Math.min(100, Math.round((totalUniqueKeys - missingUniqueKeys) / totalUniqueKeys * 100))) : 100;
1764
1768
  const textMap = /* @__PURE__ */ new Map();
1765
1769
  for (const dt of details.detectedTexts) {
1766
1770
  const t = dt.text.trim();
package/dist/index.mjs CHANGED
@@ -1659,17 +1659,18 @@ function badge2(text, ok) {
1659
1659
  return ok ? c("bgGreen", c("black", ` ${text} `)) : c("bgRed", c("white", ` ${text} `));
1660
1660
  }
1661
1661
  function miniBar(value, max, width = 20, color = "cyan") {
1662
- const filled = max > 0 ? Math.round(value / max * width) : 0;
1662
+ const filled = max > 0 ? Math.max(0, Math.min(width, Math.round(value / max * width))) : 0;
1663
1663
  const empty = width - filled;
1664
1664
  const bar = c(color, "\u2588".repeat(filled)) + dim("\u2591".repeat(empty));
1665
1665
  return "[" + bar + "]";
1666
1666
  }
1667
1667
  function progressBar(pct, width = 24) {
1668
- const filled = Math.round(pct / 100 * width);
1668
+ const safePct = Math.max(0, Math.min(100, pct));
1669
+ const filled = Math.max(0, Math.min(width, Math.round(safePct / 100 * width)));
1669
1670
  const empty = width - filled;
1670
1671
  let color = "brightGreen";
1671
- if (pct < 50) color = "brightRed";
1672
- else if (pct < 80) color = "brightYellow";
1672
+ if (safePct < 50) color = "brightRed";
1673
+ else if (safePct < 80) color = "brightYellow";
1673
1674
  const bar = c(color, "\u2588".repeat(filled)) + dim("\u2591".repeat(empty));
1674
1675
  return "[" + bar + "]";
1675
1676
  }
@@ -1700,8 +1701,10 @@ function renderTable(columns, rows) {
1700
1701
  if (isHeader) s = bold(strip(s));
1701
1702
  if (col?.align === "right") s = padStart(s, w);
1702
1703
  else if (col?.align === "center") {
1703
- const p = Math.floor((w - visLen(s)) / 2);
1704
- s = " ".repeat(p) + s + " ".repeat(w - visLen(s) - p);
1704
+ const visibleLen = visLen(s);
1705
+ const p = Math.max(0, Math.floor((w - visibleLen) / 2));
1706
+ const q = Math.max(0, w - visibleLen - p);
1707
+ s = " ".repeat(p) + s + " ".repeat(q);
1705
1708
  } else {
1706
1709
  s = padEnd(s, w);
1707
1710
  }
@@ -1722,7 +1725,8 @@ function renderTable(columns, rows) {
1722
1725
  function computeCliInsights(report) {
1723
1726
  const { details } = report;
1724
1727
  const totalUniqueKeys = new Set(details.detectedTexts.map((d) => d.suggestedKey)).size;
1725
- const coveragePct = totalUniqueKeys > 0 ? Math.round((totalUniqueKeys - details.missingKeys.length) / totalUniqueKeys * 100) : 100;
1728
+ const missingUniqueKeys = new Set(details.missingKeys.map((mk) => mk.key)).size;
1729
+ const coveragePct = totalUniqueKeys > 0 ? Math.max(0, Math.min(100, Math.round((totalUniqueKeys - missingUniqueKeys) / totalUniqueKeys * 100))) : 100;
1726
1730
  const textMap = /* @__PURE__ */ new Map();
1727
1731
  for (const dt of details.detectedTexts) {
1728
1732
  const t = dt.text.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-localize-reporting",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Localization scan reporting: JSON, HTML analytics dashboard and CLI summary",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "node": ">=18.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "ai-localize-shared": "2.0.4"
36
+ "ai-localize-shared": "2.0.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^8.0.1",