@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.28.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#135751](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/135751)
8
+ [`320e4346043c0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/320e4346043c0) -
9
+ Allows specifying multiple ignore patterns using | symbol. Fixes minor issues in
10
+ remove-token-fallbacks preset
11
+
3
12
  ## 0.27.4
4
13
 
5
14
  ### Patch Changes
package/dist/cjs/main.js CHANGED
@@ -135,7 +135,7 @@ var resolveTransform = /*#__PURE__*/function () {
135
135
  }();
136
136
  var runTransform = /*#__PURE__*/function () {
137
137
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(filePaths, transform, flags) {
138
- var logger, codemodDirs, transformPath, args, jscodeshiftContent, jscodeshiftContentNew, transformModule;
138
+ var logger, codemodDirs, transformPath, ignorePatterns, ignoreArgs, args, jscodeshiftContent, jscodeshiftContentNew, transformModule;
139
139
  return _regenerator.default.wrap(function _callee3$(_context3) {
140
140
  while (1) switch (_context3.prev = _context3.next) {
141
141
  case 0:
@@ -160,15 +160,20 @@ var runTransform = /*#__PURE__*/function () {
160
160
  }
161
161
  case 9:
162
162
  logger.log(_chalk.default.green("Transforming files matching these extensions '".concat(_chalk.default.bold(flags.extensions), "'...")));
163
- transformPath = (0, _transforms.getTransformPath)(transform);
163
+ transformPath = (0, _transforms.getTransformPath)(transform); // Split the ignorePattern by '|' and add each as a separate --ignore-pattern
164
+ ignorePatterns = flags.ignorePattern.split('|').filter(Boolean);
165
+ ignoreArgs = ignorePatterns.map(function (pattern) {
166
+ return "--ignore-pattern=".concat(pattern);
167
+ });
164
168
  args = Object.keys(flags).reduce(function (acc, key) {
165
169
  if (!['transform', 'parser', 'extensions', 'ignorePattern', 'logger', 'packages', 'sinceRef', 'preset', 'failOnError'].includes(key)) {
166
170
  acc.unshift("--".concat(key, "=").concat(flags[key]));
167
171
  }
168
172
  return acc;
169
- }, ["--transform=".concat(transformPath), "--ignore-pattern=".concat(flags.ignorePattern), "--parser=".concat(flags.parser), "--extensions=".concat(flags.extensions),
173
+ }, ["--transform=".concat(transformPath)].concat((0, _toConsumableArray2.default)(ignoreArgs), [// Spread the ignoreArgs array here
174
+ "--parser=".concat(flags.parser), "--extensions=".concat(flags.extensions),
170
175
  // Limit CPUs to 8 to prevent issues when running on CI with a large amount of cpus
171
- '--cpus=8'].concat((0, _toConsumableArray2.default)(codemodDirs)));
176
+ '--cpus=8'], (0, _toConsumableArray2.default)(codemodDirs)));
172
177
  if (flags.failOnError) {
173
178
  args.unshift('--fail-on-error');
174
179
  }
@@ -186,24 +191,24 @@ var runTransform = /*#__PURE__*/function () {
186
191
  console.warn("Error loading transform module: ".concat(transformPath, ". Skipping lifecycle hooks."));
187
192
  }
188
193
  if (!transformModule) {
189
- _context3.next = 20;
194
+ _context3.next = 22;
190
195
  break;
191
196
  }
192
- _context3.next = 20;
193
- return processLifecycleHook('beforeAll', transformModule, logger, transform, flags);
194
- case 20:
195
197
  _context3.next = 22;
198
+ return processLifecycleHook('beforeAll', transformModule, logger, transform, flags);
199
+ case 22:
200
+ _context3.next = 24;
196
201
  return (0, _projectorSpawn.default)(jscodeshift, args, {
197
202
  stdio: 'inherit'
198
203
  });
199
- case 22:
204
+ case 24:
200
205
  if (!transformModule) {
201
- _context3.next = 25;
206
+ _context3.next = 27;
202
207
  break;
203
208
  }
204
- _context3.next = 25;
209
+ _context3.next = 27;
205
210
  return processLifecycleHook('afterAll', transformModule, logger, transform, flags);
206
- case 25:
211
+ case 27:
207
212
  case "end":
208
213
  return _context3.stop();
209
214
  }
@@ -357,7 +362,7 @@ function _main() {
357
362
  case 4:
358
363
  _yield$parseArgs = _context6.sent;
359
364
  packages = _yield$parseArgs.packages;
360
- _process$env$_PACKAGE = "0.27.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
365
+ _process$env$_PACKAGE = "0.28.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
361
366
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
362
367
  if (packages && packages.length > 0) {
363
368
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -9,6 +9,7 @@ exports.beforeAll = beforeAll;
9
9
  exports.default = transformer;
10
10
  exports.parser = void 0;
11
11
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
13
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
15
  var _child_process = require("child_process");
@@ -19,13 +20,15 @@ var _utils = require("@hypermod/utils");
19
20
  var _findRoot = require("@manypkg/find-root");
20
21
  var _chalk = _interopRequireDefault(require("chalk"));
21
22
  var _allTokens = require("./utils/all-tokens");
23
+ var _chunk = require("./utils/chunk");
22
24
  var _getTeamInfo = require("./utils/get-team-info");
23
25
  var _removeUnusedImports = require("./utils/remove-unused-imports");
24
26
  var _removeUnusedVariables = require("./utils/remove-unused-variables");
25
27
  var _reporter = require("./utils/reporter");
26
28
  var _tokenProcessor = require("./utils/token-processor");
27
- /* eslint-disable no-console */
28
-
29
+ 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; } } }; }
30
+ 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; } }
31
+ 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; } /* eslint-disable no-console */
29
32
  var execAsync = (0, _util.promisify)(_child_process.exec);
30
33
 
31
34
  /**
@@ -92,35 +95,39 @@ function _transformer() {
92
95
  case 16:
93
96
  results = _context.sent;
94
97
  unusedVars = [];
95
- if (results.some(function (result) {
98
+ if (!options.reportFolder) {
99
+ _context.next = 21;
100
+ break;
101
+ }
102
+ _context.next = 21;
103
+ return (0, _reporter.writeReports)(details, options.reportFolder);
104
+ case 21:
105
+ if (!results.some(function (result) {
96
106
  return result.fallbackRemoved;
97
107
  })) {
98
- allImports = results.flatMap(function (result) {
99
- var _result$resolvedImpor;
100
- return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
101
- });
102
- allVars = results.flatMap(function (result) {
103
- var _result$resolvedLocal;
104
- return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
105
- });
106
- unusedVars.push.apply(unusedVars, (0, _toConsumableArray2.default)(allVars));
107
- if (allImports.length) {
108
- if (options.verbose) {
109
- console.log(_chalk.default.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
110
- }
111
- (0, _removeUnusedImports.removeUnusedImports)(allImports, j);
108
+ _context.next = 35;
109
+ break;
110
+ }
111
+ allImports = results.flatMap(function (result) {
112
+ var _result$resolvedImpor;
113
+ return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
114
+ });
115
+ allVars = results.flatMap(function (result) {
116
+ var _result$resolvedLocal;
117
+ return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
118
+ });
119
+ unusedVars.push.apply(unusedVars, (0, _toConsumableArray2.default)(allVars));
120
+ if (allImports.length) {
121
+ if (options.verbose) {
122
+ console.log(_chalk.default.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
112
123
  }
124
+ (0, _removeUnusedImports.removeUnusedImports)(allImports, j);
113
125
  }
114
- (0, _removeUnusedVariables.removeUnusedVariables)(unusedVars, j);
115
- if (!options.reportFolder) {
116
- _context.next = 23;
117
- break;
126
+ if (unusedVars.length) {
127
+ (0, _removeUnusedVariables.removeUnusedVariables)(unusedVars, j);
118
128
  }
119
- _context.next = 23;
120
- return (0, _reporter.writeReports)(details, options.reportFolder);
121
- case 23:
122
129
  if (!options.dry) {
123
- _context.next = 28;
130
+ _context.next = 32;
124
131
  break;
125
132
  }
126
133
  if (options.verbose) {
@@ -128,9 +135,14 @@ function _transformer() {
128
135
  }
129
136
  // Return the unmodified source if dryRun is true
130
137
  return _context.abrupt("return", fileInfo.source);
131
- case 28:
138
+ case 32:
132
139
  return _context.abrupt("return", source.toSource());
133
- case 29:
140
+ case 33:
141
+ _context.next = 36;
142
+ break;
143
+ case 35:
144
+ return _context.abrupt("return", fileInfo.source);
145
+ case 36:
134
146
  case "end":
135
147
  return _context.stop();
136
148
  }
@@ -148,7 +160,7 @@ function beforeAll(_x4) {
148
160
  }
149
161
  /**
150
162
  * Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
151
- * It also applies prettier to the affected files.
163
+ * It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
152
164
  */
153
165
  function _beforeAll() {
154
166
  _beforeAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
@@ -174,7 +186,7 @@ function afterAll(_x5) {
174
186
  }
175
187
  function _afterAll() {
176
188
  _afterAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(options) {
177
- var filesTxtPath, fileContent;
189
+ var filesTxtPath, fileContent, filePaths, firstFilePath, rootDir;
178
190
  return _regenerator.default.wrap(function _callee3$(_context3) {
179
191
  while (1) switch (_context3.prev = _context3.next) {
180
192
  case 0:
@@ -186,7 +198,7 @@ function _afterAll() {
186
198
  return (0, _reporter.combineReports)(options.reportFolder);
187
199
  case 3:
188
200
  if (!(options.reportFolder && !options.dry)) {
189
- _context3.next = 19;
201
+ _context3.next = 27;
190
202
  break;
191
203
  }
192
204
  _context3.prev = 4;
@@ -196,30 +208,269 @@ function _afterAll() {
196
208
  case 8:
197
209
  fileContent = _context3.sent;
198
210
  if (!(fileContent.length > 0)) {
199
- _context3.next = 14;
211
+ _context3.next = 22;
200
212
  break;
201
213
  }
202
- console.log("Running prettier on files: ".concat(_chalk.default.magenta(fileContent)));
203
- _context3.next = 13;
204
- return execAsync("yarn prettier --write ".concat(fileContent));
205
- case 13:
206
- console.log(_chalk.default.green("Prettier was run successfully"));
214
+ filePaths = fileContent.split(/\r?\n/).filter(Boolean); // Get the first file path and strip any quotes
215
+ firstFilePath = filePaths[0].replace(/^['"]|['"]$/g, ''); // Determine the root directory using findRoot
216
+ _context3.next = 14;
217
+ return (0, _findRoot.findRoot)(_path.default.dirname(firstFilePath));
207
218
  case 14:
208
- _context3.next = 19;
219
+ rootDir = _context3.sent;
220
+ console.log('Root directory:', rootDir);
221
+ _context3.next = 18;
222
+ return gitStage(filePaths, rootDir);
223
+ case 18:
224
+ _context3.next = 20;
225
+ return runEslint(filePaths, rootDir);
226
+ case 20:
227
+ _context3.next = 22;
228
+ return runPrettier(filePaths, rootDir);
229
+ case 22:
230
+ _context3.next = 27;
209
231
  break;
210
- case 16:
211
- _context3.prev = 16;
232
+ case 24:
233
+ _context3.prev = 24;
212
234
  _context3.t0 = _context3["catch"](4);
213
235
  if (_context3.t0 instanceof Error) {
214
- console.error(_chalk.default.red("Unexpected error running Prettier: ".concat(_context3.t0.message)));
236
+ console.error(_chalk.default.red("Unexpected error: ".concat(_context3.t0.message)));
215
237
  } else {
216
- console.error(_chalk.default.red('An unknown error occurred while running Prettier.'));
238
+ console.error(_chalk.default.red('An unknown error occurred.'));
217
239
  }
218
- case 19:
240
+ case 27:
219
241
  case "end":
220
242
  return _context3.stop();
221
243
  }
222
- }, _callee3, null, [[4, 16]]);
244
+ }, _callee3, null, [[4, 24]]);
223
245
  }));
224
246
  return _afterAll.apply(this, arguments);
247
+ }
248
+ function gitStage(_x6, _x7) {
249
+ return _gitStage.apply(this, arguments);
250
+ }
251
+ function _gitStage() {
252
+ _gitStage = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(filePaths, cwd) {
253
+ var gitAddCommand, _yield$execAsync, gitAddStdout, gitAddStderr;
254
+ return _regenerator.default.wrap(function _callee4$(_context4) {
255
+ while (1) switch (_context4.prev = _context4.next) {
256
+ case 0:
257
+ gitAddCommand = "git add ".concat(filePaths.join(' '));
258
+ console.log("Executing command: ".concat(gitAddCommand));
259
+ _context4.next = 4;
260
+ return execAsync(gitAddCommand, {
261
+ cwd: cwd
262
+ });
263
+ case 4:
264
+ _yield$execAsync = _context4.sent;
265
+ gitAddStdout = _yield$execAsync.stdout;
266
+ gitAddStderr = _yield$execAsync.stderr;
267
+ if (gitAddStdout) {
268
+ console.log(_chalk.default.blue("Git add output:\n".concat(gitAddStdout)));
269
+ }
270
+ if (gitAddStderr) {
271
+ console.error(_chalk.default.yellow("Git add errors:\n".concat(gitAddStderr)));
272
+ }
273
+ console.log(_chalk.default.green("All changes have been staged."));
274
+ case 10:
275
+ case "end":
276
+ return _context4.stop();
277
+ }
278
+ }, _callee4);
279
+ }));
280
+ return _gitStage.apply(this, arguments);
281
+ }
282
+ function runPrettier(_x8, _x9) {
283
+ return _runPrettier.apply(this, arguments);
284
+ }
285
+ function _runPrettier() {
286
+ _runPrettier = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(filePaths, cwd) {
287
+ var prettierCommand, _yield$execAsync2, prettierStdout, prettierStderr;
288
+ return _regenerator.default.wrap(function _callee5$(_context5) {
289
+ while (1) switch (_context5.prev = _context5.next) {
290
+ case 0:
291
+ prettierCommand = "yarn prettier --write ".concat(filePaths.join(' '));
292
+ console.log("Executing command: ".concat(prettierCommand));
293
+ _context5.next = 4;
294
+ return execAsync(prettierCommand, {
295
+ cwd: cwd
296
+ });
297
+ case 4:
298
+ _yield$execAsync2 = _context5.sent;
299
+ prettierStdout = _yield$execAsync2.stdout;
300
+ prettierStderr = _yield$execAsync2.stderr;
301
+ if (prettierStdout) {
302
+ console.log(_chalk.default.blue("Prettier output:\n".concat(prettierStdout)));
303
+ }
304
+ if (prettierStderr) {
305
+ console.error(_chalk.default.yellow("Prettier errors:\n".concat(prettierStderr)));
306
+ }
307
+ console.log(_chalk.default.green("Prettier was run successfully"));
308
+ case 10:
309
+ case "end":
310
+ return _context5.stop();
311
+ }
312
+ }, _callee5);
313
+ }));
314
+ return _runPrettier.apply(this, arguments);
315
+ }
316
+ function runEslint(_x10, _x11) {
317
+ return _runEslint.apply(this, arguments);
318
+ }
319
+ function _runEslint() {
320
+ _runEslint = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(filePaths, cwd) {
321
+ var fileChunks, totalChunks, _iterator, _step, _loop;
322
+ return _regenerator.default.wrap(function _callee7$(_context9) {
323
+ while (1) switch (_context9.prev = _context9.next) {
324
+ case 0:
325
+ fileChunks = (0, _chunk.chunkArray)(filePaths, 20);
326
+ totalChunks = fileChunks.length;
327
+ _iterator = _createForOfIteratorHelper(fileChunks.entries());
328
+ _context9.prev = 3;
329
+ _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
330
+ var _step$value, chunkIndex, fileChunk, eslintCommand, result, stdout, stderr, smallerChunks, totalSmallerChunks, _iterator2, _step2, _loop2;
331
+ return _regenerator.default.wrap(function _loop$(_context8) {
332
+ while (1) switch (_context8.prev = _context8.next) {
333
+ case 0:
334
+ _step$value = (0, _slicedToArray2.default)(_step.value, 2), chunkIndex = _step$value[0], fileChunk = _step$value[1];
335
+ eslintCommand = "yarn eslint ".concat(fileChunk.join(' '), " --report-unused-disable-directives --fix");
336
+ console.log("Executing command for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(eslintCommand));
337
+ _context8.prev = 3;
338
+ _context8.next = 6;
339
+ return execAsync(eslintCommand, {
340
+ cwd: cwd
341
+ });
342
+ case 6:
343
+ result = _context8.sent;
344
+ stdout = result.stdout, stderr = result.stderr;
345
+ if (stdout) {
346
+ console.log(_chalk.default.blue("ESLint output for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stdout)));
347
+ }
348
+ if (stderr) {
349
+ console.error(_chalk.default.yellow("ESLint errors for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stderr)));
350
+ }
351
+ _context8.next = 34;
352
+ break;
353
+ case 12:
354
+ _context8.prev = 12;
355
+ _context8.t0 = _context8["catch"](3);
356
+ console.error(_chalk.default.red("Error running ESLint on chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(_context8.t0)));
357
+
358
+ // Retry each file individually
359
+ console.log(_chalk.default.yellow("Retrying each file in chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, " individually...")));
360
+
361
+ // Chunk the files into smaller groups of 5 for parallel retry
362
+ smallerChunks = (0, _chunk.chunkArray)(fileChunk, 5);
363
+ totalSmallerChunks = smallerChunks.length;
364
+ _iterator2 = _createForOfIteratorHelper(smallerChunks.entries());
365
+ _context8.prev = 19;
366
+ _loop2 = /*#__PURE__*/_regenerator.default.mark(function _loop2() {
367
+ var _step2$value, smallChunkIndex, smallerChunk;
368
+ return _regenerator.default.wrap(function _loop2$(_context7) {
369
+ while (1) switch (_context7.prev = _context7.next) {
370
+ case 0:
371
+ _step2$value = (0, _slicedToArray2.default)(_step2.value, 2), smallChunkIndex = _step2$value[0], smallerChunk = _step2$value[1];
372
+ _context7.next = 3;
373
+ return Promise.all(smallerChunk.map( /*#__PURE__*/function () {
374
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(file) {
375
+ var individualEslintCommand, _result, _stdout, _stderr;
376
+ return _regenerator.default.wrap(function _callee6$(_context6) {
377
+ while (1) switch (_context6.prev = _context6.next) {
378
+ case 0:
379
+ _context6.prev = 0;
380
+ individualEslintCommand = "yarn eslint ".concat(file, " --report-unused-disable-directives --fix");
381
+ console.log("Executing command for file in small chunk ".concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(individualEslintCommand));
382
+ _context6.next = 5;
383
+ return execAsync(individualEslintCommand, {
384
+ cwd: cwd
385
+ });
386
+ case 5:
387
+ _result = _context6.sent;
388
+ _stdout = _result.stdout, _stderr = _result.stderr;
389
+ if (_stdout) {
390
+ console.log(_chalk.default.blue("ESLint output for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stdout)));
391
+ }
392
+ if (_stderr) {
393
+ console.error(_chalk.default.yellow("ESLint errors for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stderr)));
394
+ }
395
+ _context6.next = 14;
396
+ break;
397
+ case 11:
398
+ _context6.prev = 11;
399
+ _context6.t0 = _context6["catch"](0);
400
+ console.error(_chalk.default.red("Error running ESLint on file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(_context6.t0)));
401
+ case 14:
402
+ case "end":
403
+ return _context6.stop();
404
+ }
405
+ }, _callee6, null, [[0, 11]]);
406
+ }));
407
+ return function (_x12) {
408
+ return _ref2.apply(this, arguments);
409
+ };
410
+ }()));
411
+ case 3:
412
+ case "end":
413
+ return _context7.stop();
414
+ }
415
+ }, _loop2);
416
+ });
417
+ _iterator2.s();
418
+ case 22:
419
+ if ((_step2 = _iterator2.n()).done) {
420
+ _context8.next = 26;
421
+ break;
422
+ }
423
+ return _context8.delegateYield(_loop2(), "t1", 24);
424
+ case 24:
425
+ _context8.next = 22;
426
+ break;
427
+ case 26:
428
+ _context8.next = 31;
429
+ break;
430
+ case 28:
431
+ _context8.prev = 28;
432
+ _context8.t2 = _context8["catch"](19);
433
+ _iterator2.e(_context8.t2);
434
+ case 31:
435
+ _context8.prev = 31;
436
+ _iterator2.f();
437
+ return _context8.finish(31);
438
+ case 34:
439
+ console.log(_chalk.default.green("Finished running ESLint for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ".")));
440
+ case 35:
441
+ case "end":
442
+ return _context8.stop();
443
+ }
444
+ }, _loop, null, [[3, 12], [19, 28, 31, 34]]);
445
+ });
446
+ _iterator.s();
447
+ case 6:
448
+ if ((_step = _iterator.n()).done) {
449
+ _context9.next = 10;
450
+ break;
451
+ }
452
+ return _context9.delegateYield(_loop(), "t0", 8);
453
+ case 8:
454
+ _context9.next = 6;
455
+ break;
456
+ case 10:
457
+ _context9.next = 15;
458
+ break;
459
+ case 12:
460
+ _context9.prev = 12;
461
+ _context9.t1 = _context9["catch"](3);
462
+ _iterator.e(_context9.t1);
463
+ case 15:
464
+ _context9.prev = 15;
465
+ _iterator.f();
466
+ return _context9.finish(15);
467
+ case 18:
468
+ console.log(_chalk.default.green("ESLint was run on all files successfully"));
469
+ case 19:
470
+ case "end":
471
+ return _context9.stop();
472
+ }
473
+ }, _callee7, null, [[3, 12, 15, 18]]);
474
+ }));
475
+ return _runEslint.apply(this, arguments);
225
476
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.chunkArray = void 0;
7
+ // Utility function to split an array into chunks
8
+ var chunkArray = exports.chunkArray = function chunkArray(array, chunkSize) {
9
+ var result = [];
10
+ for (var i = 0; i < array.length; i += chunkSize) {
11
+ result.push(array.slice(i, i + chunkSize));
12
+ }
13
+ return result;
14
+ };
@@ -9,9 +9,10 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
9
9
  var _chalk = _interopRequireDefault(require("chalk"));
10
10
  var _colorUtils = require("./color-utils");
11
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;
12
+ var ACCEPTABLE_COLOR_DIFFERENCE = 15;
13
13
  var ACCEPTABLE_SPACE_DIFFERENCE = 0;
14
14
  var ACCEPTABLE_NUMERIC_DIFFERENCE = 0;
15
+ var ACCEPTABLE_BORDER_DIFFERENCE = 0;
15
16
  function normalizeValues(tokenKey, tokenValue, fallbackValue) {
16
17
  var tokenLogValue;
17
18
  var fallbackLogValue;
@@ -35,13 +36,13 @@ function normalizeValues(tokenKey, tokenValue, fallbackValue) {
35
36
  difference = (0, _colorUtils.compareHex)(normalizedTokenValue, normalizedFallbackValue);
36
37
  isAcceptableDifference = difference <= ACCEPTABLE_COLOR_DIFFERENCE;
37
38
  }
38
- } else if (lowerCaseTokenKey.startsWith('space')) {
39
+ } else if (lowerCaseTokenKey.startsWith('space') || lowerCaseTokenKey.startsWith('border')) {
39
40
  var tokenValueInPx = tokenValue ? convertToPx(tokenValue) : undefined;
40
41
  var fallbackValueInPx = fallbackValue ? convertToPx(fallbackValue) : undefined;
41
42
  if (tokenValueInPx !== undefined && fallbackValueInPx !== undefined) {
42
43
  var maxVal = Math.max(tokenValueInPx, fallbackValueInPx);
43
44
  difference = Math.abs(tokenValueInPx - fallbackValueInPx) / maxVal * 100;
44
- isAcceptableDifference = difference <= ACCEPTABLE_SPACE_DIFFERENCE;
45
+ isAcceptableDifference = difference <= (lowerCaseTokenKey.startsWith('space') ? ACCEPTABLE_SPACE_DIFFERENCE : ACCEPTABLE_BORDER_DIFFERENCE);
45
46
  }
46
47
  // Log the normalized values
47
48
  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
  }