@alibaba-group/open-code-review 1.9.4 → 1.9.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.
package/bin/ocr.js CHANGED
@@ -11,6 +11,8 @@ const fs = require("fs");
11
11
  const os = require("os");
12
12
 
13
13
  const { resolveNativeBinary } = require("../scripts/platform");
14
+ const { version: packageVersion } = require("../package.json");
15
+ const { shouldShowUpdateHint } = require("../scripts/version");
14
16
 
15
17
  const resolved = resolveNativeBinary();
16
18
  if (!resolved) {
@@ -24,11 +26,13 @@ const binaryPath = resolved.path;
24
26
  const hintFile = path.join(os.homedir(), ".opencodereview", "update-available");
25
27
  try {
26
28
  const hint = JSON.parse(fs.readFileSync(hintFile, "utf8"));
27
- if (hint.version && hint.pkg) {
29
+ if (hint.pkg && shouldShowUpdateHint(hint.version, packageVersion)) {
28
30
  console.error(
29
31
  `\x1b[33m[ocr] A new version (v${hint.version}) is available. Run to update:\x1b[0m\n` +
30
32
  `\x1b[33m npm i -g ${hint.pkg}@${hint.version}\x1b[0m\n`
31
33
  );
34
+ } else {
35
+ fs.unlinkSync(hintFile);
32
36
  }
33
37
  } catch (_) {}
34
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alibaba-group/open-code-review",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "OpenCodeReview CLI — AI-powered code review tool",
5
5
  "bin": {
6
6
  "ocr": "bin/ocr.js"
@@ -9,12 +9,14 @@
9
9
  "bin/ocr.js",
10
10
  "scripts/install.js",
11
11
  "scripts/update.js",
12
+ "scripts/version.js",
12
13
  "scripts/platform.js",
13
14
  "imgs/"
14
15
  ],
15
16
  "scripts": {
16
17
  "postinstall": "node scripts/install.js",
17
- "test:github-actions": "node scripts/github-actions/post-review-comments.test.js && node scripts/github-actions/check-translation-sync.test.js"
18
+ "test:github-actions": "node scripts/github-actions/post-review-comments.test.js && node scripts/github-actions/check-translation-sync.test.js",
19
+ "test:update": "node scripts/version.test.js"
18
20
  },
19
21
  "repository": {
20
22
  "type": "git",
@@ -28,12 +30,12 @@
28
30
  "checksumPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/sha256sum.txt"
29
31
  },
30
32
  "optionalDependencies": {
31
- "@alibaba-group/ocr-darwin-arm64": "1.9.4",
32
- "@alibaba-group/ocr-darwin-x64": "1.9.4",
33
- "@alibaba-group/ocr-linux-arm64": "1.9.4",
34
- "@alibaba-group/ocr-linux-x64": "1.9.4",
35
- "@alibaba-group/ocr-win32-arm64": "1.9.4",
36
- "@alibaba-group/ocr-win32-x64": "1.9.4"
33
+ "@alibaba-group/ocr-darwin-arm64": "1.9.6",
34
+ "@alibaba-group/ocr-darwin-x64": "1.9.6",
35
+ "@alibaba-group/ocr-linux-arm64": "1.9.6",
36
+ "@alibaba-group/ocr-linux-x64": "1.9.6",
37
+ "@alibaba-group/ocr-win32-arm64": "1.9.6",
38
+ "@alibaba-group/ocr-win32-x64": "1.9.6"
37
39
  },
38
40
  "engines": {
39
41
  "node": ">=14"
package/scripts/update.js CHANGED
@@ -13,6 +13,7 @@ const { spawnSync } = require("child_process");
13
13
 
14
14
  const { resolveNativeBinary } = require("./platform");
15
15
  const { loadPackageJson } = require("./install.js");
16
+ const { SEMVER_RE, parseVersionOutput, semverGt } = require("./version");
16
17
 
17
18
  const stateDir = path.join(os.homedir(), ".opencodereview");
18
19
  const tsFile = path.join(stateDir, "last-update-check");
@@ -66,8 +67,7 @@ function getInstalledVersion(binPath) {
66
67
  encoding: "utf8",
67
68
  timeout: 3000,
68
69
  });
69
- const match = (result.stdout || "").match(/v(\d+\.\d+(?:\.\d+)?)/);
70
- return match ? match[1] : null;
70
+ return parseVersionOutput(result.stdout);
71
71
  } catch (_) {
72
72
  return null;
73
73
  }
@@ -113,21 +113,6 @@ function fetchLatestVersion(pkg) {
113
113
  });
114
114
  }
115
115
 
116
- const SEMVER_RE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
117
-
118
- function semverGt(a, b) {
119
- const pa = a.replace(/-.*$/, "").split(".").map(Number);
120
- const pb = b.replace(/-.*$/, "").split(".").map(Number);
121
- for (let i = 0; i < 3; i++) {
122
- if ((pa[i] || 0) > (pb[i] || 0)) return true;
123
- if ((pa[i] || 0) < (pb[i] || 0)) return false;
124
- }
125
- const aPre = a.includes("-");
126
- const bPre = b.includes("-");
127
- if (bPre && !aPre) return true;
128
- return false;
129
- }
130
-
131
116
  function writeHint(latestVersion, pkgName) {
132
117
  try {
133
118
  fs.writeFileSync(hintFile, JSON.stringify({ version: latestVersion, pkg: pkgName }));
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 alibaba/open-code-review Contributors
3
+
4
+ "use strict";
5
+
6
+ const SEMVER_RE =
7
+ /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
8
+
9
+ function parseVersionOutput(output) {
10
+ const match = String(output || "").match(
11
+ /v(\d+\.\d+(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)/
12
+ );
13
+ return match ? match[1] : null;
14
+ }
15
+
16
+ function semverGt(a, b) {
17
+ if (!SEMVER_RE.test(a) || !SEMVER_RE.test(b)) return false;
18
+
19
+ const aWithoutBuild = a.replace(/\+.*$/, "");
20
+ const bWithoutBuild = b.replace(/\+.*$/, "");
21
+ const pa = aWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
22
+ const pb = bWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
23
+ for (let i = 0; i < 3; i++) {
24
+ if (pa[i] > pb[i]) return true;
25
+ if (pa[i] < pb[i]) return false;
26
+ }
27
+ const aPre = aWithoutBuild.includes("-");
28
+ const bPre = bWithoutBuild.includes("-");
29
+ if (bPre && !aPre) return true;
30
+ return false;
31
+ }
32
+
33
+ function shouldShowUpdateHint(hintVersion, installedVersion) {
34
+ if (!SEMVER_RE.test(hintVersion) || !SEMVER_RE.test(installedVersion)) {
35
+ return false;
36
+ }
37
+ return semverGt(hintVersion, installedVersion);
38
+ }
39
+
40
+ module.exports = {
41
+ SEMVER_RE,
42
+ parseVersionOutput,
43
+ semverGt,
44
+ shouldShowUpdateHint,
45
+ };