@uniformdev/transformer 1.1.19 → 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;
@@ -1011,7 +1031,7 @@ function walkAndRegenerate(value, currentPath) {
1011
1031
  for (const [key, val] of Object.entries(obj)) {
1012
1032
  const childPath = `${currentPath}.${key}`;
1013
1033
  if (key === "_id" && typeof val === "string" && UUID_PATTERN.test(val)) {
1014
- result[key] = computeGuidHash(val + childPath);
1034
+ result[key] = computeGuidHash(childPath);
1015
1035
  } else {
1016
1036
  result[key] = walkAndRegenerate(val, childPath);
1017
1037
  }