@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
@@ -8,11 +8,17 @@ exports.normalizeValues = normalizeValues;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _chalk = _interopRequireDefault(require("chalk"));
10
10
  var _colorUtils = require("./color-utils");
11
- // so far allowing to remove only exact matches in values. Can be increased to auto-remove fallbacks with similar values
12
- var ACCEPTABLE_COLOR_DIFFERENCE = 0;
13
- var ACCEPTABLE_SPACE_DIFFERENCE = 0;
14
- var ACCEPTABLE_NUMERIC_DIFFERENCE = 0;
15
- function normalizeValues(tokenKey, tokenValue, fallbackValue) {
11
+ // Default threshold values
12
+ var DEFAULT_COLOR_DIFFERENCE = 15;
13
+ var DEFAULT_SPACE_DIFFERENCE = 0;
14
+ var DEFAULT_NUMERIC_DIFFERENCE = 0;
15
+ var DEFAULT_BORDER_DIFFERENCE = 0;
16
+ function normalizeValues(tokenKey, tokenValue, fallbackValue, options) {
17
+ // Use options thresholds or defaults
18
+ var colorDifference = (options === null || options === void 0 ? void 0 : options.colorDifferenceThreshold) !== undefined ? options.colorDifferenceThreshold : DEFAULT_COLOR_DIFFERENCE;
19
+ var spaceDifference = (options === null || options === void 0 ? void 0 : options.spaceDifferenceThreshold) !== undefined ? options.spaceDifferenceThreshold : DEFAULT_SPACE_DIFFERENCE;
20
+ var numericDifference = (options === null || options === void 0 ? void 0 : options.numericDifferenceThreshold) !== undefined ? options.numericDifferenceThreshold : DEFAULT_NUMERIC_DIFFERENCE;
21
+ var borderDifference = (options === null || options === void 0 ? void 0 : options.borderDifferenceThreshold) !== undefined ? options.borderDifferenceThreshold : DEFAULT_BORDER_DIFFERENCE;
16
22
  var tokenLogValue;
17
23
  var fallbackLogValue;
18
24
  var normalizedTokenValue = tokenValue;
@@ -33,15 +39,15 @@ function normalizeValues(tokenKey, tokenValue, fallbackValue) {
33
39
  }
34
40
  if (normalizedTokenValue && normalizedFallbackValue) {
35
41
  difference = (0, _colorUtils.compareHex)(normalizedTokenValue, normalizedFallbackValue);
36
- isAcceptableDifference = difference <= ACCEPTABLE_COLOR_DIFFERENCE;
42
+ isAcceptableDifference = difference <= colorDifference;
37
43
  }
38
- } else if (lowerCaseTokenKey.startsWith('space')) {
44
+ } else if (lowerCaseTokenKey.startsWith('space') || lowerCaseTokenKey.startsWith('border')) {
39
45
  var tokenValueInPx = tokenValue ? convertToPx(tokenValue) : undefined;
40
46
  var fallbackValueInPx = fallbackValue ? convertToPx(fallbackValue) : undefined;
41
47
  if (tokenValueInPx !== undefined && fallbackValueInPx !== undefined) {
42
48
  var maxVal = Math.max(tokenValueInPx, fallbackValueInPx);
43
49
  difference = Math.abs(tokenValueInPx - fallbackValueInPx) / maxVal * 100;
44
- isAcceptableDifference = difference <= ACCEPTABLE_SPACE_DIFFERENCE;
50
+ isAcceptableDifference = difference <= (lowerCaseTokenKey.startsWith('space') ? spaceDifference : borderDifference);
45
51
  }
46
52
  // Log the normalized values
47
53
  normalizedTokenValue = tokenValue;
@@ -55,7 +61,7 @@ function normalizeValues(tokenKey, tokenValue, fallbackValue) {
55
61
  if (!isNaN(tokenValueNumber) && !isNaN(fallbackValueNumber)) {
56
62
  var _maxVal = Math.max(tokenValueNumber, fallbackValueNumber);
57
63
  difference = Math.abs(tokenValueNumber - fallbackValueNumber) / _maxVal * 100;
58
- isAcceptableDifference = difference <= ACCEPTABLE_NUMERIC_DIFFERENCE;
64
+ isAcceptableDifference = difference <= numericDifference;
59
65
  }
60
66
  // Log the normalized values
61
67
  normalizedTokenValue = tokenValue;
@@ -46,12 +46,12 @@ function removeUnusedImports(importDeclarations, j) {
46
46
  };
47
47
  var processImportDeclaration = function processImportDeclaration(importDeclaration) {
48
48
  var _importDeclaration$va, _importDeclaration$va2;
49
- if (((_importDeclaration$va = importDeclaration.value.specifiers) === null || _importDeclaration$va === void 0 ? void 0 : _importDeclaration$va.length) === 0) {
49
+ if (((_importDeclaration$va = importDeclaration.value) === null || _importDeclaration$va === void 0 || (_importDeclaration$va = _importDeclaration$va.specifiers) === null || _importDeclaration$va === void 0 ? void 0 : _importDeclaration$va.length) === 0) {
50
50
  return false;
51
51
  }
52
52
  var hadUnusedDefaultImport = removeUnusedDefaultImport(importDeclaration);
53
53
  var hadUnusedNonDefaultImports = removeUnusedNonDefaultImports(importDeclaration);
54
- if (((_importDeclaration$va2 = importDeclaration.value.specifiers) === null || _importDeclaration$va2 === void 0 ? void 0 : _importDeclaration$va2.length) === 0) {
54
+ if (((_importDeclaration$va2 = importDeclaration.value) === null || _importDeclaration$va2 === void 0 || (_importDeclaration$va2 = _importDeclaration$va2.specifiers) === null || _importDeclaration$va2 === void 0 ? void 0 : _importDeclaration$va2.length) === 0) {
55
55
  j(importDeclaration).remove();
56
56
  return true;
57
57
  }
@@ -82,41 +82,47 @@ function _clearFolder() {
82
82
  while (1) switch (_context3.prev = _context3.next) {
83
83
  case 0:
84
84
  console.log('Clearing report folder:', reportFolder);
85
+ // Create the folder if it doesn't exist
85
86
  _context3.next = 3;
86
- return _promises.default.readdir(reportFolder);
87
+ return _promises.default.mkdir(reportFolder, {
88
+ recursive: true
89
+ });
87
90
  case 3:
91
+ _context3.next = 5;
92
+ return _promises.default.readdir(reportFolder);
93
+ case 5:
88
94
  filesToDelete = _context3.sent;
89
95
  _iterator = _createForOfIteratorHelper(filesToDelete);
90
- _context3.prev = 5;
96
+ _context3.prev = 7;
91
97
  _iterator.s();
92
- case 7:
98
+ case 9:
93
99
  if ((_step = _iterator.n()).done) {
94
- _context3.next = 14;
100
+ _context3.next = 16;
95
101
  break;
96
102
  }
97
103
  file = _step.value;
98
104
  filePath = _path.default.join(reportFolder, file);
99
- _context3.next = 12;
105
+ _context3.next = 14;
100
106
  return _promises.default.unlink(filePath);
101
- case 12:
102
- _context3.next = 7;
103
- break;
104
107
  case 14:
105
- _context3.next = 19;
108
+ _context3.next = 9;
106
109
  break;
107
110
  case 16:
108
- _context3.prev = 16;
109
- _context3.t0 = _context3["catch"](5);
111
+ _context3.next = 21;
112
+ break;
113
+ case 18:
114
+ _context3.prev = 18;
115
+ _context3.t0 = _context3["catch"](7);
110
116
  _iterator.e(_context3.t0);
111
- case 19:
112
- _context3.prev = 19;
117
+ case 21:
118
+ _context3.prev = 21;
113
119
  _iterator.f();
114
- return _context3.finish(19);
115
- case 22:
120
+ return _context3.finish(21);
121
+ case 24:
116
122
  case "end":
117
123
  return _context3.stop();
118
124
  }
119
- }, _callee3, null, [[5, 16, 19, 22]]);
125
+ }, _callee3, null, [[7, 18, 21, 24]]);
120
126
  }));
