auto-cr-cmd 2.0.98 → 2.0.100

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/dist/index.js CHANGED
@@ -78,10 +78,16 @@ var loader_1 = require("./rules/loader");
78
78
  var autocrrc_1 = require("./config/autocrrc");
79
79
  var ignore_1 = require("./config/ignore");
80
80
  consola_1.consola.options.formatOptions = __assign(__assign({}, consola_1.consola.options.formatOptions), { date: false });
81
+ // 文本输出统一写入 stderr,避免多线程时 stdout/stderr 混排导致顺序错乱。
82
+ var textLogger = consola_1.consola.create({
83
+ stdout: process.stderr,
84
+ stderr: process.stderr,
85
+ });
86
+ textLogger.options.formatOptions = __assign(__assign({}, textLogger.options.formatOptions), { date: false });
81
87
  var consolaLoggers = {
82
- info: consola_1.consola.info.bind(consola_1.consola),
83
- warn: consola_1.consola.warn.bind(consola_1.consola),
84
- error: consola_1.consola.error.bind(consola_1.consola),
88
+ info: textLogger.info.bind(textLogger),
89
+ warn: textLogger.warn.bind(textLogger),
90
+ error: textLogger.error.bind(textLogger),
85
91
  };
86
92
  // 仅扫描 JS/TS 源码扩展名,避免把配置文件/JSON/图片等送进 SWC 解析导致报错。
87
93
  var SCANNABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
@@ -642,12 +648,12 @@ catch (error) {
642
648
  process.exit(exitCode);
643
649
  }
644
650
  if (result.scannedFiles > 0) {
645
- consola_1.consola.log(' ');
651
+ textLogger.log(' ');
646
652
  language = (0, i18n_1.getLanguage)();
647
653
  resultMessage = language.startsWith('zh')
648
654
  ? " ".concat(t.scanComplete(), "\uFF0C\u672C\u6B21\u5171\u626B\u63CF").concat(result.scannedFiles, "\u4E2A\u6587\u4EF6\uFF0C\u5176\u4E2D").concat(result.filesWithErrors, "\u4E2A\u6587\u4EF6\u5B58\u5728\u9519\u8BEF\uFF0C").concat(result.filesWithWarnings, "\u4E2A\u6587\u4EF6\u5B58\u5728\u8B66\u544A\uFF0C").concat(result.filesWithOptimizing, "\u4E2A\u6587\u4EF6\u5B58\u5728\u4F18\u5316\u5EFA\u8BAE\uFF01")
649
655
  : " ".concat(t.scanComplete(), ", scanned ").concat(result.scannedFiles, " files: ").concat(result.filesWithErrors, " with errors, ").concat(result.filesWithWarnings, " with warnings, ").concat(result.filesWithOptimizing, " with optimizing hints!");
650
- consola_1.consola.success(resultMessage);
656
+ textLogger.success(resultMessage);
651
657
  exitCode = result.filesWithErrors > 0 ? 1 : 0;
652
658
  process.exit(exitCode);
653
659
  }
@@ -31,11 +31,17 @@ var consola_1 = __importDefault(require("consola"));
31
31
  var i18n_1 = require("../i18n");
32
32
  var UNTAGGED_TAG = 'untagged';
33
33
  var DEFAULT_FORMAT = 'text';
34
+ // 文本输出统一写入 stderr,避免 stdout/stderr 混排导致顺序错乱。
35
+ var textLogger = consola_1.default.create({
36
+ stdout: process.stderr,
37
+ stderr: process.stderr,
38
+ });
39
+ textLogger.options.formatOptions = __assign(__assign({}, textLogger.options.formatOptions), { date: false });
34
40
  // 不同严重级别映射到不同日志级别。
35
41
  var severityLoggers = (_a = {},
36
- _a[auto_cr_rules_1.RuleSeverity.Error] = consola_1.default.error,
37
- _a[auto_cr_rules_1.RuleSeverity.Warning] = consola_1.default.warn,
38
- _a[auto_cr_rules_1.RuleSeverity.Optimizing] = consola_1.default.info,
42
+ _a[auto_cr_rules_1.RuleSeverity.Error] = textLogger.error,
43
+ _a[auto_cr_rules_1.RuleSeverity.Warning] = textLogger.warn,
44
+ _a[auto_cr_rules_1.RuleSeverity.Optimizing] = textLogger.info,
39
45
  _a);
