mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
34 lines
658 B
JavaScript
34 lines
658 B
JavaScript
/* eslint no-console: 0 */
|
|
|
|
// Created to workaround a limitation of tabtab package:
|
|
// https://github.com/mklabs/tabtab/issues/51
|
|
|
|
'use strict';
|
|
|
|
module.exports = (callback) => {
|
|
const original = console.log;
|
|
console.log = () => {};
|
|
const restore = () => (console.log = original);
|
|
let result;
|
|
try {
|
|
result = callback();
|
|
} catch (error) {
|
|
restore();
|
|
throw error;
|
|
}
|
|
if (result && typeof result.then === 'function') {
|
|
return result.then(
|
|
(resolution) => {
|
|
restore();
|
|
return resolution;
|
|
},
|
|
(error) => {
|
|
restore();
|
|
throw error;
|
|
}
|
|
);
|
|
}
|
|
restore();
|
|
return result;
|
|
};
|