Skip to content

Update dependencies to latest versions #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const

SIGINT = 'SIGINT',

SIGINT_LISTENER_NAME = '_tmp$sigint_listener'

// this will hold the objects need to be removed on exit
_removeObjects = [];

Expand Down Expand Up @@ -447,6 +445,8 @@ function _rimrafRemoveDirSyncWrapper(dirPath, next) {
}
}

const FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);

/**
* Prepares the callback for removal of the temporary directory.
*
Expand All @@ -457,7 +457,7 @@ function _rimrafRemoveDirSyncWrapper(dirPath, next) {
*/
function _prepareTmpDirRemoveCallback(name, opts) {
const removeFunction = opts.unsafeCleanup ? _rimrafRemoveDirWrapper : fs.rmdir.bind(fs);
const removeFunctionSync = opts.unsafeCleanup ? _rimrafRemoveDirSyncWrapper : fs.rmdirSync.bind(fs);
const removeFunctionSync = opts.unsafeCleanup ? _rimrafRemoveDirSyncWrapper : FN_RMDIR_SYNC;
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name);
const removeCallback = _prepareRemoveCallback(removeFunction, name, removeCallbackSync);
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
Expand Down Expand Up @@ -497,7 +497,14 @@ function _prepareRemoveCallback(removeFunction, arg, cleanupCallbackSync) {
// we will ignore the error
return next(err);
}
} else return removeFunction(arg, next);
} else {
// must no call rmdirSync/rmSync this way
if (removeFunction == FN_RMDIR_SYNC) {
return removeFunction(arg);
} else {
return removeFunction(arg, next);
}
}
} else return next(new Error('cleanup callback has already been called'));
};
}
Expand Down Expand Up @@ -610,43 +617,33 @@ function _is_legacy_listener(listener) {
*/
function _safely_install_sigint_listener() {

let listeners = process.listeners(SIGINT);
const listeners = process.listeners(SIGINT);
const existingListeners = [];
for (let i = 0, length = listeners.length; i < length; i++) {
const lstnr = listeners[i];
/* istanbul ignore else */
if (lstnr.name === SIGINT_LISTENER_NAME) {
if (lstnr.name === '_tmp$sigint_listener') {
existingListeners.push(lstnr);
process.removeListener(SIGINT, lstnr);
}
}
process.on(SIGINT, function _tmp$sigint_listener() {
process.on(SIGINT, function _tmp$sigint_listener(doExit) {
for (let i = 0, length = existingListeners.length; i < length; i++) {
// let the existing listener do the garbage collection (e.g. jest sandbox)
try {
// let the existing listener do the garbage collection (e.g. jest sandbox)
// pass in false in case that we are dealing with an old version of this
existingListeners[i](false);
existingListeners[i](false);
} catch (err) {
// ignore
}
}
// check if there are any user installed sigint listeners
// if there are none, exit the process
let doExit = true;
listeners = process.listeners(SIGINT);
for (let i = 0, length = listeners.length; i < length; i++) {
const lstnr = listeners[i];
if (lstnr.name !== SIGINT_LISTENER_NAME) {
doExit = false;
break;
}
}
// force the garbage collector even it is called again in the exit listener
_garbageCollector();
// exit the process if no user listeners have been installed
if (doExit) {
process.exit();
}
try {
// force the garbage collector even it is called again in the exit listener
_garbageCollector();
} finally {
if (!!doExit) {
process.exit(0);
}
}
});
}

Expand All @@ -672,11 +669,12 @@ function _safely_install_exit_listener() {
process.removeListener(EXIT, lstnr);
}
}
process.addListener(EXIT, function _tmp$safe_listener(code) {
// TODO: what was the data parameter good for?
process.addListener(EXIT, function _tmp$safe_listener(data) {
for (let i = 0, length = existingListeners.length; i < length; i++) {
// let the existing listener do the garbage collection (e.g. jest sandbox)
try {
// let the existing listener do the garbage collection (e.g. jest sandbox)
existingListeners[i](code);
existingListeners[i](data);
} catch (err) {
// ignore
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"node": ">=6"
},
"dependencies": {
"rimraf": "^2.6.3"
"rimraf": "^3.0.0"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-plugin-mocha": "^5.0.0",
"eslint": "^6.3.0",
"eslint-plugin-mocha": "^6.1.1",
"istanbul": "^0.4.5",
"mocha": "^5.1.1"
"mocha": "^6.2.0"
},
"main": "lib/tmp.js",
"files": [
Expand Down