<commit_before>import { DEPENDENCIES_FIELDS } from '@pnpm/types'
import archy = require('archy')
import chalk from 'chalk'
import cliColumns = require('cli-columns')
import { DependenciesHierarchy, PackageNode } from 'dependencies-hierarchy'
import path = require('path')
import R = require('ramda')
import getPkgInfo from './getPkgInfo'

const sortPackages = R.sortBy(R.path(['pkg', 'name']) as (pkg: object) => R.Ord)

const DEV_DEP_ONLY_CLR = chalk.yellow
const PROD_DEP_CLR = (s: string) => s // just use the default color
const OPTIONAL_DEP_CLR = chalk.blue
const NOT_SAVED_DEP_CLR = chalk.red

const LEGEND = `Legend: ${PROD_DEP_CLR('production dependency')}, ${OPTIONAL_DEP_CLR('optional only')}, ${DEV_DEP_ONLY_CLR('dev only')}\n\n`

export default async function (
  project: {
    name?: string,
    version?: string,
    path: string,
  },
  tree: DependenciesHierarchy,
  opts: {
    alwaysPrintRootPackage: boolean,
    depth: number,
    long: boolean,
    search: boolean,
  },
) {
  if (
    !opts.alwaysPrintRootPackage &&
    (!tree.dependencies || !tree.dependencies.length) &&
    (!tree.devDependencies || !tree.devDependencies.length) &&
    (!tree.optionalDependencies || !tree.optionalDependencies.length) &&
    (!tree.unsavedDependencies || !tree.unsavedDependencies.length)
  ) return ''

  let label = ''
  if (project.name) {
    label += project.name
    if (project.version) {
      label += `@${project.version}`
    }
    label += ' '
  }
  label += project.path
  let output = (opts.depth > -1 ? LEGEND : '') + label + '\n'
  const useColumns = opts.depth === 0 && opts.long === false && !opts.search
  for (let dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
    if (tree[dependenciesField] && tree[dependenciesField]!.length) {
      const depsLabel = chalk.cyanBright(
        dependenciesField !== 'unsavedDependencies'
          ? `${dependenciesField}:`
          : 'not saved (you should add these dependencies to package.json if you need them):'
      )
      output += `\n${depsLabel}\n`
      const gPkgColor = dependenciesField === 'unsavedDependencies' ? () => NOT_SAVED_DEP_CLR : getPkgColor
      if (useColumns && tree[dependenciesField].length > 10) {
        output += cliColumns(tree[dependenciesField].map(printLabel.bind(printLabel,  gPkgColor))) + '\n'
        continue
      }
      const data = await toArchyTree(gPkgColor, tree[dependenciesField]!, {
        long: opts.long,
        modules: path.join(project.path, 'node_modules'),
      })
      for (const d of data) {
        output += archy(d)
      }
    }
  }

  return output.replace(/\n$/, '')
}

type GetPkgColor = (node: PackageNode) => (s: string) => string
<commit_msg>style(list): remove multiple spaces<commit_after>import { DEPENDENCIES_FIELDS } from '@pnpm/types'
import archy = require('archy')
import chalk from 'chalk'
import cliColumns = require('cli-columns')
import { DependenciesHierarchy, PackageNode } from 'dependencies-hierarchy'
import path = require('path')
import R = require('ramda')
import getPkgInfo from './getPkgInfo'

const sortPackages = R.sortBy(R.path(['pkg', 'name']) as (pkg: object) => R.Ord)

const DEV_DEP_ONLY_CLR = chalk.yellow
const PROD_DEP_CLR = (s: string) => s // just use the default color
const OPTIONAL_DEP_CLR = chalk.blue
const NOT_SAVED_DEP_CLR = chalk.red

const LEGEND = `Legend: ${PROD_DEP_CLR('production dependency')}, ${OPTIONAL_DEP_CLR('optional only')}, ${DEV_DEP_ONLY_CLR('dev only')}\n\n`

export default async function (
  project: {
    name?: string,
    version?: string,
    path: string,
  },
  tree: DependenciesHierarchy,
  opts: {
    alwaysPrintRootPackage: boolean,
    depth: number,
    long: boolean,
    search: boolean,
  },
) {
  if (
    !opts.alwaysPrintRootPackage &&
    (!tree.dependencies || !tree.dependencies.length) &&
    (!tree.devDependencies || !tree.devDependencies.length) &&
    (!tree.optionalDependencies || !tree.optionalDependencies.length) &&
    (!tree.unsavedDependencies || !tree.unsavedDependencies.length)
  ) return ''

  let label = ''
  if (project.name) {
    label += project.name
    if (project.version) {
      label += `@${project.version}`
    }
    label += ' '
  }
  label += project.path
  let output = (opts.depth > -1 ? LEGEND : '') + label + '\n'
  const useColumns = opts.depth === 0 && opts.long === false && !opts.search
  for (let dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
    if (tree[dependenciesField] && tree[dependenciesField]!.length) {
      const depsLabel = chalk.cyanBright(
        dependenciesField !== 'unsavedDependencies'
          ? `${dependenciesField}:`
          : 'not saved (you should add these dependencies to package.json if you need them):'
      )
      output += `\n${depsLabel}\n`
      const gPkgColor = dependenciesField === 'unsavedDependencies' ? () => NOT_SAVED_DEP_CLR : getPkgColor
      if (useColumns && tree[dependenciesField].length > 10) {
        output += cliColumns(tree[dependenciesField].map(printLabel.bind(printLabel, gPkgColor))) + '\n'
        continue
      }
      const data = await toArchyTree(gPkgColor, tree[dependenciesField]!, {
        long: opts.long,
        modules: path.join(project.path, 'node_modules'),
      })
      for (const d of data) {
        output += archy(d)
      }
    }
  }

  return output.replace(/\n$/, '')
}

type GetPkgColor = (node: PackageNode) => (s: string) => string

{'fraction_non_alphanumeric': 0.1454711802378774, 'fraction_numerical': 0.001463860933211345, 'mean_word_length': 3.5894206549118386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '948397', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1731, 'n_words': 395}