<commit_before>import {
  merge
} from 'lodash';
import * as path from 'path';
import findPlugins, { PluginSummary } from 'find-plugins';
import { execSync } from 'child_process';
import { sync as commandExists } from 'command-exists';
import * as YarnConstants from 'yarn/lib/constants';


/**
 * Discover any addons for the current directory. If the current directory is a Denali project, load
 * addons from the local node_modules folder, using the local package.json as a guide.
 *
 * If the current directory is not a Denali project, load the addons from the global node_modules
 * folder (both yarn and npm are supported), and scan all the global packages for addon (rather than
 * relying on a package.json guide).
 */
export default function findAddons(isLocal: boolean): PluginSummary[] {

  let findOptions = {
    sort: true,
    configName: 'denali',
    keyword: 'denali-addon'
  };

  if (isLocal) {
    return findPlugins(findOptions);
  }

  let addons = findPlugins(merge({
    dir: execSync('npm root -g').toString().trim(),
    scanAllDirs: true
  }, findOptions));

  // Because yarn stores it's global modules separately, and doesn't yet support the `root` command,
  // we have to double check yarn's global installs for any denali addons. The easiest way of
  // determining that location is to simply include yarn and require it directly. Ugly, but until
  // they add `root`, our best option. We have to do the same for linked packages to allow for
  // development of global addons (like denali itself)
  // TODO shell out to `yarn root` once yarnpkg/yarn#2388 is fixed
  if (commandExists('yarn')) {
    let globalInstalledYarnAddons = addons.concat(findPlugins(merge({
      dir: path.join(YarnConstants.GLOBAL_MODULE_DIRECTORY, 'node_modules'),
      scanAllDirs: true
    }, findOptions)));
    let globalLinkedYarnAddons = addons.concat(findPlugins(merge({
      dir: YarnConstants.LINK_REGISTRY_DIRECTORY,
      scanAllDirs: true
    }, findOptions)));
    addons = addons.concat(globalInstalledYarnAddons, globalLinkedYarnAddons);
  }

  return addons;
<commit_msg>chore: add some debugging output to find-addons<commit_after>import {
  merge
} from 'lodash';
import * as path from 'path';
import findPlugins, { PluginSummary } from 'find-plugins';
import { execSync } from 'child_process';
import { sync as commandExists } from 'command-exists';
import * as YarnConstants from 'yarn/lib/constants';
import * as createDebug from 'debug';

const debug = createDebug('denali-cli:find-addons');


/**
 * Discover any addons for the current directory. If the current directory is a Denali project, load
 * addons from the local node_modules folder, using the local package.json as a guide.
 *
 * If the current directory is not a Denali project, load the addons from the global node_modules
 * folder (both yarn and npm are supported), and scan all the global packages for addon (rather than
 * relying on a package.json guide).
 */
export default function findAddons(isLocal: boolean): PluginSummary[] {

  let findOptions = {
    sort: true,
    configName: 'denali',
    keyword: 'denali-addon'
  };

  if (isLocal) {
    debug(`searching for addons locally in ${ process.cwd() }`);
    return findPlugins(findOptions);
  }

  let npmRoot = execSync('npm root -g').toString().trim();
  debug(`searching for addons globally in npm root: ${ npmRoot }`);
  let addons = findPlugins(merge({
    dir: npmRoot,
    scanAllDirs: true
  }, findOptions));

  // Because yarn stores it's global modules separately, and doesn't yet support the `root` command,
  // we have to double check yarn's global installs for any denali addons. The easiest way of
  // determining that location is to simply include yarn and require it directly. Ugly, but until
  // they add `root`, our best option. We have to do the same for linked packages to allow for
  // development of global addons (like denali itself)
  // TODO shell out to `yarn root` once yarnpkg/yarn#2388 is fixed
  if (commandExists('yarn')) {
    let yarnGlobalInstalls = path.join(YarnConstants.GLOBAL_MODULE_DIRECTORY, 'node_modules');
    debug(`searching for addons globally in yarn global installs: ${ yarnGlobalInstalls }`);
    let globalInstalledYarnAddons = addons.concat(findPlugins(merge({
      dir: yarnGlobalInstalls,
      scanAllDirs: true
    }, findOptions)));
    let yarnGlobalLinks = YarnConstants.LINK_REGISTRY_DIRECTORY;
    debug(`searching for addons globally in yarn global links: ${ yarnGlobalLinks }`);
    let globalLinkedYarnAddons = addons.concat(findPlugins(merge({
      dir: yarnGlobalLinks,
      scanAllDirs: true
    }, findOptions)));
    addons = addons.concat(globalInstalledYarnAddons, globalLinkedYarnAddons);
  }

  return addons;

{'fraction_non_alphanumeric': 0.09490740740740741, 'fraction_numerical': 0.0016835016835016834, 'mean_word_length': 4.088865096359743, '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': '1956234', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1356, 'n_words': 511}