@alibaba-group/open-code-review 1.0.6 → 1.0.9

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/package.json +2 -2
  2. package/scripts/update.js +16 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alibaba-group/open-code-review",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
4
4
  "description": "OpenCodeReview CLI — AI-powered code review tool",
5
5
  "bin": {
6
6
  "ocr": "bin/ocr.js"
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "ocrConfig": {
21
- "urlPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/opencodereview-v{version}-{os}-{arch}",
21
+ "urlPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/opencodereview-{os}-{arch}",
22
22
  "checksumPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/sha256sum.txt"
23
23
  },
24
24
  "engines": {
package/scripts/update.js CHANGED
@@ -4,6 +4,7 @@
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const os = require("os");
7
+ const http = require("http");
7
8
  const https = require("https");
8
9
  const { spawnSync } = require("child_process");
9
10
 
@@ -23,8 +24,7 @@ const stateDir = path.join(os.homedir(), ".open-code-review");
23
24
  const tsFile = path.join(stateDir, "last-update-check");
24
25
  const lockFile = path.join(stateDir, "update.lock");
25
26
 
26
- const GITHUB_API_URL =
27
- "https://api.github.com/repos/alibaba/open-code-review/releases/latest";
27
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
28
28
 
29
29
  function touchTimestamp() {
30
30
  fs.mkdirSync(stateDir, { recursive: true });
@@ -78,17 +78,21 @@ function getInstalledVersion() {
78
78
  }
79
79
  }
80
80
 
81
- function fetchLatestVersion() {
81
+ function fetchLatestVersion(pkg) {
82
+ const registry = (pkg.publishConfig && pkg.publishConfig.registry) || DEFAULT_REGISTRY;
83
+ const pkgName = pkg.name;
84
+ if (!pkgName) return Promise.resolve(null);
85
+ const encodedName = pkgName.replace(/\//g, "%2F");
86
+ const url = `${registry.replace(/\/$/, "")}/${encodedName}/latest`;
87
+ const client = url.startsWith("https") ? https : http;
88
+
82
89
  return new Promise((resolve) => {
83
90
  const options = {
84
- headers: {
85
- "User-Agent": "ocr-updater",
86
- Accept: "application/vnd.github.v3+json",
87
- },
91
+ headers: { "User-Agent": "ocr-updater", Accept: "application/json" },
88
92
  timeout: 15000,
89
93
  };
90
- const req = https
91
- .get(GITHUB_API_URL, options, (res) => {
94
+ const req = client
95
+ .get(url, options, (res) => {
92
96
  if (res.statusCode !== 200) {
93
97
  res.resume();
94
98
  resolve(null);
@@ -99,9 +103,7 @@ function fetchLatestVersion() {
99
103
  res.on("end", () => {
100
104
  try {
101
105
  const json = JSON.parse(data);
102
- const tag = json.tag_name || "";
103
- const version = tag.startsWith("v") ? tag.slice(1) : tag;
104
- resolve(version || null);
106
+ resolve(json.version || null);
105
107
  } catch (_) {
106
108
  resolve(null);
107
109
  }
@@ -148,13 +150,13 @@ async function main() {
148
150
  const installedVersion = getInstalledVersion();
149
151
  if (!installedVersion) return;
150
152
 
151
- const latestVersion = await fetchLatestVersion();
153
+ const pkg = loadPackageJson();
154
+ const latestVersion = await fetchLatestVersion(pkg);
152
155
  if (!latestVersion) return;
153
156
 
154
157
  if (!semverGt(latestVersion, installedVersion)) return;
155
158
 
156
159
  const { os: platform, arch } = detectPlatform();
157
- const pkg = loadPackageJson();
158
160
  const config = pkg.ocrConfig;
159
161
 
160
162
  const vars = { version: latestVersion, os: platform, arch };