@alibaba-group/open-code-review 1.11.5 → 1.11.6

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 (2) hide show
  1. package/bin/ocr.js +60 -4
  2. package/package.json +7 -7
package/bin/ocr.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { spawnSync, spawn } = require("child_process");
8
+ const { spawn } = require("child_process");
9
9
  const path = require("path");
10
10
  const fs = require("fs");
11
11
  const os = require("os");
@@ -25,7 +25,39 @@ function launcherExitCode(result) {
25
25
  return result.status ?? (result.error ? 1 : 0);
26
26
  }
27
27
 
28
- module.exports = { launcherExitCode };
28
+ // Returns a signal handler that forwards the signal to a child process.
29
+ function forwardSignal(child, signal) {
30
+ return () => {
31
+ child.kill(signal);
32
+ };
33
+ }
34
+
35
+ function installSignalHandlers(child, platform, signalTarget) {
36
+ const handlers = [];
37
+ function add(signal, handler) {
38
+ handlers.push([signal, handler]);
39
+ signalTarget.on(signal, handler);
40
+ }
41
+
42
+ // Windows sends console Ctrl+C to both attached processes. Keep the wrapper
43
+ // alive so it can wait for the binary, but do not call child.kill("SIGINT"):
44
+ // Node maps that operation to an abrupt TerminateProcess call on Windows.
45
+ if (platform === "win32") {
46
+ add("SIGINT", () => {});
47
+ } else {
48
+ for (const signal of ["SIGINT", "SIGTERM"]) {
49
+ add(signal, forwardSignal(child, signal));
50
+ }
51
+ }
52
+
53
+ return () => {
54
+ for (const [signal, handler] of handlers) {
55
+ signalTarget.removeListener(signal, handler);
56
+ }
57
+ };
58
+ }
59
+
60
+ module.exports = { launcherExitCode, forwardSignal, installSignalHandlers };
29
61
 
30
62
  if (require.main !== module) {
31
63
  // Required as a module (tests); the launcher body below must not run.
@@ -77,9 +109,33 @@ if (!process.env.OCR_NO_UPDATE) {
77
109
  }
78
110
  }
79
111
 
80
- const result = spawnSync(binaryPath, process.argv.slice(2), {
112
+ const child = spawn(binaryPath, process.argv.slice(2), {
81
113
  stdio: "inherit",
82
114
  env: process.env,
83
115
  });
84
116
 
85
- process.exit(launcherExitCode(result));
117
+ const removeSignalHandlers = installSignalHandlers(
118
+ child,
119
+ process.platform,
120
+ process
121
+ );
122
+
123
+ let settled = false;
124
+ function settle(result) {
125
+ if (settled) return;
126
+ settled = true;
127
+ removeSignalHandlers();
128
+ process.exitCode = launcherExitCode(result);
129
+ }
130
+
131
+ // Spawn failures surface through "error", not "close" alone. Setting
132
+ // exitCode lets a piped diagnostic drain before the wrapper terminates.
133
+ child.on("error", (err) => {
134
+ console.error(`[ERROR] Failed to start ${binaryPath}: ${err.message}`);
135
+ settle({ error: err });
136
+ });
137
+
138
+ // Wait for child to exit and propagate its exit status
139
+ child.on("close", (code, signal) => {
140
+ settle({ status: code, signal: signal });
141
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alibaba-group/open-code-review",
3
- "version": "1.11.5",
3
+ "version": "1.11.6",
4
4
  "description": "OpenCodeReview CLI — AI-powered code review tool",
5
5
  "bin": {
6
6
  "ocr": "bin/ocr.js"
@@ -31,12 +31,12 @@
31
31
  "checksumPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/sha256sum.txt"
32
32
  },
33
33
  "optionalDependencies": {
34
- "@alibaba-group/ocr-darwin-arm64": "1.11.5",
35
- "@alibaba-group/ocr-darwin-x64": "1.11.5",
36
- "@alibaba-group/ocr-linux-arm64": "1.11.5",
37
- "@alibaba-group/ocr-linux-x64": "1.11.5",
38
- "@alibaba-group/ocr-win32-arm64": "1.11.5",
39
- "@alibaba-group/ocr-win32-x64": "1.11.5"
34
+ "@alibaba-group/ocr-darwin-arm64": "1.11.6",
35
+ "@alibaba-group/ocr-darwin-x64": "1.11.6",
36
+ "@alibaba-group/ocr-linux-arm64": "1.11.6",
37
+ "@alibaba-group/ocr-linux-x64": "1.11.6",
38
+ "@alibaba-group/ocr-win32-arm64": "1.11.6",
39
+ "@alibaba-group/ocr-win32-x64": "1.11.6"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14"