Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 31, 2019
1 parent 158f5db commit 9c6f89d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 41 deletions.
93 changes: 57 additions & 36 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<ProcessDescriptor[]>;
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<psList.ProcessDescriptor[]>;

// TODO: remove this in the next major version, refactor the whole definition to:
// declare function psList(options?: psList.Options): Promise<psList.ProcessDescriptor[]>;
// export = psList;
default: typeof psList;
};

export = psList;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 3 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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});
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -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"
}
}

0 comments on commit 9c6f89d

Please sign in to comment.