pubo-node 1.0.181 → 1.0.182

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.
@@ -2,7 +2,7 @@ export declare function getProcessName(pid: any): Promise<string>;
2
2
  export declare function getPidByPort(port: any): Promise<unknown>;
3
3
  export declare function getProcessCpuUseByPid(pid: number): Promise<number>;
4
4
  export declare function getProcessCommandByPid(pid: number): Promise<string>;
5
- export declare function isProcessDied(pid: any): Promise<boolean>;
5
+ export declare function isProcessDied(pid: number): Promise<boolean>;
6
6
  export declare function getProcessByPpid(pid: number): Promise<number[]>;
7
7
  export declare const getProcessTree: (pid: number, tree?: any) => Promise<any>;
8
8
  export declare const getProcessList: (pid: any) => Promise<number[]>;
@@ -12,6 +12,23 @@ const child_process_1 = require("child_process");
12
12
  const pubo_utils_1 = require("pubo-utils");
13
13
  // 获取进程名称
14
14
  function getProcessName(pid) {
15
+ if (process.platform === 'win32') {
16
+ // 使用tasklist命令获取进程信息
17
+ return new Promise((resolve, reject) => {
18
+ (0, child_process_1.exec)(`tasklist /fi "PID eq ${pid}" /fo csv /nh`, (err, stdout) => {
19
+ if (err) {
20
+ reject(err);
21
+ }
22
+ else {
23
+ // 解析CSV格式的输出
24
+ const match = stdout.match(/^"(.+?)"/);
25
+ if (match && match[1]) {
26
+ resolve(match[1]);
27
+ }
28
+ }
29
+ });
30
+ });
31
+ }
15
32
  return new Promise((resolve, reject) => {
16
33
  (0, child_process_1.exec)(`grep "Name:" /proc/${pid}/status`, (err, data) => {
17
34
  if (err) {
@@ -30,7 +47,7 @@ async function getPidByPort(port) {
30
47
  }
31
48
  if (process.platform === 'win32') {
32
49
  return new Promise((resolve, reject) => {
33
- (0, child_process_1.exec)(`netstat -ano | findstr "${port}"`, (error, stdout, stderr) => {
50
+ (0, child_process_1.exec)(`netstat -ano | findstr "${port}"`, (error, stdout) => {
34
51
  if (error) {
35
52
  reject(error);
36
53
  return;
@@ -140,7 +157,10 @@ async function _SIGKILL(pid, signal = 2, times = 1) {
140
157
  }
141
158
  (0, child_process_1.exec)(`kill -${signal} ${pid}`);
142
159
  try {
143
- await (0, pubo_utils_1.waitFor)(async () => isProcessDied(pid), { checkTime: 100, timeout: 4000 });
160
+ await (0, pubo_utils_1.waitFor)(async () => isProcessDied(pid), {
161
+ checkTime: 100,
162
+ timeout: 4000,
163
+ });
144
164
  }
145
165
  catch (err) {
146
166
  await _SIGKILL(pid, 9, times + 1);
@@ -209,6 +229,9 @@ const parseAudioCard = (v) => {
209
229
  return { text: v, index: `hw:${card},${device}` };
210
230
  };
211
231
  const getAudioCards = (filter = '') => {
232
+ if (process.platform === 'win32') {
233
+ return Promise.resolve([]);
234
+ }
212
235
  return new Promise((resolve, reject) => {
213
236
  (0, child_process_1.exec)(`arecord -l`, (err, stdout) => {
214
237
  if (err) {
@@ -237,7 +260,11 @@ const parser = (str) => {
237
260
  dic.forEach((key, i) => (res[key] = item[i]));
238
261
  return res;
239
262
  })
240
- .map((item) => ({ ...item, total: parseFloat(item.size), percentage: parseFloat(item['use%']) }));
263
+ .map((item) => ({
264
+ ...item,
265
+ total: parseFloat(item.size),
266
+ percentage: parseFloat(item['use%']),
267
+ }));
241
268
  };
242
269
  const getDiskUsage = async () => {
243
270
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.181",
3
+ "version": "1.0.182",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "sideEffects": false,
@@ -21,7 +21,7 @@
21
21
  "pubo-utils": "^1.0.181",
22
22
  "yaml": "^2.5.1"
23
23
  },
24
- "gitHead": "d061e80715f4a11f2c2ab54553925bd711db49d5",
24
+ "gitHead": "31546a5a98347a16d656955db9796f88dcc09bf5",
25
25
  "devDependencies": {
26
26
  "del": "^5.1.0",
27
27
  "eslint": "^8.42.0",