From 9c6f89d59b51c2a95e22468e45130e42c054907a Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 31 Mar 2019 11:58:09 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#31) --- index.d.ts | 93 ++++++++++++++++++++++++++++++------------------- index.js | 1 + index.test-d.ts | 5 +-- package.json | 6 ++-- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/index.d.ts b/index.d.ts index d8d5fce..3c9711c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,43 +1,64 @@ -export interface Options { - /** - * Include other users' processes as well as your own. - * - * On Windows this has no effect and will always be the users' own processes. - * - * @default true - */ - readonly all?: boolean; -} +declare namespace psList { + interface Options { + /** + Include other users' processes as well as your own. -export interface ProcessDescriptor { - readonly pid: number; - readonly name: string; - readonly ppid: number; + On Windows this has no effect and will always be the users' own processes. - /** - * Not supported on Windows. - */ - readonly cmd?: string; + @default true + */ + readonly all?: boolean; + } - /** - * Not supported on Windows. - */ - readonly cpu?: number; + interface ProcessDescriptor { + readonly pid: number; + readonly name: string; + readonly ppid: number; - /** - * Not supported on Windows. - */ - readonly memory?: number; + /** + Not supported on Windows. + */ + readonly cmd?: string; - /** - * Not supported on Windows. - */ - readonly uid?: number; + /** + Not supported on Windows. + */ + readonly cpu?: number; + + /** + Not supported on Windows. + */ + readonly memory?: number; + + /** + Not supported on Windows. + */ + readonly uid?: number; + } } -/** - * Get running processes. - * - * @returns List of running processes. - */ -export default function psList(options?: Options): Promise; +declare const psList: { + /** + Get running processes. + + @returns List of running processes. + + @example + ``` + import psList = require('ps-list'); + + (async () => { + console.log(await psList()); + //=> [{pid: 3213, name: 'node', cmd: 'node test.js', ppid: 1, uid: 501, cpu: 0.1, memory: 1.5}, …] + })(); + ``` + */ + (options?: psList.Options): Promise; + + // TODO: remove this in the next major version, refactor the whole definition to: + // declare function psList(options?: psList.Options): Promise; + // export = psList; + default: typeof psList; +}; + +export = psList; diff --git a/index.js b/index.js index 920167f..2008ab2 100644 --- a/index.js +++ b/index.js @@ -59,4 +59,5 @@ const main = async (options = {}) => { }; module.exports = process.platform === 'win32' ? windows : main; +// TODO: remove this in the next major version module.exports.default = module.exports; diff --git a/index.test-d.ts b/index.test-d.ts index 72ee0cb..5ac7e51 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,6 @@ -import {expectType} from 'tsd-check'; -import psList, {ProcessDescriptor} from '.'; +import {expectType} from 'tsd'; +import psList = require('.'); +import {ProcessDescriptor} from '.'; const processes: ProcessDescriptor[] = await psList(); psList({all: false}); diff --git a/package.json b/package.json index 228a205..124439c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=8" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -30,8 +30,8 @@ "tasklist" ], "devDependencies": { - "ava": "^1.3.1", - "tsd-check": "^0.3.0", + "ava": "^1.4.1", + "tsd": "^0.7.1", "xo": "^0.24.0" } }