dsh-agent-sdk-bridge 1.3.2 → 1.3.4
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/client.js +8 -6
- package/lib/index.js +47 -5
- package/lib/types/setup.d.ts +11 -0
- package/package.json +1 -1
- package/scripts/setup-qodercli.bat +17 -11
- package/scripts/setup-qoderclicn.bat +17 -11
- package/src/minimax-cli.ts +26 -5
- package/src/setup.ts +38 -3
package/client.js
CHANGED
|
@@ -95,8 +95,8 @@ window.__ModuleLoader__.load({
|
|
|
95
95
|
cliLogoutConfirm: '确定要退出当前 Qoder 账号吗?退出后会关闭已打开的会话并清空额度,需要重新登录才能继续使用;CLI 本身不会被卸载。',
|
|
96
96
|
cliLoggingOut: '正在退出登录…',
|
|
97
97
|
cliLogoutOk: '已退出登录',
|
|
98
|
-
cliVersionMismatch: 'CLI
|
|
99
|
-
cliVersionMismatchTail: '
|
|
98
|
+
cliVersionMismatch: 'CLI 版本过旧:本机',
|
|
99
|
+
cliVersionMismatchTail: ',插件至少需要',
|
|
100
100
|
intlNav: 'Qoder 国际版',
|
|
101
101
|
intlTitle: 'Qoder 国际版',
|
|
102
102
|
intlIntro: '国际版账户(qoder.com)的模型与额度。勾选要启用的模型,并为需要的模型指定上下文窗口。改动即时生效,无需重启。',
|
|
@@ -298,8 +298,8 @@ window.__ModuleLoader__.load({
|
|
|
298
298
|
cliLogoutConfirm: 'Sign out of the current Qoder account? Open sessions will be closed and quota cleared; you will need to sign in again. The CLI itself stays installed.',
|
|
299
299
|
cliLoggingOut: 'Signing out…',
|
|
300
300
|
cliLogoutOk: 'Signed out',
|
|
301
|
-
cliVersionMismatch: 'CLI
|
|
302
|
-
cliVersionMismatchTail: 'but the plugin needs',
|
|
301
|
+
cliVersionMismatch: 'CLI too old: this machine has',
|
|
302
|
+
cliVersionMismatchTail: 'but the plugin needs at least',
|
|
303
303
|
intlNav: 'Qoder International',
|
|
304
304
|
intlTitle: 'Qoder International',
|
|
305
305
|
intlIntro: 'Models and quota for the international account (qoder.com). Tick the models you want available and set a context window where needed. Changes apply immediately.',
|
|
@@ -2431,8 +2431,10 @@ window.__ModuleLoader__.load({
|
|
|
2431
2431
|
brand.kind !== 'qoder' ? null : h('div', { style: css.group },
|
|
2432
2432
|
h('h3', { style: css.h3 }, t(brand.cliGroupKey)),
|
|
2433
2433
|
h('div', { style: css.note }, t(brand.cliHintKey)),
|
|
2434
|
-
//
|
|
2435
|
-
//
|
|
2434
|
+
// The CLI moves on its own (`qodercli update`), so only a build older
|
|
2435
|
+
// than the SDK's pin is reported: that is the one that fails every
|
|
2436
|
+
// session with a bare exit code. A newer build is fine and follows
|
|
2437
|
+
// upstream as the user expects.
|
|
2436
2438
|
setup?.versionMismatch === true
|
|
2437
2439
|
? h('div', { style: { ...css.err, marginTop: '6px' } },
|
|
2438
2440
|
`${t('cliVersionMismatch')} ${setup.cliVersion ?? '?'} ${t('cliVersionMismatchTail')} ${setup.requiredCliVersion ?? '?'}`)
|
package/lib/index.js
CHANGED
|
@@ -6135,9 +6135,28 @@ const INSTALL_FLAGS = [
|
|
|
6135
6135
|
"https://registry.npmjs.org/",
|
|
6136
6136
|
"--foreground-scripts"
|
|
6137
6137
|
];
|
|
6138
|
-
|
|
6138
|
+
/**
|
|
6139
|
+
* The Node interpreter that can load the CLI's native SQLite module.
|
|
6140
|
+
*
|
|
6141
|
+
* `@minimax-ai/code` is installed globally by npm, so its `better-sqlite3`
|
|
6142
|
+
* build matches the Node npm used — the `node` on PATH. DSH's desktop host
|
|
6143
|
+
* runs Electron, whose NODE_MODULE_VERSION differs; spawning `process.execPath`
|
|
6144
|
+
* there makes `mcode acp` die before the ACP handshake ("ACP connection
|
|
6145
|
+
* closed"). Prefer the npm shim's sibling node.exe when present, otherwise
|
|
6146
|
+
* resolve `node` from PATH.
|
|
6147
|
+
*/
|
|
6148
|
+
function cliNodeCommand(shimDir) {
|
|
6149
|
+
if (process.versions.electron === void 0) return process.execPath;
|
|
6150
|
+
if (shimDir !== void 0) {
|
|
6151
|
+
const exe = process.platform === "win32" ? "node.exe" : "node";
|
|
6152
|
+
const local = join(shimDir, exe);
|
|
6153
|
+
if (existsSync(local)) return local;
|
|
6154
|
+
}
|
|
6155
|
+
return "node";
|
|
6156
|
+
}
|
|
6157
|
+
function fromJsEntry(path, nodeCommand = cliNodeCommand()) {
|
|
6139
6158
|
return {
|
|
6140
|
-
command:
|
|
6159
|
+
command: nodeCommand,
|
|
6141
6160
|
args: [path],
|
|
6142
6161
|
cliPath: path
|
|
6143
6162
|
};
|
|
@@ -6147,10 +6166,10 @@ function fromShim(shim) {
|
|
|
6147
6166
|
try {
|
|
6148
6167
|
const text = readFileSync(shim, "utf8");
|
|
6149
6168
|
const match = /["']([^"']*node_modules[\\/]@minimax-ai[\\/]code[\\/]cli\.js)["']/.exec(text);
|
|
6150
|
-
if (match !== null && existsSync(match[1])) return fromJsEntry(match[1]);
|
|
6169
|
+
if (match !== null && existsSync(match[1])) return fromJsEntry(match[1], cliNodeCommand(dirname(shim)));
|
|
6151
6170
|
} catch {}
|
|
6152
6171
|
const sibling = join(dirname(shim), "node_modules", "@minimax-ai", "code", "cli.js");
|
|
6153
|
-
if (existsSync(sibling)) return fromJsEntry(sibling);
|
|
6172
|
+
if (existsSync(sibling)) return fromJsEntry(sibling, cliNodeCommand(dirname(shim)));
|
|
6154
6173
|
return {
|
|
6155
6174
|
command: process.env.ComSpec ?? "cmd.exe",
|
|
6156
6175
|
args: [
|
|
@@ -9117,7 +9136,7 @@ function readSetupStatus(brand = "cn") {
|
|
|
9117
9136
|
installed,
|
|
9118
9137
|
...cliVersion === void 0 ? {} : { cliVersion },
|
|
9119
9138
|
...required === void 0 ? {} : { requiredCliVersion: required },
|
|
9120
|
-
...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: cliVersion
|
|
9139
|
+
...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: compareVersions(cliVersion, required) < 0 }
|
|
9121
9140
|
};
|
|
9122
9141
|
const run = current.get(brand);
|
|
9123
9142
|
if (run === void 0) return {
|
|
@@ -9165,6 +9184,29 @@ function cancelSetup(brand) {
|
|
|
9165
9184
|
return true;
|
|
9166
9185
|
}
|
|
9167
9186
|
/**
|
|
9187
|
+
* Compare two dotted versions, numerically per segment.
|
|
9188
|
+
*
|
|
9189
|
+
* A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
|
|
9190
|
+
* backwards for the decision this feeds.
|
|
9191
|
+
*
|
|
9192
|
+
* @param left - one version, e.g. `1.1.84`.
|
|
9193
|
+
* @param right - the other, e.g. `1.1.81`.
|
|
9194
|
+
* @returns negative when `left` is older, positive when newer, 0 when equal.
|
|
9195
|
+
*/
|
|
9196
|
+
function compareVersions(left, right) {
|
|
9197
|
+
const parse = (value) => value.split(/[.-]/).map((part) => {
|
|
9198
|
+
const n = Number.parseInt(part, 10);
|
|
9199
|
+
return Number.isFinite(n) ? n : 0;
|
|
9200
|
+
});
|
|
9201
|
+
const a = parse(left);
|
|
9202
|
+
const b = parse(right);
|
|
9203
|
+
for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
|
|
9204
|
+
const diff = (a[i] ?? 0) - (b[i] ?? 0);
|
|
9205
|
+
if (diff !== 0) return diff < 0 ? -1 : 1;
|
|
9206
|
+
}
|
|
9207
|
+
return 0;
|
|
9208
|
+
}
|
|
9209
|
+
/**
|
|
9168
9210
|
* Abandon the running helper, if any.
|
|
9169
9211
|
*
|
|
9170
9212
|
* Called when the plugin is disposed. Killing `cmd.exe` does not reap the CLI it
|
package/lib/types/setup.d.ts
CHANGED
|
@@ -102,6 +102,17 @@ export declare function readSetupStatus(brand?: QoderBrand): SetupStatus;
|
|
|
102
102
|
* @returns whether a run was actually in flight.
|
|
103
103
|
*/
|
|
104
104
|
export declare function cancelSetup(brand: QoderBrand): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Compare two dotted versions, numerically per segment.
|
|
107
|
+
*
|
|
108
|
+
* A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
|
|
109
|
+
* backwards for the decision this feeds.
|
|
110
|
+
*
|
|
111
|
+
* @param left - one version, e.g. `1.1.84`.
|
|
112
|
+
* @param right - the other, e.g. `1.1.81`.
|
|
113
|
+
* @returns negative when `left` is older, positive when newer, 0 when equal.
|
|
114
|
+
*/
|
|
115
|
+
export declare function compareVersions(left: string, right: string): number;
|
|
105
116
|
/**
|
|
106
117
|
* Abandon the running helper, if any.
|
|
107
118
|
*
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-agent-sdk-bridge",
|
|
3
3
|
"displayName": "Agent SDK Bridge",
|
|
4
4
|
"description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
|
|
5
|
-
"version": "1.3.
|
|
5
|
+
"version": "1.3.4",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "k1-h2",
|
|
@@ -79,17 +79,24 @@ if defined CLIV (
|
|
|
79
79
|
echo [--] qodercli not found
|
|
80
80
|
)
|
|
81
81
|
|
|
82
|
-
rem The SDK speaks a wire protocol
|
|
83
|
-
rem 1.1.81 dropped the old SDK session
|
|
84
|
-
rem
|
|
85
|
-
rem
|
|
86
|
-
rem
|
|
82
|
+
rem The SDK speaks a wire protocol pinned to one CLI release, and only a build
|
|
83
|
+
rem OLDER than that pin is a problem: CLI 1.1.81 dropped the old SDK session
|
|
84
|
+
rem handshake and exits 42 on it. A newer build that still speaks the protocol
|
|
85
|
+
rem is fine (1.1.84 runs against the SDK pinned at 1.1.81), and the CLI updates
|
|
86
|
+
rem itself, so this helper installs the pinned build only when what is present
|
|
87
|
+
rem is older. It never downgrades a version the user has moved forward.
|
|
87
88
|
set "WANTV="
|
|
88
89
|
set "MANIFEST=%~dp0..\node_modules\@qoder-ai\qoder-agent-sdk\dist\runtime-manifest.json"
|
|
89
90
|
if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
|
|
90
91
|
set "PKGSPEC=%PKG%"
|
|
91
92
|
if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
|
|
92
|
-
if defined WANTV echo [--] this plugin
|
|
93
|
+
if defined WANTV echo [--] this plugin was tested with CLI !WANTV!
|
|
94
|
+
|
|
95
|
+
rem OUTDATED=1 only when a required version exists and the installed one is
|
|
96
|
+
rem numerically older. `node -e` does the comparing because cmd compares
|
|
97
|
+
rem strings, where "1.1.9" ranks above "1.1.10".
|
|
98
|
+
set "OUTDATED="
|
|
99
|
+
if defined WANTV if defined CLIV for /f "usebackq delims=" %%R in (`node -e "const a=process.argv[1].split('.').map(Number),b=process.argv[2].split('.').map(Number);let r=0;for(let i=0;i<Math.max(a.length,b.length);i++){const d=(a[i]||0)-(b[i]||0);if(d){r=d^<0?-1:1;break}}process.stdout.write(r^<0?'1':'')" "!CLIV!" "!WANTV!"`) do set "OUTDATED=%%R"
|
|
93
100
|
|
|
94
101
|
rem ------------------------------------------------------------- 3 install
|
|
95
102
|
echo.
|
|
@@ -100,8 +107,8 @@ if not "%MODE%"=="setup" (
|
|
|
100
107
|
echo Run this script without an argument to install it.
|
|
101
108
|
goto :fail
|
|
102
109
|
)
|
|
103
|
-
if defined
|
|
104
|
-
echo [X] installed !CLIV!, but this plugin needs !WANTV
|
|
110
|
+
if defined OUTDATED (
|
|
111
|
+
echo [X] installed !CLIV!, but this plugin needs !WANTV! or newer.
|
|
105
112
|
echo Run this script without an argument to install it.
|
|
106
113
|
goto :fail
|
|
107
114
|
)
|
|
@@ -109,9 +116,8 @@ if not "%MODE%"=="setup" (
|
|
|
109
116
|
goto :login
|
|
110
117
|
)
|
|
111
118
|
if defined QCMD (
|
|
112
|
-
if not defined
|
|
113
|
-
|
|
114
|
-
echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
|
|
119
|
+
if not defined OUTDATED goto :skipinstall
|
|
120
|
+
echo [--] installed !CLIV! is older than !WANTV! - reinstalling
|
|
115
121
|
goto :doinstall
|
|
116
122
|
)
|
|
117
123
|
:skipinstall
|
|
@@ -79,17 +79,24 @@ if defined CLIV (
|
|
|
79
79
|
echo [--] qoderclicn not found
|
|
80
80
|
)
|
|
81
81
|
|
|
82
|
-
rem The SDK speaks a wire protocol
|
|
83
|
-
rem 1.1.81 dropped the old SDK session
|
|
84
|
-
rem
|
|
85
|
-
rem
|
|
86
|
-
rem
|
|
82
|
+
rem The SDK speaks a wire protocol pinned to one CLI release, and only a build
|
|
83
|
+
rem OLDER than that pin is a problem: CLI 1.1.81 dropped the old SDK session
|
|
84
|
+
rem handshake and exits 42 on it. A newer build that still speaks the protocol
|
|
85
|
+
rem is fine (1.1.84 runs against the SDK pinned at 1.1.81), and the CLI updates
|
|
86
|
+
rem itself, so this helper installs the pinned build only when what is present
|
|
87
|
+
rem is older. It never downgrades a version the user has moved forward.
|
|
87
88
|
set "WANTV="
|
|
88
89
|
set "MANIFEST=%~dp0..\node_modules\@qodercn-ai\qodercn-agent-sdk\dist\runtime-manifest.json"
|
|
89
90
|
if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
|
|
90
91
|
set "PKGSPEC=%PKG%"
|
|
91
92
|
if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
|
|
92
|
-
if defined WANTV echo [--] this plugin
|
|
93
|
+
if defined WANTV echo [--] this plugin was tested with CLI !WANTV!
|
|
94
|
+
|
|
95
|
+
rem OUTDATED=1 only when a required version exists and the installed one is
|
|
96
|
+
rem numerically older. `node -e` does the comparing because cmd compares
|
|
97
|
+
rem strings, where "1.1.9" ranks above "1.1.10".
|
|
98
|
+
set "OUTDATED="
|
|
99
|
+
if defined WANTV if defined CLIV for /f "usebackq delims=" %%R in (`node -e "const a=process.argv[1].split('.').map(Number),b=process.argv[2].split('.').map(Number);let r=0;for(let i=0;i<Math.max(a.length,b.length);i++){const d=(a[i]||0)-(b[i]||0);if(d){r=d^<0?-1:1;break}}process.stdout.write(r^<0?'1':'')" "!CLIV!" "!WANTV!"`) do set "OUTDATED=%%R"
|
|
93
100
|
|
|
94
101
|
rem ------------------------------------------------------------- 3 install
|
|
95
102
|
echo.
|
|
@@ -100,8 +107,8 @@ if not "%MODE%"=="setup" (
|
|
|
100
107
|
echo Run this script without an argument to install it.
|
|
101
108
|
goto :fail
|
|
102
109
|
)
|
|
103
|
-
if defined
|
|
104
|
-
echo [X] installed !CLIV!, but this plugin needs !WANTV
|
|
110
|
+
if defined OUTDATED (
|
|
111
|
+
echo [X] installed !CLIV!, but this plugin needs !WANTV! or newer.
|
|
105
112
|
echo Run this script without an argument to install it.
|
|
106
113
|
goto :fail
|
|
107
114
|
)
|
|
@@ -109,9 +116,8 @@ if not "%MODE%"=="setup" (
|
|
|
109
116
|
goto :login
|
|
110
117
|
)
|
|
111
118
|
if defined QCMD (
|
|
112
|
-
if not defined
|
|
113
|
-
|
|
114
|
-
echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
|
|
119
|
+
if not defined OUTDATED goto :skipinstall
|
|
120
|
+
echo [--] installed !CLIV! is older than !WANTV! - reinstalling
|
|
115
121
|
goto :doinstall
|
|
116
122
|
)
|
|
117
123
|
:skipinstall
|
package/src/minimax-cli.ts
CHANGED
|
@@ -35,23 +35,44 @@ const INSTALL_FLAGS = [
|
|
|
35
35
|
'--foreground-scripts',
|
|
36
36
|
]
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The Node interpreter that can load the CLI's native SQLite module.
|
|
40
|
+
*
|
|
41
|
+
* `@minimax-ai/code` is installed globally by npm, so its `better-sqlite3`
|
|
42
|
+
* build matches the Node npm used — the `node` on PATH. DSH's desktop host
|
|
43
|
+
* runs Electron, whose NODE_MODULE_VERSION differs; spawning `process.execPath`
|
|
44
|
+
* there makes `mcode acp` die before the ACP handshake ("ACP connection
|
|
45
|
+
* closed"). Prefer the npm shim's sibling node.exe when present, otherwise
|
|
46
|
+
* resolve `node` from PATH.
|
|
47
|
+
*/
|
|
48
|
+
function cliNodeCommand(shimDir?: string): string {
|
|
49
|
+
if (process.versions.electron === undefined) return process.execPath
|
|
50
|
+
if (shimDir !== undefined) {
|
|
51
|
+
const exe = process.platform === 'win32' ? 'node.exe' : 'node'
|
|
52
|
+
const local = join(shimDir, exe)
|
|
53
|
+
if (existsSync(local)) return local
|
|
54
|
+
}
|
|
55
|
+
return 'node'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fromJsEntry(path: string, nodeCommand: string = cliNodeCommand()): MinimaxCliSpec {
|
|
59
|
+
return { command: nodeCommand, args: [path], cliPath: path }
|
|
40
60
|
}
|
|
41
61
|
|
|
42
62
|
function fromShim(shim: string): MinimaxCliSpec | undefined {
|
|
43
63
|
if (shim.endsWith('.cmd') || shim.endsWith('.bat')) {
|
|
44
64
|
// npm's Windows shim forwards to the package's cli.js. Reading it avoids a
|
|
45
|
-
// cmd.exe layer, which keeps ACP's stdio byte-clean
|
|
65
|
+
// cmd.exe layer, which keeps ACP's stdio byte-clean; the shim's own Node
|
|
66
|
+
// interpreter is kept so the native SQLite ABI still matches.
|
|
46
67
|
try {
|
|
47
68
|
const text = readFileSync(shim, 'utf8')
|
|
48
69
|
const match = /["']([^"']*node_modules[\\/]@minimax-ai[\\/]code[\\/]cli\.js)["']/.exec(text)
|
|
49
|
-
if (match !== null && existsSync(match[1])) return fromJsEntry(match[1])
|
|
70
|
+
if (match !== null && existsSync(match[1])) return fromJsEntry(match[1], cliNodeCommand(dirname(shim)))
|
|
50
71
|
} catch {
|
|
51
72
|
// Fall through to the sibling-package guess below.
|
|
52
73
|
}
|
|
53
74
|
const sibling = join(dirname(shim), 'node_modules', '@minimax-ai', 'code', 'cli.js')
|
|
54
|
-
if (existsSync(sibling)) return fromJsEntry(sibling)
|
|
75
|
+
if (existsSync(sibling)) return fromJsEntry(sibling, cliNodeCommand(dirname(shim)))
|
|
55
76
|
return {
|
|
56
77
|
command: process.env.ComSpec ?? 'cmd.exe',
|
|
57
78
|
args: ['/d', '/c', shim],
|
package/src/setup.ts
CHANGED
|
@@ -244,11 +244,21 @@ export function readSetupStatus(brand: QoderBrand = 'cn'): SetupStatus {
|
|
|
244
244
|
installed,
|
|
245
245
|
...cliVersion === undefined ? {} : { cliVersion },
|
|
246
246
|
...required === undefined ? {} : { requiredCliVersion: required },
|
|
247
|
-
//
|
|
248
|
-
//
|
|
247
|
+
// Only an OLDER CLI is a problem. The SDK pins the build it was tested
|
|
248
|
+
// against, but the CLI is a separate package the user (or its own `update`
|
|
249
|
+
// command) may move ahead of that pin, and a newer build that still speaks
|
|
250
|
+
// the protocol works fine — verified: SDK 1.0.58 (pinned 1.1.81) runs
|
|
251
|
+
// catalog reads, quota and full turns on CLI 1.1.84. Warning on "not equal"
|
|
252
|
+
// turned a normal update into a standing error, and the bundled helper then
|
|
253
|
+
// pulled the CLI back down, which is the opposite of following upstream.
|
|
254
|
+
//
|
|
255
|
+
// Below the pin is the real failure mode: CLI 1.1.81 removed the
|
|
256
|
+
// worker-session handshake that older SDKs spoke, so every query dies with
|
|
257
|
+
// exit code 42 (`sdk_worker_removed`). Unknown on either side stays quiet —
|
|
258
|
+
// a native build carries no manifest.
|
|
249
259
|
...cliVersion === undefined || required === undefined
|
|
250
260
|
? {}
|
|
251
|
-
: { versionMismatch: cliVersion
|
|
261
|
+
: { versionMismatch: compareVersions(cliVersion, required) < 0 },
|
|
252
262
|
}
|
|
253
263
|
const run = current.get(brand)
|
|
254
264
|
if (run === undefined) return { running: false, lines: [], truncated: false, ...build }
|
|
@@ -296,6 +306,31 @@ export function cancelSetup(brand: QoderBrand): boolean {
|
|
|
296
306
|
return true
|
|
297
307
|
}
|
|
298
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Compare two dotted versions, numerically per segment.
|
|
311
|
+
*
|
|
312
|
+
* A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
|
|
313
|
+
* backwards for the decision this feeds.
|
|
314
|
+
*
|
|
315
|
+
* @param left - one version, e.g. `1.1.84`.
|
|
316
|
+
* @param right - the other, e.g. `1.1.81`.
|
|
317
|
+
* @returns negative when `left` is older, positive when newer, 0 when equal.
|
|
318
|
+
*/
|
|
319
|
+
export function compareVersions(left: string, right: string): number {
|
|
320
|
+
const parse = (value: string): number[] =>
|
|
321
|
+
value.split(/[.-]/).map(part => {
|
|
322
|
+
const n = Number.parseInt(part, 10)
|
|
323
|
+
return Number.isFinite(n) ? n : 0
|
|
324
|
+
})
|
|
325
|
+
const a = parse(left)
|
|
326
|
+
const b = parse(right)
|
|
327
|
+
for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
|
|
328
|
+
const diff = (a[i] ?? 0) - (b[i] ?? 0)
|
|
329
|
+
if (diff !== 0) return diff < 0 ? -1 : 1
|
|
330
|
+
}
|
|
331
|
+
return 0
|
|
332
|
+
}
|
|
333
|
+
|
|
299
334
|
/**
|
|
300
335
|
* Abandon the running helper, if any.
|
|
301
336
|
*
|