auto-cr-cmd 2.0.57 → 2.0.60

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
@@ -70,6 +70,7 @@ var config_1 = require("./config");
70
70
  var report_1 = require("./report");
71
71
  var i18n_1 = require("./i18n");
72
72
  var file_1 = require("./utils/file");
73
+ var stdin_1 = require("./utils/stdin");
73
74
  var auto_cr_rules_1 = require("auto-cr-rules");
74
75
  var loader_1 = require("./rules/loader");
75
76
  consola_1.consola.options.formatOptions = __assign(__assign({}, consola_1.consola.options.formatOptions), { date: false });
@@ -463,9 +464,10 @@ commander_1.program
463
464
  .option('-r, --rule-dir <directory>', '自定义规则目录路径 / Custom rule directory')
464
465
  .option('-l, --language <language>', '设置 CLI 语言 (zh/en) / Set CLI language (zh/en)')
465
466
  .option('-o, --output <format>', '设置输出格式 (text/json) / Output format (text/json)', 'text')
467
+ .option('--stdin', '从标准输入读取扫描路径 / Read file paths from STDIN')
466
468
  .parse(process.argv);
467
469
  var options = commander_1.program.opts();
468
- var filePaths = commander_1.program.args.map(function (target) { return path_1.default.resolve(process.cwd(), target); });
470
+ var cliArguments = commander_1.program.args;
469
471
  (0, i18n_1.setLanguage)((_a = options.language) !== null && _a !== void 0 ? _a : process.env.LANG);
470
472
  var outputFormat;
471
473
  try {
@@ -478,13 +480,18 @@ catch (error) {
478
480
  }
479
481
  ;
480
482
  (function () { return __awaiter(void 0, void 0, void 0, function () {
481
- var result, t, payload, exitCode, language, resultMessage, exitCode, error_3, t, detail, payload;
483
+ var stdinTargets, combinedTargets, filePaths, result, t, payload, exitCode, language, resultMessage, exitCode, error_3, t, detail, payload;
482
484
  return __generator(this, function (_a) {
483
485
  switch (_a.label) {
484
486
  case 0:
485
- _a.trys.push([0, 2, , 3]);
486
- return [4 /*yield*/, run(filePaths, options.ruleDir, outputFormat)];
487
+ _a.trys.push([0, 3, , 4]);
488
+ return [4 /*yield*/, (0, stdin_1.readPathsFromStdin)(Boolean(options.stdin))];
487
489
  case 1:
490
+ stdinTargets = _a.sent();
491
+ combinedTargets = __spreadArray(__spreadArray([], cliArguments, true), stdinTargets, true);
492
+ filePaths = combinedTargets.map(function (target) { return path_1.default.resolve(process.cwd(), target); });
493
+ return [4 /*yield*/, run(filePaths, options.ruleDir, outputFormat)];
494
+ case 2:
488
495
  result = _a.sent();
489
496
  t = (0, i18n_1.getTranslator)();
490
497
  if (outputFormat === 'json') {
@@ -506,8 +513,8 @@ catch (error) {
506
513
  else {
507
514
  process.exit(0);
508
515
  }
509
- return [3 /*break*/, 3];
510
- case 2:
516
+ return [3 /*break*/, 4];
517
+ case 3:
511
518
  error_3 = _a.sent();
512
519
  t = (0, i18n_1.getTranslator)();
513
520
  detail = error_3 instanceof Error ? error_3.message : String(error_3);
@@ -524,8 +531,8 @@ catch (error) {
524
531
  consola_1.consola.error(t.scanError(), detail);
525
532
  }
526
533
  process.exit(1);
527
- return [3 /*break*/, 3];
528
- case 3: return [2 /*return*/];
534
+ return [3 /*break*/, 4];
535
+ case 4: return [2 /*return*/];
529
536
  }
530
537
  });
531
538
  }); })();
@@ -0,0 +1 @@
1
+ export declare function readPathsFromStdin(shouldForceRead: boolean): Promise<string[]>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.readPathsFromStdin = readPathsFromStdin;
40
+ function readPathsFromStdin(shouldForceRead) {
41
+ return __awaiter(this, void 0, void 0, function () {
42
+ var shouldRead;
43
+ return __generator(this, function (_a) {
44
+ shouldRead = shouldForceRead || !process.stdin.isTTY;
45
+ if (!shouldRead) {
46
+ return [2 /*return*/, []];
47
+ }
48
+ return [2 /*return*/, new Promise(function (resolve, reject) {
49
+ var chunks = [];
50
+ var settled = false;
51
+ var finish = function (result) {
52
+ if (settled)
53
+ return;
54
+ settled = true;
55
+ resolve(result);
56
+ };
57
+ var fail = function (error) {
58
+ if (settled)
59
+ return;
60
+ settled = true;
61
+ reject(error);
62
+ };
63
+ process.stdin.on('data', function (chunk) {
64
+ chunks.push(chunk);
65
+ });
66
+ process.stdin.on('error', function (error) {
67
+ fail(error);
68
+ });
69
+ process.stdin.on('end', function () {
70
+ try {
71
+ if (chunks.length === 0) {
72
+ return finish([]);
73
+ }
74
+ var buf = Buffer.concat(chunks);
75
+ if (buf.length === 0) {
76
+ return finish([]);
77
+ }
78
+ // Prefer NUL-delimited when present; else fall back to newline.
79
+ var hasNul = buf.includes(0); // 0x00
80
+ var payload = buf.toString('utf8');
81
+ var parts = hasNul ? payload.split('\0') : payload.split(/\r?\n/);
82
+ // Preserve spaces in filenames; only strip stray CR and drop empties.
83
+ var lines = parts
84
+ .map(function (s) { return (s.endsWith('\r') ? s.slice(0, -1) : s); })
85
+ .filter(function (s) { return s.length > 0; });
86
+ finish(lines);
87
+ }
88
+ catch (err) {
89
+ fail(err);
90
+ }
91
+ });
92
+ process.stdin.on('close', function () {
93
+ if (!settled) {
94
+ finish([]);
95
+ }
96
+ });
97
+ if (process.stdin.isTTY) {
98
+ process.stdin.resume();
99
+ }
100
+ })];
101
+ });
102
+ });
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-cr-cmd",
3
- "version": "2.0.57",
3
+ "version": "2.0.60",
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",
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@swc/core": "^1.13.20",
49
49
  "@swc/wasm": "^1.13.20",
50
- "auto-cr-rules": "^2.0.57",
50
+ "auto-cr-rules": "^2.0.60",
51
51
  "commander": "^14.0.0",
52
52
  "consola": "^3.4.2"
53
53
  },