@uniformdev/transformer 1.1.27 → 1.1.28

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
@@ -597,8 +597,8 @@ var CompositionConverterService = class {
597
597
  whatIf,
598
598
  strict
599
599
  } = options;
600
- const componentsToReferences = [...new Set(rawComponentsToReferences)];
601
- const componentsToBlocks = [...new Set(rawComponentsToBlocks)];
600
+ const initialComponentsToReferences = [...new Set(rawComponentsToReferences)];
601
+ const initialComponentsToBlocks = [...new Set(rawComponentsToBlocks)];
602
602
  const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
603
603
  const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
604
604
  const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
@@ -609,13 +609,13 @@ var CompositionConverterService = class {
609
609
  let entriesReused = 0;
610
610
  let blocksEmbedded = 0;
611
611
  this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
612
- if (componentsToReferences.length > 0) {
613
- this.logger.info(`Components to references: ${componentsToReferences.join(", ")}`);
612
+ if (initialComponentsToReferences.length > 0) {
613
+ this.logger.info(`Components to references: ${initialComponentsToReferences.join(", ")}`);
614
614
  }
615
- if (componentsToBlocks.length > 0) {
616
- this.logger.info(`Components to blocks: ${componentsToBlocks.join(", ")}`);
615
+ if (initialComponentsToBlocks.length > 0) {
616
+ this.logger.info(`Components to blocks: ${initialComponentsToBlocks.join(", ")}`);
617
617
  }
618
- const sourceItemMap = componentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
618
+ const sourceItemMap = initialComponentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
619
619
  if (sourceItemMap.size > 0) {
620
620
  this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
621
621
  }
@@ -630,6 +630,8 @@ var CompositionConverterService = class {
630
630
  return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromReferences: 0, entriesReused: 0, blocksEmbedded: 0 };
631
631
  }
632
632
  this.logger.info(`Found ${compositionResults.length} composition(s)`);
633
+ const componentsToReferences = this.expandWildcardTypes(compositionResults, initialComponentsToReferences, strict);
634
+ const componentsToBlocks = this.expandWildcardTypes(compositionResults, initialComponentsToBlocks, strict);
633
635
  const rootComponentTypes = /* @__PURE__ */ new Set();
634
636
  for (const { composition } of compositionResults) {
635
637
  rootComponentTypes.add(composition.composition.type);
@@ -724,7 +726,8 @@ var CompositionConverterService = class {
724
726
  const compositionId = comp._id;
725
727
  const compositionName = comp._name ?? compositionId;
726
728
  const compositionType = comp.type;
727
- const existingEntryPath = existingEntryMap.get(compositionId);
729
+ const compSourceItem = comp.parameters?.sourceItem?.value;
730
+ const existingEntryPath = existingEntryMap.get(compositionId) ?? (compSourceItem != null ? existingEntryMap.get(String(compSourceItem)) : void 0);
728
731
  let entry;
729
732
  let isExistingEntry = false;
730
733
  if (existingEntryPath) {
@@ -733,7 +736,7 @@ var CompositionConverterService = class {
733
736
  entry = existingEntry;
734
737
  isExistingEntry = true;
735
738
  this.logger.info(
736
- `Found existing entry "${compositionId}" \u2014 merging references and blocks`
739
+ `Found existing entry "${existingEntry.entry._id}" \u2014 merging references and blocks`
737
740
  );
738
741
  } else {
739
742
  entry = this.generateEntryFromComposition(composition);
@@ -1158,11 +1161,57 @@ var CompositionConverterService = class {
1158
1161
  return sourceItemMap.get(String(sourceItemParam.value));
1159
1162
  }
1160
1163
  // --- Utilities ---
1164
+ matchesType(instanceType, pattern, strict) {
1165
+ if (!pattern.includes("*")) {
1166
+ return strict ? instanceType === pattern : instanceType.toLowerCase() === pattern.toLowerCase();
1167
+ }
1168
+ const flags = strict ? "" : "i";
1169
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
1170
+ const regex = new RegExp(`^${escaped}$`, flags);
1171
+ return regex.test(instanceType);
1172
+ }
1161
1173
  compareTypes(type1, type2, strict) {
1162
- if (strict) {
1163
- return type1 === type2;
1174
+ if (type1.includes("*")) return this.matchesType(type2, type1, strict);
1175
+ if (type2.includes("*")) return this.matchesType(type1, type2, strict);
1176
+ return strict ? type1 === type2 : type1.toLowerCase() === type2.toLowerCase();
1177
+ }
1178
+ expandWildcardTypes(compositionResults, patterns, strict) {
1179
+ const expanded = [];
1180
+ for (const pattern of patterns) {
1181
+ if (!pattern.includes("*")) {
1182
+ expanded.push(pattern);
1183
+ continue;
1184
+ }
1185
+ const matched = /* @__PURE__ */ new Set();
1186
+ for (const { composition } of compositionResults) {
1187
+ if (composition.composition.slots) {
1188
+ this.collectMatchingTypes(composition.composition.slots, pattern, strict, matched);
1189
+ }
1190
+ }
1191
+ if (matched.size === 0) {
1192
+ this.logger.warn(`Wildcard pattern "${pattern}" did not match any component types`);
1193
+ } else {
1194
+ this.logger.info(`Wildcard "${pattern}" expanded to: ${[...matched].join(", ")}`);
1195
+ }
1196
+ for (const type of matched) {
1197
+ expanded.push(type);
1198
+ }
1199
+ }
1200
+ return [...new Set(expanded)];
1201
+ }
1202
+ collectMatchingTypes(slots, pattern, strict, matched) {
1203
+ for (const instances of Object.values(slots)) {
1204
+ if (!Array.isArray(instances)) continue;
1205
+ for (const instance of instances) {
1206
+ if (instance._pattern) continue;
1207
+ if (this.matchesType(instance.type, pattern, strict)) {
1208
+ matched.add(instance.type);
1209
+ }
1210
+ if (instance.slots) {
1211
+ this.collectMatchingTypes(instance.slots, pattern, strict, matched);
1212
+ }
1213
+ }
1164
1214
  }
1165
- return type1.toLowerCase() === type2.toLowerCase();
1166
1215
  }
1167
1216
  truncate(str, maxLength) {
1168
1217
  if (str.length <= maxLength) return str;
@@ -4965,7 +5014,7 @@ function createRemoveFieldCommand() {
4965
5014
  // package.json
4966
5015
  var package_default = {
4967
5016
  name: "@uniformdev/transformer",
4968
- version: "1.1.27",
5017
+ version: "1.1.28",
4969
5018
  description: "CLI tool for transforming Uniform.dev serialization files offline",
4970
5019
  type: "module",
4971
5020
  bin: {