@vocoder/cli 0.13.4 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43569,6 +43569,11 @@ var require_brace_expansion = __commonJS({
43569
43569
  });
43570
43570
 
43571
43571
  // src/utils/api.ts
43572
+ function computeStringsHash(input) {
43573
+ const { createHash } = __require("crypto");
43574
+ const sorted = [...input.texts].sort();
43575
+ return createHash("sha256").update(JSON.stringify({ strings: sorted, appIndustry: input.appIndustry ?? null })).digest("hex");
43576
+ }
43572
43577
  function isLimitErrorResponse(value) {
43573
43578
  if (!value || typeof value !== "object") {
43574
43579
  return false;
@@ -43672,7 +43677,6 @@ var VocoderAPI = class {
43672
43677
  return {
43673
43678
  projectName: data.projectName,
43674
43679
  organizationName: data.organizationName,
43675
- shortCode: data.shortCode,
43676
43680
  sourceLocale: data.sourceLocale,
43677
43681
  targetLocales: data.targetLocales,
43678
43682
  targetBranches: data.targetBranches ?? ["main"],
@@ -43722,9 +43726,7 @@ var VocoderAPI = class {
43722
43726
  async submitTranslation(branch, entries, targetLocales, options, repoIdentity) {
43723
43727
  const stringEntries = this.normalizeStringEntries(entries);
43724
43728
  const strings = stringEntries.map((entry) => entry.text);
43725
- const crypto = await import("crypto");
43726
- const sortedStrings = [...strings].sort();
43727
- const stringsHash = crypto.createHash("sha256").update(JSON.stringify(sortedStrings)).digest("hex");
43729
+ const stringsHash = computeStringsHash({ texts: strings, appIndustry: options?.appIndustry ?? null });
43728
43730
  return this.request(
43729
43731
  "/api/cli/sync",
43730
43732
  {
@@ -51120,34 +51122,64 @@ function buildSelectICU(props) {
51120
51122
  if (!hasOther) cases.push("other {other}");
51121
51123
  return `{value, select, ${cases.join(" ")}}`;
51122
51124
  }
51123
- function extractTextContentFromNodes(children, elementIndex = { count: 0 }) {
51125
+ function extractTextContentFromNodes(children, ctx) {
51124
51126
  let text = "";
51125
51127
  for (const child of children) {
51128
+ if (ctx.bail) return text;
51126
51129
  if (child.type === "JSXText") {
51127
51130
  text += child.value;
51128
51131
  } else if (child.type === "JSXExpressionContainer") {
51129
51132
  const expr = child.expression;
51130
51133
  if (expr.type === "Identifier") {
51134
+ ctx.namedVars.add(expr.name);
51131
51135
  text += `{${expr.name}}`;
51132
51136
  } else if (expr.type === "StringLiteral") {
51133
51137
  text += expr.value;
51138
+ } else if (expr.type === "NumericLiteral") {
51139
+ text += String(expr.value);
51140
+ } else if (expr.type === "BooleanLiteral" || expr.type === "NullLiteral") {
51134
51141
  } else if (expr.type === "TemplateLiteral") {
51135
51142
  for (let i = 0; i < expr.quasis.length; i++) {
51136
51143
  text += expr.quasis[i].value.raw;
51137
51144
  if (i < expr.expressions.length) {
51138
51145
  const e = expr.expressions[i];
51139
- text += e.type === "Identifier" ? `{${e.name}}` : "{value}";
51146
+ if (e.type === "Identifier") {
51147
+ ctx.namedVars.add(e.name);
51148
+ text += `{${e.name}}`;
51149
+ } else if (e.type === "NumericLiteral") {
51150
+ text += String(e.value);
51151
+ } else if (e.type === "BooleanLiteral" || e.type === "NullLiteral") {
51152
+ } else if (e.type === "ConditionalExpression" || e.type === "LogicalExpression") {
51153
+ ctx.bail = true;
51154
+ return text;
51155
+ } else {
51156
+ const key = ctx.complexCount++;
51157
+ ctx.complexExprs.push({ key, start: e.start, end: e.end });
51158
+ text += `{${key}}`;
51159
+ }
51140
51160
  }
51141
51161
  }
51162
+ } else if (expr.type === "ConditionalExpression" || expr.type === "LogicalExpression") {
51163
+ ctx.bail = true;
51164
+ return text;
51165
+ } else {
51166
+ const key = ctx.complexCount++;
51167
+ ctx.complexExprs.push({ key, start: expr.start, end: expr.end });
51168
+ text += `{${key}}`;
51142
51169
  }
51143
51170
  } else if (child.type === "JSXElement") {
51144
- const idx = elementIndex.count++;
51171
+ const childTagName = child.openingElement.name.type === "JSXIdentifier" ? child.openingElement.name.name : null;
51172
+ if (childTagName && ctx.tComponentNames.has(childTagName)) {
51173
+ ctx.bail = true;
51174
+ return text;
51175
+ }
51176
+ const idx = ctx.elementCount++;
51145
51177
  const isSelfClosing = child.openingElement.selfClosing;
51146
51178
  if (isSelfClosing) {
51147
- text += `<c${idx}/>`;
51179
+ text += `<${idx}/>`;
51148
51180
  } else {
51149
- const innerText = extractTextContentFromNodes(child.children, elementIndex);
51150
- text += `<c${idx}>${innerText}</c${idx}>`;
51181
+ const innerText = extractTextContentFromNodes(child.children, ctx);
51182
+ text += `<${idx}>${innerText}</${idx}>`;
51151
51183
  }
51152
51184
  }
51153
51185
  }
@@ -51359,7 +51391,16 @@ function _extractFromContent(filePath, content) {
51359
51391
  if (pluralSelectICU) {
51360
51392
  text = pluralSelectICU;
51361
51393
  } else {
51362
- text = extractTextContentFromNodes(path2.node.children, { count: 0 });
51394
+ const extractCtx = {
51395
+ elementCount: 0,
51396
+ complexCount: 0,
51397
+ namedVars: /* @__PURE__ */ new Set(),
51398
+ complexExprs: [],
51399
+ bail: false,
51400
+ tComponentNames: new Set(vocoderImports.keys())
51401
+ };
51402
+ text = extractTextContentFromNodes(path2.node.children, extractCtx);
51403
+ if (extractCtx.bail) return;
51363
51404
  }
51364
51405
  }
51365
51406
  if (!text || text.trim().length === 0) return;
@@ -51500,4 +51541,4 @@ export {
51500
51541
  loadVocoderConfig,
51501
51542
  StringExtractor
51502
51543
  };
51503
- //# sourceMappingURL=chunk-ZHRKJ2KZ.mjs.map
51544
+ //# sourceMappingURL=chunk-LLEMSC3X.mjs.map