Skip to content

Commit

Permalink
Require Node.js 6, add TypeScript definition (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 17, 2019
1 parent f4b230d commit 36c4d4a
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,4 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
2 changes: 1 addition & 1 deletion fixture-custom-log.js
@@ -1,5 +1,5 @@
'use strict';
const hardRejection = require('./');
const hardRejection = require('.');

hardRejection(str => {
console.log('custom-log', str);
Expand Down
2 changes: 1 addition & 1 deletion fixture.js
@@ -1,5 +1,5 @@
'use strict';
const hardRejection = require('./');
const hardRejection = require('.');

hardRejection();

Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
@@ -0,0 +1,6 @@
/**
Make unhandled promise rejections fail hard right away instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2).
@param log - Custom logging function to print the rejected promise. Receives the error stack. Default: `console.error`.
*/
export default function hardRejection(log?: (stack?: string) => void): void;
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -3,7 +3,7 @@ const util = require('util');

let installed = false;

module.exports = log => {
const hardRejection = log => {
if (installed) {
return;
}
Expand All @@ -17,6 +17,9 @@ module.exports = log => {
}

log(err.stack);
process.exit(1); // eslint-disable-line unicorn/no-process-exit
process.exit(1);
});
};

module.exports = hardRejection;
module.exports.default = hardRejection;
6 changes: 6 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,6 @@
import {expectType} from 'tsd-check';
import hardRejection from '.';
import './register';

expectType<void>(hardRejection());
expectType<void>(hardRejection(console.log));
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88 changes: 45 additions & 43 deletions package.json
@@ -1,45 +1,47 @@
{
"name": "hard-rejection",
"version": "1.0.0",
"description": "Make unhandled promise rejections fail hard right away instead of the default silent fail",
"license": "MIT",
"repository": "sindresorhus/hard-rejection",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"register.js"
],
"keywords": [
"promise",
"promises",
"unhandled",
"uncaught",
"rejection",
"hard",
"fail",
"catch",
"throw",
"handler",
"exit",
"debug",
"debugging",
"verbose",
"immediate",
"immediately"
],
"devDependencies": {
"ava": "*",
"execa": "^0.6.0",
"xo": "*"
}
"name": "hard-rejection",
"version": "1.0.0",
"description": "Make unhandled promise rejections fail hard right away instead of the default silent fail",
"license": "MIT",
"repository": "sindresorhus/hard-rejection",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts",
"register.js"
],
"keywords": [
"promise",
"promises",
"unhandled",
"uncaught",
"rejection",
"hard",
"fail",
"catch",
"throw",
"handler",
"exit",
"debug",
"debugging",
"verbose",
"immediate",
"immediately"
],
"devDependencies": {
"ava": "^1.3.1",
"execa": "^1.0.0",
"tsd-check": "^0.5.0",
"xo": "^0.24.0"
}
}
2 changes: 1 addition & 1 deletion register.js
@@ -1,2 +1,2 @@
'use strict';
require('./')();
require('.')();
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -2,13 +2,13 @@ import test from 'ava';
import execa from 'execa';

test('main', async t => {
const err = await t.throws(execa('node', ['fixture.js']));
const err = await t.throwsAsync(execa('node', ['fixture.js']));
t.is(err.code, 1);
t.regex(err.stderr, /^Error: Unicorn/);
});

test('custom logging', async t => {
const err = await t.throws(execa('node', ['fixture-custom-log.js']));
const err = await t.throwsAsync(execa('node', ['fixture-custom-log.js']));
t.is(err.code, 1);
t.regex(err.stdout, /^custom-log Error: Unicorn/);
});

0 comments on commit 36c4d4a

Please sign in to comment.