lingo.dev 0.85.6 → 0.86.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.
package/build/cli.mjs CHANGED
@@ -1032,6 +1032,8 @@ function createLoader(lDefinition) {
1032
1032
  const state = {
1033
1033
  defaultLocale: void 0,
1034
1034
  originalInput: void 0,
1035
+ pullInput: void 0,
1036
+ pullOutput: void 0,
1035
1037
  initCtx: void 0
1036
1038
  };
1037
1039
  return {
@@ -1059,7 +1061,10 @@ function createLoader(lDefinition) {
1059
1061
  if (locale === state.defaultLocale) {
1060
1062
  state.originalInput = input2 || null;
1061
1063
  }
1062
- return lDefinition.pull(locale, input2, state.initCtx);
1064
+ state.pullInput = input2;
1065
+ const result = await lDefinition.pull(locale, input2, state.initCtx);
1066
+ state.pullOutput = result;
1067
+ return result;
1063
1068
  },
1064
1069
  async push(locale, data) {
1065
1070
  if (!state.defaultLocale) {
@@ -1068,7 +1073,14 @@ function createLoader(lDefinition) {
1068
1073
  if (state.originalInput === void 0) {
1069
1074
  throw new Error("Cannot push data without pulling first");
1070
1075
  }
1071
- const pushResult = await lDefinition.push(locale, data, state.originalInput, state.defaultLocale);
1076
+ const pushResult = await lDefinition.push(
1077
+ locale,
1078
+ data,
1079
+ state.originalInput,
1080
+ state.defaultLocale,
1081
+ state.pullInput,
1082
+ state.pullOutput
1083
+ );
1072
1084
  return pushResult;
1073
1085
  }
1074
1086
  };
@@ -1629,25 +1641,41 @@ ${content}`;
1629
1641
  import _9 from "lodash";
1630
1642
  import { unified } from "unified";
1631
1643
  import remarkParse from "remark-parse";
1632
- import remarkMdx from "remark-mdx";
1633
1644
  import remarkFrontmatter from "remark-frontmatter";
1634
1645
  import remarkGfm from "remark-gfm";
1635
1646
  import remarkStringify from "remark-stringify";
1636
- import remarkMdxFrontmatter from "remark-mdx-frontmatter";
1637
1647
  import { VFile } from "vfile";
1638
- var parser = unified().use(remarkParse).use(remarkMdx).use(remarkFrontmatter, ["yaml"]).use(remarkMdxFrontmatter).use(remarkGfm);
1639
- var serializer = unified().use(remarkStringify).use(remarkMdx).use(remarkFrontmatter, ["yaml"]).use(remarkMdxFrontmatter).use(remarkGfm);
1648
+ var parser = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(remarkGfm);
1649
+ var serializer = unified().use(remarkStringify).use(remarkFrontmatter, ["yaml"]).use(remarkGfm);
1640
1650
  function createMdxFormatLoader() {
1651
+ const skippedTypes = ["code", "inlineCode"];
1641
1652
  return createLoader({
1642
1653
  async pull(locale, input2) {
1643
1654
  const file = new VFile(input2);
1644
1655
  const ast = parser.parse(file);
1645
- return JSON.parse(JSON.stringify(ast));
1656
+ const result = _9.cloneDeep(ast);
1657
+ traverseMdast(result, (node) => {
1658
+ if (skippedTypes.includes(node.type)) {
1659
+ if ("value" in node) {
1660
+ node.value = "";
1661
+ }
1662
+ }
1663
+ });
1664
+ return result;
1646
1665
  },
1647
- async push(locale, data) {
1648
- const ast = data;
1649
- const content = String(serializer.stringify(ast));
1650
- return content;
1666
+ async push(locale, data, originalInput, originalLocale, pullInput, pullOutput) {
1667
+ const file = new VFile(originalInput);
1668
+ const ast = parser.parse(file);
1669
+ const result = _9.cloneDeep(ast);
1670
+ traverseMdast(result, (node, indexPath) => {
1671
+ if ("value" in node) {
1672
+ const incomingValue = findNodeByIndexPath(data, indexPath);
1673
+ if (incomingValue && "value" in incomingValue && !_9.isEmpty(incomingValue.value)) {
1674
+ node.value = incomingValue.value;
1675
+ }
1676
+ }
1677
+ });
1678
+ return String(serializer.stringify(result));
1651
1679
  }
1652
1680
  });
1653
1681
  }
@@ -1676,6 +1704,28 @@ function createMdxStructureLoader() {
1676
1704
  }
1677
1705
  });
1678
1706
  }
1707
+ function traverseMdast(ast, visitor, indexPath = []) {
1708
+ visitor(ast, indexPath);
1709
+ if ("children" in ast && Array.isArray(ast.children)) {
1710
+ for (let i = 0; i < ast.children.length; i++) {
1711
+ traverseMdast(ast.children[i], visitor, [...indexPath, i]);
1712
+ }
1713
+ }
1714
+ }
1715
+ function findNodeByIndexPath(ast, indexPath) {
1716
+ let result = null;
1717
+ const stringifiedIndexPath = indexPath.join(".");
1718
+ traverseMdast(ast, (node, path18) => {
1719
+ if (result) {
1720
+ return;
1721
+ }
1722
+ const currentStringifiedPath = path18.join(".");
1723
+ if (currentStringifiedPath === stringifiedIndexPath) {
1724
+ result = node;
1725
+ }
1726
+ });
1727
+ return result;
1728
+ }
1679
1729
 
1680
1730
  // src/cli/loaders/properties.ts
1681
1731
  function createPropertiesLoader() {
@@ -1996,14 +2046,27 @@ function createPoDataLoader(params) {
1996
2046
  }
1997
2047
  return result;
1998
2048
  },
1999
- async push(locale, data, originalInput) {
2000
- const sections = originalInput?.split("\n\n").filter(Boolean) || [];
2001
- const result = sections.map((section) => {
2049
+ async push(locale, data, originalInput, originalLocale, pullInput) {
2050
+ const currentSections = pullInput?.split("\n\n").filter(Boolean) || [];
2051
+ const originalSections = originalInput?.split("\n\n").filter(Boolean) || [];
2052
+ const result = originalSections.map((section) => {
2002
2053
  const sectionPo = gettextParser.po.parse(section);
2003
2054
  const contextKey = _12.keys(sectionPo.translations)[0];
2004
2055
  const entries = sectionPo.translations[contextKey];
2005
2056
  const msgid = Object.keys(entries).find((key) => entries[key].msgid);
2006
- if (!msgid) return section;
2057
+ if (!msgid) {
2058
+ const currentSection = currentSections.find((cs) => {
2059
+ const csPo = gettextParser.po.parse(cs);
2060
+ const csContextKey = _12.keys(csPo.translations)[0];
2061
+ const csEntries = csPo.translations[csContextKey];
2062
+ const csMsgid = Object.keys(csEntries).find((key) => csEntries[key].msgid);
2063
+ return csMsgid === msgid;
2064
+ });
2065
+ if (currentSection) {
2066
+ return currentSection;
2067
+ }
2068
+ return section;
2069
+ }
2007
2070
  if (data[msgid]) {
2008
2071
  const updatedPo = _12.merge({}, sectionPo, {
2009
2072
  translations: {
@@ -5460,7 +5523,7 @@ function validateParams2(i18nConfig, flags) {
5460
5523
  // package.json
5461
5524
  var package_default = {
5462
5525
  name: "lingo.dev",
5463
- version: "0.85.6",
5526
+ version: "0.86.0",
5464
5527
  description: "Lingo.dev CLI",
5465
5528
  private: false,
5466
5529
  publishConfig: {