fix: remove left over code, use proper names

This commit is contained in:
Barış Soner Uşaklı
2019-07-09 23:09:25 -04:00
parent 2c33595507
commit 0ac49d63d9

View File

@@ -17,32 +17,42 @@ module.exports = function (theModule, ignoreKeys) {
return fn && fn.constructor && fn.constructor.name === 'AsyncFunction'; return fn && fn.constructor && fn.constructor.name === 'AsyncFunction';
} }
var parts = [];
function promisifyRecursive(module, key) { function promisifyRecursive(module) {
if (!module) { if (!module) {
return; return;
} }
if (key) {
parts.push(key);
}
var keys = Object.keys(module); var keys = Object.keys(module);
keys.forEach(function (key) { keys.forEach(function (key) {
if (ignoreKeys.includes(key)) { if (ignoreKeys.includes(key)) {
return; return;
} }
if (isAsyncFunction(module[key])) { if (isAsyncFunction(module[key])) {
module[key] = wrapIt(module[key], util.callbackify(module[key])); module[key] = wrapCallback(module[key], util.callbackify(module[key]));
} else if (isCallbackedFunction(module[key])) { } else if (isCallbackedFunction(module[key])) {
module[key] = wrapTwo(module[key], util.promisify(module[key])); module[key] = wrapPromise(module[key], util.promisify(module[key]));
} else if (typeof module[key] === 'object') { } else if (typeof module[key] === 'object') {
promisifyRecursive(module[key], key); promisifyRecursive(module[key]);
} }
}); });
parts.pop();
} }
function wrapTwo(origFn, promiseFn) { function wrapCallback(origFn, callbackFn) {
return function wrapper2(...args) { return async function wrapperCallback(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
const cb = args.pop();
args.push(function (err, res) {
return res !== undefined ? cb(err, res) : cb(err);
});
return callbackFn.apply(null, args);
}
return origFn.apply(null, arguments);
};
}
function wrapPromise(origFn, promiseFn) {
return function wrapperPromise(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
return origFn.apply(null, args); return origFn.apply(null, args);
} }
@@ -51,27 +61,7 @@ module.exports = function (theModule, ignoreKeys) {
}; };
} }
function wrapIt(origFn, callbackFn) { var parts = [];
return async function wrapper(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
const cb = args.pop();
args.push(function (err, res) {
if (err) {
return cb(err);
}
// fixes callbackified functions used in async.waterfall
if (res !== undefined) {
return cb(err, res);
}
return cb(err);
});
return callbackFn.apply(null, args);
}
return origFn.apply(null, arguments);
};
}
function deprecateRecursive(module, key) { function deprecateRecursive(module, key) {
if (!module) { if (!module) {
return; return;