@atlaskit/codemod-cli 0.27.4 → 0.28.1

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/main.js +20 -15
  3. package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +350 -43
  4. package/dist/cjs/presets/remove-token-fallbacks/utils/chunk.js +14 -0
  5. package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
  6. package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +2 -2
  7. package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +28 -21
  8. package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +201 -71
  9. package/dist/es2019/main.js +7 -1
  10. package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +164 -17
  11. package/dist/es2019/presets/remove-token-fallbacks/utils/chunk.js +8 -0
  12. package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
  13. package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +3 -3
  14. package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +6 -1
  15. package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +121 -17
  16. package/dist/esm/main.js +20 -15
  17. package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +350 -41
  18. package/dist/esm/presets/remove-token-fallbacks/utils/chunk.js +8 -0
  19. package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
  20. package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +2 -2
  21. package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +28 -21
  22. package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +201 -71
  23. package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +9 -1
  24. package/dist/types/presets/remove-token-fallbacks/types.d.ts +8 -0
  25. package/dist/types/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
  26. package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +2 -1
  27. package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +6 -0
  28. package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +9 -1
  29. package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +8 -0
  30. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
  31. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +2 -1
  32. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +6 -0
  33. package/package.json +4 -4
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
4
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
@@ -82,12 +83,43 @@ export var TokenProcessor = /*#__PURE__*/function () {
82
83
  value: function logError(message) {
83
84
  this.log(chalk.red(message));
84
85
  }
86
+
87
+ /**
88
+ * Checks if a token should be exempted from automatic fallback removal
89
+ * @param tokenKey The token key to check
90
+ * @returns An object containing whether the token should be exempted and related information
91
+ */
92
+ }, {
93
+ key: "checkTokenExemption",
94
+ value: function checkTokenExemption(tokenKey) {
95
+ // Create exemption list from user-provided skipTokens, and always include 'border'
96
+ var userExemptions = this.options.skipTokens ? this.options.skipTokens.split(',').map(function (item) {
97
+ return item.trim();
98
+ }) : [];
99
+
100
+ // Always include 'border' in the exemption list
101
+ var exemptionList = _toConsumableArray(userExemptions);
102
+ if (!exemptionList.includes('border')) {
103
+ exemptionList.push('border');
104
+ }
105
+ var isExemptedToken = exemptionList.some(function (prefix) {
106
+ return tokenKey.startsWith(prefix);
107
+ });
108
+ var exemptedPrefix = isExemptedToken ? exemptionList.find(function (prefix) {
109
+ return tokenKey.startsWith(prefix);
110
+ }) || null : null;
111
+ return {
112
+ shouldBeExempted: isExemptedToken,
113
+ exemptedPrefix: exemptedPrefix,
114
+ exemptionList: exemptionList
115
+ };
116
+ }
85
117
  }, {
86
118
  key: "processSingleToken",
87
119
  value: function () {
88
120
  var _processSingleToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(callPath) {
89
121
  var _callPath$node$loc2;
90
- var args, line, tokenKey, isSkipped, tokenValue, _ref, rawFallbackValue, fallbackValue, resolvedImportDeclaration, resolvedLocalVarDeclaration, _normalizeValues, difference, isAcceptableDifference, tokenLogValue, fallbackLogValue, normalizedTokenValue, normalizedFallbackValue, areEqual, logData, fallbackRemoved, importDeclaration, localVarDeclaration, message;
122
+ var args, line, tokenKey, tokenValue, _yield$this$getFallba, rawFallbackValue, fallbackValue, resolvedImportDeclaration, resolvedLocalVarDeclaration, _normalizeValues, difference, isAcceptableDifference, tokenLogValue, fallbackLogValue, normalizedTokenValue, normalizedFallbackValue, areEqual, logData, fallbackRemoved, importDeclaration, localVarDeclaration, _this$checkTokenExemp, shouldBeExempted, exemptedPrefix, shouldModifyToken, message;
91
123
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
92
124
  while (1) switch (_context2.prev = _context2.next) {
93
125
  case 0:
@@ -117,33 +149,17 @@ export var TokenProcessor = /*#__PURE__*/function () {
117
149
  resolvedLocalVarDeclaration: undefined
118
150
  });
119
151
  case 8:
120
- isSkipped = tokenKey.startsWith('elevation.shadow') || tokenKey.startsWith('font.body') || tokenKey.startsWith('font.heading');
121
- tokenValue = isSkipped ? '' : this.tokenMap[tokenKey];
152
+ tokenValue = this.tokenMap[tokenKey];
122
153
  this.logVerbose("Token value from tokenMap: ".concat(chalk.magenta(tokenValue), " for key: ").concat(chalk.yellow(tokenKey)));
123
- if (!isSkipped) {
124
- _context2.next = 15;
125
- break;
126
- }
127
- _context2.t0 = {
128
- rawFallbackValue: 'N/A',
129
- fallbackValue: undefined,
130
- resolvedImportDeclaration: undefined,
131
- resolvedLocalVarDeclaration: undefined
132
- };
133
- _context2.next = 18;
134
- break;
135
- case 15:
136
- _context2.next = 17;
154
+ _context2.next = 12;
137
155
  return this.getFallbackValue(args[1]);
138
- case 17:
139
- _context2.t0 = _context2.sent;
140
- case 18:
141
- _ref = _context2.t0;
142
- rawFallbackValue = _ref.rawFallbackValue;
143
- fallbackValue = _ref.fallbackValue;
144
- resolvedImportDeclaration = _ref.resolvedImportDeclaration;
145
- resolvedLocalVarDeclaration = _ref.resolvedLocalVarDeclaration;
146
- _normalizeValues = normalizeValues(tokenKey, tokenValue, fallbackValue), difference = _normalizeValues.difference, isAcceptableDifference = _normalizeValues.isAcceptableDifference, tokenLogValue = _normalizeValues.tokenLogValue, fallbackLogValue = _normalizeValues.fallbackLogValue, normalizedTokenValue = _normalizeValues.normalizedTokenValue, normalizedFallbackValue = _normalizeValues.normalizedFallbackValue;
156
+ case 12:
157
+ _yield$this$getFallba = _context2.sent;
158
+ rawFallbackValue = _yield$this$getFallba.rawFallbackValue;
159
+ fallbackValue = _yield$this$getFallba.fallbackValue;
160
+ resolvedImportDeclaration = _yield$this$getFallba.resolvedImportDeclaration;
161
+ resolvedLocalVarDeclaration = _yield$this$getFallba.resolvedLocalVarDeclaration;
162
+ _normalizeValues = normalizeValues(tokenKey, tokenValue, fallbackValue, this.options), difference = _normalizeValues.difference, isAcceptableDifference = _normalizeValues.isAcceptableDifference, tokenLogValue = _normalizeValues.tokenLogValue, fallbackLogValue = _normalizeValues.fallbackLogValue, normalizedTokenValue = _normalizeValues.normalizedTokenValue, normalizedFallbackValue = _normalizeValues.normalizedFallbackValue;
147
163
  areEqual = normalizedTokenValue === normalizedFallbackValue;
148
164
  logData = {
149
165
  teamInfo: this.teamInfo,
@@ -156,7 +172,16 @@ export var TokenProcessor = /*#__PURE__*/function () {
156
172
  difference: difference
157
173
  };
158
174
  fallbackRemoved = false;
159
- if (areEqual || isAcceptableDifference || this.options.forceUpdate) {
175
+ // Check if token should be exempted
176
+ _this$checkTokenExemp = this.checkTokenExemption(tokenKey), shouldBeExempted = _this$checkTokenExemp.shouldBeExempted, exemptedPrefix = _this$checkTokenExemp.exemptedPrefix; // Determine if we should modify this token based on the exemption status and settings
177
+ shouldModifyToken =
178
+ // Always modify if not exempted and values match
179
+ areEqual && !shouldBeExempted ||
180
+ // Or if values don't exactly match but are acceptable to modify and not exempted
181
+ (isAcceptableDifference || this.options.forceUpdate) && !shouldBeExempted ||
182
+ // Or if exempted but values match exactly and we're not preserving skipped fallbacks
183
+ areEqual && shouldBeExempted && !this.options.preserveSkippedFallbacks;
184
+ if (shouldModifyToken) {
160
185
  this.log(chalk.green(areEqual ? 'Token value and fallback value are equal, removing fallback' : 'Token value and fallback value are within acceptable difference threshold, removing fallback'));
161
186
  args.pop();
162
187
  this.details.replaced.push(logData);
@@ -164,7 +189,7 @@ export var TokenProcessor = /*#__PURE__*/function () {
164
189
  importDeclaration = resolvedImportDeclaration;
165
190
  localVarDeclaration = resolvedLocalVarDeclaration;
166
191
  } else {
167
- message = normalizedFallbackValue === undefined ? "Fallback value could not be resolved" : "Values mismatched significantly";
192
+ message = shouldBeExempted ? this.options.preserveSkippedFallbacks && areEqual ? "Preserving fallback for exempted token '".concat(tokenKey, "' (matches exemption '").concat(exemptedPrefix, "')") : "Skip modifying exempted token '".concat(tokenKey, "' (matches exemption '").concat(exemptedPrefix, "')") : normalizedFallbackValue === undefined ? "Fallback value could not be resolved" : "Values mismatched significantly";
168
193
  this.logError(message);
169
194
  if (this.options.addEslintComments) {
170
195
  addOrUpdateEslintIgnoreComment(this.j, tokenValue, fallbackValue, callPath);
@@ -178,7 +203,7 @@ export var TokenProcessor = /*#__PURE__*/function () {
178
203
  resolvedImportDeclaration: importDeclaration,
179
204
  resolvedLocalVarDeclaration: localVarDeclaration
180
205
  });
181
- case 30:
206
+ case 26:
182
207
  case "end":
183
208
  return _context2.stop();
184
209
  }
@@ -321,10 +346,57 @@ export var TokenProcessor = /*#__PURE__*/function () {
321
346
  key: "processFallbackAsMemberExpression",
322
347
  value: function () {
323
348
  var _processFallbackAsMemberExpression = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(fallbackValueNode) {
324
- var objectName, propertyName, fallbackValue, rawFallbackValue, resolvedImportDeclaration, importDeclaration, importSource;
349
+ var objectName, propertyName, fallbackValue, resolvedImportDeclaration, resolvedLocalVarDeclaration, _getFullMemberPath, fullMemberPath, pathSegments, localVarDeclaration, _importDeclaration, rawFallbackValue, importDeclaration, importSource;
325
350
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
326
351
  while (1) switch (_context5.prev = _context5.next) {
327
352
  case 0:
353
+ // Function to get full member expression path as string
354
+ _getFullMemberPath = function getFullMemberPath(node) {
355
+ if (node.type === 'Identifier') {
356
+ return node.name;
357
+ } else if (node.type === 'MemberExpression') {
358
+ return "".concat(_getFullMemberPath(node.object), ".").concat(node.property.type === 'Identifier' ? node.property.name : '');
359
+ }
360
+ return '';
361
+ };
362
+ fullMemberPath = _getFullMemberPath(fallbackValueNode); // Detect long member expression paths
363
+ pathSegments = fullMemberPath.split('.');
364
+ if (!(pathSegments.length > 2)) {
365
+ _context5.next = 9;
366
+ break;
367
+ }
368
+ this.logVerbose("Detected long member expression: ".concat(chalk.yellow(fullMemberPath), ". Just resolving import or local variable declaration."));
369
+
370
+ // Find the import statement or local variable for the top-level object
371
+ objectName = pathSegments[0];
372
+
373
+ // Check if it's a local variable
374
+ localVarDeclaration = this.source.find(this.j.VariableDeclarator, {
375
+ id: {
376
+ name: objectName
377
+ }
378
+ }).at(0);
379
+ if (localVarDeclaration.size()) {
380
+ resolvedLocalVarDeclaration = localVarDeclaration.paths()[0];
381
+ this.logVerbose("Resolved local variable declaration for: ".concat(chalk.yellow(objectName)));
382
+ } else {
383
+ // Search for import declaration
384
+ _importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
385
+ if (_importDeclaration.size()) {
386
+ resolvedImportDeclaration = _importDeclaration.paths()[0];
387
+ this.logVerbose("Resolved import declaration for: ".concat(chalk.yellow(objectName)));
388
+ } else {
389
+ this.logError("Could not resolve import or local variable for: ".concat(chalk.yellow(objectName)));
390
+ }
391
+ }
392
+ return _context5.abrupt("return", {
393
+ rawFallbackValue: fullMemberPath,
394
+ fallbackValue: undefined,
395
+ resolvedImportDeclaration: resolvedImportDeclaration,
396
+ resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
397
+ });
398
+ case 9:
399
+ // Existing logic for member expressions with shorter paths
328
400
  if (fallbackValueNode.object.type === 'Identifier') {
329
401
  objectName = fallbackValueNode.object.name;
330
402
  }
@@ -334,7 +406,7 @@ export var TokenProcessor = /*#__PURE__*/function () {
334
406
  propertyName = fallbackValueNode.property.value;
335
407
  }
336
408
  if (!(!objectName || !propertyName)) {
337
- _context5.next = 5;
409
+ _context5.next = 14;
338
410
  break;
339
411
  }
340
412
  this.logError("Could not determine object and property names from member expression: ".concat(chalk.yellow(fallbackValueNode)));
@@ -344,36 +416,37 @@ export var TokenProcessor = /*#__PURE__*/function () {
344
416
  resolvedImportDeclaration: undefined,
345
417
  resolvedLocalVarDeclaration: undefined
346
418
  });
347
- case 5:
419
+ case 14:
348
420
  rawFallbackValue = "".concat(objectName, ".").concat(propertyName);
349
421
  this.logVerbose("Fallback is a member expression: ".concat(chalk.yellow(rawFallbackValue), ", attempting to resolve..."));
422
+
350
423
  // Find the import statement for the object
351
424
  importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
352
425
  if (!importDeclaration.size()) {
353
- _context5.next = 16;
426
+ _context5.next = 25;
354
427
  break;
355
428
  }
356
429
  importSource = importDeclaration.get().value.source.value;
357
- _context5.next = 12;
430
+ _context5.next = 21;
358
431
  return this.resolveValueFromImport(this.rootDir, importSource, objectName, propertyName);
359
- case 12:
432
+ case 21:
360
433
  fallbackValue = _context5.sent;
361
434
  if (fallbackValue !== undefined) {
362
435
  resolvedImportDeclaration = importDeclaration.paths()[0];
363
436
  this.logVerbose("Resolved fallback value from member expression: ".concat(chalk.yellow(fallbackValue)));
364
437
  }
365
- _context5.next = 17;
438
+ _context5.next = 26;
366
439
  break;
367
- case 16:
440
+ case 25:
368
441
  this.logError("Could not find import for member expression: ".concat(chalk.yellow(rawFallbackValue)));
369
- case 17:
442
+ case 26:
370
443
  return _context5.abrupt("return", {
371
444
  rawFallbackValue: rawFallbackValue,
372
445
  fallbackValue: fallbackValue,
373
446
  resolvedImportDeclaration: resolvedImportDeclaration,
374
447
  resolvedLocalVarDeclaration: undefined
375
448
  });
376
- case 18:
449
+ case 27:
377
450
  case "end":
378
451
  return _context5.stop();
379
452
  }
@@ -388,51 +461,108 @@ export var TokenProcessor = /*#__PURE__*/function () {
388
461
  key: "processFallbackAsTemplateLiteral",
389
462
  value: function () {
390
463
  var _processFallbackAsTemplateLiteral = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(fallbackValueNode) {
391
- var expressions, rawFallbackValue, fallbackValue, quasis, exprValue, expression, resolvedImportDeclaration, resolvedLocalVarDeclaration, result, _result;
464
+ var expressions, quasis, resolvedImportDeclaration, resolvedLocalVarDeclaration, rawFallbackValue, fallbackValue, _iterator, _step, _expression, result, _result, exprValue, expression, _result2, _result3;
392
465
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
393
466
  while (1) switch (_context6.prev = _context6.next) {
394
467
  case 0:
395
468
  expressions = fallbackValueNode.expressions;
396
- rawFallbackValue = '';
397
469
  quasis = fallbackValueNode.quasis;
470
+ rawFallbackValue = '';
398
471
  if (!(expressions.length !== 1 || quasis.length !== 2)) {
399
- _context6.next = 6;
472
+ _context6.next = 35;
400
473
  break;
401
474
  }
402
475
  this.logError("Unsupported template literal structure");
476
+
477
+ // Attempt to resolve any imports or local variables used in expressions
478
+ _iterator = _createForOfIteratorHelper(expressions);
479
+ _context6.prev = 6;
480
+ _iterator.s();
481
+ case 8:
482
+ if ((_step = _iterator.n()).done) {
483
+ _context6.next = 26;
484
+ break;
485
+ }
486
+ _expression = _step.value;
487
+ if (!(_expression.type === 'Identifier')) {
488
+ _context6.next = 18;
489
+ break;
490
+ }
491
+ _context6.next = 13;
492
+ return this.processFallbackAsIdentifier(_expression);
493
+ case 13:
494
+ result = _context6.sent;
495
+ if (result.resolvedImportDeclaration) {
496
+ resolvedImportDeclaration = result.resolvedImportDeclaration;
497
+ }
498
+ if (result.resolvedLocalVarDeclaration) {
499
+ resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
500
+ }
501
+ _context6.next = 24;
502
+ break;
503
+ case 18:
504
+ if (!(_expression.type === 'MemberExpression')) {
505
+ _context6.next = 24;
506
+ break;
507
+ }
508
+ _context6.next = 21;
509
+ return this.processFallbackAsMemberExpression(_expression);
510
+ case 21:
511
+ _result = _context6.sent;
512
+ if (_result.resolvedImportDeclaration) {
513
+ resolvedImportDeclaration = _result.resolvedImportDeclaration;
514
+ }
515
+ if (_result.resolvedLocalVarDeclaration) {
516
+ resolvedLocalVarDeclaration = _result.resolvedLocalVarDeclaration;
517
+ }
518
+ case 24:
519
+ _context6.next = 8;
520
+ break;
521
+ case 26:
522
+ _context6.next = 31;
523
+ break;
524
+ case 28:
525
+ _context6.prev = 28;
526
+ _context6.t0 = _context6["catch"](6);
527
+ _iterator.e(_context6.t0);
528
+ case 31:
529
+ _context6.prev = 31;
530
+ _iterator.f();
531
+ return _context6.finish(31);
532
+ case 34:
403
533
  return _context6.abrupt("return", {
404
534
  rawFallbackValue: rawFallbackValue,
405
535
  fallbackValue: fallbackValue,
406
- resolvedImportDeclaration: undefined,
407
- resolvedLocalVarDeclaration: undefined
536
+ resolvedImportDeclaration: resolvedImportDeclaration,
537
+ resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
408
538
  });
409
- case 6:
539
+ case 35:
410
540
  expression = expressions[0];
411
541
  if (!(expression.type === 'Identifier')) {
412
- _context6.next = 16;
542
+ _context6.next = 45;
413
543
  break;
414
544
  }
415
- _context6.next = 10;
545
+ _context6.next = 39;
416
546
  return this.processFallbackAsIdentifier(expression);
417
- case 10:
418
- result = _context6.sent;
419
- exprValue = result.fallbackValue;
420
- resolvedImportDeclaration = result.resolvedImportDeclaration;
421
- resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
422
- _context6.next = 22;
547
+ case 39:
548
+ _result2 = _context6.sent;
549
+ exprValue = _result2.fallbackValue;
550
+ resolvedImportDeclaration = _result2.resolvedImportDeclaration;
551
+ resolvedLocalVarDeclaration = _result2.resolvedLocalVarDeclaration;
552
+ _context6.next = 51;
423
553
  break;
424
- case 16:
554
+ case 45:
425
555
  if (!(expression.type === 'MemberExpression')) {
426
- _context6.next = 22;
556
+ _context6.next = 51;
427
557
  break;
428
558
  }
429
- _context6.next = 19;
559
+ _context6.next = 48;
430
560
  return this.processFallbackAsMemberExpression(expression);
431
- case 19:
432
- _result = _context6.sent;
433
- exprValue = _result.fallbackValue;
434
- resolvedImportDeclaration = _result.resolvedImportDeclaration;
435
- case 22:
561
+ case 48:
562
+ _result3 = _context6.sent;
563
+ exprValue = _result3.fallbackValue;
564
+ resolvedImportDeclaration = _result3.resolvedImportDeclaration;
565
+ case 51:
436
566
  if (exprValue !== undefined) {
437
567
  rawFallbackValue = "".concat(quasis[0].value.raw, "${").concat(exprValue, "}").concat(quasis[1].value.raw);
438
568
  fallbackValue = "".concat(quasis[0].value.cooked).concat(exprValue).concat(quasis[1].value.cooked);
@@ -444,11 +574,11 @@ export var TokenProcessor = /*#__PURE__*/function () {
444
574
  resolvedImportDeclaration: resolvedImportDeclaration,
445
575
  resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
446
576
  });
447
- case 24:
577
+ case 53:
448
578
  case "end":
449
579
  return _context6.stop();
450
580
  }
451
- }, _callee6, this);
581
+ }, _callee6, this, [[6, 28, 31, 34]]);
452
582
  }));
453
583
  function processFallbackAsTemplateLiteral(_x6) {
454
584
  return _processFallbackAsTemplateLiteral.apply(this, arguments);
@@ -472,19 +602,19 @@ export var TokenProcessor = /*#__PURE__*/function () {
472
602
  key: "tryResolveLocalPath",
473
603
  value: function () {
474
604
  var _tryResolveLocalPath = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(currentDir, importPath) {
475
- var _iterator, _step, ext, potentialPath;
605
+ var _iterator2, _step2, ext, potentialPath;
476
606
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
477
607
  while (1) switch (_context7.prev = _context7.next) {
478
608
  case 0:
479
- _iterator = _createForOfIteratorHelper(this.possibleExtensions);
609
+ _iterator2 = _createForOfIteratorHelper(this.possibleExtensions);
480
610
  _context7.prev = 1;
481
- _iterator.s();
611
+ _iterator2.s();
482
612
  case 3:
483
- if ((_step = _iterator.n()).done) {
613
+ if ((_step2 = _iterator2.n()).done) {
484
614
  _context7.next = 17;
485
615
  break;
486
616
  }
487
- ext = _step.value;
617
+ ext = _step2.value;
488
618
  potentialPath = path.resolve(currentDir, "".concat(importPath).concat(ext));
489
619
  _context7.prev = 6;
490
620
  _context7.next = 9;
@@ -504,10 +634,10 @@ export var TokenProcessor = /*#__PURE__*/function () {
504
634
  case 19:
505
635
  _context7.prev = 19;
506
636
  _context7.t1 = _context7["catch"](1);
507
- _iterator.e(_context7.t1);
637
+ _iterator2.e(_context7.t1);
508
638
  case 22:
509
639
  _context7.prev = 22;
510
- _iterator.f();
640
+ _iterator2.f();
511
641
  return _context7.finish(22);
512
642
  case 25:
513
643
  return _context7.abrupt("return", null);
@@ -596,7 +726,7 @@ export var TokenProcessor = /*#__PURE__*/function () {
596
726
  }
597
727
  }, _callee8, this);
598
728
  }));
599
- function resolveValueFromImport(_x9, _x10, _x11, _x12) {
729
+ function resolveValueFromImport(_x9, _x0, _x1, _x10) {
600
730
  return _resolveValueFromImport.apply(this, arguments);
601
731
  }
602
732
  return resolveValueFromImport;
@@ -13,6 +13,14 @@ import { RemoveTokenFallbackOptions } from './types';
13
13
  * @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
14
14
  * @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
15
15
  * @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
16
+ * @param {string} [options.skipTokens] - A comma-separated list of token prefixes to exempt from automatic fallback removal. By default, 'border' tokens are always included in this list. Whether fallbacks for these tokens are removed when they exactly match depends on the preserveSkippedFallbacks option.
17
+ * @param {boolean} [options.preserveSkippedFallbacks] - If true, fallbacks for skipped tokens will never be removed, even if they exactly match the token value. If false (default), fallbacks for skipped tokens will be removed if they exactly match.
18
+ * @param {boolean} [options.skipEslint] - If true, skips running ESLint on modified files after transformation.
19
+ * @param {boolean} [options.skipPrettier] - If true, skips running Prettier on modified files after transformation.
20
+ * @param {number} [options.colorDifferenceThreshold] - The maximum allowed difference for color tokens to be considered acceptable for removal. Default is 15.
21
+ * @param {number} [options.spaceDifferenceThreshold] - The maximum allowed percentage difference for space tokens to be considered acceptable for removal. Default is 0.
22
+ * @param {number} [options.numericDifferenceThreshold] - The maximum allowed percentage difference for numeric tokens to be considered acceptable for removal. Default is 0.
23
+ * @param {number} [options.borderDifferenceThreshold] - The maximum allowed percentage difference for border tokens to be considered acceptable for removal. Default is 0.
16
24
  *
17
25
  * @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
18
26
  */
@@ -24,6 +32,6 @@ export declare const parser = "tsx";
24
32
  export declare function beforeAll(options: RemoveTokenFallbackOptions): Promise<void>;
25
33
  /**
26
34
  * Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
27
- * It also applies prettier to the affected files.
35
+ * It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
28
36
  */
29
37
  export declare function afterAll(options: RemoveTokenFallbackOptions): Promise<void>;
@@ -22,6 +22,14 @@ export type RemoveTokenFallbackOptions = Options & {
22
22
  reportFolder?: string;
23
23
  addEslintComments?: boolean;
24
24
  forceUpdate?: boolean;
25
+ skipTokens?: string;
26
+ preserveSkippedFallbacks?: boolean;
27
+ skipEslint?: boolean;
28
+ skipPrettier?: boolean;
29
+ colorDifferenceThreshold?: number;
30
+ spaceDifferenceThreshold?: number;
31
+ numericDifferenceThreshold?: number;
32
+ borderDifferenceThreshold?: number;
25
33
  };
26
34
  export type WithResolvedDeclarations = {
27
35
  resolvedImportDeclaration?: ASTPath<ImportDeclaration>;
@@ -0,0 +1 @@
1
+ export declare const chunkArray: <T>(array: T[], chunkSize: number) => T[][];
@@ -1,4 +1,5 @@
1
- export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined): {
1
+ import { RemoveTokenFallbackOptions } from '../types';
2
+ export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined, options?: RemoveTokenFallbackOptions): {
2
3
  difference?: number;
3
4
  isAcceptableDifference?: boolean;
4
5
  tokenLogValue: string;
@@ -16,6 +16,12 @@ export declare class TokenProcessor {
16
16
  private logVerbose;
17
17
  private log;
18
18
  private logError;
19
+ /**
20
+ * Checks if a token should be exempted from automatic fallback removal
21
+ * @param tokenKey The token key to check
22
+ * @returns An object containing whether the token should be exempted and related information
23
+ */
24
+ private checkTokenExemption;
19
25
  private processSingleToken;
20
26
  private getTokenKey;
21
27
  private getFallbackValue;
@@ -13,6 +13,14 @@ import { RemoveTokenFallbackOptions } from './types';
13
13
  * @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
14
14
  * @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
15
15
  * @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
16
+ * @param {string} [options.skipTokens] - A comma-separated list of token prefixes to exempt from automatic fallback removal. By default, 'border' tokens are always included in this list. Whether fallbacks for these tokens are removed when they exactly match depends on the preserveSkippedFallbacks option.
17
+ * @param {boolean} [options.preserveSkippedFallbacks] - If true, fallbacks for skipped tokens will never be removed, even if they exactly match the token value. If false (default), fallbacks for skipped tokens will be removed if they exactly match.
18
+ * @param {boolean} [options.skipEslint] - If true, skips running ESLint on modified files after transformation.
19
+ * @param {boolean} [options.skipPrettier] - If true, skips running Prettier on modified files after transformation.
20
+ * @param {number} [options.colorDifferenceThreshold] - The maximum allowed difference for color tokens to be considered acceptable for removal. Default is 15.
21
+ * @param {number} [options.spaceDifferenceThreshold] - The maximum allowed percentage difference for space tokens to be considered acceptable for removal. Default is 0.
22
+ * @param {number} [options.numericDifferenceThreshold] - The maximum allowed percentage difference for numeric tokens to be considered acceptable for removal. Default is 0.
23
+ * @param {number} [options.borderDifferenceThreshold] - The maximum allowed percentage difference for border tokens to be considered acceptable for removal. Default is 0.
16
24
  *
17
25
  * @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
18
26
  */
@@ -24,6 +32,6 @@ export declare const parser = "tsx";
24
32
  export declare function beforeAll(options: RemoveTokenFallbackOptions): Promise<void>;
25
33
  /**
26
34
  * Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
27
- * It also applies prettier to the affected files.
35
+ * It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
28
36
  */
29
37
  export declare function afterAll(options: RemoveTokenFallbackOptions): Promise<void>;
@@ -22,6 +22,14 @@ export type RemoveTokenFallbackOptions = Options & {
22
22
  reportFolder?: string;
23
23
  addEslintComments?: boolean;
24
24
  forceUpdate?: boolean;
25
+ skipTokens?: string;
26
+ preserveSkippedFallbacks?: boolean;
27
+ skipEslint?: boolean;
28
+ skipPrettier?: boolean;
29
+ colorDifferenceThreshold?: number;
30
+ spaceDifferenceThreshold?: number;
31
+ numericDifferenceThreshold?: number;
32
+ borderDifferenceThreshold?: number;
25
33
  };
26
34
  export type WithResolvedDeclarations = {
27
35
  resolvedImportDeclaration?: ASTPath<ImportDeclaration>;
@@ -0,0 +1 @@
1
+ export declare const chunkArray: <T>(array: T[], chunkSize: number) => T[][];
@@ -1,4 +1,5 @@
1
- export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined): {
1
+ import { RemoveTokenFallbackOptions } from '../types';
2
+ export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined, options?: RemoveTokenFallbackOptions): {
2
3
  difference?: number;
3
4
  isAcceptableDifference?: boolean;
4
5
  tokenLogValue: string;
@@ -16,6 +16,12 @@ export declare class TokenProcessor {
16
16
  private logVerbose;
17
17
  private log;
18
18
  private logError;
19
+ /**
20
+ * Checks if a token should be exempted from automatic fallback removal
21
+ * @param tokenKey The token key to check
22
+ * @returns An object containing whether the token should be exempted and related information
23
+ */
24
+ private checkTokenExemption;
19
25
  private processSingleToken;
20
26
  private getTokenKey;
21
27
  private getFallbackValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.27.4",
3
+ "version": "0.28.1",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -39,7 +39,7 @@
39
39
  "bin": "./bin/codemod-cli.js",
40
40
  "dependencies": {
41
41
  "@atlaskit/codemod-utils": "^4.2.0",
42
- "@atlaskit/tokens": "^4.5.0",
42
+ "@atlaskit/tokens": "^5.0.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@codeshift/utils": "^0.2.4",
45
45
  "@hypermod/utils": "^0.4.2",
@@ -49,7 +49,7 @@
49
49
  "color-diff": "^1.2.0",
50
50
  "enquirer": "^2.3.4",
51
51
  "glob": "9.0.0",
52
- "jscodeshift": "^0.16.1",
52
+ "jscodeshift": "^17.0.0",
53
53
  "meow": "^8.1.1",
54
54
  "projector-spawn": "^1.0.1",
55
55
  "read-pkg-up": "^7.0.1",
@@ -58,7 +58,7 @@
58
58
  "uuid": "^3.1.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@af/formatting": "^0.0.4",
61
+ "@af/formatting": "workspace:^",
62
62
  "@types/color-diff": "^1.2.1",
63
63
  "prettier": "^3.2.5",
64
64
  "ts-node": "^10.9.1",