From cc443805ffa0f56f51c8e9e1b441a2430a29d30f Mon Sep 17 00:00:00 2001 From: ZA139 Date: Tue, 20 Jan 2026 20:34:18 +0800 Subject: [PATCH 1/3] Add getAllProcesses API for retrieving all system processes Introduces the getAllProcesses function to retrieve a list of all processes on Windows systems, with both callback and Promise-based interfaces. Updates typings to reflect the new API. --- lib/index.ts | 21 ++++++++++++++++++++- typings/windows-process-tree.d.ts | 13 ++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 065c338..acbdd58 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -223,7 +223,26 @@ export namespace getProcessTree { }); } +/** + * Returns a list of all processes on the system + * @param callback The callback to use with the returned set of processes + * @param flags The flags for what process data should be included + */ +export function getAllProcesses(callback: (processList: IProcessInfo[]) => void, flags?: ProcessDataFlag): void { + if (process.platform !== 'win32') { + throw new Error('getAllProcesses is only implemented on Windows'); + } + getRawProcessList(callback, flags); +} + +export namespace getAllProcesses { + // tslint:disable-next-line:variable-name + export const __promisify__ = (flags?: ProcessDataFlag): Promise => new Promise((resolve, reject) => { + getAllProcesses((processList) => resolve(processList), flags); + }); +} + // Since symbol properties can't be declared via namespace merging, we just define __promisify__ that way and // and manually set the "modern" promisify symbol: https://github.com/microsoft/TypeScript/issues/36813 -[getProcessTree, getProcessList, getProcessCpuUsage].forEach(func => +[getProcessTree, getProcessList, getProcessCpuUsage,getAllProcesses].forEach(func => Object.defineProperty(func, promisify.custom, { enumerable: false, value: func.__promisify__ })); diff --git a/typings/windows-process-tree.d.ts b/typings/windows-process-tree.d.ts index 996868e..4206857 100644 --- a/typings/windows-process-tree.d.ts +++ b/typings/windows-process-tree.d.ts @@ -72,4 +72,15 @@ declare module '@vscode/windows-process-tree' { namespace getProcessCpuUsage { function __promisify__(processList: IProcessInfo[]): Promise; } -} + + /** + * Returns a list of all processes on the system. + * @param callback - The callback to use with the returned set of processes. + * @param flags - The flags for what process data should be included. + */ + export function getAllProcesses(callback: (processList: IProcessInfo[]) => void, flags?: ProcessDataFlag): void; + + namespace getAllProcesses { + function __promisify__(flags?: ProcessDataFlag): Promise; + } +} \ No newline at end of file From c43ae0b978ceba76d0d6c13ee2c0d401c00ba784 Mon Sep 17 00:00:00 2001 From: ZA139 <40553487+ZA139@users.noreply.github.com> Date: Tue, 20 Jan 2026 23:55:18 +0800 Subject: [PATCH 2/3] Add getAllProcesses API and tests Introduces the getAllProcesses function to the promises module, updates type definitions, and adds unit tests to verify its behavior and flag support. --- lib/promises.ts | 1 + lib/test.ts | 33 ++++++++++++++++++++++ typings/windows-process-tree.d.ts | 2 +- typings/windows-process-tree/promises.d.ts | 6 ++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/promises.ts b/lib/promises.ts index 93e7093..5dca8dc 100644 --- a/lib/promises.ts +++ b/lib/promises.ts @@ -12,3 +12,4 @@ export { ProcessDataFlag } from './index'; export const getProcessTree = promisify(wpc.getProcessTree); export const getProcessList = promisify(wpc.getProcessList); export const getProcessCpuUsage = promisify(wpc.getProcessCpuUsage); +export const getAllProcesses = promisify(wpc.getAllProcesses); \ No newline at end of file diff --git a/lib/test.ts b/lib/test.ts index f502765..b5bc932 100644 --- a/lib/test.ts +++ b/lib/test.ts @@ -27,6 +27,39 @@ function pollUntil(makePromise: () => Promise, cb: () => void, interval if (isWindows) { const native = require('../build/Release/windows_process_tree.node'); + describe('getAllProcesses', () => { + it('should return a list containing this process', (done) => { + native.getProcessList((list) => { + assert.notStrictEqual(list?.find(p => p.pid === process.pid), undefined); + done(); + }, 0); + }); + + it('should work via API', (done) => { + const { getAllProcesses } = require('./index'); + getAllProcesses((list) => { + assert.ok(Array.isArray(list)); + assert.notStrictEqual(list.find(p => p.pid === process.pid), undefined); + done(); + }); + }); + + it('should work promisified', async () => { + const list = await promises.getAllProcesses(); + assert.ok(Array.isArray(list)); + assert.notStrictEqual(list.find(p => p.pid === process.pid), undefined); + }); + + it('should return memory information only when the flag is set', async () => { + const list = await promises.getAllProcesses(ProcessDataFlag.Memory); + assert.ok(list.some(p => typeof p.memory === 'number')); + }); + + it('should return command line information only when the flag is set', async () => { + const list = await promises.getAllProcesses(ProcessDataFlag.CommandLine); + assert.ok(list.every(p => typeof p.commandLine === 'string')); + }); + }); describe('getRawProcessList', () => { it('should throw if arguments are not provided', (done) => { assert.throws(() => native.getProcessList()); diff --git a/typings/windows-process-tree.d.ts b/typings/windows-process-tree.d.ts index 4206857..ffbd66a 100644 --- a/typings/windows-process-tree.d.ts +++ b/typings/windows-process-tree.d.ts @@ -75,7 +75,7 @@ declare module '@vscode/windows-process-tree' { /** * Returns a list of all processes on the system. - * @param callback - The callback to use with the returned set of processes. + * @param callback - The callback to use with the returned list of processes. * @param flags - The flags for what process data should be included. */ export function getAllProcesses(callback: (processList: IProcessInfo[]) => void, flags?: ProcessDataFlag): void; diff --git a/typings/windows-process-tree/promises.d.ts b/typings/windows-process-tree/promises.d.ts index 25d8422..ce1cbb5 100644 --- a/typings/windows-process-tree/promises.d.ts +++ b/typings/windows-process-tree/promises.d.ts @@ -37,4 +37,10 @@ declare module '@vscode/windows-process-tree/promises' { * @param processList - The list of processes. */ export function getProcessCpuUsage(processList: IProcessInfo[]): Promise; + + /** + * Returns a list of all processes on the system. + * @param flags - The flags for what process data should be included. + */ + export function getAllProcesses(flags?: ProcessDataFlag): Promise; } From 86de9cc5949ed4688305498ec647bc52a24c4518 Mon Sep 17 00:00:00 2001 From: ZA139 Date: Mon, 26 Jan 2026 20:22:24 +0800 Subject: [PATCH 3/3] Fix formatting and clarify test description Corrected spacing in array declaration in index.ts, added missing newline in promises.ts and typings, and clarified the test description for getAllProcesses to specify use of the native API. --- lib/index.ts | 2 +- lib/promises.ts | 2 +- lib/test.ts | 2 +- typings/windows-process-tree.d.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index acbdd58..7b53aad 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -244,5 +244,5 @@ export namespace getAllProcesses { // Since symbol properties can't be declared via namespace merging, we just define __promisify__ that way and // and manually set the "modern" promisify symbol: https://github.com/microsoft/TypeScript/issues/36813 -[getProcessTree, getProcessList, getProcessCpuUsage,getAllProcesses].forEach(func => +[getProcessTree, getProcessList, getProcessCpuUsage, getAllProcesses].forEach(func => Object.defineProperty(func, promisify.custom, { enumerable: false, value: func.__promisify__ })); diff --git a/lib/promises.ts b/lib/promises.ts index 5dca8dc..c60cf3b 100644 --- a/lib/promises.ts +++ b/lib/promises.ts @@ -12,4 +12,4 @@ export { ProcessDataFlag } from './index'; export const getProcessTree = promisify(wpc.getProcessTree); export const getProcessList = promisify(wpc.getProcessList); export const getProcessCpuUsage = promisify(wpc.getProcessCpuUsage); -export const getAllProcesses = promisify(wpc.getAllProcesses); \ No newline at end of file +export const getAllProcesses = promisify(wpc.getAllProcesses); diff --git a/lib/test.ts b/lib/test.ts index b5bc932..dddf6a8 100644 --- a/lib/test.ts +++ b/lib/test.ts @@ -28,7 +28,7 @@ if (isWindows) { const native = require('../build/Release/windows_process_tree.node'); describe('getAllProcesses', () => { - it('should return a list containing this process', (done) => { + it('should return a list containing this process via native API', (done) => { native.getProcessList((list) => { assert.notStrictEqual(list?.find(p => p.pid === process.pid), undefined); done(); diff --git a/typings/windows-process-tree.d.ts b/typings/windows-process-tree.d.ts index ffbd66a..70e242b 100644 --- a/typings/windows-process-tree.d.ts +++ b/typings/windows-process-tree.d.ts @@ -83,4 +83,4 @@ declare module '@vscode/windows-process-tree' { namespace getAllProcesses { function __promisify__(flags?: ProcessDataFlag): Promise; } -} \ No newline at end of file +}