@lingo.dev/_compiler 0.3.1 → 0.3.3

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/index.cjs CHANGED
@@ -4,7 +4,7 @@ var _unplugin = require('unplugin');
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.3.1",
7
+ version: "0.3.3",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -834,9 +834,10 @@ var LCPCache = class {
834
834
  }
835
835
  // merge dictionary with current cache, sort files, entries and locales to minimize diffs
836
836
  static _mergeLocaleDictionary(currentCache, dictionary, lcp) {
837
- const newCache = _lodash2.default.cloneDeep(currentCache);
838
- for (const [fileName, fileData] of Object.entries(dictionary.files)) {
839
- for (const [entryName, entryValue] of Object.entries(fileData.entries)) {
837
+ const files = _lodash2.default.call(void 0, dictionary.files).mapValues((file, fileName) => ({
838
+ ...file,
839
+ entries: _lodash2.default.call(void 0, file.entries).mapValues((entry, entryName) => {
840
+ const cachedEntry = _nullishCoalesce(_lodash2.default.get(currentCache, ["files", fileName, "entries", entryName]), () => ( {}));
840
841
  const hash = _lodash2.default.get(lcp, [
841
842
  "files",
842
843
  fileName,
@@ -844,33 +845,19 @@ var LCPCache = class {
844
845
  entryName,
845
846
  "hash"
846
847
  ]);
847
- const existingEntry = _lodash2.default.get(newCache, [
848
- "files",
849
- fileName,
850
- "entries",
851
- entryName
852
- ]) || {
853
- content: {},
854
- hash
855
- };
856
- const mergedContent = _lodash2.default.call(void 0, {
857
- ...existingEntry.content,
858
- [dictionary.locale]: entryValue
848
+ const cachedEntryContent = cachedEntry.hash === hash ? cachedEntry.content : {};
849
+ const content = _lodash2.default.call(void 0, {
850
+ ...cachedEntryContent,
851
+ [dictionary.locale]: entry
859
852
  }).toPairs().sortBy([0]).fromPairs().value();
860
- _lodash2.default.set(newCache, ["files", fileName, "entries", entryName], {
861
- content: mergedContent,
862
- hash
863
- });
864
- }
865
- }
866
- const sortedFiles = _lodash2.default.call(void 0, newCache.files).toPairs().sortBy([0]).map(([fileName, file]) => {
867
- const sortedEntries = _lodash2.default.call(void 0, file.entries).toPairs().sortBy([0]).fromPairs().value();
868
- return [fileName, { entries: sortedEntries }];
869
- }).fromPairs().value();
870
- return {
853
+ return { content, hash };
854
+ }).toPairs().sortBy([0]).fromPairs().value()
855
+ })).toPairs().sortBy([0]).fromPairs().value();
856
+ const newCache = {
871
857
  version: dictionary.version,
872
- files: sortedFiles
858
+ files
873
859
  };
860
+ return newCache;
874
861
  }
875
862
  // extract dictionary from cache for given locale, validate entry hash from LCP schema
876
863
  static _extractLocaleDictionary(cache, locale, lcp) {
@@ -1743,6 +1730,10 @@ var LCPServer = (_class = class {
1743
1730
  params.targetLocale
1744
1731
  );
1745
1732
  targetDictionary = this._mergeDictionaries(newTranslations, cache);
1733
+ targetDictionary = {
1734
+ ...targetDictionary,
1735
+ locale: params.targetLocale
1736
+ };
1746
1737
  await LCPCache.writeLocaleDictionary(targetDictionary, cacheParams);
1747
1738
  }
1748
1739
  const targetDictionaryWithFallback = this._mergeDictionaries(
package/build/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { createUnplugin } from "unplugin";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.3.1",
7
+ version: "0.3.3",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -834,9 +834,10 @@ var LCPCache = class {
834
834
  }
835
835
  // merge dictionary with current cache, sort files, entries and locales to minimize diffs
836
836
  static _mergeLocaleDictionary(currentCache, dictionary, lcp) {
837
- const newCache = _3.cloneDeep(currentCache);
838
- for (const [fileName, fileData] of Object.entries(dictionary.files)) {
839
- for (const [entryName, entryValue] of Object.entries(fileData.entries)) {
837
+ const files = _3(dictionary.files).mapValues((file, fileName) => ({
838
+ ...file,
839
+ entries: _3(file.entries).mapValues((entry, entryName) => {
840
+ const cachedEntry = _3.get(currentCache, ["files", fileName, "entries", entryName]) ?? {};
840
841
  const hash = _3.get(lcp, [
841
842
  "files",
842
843
  fileName,
@@ -844,33 +845,19 @@ var LCPCache = class {
844
845
  entryName,
845
846
  "hash"
846
847
  ]);
847
- const existingEntry = _3.get(newCache, [
848
- "files",
849
- fileName,
850
- "entries",
851
- entryName
852
- ]) || {
853
- content: {},
854
- hash
855
- };
856
- const mergedContent = _3({
857
- ...existingEntry.content,
858
- [dictionary.locale]: entryValue
848
+ const cachedEntryContent = cachedEntry.hash === hash ? cachedEntry.content : {};
849
+ const content = _3({
850
+ ...cachedEntryContent,
851
+ [dictionary.locale]: entry
859
852
  }).toPairs().sortBy([0]).fromPairs().value();
860
- _3.set(newCache, ["files", fileName, "entries", entryName], {
861
- content: mergedContent,
862
- hash
863
- });
864
- }
865
- }
866
- const sortedFiles = _3(newCache.files).toPairs().sortBy([0]).map(([fileName, file]) => {
867
- const sortedEntries = _3(file.entries).toPairs().sortBy([0]).fromPairs().value();
868
- return [fileName, { entries: sortedEntries }];
869
- }).fromPairs().value();
870
- return {
853
+ return { content, hash };
854
+ }).toPairs().sortBy([0]).fromPairs().value()
855
+ })).toPairs().sortBy([0]).fromPairs().value();
856
+ const newCache = {
871
857
  version: dictionary.version,
872
- files: sortedFiles
858
+ files
873
859
  };
860
+ return newCache;
874
861
  }
875
862
  // extract dictionary from cache for given locale, validate entry hash from LCP schema
876
863
  static _extractLocaleDictionary(cache, locale, lcp) {
@@ -1743,6 +1730,10 @@ var LCPServer = class {
1743
1730
  params.targetLocale
1744
1731
  );
1745
1732
  targetDictionary = this._mergeDictionaries(newTranslations, cache);
1733
+ targetDictionary = {
1734
+ ...targetDictionary,
1735
+ locale: params.targetLocale
1736
+ };
1746
1737
  await LCPCache.writeLocaleDictionary(targetDictionary, cacheParams);
1747
1738
  }
1748
1739
  const targetDictionaryWithFallback = this._mergeDictionaries(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
6
  "publishConfig": {