This commit is contained in:
Stephen Franceschelli 2019-07-30 13:41:05 -04:00
parent 596a6da241
commit c1a589c5b6
7078 changed files with 1882834 additions and 319 deletions

38
node_modules/capture-exit/README.md generated vendored Normal file
View file

@ -0,0 +1,38 @@
# capture-exit
[![Build status](https://ci.appveyor.com/api/projects/status/8044m918rwic8b9n/branch/master?svg=true)](https://ci.appveyor.com/project/embercli/capture-exit/branch/master)
[![Build Status](https://travis-ci.org/ember-cli/capture-exit.svg?branch=master)](https://travis-ci.org/ember-cli/capture-exit)
Allow cooprative async exit handlers, we unfortunately must hijack
process.exit.
It allows a handler to ensure exit, without that exit handler impeding other
similar handlers
for example, see: [sindresorhus/ora#27](https://github.com/sindresorhus/ora/issues/27)
Differences between `process.on('exit')` and `captureExit.onExit(...)` => https://github.com/ember-cli/capture-exit/issues/12
### Installation
```sh
yarn add capture-exit
// or
npm install --save capture-exit
```
### Usage
```js
// as early in startup as possible
require('capture-exit').captureExit();
// when you want to schedule some work on exit:
function onExit() {
return something.processWillExit(); // you can return promises, which will pause exit until fulfilled
}
require('capture-exit').onExit(onExit); // add an exit handler
require('capture-exit').offExit(onExit); // allows one to remove an exit handle if it is not longer required
```

153
node_modules/capture-exit/index.js generated vendored Normal file
View file

@ -0,0 +1,153 @@
var RSVP = require('rsvp');
var exit;
var handlers = [];
var lastTime;
var isExiting = false;
process.on('beforeExit', function (code) {
if (handlers.length === 0) { return; }
var own = lastTime = module.exports._flush(lastTime, code)
.finally(function () {
// if an onExit handler has called process.exit, do not disturb
// `lastTime`.
//
// Otherwise, clear `lastTime` so that we know to synchronously call the
// real `process.exit` with the given exit code, when our captured
// `process.exit` is called during a `process.on('exit')` handler
//
// This is impossible to reason about, don't feel bad. Just look at
// test-natural-exit-subprocess-error.js
if (own === lastTime) {
lastTime = undefined;
}
});
});
// This exists only for testing
module.exports._reset = function () {
module.exports.releaseExit();
handlers = [];
lastTime = undefined;
isExiting = false;
firstExitCode = undefined;
}
/*
* To allow cooperative async exit handlers, we unfortunately must hijack
* process.exit.
*
* It allows a handler to ensure exit, without that exit handler impeding other
* similar handlers
*
* for example, see: https://github.com/sindresorhus/ora/issues/27
*
*/
module.exports.releaseExit = function() {
if (exit) {
process.exit = exit;
exit = null;
}
};
var firstExitCode;
module.exports.captureExit = function() {
if (exit) {
// already captured, no need to do more work
return;
}
exit = process.exit;
process.exit = function(code) {
if (handlers.length === 0 && lastTime === undefined) {
// synchronously exit.
//
// We do this brecause either
//
// 1. The process exited due to a call to `process.exit` but we have no
// async work to do because no handlers had been attached. It
// doesn't really matter whether we take this branch or not in this
// case.
//
// 2. The process exited naturally. We did our async work during
// `beforeExit` and are in this function because someone else has
// called `process.exit` during an `on('exit')` hook. The only way
// for us to preserve the exit code in this case is to exit
// synchronously.
//
return exit.call(process, code);
}
if (firstExitCode === undefined) {
firstExitCode = code;
}
var own = lastTime = module.exports._flush(lastTime, firstExitCode)
.then(function() {
// if another chain has started, let it exit
if (own !== lastTime) { return; }
exit.call(process, firstExitCode);
})
.catch(function(error) {
// if another chain has started, let it exit
if (own !== lastTime) {
throw error;
}
console.error(error);
exit.call(process, 1);
});
};
};
module.exports._handlers = handlers;
module.exports._flush = function(lastTime, code) {
isExiting = true;
var work = handlers.splice(0, handlers.length);
return RSVP.Promise.resolve(lastTime).
then(function() {
var firstRejected;
return RSVP.allSettled(work.map(function(handler) {
return RSVP.resolve(handler.call(null, code)).catch(function(e) {
if (!firstRejected) {
firstRejected = e;
}
throw e;
});
})).then(function(results) {
if (firstRejected) {
throw firstRejected;
}
});
});
};
module.exports.onExit = function(cb) {
if (!exit) {
throw new Error('Cannot install handler when exit is not captured. Call `captureExit()` first');
}
if (isExiting) {
throw new Error('Cannot install handler while `onExit` handlers are running.');
}
var index = handlers.indexOf(cb);
if (index > -1) { return; }
handlers.push(cb);
};
module.exports.offExit = function(cb) {
var index = handlers.indexOf(cb);
if (index < 0) { return; }
handlers.splice(index, 1);
};
module.exports.exit = function() {
exit.apply(process, arguments);
};
module.exports.listenerCount = function() {
return handlers.length;
};

63
node_modules/capture-exit/package.json generated vendored Normal file
View file

@ -0,0 +1,63 @@
{
"_from": "capture-exit@^2.0.0",
"_id": "capture-exit@2.0.0",
"_inBundle": false,
"_integrity": "sha512-PiT/hQmTonHhl/HFGN+Lx3JJUznrVYJ3+AQsnthneZbvW7x+f08Tk7yLJTLEOUvBTbduLeeBkxEaYXUOUrRq6g==",
"_location": "/capture-exit",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "capture-exit@^2.0.0",
"name": "capture-exit",
"escapedName": "capture-exit",
"rawSpec": "^2.0.0",
"saveSpec": null,
"fetchSpec": "^2.0.0"
},
"_requiredBy": [
"/sane"
],
"_resolved": "https://registry.npmjs.org/capture-exit/-/capture-exit-2.0.0.tgz",
"_shasum": "fb953bfaebeb781f62898239dabb426d08a509a4",
"_spec": "capture-exit@^2.0.0",
"_where": "E:\\github\\setup-java\\node_modules\\sane",
"author": {
"name": "Stefan Penner",
"email": "stefan.penner@gmail.com"
},
"bugs": {
"url": "https://github.com/stefanpenner/capture-exit/issues"
},
"bundleDependencies": false,
"dependencies": {
"rsvp": "^4.8.4"
},
"deprecated": false,
"description": "safely cleanup in signal handlers",
"devDependencies": {
"chai": "^4.2.0",
"execa": "1.0.0",
"mocha": "^5.2.0",
"ora": "^3.0.0"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
},
"files": [
"index.js"
],
"homepage": "https://github.com/stefanpenner/capture-exit#readme",
"license": "ISC",
"main": "index.js",
"name": "capture-exit",
"repository": {
"type": "git",
"url": "git+https://github.com/stefanpenner/capture-exit.git"
},
"scripts": {
"test": "mocha test",
"test:debug": "mocha debug test"
},
"version": "2.0.0"
}