<commit_before>'use strict';

process.env.DEBUG = 'digs:plugins';

let Promise = require('bluebird');
let path = require('path');
let _ = require('lodash');
let pkg = require('../package.json');
let domain = require('domain');
let Joi = require('joi');
let findup = require('findup');
let fs = require('fs');
let digsUtil = require('digs-common/digs-util');

const PACKAGE_JSON = 'package.json';
const PLUGIN_REGEX = new RegExp(`^${pkg.name}-?plugin$`);
const CHARSET = 'utf8';
const NODE_MODULES = 'node_modules';

let join = path.join;
let debug = require('debug')('digs:plugins');
let makeError = digsUtil.makeError;

Promise.promisifyAll(fs);

let Plugins = {

  autoDetect(cwd) {
    return Plugins.discoverPlugins(cwd)
      .then(Plugins.requirePlugins)
      .catch(function (err) {
        debug(`Could not autodetect plugins: ${String(err)}`);
        throw makeError(err);
      });
  },

  discoverPlugins() {
    let cwd = join(__dirname, '..');
    // find the parent package.json
    debug(`Discovering plugins within "${cwd}"`);
    return findup(cwd, PACKAGE_JSON)
      .catch(function (err) {
        debug('package.json not found');
        throw makeError(err);
      })
      .then(function (parentPkgPath) {
        let readFile = fs.readFileAsync;
        // read it
        let parentPkg = join(parentPkgPath, PACKAGE_JSON);
        debug(`Reading dependencies from "${parentPkg}"`);
        return readFile(parentPkg, CHARSET)
          .then(function (pkgFile) {
            // map each dependency to its path within the parent
            // (siblings of this module)
            let pkg = JSON.parse(pkgFile);
            let pkgPaths = _.mapValues(pkg.dependencies,
              function (version, pkgName) {
                return join(parentPkgPath, NODE_MODULES, pkgName);
              });
            let numDeps = _.size(pkgPaths);<commit_msg>actually look for plugins amongst siblings<commit_after>'use strict';

process.env.DEBUG = 'digs:plugins';

let Promise = require('bluebird');
let path = require('path');
let _ = require('lodash');
let pkg = require('../package.json');
let domain = require('domain');
let Joi = require('joi');
let findup = require('findup');
let fs = require('fs');
let digsUtil = require('digs-common/digs-util');

const PACKAGE_JSON = 'package.json';
const PLUGIN_REGEX = new RegExp(`^${pkg.name}-?plugin$`);
const CHARSET = 'utf8';
const NODE_MODULES = 'node_modules';

let join = path.join;
let debug = require('debug')('digs:plugins');
let makeError = digsUtil.makeError;

Promise.promisifyAll(fs);

let Plugins = {

  autoDetect(cwd) {
    return Plugins.discoverPlugins(cwd)
      .then(Plugins.requirePlugins)
      .catch(function (err) {
        debug(`Could not autodetect plugins: ${String(err)}`);
        throw makeError(err);
      });
  },

  discoverPlugins() {
    let cwd = join(__dirname, '..', '..');
    // find the parent package.json
    debug(`Discovering plugins within "${cwd}"`);
    return findup(cwd, PACKAGE_JSON)
      .catch(function (err) {
        debug('package.json not found');
        throw makeError(err);
      })
      .then(function (parentPkgPath) {
        let readFile = fs.readFileAsync;
        // read it
        let parentPkg = join(parentPkgPath, PACKAGE_JSON);
        debug(`Reading dependencies from "${parentPkg}"`);
        return readFile(parentPkg, CHARSET)
          .then(function (pkgFile) {
            // map each dependency to its path within the parent
            // (siblings of this module)
            let pkg = JSON.parse(pkgFile);
            let pkgPaths = _.mapValues(pkg.dependencies,
              function (version, pkgName) {
                return join(parentPkgPath, NODE_MODULES, pkgName);
              });
            let numDeps = _.size(pkgPaths);
{'fraction_non_alphanumeric': 0.14255599472990776, 'fraction_numerical': 0.0005270092226613965, 'mean_word_length': 2.9582898852971846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3045649', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1172, 'n_words': 282}