From 7e25163d676b616b188428134d2cc7eb9a0a3748 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sat, 6 Apr 2024 20:27:11 +0300 Subject: [PATCH] feat: let `tree` opts be optional --- package.json | 2 +- src/main/ts/ps.ts | 7 +++++-- src/test/ts/ps.test.ts | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 572dd80..82d53dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webpod/ps", - "version": "0.0.0-beta.2", + "version": "0.0.0-beta.3", "description": "A process lookup utility", "publishConfig": { "access": "public" diff --git a/src/main/ts/ps.ts b/src/main/ts/ps.ts index 3f1924b..98f96a6 100644 --- a/src/main/ts/ps.ts +++ b/src/main/ts/ps.ts @@ -128,14 +128,17 @@ export const pickTree = (list: TPsLookupEntry[], pid: string | number, recursive ] } -export const tree = async (opts: string | number | TPsTreeOpts, cb: TPsLookupCallback = noop): Promise => { +export const tree = async (opts?: string | number | TPsTreeOpts | undefined, cb: TPsLookupCallback = noop): Promise => { if (typeof opts === 'string' || typeof opts === 'number') { return tree({ pid: opts }, cb) } try { + const all = await lookup() + if (opts === undefined) return all + const {pid, recursive = false} = opts - const list = pickTree(await lookup(), pid, recursive) + const list = pickTree(all, pid, recursive) cb(null, list) return list diff --git a/src/test/ts/ps.test.ts b/src/test/ts/ps.test.ts index 843709d..f41c74b 100644 --- a/src/test/ts/ps.test.ts +++ b/src/test/ts/ps.test.ts @@ -83,4 +83,9 @@ describe('tree()', () => { assert.equal((await lookup({ arguments: marker })).length, 0) }) + + it('returns all ps list if no opts provided', async () => { + const list = await tree() + assert.ok(list.length > 0) + }) })