<commit_before>import fs = require('mz/fs')
import path = require('path')
import flatten = require('arr-flatten')
import pFilter = require('p-filter')

export default async function (modules: string): Promise<string[]> {
  const dirs = await getDirectories(modules)
  const subdirs = await Promise.all(
    dirs.map((dir: string): Promise<string[]> => {
      return isScopedPkgsDir(dir) ? getDirectories(dir) : Promise.resolve([dir])
    })
  )
  return flatten(subdirs)
}

async function getDirectories (srcPath: string): Promise<string[]> {
  let dirs: string[]
  try {
    dirs = await fs.readdir(srcPath)
  } catch (err) {
    if ((<NodeJS.ErrnoException>err).code !== 'ENOENT') {
      throw err
    }
    dirs = []
  }
  return pFilter(
    dirs
      .filter(relativePath => relativePath[0] !== '.') // ignore directories like .bin, .store, etc
      .map(relativePath => path.join(srcPath, relativePath)),
    async (absolutePath: string) => {
      const stats = await fs.stat(absolutePath)
      return stats.isDirectory()
    }
  )
}

function isScopedPkgsDir (dirPath: string) {
  return path.basename(dirPath)[0] === '@'
}<commit_msg>fix: skip not found dir in getPkgDirs<commit_after>import fs = require('mz/fs')
import path = require('path')
import flatten = require('arr-flatten')
import pFilter = require('p-filter')
import logger from 'pnpm-logger'

export default async function (modules: string): Promise<string[]> {
  const dirs = await getDirectories(modules)
  const subdirs = await Promise.all(
    dirs.map((dir: string): Promise<string[]> => {
      return isScopedPkgsDir(dir) ? getDirectories(dir) : Promise.resolve([dir])
    })
  )
  return flatten(subdirs)
}

async function getDirectories (srcPath: string): Promise<string[]> {
  let dirs: string[]
  try {
    dirs = await fs.readdir(srcPath)
  } catch (err) {
    if ((<NodeJS.ErrnoException>err).code !== 'ENOENT') {
      throw err
    }
    dirs = []
  }
  return pFilter(
    dirs
      .filter(relativePath => relativePath[0] !== '.') // ignore directories like .bin, .store, etc
      .map(relativePath => path.join(srcPath, relativePath)),
    async (absolutePath: string) => {
      try {
        const stats = await fs.stat(absolutePath)
        return stats.isDirectory()
      } catch (err) {
        if (err!.code !== 'ENOENT') throw err
        logger.warn(`Cannot find file at ${absolutePath} although it was listed by readdir`)
        return false
      }
    }
  )
}

function isScopedPkgsDir (dirPath: string) {
  return path.basename(dirPath)[0] === '@'
}
{'fraction_non_alphanumeric': 0.1457600625244236, 'fraction_numerical': 0.0015631105900742479, 'mean_word_length': 3.491228070175439, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '3584429', 'n_tokens_mistral': 829, 'n_tokens_neox': 823, 'n_words': 203}