@atlaskit/codemod-cli 0.27.4 → 0.28.0

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 (27) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/main.js +18 -13
  3. package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +294 -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 +4 -3
  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 +154 -46
  9. package/dist/es2019/main.js +7 -1
  10. package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +122 -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 +4 -3
  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 +85 -9
  16. package/dist/esm/main.js +18 -13
  17. package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +294 -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 +4 -3
  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 +154 -46
  23. package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +1 -1
  24. package/dist/types/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
  25. package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +1 -1
  26. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
  27. package/package.json +3 -3
@@ -67,7 +67,10 @@ export class TokenProcessor {
67
67
  resolvedLocalVarDeclaration: undefined
68
68
  };
69
69
  }
70
- const isSkipped = tokenKey.startsWith('elevation.shadow') || tokenKey.startsWith('font.body') || tokenKey.startsWith('font.heading');
70
+ const isSkipped = false;
71
+ // tokenKey.startsWith('elevation.shadow') ||
72
+ // tokenKey.startsWith('font.body') ||
73
+ // tokenKey.startsWith('font.heading');
71
74
  const tokenValue = isSkipped ? '' : this.tokenMap[tokenKey];
72
75
  this.logVerbose(`Token value from tokenMap: ${chalk.magenta(tokenValue)} for key: ${chalk.yellow(tokenKey)}`);
