panrouter 5.4.4 → 5.4.5

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 +1 -1
  2. package/pool-worker.mjs +12 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "panrouter",
3
- "version": "5.4.4",
3
+ "version": "5.4.5",
4
4
  "description": "让 Claude Code 免费使用 DeepSeek 等模型,无需 API Key",
5
5
  "type": "module",
6
6
  "bin": {
package/pool-worker.mjs CHANGED
@@ -203,13 +203,19 @@ function handleUpgrade() {
203
203
  killPort(SERVER_PORT);
204
204
 
205
205
  if (oldVersion !== newVersion) {
206
- // 版本变了spawn 新进程加载新代码
207
- log(`版本变更: v${oldVersion} → v${newVersion},启动新进程`, "OK");
208
- try {
209
- if (!fs.existsSync(RUNTIME_DIR)) fs.mkdirSync(RUNTIME_DIR, { recursive: true });
210
- fs.writeFileSync(PID_FILE, String(process.pid), "utf-8");
211
- } catch {}
206
+ log(`版本变更: v${oldVersion}v${newVersion},升级并重启`, "OK");
207
+
208
+ // Windows 下当前进程锁住了 npm 目录 → 先 exit 释放锁再 npm install
209
+ // start /b 提交一个后台脚本,等 2 秒(进程退出锁释放)后执行升级 + 启动
210
+ // start /b 的输出会打到当前终端,用户能看到进度
211
+ if (process.platform === 'win32') {
212
+ const cmd = `start /b cmd /c "@ping 127.0.0.1 -n 3 >nul && npm install -g panrouter@latest && panrouter --pool"`;
213
+ try { execSync(cmd, { stdio: 'pipe', timeout: 5000, shell: true }); } catch {}
214
+ log("升级脚本已提交 (当前进程退出后自动执行),旧进程退出", "OFF");
215
+ process.exit(0);
216
+ }
212
217
 
218
+ // Unix 可以直接 spawn(不会锁)
213
219
  spawn(process.execPath, [process.argv[1], "--pool"], {
214
220
  cwd: __dirname,
215
221
  stdio: "inherit",