40
46
  function createReporter(filePath, source, options) {
41
47
  var _a;
@@ -198,6 +204,9 @@ function renderViolations(filePath, violations, options) {
198
204
  var indent = ' ';
199
205
  var colon = language === 'zh' ? ':' : ':';
200
206
  var headerGap = language === 'zh' ? '' : ' ';
207
+ var writeLine = function (stream, line) {
208
+ stream.write("".concat(line, "\n"));
209
+ };
201
210
  (_b = options.onBeforeReport) === null || _b === void 0 ? void 0 : _b.call(options);
202
211
  violations.forEach(function (violation) {
203
212
  var timestamp = formatter.format(new Date());
@@ -206,25 +215,27 @@ function renderViolations(filePath, violations, options) {
206
215
  var logger = getLoggerForSeverity(violation.severity);
207
216
  var header = "[".concat(timestamp, "] ").concat(severityIcon, " [").concat(tagLabel, "]").concat(colon).concat(headerGap).concat(violation.ruleName);
208
217
  logger(header);
218
+ // header 与详情统一走 stderr,避免多线程混排导致输出顺序错乱。
219
+ var detailStream = process.stderr;
209
220
  var location = typeof violation.line === 'number' ? "".concat(filePath, ":").concat(violation.line) : filePath;
210
- consola_1.default.log("".concat(indent).concat(t.reporterFileLabel(), ": ").concat(location));
211
- consola_1.default.log("".concat(indent).concat(t.reporterDescriptionLabel(), ": ").concat(violation.message));
221
+ writeLine(detailStream, "".concat(indent).concat(t.reporterFileLabel(), ": ").concat(location));
222
+ writeLine(detailStream, "".concat(indent).concat(t.reporterDescriptionLabel(), ": ").concat(violation.message));
212
223
  if (violation.code) {
213
- consola_1.default.log("".concat(indent).concat(t.reporterCodeLabel(), ": ").concat(violation.code));
224
+ writeLine(detailStream, "".concat(indent).concat(t.reporterCodeLabel(), ": ").concat(violation.code));
214
225
  }
215
226
  if (violation.suggestions && violation.suggestions.length > 0) {
216
227
  var suggestionSeparator = language === 'zh' ? '; ' : ' | ';
217
228
  var suggestionLine = violation.suggestions
218
229
  .map(function (suggestion) { return t.reporterFormatSuggestion(suggestion); })
219
230
  .join(suggestionSeparator);
220
- consola_1.default.log("".concat(indent).concat(t.reporterSuggestionLabel(), ": ").concat(suggestionLine));
231
+ writeLine(detailStream, "".concat(indent).concat(t.reporterSuggestionLabel(), ": ").concat(suggestionLine));
221
232
  }
222
233
  });
223
234
  (_c = options.onAfterReport) === null || _c === void 0 ? void 0 : _c.call(options);
224
235
  }
225
236
  function getLoggerForSeverity(severity) {
226
237
  var _a;
227
- return (_a = severityLoggers[severity]) !== null && _a !== void 0 ? _a : consola_1.default.error;
238
+ return (_a = severityLoggers[severity]) !== null && _a !== void 0 ? _a : textLogger.error;
228
239
  }
229
240
  function resolveLine(record, offsets) {
230
241
  if (typeof record.line === 'number') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-cr-cmd",
3
- "version": "2.0.98",
3
+ "version": "2.0.100",
4
4
  "description": "Fast automated code review CLI powered by SWC-based static analysis",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "consola": "^3.4.2",
40
40
  "jsonc-parser": "^3.3.1",
41
41
  "picomatch": "^4.0.3",
42
- "auto-cr-rules": "2.0.98"
42
+ "auto-cr-rules": "2.0.100"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@eslint/js": "^9.39.2",