Skip to content

Commit 537ec94

Browse files
MarkTiedemannsindresorhus
authored andcommitted
Improve Windows performance (#21)
Fixes #20
1 parent fe0f391 commit 537ec94

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

fastlist.exe

44 KB
Binary file not shown.

index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
'use strict';
22
const path = require('path');
33
const childProcess = require('child_process');
4-
const tasklist = require('tasklist');
54
const pify = require('pify');
65

76
const TEN_MEGABYTES = 1000 * 1000 * 10;
87

98
function win() {
10-
return tasklist().then(data => {
11-
return data.map(x => {
12-
return {
13-
pid: x.pid,
14-
name: x.imageName,
15-
cmd: x.imageName
16-
};
17-
});
18-
});
9+
// Source: https://github.com/MarkTiedemann/fastlist
10+
const bin = path.join(__dirname, 'fastlist.exe');
11+
12+
return pify(childProcess.execFile)(bin, {maxBuffer: TEN_MEGABYTES})
13+
.then(stdout =>
14+
stdout.trim()
15+
.split('\r\n')
16+
.map(line => line.split('\t'))
17+
.map(([name, pid, ppid]) => ({
18+
name,
19+
pid: Number.parseInt(pid, 10),
20+
ppid: Number.parseInt(ppid, 10)
21+
}))
22+
);
1923
}
2024

2125
function def(options = {}) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
"tasklist"
2929
],
3030
"dependencies": {
31-
"pify": "^3.0.0",
32-
"tasklist": "^3.1.0"
31+
"pify": "^4.0.0"
3332
},
3433
"devDependencies": {
3534
"ava": "*",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const psList = require('ps-list');
2323
})();
2424
```
2525

26-
> The `cpu`, `memory`, and `ppid` properties are not supported on Windows.
26+
> The `cmd`, `cpu`, and `memory` properties are not supported on Windows.
2727
2828

2929
## API

test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ test('main', async t => {
1212
list.every(x =>
1313
typeof x.pid === 'number' &&
1414
typeof x.name === 'string' &&
15-
typeof x.cmd === 'string'
15+
typeof x.ppid === 'number'
1616
)
1717
);
1818

1919
if (!isWindows) {
2020
t.true(
2121
list.every(x =>
22+
typeof x.cmd === 'string' &&
2223
typeof x.cpu === 'number' &&
2324
typeof x.memory === 'number'
2425
)
2526
);
26-
t.true(
27-
list.every(x => typeof x.ppid === 'number')
28-
);
2927
}
3028
});

0 commit comments

Comments
 (0)