@bytedance/doubao-cli 2.36.1 → 2.37.1
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/README.md +2 -1
- package/artifacts.json +10 -10
- package/package.json +1 -1
- package/scripts/install.cjs +68 -28
- package/scripts/run.cjs +6 -6
- package/scripts/runtime.cjs +10 -8
- package/scripts/update.cjs +12 -12
package/README.md
CHANGED
|
@@ -31,7 +31,8 @@ npm install -g @bytedance/doubao-cli
|
|
|
31
31
|
npm view @bytedance/doubao-cli versions --json
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
更新脚本会尝试停止 `--service-start` 服务任务;请先退出所有 TUI,再执行
|
|
35
|
+
`doubao update`,或重复上面的安装命令。
|
|
35
36
|
有实例仍在运行时,更新会停止并提示退出,不会自动终止进程。
|
|
36
37
|
已下载的安装包会在 SHA-256 校验通过后复用,退出实例后重试无需重复下载。
|
|
37
38
|
`doubao update` 在版本相同时提示已是最新版本;本机版本较新时保留本机版本,不自动降级。
|
package/artifacts.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.37.1",
|
|
3
3
|
"platforms": {
|
|
4
4
|
"linux-x64": {
|
|
5
|
-
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.
|
|
6
|
-
"sha256": "
|
|
7
|
-
"root": "doubao-cli-2.
|
|
5
|
+
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-linux-x64-signed.tar.gz",
|
|
6
|
+
"sha256": "c1e4ac2ebe50616dbf4be65546048fcc705b3ff6126044d62f56a2c739f97ce5",
|
|
7
|
+
"root": "doubao-cli-2.37.1-linux-x64"
|
|
8
8
|
},
|
|
9
9
|
"darwin-arm64": {
|
|
10
|
-
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.
|
|
11
|
-
"sha256": "
|
|
12
|
-
"root": "doubao-cli-2.
|
|
10
|
+
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-darwin-arm64-signed-signed.tar.gz",
|
|
11
|
+
"sha256": "5e9e5d0b260da5f97341df6d9244b46a9485f8facd0499cf523eedd66f7b77d7",
|
|
12
|
+
"root": "doubao-cli-2.37.1-darwin-arm64"
|
|
13
13
|
},
|
|
14
14
|
"win32-x64": {
|
|
15
|
-
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.
|
|
16
|
-
"sha256": "
|
|
17
|
-
"root": "doubao-cli-2.
|
|
15
|
+
"url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-win-x64-signed.zip",
|
|
16
|
+
"sha256": "528c1dcc395ae5b4d669662596aaca9ee45069d9ef53863b63ca6a98ed797570",
|
|
17
|
+
"root": "doubao-cli-2.37.1-win-x64"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
package/package.json
CHANGED
package/scripts/install.cjs
CHANGED
|
@@ -5,36 +5,59 @@ const path = require('node:path');
|
|
|
5
5
|
const crypto = require('node:crypto');
|
|
6
6
|
const { execFileSync } = require('node:child_process');
|
|
7
7
|
const { pipeline } = require('node:stream/promises');
|
|
8
|
+
const { setTimeout: delay } = require('node:timers/promises');
|
|
8
9
|
const packageRoot = path.resolve(__dirname, '..');
|
|
9
10
|
const platforms = ['win32-x64', 'darwin-arm64', 'linux-x64'];
|
|
10
11
|
|
|
12
|
+
function stopCurrentService(app, platform, execute = execFileSync) {
|
|
13
|
+
const binary = platform === 'win32-x64' ? 'doubao.exe' : 'doubao';
|
|
14
|
+
const executable = path.join(app, 'current', binary);
|
|
15
|
+
let info;
|
|
16
|
+
try {
|
|
17
|
+
info = fs.lstatSync(executable);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (error.code === 'ENOENT') return false;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
execute(executable, ['--service-stop'],
|
|
27
|
+
{ cwd: path.dirname(executable), stdio: 'ignore', windowsHide: true, timeout: 5000 });
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
function validateConfig(config, version) {
|
|
12
|
-
if (config.version !== version) throw new Error('
|
|
35
|
+
if (config.version !== version) throw new Error('下载清单版本必须与 package.json 一致。');
|
|
13
36
|
for (const platform of platforms) {
|
|
14
37
|
const artifact = config.platforms[platform];
|
|
15
38
|
if (!artifact || !/^[a-f0-9]{64}$/i.test(artifact.sha256)) {
|
|
16
|
-
throw new Error(
|
|
39
|
+
throw new Error(`缺少 ${platform} 的 SHA-256 校验值。`);
|
|
17
40
|
}
|
|
18
41
|
const url = new URL(artifact.url);
|
|
19
42
|
if (url.protocol !== 'https:' || url.username || url.password) {
|
|
20
|
-
throw new Error(
|
|
43
|
+
throw new Error(`${platform} 的下载地址必须使用 HTTPS,且不能包含用户名或密码。`);
|
|
21
44
|
}
|
|
22
45
|
validatePath(artifact.root);
|
|
23
|
-
if (artifact.root.includes('/')) throw new Error('
|
|
46
|
+
if (artifact.root.includes('/')) throw new Error('压缩包顶层目录必须是单个目录。');
|
|
24
47
|
}
|
|
25
48
|
}
|
|
26
49
|
|
|
27
50
|
function validatePath(name) {
|
|
28
51
|
if (!name || /[\\:\x00-\x1f]/.test(name) || name.startsWith('/') ||
|
|
29
52
|
name.split('/').some((part) => part === '..' || part === '.')) {
|
|
30
|
-
throw new Error(
|
|
53
|
+
throw new Error(`压缩包路径不安全:${name}`);
|
|
31
54
|
}
|
|
32
55
|
}
|
|
33
56
|
|
|
34
57
|
async function verifyChecksum(file, expected) {
|
|
35
58
|
const hash = crypto.createHash('sha256');
|
|
36
59
|
await pipeline(fs.createReadStream(file), hash);
|
|
37
|
-
if (hash.digest('hex') !== expected.toLowerCase()) throw new Error('
|
|
60
|
+
if (hash.digest('hex') !== expected.toLowerCase()) throw new Error('安装包 SHA-256 不匹配');
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
function extract(archive, destination, root) {
|
|
@@ -42,7 +65,7 @@ function extract(archive, destination, root) {
|
|
|
42
65
|
? path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'tar.exe')
|
|
43
66
|
: 'tar';
|
|
44
67
|
if (process.platform === 'win32' && !fs.existsSync(tar)) {
|
|
45
|
-
throw new Error(
|
|
68
|
+
throw new Error(`解压 ZIP 安装包需要 Windows 系统 tar.exe:${tar}`);
|
|
46
69
|
}
|
|
47
70
|
const options = { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 };
|
|
48
71
|
const names = execFileSync(tar, ['-tf', archive], options).trim().split(/\r?\n/);
|
|
@@ -51,12 +74,12 @@ function extract(archive, destination, root) {
|
|
|
51
74
|
const name = entryName.replace(/^(?:\.\/)+/, '');
|
|
52
75
|
validatePath(name);
|
|
53
76
|
if (name !== root && !name.startsWith(`${root}/`)) {
|
|
54
|
-
throw new Error(
|
|
77
|
+
throw new Error(`压缩包顶层目录与配置不一致:${name}`);
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
80
|
const entries = execFileSync(tar, ['-tvf', archive], options).trim().split(/\r?\n/);
|
|
58
81
|
if (entries.some((entry) => !/^[-d]/.test(entry))) {
|
|
59
|
-
throw new Error('
|
|
82
|
+
throw new Error('压缩包不支持链接或特殊文件。');
|
|
60
83
|
}
|
|
61
84
|
execFileSync(tar, ['-xf', archive, '-C', destination], { stdio: 'inherit' });
|
|
62
85
|
}
|
|
@@ -67,12 +90,12 @@ function validateRuntime(root, platform, version) {
|
|
|
67
90
|
const target = platform === 'win32-x64' ? 'win-x64' : platform;
|
|
68
91
|
if (manifest.schema_version !== 1 || manifest.target !== target ||
|
|
69
92
|
typeof manifest.version !== 'string' || !manifest.version ||
|
|
70
|
-
(version && manifest.version !== version)) throw new Error('
|
|
71
|
-
if (manifest.entrypoint !== binary) throw new Error('
|
|
72
|
-
if (!Array.isArray(manifest.files) || !manifest.files.length) throw new Error('
|
|
93
|
+
(version && manifest.version !== version)) throw new Error('运行时清单的版本或平台不匹配。');
|
|
94
|
+
if (manifest.entrypoint !== binary) throw new Error('运行时清单的程序入口不匹配。');
|
|
95
|
+
if (!Array.isArray(manifest.files) || !manifest.files.length) throw new Error('缺少运行时文件清单。');
|
|
73
96
|
for (const name of [binary, 'resources/js_app/cli-manifest.json', ...manifest.files.map((file) => file.path)]) {
|
|
74
97
|
validatePath(name);
|
|
75
|
-
if (!fs.statSync(path.join(root, name)).isFile()) throw new Error(
|
|
98
|
+
if (!fs.statSync(path.join(root, name)).isFile()) throw new Error(`缺少运行时文件:${name}`);
|
|
76
99
|
}
|
|
77
100
|
if (platform !== 'win32-x64') fs.accessSync(path.join(root, binary), fs.constants.X_OK);
|
|
78
101
|
}
|
|
@@ -86,14 +109,14 @@ async function cachedArchive(app, temporary, artifact) {
|
|
|
86
109
|
const archive = path.join(temporary, 'package');
|
|
87
110
|
try {
|
|
88
111
|
const info = fs.lstatSync(stored);
|
|
89
|
-
if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1) throw new Error('
|
|
112
|
+
if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1) throw new Error('下载缓存不安全。');
|
|
90
113
|
// Verify a private snapshot; concurrent cache replacement cannot change extraction input.
|
|
91
114
|
fs.copyFileSync(stored, archive, fs.constants.COPYFILE_EXCL);
|
|
92
115
|
await verifyChecksum(archive, name);
|
|
93
|
-
console.log('
|
|
116
|
+
console.log('已使用验证通过的豆包 CLI 缓存包。');
|
|
94
117
|
return archive;
|
|
95
118
|
} catch (error) {
|
|
96
|
-
if (error.message === '
|
|
119
|
+
if (error.message === '下载缓存不安全。') throw error;
|
|
97
120
|
if (error.code && error.code !== 'ENOENT') throw error;
|
|
98
121
|
fs.rmSync(archive, { force: true });
|
|
99
122
|
}
|
|
@@ -106,14 +129,26 @@ async function cachedArchive(app, temporary, artifact) {
|
|
|
106
129
|
fs.copyFileSync(archive, pending, fs.constants.COPYFILE_EXCL);
|
|
107
130
|
fs.renameSync(pending, stored);
|
|
108
131
|
} catch (error) {
|
|
109
|
-
console.warn('
|
|
132
|
+
console.warn('无法保存已验证的下载缓存:' + error.message);
|
|
110
133
|
} finally {
|
|
111
134
|
try { fs.rmSync(pending, { force: true }); }
|
|
112
|
-
catch (error) { console.warn('
|
|
135
|
+
catch (error) { console.warn('无法删除临时下载缓存:' + error.message); }
|
|
113
136
|
}
|
|
114
137
|
return archive;
|
|
115
138
|
}
|
|
116
139
|
|
|
140
|
+
async function renameStaged(from, to) {
|
|
141
|
+
for (let retries = 0; ; retries++) {
|
|
142
|
+
try {
|
|
143
|
+
fs.renameSync(from, to);
|
|
144
|
+
return;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (retries === 3 || !['EPERM', 'EACCES', 'EBUSY'].includes(error.code)) throw error;
|
|
147
|
+
await delay(2000);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
117
152
|
async function install(root = packageRoot, applicationRoot) {
|
|
118
153
|
const config = JSON.parse(fs.readFileSync(path.join(root, 'artifacts.json'), 'utf8'));
|
|
119
154
|
const version = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version;
|
|
@@ -122,14 +157,14 @@ async function install(root = packageRoot, applicationRoot) {
|
|
|
122
157
|
if (process.platform !== 'win32') fs.chmodSync(path.join(root, 'scripts/run.cjs'), 0o755);
|
|
123
158
|
const support = require('./runtime.cjs');
|
|
124
159
|
const platform = support.platform;
|
|
125
|
-
if (!platforms.includes(platform)) throw new Error('
|
|
160
|
+
if (!platforms.includes(platform)) throw new Error('不支持的平台:' + platform);
|
|
126
161
|
const artifact = config.platforms[platform];
|
|
127
162
|
support.directory(applicationRoot || support.appRoot());
|
|
128
163
|
const app = fs.realpathSync(applicationRoot || support.appRoot());
|
|
129
164
|
const temporary = fs.mkdtempSync(path.join(app, '.staging-'));
|
|
130
165
|
let runner;
|
|
131
166
|
try {
|
|
132
|
-
console.log('
|
|
167
|
+
console.log('正在准备豆包 CLI ' + version + ' (' + platform + ')...');
|
|
133
168
|
const archive = await cachedArchive(app, temporary, artifact);
|
|
134
169
|
const unpacked = path.join(temporary, 'unpacked');
|
|
135
170
|
fs.mkdirSync(unpacked);
|
|
@@ -137,18 +172,18 @@ async function install(root = packageRoot, applicationRoot) {
|
|
|
137
172
|
const staged = path.join(unpacked, artifact.root);
|
|
138
173
|
const executable = path.join(staged, support.updaterName);
|
|
139
174
|
const info = fs.lstatSync(executable, { throwIfNoEntry: false });
|
|
140
|
-
if (!info || !info.isFile() || info.isSymbolicLink() || info.nlink !== 1) throw new Error('
|
|
175
|
+
if (!info || !info.isFile() || info.isSymbolicLink() || info.nlink !== 1) throw new Error('独立更新程序缺失或不安全,请使用重新构建的原生安装包。');
|
|
141
176
|
if (process.platform !== 'win32') {
|
|
142
177
|
const binary = path.join(staged, 'doubao');
|
|
143
178
|
const binaryInfo = fs.lstatSync(binary);
|
|
144
|
-
if (!binaryInfo.isFile() || binaryInfo.isSymbolicLink() || binaryInfo.nlink !== 1) throw new Error('
|
|
179
|
+
if (!binaryInfo.isFile() || binaryInfo.isSymbolicLink() || binaryInfo.nlink !== 1) throw new Error('运行时程序缺失或不安全。');
|
|
145
180
|
fs.chmodSync(binary, 0o755);
|
|
146
181
|
fs.chmodSync(executable, 0o755);
|
|
147
182
|
}
|
|
148
183
|
validateRuntime(staged, platform, version);
|
|
149
184
|
if (process.platform !== 'win32') fs.accessSync(executable, fs.constants.X_OK);
|
|
150
185
|
const payload = path.join(temporary, 'payload');
|
|
151
|
-
|
|
186
|
+
await renameStaged(staged, payload);
|
|
152
187
|
runner = support.prepareUpdater(payload, app);
|
|
153
188
|
// Reporting metadata only: an unreadable old manifest must not block repair.
|
|
154
189
|
let fromVersion = '';
|
|
@@ -157,13 +192,14 @@ async function install(root = packageRoot, applicationRoot) {
|
|
|
157
192
|
if (typeof manifest.version === 'string') fromVersion = manifest.version;
|
|
158
193
|
} catch { /* First installation or damaged old manifest. */ }
|
|
159
194
|
const operation = process.env.DOUBAO_CLI_INSTALL_OPERATION === 'update' ? 'update' : 'install';
|
|
195
|
+
stopCurrentService(app, platform);
|
|
160
196
|
support.invokeUpdater(path.join(runner, support.updaterName), app,
|
|
161
197
|
['--staging=' + path.basename(temporary), '--from-version=' + fromVersion,
|
|
162
198
|
'--to-version=' + version, '--operation=' + operation]);
|
|
163
|
-
console.log('
|
|
199
|
+
console.log('豆包 CLI ' + version + ' 已安装。');
|
|
164
200
|
try { fs.unlinkSync(path.join(app, 'downloads', artifact.sha256.toLowerCase())); }
|
|
165
201
|
catch (error) {
|
|
166
|
-
if (error.code !== 'ENOENT') console.warn('
|
|
202
|
+
if (error.code !== 'ENOENT') console.warn('无法删除下载缓存:' + error.message);
|
|
167
203
|
}
|
|
168
204
|
} finally {
|
|
169
205
|
const record = path.join(app, 'update-state.json');
|
|
@@ -179,11 +215,15 @@ async function install(root = packageRoot, applicationRoot) {
|
|
|
179
215
|
// Cleanup errors must not turn an already committed install into a failure.
|
|
180
216
|
for (const file of [temporary, runner].filter(Boolean)) {
|
|
181
217
|
try { fs.rmSync(file, { recursive: true, force: true }); }
|
|
182
|
-
catch (error) { console.warn('
|
|
218
|
+
catch (error) { console.warn('无法删除临时文件:' + error.message); }
|
|
183
219
|
}
|
|
184
220
|
}
|
|
185
221
|
}
|
|
186
222
|
}
|
|
187
223
|
|
|
188
|
-
module.exports = { validateConfig, validatePath, verifyChecksum, extract, validateRuntime,
|
|
189
|
-
|
|
224
|
+
module.exports = { validateConfig, validatePath, verifyChecksum, extract, validateRuntime,
|
|
225
|
+
cachedArchive, renameStaged, stopCurrentService, install };
|
|
226
|
+
if (require.main === module) install().catch(error => {
|
|
227
|
+
if (!error.reported) console.error('豆包 CLI 安装失败:' + error.message);
|
|
228
|
+
process.exitCode = 1;
|
|
229
|
+
});
|
package/scripts/run.cjs
CHANGED
|
@@ -16,10 +16,10 @@ function confirmUpdate() {
|
|
|
16
16
|
resolve(null);
|
|
17
17
|
});
|
|
18
18
|
input.on('SIGINT', () => input.close());
|
|
19
|
-
const ask = () => input.question('
|
|
19
|
+
const ask = () => input.question('是否现在更新?[Y/N] ', (answer) => {
|
|
20
20
|
const choice = answer.trim().toLowerCase();
|
|
21
21
|
if (choice !== 'y' && choice !== 'n') {
|
|
22
|
-
console.error('
|
|
22
|
+
console.error('请输入 Y 开始更新,或输入 N 跳过并继续。');
|
|
23
23
|
ask();
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -32,7 +32,7 @@ function confirmUpdate() {
|
|
|
32
32
|
|
|
33
33
|
async function run(args = process.argv.slice(2), root = runtime.appRoot()) {
|
|
34
34
|
if (args[0] === 'update') {
|
|
35
|
-
if (args.length !== 1) throw new Error('
|
|
35
|
+
if (args.length !== 1) throw new Error('用法:doubao update');
|
|
36
36
|
return updates.update(root);
|
|
37
37
|
}
|
|
38
38
|
const current = path.join(root, 'current');
|
|
@@ -45,7 +45,7 @@ async function run(args = process.argv.slice(2), root = runtime.appRoot()) {
|
|
|
45
45
|
if (confirmed) {
|
|
46
46
|
try { return await updates.update(root); }
|
|
47
47
|
catch (error) {
|
|
48
|
-
console.error(
|
|
48
|
+
console.error(`无法更新豆包 CLI:${error.message}`);
|
|
49
49
|
return 1;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -80,8 +80,8 @@ function isInfoQuery(args) {
|
|
|
80
80
|
if (require.main === module) {
|
|
81
81
|
run().then((code) => { process.exitCode = code; }).catch((error) => {
|
|
82
82
|
console.error(process.argv[2] === 'update'
|
|
83
|
-
?
|
|
84
|
-
:
|
|
83
|
+
? `无法更新豆包 CLI:${error.message}`
|
|
84
|
+
: `无法启动豆包 CLI:${error.message}`);
|
|
85
85
|
process.exitCode = 1;
|
|
86
86
|
});
|
|
87
87
|
}
|
package/scripts/runtime.cjs
CHANGED
|
@@ -16,20 +16,20 @@ function appRoot() {
|
|
|
16
16
|
if (process.env.XDG_DATA_HOME) parent = process.env.XDG_DATA_HOME;
|
|
17
17
|
else {
|
|
18
18
|
// Native uses HOME directly; do not silently choose a different passwd fallback.
|
|
19
|
-
if (!process.env.HOME || !path.isAbsolute(process.env.HOME)) throw new Error('
|
|
19
|
+
if (!process.env.HOME || !path.isAbsolute(process.env.HOME)) throw new Error('请将 HOME 或 XDG_DATA_HOME 设置为绝对路径。');
|
|
20
20
|
parent = path.join(process.env.HOME, '.local/share');
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
if (!parent || !path.isAbsolute(parent)) throw new Error('
|
|
23
|
+
if (!parent || !path.isAbsolute(parent)) throw new Error('无法确定系统用户的应用数据目录。');
|
|
24
24
|
return path.join(parent, 'doubao_cli', 'app');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function directory(file) {
|
|
28
28
|
fs.mkdirSync(file, { recursive: true, mode: 0o700 });
|
|
29
29
|
const info = fs.lstatSync(file);
|
|
30
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error(
|
|
30
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error(`应用目录不安全:${file}`);
|
|
31
31
|
if (process.platform !== 'win32' && (info.uid !== process.getuid() || (info.mode & 0o022))) {
|
|
32
|
-
throw new Error(
|
|
32
|
+
throw new Error(`应用目录必须属于当前用户,且其他用户不能写入:${file}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -37,11 +37,11 @@ function checkCurrent(root) {
|
|
|
37
37
|
const current = path.join(root, 'current');
|
|
38
38
|
try {
|
|
39
39
|
const info = fs.lstatSync(current);
|
|
40
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('
|
|
40
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('当前运行时目录不安全。');
|
|
41
41
|
require('./install.cjs').validateRuntime(current, platform);
|
|
42
42
|
return JSON.parse(fs.readFileSync(path.join(current, 'manifest.json'), 'utf8')).version;
|
|
43
43
|
} catch (error) {
|
|
44
|
-
throw new Error(
|
|
44
|
+
throw new Error(`已安装的运行时缺失或无效:${error.message}。若正在执行更新,请等待完成后重试;否则请通过启用安装脚本的 npm 重新安装。`, { cause: error });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -55,8 +55,10 @@ function invokeUpdater(executable, root, args) {
|
|
|
55
55
|
} catch (error) {
|
|
56
56
|
if (error.status === 10) return;
|
|
57
57
|
if (error.status === 3) throw Object.assign(new Error(
|
|
58
|
-
'
|
|
59
|
-
|
|
58
|
+
'无法获取运行锁。请退出其他实例,或等待当前更新完成后重试;若问题持续,请检查目录权限。'), { code: 'ELOCKED', reported: true });
|
|
59
|
+
// Native reports its defined failure results through inherited stderr.
|
|
60
|
+
throw Object.assign(new Error('更新程序失败(' + (error.status ?? error.code ?? error.signal) + ')。请保留更新文件后重试。', { cause: error }),
|
|
61
|
+
{ reported: [2, 4, 5].includes(error.status) });
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
package/scripts/update.cjs
CHANGED
|
@@ -9,11 +9,11 @@ function distribution() {
|
|
|
9
9
|
const { name, publishConfig } = require('../package.json');
|
|
10
10
|
if (!/^@[a-z0-9-]+\/[a-z0-9-]+$/.test(name || '') ||
|
|
11
11
|
!publishConfig || !/^[a-z][a-z0-9-]*$/.test(publishConfig.tag || '')) {
|
|
12
|
-
throw new Error('
|
|
12
|
+
throw new Error('npm 更新包或标签配置无效,请重新安装。');
|
|
13
13
|
}
|
|
14
14
|
const url = new URL(publishConfig.registry);
|
|
15
15
|
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) {
|
|
16
|
-
throw new Error('
|
|
16
|
+
throw new Error('npm 更新源必须使用 HTTPS,且不能包含登录信息或查询参数。');
|
|
17
17
|
}
|
|
18
18
|
return { packageName: name, registry: publishConfig.registry, tag: publishConfig.tag };
|
|
19
19
|
}
|
|
@@ -33,7 +33,7 @@ function npmCli() {
|
|
|
33
33
|
if (path.basename(resolved) === 'npm-cli.js' && fs.statSync(resolved).isFile()) return resolved;
|
|
34
34
|
} catch { /* Try the next installed npm location. */ }
|
|
35
35
|
}
|
|
36
|
-
throw new Error('
|
|
36
|
+
throw new Error('找不到 npm-cli.js,请通过 npm install -g 并指定本渠道的源进行更新。');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function parseVersion(version) {
|
|
@@ -68,28 +68,28 @@ function latest({ packageName, registry, tag }, timeout = 15000) {
|
|
|
68
68
|
'--json', '--prefer-online', `--registry=${registry}`], { encoding: 'utf8', timeout, maxBuffer: 16384,
|
|
69
69
|
stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
70
70
|
const version = JSON.parse(output);
|
|
71
|
-
if (!parseVersion(version)) throw new Error('
|
|
71
|
+
if (!parseVersion(version)) throw new Error('npm 源返回的版本号无效。');
|
|
72
72
|
return version;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
async function update(root = runtime.appRoot()) {
|
|
76
76
|
const installed = runtime.checkCurrent(root);
|
|
77
77
|
const config = distribution();
|
|
78
|
-
const { packageName, registry
|
|
78
|
+
const { packageName, registry } = config;
|
|
79
79
|
const version = latest(config);
|
|
80
80
|
// Always update the installation containing this launcher, including custom prefixes.
|
|
81
81
|
const modules = path.resolve(runtime.packageRoot, '../..');
|
|
82
|
-
if (path.basename(modules) !== 'node_modules') throw new Error('doubao update
|
|
82
|
+
if (path.basename(modules) !== 'node_modules') throw new Error('doubao update 仅支持通过 npm 全局安装的豆包 CLI。');
|
|
83
83
|
let prefix = path.dirname(modules);
|
|
84
84
|
if (process.platform !== 'win32') {
|
|
85
|
-
if (path.basename(prefix) !== 'lib') throw new Error('
|
|
85
|
+
if (path.basename(prefix) !== 'lib') throw new Error('无法确定 npm 全局安装目录。');
|
|
86
86
|
prefix = path.dirname(prefix);
|
|
87
87
|
}
|
|
88
|
-
if (!parseVersion(installed)) throw new Error('
|
|
88
|
+
if (!parseVersion(installed)) throw new Error('已安装的运行时版本号无效,请重新安装以修复。');
|
|
89
89
|
if (!newer(version, installed)) {
|
|
90
90
|
console.log(installed === version
|
|
91
|
-
?
|
|
92
|
-
:
|
|
91
|
+
? `豆包 CLI ${installed} 已是最新版本。`
|
|
92
|
+
: `当前版本 ${installed} 不低于远端版本 (${version}),无需更新。`);
|
|
93
93
|
return 0;
|
|
94
94
|
}
|
|
95
95
|
const child = spawn(process.execPath, [npmCli(), 'install', '-g', `${packageName}@${version}`,
|
|
@@ -101,7 +101,7 @@ async function update(root = runtime.appRoot()) {
|
|
|
101
101
|
if (code !== 0) return resolve(code ?? 1);
|
|
102
102
|
try {
|
|
103
103
|
const installed = runtime.checkCurrent(root);
|
|
104
|
-
if (installed !== version) throw new Error(`npm
|
|
104
|
+
if (installed !== version) throw new Error(`npm 已完成,但运行时仍为 ${installed},预期为 ${version}。请启用安装脚本后重试`);
|
|
105
105
|
resolve(0);
|
|
106
106
|
} catch (error) { reject(error); }
|
|
107
107
|
});
|
|
@@ -114,7 +114,7 @@ function notifier(installed) {
|
|
|
114
114
|
try {
|
|
115
115
|
const version = latest(distribution(), 3000);
|
|
116
116
|
return newer(version, installed)
|
|
117
|
-
?
|
|
117
|
+
? `检测到豆包 CLI 有可用的新版本:${installed} -> ${version}。` : null;
|
|
118
118
|
} catch { return null; }
|
|
119
119
|
}
|
|
120
120
|
|