Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TypeScript definition to CommonJS compatible export #31

Merged
merged 1 commit into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}