Stryker

PluginLoader.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
PluginLoader.js
79%
35/44 35 9 0 0 0 35 9 44

Code

"use strict";
var fs = require('fs');
var path = require('path');
var log4js = require('log4js');
var _ = require('lodash');
var fileUtils_1 = require('./utils/fileUtils');
var log = log4js.getLogger('PluginLoader');
var IGNORED_PACKAGES = ['stryker-cli', 'stryker-api'];
var PluginLoader = (function () 0{
    function PluginLoader(plugins) 1{
        this.plugins = plugins;
    }
    PluginLoader.prototype.load = function () 2{
        this.getModules().forEach(this.requirePlugin);
    };
    PluginLoader.prototype.getModules = function () 3{
        var modules = [];
        this.plugins.forEach(function (pluginExpression) 4{
            if (56_.isString(pluginExpression)) 7{
                if (8910pluginExpression.indexOf('*') !== 11-1) 12{
                    // Plugin directory is the node_modules folder of the module that installed stryker
                    // So if current __dirname is './stryker/src' than the plugin directory should be 2 directories above
                    var pluginDirectory_1 = path.normalize(13__dirname + '/../..');
                    var regexp_1 = new RegExp(14'^' + pluginExpression.replace('*', '.*'));
                    log.debug('Loading %s from %s', pluginExpression, pluginDirectory_1);
                    var plugins = fs.readdirSync(pluginDirectory_1)
                        .filter(function (pluginName) 15{ return 1617IGNORED_PACKAGES.indexOf(pluginName) === 18-1 && regexp_1.test(pluginName); })
                        .map(function (pluginName) 19{ return 2021pluginDirectory_1 + '/' + pluginName; });
                    if (222324plugins.length === 0) 25{
                        log.debug('Expression %s not resulted in plugins to load', pluginExpression);
                    }
                    plugins
                        .map(function (plugin) 26{ return path.basename(plugin); })
                        .map(function (plugin) 27{
                        log.debug('Loading plugins %s (matched with expression %s)', plugin, pluginExpression);
                        return plugin;
                    })
                        .forEach(function (p) 28{ return modules.push(p); });
                }
                else 29{
                    modules.push(pluginExpression);
                }
            }
            else 30{
                log.warn('Ignoring plugin %s, as its not a string type', pluginExpression);
            }
        });
        return modules;
    };
    PluginLoader.prototype.requirePlugin = function (name) 31{
        log.debug(32"Loading plugins " + name);
        try 33{
            fileUtils_1.importModule(name);
        }
        catch (e) 34{
            if (35363738e.code === 'MODULE_NOT_FOUND' && 39e.message.indexOf(name) !== 40-1) 41{
                log.warn(42'Cannot find plugin "%s".\n  Did you forget to install it ?\n' +
                    '  npm install %s --save-dev', name, name);
            }
            else 43{
                log.warn('Error during loading "%s" plugin:\n  %s', name, e.message);
            }
        }
    };
    return PluginLoader;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PluginLoader;
//# sourceMappingURL=PluginLoader.js.map