@ionic/utils-process
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -59,3 +59,2 @@ /// <reference types="node" /> | ||
export declare function offBeforeExit(fn: ExitFn): void; | ||
export declare type Signal = 'process.exit' | NodeJS.Signals; | ||
/** | ||
@@ -62,0 +61,0 @@ * Asynchronous `process.exit()`, for running functions registered with |
@@ -111,6 +111,5 @@ "use strict"; | ||
exports.offBeforeExit = offBeforeExit; | ||
const BEFORE_EXIT_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK']; | ||
const beforeExitHandlerWrapper = (signal) => lodash.once(async () => { | ||
debug(`onBeforeExit handler: ${signal} received`); | ||
debug(`onBeforeExit handler: running ${exitFns.size} functions`); | ||
debug('onBeforeExit handler: %O received', signal); | ||
debug('onBeforeExit handler: running %O functions', exitFns.size); | ||
await Promise.all([...exitFns.values()].map(async (fn) => { | ||
@@ -124,7 +123,16 @@ try { | ||
})); | ||
debug(`onBeforeExit handler: exiting (exit code ${process.exitCode ? process.exitCode : 0})`); | ||
process.exit(); | ||
if (signal !== 'process.exit') { | ||
debug('onBeforeExit handler: killing self (exit code %O, signal %O)', process.exitCode ? process.exitCode : 0, signal); | ||
process.removeListener(signal, BEFORE_EXIT_SIGNAL_LISTENERS[signal]); | ||
process.kill(process.pid, signal); | ||
} | ||
}); | ||
for (const signal of BEFORE_EXIT_SIGNALS) { | ||
process.on(signal, beforeExitHandlerWrapper(signal)); | ||
const BEFORE_EXIT_SIGNAL_LISTENERS = { | ||
SIGINT: beforeExitHandlerWrapper('SIGINT'), | ||
SIGTERM: beforeExitHandlerWrapper('SIGTERM'), | ||
SIGHUP: beforeExitHandlerWrapper('SIGHUP'), | ||
SIGBREAK: beforeExitHandlerWrapper('SIGBREAK'), | ||
}; | ||
for (const [signal, fn] of lodash.entries(BEFORE_EXIT_SIGNAL_LISTENERS)) { | ||
process.on(signal, fn); | ||
} | ||
@@ -139,3 +147,5 @@ const processExitHandler = beforeExitHandlerWrapper('process.exit'); | ||
await processExitHandler(); | ||
debug('processExit: exiting (exit code: %O)', process.exitCode); | ||
process.exit(); | ||
} | ||
exports.processExit = processExit; |
{ | ||
"name": "@ionic/utils-process", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "Process utils for NodeJS", | ||
@@ -39,4 +39,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@ionic/utils-object": "1.0.0-beta.1", | ||
"@ionic/utils-terminal": "1.0.0-beta.1", | ||
"@ionic/utils-object": "1.0.0-beta.2", | ||
"@ionic/utils-terminal": "1.0.0-beta.2", | ||
"debug": "^4.0.0", | ||
@@ -60,3 +60,3 @@ "lodash": "^4.17.5", | ||
}, | ||
"gitHead": "ef8296bb16d44c6065b4467782a6a42ca0d5422f" | ||
"gitHead": "d82bfdec8826557b816befcac1f220688e55f7ca" | ||
} |
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
10431
211
+ Added@ionic/utils-object@1.0.0-beta.2(transitive)
+ Added@ionic/utils-terminal@1.0.0-beta.2(transitive)
- Removed@ionic/utils-object@1.0.0-beta.1(transitive)
- Removed@ionic/utils-terminal@1.0.0-beta.1(transitive)