@codechecks/client
Version:
Open source platform for code review automation
28 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const errors_1 = require("../utils/errors");
async function moduleExecutor(module, options) {
const hasDefaultExport = !!module.default;
const hasMainExport = !!module.main;
const hasDefaultCommonExport = util_1.isFunction(module);
if (!hasDefaultExport && !hasMainExport && !hasDefaultCommonExport) {
throw errors_1.crash("Your CodeChecks file has to export default export or function named 'main'");
}
if ([hasDefaultExport, hasMainExport, hasDefaultCommonExport].filter(x => x === true).length > 1) {
throw errors_1.crash("Your CodeChecks file can't export default export, 'main' function and default commonjs export at the same time!");
}
let fn;
if (hasMainExport) {
fn = module.main;
}
if (hasDefaultExport) {
fn = module.default;
}
if (hasDefaultCommonExport) {
fn = module;
}
await fn(options);
}
exports.moduleExecutor = moduleExecutor;
//# sourceMappingURL=moduleExecutor.js.map