@taole/dd-playwright 0.1.8 → 0.1.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.
@@ -11,7 +11,7 @@ import { resolveConfig } from "../src/config.mjs";
11
11
  import { PlaywrightBrowserManager } from "../src/browser-manager.mjs";
12
12
  import { pathToFileURL } from "node:url";
13
13
 
14
- export const MCP_VERSION = "0.1.8";
14
+ export const MCP_VERSION = "0.1.9";
15
15
 
16
16
  function textResult(payload) {
17
17
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dd-playwright",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Standalone stdio MCP & CLI: Playwright browser automation + isolated whistle proxy + diandian account storageState injection",
5
5
  "type": "module",
6
6
  "license": "ISC",
package/src/updater.mjs CHANGED
@@ -1,6 +1,12 @@
1
1
  import { readFileSync, existsSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { execSync } from "node:child_process";
4
+ import { resolveConfig } from "./config.mjs";
5
+ import {
6
+ getStoredWebPid,
7
+ stopWebDaemon,
8
+ startWebDaemon,
9
+ } from "./server/daemon.mjs";
4
10
 
5
11
  export const PACKAGE_NAME = "@taole/dd-playwright";
6
12
 
@@ -91,21 +97,48 @@ export async function handleUpdateCommand(overrideCurrentVersion = null) {
91
97
  console.log(` 🚀 发现新版本可用: v${currentVersion} -> v${latestVersion}`);
92
98
  console.log(`==================================================\n`);
93
99
 
94
- console.log(`[dd-playwright] 正在尝试自动执行全局升级 (npm install -g ${PACKAGE_NAME}@latest)...`);
100
+ const config = resolveConfig();
101
+ const runningPid = getStoredWebPid(config.webPidFile);
102
+ const wasWebRunning = Boolean(runningPid);
103
+
104
+ if (wasWebRunning) {
105
+ console.log(
106
+ `[dd-playwright] 检测到后台 Web 服务正在运行 (PID: ${runningPid}),正在安全停止以释放文件锁...`,
107
+ );
108
+ await stopWebDaemon(config.webPidFile);
109
+ // 等待 500ms 确保操作系统完全释放文件句柄
110
+ await new Promise((r) => setTimeout(r, 500));
111
+ }
112
+
113
+ console.log(`[dd-playwright] 正在执行全局升级 (npm install -g ${PACKAGE_NAME}@latest)...`);
95
114
 
96
115
  try {
97
- // 优先尝试自动升级
98
116
  execSync(`npm install -g ${PACKAGE_NAME}@latest`, {
99
117
  stdio: "inherit",
100
118
  windowsHide: true,
101
119
  });
102
- console.log(`\n🎉 自动更新完成!已成功升级至最新版本 v${latestVersion}。\n`);
103
- console.log(`提示:若当前后台正在运行 Web 服务,建议重启生效:`);
104
- console.log(` dd-pw stopweb && dd-pw startweb\n`);
120
+ console.log(`\n🎉 自动升级成功!已成功升级至最新版本 v${latestVersion}。\n`);
121
+
122
+ if (wasWebRunning) {
123
+ console.log(`[dd-playwright] 正在自动为您重启后台 Web 服务...`);
124
+ const restartRes = await startWebDaemon({
125
+ port: 12309,
126
+ dataDir: config.dataDir,
127
+ pidFile: config.webPidFile,
128
+ logFile: config.webLogFile,
129
+ });
130
+ if (restartRes.started) {
131
+ console.log(`[dd-playwright] Web 服务已成功重启并常驻后台!`);
132
+ console.log(` - 进程 PID: ${restartRes.pid}`);
133
+ console.log(` - 访问地址: ${restartRes.url}\n`);
134
+ }
135
+ }
105
136
  } catch (err) {
106
- // 若因系统权限不足等原因报错,优雅降级,打印完整手工升级命令
107
137
  console.warn(`\n⚠️ 自动升级未完成(可能需要管理员权限或当前终端权限受限)。`);
108
138
  console.log(`请复制下方命令并在终端中执行升级:\n`);
109
139
  console.log(`👉 npm install -g ${PACKAGE_NAME}@latest\n`);
140
+ if (wasWebRunning) {
141
+ console.log(`如需重新启动 Web 服务,请执行: dd-pw startweb\n`);
142
+ }
110
143
  }
111
144
  }