@uniformdev/transformer 1.1.18 → 1.1.20

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/index.d.ts CHANGED
@@ -198,6 +198,7 @@ declare class ComponentService {
198
198
  filePath: string;
199
199
  }>;
200
200
  saveComponent(filePath: string, component: ComponentDefinition): Promise<void>;
201
+ private sortComponentArrays;
201
202
  findParameter(component: ComponentDefinition, parameterName: string, options?: FindOptions$1): Parameter | undefined;
202
203
  isGroupParameter(parameter: Parameter): boolean;
203
204
  resolveGroupParameters(component: ComponentDefinition, groupParameter: Parameter, options?: FindOptions$1): Parameter[];
@@ -488,7 +489,7 @@ declare function computeGuidHash(guidOrSeed: string): string;
488
489
 
489
490
  /**
490
491
  * Recursively walks through a value and regenerates all `_id` properties that contain UUIDs.
491
- * Uses computeGuidHash(originalValue + jsonPath) to produce deterministic new IDs.
492
+ * Uses computeGuidHash(jsonPath) to produce deterministic new IDs based purely on position.
492
493
  * Also creates a deep clone of the value — the original is not modified.
493
494
  */
494
495
  declare function regenerateIds<T>(value: T, basePath: string): T;
package/dist/index.js CHANGED
@@ -179,7 +179,27 @@ var ComponentService = class {
179
179
  throw new ComponentNotFoundError(componentType, componentsDir);
180
180
  }
181
181
  async saveComponent(filePath, component) {
182
- await this.fileSystem.writeFile(filePath, component);
182
+ const sorted = this.sortComponentArrays(component);
183
+ await this.fileSystem.writeFile(filePath, sorted);
184
+ }
185
+ sortComponentArrays(component) {
186
+ const result = { ...component };
187
+ if (result.parameters) {
188
+ result.parameters = [...result.parameters].sort((a, b) => a.id.localeCompare(b.id));
189
+ }
190
+ if (result.slots) {
191
+ result.slots = [...result.slots].sort((a, b) => a.id.localeCompare(b.id)).map((slot) => {
192
+ if (slot.allowedComponents) {
193
+ return { ...slot, allowedComponents: [...slot.allowedComponents].sort((a, b) => a.localeCompare(b)) };
194
+ }
195
+ return slot;
196
+ });
197
+ }
198
+ const variants = result.variants;
199
+ if (Array.isArray(variants)) {
200
+ result.variants = [...variants].sort((a, b) => a.id.localeCompare(b.id));
201
+ }
202
+ return result;
183
203
  }
184
204
  findParameter(component, parameterName, options = {}) {
185
205
  const { strict = false } = options;
@@ -664,9 +684,26 @@ var CompositionConverterService = class {
664
684
  for (const inst of instances) {
665
685
  const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
666
686
  if (existingId) {
667
- this.logger.info(
668
- `Reusing existing entry ${existingId} for ${flattenType} (sourceItem match)`
687
+ const existingEntryPath = this.fileSystem.joinPath(
688
+ entriesDirFull,
689
+ `${existingId}.json`
690
+ );
691
+ this.logger.action(
692
+ whatIf,
693
+ "UPDATE",
694
+ `${entriesDir}/${existingId}.json (${flattenType}, merged fields from "${this.truncate(compositionName, 50)}")`
669
695
  );
696
+ if (!whatIf) {
697
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath);
698
+ if (existingEntry?.entry) {
699
+ const instanceFields = inst.instance.parameters ?? {};
700
+ existingEntry.entry.fields = {
701
+ ...existingEntry.entry.fields,
702
+ ...instanceFields
703
+ };
704
+ await this.fileSystem.writeFile(existingEntryPath, existingEntry);
705
+ }
706
+ }
670
707
  entriesReused++;
671
708
  continue;
672
709
  }
@@ -994,7 +1031,7 @@ function walkAndRegenerate(value, currentPath) {
994
1031
  for (const [key, val] of Object.entries(obj)) {
995
1032
  const childPath = `${currentPath}.${key}`;
996
1033
  if (key === "_id" && typeof val === "string" && UUID_PATTERN.test(val)) {
997
- result[key] = computeGuidHash(val + childPath);
1034
+ result[key] = computeGuidHash(childPath);
998
1035
  } else {
999
1036
  result[key] = walkAndRegenerate(val, childPath);
1000
1037
  }