@formatjs/cli 6.4.2 → 6.5.0

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 (2) hide show
  1. package/bin/formatjs +61 -81
  2. package/package.json +2 -2
package/bin/formatjs CHANGED
@@ -12469,88 +12469,60 @@ var require_manipulator = __commonJS({
12469
12469
  }
12470
12470
  return ast;
12471
12471
  }
12472
- function isStructurallySamePluralOrSelect(el1, el2) {
12473
- var options1 = el1.options;
12474
- var options2 = el2.options;
12475
- if (Object.keys(options1).length !== Object.keys(options2).length) {
12476
- return false;
12472
+ function collectVariables(ast, vars) {
12473
+ if (vars === void 0) {
12474
+ vars = /* @__PURE__ */ new Map();
12477
12475
  }
12478
- for (var key in options1) {
12479
- if (!options2[key]) {
12480
- return false;
12476
+ ast.forEach(function(el) {
12477
+ if ((0, types_1.isArgumentElement)(el) || (0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el) || (0, types_1.isNumberElement)(el)) {
12478
+ if (el.value in vars && vars.get(el.value) !== el.type) {
12479
+ throw new Error("Variable ".concat(el.value, " has conflicting types"));
12480
+ }
12481
+ vars.set(el.value, el.type);
12481
12482
  }
12482
- if (!isStructurallySame2(options1[key].value, options2[key].value)) {
12483
- return false;
12483
+ if ((0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el)) {
12484
+ vars.set(el.value, el.type);
12485
+ Object.keys(el.options).forEach(function(k) {
12486
+ collectVariables(el.options[k].value, vars);
12487
+ });
12484
12488
  }
12485
- }
12486
- return true;
12489
+ if ((0, types_1.isTagElement)(el)) {
12490
+ vars.set(el.value, el.type);
12491
+ collectVariables(el.children, vars);
12492
+ }
12493
+ });
12487
12494
  }
12488
12495
  function isStructurallySame2(a, b) {
12489
- var aWithoutLiteral = a.filter(function(el) {
12490
- return !(0, types_1.isLiteralElement)(el);
12491
- });
12492
- var bWithoutLiteral = b.filter(function(el) {
12493
- return !(0, types_1.isLiteralElement)(el);
12494
- });
12495
- if (aWithoutLiteral.length !== bWithoutLiteral.length) {
12496
- return false;
12496
+ var aVars = /* @__PURE__ */ new Map();
12497
+ var bVars = /* @__PURE__ */ new Map();
12498
+ collectVariables(a, aVars);
12499
+ collectVariables(b, bVars);
12500
+ if (aVars.size !== bVars.size) {
12501
+ return {
12502
+ success: false,
12503
+ error: new Error("Different number of variables: [".concat(Array.from(aVars.keys()).join(", "), "] vs [").concat(Array.from(bVars.keys()).join(", "), "]"))
12504
+ };
12497
12505
  }
12498
- var elementsMapInA = aWithoutLiteral.reduce(function(all, el) {
12499
- if ((0, types_1.isPoundElement)(el)) {
12500
- all["#"] = el;
12501
- return all;
12502
- }
12503
- all[el.value] = el;
12504
- return all;
12505
- }, {});
12506
- var elementsMapInB = bWithoutLiteral.reduce(function(all, el) {
12507
- if ((0, types_1.isPoundElement)(el)) {
12508
- all["#"] = el;
12509
- return all;
12510
- }
12511
- all[el.value] = el;
12512
- return all;
12513
- }, {});
12514
- for (var _i = 0, _a = Object.keys(elementsMapInA); _i < _a.length; _i++) {
12515
- var varName = _a[_i];
12516
- var elA = elementsMapInA[varName];
12517
- var elB = elementsMapInB[varName];
12518
- if (!elB) {
12519
- return false;
12520
- }
12521
- if (elA.type !== elB.type) {
12522
- return false;
12523
- }
12524
- if ((0, types_1.isLiteralElement)(elA) || (0, types_1.isLiteralElement)(elB)) {
12525
- continue;
12526
- }
12527
- if ((0, types_1.isArgumentElement)(elA) && (0, types_1.isArgumentElement)(elB) && elA.value !== elB.value) {
12528
- return false;
12529
- }
12530
- if ((0, types_1.isPoundElement)(elA) || (0, types_1.isPoundElement)(elB)) {
12531
- continue;
12532
- }
12533
- if ((0, types_1.isDateElement)(elA) || (0, types_1.isTimeElement)(elA) || (0, types_1.isNumberElement)(elA) || (0, types_1.isDateElement)(elB) || (0, types_1.isTimeElement)(elB) || (0, types_1.isNumberElement)(elB)) {
12534
- if (elA.value !== elB.value) {
12535
- return false;
12536
- }
12537
- }
12538
- if ((0, types_1.isPluralElement)(elA) && (0, types_1.isPluralElement)(elB) && !isStructurallySamePluralOrSelect(elA, elB)) {
12539
- return false;
12506
+ return Array.from(aVars.entries()).reduce(function(result, _a) {
12507
+ var key = _a[0], type = _a[1];
12508
+ if (!result.success) {
12509
+ return result;
12540
12510
  }
12541
- if ((0, types_1.isSelectElement)(elA) && (0, types_1.isSelectElement)(elB) && isStructurallySamePluralOrSelect(elA, elB)) {
12542
- return false;
12511
+ var bType = bVars.get(key);
12512
+ if (bType == null) {
12513
+ return {
12514
+ success: false,
12515
+ error: new Error("Missing variable ".concat(key, " in message"))
12516
+ };
12543
12517
  }
12544
- if ((0, types_1.isTagElement)(elA) && (0, types_1.isTagElement)(elB)) {
12545
- if (elA.value !== elB.value) {
12546
- return false;
12547
- }
12548
- if (!isStructurallySame2(elA.children, elB.children)) {
12549
- return false;
12550
- }
12518
+ if (bType !== type) {
12519
+ return {
12520
+ success: false,
12521
+ error: new Error("Variable ".concat(key, " has conflicting types: ").concat(types_1.TYPE[type], " vs ").concat(types_1.TYPE[bType]))
12522
+ };
12551
12523
  }
12552
- }
12553
- return true;
12524
+ return result;
12525
+ }, { success: true });
12554
12526
  }
12555
12527
  }
12556
12528
  });
@@ -228049,19 +228021,25 @@ async function checkStructuralEquality(translationFilesContents, sourceLocale) {
228049
228021
  }, {});
228050
228022
  return Object.entries(translationFilesContents).filter(([locale]) => locale !== sourceLocale).reduce((result, [locale, content]) => {
228051
228023
  const localeMessages = flatten(content);
228052
- const problematicKeys = Object.keys(enUSMessages).filter((k) => {
228024
+ const problematicKeys = Object.keys(enUSMessages).map((k) => {
228053
228025
  if (!localeMessages[k]) {
228054
- return false;
228026
+ return { key: k, success: true };
228055
228027
  }
228056
228028
  const enUSMessage = enUSMessages[k];
228057
228029
  try {
228058
228030
  const localeMessage = (0, import_icu_messageformat_parser4.parse)(localeMessages[k]);
228059
- return !(0, import_icu_messageformat_parser4.isStructurallySame)(enUSMessage, localeMessage);
228031
+ return {
228032
+ key: k,
228033
+ ...(0, import_icu_messageformat_parser4.isStructurallySame)(enUSMessage, localeMessage)
228034
+ };
228060
228035
  } catch (e) {
228061
- (0, import_console.error)("Error comparing message", k, enUSMessage, localeMessages[k], e);
228062
- return true;
228036
+ return {
228037
+ key: k,
228038
+ success: false,
228039
+ error: e instanceof Error ? e : new Error(String(e))
228040
+ };
228063
228041
  }
228064
- });
228042
+ }).filter((s) => !s.success);
228065
228043
  if (!problematicKeys.length) {
228066
228044
  return result;
228067
228045
  }
@@ -228070,8 +228048,10 @@ async function checkStructuralEquality(translationFilesContents, sourceLocale) {
228070
228048
  `These translation keys for locale ${locale} are structurally different from ${sourceLocale}:
228071
228049
  `
228072
228050
  );
228073
- problematicKeys.forEach((r) => writeStderr(`${r}
228074
- `));
228051
+ problematicKeys.forEach(
228052
+ ({ key, error: error2 }) => writeStderr(`${key}: ${error2 == null ? void 0 : error2.message}
228053
+ `)
228054
+ );
228075
228055
  return false;
228076
228056
  }, true);
228077
228057
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/cli",
3
- "version": "6.4.2",
3
+ "version": "6.5.0",
4
4
  "description": "A CLI for formatjs.",
5
5
  "keywords": [
6
6
  "intl",
@@ -33,7 +33,7 @@
33
33
  "url": "https://github.com/formatjs/formatjs/issues"
34
34
  },
35
35
  "devDependencies": {
36
- "@formatjs/cli-lib": "7.1.2"
36
+ "@formatjs/cli-lib": "7.2.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@glimmer/env": "^0.1.7",