Comparing version 3.1.4 to 3.2.0
/** | ||
@callback onExit | ||
@param {number} signal - The exit code. | ||
*/ | ||
/** | ||
Run some code when the process exits. | ||
@@ -8,3 +13,3 @@ | ||
@param onExit - The callback function to execute when the process exits. | ||
@param {onExit} onExit - The callback function to execute when the process exits. | ||
@returns A function that removes the hook when called. | ||
@@ -16,4 +21,4 @@ | ||
exitHook(() => { | ||
console.log('Exiting'); | ||
exitHook(signal => { | ||
console.log(`Exiting with signal: ${signal}`); | ||
}); | ||
@@ -37,3 +42,3 @@ | ||
*/ | ||
export default function exitHook(onExit: () => void): () => void; | ||
export default function exitHook(onExit: (signal: number) => void): () => void; | ||
@@ -44,3 +49,3 @@ /** | ||
@see https://github.com/sindresorhus/exit-hook/blob/main/readme.md#asynchronous-exit-notes | ||
@param onExit - The callback function to execute when the process exits via `gracefulExit`, and will be wrapped in `Promise.resolve`. | ||
@param {onExit} onExit - The callback function to execute when the process exits via `gracefulExit`, and will be wrapped in `Promise.resolve`. | ||
@returns A function that removes the hook when called. | ||
@@ -68,3 +73,3 @@ | ||
*/ | ||
export function asyncExitHook(onExit: () => (void | Promise<void>), options: Options): () => void; | ||
export function asyncExitHook(onExit: (signal: number) => (void | Promise<void>), options: Options): () => void; | ||
@@ -71,0 +76,0 @@ /** |
@@ -26,5 +26,7 @@ import process from 'node:process'; | ||
const exitCode = 128 + signal; | ||
const done = (force = false) => { | ||
if (force === true || shouldManuallyExit === true) { | ||
process.exit(128 + signal); // eslint-disable-line unicorn/no-process-exit | ||
process.exit(exitCode); // eslint-disable-line unicorn/no-process-exit | ||
} | ||
@@ -34,3 +36,3 @@ }; | ||
for (const callback of callbacks) { | ||
callback(); | ||
callback(exitCode); | ||
} | ||
@@ -47,3 +49,3 @@ | ||
forceAfter = Math.max(forceAfter, wait); | ||
promises.push(Promise.resolve(callback())); | ||
promises.push(Promise.resolve(callback(exitCode))); | ||
} | ||
@@ -50,0 +52,0 @@ |
{ | ||
"name": "exit-hook", | ||
"version": "3.1.4", | ||
"version": "3.2.0", | ||
"description": "Run some code when the process exits", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -20,4 +20,4 @@ # exit-hook | ||
exitHook(() => { | ||
console.log('Exiting'); | ||
exitHook(signal => { | ||
console.log(`Exiting with signal: ${signal}`); | ||
}); | ||
@@ -56,3 +56,3 @@ | ||
Type: `() => void` | ||
Type: `(signal: number) => void` | ||
@@ -71,3 +71,3 @@ The callback function to execute when the process exits. | ||
Type: `() => (void | Promise<void>)` | ||
Type: `(signal: number) => (void | Promise<void>)` | ||
@@ -74,0 +74,0 @@ The callback function to execute when the process exits via `gracefulExit`, and will be wrapped in `Promise.resolve`. |
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
11224
181