@uniformdev/transformer 1.1.51 → 1.1.53

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
@@ -4977,6 +4977,9 @@ var ParameterRemoverService = class {
4977
4977
  strict,
4978
4978
  "composition"
4979
4979
  );
4980
+ this.logger.info(
4981
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
4982
+ );
4980
4983
  const compositionPatternsResult = await this.removeParameterInDirectory(
4981
4984
  fullCompositionPatternsDir,
4982
4985
  componentType,
@@ -4985,6 +4988,9 @@ var ParameterRemoverService = class {
4985
4988
  strict,
4986
4989
  "compositionPattern"
4987
4990
  );
4991
+ this.logger.info(
4992
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
4993
+ );
4988
4994
  const componentPatternsResult = await this.removeParameterInDirectory(
4989
4995
  fullComponentPatternsDir,
4990
4996
  componentType,
@@ -4993,6 +4999,9 @@ var ParameterRemoverService = class {
4993
4999
  strict,
4994
5000
  "componentPattern"
4995
5001
  );
5002
+ this.logger.info(
5003
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
5004
+ );
4996
5005
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
4997
5006
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
4998
5007
  this.logger.info("");
@@ -5012,13 +5021,25 @@ var ParameterRemoverService = class {
5012
5021
  try {
5013
5022
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
5014
5023
  } catch {
5015
- return { filesModified: 0, instancesUpdated: 0 };
5024
+ return {
5025
+ filesModified: 0,
5026
+ instancesUpdated: 0,
5027
+ totalFilesMatched: 0,
5028
+ validCompositionDocuments: 0
5029
+ };
5016
5030
  }
5031
+ const totalFilesMatched = files.length;
5017
5032
  if (files.length === 0) {
5018
- return { filesModified: 0, instancesUpdated: 0 };
5033
+ return {
5034
+ filesModified: 0,
5035
+ instancesUpdated: 0,
5036
+ totalFilesMatched: 0,
5037
+ validCompositionDocuments: 0
5038
+ };
5019
5039
  }
5020
5040
  let filesModified = 0;
5021
5041
  let instancesUpdated = 0;
5042
+ let validCompositionDocuments = 0;
5022
5043
  for (const filePath of files) {
5023
5044
  let composition;
5024
5045
  try {
@@ -5029,6 +5050,7 @@ var ParameterRemoverService = class {
5029
5050
  if (!composition?.composition) {
5030
5051
  continue;
5031
5052
  }
5053
+ validCompositionDocuments++;
5032
5054
  const count = this.removeParameterFromTree(
5033
5055
  composition.composition,
5034
5056
  componentType,
@@ -5056,7 +5078,7 @@ var ParameterRemoverService = class {
5056
5078
  instancesUpdated += totalCount;
5057
5079
  }
5058
5080
  }
5059
- return { filesModified, instancesUpdated };
5081
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
5060
5082
  }
5061
5083
  removeParameterFromTree(node, componentType, parameterIds, strict) {
5062
5084
  let count = 0;
@@ -5098,24 +5120,54 @@ var ParameterRemoverService = class {
5098
5120
  componentType,
5099
5121
  parameterIds,
5100
5122
  strict,
5101
- counter
5123
+ counter,
5124
+ [composition.composition._id]
5102
5125
  );
5103
5126
  count += counter.count;
5127
+ const slotTreeCounter = { count: 0 };
5128
+ this.removeParameterFromOverrideSlotTrees(
5129
+ composition.composition._overrides,
5130
+ componentType,
5131
+ parameterIds,
5132
+ strict,
5133
+ slotTreeCounter
5134
+ );
5135
+ count += slotTreeCounter.count;
5104
5136
  return count;
5105
5137
  }
5106
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter) {
5138
+ removeParameterFromOverrideSlotTrees(overrides, componentType, parameterIds, strict, counter) {
5139
+ for (const entry of Object.values(overrides)) {
5140
+ const slots = entry.slots;
5141
+ if (!slots) continue;
5142
+ for (const slotInstances of Object.values(slots)) {
5143
+ if (!Array.isArray(slotInstances)) continue;
5144
+ for (const instance of slotInstances) {
5145
+ counter.count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
5146
+ }
5147
+ }
5148
+ }
5149
+ }
5150
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter, idPath) {
5107
5151
  if (node.slots) {
5108
5152
  for (const slotInstances of Object.values(node.slots)) {
5109
5153
  if (!Array.isArray(slotInstances)) continue;
5110
5154
  for (const instance of slotInstances) {
5111
5155
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
5112
- const instanceOverrides = overrides[instance._id];
5113
- if (instanceOverrides?.parameters) {
5114
- const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
5115
- if (removed > 0) {
5116
- counter.count++;
5156
+ const compoundKey = [...idPath, instance._id].join("|");
5157
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
5158
+ let removedAny = false;
5159
+ for (const overrideKey of keysToTry) {
5160
+ const instanceOverrides = overrides[overrideKey];
5161
+ if (instanceOverrides?.parameters) {
5162
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
5163
+ if (removed > 0) {
5164
+ removedAny = true;
5165
+ }
5117
5166
  }
5118
5167
  }
5168
+ if (removedAny) {
5169
+ counter.count++;
5170
+ }
5119
5171
  }
5120
5172
  this.removeOverridesForMatchingInstances(
5121
5173
  instance,
@@ -5123,7 +5175,8 @@ var ParameterRemoverService = class {
5123
5175
  componentType,
5124
5176
  parameterIds,
5125
5177
  strict,
5126
- counter
5178
+ counter,
5179
+ [...idPath, instance._id ?? ""]
5127
5180
  );
5128
5181
  }
5129
5182
  }
@@ -5259,6 +5312,7 @@ var FieldRemoverService = class {
5259
5312
  compositionsDir,
5260
5313
  compositionPatternsDir,
5261
5314
  componentPatternsDir,
5315
+ contentTypesDir,
5262
5316
  componentType,
5263
5317
  parameterId,
5264
5318
  whatIf,
@@ -5269,6 +5323,7 @@ var FieldRemoverService = class {
5269
5323
  const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
5270
5324
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
5271
5325
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
5326
+ const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
5272
5327
  let allIdsToRemove = [parameterId];
5273
5328
  try {
5274
5329
  const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
@@ -5283,6 +5338,13 @@ var FieldRemoverService = class {
5283
5338
  this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
5284
5339
  }
5285
5340
  this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
5341
+ const contentTypesModified = await this.removeFieldFromContentTypes(
5342
+ fullContentTypesDir,
5343
+ componentType,
5344
+ allIdsToRemove,
5345
+ whatIf,
5346
+ strict
5347
+ );
5286
5348
  const compositionsResult = await this.removeFieldInDirectory(
5287
5349
  fullCompositionsDir,
5288
5350
  componentType,
@@ -5291,6 +5353,9 @@ var FieldRemoverService = class {
5291
5353
  strict,
5292
5354
  "composition"
5293
5355
  );
5356
+ this.logger.info(
5357
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
5358
+ );
5294
5359
  const compositionPatternsResult = await this.removeFieldInDirectory(
5295
5360
  fullCompositionPatternsDir,
5296
5361
  componentType,
@@ -5299,6 +5364,9 @@ var FieldRemoverService = class {
5299
5364
  strict,
5300
5365
  "compositionPattern"
5301
5366
  );
5367
+ this.logger.info(
5368
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
5369
+ );
5302
5370
  const componentPatternsResult = await this.removeFieldInDirectory(
5303
5371
  fullComponentPatternsDir,
5304
5372
  componentType,
@@ -5307,31 +5375,101 @@ var FieldRemoverService = class {
5307
5375
  strict,
5308
5376
  "componentPattern"
5309
5377
  );
5378
+ this.logger.info(
5379
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
5380
+ );
5310
5381
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
5311
5382
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
5312
5383
  this.logger.info("");
5313
5384
  this.logger.info(
5314
- `Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
5385
+ `Summary: ${contentTypesModified} content type(s), ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
5315
5386
  );
5316
5387
  return {
5317
5388
  compositionsModified: compositionsResult.filesModified,
5318
5389
  compositionPatternsModified: compositionPatternsResult.filesModified,
5319
5390
  componentPatternsModified: componentPatternsResult.filesModified,
5391
+ contentTypesModified,
5320
5392
  instancesUpdated: totalInstances
5321
5393
  };
5322
5394
  }
5395
+ async removeFieldFromContentTypes(contentTypesDir, componentType, fieldIds, whatIf, strict) {
5396
+ let files;
5397
+ try {
5398
+ files = await this.fileSystem.findFiles(contentTypesDir, "**/*.{json,yaml,yml}");
5399
+ } catch {
5400
+ return 0;
5401
+ }
5402
+ if (files.length === 0) {
5403
+ return 0;
5404
+ }
5405
+ const isWildcard = componentType === "*";
5406
+ let contentTypesModified = 0;
5407
+ for (const filePath of files) {
5408
+ let contentType;
5409
+ try {
5410
+ contentType = await this.fileSystem.readFile(filePath);
5411
+ } catch {
5412
+ continue;
5413
+ }
5414
+ if (!contentType?.id || !contentType.fields) {
5415
+ continue;
5416
+ }
5417
+ if (!isWildcard && !this.compareIds(contentType.id, componentType, strict)) {
5418
+ continue;
5419
+ }
5420
+ const removedFieldIds = [];
5421
+ contentType.fields = contentType.fields.filter((field) => {
5422
+ const shouldRemove = fieldIds.some((id) => this.compareIds(field.id, id, strict));
5423
+ if (shouldRemove) {
5424
+ removedFieldIds.push(field.id);
5425
+ }
5426
+ return !shouldRemove;
5427
+ });
5428
+ if (removedFieldIds.length === 0) {
5429
+ continue;
5430
+ }
5431
+ const entryName = contentType.entryName;
5432
+ if (entryName && removedFieldIds.some((id) => this.compareIds(id, entryName, strict))) {
5433
+ this.logger.info(`Clearing entryName "${entryName}" on content type "${contentType.id}" (field was removed)`);
5434
+ contentType.entryName = "";
5435
+ }
5436
+ const relativePath = this.fileSystem.getBasename(filePath);
5437
+ this.logger.action(
5438
+ whatIf,
5439
+ "UPDATE",
5440
+ `contentType/${relativePath} (removed ${removedFieldIds.length} field(s): ${removedFieldIds.join(", ")})`
5441
+ );
5442
+ if (!whatIf) {
5443
+ await this.fileSystem.writeFile(filePath, contentType);
5444
+ }
5445
+ contentTypesModified++;
5446
+ }
5447
+ return contentTypesModified;
5448
+ }
5323
5449
  async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
5324
5450
  let files;
5325
5451
  try {
5326
5452
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
5327
5453
  } catch {
5328
- return { filesModified: 0, instancesUpdated: 0 };
5454
+ return {
5455
+ filesModified: 0,
5456
+ instancesUpdated: 0,
5457
+ totalFilesMatched: 0,
5458
+ validCompositionDocuments: 0
5459
+ };
5329
5460
  }
5461
+ const totalFilesMatched = files.length;
5330
5462
  if (files.length === 0) {
5331
- return { filesModified: 0, instancesUpdated: 0 };
5463
+ return {
5464
+ filesModified: 0,
5465
+ instancesUpdated: 0,
5466
+ totalFilesMatched: 0,
5467
+ validCompositionDocuments: 0
5468
+ };
5332
5469
  }
5333
5470
  let filesModified = 0;
5334
5471
  let instancesUpdated = 0;
5472
+ let validCompositionDocuments = 0;
5335
5473
  for (const filePath of files) {
5336
5474
  let composition;
5337
5475
  try {
@@ -5342,6 +5480,7 @@ var FieldRemoverService = class {
5342
5480
  if (!composition?.composition) {
5343
5481
  continue;
5344
5482
  }
5483
+ validCompositionDocuments++;
5345
5484
  const treeCount = this.removeFieldFromTree(
5346
5485
  composition.composition,
5347
5486
  componentType,
@@ -5369,7 +5508,7 @@ var FieldRemoverService = class {
5369
5508
  instancesUpdated += totalCount;
5370
5509
  }
5371
5510
  }
5372
- return { filesModified, instancesUpdated };
5511
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
5373
5512
  }
5374
5513
  removeFieldFromTree(node, componentType, parameterIds, strict) {
5375
5514
  let count = 0;
@@ -5395,8 +5534,8 @@ var FieldRemoverService = class {
5395
5534
  }
5396
5535
  let count = 0;
5397
5536
  if (this.compareIds(composition.composition.type, componentType, strict)) {
5398
- const rootId = composition.composition._id;
5399
- const rootOverrides = composition.composition._overrides[rootId];
5537
+ const rootId2 = composition.composition._id;
5538
+ const rootOverrides = composition.composition._overrides[rootId2];
5400
5539
  if (rootOverrides?.parameters) {
5401
5540
  const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
5402
5541
  if (removed > 0) {
@@ -5404,8 +5543,16 @@ var FieldRemoverService = class {
5404
5543
  }
5405
5544
  }
5406
5545
  }
5546
+ const rootId = composition.composition._id;
5407
5547
  count += this.removeOverridesForMatchingInstances(
5408
5548
  composition.composition,
5549
+ composition.composition._overrides,
5550
+ componentType,
5551
+ parameterIds,
5552
+ strict,
5553
+ [rootId]
5554
+ );
5555
+ count += this.removeFieldFromOverrideSlotTrees(
5409
5556
  composition.composition._overrides,
5410
5557
  componentType,
5411
5558
  parameterIds,
@@ -5413,27 +5560,58 @@ var FieldRemoverService = class {
5413
5560
  );
5414
5561
  return count;
5415
5562
  }
5416
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict) {
5563
+ /**
5564
+ * Walks every _overrides entry's `slots` trees (if present) and removes parameter keys from
5565
+ * matching component instances. Uniform often stores nested slot patches only here.
5566
+ */
5567
+ removeFieldFromOverrideSlotTrees(overrides, componentType, parameterIds, strict) {
5568
+ let count = 0;
5569
+ for (const entry of Object.values(overrides)) {
5570
+ const slots = entry.slots;
5571
+ if (!slots) continue;
5572
+ for (const slotInstances of Object.values(slots)) {
5573
+ if (!Array.isArray(slotInstances)) continue;
5574
+ for (const instance of slotInstances) {
5575
+ count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
5576
+ }
5577
+ }
5578
+ }
5579
+ return count;
5580
+ }
5581
+ /**
5582
+ * Looks up override entries by compound key (ancestor _id chain joined with |) and,
5583
+ * for backward compatibility, by instance _id alone when it differs from the compound key.
5584
+ */
5585
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, idPath) {
5417
5586
  let count = 0;
5418
5587
  if (node.slots) {
5419
5588
  for (const slotInstances of Object.values(node.slots)) {
5420
5589
  if (!Array.isArray(slotInstances)) continue;
5421
5590
  for (const instance of slotInstances) {
5422
5591
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
5423
- const instanceOverrides = overrides[instance._id];
5424
- if (instanceOverrides?.parameters) {
5425
- const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
5426
- if (removed > 0) {
5427
- count++;
5592
+ const compoundKey = [...idPath, instance._id].join("|");
5593
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
5594
+ let removedAny = false;
5595
+ for (const overrideKey of keysToTry) {
5596
+ const instanceOverrides = overrides[overrideKey];
5597
+ if (instanceOverrides?.parameters) {
5598
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
5599
+ if (removed > 0) {
5600
+ removedAny = true;
5601
+ }
5428
5602
  }
5429
5603
  }
5604
+ if (removedAny) {
5605
+ count++;
5606
+ }
5430
5607
  }
5431
5608
  count += this.removeOverridesForMatchingInstances(
5432
5609
  instance,
5433
5610
  overrides,
5434
5611
  componentType,
5435
5612
  parameterIds,
5436
- strict
5613
+ strict,
5614
+ [...idPath, instance._id ?? ""]
5437
5615
  );
5438
5616
  }
5439
5617
  }
@@ -5477,6 +5655,8 @@ function createRemoveFieldCommand() {
5477
5655
  parameterId: opts.parameterId
5478
5656
  };
5479
5657
  const logger = new Logger();
5658
+ logger.info(`componentType: ${options.componentType}`);
5659
+ logger.info(`parameterId: ${options.parameterId}`);
5480
5660
  const fileSystem = new FileSystemService();
5481
5661
  const componentService = new ComponentService(fileSystem);
5482
5662
  const remover = new FieldRemoverService(fileSystem, componentService, logger);
@@ -5485,7 +5665,8 @@ function createRemoveFieldCommand() {
5485
5665
  const aggregate = {
5486
5666
  compositionsModified: 0,
5487
5667
  compositionPatternsModified: 0,
5488
- componentPatternsModified: 0
5668
+ componentPatternsModified: 0,
5669
+ contentTypesModified: 0
5489
5670
  };
5490
5671
  try {
5491
5672
  for (const componentType of componentTypes) {
@@ -5495,6 +5676,7 @@ function createRemoveFieldCommand() {
5495
5676
  compositionsDir: options.compositionsDir,
5496
5677
  compositionPatternsDir: options.compositionPatternsDir,
5497
5678
  componentPatternsDir: options.componentPatternsDir,
5679
+ contentTypesDir: options.contentTypesDir,
5498
5680
  componentType,
5499
5681
  parameterId: options.parameterId,
5500
5682
  whatIf: options.whatIf ?? false,
@@ -5503,9 +5685,10 @@ function createRemoveFieldCommand() {
5503
5685
  aggregate.compositionsModified += result.compositionsModified;
5504
5686
  aggregate.compositionPatternsModified += result.compositionPatternsModified;
5505
5687
  aggregate.componentPatternsModified += result.componentPatternsModified;
5688
+ aggregate.contentTypesModified += result.contentTypesModified;
5506
5689
  }
5507
5690
  logger.success(
5508
- `Removed field: ${aggregate.compositionsModified} composition(s), ${aggregate.compositionPatternsModified} composition pattern(s), ${aggregate.componentPatternsModified} component pattern(s) updated`
5691
+ `Removed field: ${aggregate.contentTypesModified} content type(s), ${aggregate.compositionsModified} composition(s), ${aggregate.compositionPatternsModified} composition pattern(s), ${aggregate.componentPatternsModified} component pattern(s) updated`
5509
5692
  );
5510
5693
  } catch (error) {
5511
5694
  if (error instanceof TransformError) {
@@ -7704,7 +7887,7 @@ function createClearSlotCommand() {
7704
7887
  // package.json
7705
7888
  var package_default = {
7706
7889
  name: "@uniformdev/transformer",
7707
- version: "1.1.51",
7890
+ version: "1.1.53",
7708
7891
  description: "CLI tool for transforming Uniform.dev serialization files offline",
7709
7892
  type: "module",
7710
7893
  bin: {