@uniformdev/transformer 1.1.25 → 1.1.27

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/dist/cli/index.js CHANGED
@@ -619,6 +619,7 @@ var CompositionConverterService = class {
619
619
  if (sourceItemMap.size > 0) {
620
620
  this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
621
621
  }
622
+ const existingEntryMap = await this.buildEntryIdMap(entriesDirFull);
622
623
  const compositionResults = await this.compositionService.findCompositionsByTypes(
623
624
  compositionsDirFull,
624
625
  compositionTypes,
@@ -723,7 +724,23 @@ var CompositionConverterService = class {
723
724
  const compositionId = comp._id;
724
725
  const compositionName = comp._name ?? compositionId;
725
726
  const compositionType = comp.type;
726
- const entry = this.generateEntryFromComposition(composition);
727
+ const existingEntryPath = existingEntryMap.get(compositionId);
728
+ let entry;
729
+ let isExistingEntry = false;
730
+ if (existingEntryPath) {
731
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath);
732
+ if (existingEntry?.entry) {
733
+ entry = existingEntry;
734
+ isExistingEntry = true;
735
+ this.logger.info(
736
+ `Found existing entry "${compositionId}" \u2014 merging references and blocks`
737
+ );
738
+ } else {
739
+ entry = this.generateEntryFromComposition(composition);
740
+ }
741
+ } else {
742
+ entry = this.generateEntryFromComposition(composition);
743
+ }
727
744
  const refsByType = /* @__PURE__ */ new Map();
728
745
  if (componentsToReferences.length > 0 && comp.slots) {
729
746
  for (const refType of componentsToReferences) {
@@ -803,21 +820,33 @@ var CompositionConverterService = class {
803
820
  blocksEmbedded += instances.length;
804
821
  }
805
822
  const entryId = entry.entry._id;
806
- const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
807
- this.logger.action(
808
- whatIf,
809
- "WRITE",
810
- `${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
811
- );
812
- if (!whatIf) {
813
- await this.fileSystem.writeFile(entryFilePath, entry);
823
+ if (isExistingEntry) {
824
+ this.logger.action(
825
+ whatIf,
826
+ "UPDATE",
827
+ `${entriesDir}/${entryId}.json (${compositionType}, merged refs/blocks from "${this.truncate(compositionName, 50)}")`
828
+ );
829
+ if (!whatIf) {
830
+ await this.fileSystem.writeFile(existingEntryPath, entry);
831
+ }
832
+ entriesReused++;
833
+ } else {
834
+ const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
835
+ this.logger.action(
836
+ whatIf,
837
+ "WRITE",
838
+ `${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
839
+ );
840
+ if (!whatIf) {
841
+ await this.fileSystem.writeFile(entryFilePath, entry);
842
+ }
843
+ entriesFromCompositions++;
814
844
  }
815
- entriesFromCompositions++;
816
845
  for (const [refType, instances] of refsByType) {
817
846
  for (const inst of instances) {
818
847
  const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
819
848
  if (existingId) {
820
- const existingEntryPath = this.fileSystem.joinPath(
849
+ const existingEntryPath2 = this.fileSystem.joinPath(
821
850
  entriesDirFull,
822
851
  `${existingId}.json`
823
852
  );
@@ -827,14 +856,14 @@ var CompositionConverterService = class {
827
856
  `${entriesDir}/${existingId}.json (${refType}, merged fields from "${this.truncate(compositionName, 50)}")`
828
857
  );
829
858
  if (!whatIf) {
830
- const existingEntry = await this.fileSystem.readFile(existingEntryPath);
859
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath2);
831
860
  if (existingEntry?.entry) {
832
861
  const instanceFields = inst.instance.parameters ?? {};
833
862
  existingEntry.entry.fields = {
834
863
  ...existingEntry.entry.fields,
835
864
  ...instanceFields
836
865
  };
837
- await this.fileSystem.writeFile(existingEntryPath, existingEntry);
866
+ await this.fileSystem.writeFile(existingEntryPath2, existingEntry);
838
867
  }
839
868
  }
840
869
  entriesReused++;
@@ -1090,6 +1119,21 @@ var CompositionConverterService = class {
1090
1119
  }
1091
1120
  }
1092
1121
  // --- Source Item Matching ---
1122
+ async buildEntryIdMap(entriesDirFull) {
1123
+ const entryIdMap = /* @__PURE__ */ new Map();
1124
+ const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
1125
+ for (const filePath of entryFiles) {
1126
+ try {
1127
+ const entryData = await this.fileSystem.readFile(filePath);
1128
+ if (entryData?.entry?._id) {
1129
+ entryIdMap.set(entryData.entry._id, filePath);
1130
+ }
1131
+ } catch {
1132
+ continue;
1133
+ }
1134
+ }
1135
+ return entryIdMap;
1136
+ }
1093
1137
  async buildSourceItemMap(entriesDirFull) {
1094
1138
  const sourceItemMap = /* @__PURE__ */ new Map();
1095
1139
  const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
@@ -1235,8 +1279,16 @@ var PropertyPropagatorService = class {
1235
1279
  const sourceComponents = [];
1236
1280
  for (const sourceType of compositionTypes) {
1237
1281
  this.logger.info(`Loading component: ${sourceType}`);
1238
- const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
1239
- sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
1282
+ try {
1283
+ const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
1284
+ sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
1285
+ } catch (error) {
1286
+ if (error instanceof ComponentNotFoundError) {
1287
+ this.logger.warn(`Component not found: ${sourceType} (searched: ${fullComponentsDir})`);
1288
+ continue;
1289
+ }
1290
+ throw error;
1291
+ }
1240
1292
  }
1241
1293
  this.logger.info(`Loading component: ${targetComponentType}`);
1242
1294
  const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
@@ -4016,8 +4068,16 @@ var SlotPropagatorService = class {
4016
4068
  const sourceComponents = [];
4017
4069
  for (const sourceType of compositionTypes) {
4018
4070
  this.logger.info(`Loading component: ${sourceType}`);
4019
- const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
4020
- sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
4071
+ try {
4072
+ const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
4073
+ sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
4074
+ } catch (error) {
4075
+ if (error instanceof ComponentNotFoundError) {
4076
+ this.logger.warn(`Component not found: ${sourceType} (searched: ${fullComponentsDir})`);
4077
+ continue;
4078
+ }
4079
+ throw error;
4080
+ }
4021
4081
  }
4022
4082
  this.logger.info(`Loading component: ${targetComponentType}`);
4023
4083
  const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
@@ -4905,7 +4965,7 @@ function createRemoveFieldCommand() {
4905
4965
  // package.json
4906
4966
  var package_default = {
4907
4967
  name: "@uniformdev/transformer",
4908
- version: "1.1.25",
4968
+ version: "1.1.27",
4909
4969
  description: "CLI tool for transforming Uniform.dev serialization files offline",
4910
4970
  type: "module",
4911
4971
  bin: {