<commit_before>import * as fs from 'fs'
import * as path from 'path'
import Promise = require('any-promise')
import stripBom = require('strip-bom')
import parseJson = require('parse-json')
import stripComments = require('strip-json-comments')

export interface LoadResult {
  path?: string
  config: any
}

const CONFIG_FILENAME = 'tsconfig.json'

/**
 * Resolve a configuration file, like `tsc`.
 */
export function resolve (cwd: string, filename?: string): Promise<string | void> {
  if (!filename) {
    return find(cwd)
  }

  const fullPath = path.join(cwd, filename)

  return stat(fullPath)
    .then<string | void>(stats => {
      if (isFile(stats)) {
        return fullPath
      }

      if (isDirectory(stats)) {
        const configFile = path.join(fullPath, CONFIG_FILENAME)

        return stat(configFile)
          .then(stats => {
            if (isFile(stats)) {
              return configFile
            }

            throw new TypeError(`Cannot find a ${CONFIG_FILENAME} file at the specified directory: ${filename}`)
          })
      }

      throw new TypeError(`The specified path does not exist: ${filename}`)
    })
}

/**
 * Synchronous `resolve`.
 */
export function resolveSync (cwd: string, filename?: string): string | void {
  if (!filename) {
    return findSync(cwd)
  }

  const fullPath = path.join(cwd, filename)
  const stats = statSync(fullPath)

  if (isFile(stats)) {
    return fullPath
  }

  if (isDirectory(stats)) {
    const configFile = path.join(fullPath, CONFIG_FILENAME)
    const stats = statSync(configFile)

    if (isFile(stats)) {
      return configFile
    }

    throw new TypeError(`Cannot find a ${CONFIG_FILENAME} file at the specified directory: ${filename}`)
  }

  throw new TypeError(`The specified path does not exist: ${filename}`)
}

/**
 * Resolve `tsconfig.json` from a directory.
 */
export function find (dir: string): Promise<string | void> {
  const configFile = path.resolve(dir, CONFIG_FILENAME)<commit_msg>Use `path.resolve` over `path.join` for resolving<commit_after>import * as fs from 'fs'
import * as path from 'path'
import Promise = require('any-promise')
import stripBom = require('strip-bom')
import parseJson = require('parse-json')
import stripComments = require('strip-json-comments')

export interface LoadResult {
  path?: string
  config: any
}

const CONFIG_FILENAME = 'tsconfig.json'

/**
 * Resolve a configuration file, like `tsc`.
 */
export function resolve (cwd: string, filename?: string): Promise<string | void> {
  if (!filename) {
    return find(cwd)
  }

  const fullPath = path.resolve(cwd, filename)

  return stat(fullPath)
    .then<string | void>(stats => {
      if (isFile(stats)) {
        return fullPath
      }

      if (isDirectory(stats)) {
        const configFile = path.join(fullPath, CONFIG_FILENAME)

        return stat(configFile)
          .then(stats => {
            if (isFile(stats)) {
              return configFile
            }

            throw new TypeError(`Cannot find a ${CONFIG_FILENAME} file at the specified directory: ${filename}`)
          })
      }

      throw new TypeError(`The specified path does not exist: ${filename}`)
    })
}

/**
 * Synchronous `resolve`.
 */
export function resolveSync (cwd: string, filename?: string): string | void {
  if (!filename) {
    return findSync(cwd)
  }

  const fullPath = path.resolve(cwd, filename)
  const stats = statSync(fullPath)

  if (isFile(stats)) {
    return fullPath
  }

  if (isDirectory(stats)) {
    const configFile = path.join(fullPath, CONFIG_FILENAME)
    const stats = statSync(configFile)

    if (isFile(stats)) {
      return configFile
    }

    throw new TypeError(`Cannot find a ${CONFIG_FILENAME} file at the specified directory: ${filename}`)
  }

  throw new TypeError(`The specified path does not exist: ${filename}`)
}

/**
 * Resolve `tsconfig.json` from a directory.
 */
export function find (dir: string): Promise<string | void> {
  const configFile = path.resolve(dir, CONFIG_FILENAME)
{'fraction_non_alphanumeric': 0.12182993535554451, 'fraction_numerical': 0.0, 'mean_word_length': 3.190625, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5063182', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1184, 'n_words': 350}