73
76
  const {
@@ -103,7 +106,8 @@ export class TokenProcessor {
103
106
  let fallbackRemoved = false;
104
107
  let importDeclaration;
105
108
  let localVarDeclaration;
106
- if (areEqual || isAcceptableDifference || this.options.forceUpdate) {
109
+ const isBorderToken = tokenKey.startsWith('border');
110
+ if (areEqual || (isAcceptableDifference || this.options.forceUpdate) && !isBorderToken) {
107
111
  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'));
108
112
  args.pop();
109
113
  this.details.replaced.push(logData);
@@ -111,7 +115,7 @@ export class TokenProcessor {
111
115
  importDeclaration = resolvedImportDeclaration;
112
116
  localVarDeclaration = resolvedLocalVarDeclaration;
113
117
  } else {
114
- const message = normalizedFallbackValue === undefined ? `Fallback value could not be resolved` : `Values mismatched significantly`;
118
+ const message = isBorderToken ? 'Skip modifying border token' : normalizedFallbackValue === undefined ? `Fallback value could not be resolved` : `Values mismatched significantly`;
115
119
  this.logError(message);
116
120
  if (this.options.addEslintComments) {
117
121
  addOrUpdateEslintIgnoreComment(this.j, tokenValue, fallbackValue, callPath);
@@ -211,6 +215,56 @@ export class TokenProcessor {
211
215
  let objectName;
212
216
  let propertyName;
213
217
  let fallbackValue;
218
+ let resolvedImportDeclaration;
219
+ let resolvedLocalVarDeclaration;
220
+
221
+ // Function to get full member expression path as string
222
+ const getFullMemberPath = node => {
223
+ if (node.type === 'Identifier') {
224
+ return node.name;
225
+ } else if (node.type === 'MemberExpression') {
226
+ return `${getFullMemberPath(node.object)}.${node.property.type === 'Identifier' ? node.property.name : ''}`;
227
+ }
228
+ return '';
229
+ };
230
+ const fullMemberPath = getFullMemberPath(fallbackValueNode);
231
+
232
+ // Detect long member expression paths
233
+ const pathSegments = fullMemberPath.split('.');
234
+ if (pathSegments.length > 2) {
235
+ this.logVerbose(`Detected long member expression: ${chalk.yellow(fullMemberPath)}. Just resolving import or local variable declaration.`);
236
+
237
+ // Find the import statement or local variable for the top-level object
238
+ objectName = pathSegments[0];
239
+
240
+ // Check if it's a local variable
241
+ const localVarDeclaration = this.source.find(this.j.VariableDeclarator, {
242
+ id: {
243
+ name: objectName
244
+ }
245
+ }).at(0);
246
+ if (localVarDeclaration.size()) {
247
+ resolvedLocalVarDeclaration = localVarDeclaration.paths()[0];
248
+ this.logVerbose(`Resolved local variable declaration for: ${chalk.yellow(objectName)}`);
249
+ } else {
250
+ // Search for import declaration
251
+ const importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
252
+ if (importDeclaration.size()) {
253
+ resolvedImportDeclaration = importDeclaration.paths()[0];
254
+ this.logVerbose(`Resolved import declaration for: ${chalk.yellow(objectName)}`);
255
+ } else {
256
+ this.logError(`Could not resolve import or local variable for: ${chalk.yellow(objectName)}`);
257
+ }
258
+ }
259
+ return {
260
+ rawFallbackValue: fullMemberPath,
261
+ fallbackValue: undefined,
262
+ resolvedImportDeclaration,
263
+ resolvedLocalVarDeclaration
264
+ };
265
+ }
266
+
267
+ // Existing logic for member expressions with shorter paths
214
268
  if (fallbackValueNode.object.type === 'Identifier') {
215
269
  objectName = fallbackValueNode.object.name;
216
270
  }
@@ -230,7 +284,6 @@ export class TokenProcessor {
230
284
  }
231
285
  const rawFallbackValue = `${objectName}.${propertyName}`;
232
286
  this.logVerbose(`Fallback is a member expression: ${chalk.yellow(rawFallbackValue)}, attempting to resolve...`);
233
- let resolvedImportDeclaration;
234
287
 
235
288
  // Find the import statement for the object
236
289
  const importDeclaration = this.source.find(this.j.ImportDeclaration).filter(this.createImportFilter(objectName)).at(0);
@@ -253,22 +306,45 @@ export class TokenProcessor {
253
306
  }
254
307
  async processFallbackAsTemplateLiteral(fallbackValueNode) {
255
308
  const expressions = fallbackValueNode.expressions;
309
+ const quasis = fallbackValueNode.quasis;
310
+ let resolvedImportDeclaration;
311
+ let resolvedLocalVarDeclaration;
256
312
  let rawFallbackValue = '';
257
313
  let fallbackValue;
258
- const quasis = fallbackValueNode.quasis;
259
314
  if (expressions.length !== 1 || quasis.length !== 2) {
260
315
  this.logError(`Unsupported template literal structure`);
316
+
317
+ // Attempt to resolve any imports or local variables used in expressions
318
+ for (const expression of expressions) {
319
+ if (expression.type === 'Identifier') {
320
+ const result = await this.processFallbackAsIdentifier(expression);
321
+ if (result.resolvedImportDeclaration) {
322
+ resolvedImportDeclaration = result.resolvedImportDeclaration;
323
+ }
324
+ if (result.resolvedLocalVarDeclaration) {
325
+ resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
326
+ }
327
+ } else if (expression.type === 'MemberExpression') {
328
+ const result = await this.processFallbackAsMemberExpression(expression);
329
+ if (result.resolvedImportDeclaration) {
330
+ resolvedImportDeclaration = result.resolvedImportDeclaration;
331
+ }
332
+ if (result.resolvedLocalVarDeclaration) {
333
+ resolvedLocalVarDeclaration = result.resolvedLocalVarDeclaration;
334
+ }
335
+ }
336
+ }
261
337
  return {
262
338
  rawFallbackValue,
263
339
  fallbackValue,
264
- resolvedImportDeclaration: undefined,
265
- resolvedLocalVarDeclaration: undefined
340
+ resolvedImportDeclaration,
341
+ resolvedLocalVarDeclaration
266
342
  };
267
343
  }
344
+
345
+ // Handle supported template literal structures as before
268
346
  let exprValue;
269
347
  const expression = expressions[0];
270
- let resolvedImportDeclaration;
271
- let resolvedLocalVarDeclaration;
272
348
  if (expression.type === 'Identifier') {
273
349
  const result = await this.processFallbackAsIdentifier(expression);
274
350
  exprValue = result.fallbackValue;
package/dist/esm/main.js CHANGED
@@ -128,7 +128,7 @@ var resolveTransform = /*#__PURE__*/function () {
128
128
  }();
129
129
  var runTransform = /*#__PURE__*/function () {
130
130
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filePaths, transform, flags) {
131
- var logger, codemodDirs, transformPath, args, jscodeshiftContent, jscodeshiftContentNew, transformModule;
131
+ var logger, codemodDirs, transformPath, ignorePatterns, ignoreArgs, args, jscodeshiftContent, jscodeshiftContentNew, transformModule;
132
132
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
133
133
  while (1) switch (_context3.prev = _context3.next) {
134
134
  case 0:
@@ -153,15 +153,20 @@ var runTransform = /*#__PURE__*/function () {
153
153
  }
154
154
  case 9:
155
155
  logger.log(chalk.green("Transforming files matching these extensions '".concat(chalk.bold(flags.extensions), "'...")));
156
- transformPath = getTransformPath(transform);
156
+ transformPath = getTransformPath(transform); // Split the ignorePattern by '|' and add each as a separate --ignore-pattern
157
+ ignorePatterns = flags.ignorePattern.split('|').filter(Boolean);
158
+ ignoreArgs = ignorePatterns.map(function (pattern) {
159
+ return "--ignore-pattern=".concat(pattern);
160
+ });
157
161
  args = Object.keys(flags).reduce(function (acc, key) {
158
162
  if (!['transform', 'parser', 'extensions', 'ignorePattern', 'logger', 'packages', 'sinceRef', 'preset', 'failOnError'].includes(key)) {
159
163
  acc.unshift("--".concat(key, "=").concat(flags[key]));
160
164
  }
161
165
  return acc;
162
- }, ["--transform=".concat(transformPath), "--ignore-pattern=".concat(flags.ignorePattern), "--parser=".concat(flags.parser), "--extensions=".concat(flags.extensions),
166
+ }, ["--transform=".concat(transformPath)].concat(_toConsumableArray(ignoreArgs), [// Spread the ignoreArgs array here
167
+ "--parser=".concat(flags.parser), "--extensions=".concat(flags.extensions),
163
168
  // Limit CPUs to 8 to prevent issues when running on CI with a large amount of cpus
164
- '--cpus=8'].concat(_toConsumableArray(codemodDirs)));
169
+ '--cpus=8'], _toConsumableArray(codemodDirs)));
165
170
  if (flags.failOnError) {
166
171
  args.unshift('--fail-on-error');
167
172
  }
@@ -179,24 +184,24 @@ var runTransform = /*#__PURE__*/function () {
179
184
  console.warn("Error loading transform module: ".concat(transformPath, ". Skipping lifecycle hooks."));
180
185
  }
181
186
  if (!transformModule) {
182
- _context3.next = 20;
187
+ _context3.next = 22;
183
188
  break;
184
189
  }
185
- _context3.next = 20;
186
- return processLifecycleHook('beforeAll', transformModule, logger, transform, flags);
187
- case 20:
188
190
  _context3.next = 22;
191
+ return processLifecycleHook('beforeAll', transformModule, logger, transform, flags);
192
+ case 22:
193
+ _context3.next = 24;
189
194
  return spawn(jscodeshift, args, {
190
195
  stdio: 'inherit'
191
196
  });
192
- case 22:
197
+ case 24:
193
198
  if (!transformModule) {
194
- _context3.next = 25;
199
+ _context3.next = 27;
195
200
  break;
196
201
  }
197
- _context3.next = 25;
202
+ _context3.next = 27;
198
203
  return processLifecycleHook('afterAll', transformModule, logger, transform, flags);
199
- case 25:
204
+ case 27:
200
205
  case "end":
201
206
  return _context3.stop();
202
207
  }
@@ -350,7 +355,7 @@ function _main() {
350
355
  case 4:
351
356
  _yield$parseArgs = _context6.sent;
352
357
  packages = _yield$parseArgs.packages;
353
- _process$env$_PACKAGE = "0.27.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
358
+ _process$env$_PACKAGE = "0.28.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
354
359
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
355
360
  if (packages && packages.length > 0) {
356
361
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -1,5 +1,9 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
3
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
8
  /* eslint-disable no-console */
5
9
  import { exec } from 'child_process';
@@ -10,6 +14,7 @@ import { hasImportDeclaration } from '@hypermod/utils';
10
14
  import { findRoot } from '@manypkg/find-root';
11
15
  import chalk from 'chalk';
12
16
  import { getTokenMap } from './utils/all-tokens';
17
+ import { chunkArray } from './utils/chunk';
13
18
  import { getTeamInfo } from './utils/get-team-info';
14
19
  import { removeUnusedImports } from './utils/remove-unused-imports';
15
20
  import { removeUnusedVariables } from './utils/remove-unused-variables';
@@ -81,35 +86,39 @@ function _transformer() {
81
86
  case 16:
82
87
  results = _context.sent;
83
88
  unusedVars = [];
84
- if (results.some(function (result) {
89
+ if (!options.reportFolder) {
90
+ _context.next = 21;
91
+ break;
92
+ }
93
+ _context.next = 21;
94
+ return writeReports(details, options.reportFolder);
95
+ case 21:
96
+ if (!results.some(function (result) {
85
97
  return result.fallbackRemoved;
86
98
  })) {
87
- allImports = results.flatMap(function (result) {
88
- var _result$resolvedImpor;
89
- return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
90
- });
91
- allVars = results.flatMap(function (result) {
92
- var _result$resolvedLocal;
93
- return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
94
- });
95
- unusedVars.push.apply(unusedVars, _toConsumableArray(allVars));
96
- if (allImports.length) {
97
- if (options.verbose) {
98
- console.log(chalk.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
99
- }
100
- removeUnusedImports(allImports, j);
99
+ _context.next = 35;
100
+ break;
101
+ }
102
+ allImports = results.flatMap(function (result) {
103
+ var _result$resolvedImpor;
104
+ return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
105
+ });
106
+ allVars = results.flatMap(function (result) {
107
+ var _result$resolvedLocal;
108
+ return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
109
+ });
110
+ unusedVars.push.apply(unusedVars, _toConsumableArray(allVars));
111
+ if (allImports.length) {
112
+ if (options.verbose) {
113
+ console.log(chalk.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
101
114
  }
115
+ removeUnusedImports(allImports, j);
102
116
  }
103
- removeUnusedVariables(unusedVars, j);
104
- if (!options.reportFolder) {
105
- _context.next = 23;
106
- break;
117
+ if (unusedVars.length) {
118
+ removeUnusedVariables(unusedVars, j);
107
119
  }
108
- _context.next = 23;
109
- return writeReports(details, options.reportFolder);
110
- case 23:
111
120
  if (!options.dry) {
112
- _context.next = 28;
121
+ _context.next = 32;
113
122
  break;
114
123
  }
115
124
  if (options.verbose) {
@@ -117,9 +126,14 @@ function _transformer() {
117
126
  }
118
127
  // Return the unmodified source if dryRun is true
119
128
  return _context.abrupt("return", fileInfo.source);
120
- case 28:
129
+ case 32:
121
130
  return _context.abrupt("return", source.toSource());
122
- case 29:
131
+ case 33:
132
+ _context.next = 36;
133
+ break;
134
+ case 35:
135
+ return _context.abrupt("return", fileInfo.source);
136
+ case 36:
123
137
  case "end":
124
138
  return _context.stop();
125
139
  }
@@ -138,7 +152,7 @@ export function beforeAll(_x4) {
138
152
 
139
153
  /**
140
154
  * Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
141
- * It also applies prettier to the affected files.
155
+ * It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
142
156
  */
143
157
  function _beforeAll() {
144
158
  _beforeAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
@@ -164,7 +178,7 @@ export function afterAll(_x5) {
164
178
  }
165
179
  function _afterAll() {
166
180
  _afterAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
167
- var filesTxtPath, fileContent;
181
+ var filesTxtPath, fileContent, filePaths, firstFilePath, rootDir;
168
182
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
169
183
  while (1) switch (_context3.prev = _context3.next) {
170
184
  case 0:
@@ -176,7 +190,7 @@ function _afterAll() {
176
190
  return combineReports(options.reportFolder);
177
191
  case 3:
178
192
  if (!(options.reportFolder && !options.dry)) {
179
- _context3.next = 19;
193
+ _context3.next = 27;
180
194
  break;
181
195
  }
182
196
  _context3.prev = 4;
@@ -186,30 +200,269 @@ function _afterAll() {
186
200
  case 8:
187
201
  fileContent = _context3.sent;
188
202
  if (!(fileContent.length > 0)) {
189
- _context3.next = 14;
203
+ _context3.next = 22;
190
204
  break;
191
205
  }
192
- console.log("Running prettier on files: ".concat(chalk.magenta(fileContent)));
193
- _context3.next = 13;
194
- return execAsync("yarn prettier --write ".concat(fileContent));
195
- case 13:
196
- console.log(chalk.green("Prettier was run successfully"));
206
+ filePaths = fileContent.split(/\r?\n/).filter(Boolean); // Get the first file path and strip any quotes
207
+ firstFilePath = filePaths[0].replace(/^['"]|['"]$/g, ''); // Determine the root directory using findRoot
208
+ _context3.next = 14;
209
+ return findRoot(path.dirname(firstFilePath));
197
210
  case 14:
198
- _context3.next = 19;
211
+ rootDir = _context3.sent;
212
+ console.log('Root directory:', rootDir);
213
+ _context3.next = 18;
214
+ return gitStage(filePaths, rootDir);
215
+ case 18:
216
+ _context3.next = 20;
217
+ return runEslint(filePaths, rootDir);
218
+ case 20:
219
+ _context3.next = 22;
220
+ return runPrettier(filePaths, rootDir);
221
+ case 22:
222
+ _context3.next = 27;
199
223
  break;
200
- case 16:
201
- _context3.prev = 16;
224
+ case 24:
225
+ _context3.prev = 24;
202
226
  _context3.t0 = _context3["catch"](4);
203
227
  if (_context3.t0 instanceof Error) {
204
- console.error(chalk.red("Unexpected error running Prettier: ".concat(_context3.t0.message)));
228
+ console.error(chalk.red("Unexpected error: ".concat(_context3.t0.message)));
205
229
  } else {
206
- console.error(chalk.red('An unknown error occurred while running Prettier.'));
230
+ console.error(chalk.red('An unknown error occurred.'));
207
231
  }
208
- case 19:
232
+ case 27:
209
233
  case "end":
210
234
  return _context3.stop();
211
235
  }
212
- }, _callee3, null, [[4, 16]]);
236
+ }, _callee3, null, [[4, 24]]);
213
237
  }));
214
238
  return _afterAll.apply(this, arguments);
239
+ }
240
+ function gitStage(_x6, _x7) {
241
+ return _gitStage.apply(this, arguments);
242
+ }
243
+ function _gitStage() {
244
+ _gitStage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(filePaths, cwd) {
245
+ var gitAddCommand, _yield$execAsync, gitAddStdout, gitAddStderr;
246
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
247
+ while (1) switch (_context4.prev = _context4.next) {
248
+ case 0:
249
+ gitAddCommand = "git add ".concat(filePaths.join(' '));
250
+ console.log("Executing command: ".concat(gitAddCommand));
251
+ _context4.next = 4;
252
+ return execAsync(gitAddCommand, {
253
+ cwd: cwd
254
+ });
255
+ case 4:
256
+ _yield$execAsync = _context4.sent;
257
+ gitAddStdout = _yield$execAsync.stdout;
258
+ gitAddStderr = _yield$execAsync.stderr;
259
+ if (gitAddStdout) {
260
+ console.log(chalk.blue("Git add output:\n".concat(gitAddStdout)));
261
+ }
262
+ if (gitAddStderr) {
263
+ console.error(chalk.yellow("Git add errors:\n".concat(gitAddStderr)));
264
+ }
265
+ console.log(chalk.green("All changes have been staged."));
266
+ case 10:
267
+ case "end":
268
+ return _context4.stop();
269
+ }
270
+ }, _callee4);
271
+ }));
272
+ return _gitStage.apply(this, arguments);
273
+ }
274
+ function runPrettier(_x8, _x9) {
275
+ return _runPrettier.apply(this, arguments);
276
+ }
277
+ function _runPrettier() {
278
+ _runPrettier = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(filePaths, cwd) {
279
+ var prettierCommand, _yield$execAsync2, prettierStdout, prettierStderr;
280
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
281
+ while (1) switch (_context5.prev = _context5.next) {
282
+ case 0:
283
+ prettierCommand = "yarn prettier --write ".concat(filePaths.join(' '));
284
+ console.log("Executing command: ".concat(prettierCommand));
285
+ _context5.next = 4;
286
+ return execAsync(prettierCommand, {
287
+ cwd: cwd
288
+ });
289
+ case 4:
290
+ _yield$execAsync2 = _context5.sent;
291
+ prettierStdout = _yield$execAsync2.stdout;
292
+ prettierStderr = _yield$execAsync2.stderr;
293
+ if (prettierStdout) {
294
+ console.log(chalk.blue("Prettier output:\n".concat(prettierStdout)));
295
+ }
296
+ if (prettierStderr) {
297
+ console.error(chalk.yellow("Prettier errors:\n".concat(prettierStderr)));
298
+ }
299
+ console.log(chalk.green("Prettier was run successfully"));
300
+ case 10:
301
+ case "end":
302
+ return _context5.stop();
303
+ }
304
+ }, _callee5);
305
+ }));
306
+ return _runPrettier.apply(this, arguments);
307
+ }
308
+ function runEslint(_x10, _x11) {
309
+ return _runEslint.apply(this, arguments);
310
+ }
311
+ function _runEslint() {
312
+ _runEslint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(filePaths, cwd) {
313
+ var fileChunks, totalChunks, _iterator, _step, _loop;
314
+ return _regeneratorRuntime.wrap(function _callee7$(_context9) {
315
+ while (1) switch (_context9.prev = _context9.next) {
316
+ case 0:
317
+ fileChunks = chunkArray(filePaths, 20);
318
+ totalChunks = fileChunks.length;
319
+ _iterator = _createForOfIteratorHelper(fileChunks.entries());
320
+ _context9.prev = 3;
321
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
322
+ var _step$value, chunkIndex, fileChunk, eslintCommand, result, stdout, stderr, smallerChunks, totalSmallerChunks, _iterator2, _step2, _loop2;
323
+ return _regeneratorRuntime.wrap(function _loop$(_context8) {
324
+ while (1) switch (_context8.prev = _context8.next) {
325
+ case 0:
326
+ _step$value = _slicedToArray(_step.value, 2), chunkIndex = _step$value[0], fileChunk = _step$value[1];
327
+ eslintCommand = "yarn eslint ".concat(fileChunk.join(' '), " --report-unused-disable-directives --fix");
328
+ console.log("Executing command for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(eslintCommand));
329
+ _context8.prev = 3;
330
+ _context8.next = 6;
331
+ return execAsync(eslintCommand, {
332
+ cwd: cwd
333
+ });
334
+ case 6:
335
+ result = _context8.sent;
336
+ stdout = result.stdout, stderr = result.stderr;
337
+ if (stdout) {
338
+ console.log(chalk.blue("ESLint output for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stdout)));
339
+ }
340
+ if (stderr) {
341
+ console.error(chalk.yellow("ESLint errors for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stderr)));
342
+ }
343
+ _context8.next = 34;
344
+ break;
345
+ case 12:
346
+ _context8.prev = 12;
347
+ _context8.t0 = _context8["catch"](3);
348
+ console.error(chalk.red("Error running ESLint on chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(_context8.t0)));
349
+
350
+ // Retry each file individually
351
+ console.log(chalk.yellow("Retrying each file in chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, " individually...")));
352
+
353
+ // Chunk the files into smaller groups of 5 for parallel retry
354
+ smallerChunks = chunkArray(fileChunk, 5);
355
+ totalSmallerChunks = smallerChunks.length;
356
+ _iterator2 = _createForOfIteratorHelper(smallerChunks.entries());
357
+ _context8.prev = 19;
358
+ _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
359
+ var _step2$value, smallChunkIndex, smallerChunk;
360
+ return _regeneratorRuntime.wrap(function _loop2$(_context7) {
361
+ while (1) switch (_context7.prev = _context7.next) {
362
+ case 0:
363
+ _step2$value = _slicedToArray(_step2.value, 2), smallChunkIndex = _step2$value[0], smallerChunk = _step2$value[1];
364
+ _context7.next = 3;
365
+ return Promise.all(smallerChunk.map( /*#__PURE__*/function () {
366
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(file) {
367
+ var individualEslintCommand, _result, _stdout, _stderr;
368
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
369
+ while (1) switch (_context6.prev = _context6.next) {
370
+ case 0:
371
+ _context6.prev = 0;
372
+ individualEslintCommand = "yarn eslint ".concat(file, " --report-unused-disable-directives --fix");
373
+ console.log("Executing command for file in small chunk ".concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(individualEslintCommand));
374
+ _context6.next = 5;
375
+ return execAsync(individualEslintCommand, {
376
+ cwd: cwd
377
+ });
378
+ case 5:
379
+ _result = _context6.sent;
380
+ _stdout = _result.stdout, _stderr = _result.stderr;
381
+ if (_stdout) {
382
+ console.log(chalk.blue("ESLint output for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stdout)));
383
+ }
384
+ if (_stderr) {
385
+ console.error(chalk.yellow("ESLint errors for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stderr)));
386
+ }
387
+ _context6.next = 14;
388
+ break;
389
+ case 11:
390
+ _context6.prev = 11;
391
+ _context6.t0 = _context6["catch"](0);
392
+ console.error(chalk.red("Error running ESLint on file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(_context6.t0)));
393
+ case 14:
394
+ case "end":
395
+ return _context6.stop();
396
+ }
397
+ }, _callee6, null, [[0, 11]]);
398
+ }));
399
+ return function (_x12) {
400
+ return _ref2.apply(this, arguments);
401
+ };
402
+ }()));
403
+ case 3:
404
+ case "end":
405
+ return _context7.stop();
406
+ }
407
+ }, _loop2);
408
+ });
409
+ _iterator2.s();
410
+ case 22:
411
+ if ((_step2 = _iterator2.n()).done) {
412
+ _context8.next = 26;
413
+ break;
414
+ }
415
+ return _context8.delegateYield(_loop2(), "t1", 24);
416
+ case 24:
417
+ _context8.next = 22;
418
+ break;
419
+ case 26:
420
+ _context8.next = 31;
421
+ break;
422
+ case 28:
423
+ _context8.prev = 28;
424
+ _context8.t2 = _context8["catch"](19);
425
+ _iterator2.e(_context8.t2);
426
+ case 31:
427
+ _context8.prev = 31;
428
+ _iterator2.f();
429
+ return _context8.finish(31);
430
+ case 34:
431
+ console.log(chalk.green("Finished running ESLint for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ".")));
432
+ case 35:
433
+ case "end":
434
+ return _context8.stop();
435
+ }
436
+ }, _loop, null, [[3, 12], [19, 28, 31, 34]]);
437
+ });
438
+ _iterator.s();
439
+ case 6:
440
+ if ((_step = _iterator.n()).done) {
441
+ _context9.next = 10;
442
+ break;
443
+ }
444
+ return _context9.delegateYield(_loop(), "t0", 8);
445
+ case 8:
446
+ _context9.next = 6;
447
+ break;
448
+ case 10:
449
+ _context9.next = 15;
450
+ break;
451
+ case 12:
452
+ _context9.prev = 12;
453
+ _context9.t1 = _context9["catch"](3);
454
+ _iterator.e(_context9.t1);
455
+ case 15:
456
+ _context9.prev = 15;
457
+ _iterator.f();
458
+ return _context9.finish(15);
459
+ case 18:
460
+ console.log(chalk.green("ESLint was run on all files successfully"));
461
+ case 19:
462
+ case "end":
463
+ return _context9.stop();
464
+ }
465
+ }, _callee7, null, [[3, 12, 15, 18]]);
466
+ }));
467
+ return _runEslint.apply(this, arguments);
215
468
  }
@@ -0,0 +1,8 @@
1
+ // Utility function to split an array into chunks
2
+ export var chunkArray = function chunkArray(array, chunkSize) {
3
+ var result = [];
4
+ for (var i = 0; i < array.length; i += chunkSize) {
5
+ result.push(array.slice(i, i + chunkSize));
6
+ }
7
+ return result;
8
+ };
@@ -3,9 +3,10 @@ import chalk from 'chalk';
3
3
  import { colorToHex, compareHex, isValidColor } from './color-utils';
4
4
 
5
5
  // so far allowing to remove only exact matches in values. Can be increased to auto-remove fallbacks with similar values
6
- var ACCEPTABLE_COLOR_DIFFERENCE = 0;
6
+ var ACCEPTABLE_COLOR_DIFFERENCE = 15;
7
7
  var ACCEPTABLE_SPACE_DIFFERENCE = 0;
8
8
  var ACCEPTABLE_NUMERIC_DIFFERENCE = 0;
9
+ var ACCEPTABLE_BORDER_DIFFERENCE = 0;
9
10
  export function normalizeValues(tokenKey, tokenValue, fallbackValue) {
10
11
  var tokenLogValue;
11
12
  var fallbackLogValue;
@@ -29,13 +30,13 @@ export function normalizeValues(tokenKey, tokenValue, fallbackValue) {
29
30
  difference = compareHex(normalizedTokenValue, normalizedFallbackValue);
30
31
  isAcceptableDifference = difference <= ACCEPTABLE_COLOR_DIFFERENCE;
31
32
  }
32
- } else if (lowerCaseTokenKey.startsWith('space')) {
33
+ } else if (lowerCaseTokenKey.startsWith('space') || lowerCaseTokenKey.startsWith('border')) {
33
34
  var tokenValueInPx = tokenValue ? convertToPx(tokenValue) : undefined;
34
35
  var fallbackValueInPx = fallbackValue ? convertToPx(fallbackValue) : undefined;
35
36
  if (tokenValueInPx !== undefined && fallbackValueInPx !== undefined) {
36
37
  var maxVal = Math.max(tokenValueInPx, fallbackValueInPx);
37
38
  difference = Math.abs(tokenValueInPx - fallbackValueInPx) / maxVal * 100;
38
- isAcceptableDifference = difference <= ACCEPTABLE_SPACE_DIFFERENCE;
39
+ isAcceptableDifference = difference <= (lowerCaseTokenKey.startsWith('space') ? ACCEPTABLE_SPACE_DIFFERENCE : ACCEPTABLE_BORDER_DIFFERENCE);
39
40
  }
40
41
  // Log the normalized values
41
42
  normalizedTokenValue = tokenValue;