Comparing version 2.2.1 to 3.0.0
@@ -8,3 +8,3 @@ /** | ||
@param callback - The callback to execute when the process exits. | ||
@param onExit - The callback function to execute when the process exits. | ||
@returns A function that removes the hook when called. | ||
@@ -14,3 +14,3 @@ | ||
``` | ||
import exitHook = require('exit-hook'); | ||
import exitHook from 'exit-hook'; | ||
@@ -37,4 +37,2 @@ exitHook(() => { | ||
*/ | ||
declare function exitHook(callback: () => void): () => void; | ||
export = exitHook; | ||
export default function exitHook(onExit: () => void): () => void; |
18
index.js
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
import process from 'node:process'; | ||
@@ -7,3 +7,3 @@ const callbacks = new Set(); | ||
function exit(exit, signal) { | ||
function exit(shouldManuallyExit, signal) { | ||
if (isCalled) { | ||
@@ -19,3 +19,3 @@ return; | ||
if (exit === true) { | ||
if (shouldManuallyExit === true) { | ||
process.exit(128 + signal); // eslint-disable-line unicorn/no-process-exit | ||
@@ -25,4 +25,4 @@ } | ||
module.exports = callback => { | ||
callbacks.add(callback); | ||
export default function exitHook(onExit) { | ||
callbacks.add(onExit); | ||
@@ -33,4 +33,4 @@ if (!isRegistered) { | ||
process.once('exit', exit); | ||
process.once('SIGINT', exit.bind(null, true, 2)); | ||
process.once('SIGTERM', exit.bind(null, true, 15)); | ||
process.once('SIGINT', exit.bind(undefined, true, 2)); | ||
process.once('SIGTERM', exit.bind(undefined, true, 15)); | ||
@@ -48,4 +48,4 @@ // PM2 Cluster shutdown message. Caught to support async handlers with pm2, needed because | ||
return () => { | ||
callbacks.delete(callback); | ||
callbacks.delete(onExit); | ||
}; | ||
}; | ||
} |
{ | ||
"name": "exit-hook", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Run some code when the process exits", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -41,7 +43,7 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"execa": "^1.0.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"execa": "^5.1.1", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -18,3 +18,3 @@ # exit-hook | ||
```js | ||
const exitHook = require('exit-hook'); | ||
import exitHook from 'exit-hook'; | ||
@@ -39,3 +39,3 @@ exitHook(() => { | ||
```js | ||
const exitHook = require('exit-hook'); | ||
import exitHook from 'exit-hook'; | ||
@@ -49,11 +49,11 @@ const unsubscribe = exitHook(() => {}); | ||
### exitHook(callback) | ||
### exitHook(onExit) | ||
Returns a function that removes the hook when called. | ||
#### callback | ||
#### onExit | ||
Type: `Function` | ||
The callback to execute when the process exits. | ||
The callback function to execute when the process exits. | ||
@@ -60,0 +60,0 @@ --- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4956
Yes
61