tt-help-cli-ycl 1.4.5 → 1.4.6
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/package.json +1 -1
- package/src/cli/tag.js +19 -3
- package/src/lib/browser/cdp.js +19 -0
package/package.json
CHANGED
package/src/cli/tag.js
CHANGED
|
@@ -66,12 +66,28 @@ function getBrowserMemory(port = null) {
|
|
|
66
66
|
cmd =
|
|
67
67
|
'ps aux | grep "[m]sedge" | awk \'{sum += $6} END {printf "%d", sum/1024}\'';
|
|
68
68
|
}
|
|
69
|
+
} else if (platform === "win32") {
|
|
70
|
+
// Windows: 用 PowerShell 查 msedge 进程内存(WorkingSet64 → MB)
|
|
71
|
+
// 按端口筛选时匹配命令行参数 --remote-debugging-port=PORT
|
|
72
|
+
if (port) {
|
|
73
|
+
cmd = `powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter 'Name LIKE \\\"msedge%\\\"' | Where-Object { $_.CommandLine -match 'remote-debugging-port=${port}' } | ForEach-Object { $_.WorkingSet64 } | Measure-Object -Sum | Select-Object -ExpandProperty Sum"`;
|
|
74
|
+
} else {
|
|
75
|
+
cmd = `powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter 'Name LIKE \\\"msedge%\\\"' | ForEach-Object { $_.WorkingSet64 } | Measure-Object -Sum | Select-Object -ExpandProperty Sum"`;
|
|
76
|
+
}
|
|
69
77
|
} else {
|
|
70
78
|
return null;
|
|
71
79
|
}
|
|
72
|
-
const result = execSync(cmd, { timeout:
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const result = execSync(cmd, { timeout: 5000 }).toString().trim();
|
|
81
|
+
if (platform === "win32") {
|
|
82
|
+
// PowerShell 返回 WorkingSet64(字节),需除以 1048576 得 MB
|
|
83
|
+
const bytes = parseInt(result, 10);
|
|
84
|
+
const mb = bytes > 0 ? Math.round(bytes / 1048576) : 0;
|
|
85
|
+
return mb > 0 ? mb : null;
|
|
86
|
+
} else {
|
|
87
|
+
// macOS/Linux: ps RSS 是 KB,awk 已除以 1024 得 MB
|
|
88
|
+
const mb = parseInt(result, 10);
|
|
89
|
+
return mb > 0 ? mb : null;
|
|
90
|
+
}
|
|
75
91
|
} catch {
|
|
76
92
|
return null;
|
|
77
93
|
}
|
package/src/lib/browser/cdp.js
CHANGED
|
@@ -97,6 +97,23 @@ function killEdgeProcesses(targetDir, port) {
|
|
|
97
97
|
} else {
|
|
98
98
|
command = "true";
|
|
99
99
|
}
|
|
100
|
+
} else if (port) {
|
|
101
|
+
// 仅按端口筛选,不误杀其他端口的 Edge 实例
|
|
102
|
+
let pids = "";
|
|
103
|
+
try {
|
|
104
|
+
pids = execSync(
|
|
105
|
+
`ps aux | grep "[M]icrosoft Edge" | grep -v "Helper\\|crashpad" | grep "remote-debugging-port=${port}" | awk '{print $2}'`,
|
|
106
|
+
)
|
|
107
|
+
.toString()
|
|
108
|
+
.trim();
|
|
109
|
+
} catch (e) {
|
|
110
|
+
pids = "";
|
|
111
|
+
}
|
|
112
|
+
if (pids) {
|
|
113
|
+
command = `kill -9 ${pids} 2>/dev/null; rm -f ~/Library/Caches/Microsoft\\ Edge/Singleton*; true`;
|
|
114
|
+
} else {
|
|
115
|
+
command = "true";
|
|
116
|
+
}
|
|
100
117
|
} else {
|
|
101
118
|
command =
|
|
102
119
|
'killall -9 "Microsoft Edge" 2>/dev/null; rm -f ~/Library/Caches/Microsoft\\ Edge/Singleton*; true';
|
|
@@ -143,6 +160,8 @@ function killEdgeProcesses(targetDir, port) {
|
|
|
143
160
|
if (targetDir) {
|
|
144
161
|
const escapedDir = targetDir.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
145
162
|
command = `ps aux | grep msedge | grep -v Helper | grep -E -- '--user-data-dir=${escapedDir}($|[^A-Za-z0-9_])' | awk '{print $2}' | xargs -r kill -9 2>/dev/null; true`;
|
|
163
|
+
} else if (port) {
|
|
164
|
+
command = `ps aux | grep msedge | grep -v Helper | grep "remote-debugging-port=${port}" | awk '{print $2}' | xargs -r kill -9 2>/dev/null; true`;
|
|
146
165
|
} else {
|
|
147
166
|
command = "pkill -9 -f msedge 2>/dev/null; true";
|
|
148
167
|
}
|