@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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/main.js +20 -15
- package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +350 -43
- package/dist/cjs/presets/remove-token-fallbacks/utils/chunk.js +14 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
- package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +2 -2
- package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +28 -21
- package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +201 -71
- package/dist/es2019/main.js +7 -1
- package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +164 -17
- package/dist/es2019/presets/remove-token-fallbacks/utils/chunk.js +8 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
- package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +3 -3
- package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +6 -1
- package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +121 -17
- package/dist/esm/main.js +20 -15
- package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +350 -41
- package/dist/esm/presets/remove-token-fallbacks/utils/chunk.js +8 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +15 -9
- package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +2 -2
- package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +28 -21
- package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +201 -71
- package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +9 -1
- package/dist/types/presets/remove-token-fallbacks/types.d.ts +8 -0
- package/dist/types/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +2 -1
- package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +6 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +9 -1
- package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +8 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/chunk.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +2 -1
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +6 -0
- package/package.json +4 -4
|
@@ -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';
|
|
@@ -30,6 +35,14 @@ var execAsync = promisify(exec);
|
|
|
30
35
|
* @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
|
|
31
36
|
* @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
|
|
32
37
|
* @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
|
|
38
|
+
* @param {string} [options.skipTokens] - A comma-separated list of token prefixes to exempt from automatic fallback removal. By default, 'border' tokens are always included in this list. Whether fallbacks for these tokens are removed when they exactly match depends on the preserveSkippedFallbacks option.
|
|
39
|
+
* @param {boolean} [options.preserveSkippedFallbacks] - If true, fallbacks for skipped tokens will never be removed, even if they exactly match the token value. If false (default), fallbacks for skipped tokens will be removed if they exactly match.
|
|
40
|
+
* @param {boolean} [options.skipEslint] - If true, skips running ESLint on modified files after transformation.
|
|
41
|
+
* @param {boolean} [options.skipPrettier] - If true, skips running Prettier on modified files after transformation.
|
|
42
|
+
* @param {number} [options.colorDifferenceThreshold] - The maximum allowed difference for color tokens to be considered acceptable for removal. Default is 15.
|
|
43
|
+
* @param {number} [options.spaceDifferenceThreshold] - The maximum allowed percentage difference for space tokens to be considered acceptable for removal. Default is 0.
|
|
44
|
+
* @param {number} [options.numericDifferenceThreshold] - The maximum allowed percentage difference for numeric tokens to be considered acceptable for removal. Default is 0.
|
|
45
|
+
* @param {number} [options.borderDifferenceThreshold] - The maximum allowed percentage difference for border tokens to be considered acceptable for removal. Default is 0.
|
|
33
46
|
*
|
|
34
47
|
* @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
|
|
35
48
|
*/
|
|
@@ -61,6 +74,32 @@ function _transformer() {
|
|
|
61
74
|
};
|
|
62
75
|
if (options.verbose) {
|
|
63
76
|
console.log(chalk.yellow("Using ".concat(options.useLegacyColorTheme ? 'legacy light' : 'light', " theme.")));
|
|
77
|
+
if (options.skipTokens) {
|
|
78
|
+
console.log(chalk.yellow("Auto fallback exemptions active for: ".concat(options.skipTokens)));
|
|
79
|
+
}
|
|
80
|
+
if (options.preserveSkippedFallbacks) {
|
|
81
|
+
console.log(chalk.yellow("Preserving all fallbacks for skipped tokens, even if they match exactly."));
|
|
82
|
+
}
|
|
83
|
+
if (options.skipEslint) {
|
|
84
|
+
console.log(chalk.yellow("Skipping ESLint post-processing."));
|
|
85
|
+
}
|
|
86
|
+
if (options.skipPrettier) {
|
|
87
|
+
console.log(chalk.yellow("Skipping Prettier post-processing."));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Log threshold values if they are set
|
|
91
|
+
if (options.colorDifferenceThreshold !== undefined) {
|
|
92
|
+
console.log(chalk.yellow("Color difference threshold set to: ".concat(options.colorDifferenceThreshold)));
|
|
93
|
+
}
|
|
94
|
+
if (options.spaceDifferenceThreshold !== undefined) {
|
|
95
|
+
console.log(chalk.yellow("Space difference threshold set to: ".concat(options.spaceDifferenceThreshold, "%")));
|
|
96
|
+
}
|
|
97
|
+
if (options.numericDifferenceThreshold !== undefined) {
|
|
98
|
+
console.log(chalk.yellow("Numeric difference threshold set to: ".concat(options.numericDifferenceThreshold, "%")));
|
|
99
|
+
}
|
|
100
|
+
if (options.borderDifferenceThreshold !== undefined) {
|
|
101
|
+
console.log(chalk.yellow("Border difference threshold set to: ".concat(options.borderDifferenceThreshold, "%")));
|
|
102
|
+
}
|
|
64
103
|
}
|
|
65
104
|
tokenMap = getTokenMap((_options$useLegacyCol = options.useLegacyColorTheme) !== null && _options$useLegacyCol !== void 0 ? _options$useLegacyCol : false);
|
|
66
105
|
_context.next = 12;
|
|
@@ -81,35 +120,39 @@ function _transformer() {
|
|
|
81
120
|
case 16:
|
|
82
121
|
results = _context.sent;
|
|
83
122
|
unusedVars = [];
|
|
84
|
-
if (
|
|
123
|
+
if (!options.reportFolder) {
|
|
124
|
+
_context.next = 21;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
_context.next = 21;
|
|
128
|
+
return writeReports(details, options.reportFolder);
|
|
129
|
+
case 21:
|
|
130
|
+
if (!results.some(function (result) {
|
|
85
131
|
return result.fallbackRemoved;
|
|
86
132
|
})) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
133
|
+
_context.next = 35;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
allImports = results.flatMap(function (result) {
|
|
137
|
+
var _result$resolvedImpor;
|
|
138
|
+
return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
|
|
139
|
+
});
|
|
140
|
+
allVars = results.flatMap(function (result) {
|
|
141
|
+
var _result$resolvedLocal;
|
|
142
|
+
return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
|
|
143
|
+
});
|
|
144
|
+
unusedVars.push.apply(unusedVars, _toConsumableArray(allVars));
|
|
145
|
+
if (allImports.length) {
|
|
146
|
+
if (options.verbose) {
|
|
147
|
+
console.log(chalk.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
|
|
101
148
|
}
|
|
149
|
+
removeUnusedImports(allImports, j);
|
|
102
150
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
_context.next = 23;
|
|
106
|
-
break;
|
|
151
|
+
if (unusedVars.length) {
|
|
152
|
+
removeUnusedVariables(unusedVars, j);
|
|
107
153
|
}
|
|
108
|
-
_context.next = 23;
|
|
109
|
-
return writeReports(details, options.reportFolder);
|
|
110
|
-
case 23:
|
|
111
154
|
if (!options.dry) {
|
|
112
|
-
_context.next =
|
|
155
|
+
_context.next = 32;
|
|
113
156
|
break;
|
|
114
157
|
}
|
|
115
158
|
if (options.verbose) {
|
|
@@ -117,9 +160,14 @@ function _transformer() {
|
|
|
117
160
|
}
|
|
118
161
|
// Return the unmodified source if dryRun is true
|
|
119
162
|
return _context.abrupt("return", fileInfo.source);
|
|
120
|
-
case
|
|
163
|
+
case 32:
|
|
121
164
|
return _context.abrupt("return", source.toSource());
|
|
122
|
-
case
|
|
165
|
+
case 33:
|
|
166
|
+
_context.next = 36;
|
|
167
|
+
break;
|
|
168
|
+
case 35:
|
|
169
|
+
return _context.abrupt("return", fileInfo.source);
|
|
170
|
+
case 36:
|
|
123
171
|
case "end":
|
|
124
172
|
return _context.stop();
|
|
125
173
|
}
|
|
@@ -138,7 +186,7 @@ export function beforeAll(_x4) {
|
|
|
138
186
|
|
|
139
187
|
/**
|
|
140
188
|
* Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
|
|
141
|
-
* It also applies prettier to the affected files.
|
|
189
|
+
* It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
|
|
142
190
|
*/
|
|
143
191
|
function _beforeAll() {
|
|
144
192
|
_beforeAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
|
|
@@ -164,7 +212,7 @@ export function afterAll(_x5) {
|
|
|
164
212
|
}
|
|
165
213
|
function _afterAll() {
|
|
166
214
|
_afterAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
|
|
167
|
-
var filesTxtPath, fileContent;
|
|
215
|
+
var filesTxtPath, fileContent, filePaths, firstFilePath, rootDir;
|
|
168
216
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
169
217
|
while (1) switch (_context3.prev = _context3.next) {
|
|
170
218
|
case 0:
|
|
@@ -176,7 +224,7 @@ function _afterAll() {
|
|
|
176
224
|
return combineReports(options.reportFolder);
|
|
177
225
|
case 3:
|
|
178
226
|
if (!(options.reportFolder && !options.dry)) {
|
|
179
|
-
_context3.next =
|
|
227
|
+
_context3.next = 35;
|
|
180
228
|
break;
|
|
181
229
|
}
|
|
182
230
|
_context3.prev = 4;
|
|
@@ -186,30 +234,291 @@ function _afterAll() {
|
|
|
186
234
|
case 8:
|
|
187
235
|
fileContent = _context3.sent;
|
|
188
236
|
if (!(fileContent.length > 0)) {
|
|
189
|
-
_context3.next =
|
|
237
|
+
_context3.next = 30;
|
|
190
238
|
break;
|
|
191
239
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
console.log(chalk.green("Prettier was run successfully"));
|
|
240
|
+
filePaths = fileContent.split(/\r?\n/).filter(Boolean); // Get the first file path and strip any quotes
|
|
241
|
+
firstFilePath = filePaths[0].replace(/^['"]|['"]$/g, ''); // Determine the root directory using findRoot
|
|
242
|
+
_context3.next = 14;
|
|
243
|
+
return findRoot(path.dirname(firstFilePath));
|
|
197
244
|
case 14:
|
|
198
|
-
|
|
245
|
+
rootDir = _context3.sent;
|
|
246
|
+
console.log('Root directory:', rootDir);
|
|
247
|
+
_context3.next = 18;
|
|
248
|
+
return gitStage(filePaths, rootDir);
|
|
249
|
+
case 18:
|
|
250
|
+
if (options.skipEslint) {
|
|
251
|
+
_context3.next = 23;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
_context3.next = 21;
|
|
255
|
+
return runEslint(filePaths, rootDir);
|
|
256
|
+
case 21:
|
|
257
|
+
_context3.next = 24;
|
|
199
258
|
break;
|
|
200
|
-
case
|
|
201
|
-
|
|
259
|
+
case 23:
|
|
260
|
+
if (options.verbose) {
|
|
261
|
+
console.log(chalk.blue('Skipping ESLint post-processing as requested.'));
|
|
262
|
+
}
|
|
263
|
+
case 24:
|
|
264
|
+
if (options.skipPrettier) {
|
|
265
|
+
_context3.next = 29;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
_context3.next = 27;
|
|
269
|
+
return runPrettier(filePaths, rootDir);
|
|
270
|
+
case 27:
|
|
271
|
+
_context3.next = 30;
|
|
272
|
+
break;
|
|
273
|
+
case 29:
|
|
274
|
+
if (options.verbose) {
|
|
275
|
+
console.log(chalk.blue('Skipping Prettier post-processing as requested.'));
|
|
276
|
+
}
|
|
277
|
+
case 30:
|
|
278
|
+
_context3.next = 35;
|
|
279
|
+
break;
|
|
280
|
+
case 32:
|
|
281
|
+
_context3.prev = 32;
|
|
202
282
|
_context3.t0 = _context3["catch"](4);
|
|
203
283
|
if (_context3.t0 instanceof Error) {
|
|
204
|
-
console.error(chalk.red("Unexpected error
|
|
284
|
+
console.error(chalk.red("Unexpected error: ".concat(_context3.t0.message)));
|
|
205
285
|
} else {
|
|
206
|
-
console.error(chalk.red('An unknown error occurred
|
|
286
|
+
console.error(chalk.red('An unknown error occurred.'));
|
|
207
287
|
}
|
|
208
|
-
case
|
|
288
|
+
case 35:
|
|
209
289
|
case "end":
|
|
210
290
|
return _context3.stop();
|
|
211
291
|
}
|
|
212
|
-
}, _callee3, null, [[4,
|
|
292
|
+
}, _callee3, null, [[4, 32]]);
|
|
213
293
|
}));
|
|
214
294
|
return _afterAll.apply(this, arguments);
|
|
295
|
+
}
|
|
296
|
+
function gitStage(_x6, _x7) {
|
|
297
|
+
return _gitStage.apply(this, arguments);
|
|
298
|
+
}
|
|
299
|
+
function _gitStage() {
|
|
300
|
+
_gitStage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(filePaths, cwd) {
|
|
301
|
+
var gitAddCommand, _yield$execAsync, gitAddStdout, gitAddStderr;
|
|
302
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
303
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
304
|
+
case 0:
|
|
305
|
+
gitAddCommand = "git add ".concat(filePaths.join(' '));
|
|
306
|
+
console.log("Executing command: ".concat(gitAddCommand));
|
|
307
|
+
_context4.next = 4;
|
|
308
|
+
return execAsync(gitAddCommand, {
|
|
309
|
+
cwd: cwd
|
|
310
|
+
});
|
|
311
|
+
case 4:
|
|
312
|
+
_yield$execAsync = _context4.sent;
|
|
313
|
+
gitAddStdout = _yield$execAsync.stdout;
|
|
314
|
+
gitAddStderr = _yield$execAsync.stderr;
|
|
315
|
+
if (gitAddStdout) {
|
|
316
|
+
console.log(chalk.blue("Git add output:\n".concat(gitAddStdout)));
|
|
317
|
+
}
|
|
318
|
+
if (gitAddStderr) {
|
|
319
|
+
console.error(chalk.yellow("Git add errors:\n".concat(gitAddStderr)));
|
|
320
|
+
}
|
|
321
|
+
console.log(chalk.green("All changes have been staged."));
|
|
322
|
+
case 10:
|
|
323
|
+
case "end":
|
|
324
|
+
return _context4.stop();
|
|
325
|
+
}
|
|
326
|
+
}, _callee4);
|
|
327
|
+
}));
|
|
328
|
+
return _gitStage.apply(this, arguments);
|
|
329
|
+
}
|
|
330
|
+
function runPrettier(_x8, _x9) {
|
|
331
|
+
return _runPrettier.apply(this, arguments);
|
|
332
|
+
}
|
|
333
|
+
function _runPrettier() {
|
|
334
|
+
_runPrettier = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(filePaths, cwd) {
|
|
335
|
+
var prettierCommand, _yield$execAsync2, prettierStdout, prettierStderr;
|
|
336
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
337
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
338
|
+
case 0:
|
|
339
|
+
prettierCommand = "yarn prettier --write ".concat(filePaths.join(' '));
|
|
340
|
+
console.log("Executing command: ".concat(prettierCommand));
|
|
341
|
+
_context5.next = 4;
|
|
342
|
+
return execAsync(prettierCommand, {
|
|
343
|
+
cwd: cwd
|
|
344
|
+
});
|
|
345
|
+
case 4:
|
|
346
|
+
_yield$execAsync2 = _context5.sent;
|
|
347
|
+
prettierStdout = _yield$execAsync2.stdout;
|
|
348
|
+
prettierStderr = _yield$execAsync2.stderr;
|
|
349
|
+
if (prettierStdout) {
|
|
350
|
+
console.log(chalk.blue("Prettier output:\n".concat(prettierStdout)));
|
|
351
|
+
}
|
|
352
|
+
if (prettierStderr) {
|
|
353
|
+
console.error(chalk.yellow("Prettier errors:\n".concat(prettierStderr)));
|
|
354
|
+
}
|
|
355
|
+
console.log(chalk.green("Prettier was run successfully"));
|
|
356
|
+
case 10:
|
|
357
|
+
case "end":
|
|
358
|
+
return _context5.stop();
|
|
359
|
+
}
|
|
360
|
+
}, _callee5);
|
|
361
|
+
}));
|
|
362
|
+
return _runPrettier.apply(this, arguments);
|
|
363
|
+
}
|
|
364
|
+
function runEslint(_x0, _x1) {
|
|
365
|
+
return _runEslint.apply(this, arguments);
|
|
366
|
+
}
|
|
367
|
+
function _runEslint() {
|
|
368
|
+
_runEslint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(filePaths, cwd) {
|
|
369
|
+
var fileChunks, totalChunks, _iterator, _step, _loop;
|
|
370
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context9) {
|
|
371
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
372
|
+
case 0:
|
|
373
|
+
fileChunks = chunkArray(filePaths, 20);
|
|
374
|
+
totalChunks = fileChunks.length;
|
|
375
|
+
_iterator = _createForOfIteratorHelper(fileChunks.entries());
|
|
376
|
+
_context9.prev = 3;
|
|
377
|
+
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
378
|
+
var _step$value, chunkIndex, fileChunk, eslintCommand, result, stdout, stderr, smallerChunks, totalSmallerChunks, _iterator2, _step2, _loop2;
|
|
379
|
+
return _regeneratorRuntime.wrap(function _loop$(_context8) {
|
|
380
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
381
|
+
case 0:
|
|
382
|
+
_step$value = _slicedToArray(_step.value, 2), chunkIndex = _step$value[0], fileChunk = _step$value[1];
|
|
383
|
+
eslintCommand = "yarn eslint ".concat(fileChunk.join(' '), " --report-unused-disable-directives --fix");
|
|
384
|
+
console.log("Executing command for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(eslintCommand));
|
|
385
|
+
_context8.prev = 3;
|
|
386
|
+
_context8.next = 6;
|
|
387
|
+
return execAsync(eslintCommand, {
|
|
388
|
+
cwd: cwd
|
|
389
|
+
});
|
|
390
|
+
case 6:
|
|
391
|
+
result = _context8.sent;
|
|
392
|
+
stdout = result.stdout, stderr = result.stderr;
|
|
393
|
+
if (stdout) {
|
|
394
|
+
console.log(chalk.blue("ESLint output for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stdout)));
|
|
395
|
+
}
|
|
396
|
+
if (stderr) {
|
|
397
|
+
console.error(chalk.yellow("ESLint errors for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stderr)));
|
|
398
|
+
}
|
|
399
|
+
_context8.next = 34;
|
|
400
|
+
break;
|
|
401
|
+
case 12:
|
|
402
|
+
_context8.prev = 12;
|
|
403
|
+
_context8.t0 = _context8["catch"](3);
|
|
404
|
+
console.error(chalk.red("Error running ESLint on chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(_context8.t0)));
|
|
405
|
+
|
|
406
|
+
// Retry each file individually
|
|
407
|
+
console.log(chalk.yellow("Retrying each file in chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, " individually...")));
|
|
408
|
+
|
|
409
|
+
// Chunk the files into smaller groups of 5 for parallel retry
|
|
410
|
+
smallerChunks = chunkArray(fileChunk, 5);
|
|
411
|
+
totalSmallerChunks = smallerChunks.length;
|
|
412
|
+
_iterator2 = _createForOfIteratorHelper(smallerChunks.entries());
|
|
413
|
+
_context8.prev = 19;
|
|
414
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
|
|
415
|
+
var _step2$value, smallChunkIndex, smallerChunk;
|
|
416
|
+
return _regeneratorRuntime.wrap(function _loop2$(_context7) {
|
|
417
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
418
|
+
case 0:
|
|
419
|
+
_step2$value = _slicedToArray(_step2.value, 2), smallChunkIndex = _step2$value[0], smallerChunk = _step2$value[1];
|
|
420
|
+
_context7.next = 3;
|
|
421
|
+
return Promise.all(smallerChunk.map( /*#__PURE__*/function () {
|
|
422
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(file) {
|
|
423
|
+
var individualEslintCommand, _result, _stdout, _stderr;
|
|
424
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
425
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
426
|
+
case 0:
|
|
427
|
+
_context6.prev = 0;
|
|
428
|
+
individualEslintCommand = "yarn eslint ".concat(file, " --report-unused-disable-directives --fix");
|
|
429
|
+
console.log("Executing command for file in small chunk ".concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(individualEslintCommand));
|
|
430
|
+
_context6.next = 5;
|
|
431
|
+
return execAsync(individualEslintCommand, {
|
|
432
|
+
cwd: cwd
|
|
433
|
+
});
|
|
434
|
+
case 5:
|
|
435
|
+
_result = _context6.sent;
|
|
436
|
+
_stdout = _result.stdout, _stderr = _result.stderr;
|
|
437
|
+
if (_stdout) {
|
|
438
|
+
console.log(chalk.blue("ESLint output for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stdout)));
|
|
439
|
+
}
|
|
440
|
+
if (_stderr) {
|
|
441
|
+
console.error(chalk.yellow("ESLint errors for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stderr)));
|
|
442
|
+
}
|
|
443
|
+
_context6.next = 14;
|
|
444
|
+
break;
|
|
445
|
+
case 11:
|
|
446
|
+
_context6.prev = 11;
|
|
447
|
+
_context6.t0 = _context6["catch"](0);
|
|
448
|
+
console.error(chalk.red("Error running ESLint on file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(_context6.t0)));
|
|
449
|
+
case 14:
|
|
450
|
+
case "end":
|
|
451
|
+
return _context6.stop();
|
|
452
|
+
}
|
|
453
|
+
}, _callee6, null, [[0, 11]]);
|
|
454
|
+
}));
|
|
455
|
+
return function (_x10) {
|
|
456
|
+
return _ref2.apply(this, arguments);
|
|
457
|
+
};
|
|
458
|
+
}()));
|
|
459
|
+
case 3:
|
|
460
|
+
case "end":
|
|
461
|
+
return _context7.stop();
|
|
462
|
+
}
|
|
463
|
+
}, _loop2);
|
|
464
|
+
});
|
|
465
|
+
_iterator2.s();
|
|
466
|
+
case 22:
|
|
467
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
468
|
+
_context8.next = 26;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
return _context8.delegateYield(_loop2(), "t1", 24);
|
|
472
|
+
case 24:
|
|
473
|
+
_context8.next = 22;
|
|
474
|
+
break;
|
|
475
|
+
case 26:
|
|
476
|
+
_context8.next = 31;
|
|
477
|
+
break;
|
|
478
|
+
case 28:
|
|
479
|
+
_context8.prev = 28;
|
|
480
|
+
_context8.t2 = _context8["catch"](19);
|
|
481
|
+
_iterator2.e(_context8.t2);
|
|
482
|
+
case 31:
|
|
483
|
+
_context8.prev = 31;
|
|
484
|
+
_iterator2.f();
|
|
485
|
+
return _context8.finish(31);
|
|
486
|
+
case 34:
|
|
487
|
+
console.log(chalk.green("Finished running ESLint for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ".")));
|
|
488
|
+
case 35:
|
|
489
|
+
case "end":
|
|
490
|
+
return _context8.stop();
|
|
491
|
+
}
|
|
492
|
+
}, _loop, null, [[3, 12], [19, 28, 31, 34]]);
|
|
493
|
+
});
|
|
494
|
+
_iterator.s();
|
|
495
|
+
case 6:
|
|
496
|
+
if ((_step = _iterator.n()).done) {
|
|
497
|
+
_context9.next = 10;
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
return _context9.delegateYield(_loop(), "t0", 8);
|
|
501
|
+
case 8:
|
|
502
|
+
_context9.next = 6;
|
|
503
|
+
break;
|
|
504
|
+
case 10:
|
|
505
|
+
_context9.next = 15;
|
|
506
|
+
break;
|
|
507
|
+
case 12:
|
|
508
|
+
_context9.prev = 12;
|
|
509
|
+
_context9.t1 = _context9["catch"](3);
|
|
510
|
+
_iterator.e(_context9.t1);
|
|
511
|
+
case 15:
|
|
512
|
+
_context9.prev = 15;
|
|
513
|
+
_iterator.f();
|
|
514
|
+
return _context9.finish(15);
|
|
515
|
+
case 18:
|
|
516
|
+
console.log(chalk.green("ESLint was run on all files successfully"));
|
|
517
|
+
case 19:
|
|
518
|
+
case "end":
|
|
519
|
+
return _context9.stop();
|
|
520
|
+
}
|
|
521
|
+
}, _callee7, null, [[3, 12, 15, 18]]);
|
|
522
|
+
}));
|
|
523
|
+
return _runEslint.apply(this, arguments);
|
|
215
524
|
}
|
|
@@ -2,11 +2,17 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { colorToHex, compareHex, isValidColor } from './color-utils';
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
5
|
+
// Default threshold values
|
|
6
|
+
var DEFAULT_COLOR_DIFFERENCE = 15;
|
|
7
|
+
var DEFAULT_SPACE_DIFFERENCE = 0;
|
|
8
|
+
var DEFAULT_NUMERIC_DIFFERENCE = 0;
|
|
9
|
+
var DEFAULT_BORDER_DIFFERENCE = 0;
|
|
10
|
+
export function normalizeValues(tokenKey, tokenValue, fallbackValue, options) {
|
|
11
|
+
// Use options thresholds or defaults
|
|
12
|
+
var colorDifference = (options === null || options === void 0 ? void 0 : options.colorDifferenceThreshold) !== undefined ? options.colorDifferenceThreshold : DEFAULT_COLOR_DIFFERENCE;
|
|
13
|
+
var spaceDifference = (options === null || options === void 0 ? void 0 : options.spaceDifferenceThreshold) !== undefined ? options.spaceDifferenceThreshold : DEFAULT_SPACE_DIFFERENCE;
|
|
14
|
+
var numericDifference = (options === null || options === void 0 ? void 0 : options.numericDifferenceThreshold) !== undefined ? options.numericDifferenceThreshold : DEFAULT_NUMERIC_DIFFERENCE;
|
|
15
|
+
var borderDifference = (options === null || options === void 0 ? void 0 : options.borderDifferenceThreshold) !== undefined ? options.borderDifferenceThreshold : DEFAULT_BORDER_DIFFERENCE;
|
|
10
16
|
var tokenLogValue;
|
|
11
17
|
var fallbackLogValue;
|
|
12
18
|
var normalizedTokenValue = tokenValue;
|
|
@@ -27,15 +33,15 @@ export function normalizeValues(tokenKey, tokenValue, fallbackValue) {
|
|
|
27
33
|
}
|
|
28
34
|
if (normalizedTokenValue && normalizedFallbackValue) {
|
|
29
35
|
difference = compareHex(normalizedTokenValue, normalizedFallbackValue);
|
|
30
|
-
isAcceptableDifference = difference <=
|
|
36
|
+
isAcceptableDifference = difference <= colorDifference;
|
|
31
37
|
}
|
|
32
|
-
} else if (lowerCaseTokenKey.startsWith('space')) {
|
|
38
|
+
} else if (lowerCaseTokenKey.startsWith('space') || lowerCaseTokenKey.startsWith('border')) {
|
|
33
39
|
var tokenValueInPx = tokenValue ? convertToPx(tokenValue) : undefined;
|
|
34
40
|
var fallbackValueInPx = fallbackValue ? convertToPx(fallbackValue) : undefined;
|
|
35
41
|
if (tokenValueInPx !== undefined && fallbackValueInPx !== undefined) {
|
|
36
42
|
var maxVal = Math.max(tokenValueInPx, fallbackValueInPx);
|
|
37
43
|
difference = Math.abs(tokenValueInPx - fallbackValueInPx) / maxVal * 100;
|
|
38
|
-
isAcceptableDifference = difference <=
|
|
44
|
+
isAcceptableDifference = difference <= (lowerCaseTokenKey.startsWith('space') ? spaceDifference : borderDifference);
|
|
39
45
|
}
|
|
40
46
|
// Log the normalized values
|
|
41
47
|
normalizedTokenValue = tokenValue;
|
|
@@ -49,7 +55,7 @@ export function normalizeValues(tokenKey, tokenValue, fallbackValue) {
|
|
|
49
55
|
if (!isNaN(tokenValueNumber) && !isNaN(fallbackValueNumber)) {
|
|
50
56
|
var _maxVal = Math.max(tokenValueNumber, fallbackValueNumber);
|
|
51
57
|
difference = Math.abs(tokenValueNumber - fallbackValueNumber) / _maxVal * 100;
|
|
52
|
-
isAcceptableDifference = difference <=
|
|
58
|
+
isAcceptableDifference = difference <= numericDifference;
|
|
53
59
|
}
|
|
54
60
|
// Log the normalized values
|
|
55
61
|
normalizedTokenValue = tokenValue;
|
|
@@ -40,12 +40,12 @@ export function removeUnusedImports(importDeclarations, j) {
|
|
|
40
40
|
};
|
|
41
41
|
var processImportDeclaration = function processImportDeclaration(importDeclaration) {
|
|
42
42
|
var _importDeclaration$va, _importDeclaration$va2;
|
|
43
|
-
if (((_importDeclaration$va = importDeclaration.value.specifiers) === null || _importDeclaration$va === void 0 ? void 0 : _importDeclaration$va.length) === 0) {
|
|
43
|
+
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) {
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
var hadUnusedDefaultImport = removeUnusedDefaultImport(importDeclaration);
|
|
47
47
|
var hadUnusedNonDefaultImports = removeUnusedNonDefaultImports(importDeclaration);
|
|
48
|
-
if (((_importDeclaration$va2 = importDeclaration.value.specifiers) === null || _importDeclaration$va2 === void 0 ? void 0 : _importDeclaration$va2.length) === 0) {
|
|
48
|
+
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) {
|
|
49
49
|
j(importDeclaration).remove();
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
@@ -74,41 +74,47 @@ function _clearFolder() {
|
|
|
74
74
|
while (1) switch (_context3.prev = _context3.next) {
|
|
75
75
|
case 0:
|
|
76
76
|
console.log('Clearing report folder:', reportFolder);
|
|
77
|
+
// Create the folder if it doesn't exist
|
|
77
78
|
_context3.next = 3;
|
|
78
|
-
return fs.
|
|
79
|
+
return fs.mkdir(reportFolder, {
|
|
80
|
+
recursive: true
|
|
81
|
+
});
|
|
79
82
|
case 3:
|
|
83
|
+
_context3.next = 5;
|
|
84
|
+
return fs.readdir(reportFolder);
|
|
85
|
+
case 5:
|
|
80
86
|
filesToDelete = _context3.sent;
|
|
81
87
|
_iterator = _createForOfIteratorHelper(filesToDelete);
|
|
82
|
-
_context3.prev =
|
|
88
|
+
_context3.prev = 7;
|
|
83
89
|
_iterator.s();
|
|
84
|
-
case
|
|
90
|
+
case 9:
|
|
85
91
|
if ((_step = _iterator.n()).done) {
|
|
86
|
-
_context3.next =
|
|
92
|
+
_context3.next = 16;
|
|
87
93
|
break;
|
|
88
94
|
}
|
|
89
95
|
file = _step.value;
|
|
90
96
|
filePath = path.join(reportFolder, file);
|
|
91
|
-
_context3.next =
|
|
97
|
+
_context3.next = 14;
|
|
92
98
|
return fs.unlink(filePath);
|
|
93
|
-
case 12:
|
|
94
|
-
_context3.next = 7;
|
|
95
|
-
break;
|
|
96
99
|
case 14:
|
|
97
|
-
_context3.next =
|
|
100
|
+
_context3.next = 9;
|
|
98
101
|
break;
|
|
99
102
|
case 16:
|
|
100
|
-
_context3.
|
|
101
|
-
|
|
103
|
+
_context3.next = 21;
|
|
104
|
+
break;
|
|
105
|
+
case 18:
|
|
106
|
+
_context3.prev = 18;
|
|
107
|
+
_context3.t0 = _context3["catch"](7);
|
|
102
108
|
_iterator.e(_context3.t0);
|
|
103
|
-
case
|
|
104
|
-
_context3.prev =
|
|
109
|
+
case 21:
|
|
110
|
+
_context3.prev = 21;
|
|
105
111
|
_iterator.f();
|
|
106
|
-
return _context3.finish(
|
|
107
|
-
case
|
|
112
|
+
return _context3.finish(21);
|
|
113
|
+
case 24:
|
|
108
114
|
case "end":
|
|
109
115
|
return _context3.stop();
|
|
110
116
|
}
|
|
111
|
-
}, _callee3, null, [[
|
|
117
|
+
}, _callee3, null, [[7, 18, 21, 24]]);
|
|
112
118
|
}));
|
|
113
119
|
return _clearFolder.apply(this, arguments);
|
|
114
120
|
}
|
|
@@ -117,16 +123,17 @@ function saveFilePaths(_x5, _x6) {
|
|
|
117
123
|
}
|
|
118
124
|
function _saveFilePaths() {
|
|
119
125
|
_saveFilePaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(reportFolder, files) {
|
|
120
|
-
var filesTxtPath;
|
|
126
|
+
var filesTxtPath, sortedFiles;
|
|
121
127
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
122
128
|
while (1) switch (_context4.prev = _context4.next) {
|
|
123
129
|
case 0:
|
|
124
130
|
filesTxtPath = path.join(reportFolder, 'files.txt');
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
sortedFiles = Array.from(files).sort(); // Sort the file paths alphabetically
|
|
132
|
+
_context4.next = 4;
|
|
133
|
+
return fs.writeFile(filesTxtPath, sortedFiles.map(function (filePath) {
|
|
127
134
|
return "\"".concat(filePath, "\"");
|
|
128
|
-
}).join('
|
|
129
|
-
case
|
|
135
|
+
}).join('\n'), 'utf-8');
|
|
136
|
+
case 4:
|
|
130
137
|
case "end":
|
|
131
138
|
return _context4.stop();
|
|
132
139
|
}
|