<commit_before>import Q from 'q';
import path from 'path';
import { exec } from 'child_process';
import _ from 'lodash';
import debug from 'debug';
import feathers from 'feathers';

const log = debug('mysam:plugins');

export default function() {
  const app = this;
  const plugins = app.service('plugins');
  const loadPlugin = moduleName => {
    try {
      let pkgPath = require.resolve(path.join(moduleName, 'package.json'));

      let pkg = require(pkgPath);
      let config = pkg.mysam;
      
      if(!config) {
        return Q(null);
      }

      log(`Found plugin ${pkg.name}`);

      let dirname = path.dirname(pkgPath);
      let staticPath = path.join(dirname, config.public || '.');

      log(`Setting up ${staticPath} at /${pkg.name}`);

      app.use(`/${pkg.name}`, feathers.static(staticPath));

      return Q.ninvoke(plugins, 'create', pkg)
        .then(() => {
          try {
            let pluginLoader = require(moduleName);
            pluginLoader(app);
          } catch(e) {
            log(`No server configuration module for ${pkg.name}.`);
          }
        });
    } catch(e) {
      debug(`Not loading plugin module ${moduleName}`);
      return Q(null);
    }
  };

  Q.nfcall(exec, 'npm ls --depth 0 -g --parseable').then(stdout => {
    let modules = stdout.toString().trim().split('\n');

    return Q.all(modules.map(path => loadPlugin(path)));
  }).fail(error => console.error(error.stack));;
}<commit_msg>Fix tests<commit_after>import Q from 'q';
import path from 'path';
import { exec } from 'child_process';
import debug from 'debug';
import feathers from 'feathers';

const log = debug('mysam:plugins');

export default function() {
  const app = this;
  const plugins = app.service('plugins');
  const loadPlugin = moduleName => {
    try {
      let pkgPath = require.resolve(path.join(moduleName, 'package.json'));

      let pkg = require(pkgPath);
      let config = pkg.mysam;

      if(!config) {
        return Q(null);
      }

      log(`Found plugin ${pkg.name}`);

      let dirname = path.dirname(pkgPath);
      let staticPath = path.join(dirname, config.public || '.');

      log(`Setting up ${staticPath} at /${pkg.name}`);

      app.use(`/${pkg.name}`, feathers.static(staticPath));

      return Q.ninvoke(plugins, 'create', pkg)
        .then(() => {
          try {
            let pluginLoader = require(moduleName);
            pluginLoader(app);
          } catch(e) {
            log(`No server configuration module for ${pkg.name}.`);
          }
        });
    } catch(e) {
      debug(`Not loading plugin module ${moduleName}`);
      return Q(null);
    }
  };

  Q.nfcall(exec, 'npm ls --depth 0 -g --parseable').then(stdout => {
    let modules = stdout.toString().trim().split('\n');

    return Q.all(modules.map(path => loadPlugin(path)));
  }).fail(error => console.error(error.stack));
}
{'fraction_non_alphanumeric': 0.16591461298160362, 'fraction_numerical': 0.0006942034015966678, 'mean_word_length': 2.6481012658227847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3773201', 'n_tokens_mistral': 891, 'n_tokens_neox': 869, 'n_words': 216}