Skip to content

Commit

Permalink
Merge pull request #4 from mrbar42/v0.3.1
Browse files Browse the repository at this point in the history
fix ts type file, add more strict ts testing
  • Loading branch information
mrbar42 authored Mar 24, 2018
2 parents 950692e + 255a541 commit 161a16c
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 23 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SignalListener = (done: () => void, event: any, signal: string) => (undefined | Promise<any>)
type SignalListener = (done: () => void, event: any, signal: string) => (undefined | Promise<void> | Promise<any> | Promise<Error>)
type cancelSubscription = () => void


Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +----------------------------------------------------------------------+
// | node-graceful v0.3.0 (https://github.com/mrbar42/node-graceful) |
// | node-graceful v0.3.1 (https://github.com/mrbar42/node-graceful) |
// | Graceful process exit manager. |
// |----------------------------------------------------------------------|
'use strict';
Expand Down Expand Up @@ -170,3 +170,7 @@ Graceful.prototype._invokeListener = function _invokeListener(listener, quit, ev

let graceful = new Graceful();
module.exports = graceful;

// monkey patch exports to support both old & new & Typescript module systems
module.exports.Graceful = graceful;
module.exports.default = graceful;
86 changes: 82 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-graceful",
"version": "0.3.0",
"version": "0.3.1",
"description": "Graceful process exit manager. allows waiting on multiple async services.",
"main": "index",
"repository": {
Expand All @@ -18,15 +18,18 @@
],
"scripts": {
"test:unit": "node tests/runner",
"test:lint": "tslint -c tslint.json --fix tests/*.ts",
"test": "npm run test:unit && npm run test:lint",
"test:unit-ts": "ts-node tests/wait-for-multiple-promise.ts",
"test:lint": "tsc && tslint -c tslint.json --fix tests/*.ts",
"test": "npm run test:lint && npm run test:unit && npm run test:unit-ts",
"transpile": "tsc --allowJs --outFile es5/index.js --pretty index.js ",
"prepublish": "npm run test && npm run transpile"
"prepublishOnly": "npm run test && npm run transpile"
},
"author": "mrbar42",
"license": "WTFPL",
"devDependencies": {
"@types/node": "9.6.0",
"ts-node": "5.0.1",
"tslint": "5.9.1",
"typescript": "2.6.2"
"typescript": "2.7.2"
}
}
14 changes: 10 additions & 4 deletions tests/TypeScript.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {Graceful} from "../";
import Graceful from "../";

const listener = (done, event, signal) => {
const listener = (done: () => {}, event: any, signal: string) => {
done();
};

const listenerPromise = (done, event, signal) => Promise.resolve();

const listenerPromise = (done: () => {}, event: any, signal: string) => Promise.resolve("abc");
Graceful.on("exit", listener);
const listenerPromise1 = (done: () => {}, event: any, signal: string) => Promise.resolve({});
Graceful.on("exit", listenerPromise1);
const listenerPromise2 = (done: () => {}, event: any, signal: string) => new Promise((resolve) => {
resolve();
});
Graceful.on("exit", listenerPromise2);

Graceful.on("exit", listener, true);
Graceful.on("exit", listenerPromise);
Graceful.on("exit", listenerPromise, true);
Expand Down
26 changes: 26 additions & 0 deletions tests/wait-for-multiple-promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

import Graceful from "../";

const handlerSuccess = () => {
return new Promise((resolve) => {
setTimeout(() => {
process.stdout.write("ok");
resolve();
}, 100);
});
};

const handlerReject = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
process.stdout.write("ok");
reject();
}, 200);
});
};

Graceful.on("exit", handlerSuccess);
Graceful.on("exit", handlerReject);

Graceful.exit();
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compileOnSave": false,
"compilerOptions": {
"target": "es2015",
"noImplicitAny": true,
"strictNullChecks": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": false,
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es2015"
]
}
}
13 changes: 5 additions & 8 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
]
}

0 comments on commit 161a16c

Please sign in to comment.