stuff
This commit is contained in:
62
buildfiles/node_modules/async-exit-hook/CHANGELOG.md
generated
vendored
Normal file
62
buildfiles/node_modules/async-exit-hook/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
<a name="2.0.1"></a>
|
||||
## [2.0.1](https://github.com/tapppi/async-exit-hook/compare/v2.0.0...v2.0.1) (2017-08-03)
|
||||
|
||||
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
# [2.0.0](https://github.com/tapppi/async-exit-hook/compare/v1.1.2...v2.0.0) (2017-08-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add unhandledRejectionHandler ([#3](https://github.com/tapppi/async-exit-hook/issues/3)) ([96a194f](https://github.com/tapppi/async-exit-hook/commit/96a194f))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* unhandledExceptionHandler no longer
|
||||
catches rejections.
|
||||
|
||||
|
||||
|
||||
<a name="1.1.2"></a>
|
||||
## [1.1.2](https://github.com/tapppi/async-exit-hook/compare/v1.1.1...v1.1.2) (2017-03-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* filters are used individually for events [#1](https://github.com/tapppi/async-exit-hook/issues/1) ([03235c8](https://github.com/tapppi/async-exit-hook/commit/03235c8))
|
||||
|
||||
|
||||
|
||||
<a name="1.1.1"></a>
|
||||
## [1.1.1](https://github.com/tapppi/async-exit-hook/compare/v1.1.0...v1.1.1) (2016-11-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* unhandled rejections now handled ([4302b9e](https://github.com/tapppi/async-exit-hook/commit/4302b9e))
|
||||
|
||||
|
||||
### Chores
|
||||
|
||||
* drop support for node 0.12 ([2830391](https://github.com/tapppi/async-exit-hook/commit/2830391))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* node 0.12 not tested anymore
|
||||
|
||||
|
||||
|
||||
<a name="1.1.0"></a>
|
||||
# [1.1.0](https://github.com/tapppi/async-exit-hook/compare/v1.0.0...v1.1.0) (2016-10-13)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support uncaughtRejectionHandler ([9098e3c](https://github.com/tapppi/async-exit-hook/commit/9098e3c))
|
171
buildfiles/node_modules/async-exit-hook/index.js
generated
vendored
Normal file
171
buildfiles/node_modules/async-exit-hook/index.js
generated
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
|
||||
const hooks = [];
|
||||
const errHooks = [];
|
||||
let called = false;
|
||||
let waitingFor = 0;
|
||||
let asyncTimeoutMs = 10000;
|
||||
|
||||
const events = {};
|
||||
const filters = {};
|
||||
|
||||
function exit(exit, code, err) {
|
||||
// Helper functions
|
||||
let doExitDone = false;
|
||||
|
||||
function doExit() {
|
||||
if (doExitDone) {
|
||||
return;
|
||||
}
|
||||
doExitDone = true;
|
||||
|
||||
if (exit === true) {
|
||||
// All handlers should be called even if the exit-hook handler was registered first
|
||||
process.nextTick(process.exit.bind(null, code));
|
||||
}
|
||||
}
|
||||
|
||||
// Async hook callback, decrements waiting counter
|
||||
function stepTowardExit() {
|
||||
process.nextTick(() => {
|
||||
if (--waitingFor === 0) {
|
||||
doExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Runs a single hook
|
||||
function runHook(syncArgCount, err, hook) {
|
||||
// Cannot perform async hooks in `exit` event
|
||||
if (exit && hook.length > syncArgCount) {
|
||||
// Hook is async, expects a finish callback
|
||||
waitingFor++;
|
||||
|
||||
if (err) {
|
||||
// Pass error, calling uncaught exception handlers
|
||||
return hook(err, stepTowardExit);
|
||||
}
|
||||
return hook(stepTowardExit);
|
||||
}
|
||||
|
||||
// Hook is synchronous
|
||||
if (err) {
|
||||
// Pass error, calling uncaught exception handlers
|
||||
return hook(err);
|
||||
}
|
||||
return hook();
|
||||
}
|
||||
|
||||
// Only execute hooks once
|
||||
if (called) {
|
||||
return;
|
||||
}
|
||||
|
||||
called = true;
|
||||
|
||||
// Run hooks
|
||||
if (err) {
|
||||
// Uncaught exception, run error hooks
|
||||
errHooks.map(runHook.bind(null, 1, err));
|
||||
}
|
||||
hooks.map(runHook.bind(null, 0, null));
|
||||
|
||||
if (waitingFor) {
|
||||
// Force exit after x ms (10000 by default), even if async hooks in progress
|
||||
setTimeout(() => {
|
||||
doExit();
|
||||
}, asyncTimeoutMs);
|
||||
} else {
|
||||
// No asynchronous hooks, exit immediately
|
||||
doExit();
|
||||
}
|
||||
}
|
||||
|
||||
// Add a hook
|
||||
function add(hook) {
|
||||
hooks.push(hook);
|
||||
|
||||
if (hooks.length === 1) {
|
||||
add.hookEvent('exit');
|
||||
add.hookEvent('beforeExit', 0);
|
||||
add.hookEvent('SIGHUP', 128 + 1);
|
||||
add.hookEvent('SIGINT', 128 + 2);
|
||||
add.hookEvent('SIGTERM', 128 + 15);
|
||||
add.hookEvent('SIGBREAK', 128 + 21);
|
||||
|
||||
// PM2 Cluster shutdown message. Caught to support async handlers with pm2, needed because
|
||||
// explicitly calling process.exit() doesn't trigger the beforeExit event, and the exit
|
||||
// event cannot support async handlers, since the event loop is never called after it.
|
||||
add.hookEvent('message', 0, function (msg) { // eslint-disable-line prefer-arrow-callback
|
||||
if (msg !== 'shutdown') {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// New signal / event to hook
|
||||
add.hookEvent = function (event, code, filter) {
|
||||
events[event] = function () {
|
||||
const eventFilters = filters[event];
|
||||
for (let i = 0; i < eventFilters.length; i++) {
|
||||
if (eventFilters[i].apply(this, arguments)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
exit(code !== undefined && code !== null, code);
|
||||
};
|
||||
|
||||
if (!filters[event]) {
|
||||
filters[event] = [];
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
filters[event].push(filter);
|
||||
}
|
||||
process.on(event, events[event]);
|
||||
};
|
||||
|
||||
// Unhook signal / event
|
||||
add.unhookEvent = function (event) {
|
||||
process.removeListener(event, events[event]);
|
||||
delete events[event];
|
||||
delete filters[event];
|
||||
};
|
||||
|
||||
// List hooked events
|
||||
add.hookedEvents = function () {
|
||||
const ret = [];
|
||||
for (const name in events) {
|
||||
if ({}.hasOwnProperty.call(events, name)) {
|
||||
ret.push(name);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
// Add an uncaught exception handler
|
||||
add.uncaughtExceptionHandler = function (hook) {
|
||||
errHooks.push(hook);
|
||||
|
||||
if (errHooks.length === 1) {
|
||||
process.once('uncaughtException', exit.bind(null, true, 1));
|
||||
}
|
||||
};
|
||||
|
||||
// Add an unhandled rejection handler
|
||||
add.unhandledRejectionHandler = function (hook) {
|
||||
errHooks.push(hook);
|
||||
|
||||
if (errHooks.length === 1) {
|
||||
process.once('unhandledRejection', exit.bind(null, true, 1));
|
||||
}
|
||||
};
|
||||
|
||||
// Configure async force exit timeout
|
||||
add.forceExitTimeout = function (ms) {
|
||||
asyncTimeoutMs = ms;
|
||||
};
|
||||
|
||||
// Export
|
||||
module.exports = add;
|
21
buildfiles/node_modules/async-exit-hook/license
generated
vendored
Normal file
21
buildfiles/node_modules/async-exit-hook/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
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:
|
||||
|
||||
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.
|
96
buildfiles/node_modules/async-exit-hook/package.json
generated
vendored
Normal file
96
buildfiles/node_modules/async-exit-hook/package.json
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"_from": "async-exit-hook@^2.0.1",
|
||||
"_id": "async-exit-hook@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==",
|
||||
"_location": "/async-exit-hook",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "async-exit-hook@^2.0.1",
|
||||
"name": "async-exit-hook",
|
||||
"escapedName": "async-exit-hook",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/app-builder-lib",
|
||||
"/temp-file"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-exit-hook/-/async-exit-hook-2.0.1.tgz",
|
||||
"_shasum": "8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3",
|
||||
"_spec": "async-exit-hook@^2.0.1",
|
||||
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/app-builder-lib",
|
||||
"author": {
|
||||
"name": "Tapani Moilanen",
|
||||
"email": "moilanen.tapani@gmail.com",
|
||||
"url": "https://github.com/tapppi"
|
||||
},
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/*.js",
|
||||
"!tests/cases/*"
|
||||
]
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/tapppi/async-exit-hook/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "http://sindresorhus.com"
|
||||
}
|
||||
],
|
||||
"deprecated": false,
|
||||
"description": "Run some code when the process exits (supports async hooks and pm2 clustering)",
|
||||
"devDependencies": {
|
||||
"ava": "^0.21.0",
|
||||
"coveralls": "^2.11.14",
|
||||
"nyc": "^10.3.2",
|
||||
"standard-version": "^4.2.0",
|
||||
"xo": "^0.18.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/tapppi/async-exit-hook#readme",
|
||||
"keywords": [
|
||||
"exit",
|
||||
"quit",
|
||||
"process",
|
||||
"hook",
|
||||
"graceful",
|
||||
"handler",
|
||||
"shutdown",
|
||||
"sigterm",
|
||||
"sigint",
|
||||
"sighup",
|
||||
"pm2",
|
||||
"cluster",
|
||||
"child",
|
||||
"reload",
|
||||
"async",
|
||||
"terminate",
|
||||
"kill",
|
||||
"stop",
|
||||
"event"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "async-exit-hook",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tapppi/async-exit-hook.git"
|
||||
},
|
||||
"scripts": {
|
||||
"release": "standard-version",
|
||||
"test": "xo && nyc ava"
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
118
buildfiles/node_modules/async-exit-hook/readme.md
generated
vendored
Normal file
118
buildfiles/node_modules/async-exit-hook/readme.md
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
# async-exit-hook
|
||||
[](https://travis-ci.org/Tapppi/async-exit-hook)
|
||||
[](https://coveralls.io/github/Tapppi/async-exit-hook?branch=master)
|
||||
|
||||
> Run some code when the process exits
|
||||
|
||||
The `process.on('exit')` event doesn't catch all the ways a process can exit. This module catches:
|
||||
|
||||
* process SIGINT, SIGTERM and SIGHUP, SIGBREAK signals
|
||||
* process beforeExit and exit events
|
||||
* PM2 clustering process shutdown message ([PM2 graceful reload](http://pm2.keymetrics.io/docs/usage/cluster-mode/#graceful-reload))
|
||||
|
||||
Useful for cleaning up. You can also include async handlers, and add custom events to hook and exit on.
|
||||
|
||||
Forked and pretty much rewritten from [exit-hook](https://npmjs.com/package/exit-hook).
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save async-exit-hook
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Considerations and warning
|
||||
#### On `process.exit()` and asynchronous code
|
||||
**If you use asynchronous exit hooks, DO NOT use `process.exit()` to exit.
|
||||
The `exit` event DOES NOT support asynchronous code.**
|
||||
>['beforeExit' is not emitted for conditions causing explicit termination, such as process.exit()]
|
||||
(https://nodejs.org/api/process.html#process_event_beforeexit)
|
||||
|
||||
#### Windows and `process.kill(signal)`
|
||||
On windows `process.kill(signal)` immediately kills the process, and does not fire signal events,
|
||||
and as such, cannot be used to gracefully exit. See *Clustering and child processes* for a
|
||||
workaround when killing child processes. I'm planning to support gracefully exiting
|
||||
with async support on windows soon.
|
||||
|
||||
### Clustering and child processes
|
||||
If you use custom clustering / child processes, you can gracefully shutdown your child process
|
||||
by sending a shutdown message (`childProc.send('shutdown')`).
|
||||
|
||||
### Example
|
||||
```js
|
||||
const exitHook = require('async-exit-hook');
|
||||
|
||||
exitHook(() => {
|
||||
console.log('exiting');
|
||||
});
|
||||
|
||||
// you can add multiple hooks, even across files
|
||||
exitHook(() => {
|
||||
console.log('exiting 2');
|
||||
});
|
||||
|
||||
// you can add async hooks by accepting a callback
|
||||
exitHook(callback => {
|
||||
setTimeout(() => {
|
||||
console.log('exiting 3');
|
||||
callback();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// You can hook uncaught errors with uncaughtExceptionHandler(), consequently adding
|
||||
// async support to uncaught errors (normally uncaught errors result in a synchronous exit).
|
||||
exitHook.uncaughtExceptionHandler(err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
// You can hook unhandled rejections with unhandledRejectionHandler()
|
||||
exitHook.unhandledRejectionHandler(err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
// You can add multiple uncaught error handlers
|
||||
// Add the second parameter (callback) to indicate async hooks
|
||||
exitHook.uncaughtExceptionHandler((err, callback) => {
|
||||
sendErrorToCloudOrWhatever(err) // Returns promise
|
||||
.then(() => {
|
||||
console.log('Sent err to cloud');
|
||||
});
|
||||
.catch(sendError => {
|
||||
console.error('Error sending to cloud: ', err.stack));
|
||||
})
|
||||
.then(() => callback);
|
||||
});
|
||||
});
|
||||
|
||||
// Add exit hooks for a signal or custom message:
|
||||
|
||||
// Custom signal
|
||||
// Arguments are `signal, exitCode` (SIGBREAK is already handled, this is an example)
|
||||
exitHook.hookEvent('SIGBREAK', 21);
|
||||
|
||||
// process event: `message` with a filter
|
||||
// filter gets all arguments passed to *handler*: `process.on(message, *handler*)`
|
||||
// Exits on process event `message` with msg `customShutdownMessage` only
|
||||
exitHook.hookEvent('message', 0, msg => msg !== 'customShutdownMessage');
|
||||
|
||||
// All async hooks will work with uncaught errors when you have specified an uncaughtExceptionHandler
|
||||
throw new Error('awesome');
|
||||
|
||||
//=> // Sync uncaughtExcpetion hooks called and retun
|
||||
//=> '[Error: awesome]'
|
||||
//=> // Sync hooks called and retun
|
||||
//=> 'exiting'
|
||||
//=> 'exiting 2'
|
||||
//=> // Async uncaughtException hooks return
|
||||
//=> 'Sent error to cloud'
|
||||
//=> // Sync uncaughtException hooks return
|
||||
//=> 'exiting 3'
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © Tapani Moilanen
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
Reference in New Issue
Block a user