@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.28.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 0.28.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#135751](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/135751)
|
|
14
|
+
[`320e4346043c0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/320e4346043c0) -
|
|
15
|
+
Allows specifying multiple ignore patterns using | symbol. Fixes minor issues in
|
|
16
|
+
remove-token-fallbacks preset
|
|
17
|
+
|
|
3
18
|
## 0.27.4
|
|
4
19
|
|
|
5
20
|
### 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)
|
|
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']
|
|
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 =
|
|
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
|
|
204
|
+
case 24:
|
|
200
205
|
if (!transformModule) {
|
|
201
|
-
_context3.next =
|
|
206
|
+
_context3.next = 27;
|
|
202
207
|
break;
|
|
203
208
|
}
|
|
204
|
-
_context3.next =
|
|
209
|
+
_context3.next = 27;
|
|
205
210
|
return processLifecycleHook('afterAll', transformModule, logger, transform, flags);
|
|
206
|
-
case
|
|
211
|
+
case 27:
|
|
207
212
|
case "end":
|
|
208
213
|
return _context3.stop();
|
|
209
214
|
}
|
|
@@ -309,7 +314,7 @@ var defaultFlags = {
|
|
|
309
314
|
ignorePattern: 'node_modules',
|
|
310
315
|
logger: console
|
|
311
316
|
};
|
|
312
|
-
function processLifecycleHook(_x9,
|
|
317
|
+
function processLifecycleHook(_x9, _x0, _x1, _x10, _x11) {
|
|
313
318
|
return _processLifecycleHook.apply(this, arguments);
|
|
314
319
|
}
|
|
315
320
|
function _processLifecycleHook() {
|
|
@@ -341,7 +346,7 @@ function _processLifecycleHook() {
|
|
|
341
346
|
}));
|
|
342
347
|
return _processLifecycleHook.apply(this, arguments);
|
|
343
348
|
}
|
|
344
|
-
function main(
|
|
349
|
+
function main(_x12, _x13) {
|
|
345
350
|
return _main.apply(this, arguments);
|
|
346
351
|
}
|
|
347
352
|
function _main() {
|
|
@@ -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.
|
|
365
|
+
_process$env$_PACKAGE = "0.28.1", _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
|
-
|
|
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
|
/**
|
|
@@ -41,6 +44,14 @@ var execAsync = (0, _util.promisify)(_child_process.exec);
|
|
|
41
44
|
* @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
|
|
42
45
|
* @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
|
|
43
46
|
* @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
|
|
47
|
+
* @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.
|
|
48
|
+
* @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.
|
|
49
|
+
* @param {boolean} [options.skipEslint] - If true, skips running ESLint on modified files after transformation.
|
|
50
|
+
* @param {boolean} [options.skipPrettier] - If true, skips running Prettier on modified files after transformation.
|
|
51
|
+
* @param {number} [options.colorDifferenceThreshold] - The maximum allowed difference for color tokens to be considered acceptable for removal. Default is 15.
|
|
52
|
+
* @param {number} [options.spaceDifferenceThreshold] - The maximum allowed percentage difference for space tokens to be considered acceptable for removal. Default is 0.
|
|
53
|
+
* @param {number} [options.numericDifferenceThreshold] - The maximum allowed percentage difference for numeric tokens to be considered acceptable for removal. Default is 0.
|
|
54
|
+
* @param {number} [options.borderDifferenceThreshold] - The maximum allowed percentage difference for border tokens to be considered acceptable for removal. Default is 0.
|
|
44
55
|
*
|
|
45
56
|
* @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
|
|
46
57
|
*/
|
|
@@ -72,6 +83,32 @@ function _transformer() {
|
|
|
72
83
|
};
|
|
73
84
|
if (options.verbose) {
|
|
74
85
|
console.log(_chalk.default.yellow("Using ".concat(options.useLegacyColorTheme ? 'legacy light' : 'light', " theme.")));
|
|
86
|
+
if (options.skipTokens) {
|
|
87
|
+
console.log(_chalk.default.yellow("Auto fallback exemptions active for: ".concat(options.skipTokens)));
|
|
88
|
+
}
|
|
89
|
+
if (options.preserveSkippedFallbacks) {
|
|
90
|
+
console.log(_chalk.default.yellow("Preserving all fallbacks for skipped tokens, even if they match exactly."));
|
|
91
|
+
}
|
|
92
|
+
if (options.skipEslint) {
|
|
93
|
+
console.log(_chalk.default.yellow("Skipping ESLint post-processing."));
|
|
94
|
+
}
|
|
95
|
+
if (options.skipPrettier) {
|
|
96
|
+
console.log(_chalk.default.yellow("Skipping Prettier post-processing."));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Log threshold values if they are set
|
|
100
|
+
if (options.colorDifferenceThreshold !== undefined) {
|
|
101
|
+
console.log(_chalk.default.yellow("Color difference threshold set to: ".concat(options.colorDifferenceThreshold)));
|
|
102
|
+
}
|
|
103
|
+
if (options.spaceDifferenceThreshold !== undefined) {
|
|
104
|
+
console.log(_chalk.default.yellow("Space difference threshold set to: ".concat(options.spaceDifferenceThreshold, "%")));
|
|
105
|
+
}
|
|
106
|
+
if (options.numericDifferenceThreshold !== undefined) {
|
|
107
|
+
console.log(_chalk.default.yellow("Numeric difference threshold set to: ".concat(options.numericDifferenceThreshold, "%")));
|
|
108
|
+
}
|
|
109
|
+
if (options.borderDifferenceThreshold !== undefined) {
|
|
110
|
+
console.log(_chalk.default.yellow("Border difference threshold set to: ".concat(options.borderDifferenceThreshold, "%")));
|
|
111
|
+
}
|
|
75
112
|
}
|
|
76
113
|
tokenMap = (0, _allTokens.getTokenMap)((_options$useLegacyCol = options.useLegacyColorTheme) !== null && _options$useLegacyCol !== void 0 ? _options$useLegacyCol : false);
|
|
77
114
|
_context.next = 12;
|
|
@@ -92,35 +129,39 @@ function _transformer() {
|
|
|
92
129
|
case 16:
|
|
93
130
|
results = _context.sent;
|
|
94
131
|
unusedVars = [];
|
|
95
|
-
if (
|
|
132
|
+
if (!options.reportFolder) {
|
|
133
|
+
_context.next = 21;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
_context.next = 21;
|
|
137
|
+
return (0, _reporter.writeReports)(details, options.reportFolder);
|
|
138
|
+
case 21:
|
|
139
|
+
if (!results.some(function (result) {
|
|
96
140
|
return result.fallbackRemoved;
|
|
97
141
|
})) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
142
|
+
_context.next = 35;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
allImports = results.flatMap(function (result) {
|
|
146
|
+
var _result$resolvedImpor;
|
|
147
|
+
return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
|
|
148
|
+
});
|
|
149
|
+
allVars = results.flatMap(function (result) {
|
|
150
|
+
var _result$resolvedLocal;
|
|
151
|
+
return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
|
|
152
|
+
});
|
|
153
|
+
unusedVars.push.apply(unusedVars, (0, _toConsumableArray2.default)(allVars));
|
|
154
|
+
if (allImports.length) {
|
|
155
|
+
if (options.verbose) {
|
|
156
|
+
console.log(_chalk.default.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
|
|
112
157
|
}
|
|
158
|
+
(0, _removeUnusedImports.removeUnusedImports)(allImports, j);
|
|
113
159
|
}
|
|
114
|
-
(
|
|
115
|
-
|
|
116
|
-
_context.next = 23;
|
|
117
|
-
break;
|
|
160
|
+
if (unusedVars.length) {
|
|
161
|
+
(0, _removeUnusedVariables.removeUnusedVariables)(unusedVars, j);
|
|
118
162
|
}
|
|
119
|
-
_context.next = 23;
|
|
120
|
-
return (0, _reporter.writeReports)(details, options.reportFolder);
|
|
121
|
-
case 23:
|
|
122
163
|
if (!options.dry) {
|
|
123
|
-
_context.next =
|
|
164
|
+
_context.next = 32;
|
|
124
165
|
break;
|
|
125
166
|
}
|
|
126
167
|
if (options.verbose) {
|
|
@@ -128,9 +169,14 @@ function _transformer() {
|
|
|
128
169
|
}
|
|
129
170
|
// Return the unmodified source if dryRun is true
|
|
130
171
|
return _context.abrupt("return", fileInfo.source);
|
|
131
|
-
case
|
|
172
|
+
case 32:
|
|
132
173
|
return _context.abrupt("return", source.toSource());
|
|
133
|
-
case
|
|
174
|
+
case 33:
|
|
175
|
+
_context.next = 36;
|
|
176
|
+
break;
|
|
177
|
+
case 35:
|
|
178
|
+
return _context.abrupt("return", fileInfo.source);
|
|
179
|
+
case 36:
|
|
134
180
|
case "end":
|
|
135
181
|
return _context.stop();
|
|
136
182
|
}
|
|
@@ -148,7 +194,7 @@ function beforeAll(_x4) {
|
|
|
148
194
|
}
|
|
149
195
|
/**
|
|
150
196
|
* Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
|
|
151
|
-
* It also applies prettier to the affected files.
|
|
197
|
+
* It also applies prettier and eslint (to remove dangling suppressions) to the affected files.
|
|
152
198
|
*/
|
|
153
199
|
function _beforeAll() {
|
|
154
200
|
_beforeAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
|
|
@@ -174,7 +220,7 @@ function afterAll(_x5) {
|
|
|
174
220
|
}
|
|
175
221
|
function _afterAll() {
|
|
176
222
|
_afterAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(options) {
|
|
177
|
-
var filesTxtPath, fileContent;
|
|
223
|
+
var filesTxtPath, fileContent, filePaths, firstFilePath, rootDir;
|
|
178
224
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
179
225
|
while (1) switch (_context3.prev = _context3.next) {
|
|
180
226
|
case 0:
|
|
@@ -186,7 +232,7 @@ function _afterAll() {
|
|
|
186
232
|
return (0, _reporter.combineReports)(options.reportFolder);
|
|
187
233
|
case 3:
|
|
188
234
|
if (!(options.reportFolder && !options.dry)) {
|
|
189
|
-
_context3.next =
|
|
235
|
+
_context3.next = 35;
|
|
190
236
|
break;
|
|
191
237
|
}
|
|
192
238
|
_context3.prev = 4;
|
|
@@ -196,30 +242,291 @@ function _afterAll() {
|
|
|
196
242
|
case 8:
|
|
197
243
|
fileContent = _context3.sent;
|
|
198
244
|
if (!(fileContent.length > 0)) {
|
|
199
|
-
_context3.next =
|
|
245
|
+
_context3.next = 30;
|
|
200
246
|
break;
|
|
201
247
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
console.log(_chalk.default.green("Prettier was run successfully"));
|
|
248
|
+
filePaths = fileContent.split(/\r?\n/).filter(Boolean); // Get the first file path and strip any quotes
|
|
249
|
+
firstFilePath = filePaths[0].replace(/^['"]|['"]$/g, ''); // Determine the root directory using findRoot
|
|
250
|
+
_context3.next = 14;
|
|
251
|
+
return (0, _findRoot.findRoot)(_path.default.dirname(firstFilePath));
|
|
207
252
|
case 14:
|
|
208
|
-
|
|
253
|
+
rootDir = _context3.sent;
|
|
254
|
+
console.log('Root directory:', rootDir);
|
|
255
|
+
_context3.next = 18;
|
|
256
|
+
return gitStage(filePaths, rootDir);
|
|
257
|
+
case 18:
|
|
258
|
+
if (options.skipEslint) {
|
|
259
|
+
_context3.next = 23;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
_context3.next = 21;
|
|
263
|
+
return runEslint(filePaths, rootDir);
|
|
264
|
+
case 21:
|
|
265
|
+
_context3.next = 24;
|
|
209
266
|
break;
|
|
210
|
-
case
|
|
211
|
-
|
|
267
|
+
case 23:
|
|
268
|
+
if (options.verbose) {
|
|
269
|
+
console.log(_chalk.default.blue('Skipping ESLint post-processing as requested.'));
|
|
270
|
+
}
|
|
271
|
+
case 24:
|
|
272
|
+
if (options.skipPrettier) {
|
|
273
|
+
_context3.next = 29;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
_context3.next = 27;
|
|
277
|
+
return runPrettier(filePaths, rootDir);
|
|
278
|
+
case 27:
|
|
279
|
+
_context3.next = 30;
|
|
280
|
+
break;
|
|
281
|
+
case 29:
|
|
282
|
+
if (options.verbose) {
|
|
283
|
+
console.log(_chalk.default.blue('Skipping Prettier post-processing as requested.'));
|
|
284
|
+
}
|
|
285
|
+
case 30:
|
|
286
|
+
_context3.next = 35;
|
|
287
|
+
break;
|
|
288
|
+
case 32:
|
|
289
|
+
_context3.prev = 32;
|
|
212
290
|
_context3.t0 = _context3["catch"](4);
|
|
213
291
|
if (_context3.t0 instanceof Error) {
|
|
214
|
-
console.error(_chalk.default.red("Unexpected error
|
|
292
|
+
console.error(_chalk.default.red("Unexpected error: ".concat(_context3.t0.message)));
|
|
215
293
|
} else {
|
|
216
|
-
console.error(_chalk.default.red('An unknown error occurred
|
|
294
|
+
console.error(_chalk.default.red('An unknown error occurred.'));
|
|
217
295
|
}
|
|
218
|
-
case
|
|
296
|
+
case 35:
|
|
219
297
|
case "end":
|
|
220
298
|
return _context3.stop();
|
|
221
299
|
}
|
|
222
|
-
}, _callee3, null, [[4,
|
|
300
|
+
}, _callee3, null, [[4, 32]]);
|
|
223
301
|
}));
|
|
224
302
|
return _afterAll.apply(this, arguments);
|
|
303
|
+
}
|
|
304
|
+
function gitStage(_x6, _x7) {
|
|
305
|
+
return _gitStage.apply(this, arguments);
|
|
306
|
+
}
|
|
307
|
+
function _gitStage() {
|
|
308
|
+
_gitStage = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(filePaths, cwd) {
|
|
309
|
+
var gitAddCommand, _yield$execAsync, gitAddStdout, gitAddStderr;
|
|
310
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
311
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
312
|
+
case 0:
|
|
313
|
+
gitAddCommand = "git add ".concat(filePaths.join(' '));
|
|
314
|
+
console.log("Executing command: ".concat(gitAddCommand));
|
|
315
|
+
_context4.next = 4;
|
|
316
|
+
return execAsync(gitAddCommand, {
|
|
317
|
+
cwd: cwd
|
|
318
|
+
});
|
|
319
|
+
case 4:
|
|
320
|
+
_yield$execAsync = _context4.sent;
|
|
321
|
+
gitAddStdout = _yield$execAsync.stdout;
|
|
322
|
+
gitAddStderr = _yield$execAsync.stderr;
|
|
323
|
+
if (gitAddStdout) {
|
|
324
|
+
console.log(_chalk.default.blue("Git add output:\n".concat(gitAddStdout)));
|
|
325
|
+
}
|
|
326
|
+
if (gitAddStderr) {
|
|
327
|
+
console.error(_chalk.default.yellow("Git add errors:\n".concat(gitAddStderr)));
|
|
328
|
+
}
|
|
329
|
+
console.log(_chalk.default.green("All changes have been staged."));
|
|
330
|
+
case 10:
|
|
331
|
+
case "end":
|
|
332
|
+
return _context4.stop();
|
|
333
|
+
}
|
|
334
|
+
}, _callee4);
|
|
335
|
+
}));
|
|
336
|
+
return _gitStage.apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
function runPrettier(_x8, _x9) {
|
|
339
|
+
return _runPrettier.apply(this, arguments);
|
|
340
|
+
}
|
|
341
|
+
function _runPrettier() {
|
|
342
|
+
_runPrettier = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(filePaths, cwd) {
|
|
343
|
+
var prettierCommand, _yield$execAsync2, prettierStdout, prettierStderr;
|
|
344
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
345
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
346
|
+
case 0:
|
|
347
|
+
prettierCommand = "yarn prettier --write ".concat(filePaths.join(' '));
|
|
348
|
+
console.log("Executing command: ".concat(prettierCommand));
|
|
349
|
+
_context5.next = 4;
|
|
350
|
+
return execAsync(prettierCommand, {
|
|
351
|
+
cwd: cwd
|
|
352
|
+
});
|
|
353
|
+
case 4:
|
|
354
|
+
_yield$execAsync2 = _context5.sent;
|
|
355
|
+
prettierStdout = _yield$execAsync2.stdout;
|
|
356
|
+
prettierStderr = _yield$execAsync2.stderr;
|
|
357
|
+
if (prettierStdout) {
|
|
358
|
+
console.log(_chalk.default.blue("Prettier output:\n".concat(prettierStdout)));
|
|
359
|
+
}
|
|
360
|
+
if (prettierStderr) {
|
|
361
|
+
console.error(_chalk.default.yellow("Prettier errors:\n".concat(prettierStderr)));
|
|
362
|
+
}
|
|
363
|
+
console.log(_chalk.default.green("Prettier was run successfully"));
|
|
364
|
+
case 10:
|
|
365
|
+
case "end":
|
|
366
|
+
return _context5.stop();
|
|
367
|
+
}
|
|
368
|
+
}, _callee5);
|
|
369
|
+
}));
|
|
370
|
+
return _runPrettier.apply(this, arguments);
|
|
371
|
+
}
|
|
372
|
+
function runEslint(_x0, _x1) {
|
|
373
|
+
return _runEslint.apply(this, arguments);
|
|
374
|
+
}
|
|
375
|
+
function _runEslint() {
|
|
376
|
+
_runEslint = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(filePaths, cwd) {
|
|
377
|
+
var fileChunks, totalChunks, _iterator, _step, _loop;
|
|
378
|
+
return _regenerator.default.wrap(function _callee7$(_context9) {
|
|
379
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
380
|
+
case 0:
|
|
381
|
+
fileChunks = (0, _chunk.chunkArray)(filePaths, 20);
|
|
382
|
+
totalChunks = fileChunks.length;
|
|
383
|
+
_iterator = _createForOfIteratorHelper(fileChunks.entries());
|
|
384
|
+
_context9.prev = 3;
|
|
385
|
+
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
386
|
+
var _step$value, chunkIndex, fileChunk, eslintCommand, result, stdout, stderr, smallerChunks, totalSmallerChunks, _iterator2, _step2, _loop2;
|
|
387
|
+
return _regenerator.default.wrap(function _loop$(_context8) {
|
|
388
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
389
|
+
case 0:
|
|
390
|
+
_step$value = (0, _slicedToArray2.default)(_step.value, 2), chunkIndex = _step$value[0], fileChunk = _step$value[1];
|
|
391
|
+
eslintCommand = "yarn eslint ".concat(fileChunk.join(' '), " --report-unused-disable-directives --fix");
|
|
392
|
+
console.log("Executing command for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(eslintCommand));
|
|
393
|
+
_context8.prev = 3;
|
|
394
|
+
_context8.next = 6;
|
|
395
|
+
return execAsync(eslintCommand, {
|
|
396
|
+
cwd: cwd
|
|
397
|
+
});
|
|
398
|
+
case 6:
|
|
399
|
+
result = _context8.sent;
|
|
400
|
+
stdout = result.stdout, stderr = result.stderr;
|
|
401
|
+
if (stdout) {
|
|
402
|
+
console.log(_chalk.default.blue("ESLint output for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stdout)));
|
|
403
|
+
}
|
|
404
|
+
if (stderr) {
|
|
405
|
+
console.error(_chalk.default.yellow("ESLint errors for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ":\n").concat(stderr)));
|
|
406
|
+
}
|
|
407
|
+
_context8.next = 34;
|
|
408
|
+
break;
|
|
409
|
+
case 12:
|
|
410
|
+
_context8.prev = 12;
|
|
411
|
+
_context8.t0 = _context8["catch"](3);
|
|
412
|
+
console.error(_chalk.default.red("Error running ESLint on chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ": ").concat(_context8.t0)));
|
|
413
|
+
|
|
414
|
+
// Retry each file individually
|
|
415
|
+
console.log(_chalk.default.yellow("Retrying each file in chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, " individually...")));
|
|
416
|
+
|
|
417
|
+
// Chunk the files into smaller groups of 5 for parallel retry
|
|
418
|
+
smallerChunks = (0, _chunk.chunkArray)(fileChunk, 5);
|
|
419
|
+
totalSmallerChunks = smallerChunks.length;
|
|
420
|
+
_iterator2 = _createForOfIteratorHelper(smallerChunks.entries());
|
|
421
|
+
_context8.prev = 19;
|
|
422
|
+
_loop2 = /*#__PURE__*/_regenerator.default.mark(function _loop2() {
|
|
423
|
+
var _step2$value, smallChunkIndex, smallerChunk;
|
|
424
|
+
return _regenerator.default.wrap(function _loop2$(_context7) {
|
|
425
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
426
|
+
case 0:
|
|
427
|
+
_step2$value = (0, _slicedToArray2.default)(_step2.value, 2), smallChunkIndex = _step2$value[0], smallerChunk = _step2$value[1];
|
|
428
|
+
_context7.next = 3;
|
|
429
|
+
return Promise.all(smallerChunk.map( /*#__PURE__*/function () {
|
|
430
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(file) {
|
|
431
|
+
var individualEslintCommand, _result, _stdout, _stderr;
|
|
432
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
433
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
434
|
+
case 0:
|
|
435
|
+
_context6.prev = 0;
|
|
436
|
+
individualEslintCommand = "yarn eslint ".concat(file, " --report-unused-disable-directives --fix");
|
|
437
|
+
console.log("Executing command for file in small chunk ".concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(individualEslintCommand));
|
|
438
|
+
_context6.next = 5;
|
|
439
|
+
return execAsync(individualEslintCommand, {
|
|
440
|
+
cwd: cwd
|
|
441
|
+
});
|
|
442
|
+
case 5:
|
|
443
|
+
_result = _context6.sent;
|
|
444
|
+
_stdout = _result.stdout, _stderr = _result.stderr;
|
|
445
|
+
if (_stdout) {
|
|
446
|
+
console.log(_chalk.default.blue("ESLint output for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stdout)));
|
|
447
|
+
}
|
|
448
|
+
if (_stderr) {
|
|
449
|
+
console.error(_chalk.default.yellow("ESLint errors for file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ":\n").concat(_stderr)));
|
|
450
|
+
}
|
|
451
|
+
_context6.next = 14;
|
|
452
|
+
break;
|
|
453
|
+
case 11:
|
|
454
|
+
_context6.prev = 11;
|
|
455
|
+
_context6.t0 = _context6["catch"](0);
|
|
456
|
+
console.error(_chalk.default.red("Error running ESLint on file ".concat(file, " in small chunk ").concat(smallChunkIndex + 1, " of ").concat(totalSmallerChunks, ": ").concat(_context6.t0)));
|
|
457
|
+
case 14:
|
|
458
|
+
case "end":
|
|
459
|
+
return _context6.stop();
|
|
460
|
+
}
|
|
461
|
+
}, _callee6, null, [[0, 11]]);
|
|
462
|
+
}));
|
|
463
|
+
return function (_x10) {
|
|
464
|
+
return _ref2.apply(this, arguments);
|
|
465
|
+
};
|
|
466
|
+
}()));
|
|
467
|
+
case 3:
|
|
468
|
+
case "end":
|
|
469
|
+
return _context7.stop();
|
|
470
|
+
}
|
|
471
|
+
}, _loop2);
|
|
472
|
+
});
|
|
473
|
+
_iterator2.s();
|
|
474
|
+
case 22:
|
|
475
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
476
|
+
_context8.next = 26;
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
return _context8.delegateYield(_loop2(), "t1", 24);
|
|
480
|
+
case 24:
|
|
481
|
+
_context8.next = 22;
|
|
482
|
+
break;
|
|
483
|
+
case 26:
|
|
484
|
+
_context8.next = 31;
|
|
485
|
+
break;
|
|
486
|
+
case 28:
|
|
487
|
+
_context8.prev = 28;
|
|
488
|
+
_context8.t2 = _context8["catch"](19);
|
|
489
|
+
_iterator2.e(_context8.t2);
|
|
490
|
+
case 31:
|
|
491
|
+
_context8.prev = 31;
|
|
492
|
+
_iterator2.f();
|
|
493
|
+
return _context8.finish(31);
|
|
494
|
+
case 34:
|
|
495
|
+
console.log(_chalk.default.green("Finished running ESLint for chunk ".concat(chunkIndex + 1, " of ").concat(totalChunks, ".")));
|
|
496
|
+
case 35:
|
|
497
|
+
case "end":
|
|
498
|
+
return _context8.stop();
|
|
499
|
+
}
|
|
500
|
+
}, _loop, null, [[3, 12], [19, 28, 31, 34]]);
|
|
501
|
+
});
|
|
502
|
+
_iterator.s();
|
|
503
|
+
case 6:
|
|
504
|
+
if ((_step = _iterator.n()).done) {
|
|
505
|
+
_context9.next = 10;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
return _context9.delegateYield(_loop(), "t0", 8);
|
|
509
|
+
case 8:
|
|
510
|
+
_context9.next = 6;
|
|
511
|
+
break;
|
|
512
|
+
case 10:
|
|
513
|
+
_context9.next = 15;
|
|
514
|
+
break;
|
|
515
|
+
case 12:
|
|
516
|
+
_context9.prev = 12;
|
|
517
|
+
_context9.t1 = _context9["catch"](3);
|
|
518
|
+
_iterator.e(_context9.t1);
|
|
519
|
+
case 15:
|
|
520
|
+
_context9.prev = 15;
|
|
521
|
+
_iterator.f();
|
|
522
|
+
return _context9.finish(15);
|
|
523
|
+
case 18:
|
|
524
|
+
console.log(_chalk.default.green("ESLint was run on all files successfully"));
|
|
525
|
+
case 19:
|
|
526
|
+
case "end":
|
|
527
|
+
return _context9.stop();
|
|
528
|
+
}
|
|
529
|
+
}, _callee7, null, [[3, 12, 15, 18]]);
|
|
530
|
+
}));
|
|
531
|
+
return _runEslint.apply(this, arguments);
|
|
225
532
|
}
|
|
@@ -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
|
+
};
|