Sha256: d47ba826a01cb1a263079da9773681a65992fa7cf7d2b7dcb28502aa0a57ed4c

Contents?: true

Size: 1.59 KB

Versions: 17

Compression:

Stored size: 1.59 KB

Contents

var fs = require('fs');
var path = require('path');

var helper = require('./helper');
var log = require('./logger').create('plugin');


var IGNORED_PACKAGES = ['karma-cli', 'karma-runner.github.com'];

exports.resolve = function(plugins) {
  var modules = [];

  var requirePlugin = function(name) {
    log.debug('Loading plugin %s.', name);
    try {
      modules.push(require(name));
    } catch (e) {
      if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(name) !== -1) {
        log.warn('Cannot find plugin "%s".\n  Did you forget to install it ?\n' +
                 '  npm install %s --save-dev', name, name);
      } else {
        log.warn('Error during loading "%s" plugin:\n  %s', name, e.message);
      }
    }
  };

  plugins.forEach(function(plugin) {
    if (helper.isString(plugin)) {
      if (plugin.indexOf('*') !== -1) {
        var pluginDirectory = path.normalize(__dirname + '/../..');
        var regexp = new RegExp('^' + plugin.replace('*', '.*'));

        log.debug('Loading %s from %s', plugin, pluginDirectory);
        fs.readdirSync(pluginDirectory).filter(function(pluginName) {
          return IGNORED_PACKAGES.indexOf(pluginName) === -1 && regexp.test(pluginName);
        }).forEach(function(pluginName) {
          requirePlugin(pluginDirectory + '/' + pluginName);
        });
      } else {
        requirePlugin(plugin);
      }
    } else if (helper.isObject(plugin)) {
      log.debug('Loading inlined plugin (defining %s).', Object.keys(plugin).join(', '));
      modules.push(plugin);
    } else {
      log.warn('Invalid plugin %s', plugin);
    }
  });

  return modules;
};

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/lib/plugin.js
hooch-0.4.1 jasmine/node_modules/karma/lib/plugin.js
hooch-0.4.0 jasmine/node_modules/karma/lib/plugin.js
hooch-0.3.0 jasmine/node_modules/karma/lib/plugin.js
hooch-0.2.1 jasmine/node_modules/karma/lib/plugin.js
hooch-0.2.0 jasmine/node_modules/karma/lib/plugin.js
hooch-0.1.0 jasmine/node_modules/karma/lib/plugin.js
hooch-0.0.8 jasmine/node_modules/karma/lib/plugin.js
hooch-0.0.7 jasmine/node_modules/karma/lib/plugin.js
hooch-0.0.6 jasmine/node_modules/karma/lib/plugin.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/lib/plugin.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/lib/plugin.js