function runScriptViaModuleLoader()

in src/hooks/HooksRunner.js [142:161]


function runScriptViaModuleLoader (script, context) {
    if (!fs.existsSync(script.fullPath)) {
        events.emit('warn', 'Script file does\'t exist and will be skipped: ' + script.fullPath);
        return Promise.resolve();
    }
    const scriptFn = require(script.fullPath);
    context.scriptLocation = script.fullPath;
    if (script.plugin) {
        context.opts.plugin = script.plugin;
    }

    // We can't run script if it is a plain Node script - it will run its commands when we require it.
    // This is not a desired case as we want to pass context, but added for compatibility.
    if (scriptFn instanceof Function) {
        // If hook is async it can return promise instance and we will handle it.
        return Promise.resolve(scriptFn(context));
    } else {
        return Promise.resolve();
    }
}