121
127
  return _clearFolder.apply(this, arguments);
122
128
  }
@@ -125,16 +131,17 @@ function saveFilePaths(_x5, _x6) {
125
131
  }
126
132
  function _saveFilePaths() {
127
133
  _saveFilePaths = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(reportFolder, files) {
128
- var filesTxtPath;
134
+ var filesTxtPath, sortedFiles;
129
135
  return _regenerator.default.wrap(function _callee4$(_context4) {
130
136
  while (1) switch (_context4.prev = _context4.next) {
131
137
  case 0:
132
138
  filesTxtPath = _path.default.join(reportFolder, 'files.txt');
133
- _context4.next = 3;
134
- return _promises.default.writeFile(filesTxtPath, Array.from(files).map(function (filePath) {
139
+ sortedFiles = Array.from(files).sort(); // Sort the file paths alphabetically
140
+ _context4.next = 4;
141
+ return _promises.default.writeFile(filesTxtPath, sortedFiles.map(function (filePath) {
135
142
  return "\"".concat(filePath, "\"");
136
- }).join(' '), 'utf-8');
137
- case 3:
143
+ }).join('\n'), 'utf-8');
144
+ case 4:
138
145
  case "end":
139
146
  return _context4.stop();
140
147
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.TokenProcessor = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -89,12 +90,43 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
89
90
  value: function logError(message) {
90
91
  this.log(_chalk.default.red(message));
91
92
  }
93
+
94
+ /**
95
+ * Checks if a token should be exempted from automatic fallback removal
96
+ * @param tokenKey The token key to check
97
+ * @returns An object containing whether the token should be exempted and related information
98
+ */
99
+ }, {
100
+ key: "checkTokenExemption",
101
+ value: function checkTokenExemption(tokenKey) {
102
+ // Create exemption list from user-provided skipTokens, and always include 'border'
103
+ var userExemptions = this.options.skipTokens ? this.options.skipTokens.split(',').map(function (item) {
104
+ return item.trim();
105
+ }) : [];
106
+
107
+ // Always include 'border' in the exemption list
108
+ var exemptionList = (0, _toConsumableArray2.default)(userExemptions);
109
+ if (!exemptionList.includes('border')) {
110
+ exemptionList.push('border');
111
+ }
112
+ var isExemptedToken = exemptionList.some(function (prefix) {
113
+ return tokenKey.startsWith(prefix);
114
+ });
115
+ var exemptedPrefix = isExemptedToken ? exemptionList.find(function (prefix) {
116
+ return tokenKey.startsWith(prefix);
117
+ }) || null : null;
118
+ return {
119
+ shouldBeExempted: isExemptedToken,
120
+ exemptedPrefix: exemptedPrefix,
121
+ exemptionList: exemptionList
122
+ };
123
+ }
92
124
  }, {
93
125
  key: "processSingleToken",
94
126
  value: function () {
95
127
  var _processSingleToken = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(callPath) {
96
128
  var _callPath$node$loc2;
97
- var args, line, tokenKey, isSkipped, tokenValue, _ref, rawFallbackValue, fallbackValue, resolvedImportDeclaration, resolvedLocalVarDeclaration, _normalizeValues, difference, isAcceptableDifference, tokenLogValue, fallbackLogValue, normalizedTokenValue, normalizedFallbackValue, areEqual, logData, fallbackRemoved, importDeclaration, localVarDeclaration, message;
129
+ 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;
98
130
  return _regenerator.default.wrap(function _callee2$(_context2) {
99
131
  while (1) switch (_context2.prev = _context2.next) {
100
132
  case 0:
@@ -124,33 +156,17 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
124
156
  resolvedLocalVarDeclaration: undefined
125
157
  });
126
158
  case 8:
127
- isSkipped = tokenKey.startsWith('elevation.shadow') || tokenKey.startsWith('font.body') || tokenKey.startsWith('font.heading');
128
- tokenValue = isSkipped ? '' : this.tokenMap[tokenKey];
159
+ tokenValue = this.tokenMap[tokenKey];
129
160
  this.logVerbose("Token value from tokenMap: ".concat(_chalk.default.magenta(tokenValue), " for key: ").concat(_chalk.default.yellow(tokenKey)));
130
- if (!isSkipped) {
131
- _context2.next = 15;
132
- break;
133
- }
134
- _context2.t0 = {
135
- rawFallbackValue: 'N/A',
136
- fallbackValue: undefined,
137
- resolvedImportDeclaration: undefined,
138
- resolvedLocalVarDeclaration: undefined
139
- };
140
- _context2.next = 18;
141
- break;
142
- case 15:
143
- _context2.next = 17;
161
+ _context2.next = 12;
144
162
  return this.getFallbackValue(args[1]);
145
- case 17:
146
- _context2.t0 = _context2.sent;
147
- case 18:
148
- _ref = _context2.t0;
149
- rawFallbackValue = _ref.rawFallbackValue;
150
- fallbackValue = _ref.fallbackValue;
151
- resolvedImportDeclaration = _ref.resolvedImportDeclaration;
152
- resolvedLocalVarDeclaration = _ref.resolvedLocalVarDeclaration;
153
- _normalizeValues = (0, _normalizeValues2.normalizeValues)(tokenKey, tokenValue, fallbackValue), difference = _normalizeValues.difference, isAcceptableDifference = _normalizeValues.isAcceptableDifference, tokenLogValue = _normalizeValues.tokenLogValue, fallbackLogValue = _normalizeValues.fallbackLogValue, normalizedTokenValue = _normalizeValues.normalizedTokenValue, normalizedFallbackValue = _normalizeValues.normalizedFallbackValue;
163
+ case 12:
164
+ _yield$this$getFallba = _context2.sent;
165
+ rawFallbackValue = _yield$this$getFallba.rawFallbackValue;
166
+ fallbackValue = _yield$this$getFallba.fallbackValue;
167
+ resolvedImportDeclaration = _yield$this$getFallba.resolvedImportDeclaration;
168
+ resolvedLocalVarDeclaration = _yield$this$getFallba.resolvedLocalVarDeclaration;
169
+ _normalizeValues = (0, _normalizeValues2.normalizeValues)(tokenKey, tokenValue, fallbackValue, this.options), difference = _normalizeValues.difference, isAcceptableDifference = _normalizeValues.isAcceptableDifference, tokenLogValue = _normalizeValues.tokenLogValue, fallbackLogValue = _normalizeValues.fallbackLogValue, normalizedTokenValue = _normalizeValues.normalizedTokenValue, normalizedFallbackValue = _normalizeValues.normalizedFallbackValue;
154
170
  areEqual = normalizedTokenValue === normalizedFallbackValue;
155
171
  logData = {
156
172
  teamInfo: this.teamInfo,
@@ -163,7 +179,16 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
163
179
  difference: difference
164
180
  };
165
181
  fallbackRemoved = false;
166
- if (areEqual || isAcceptableDifference || this.options.forceUpdate) {
182
+ // Check if token should be exempted
183
+ _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
184
+ shouldModifyToken =
185
+ // Always modify if not exempted and values match
186
+ areEqual && !shouldBeExempted ||
187
+ // Or if values don't exactly match but are acceptable to modify and not exempted
188
+ (isAcceptableDifference || this.options.forceUpdate) && !shouldBeExempted ||
189
+ // Or if exempted but values match exactly and we're not preserving skipped fallbacks
190
+ areEqual && shouldBeExempted && !this.options.preserveSkippedFallbacks;
191
+ if (shouldModifyToken) {
167
192
  this.log(_chalk.default.green(areEqual ? 'Token value and fallback value are equal, removing fallback' : 'Token value and fallback value are within acceptable difference threshold, removing fallback'));
168
193
  args.pop();
169
194
  this.details.replaced.push(logData);
@@ -171,7 +196,7 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
171
196
  importDeclaration = resolvedImportDeclaration;
172
197
  localVarDeclaration = resolvedLocalVarDeclaration;
173
198
  } else {
174
- message = normalizedFallbackValue === undefined ? "Fallback value could not be resolved" : "Values mismatched significantly";
199
+ 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";
175
200
  this.logError(message);
176
201
  if (this.options.addEslintComments) {
177
202
  (0, _updateComments.addOrUpdateEslintIgnoreComment)(this.j, tokenValue, fallbackValue, callPath);
@@ -185,7 +210,7 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
185
210
  resolvedImportDeclaration: importDeclaration,
186
211
  resolvedLocalVarDeclaration: localVarDeclaration
187
212
  });
188
- case 30:
213
+ case 26:
189
214
  case "end":
190
215
  return _context2.stop();
191
216
  }
@@ -328,10 +353,57 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
328
353
  key: "processFallbackAsMemberExpression",
329
354
  value: function () {
330
355
  var _processFallbackAsMemberExpression = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(fallbackValueNode) {
331
- var objectName, propertyName, fallbackValue, rawFallbackValue, resolvedImportDeclaration, importDeclaration, importSource;
356
+ var objectName, propertyName, fallbackValue, resolvedImportDeclaration, resolvedLocalVarDeclaration, _getFullMemberPath, fullMemberPath, pathSegments, localVarDeclaration, _importDeclaration, rawFallbackValue, importDeclaration, importSource;
332
357
  return _regenerator.default.wrap(function _callee5$(_context5) {
333
358
  while (1) switch (_context5.prev = _context5.next) {
334
359
  case 0:
360
+ // Function to get full member expression path as string
361
+ _getFullMemberPath = function getFullMemberPath(node) {
362
+ if (node.type === 'Identifier') {
363
+ return node.name;
364
+ } else if (node.type === 'MemberExpression') {
365
+ return "".concat(_getFullMemberPath(node.object), ".").concat(node.property.type === 'Identifier' ? node.property.name : '');
366
+ }
367
+ return '';
368
+ };
369
+ fullMemberPath = _getFullMemberPath(fallbackValueNode); // Detect long member expression paths
370
+ pathSegments = fullMemberPath.split('.');
371
+ if (!(pathSegments.length > 2)) {
372
+ _context5.next = 9;
373
+ break;
374
+ }
375
+ this.logVerbose("Detected long member expression: ".concat(_chalk.default.yellow(fullMemberPath), ". Just resolving import or local variable declaration."));
376
+
377
+ // Find the import statement or local variable for the top-level object
378
+ objectName = pathSegments[0];
379
+
380
+ // Check if it's a local variable
381
+ localVarDeclaration = this.source.find(this.j.VariableDeclarator, {
382
+ id: {
383
+ name: objectName
384
+ }
385
+ }).at(0);
386
+ if (localVarDeclaration.size()) {
387
+ resolvedLocalVarDeclaration = localVarDeclaration.paths()[0];
388
+ this.logVerbose("Resolved local variable declaration for: ".concat(_chalk.default.yellow(objectName)));
389
+ } else {
390
+ // Search for import declaration
391
+ _importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
392
+ if (_importDeclaration.size()) {
393
+ resolvedImportDeclaration = _importDeclaration.paths()[0];
394
+ this.logVerbose("Resolved import declaration for: ".concat(_chalk.default.yellow(objectName)));
395
+ } else {
396
+ this.logError("Could not resolve import or local variable for: ".concat(_chalk.default.yellow(objectName)));
397
+ }
398
+ }
399
+ return _context5.abrupt("return", {
400
+ rawFallbackValue: fullMemberPath,
401
+ fallbackValue: undefined,
402
+ resolvedImportDeclaration: resolvedImportDeclaration,
403
+ resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
404
+ });
405
+ case 9:
406
+ // Existing logic for member expressions with shorter paths
335
407
  if (fallbackValueNode.object.type === 'Identifier') {
336
408
  objectName = fallbackValueNode.object.name;
337
409
  }
@@ -341,7 +413,7 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
341
413
  propertyName = fallbackValueNode.property.value;
342
414
  }
343
415
  if (!(!objectName || !propertyName)) {
344
- _context5.next = 5;
416
+ _context5.next = 14;
345
417
  break;
346
418
  }
347
419
  this.logError("Could not determine object and property names from member expression: ".concat(_chalk.default.yellow(fallbackValueNode)));
@@ -351,36 +423,37 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
351
423
  resolvedImportDeclaration: undefined,
352
424
  resolvedLocalVarDeclaration: undefined
353
425
  });
354
- case 5:
426
+ case 14:
355
427
  rawFallbackValue = "".concat(objectName, ".").concat(propertyName);
356
428
  this.logVerbose("Fallback is a member expression: ".concat(_chalk.default.yellow(rawFallbackValue), ", attempting to resolve..."));
429
+
357
430
  // Find the import statement for the object
358
431
  importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
359
432
  if (!importDeclaration.size()) {
360
- _context5.next = 16;
433
+ _context5.next = 25;
361
434
  break;
362
435
  }
363
436
  importSource = importDeclaration.get().value.source.value;
364
- _context5.next = 12;
437
+ _context5.next = 21;
365
438
  return this.resolveValueFromImport(this.rootDir, importSource, objectName, propertyName);
366
- case 12:
439
+ case 21:
367
440
  fallbackValue = _context5.sent;
368
441
  if (fallbackValue !== undefined) {
369
442
  resolvedImportDeclaration = importDeclaration.paths()[0];
370
443
  this.logVerbose("Resolved fallback value from member expression: ".concat(_chalk.default.yellow(fallbackValue)));
371
444
  }
372
- _context5.next = 17;
445
+ _context5.next = 26;
373
446
  break;
374
- case 16:
447
+ case 25:
375
448
  this.logError("Could not find import for member expression: ".concat(_chalk.default.yellow(rawFallbackValue)));
376
- case 17:
449
+ case 26:
377
450
  return _context5.abrupt("return", {
378
451
  rawFallbackValue: rawFallbackValue,
379
452
  fallbackValue: fallbackValue,
380
453
  resolvedImportDeclaration: resolvedImportDeclaration,
381
454
  resolvedLocalVarDeclaration: undefined
382
455
  });
383
- case 18:
456
+ case 27:
384
457
  case "end":
385
458
  return _context5.stop();
386
459
  }
@@ -395,51 +468,108 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
395
468
  key: "processFallbackAsTemplateLiteral",
396
469
  value: function () {
397
470
  var _processFallbackAsTemplateLiteral = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(fallbackValueNode) {
398
- var expressions, rawFallbackValue, fallbackValue, quasis, exprValue, expression, resolvedImportDeclaration, resolvedLocalVarDeclaration, result, _result;
471
+ var expressions, quasis, resolvedImportDeclaration, resolvedLocalVarDeclaration, rawFallbackValue, fallbackValue, _iterator, _step, _expression, result, _result, exprValue, expression, _result2, _result3;
399
472
  return _regenerator.default.wrap(function _callee6$(_context6) {
400
473
  while (1) switch (_context6.prev = _context6.next) {
401
474
  case 0:
402
475
  expressions = fallbackValueNode.expressions;
403
- rawFallbackValue = '';
404
476
  quasis = fallbackValueNode.quasis;
477
+ rawFallbackValue = '';
405
478
  if (!(expressions.length !== 1 || quasis.length !== 2)) {
406
- _context6.next = 6;
479
+ _context6.next = 35;
407
480
  break;
408
481
  }
409
482
  this.logError("Unsupported template literal structure");
483
+
484
+ // Attempt to resolve any imports or local variables used in expressions
485
+ _iterator = _createForOfIteratorHelper(expressions);
486
+ _context6.prev = 6;
487
+ _iterator.s();
488
+ case 8:
489
+ if ((_step = _iterator.n()).done) {
490
+ _context6.next = 26;
491
+ break;
492
+ }
493
+ _expression = _step.value;
494
+ if (!(_expression.type === 'Identifier')) {
495
+ _context6.next = 18;
496
+ break;
497
+ }
498
+ _context6.next = 13;
499
+ return this.processFallbackAsIdentifier(_expression);
500
+ case 13:
501
+ result = _context6.sent;
502
+ if (result.resolvedImportDeclaration) {
503
+ resolvedImportDeclaration = result.resolvedImportDeclaration;
504
+ }
505
+ if (result.resolvedLocalVarDeclaration) {
506
+ resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
507
+ }
508
+ _context6.next = 24;
509
+ break;
510
+ case 18:
511
+ if (!(_expression.type === 'MemberExpression')) {
512
+ _context6.next = 24;
513
+ break;
514
+ }
515
+ _context6.next = 21;
516
+ return this.processFallbackAsMemberExpression(_expression);
517
+ case 21:
518
+ _result = _context6.sent;
519
+ if (_result.resolvedImportDeclaration) {
520
+ resolvedImportDeclaration = _result.resolvedImportDeclaration;
521
+ }
522
+ if (_result.resolvedLocalVarDeclaration) {
523
+ resolvedLocalVarDeclaration = _result.resolvedLocalVarDeclaration;
524
+ }
525
+ case 24:
526
+ _context6.next = 8;
527
+ break;
528
+ case 26:
529
+ _context6.next = 31;
530
+ break;
531
+ case 28:
532
+ _context6.prev = 28;
533
+ _context6.t0 = _context6["catch"](6);
534
+ _iterator.e(_context6.t0);
535
+ case 31:
536
+ _context6.prev = 31;
537
+ _iterator.f();
538
+ return _context6.finish(31);
539
+ case 34:
410
540
  return _context6.abrupt("return", {
411
541
  rawFallbackValue: rawFallbackValue,
412
542
  fallbackValue: fallbackValue,
413
- resolvedImportDeclaration: undefined,
414
- resolvedLocalVarDeclaration: undefined
543
+ resolvedImportDeclaration: resolvedImportDeclaration,
544
+ resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
415
545
  });
416
- case 6:
546
+ case 35:
417
547
  expression = expressions[0];
418
548
  if (!(expression.type === 'Identifier')) {
419
- _context6.next = 16;
549
+ _context6.next = 45;
420
550
  break;
421
551
  }
422
- _context6.next = 10;
552
+ _context6.next = 39;
423
553
  return this.processFallbackAsIdentifier(expression);
424
- case 10:
425
- result = _context6.sent;
426
- exprValue = result.fallbackValue;
427
- resolvedImportDeclaration = result.resolvedImportDeclaration;
428
- resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
429
- _context6.next = 22;
554
+ case 39:
555
+ _result2 = _context6.sent;
556
+ exprValue = _result2.fallbackValue;
557
+ resolvedImportDeclaration = _result2.resolvedImportDeclaration;
558
+ resolvedLocalVarDeclaration = _result2.resolvedLocalVarDeclaration;
559
+ _context6.next = 51;
430
560
  break;
431
- case 16:
561
+ case 45:
432
562
  if (!(expression.type === 'MemberExpression')) {
433
- _context6.next = 22;
563
+ _context6.next = 51;
434
564
  break;
435
565
  }
436
- _context6.next = 19;
566
+ _context6.next = 48;
437
567
  return this.processFallbackAsMemberExpression(expression);
438
- case 19:
439
- _result = _context6.sent;
440
- exprValue = _result.fallbackValue;
441
- resolvedImportDeclaration = _result.resolvedImportDeclaration;
442
- case 22:
568
+ case 48:
569
+ _result3 = _context6.sent;
570
+ exprValue = _result3.fallbackValue;
571
+ resolvedImportDeclaration = _result3.resolvedImportDeclaration;
572
+ case 51:
443
573
  if (exprValue !== undefined) {
444
574
  rawFallbackValue = "".concat(quasis[0].value.raw, "${").concat(exprValue, "}").concat(quasis[1].value.raw);
445
575
  fallbackValue = "".concat(quasis[0].value.cooked).concat(exprValue).concat(quasis[1].value.cooked);
@@ -451,11 +581,11 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
451
581
  resolvedImportDeclaration: resolvedImportDeclaration,
452
582
  resolvedLocalVarDeclaration: resolvedLocalVarDeclaration
453
583
  });
454
- case 24:
584
+ case 53:
455
585
  case "end":
456
586
  return _context6.stop();
457
587
  }
458
- }, _callee6, this);
588
+ }, _callee6, this, [[6, 28, 31, 34]]);
459
589
  }));
460
590
  function processFallbackAsTemplateLiteral(_x6) {
461
591
  return _processFallbackAsTemplateLiteral.apply(this, arguments);
@@ -479,19 +609,19 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
479
609
  key: "tryResolveLocalPath",
480
610
  value: function () {
481
611
  var _tryResolveLocalPath = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(currentDir, importPath) {
482
- var _iterator, _step, ext, potentialPath;
612
+ var _iterator2, _step2, ext, potentialPath;
483
613
  return _regenerator.default.wrap(function _callee7$(_context7) {
484
614
  while (1) switch (_context7.prev = _context7.next) {
485
615
  case 0:
486
- _iterator = _createForOfIteratorHelper(this.possibleExtensions);
616
+ _iterator2 = _createForOfIteratorHelper(this.possibleExtensions);
487
617
  _context7.prev = 1;
488
- _iterator.s();
618
+ _iterator2.s();
489
619
  case 3:
490
- if ((_step = _iterator.n()).done) {
620
+ if ((_step2 = _iterator2.n()).done) {
491
621
  _context7.next = 17;
492
622
  break;
493
623
  }
494
- ext = _step.value;
624
+ ext = _step2.value;
495
625
  potentialPath = _path.default.resolve(currentDir, "".concat(importPath).concat(ext));
496
626
  _context7.prev = 6;
497
627
  _context7.next = 9;
@@ -511,10 +641,10 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
511
641
  case 19:
512
642
  _context7.prev = 19;
513
643
  _context7.t1 = _context7["catch"](1);
514
- _iterator.e(_context7.t1);
644
+ _iterator2.e(_context7.t1);
515
645
  case 22:
516
646
  _context7.prev = 22;
517
- _iterator.f();
647
+ _iterator2.f();
518
648
  return _context7.finish(22);
519
649
  case 25:
520
650
  return _context7.abrupt("return", null);
@@ -603,7 +733,7 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
603
733
  }
604
734
  }, _callee8, this);
605
735
  }));
606
- function resolveValueFromImport(_x9, _x10, _x11, _x12) {
736
+ function resolveValueFromImport(_x9, _x0, _x1, _x10) {
607
737
  return _resolveValueFromImport.apply(this, arguments);
608
738
  }
609
739
  return resolveValueFromImport;
@@ -88,12 +88,18 @@ const runTransform = async (filePaths, transform, flags) => {
88
88
  }
89
89
  logger.log(chalk.green(`Transforming files matching these extensions '${chalk.bold(flags.extensions)}'...`));
90
90
  const transformPath = getTransformPath(transform);
91
+
92
+ // Split the ignorePattern by '|' and add each as a separate --ignore-pattern
93
+ const ignorePatterns = flags.ignorePattern.split('|').filter(Boolean);
94
+ const ignoreArgs = ignorePatterns.map(pattern => `--ignore-pattern=${pattern}`);
91
95
  const args = Object.keys(flags).reduce((acc, key) => {
92
96
  if (!['transform', 'parser', 'extensions', 'ignorePattern', 'logger', 'packages', 'sinceRef', 'preset', 'failOnError'].includes(key)) {
93
97
  acc.unshift(`--${key}=${flags[key]}`);
94
98
  }
95
99
  return acc;
96
- }, [`--transform=${transformPath}`, `--ignore-pattern=${flags.ignorePattern}`, `--parser=${flags.parser}`, `--extensions=${flags.extensions}`,
100
+ }, [`--transform=${transformPath}`, ...ignoreArgs,
101
+ // Spread the ignoreArgs array here
102
+ `--parser=${flags.parser}`, `--extensions=${flags.extensions}`,
97
103
  // Limit CPUs to 8 to prevent issues when running on CI with a large amount of cpus
98
104
  '--cpus=8', ...codemodDirs]);
99
105
  if (flags.failOnError) {