fix: remove left over code, use proper names

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 2c33595507
commit 0ac49d63d9

@ -17,54 +17,33 @@ 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') {
return origFn.apply(null, args);
}
return promiseFn.apply(null, arguments);
};
}
function wrapIt(origFn, callbackFn) {
return async function wrapper(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
const cb = args.pop(); const cb = args.pop();
args.push(function (err, res) { args.push(function (err, res) {
if (err) { return res !== undefined ? cb(err, res) : cb(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 callbackFn.apply(null, args);
} }
@ -72,6 +51,17 @@ module.exports = function (theModule, ignoreKeys) {
}; };
} }
function wrapPromise(origFn, promiseFn) {
return function wrapperPromise(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
return origFn.apply(null, args);
}
return promiseFn.apply(null, arguments);
};
}
var parts = [];
function deprecateRecursive(module, key) { function deprecateRecursive(module, key) {
if (!module) { if (!module) {
return; return;

Loading…
Cancel
Save