<commit_before>import path from 'path';
import pkgUp from 'pkg-up';
import fse from 'fs-extra';
import defaultsDeep from 'lodash/defaultsDeep';
import { isPlainObject, get, toTitleCase } from '@terascope/utils';
import sortPackageJson from 'sort-package-json';
import { PackageInfo, RootPackageInfo, Service } from './interfaces';
import { NPM_DEFAULT_REGISTRY, DEV_TAG, DEV_DOCKER_IMAGE } from './config';
import signale from './signale';

let rootDir: string | undefined;

export function getRootDir(cwd: string = process.cwd()): string {
    if (rootDir) return rootDir;

    const rootPkgJSON = pkgUp.sync({ cwd });

    if (!rootPkgJSON) {
        const children = fse.readdirSync(cwd);
        throw new Error(`Unable to find root directory, run in the root of the repo. cwd is ${cwd}, rootPkgJSON is ${rootPkgJSON}, children: ${children.join('\n')}`);
    }

    if (_getRootInfo(rootPkgJSON) != null) {
        rootDir = path.dirname(rootPkgJSON);
        return rootDir;
    }

    const upOne = path.join(path.dirname(rootPkgJSON), '..');

    if (!fse.existsSync(upOne) || !fse.statSync(upOne).isDirectory()) {
        throw new Error('Unable to find root directory');
    }

    return getRootDir(upOne);
}

function _getRootInfo(pkgJSONPath: string): RootPackageInfo | undefined {
    const pkg = fse.readJSONSync(pkgJSONPath);
    const isRoot = get(pkg, 'terascope.root', false);<commit_msg>revert children logging<commit_after>import path from 'path';
import pkgUp from 'pkg-up';
import fse from 'fs-extra';
import defaultsDeep from 'lodash/defaultsDeep';
import { isPlainObject, get, toTitleCase } from '@terascope/utils';
import sortPackageJson from 'sort-package-json';
import { PackageInfo, RootPackageInfo, Service } from './interfaces';
import { NPM_DEFAULT_REGISTRY, DEV_TAG, DEV_DOCKER_IMAGE } from './config';
import signale from './signale';

let rootDir: string | undefined;

export function getRootDir(cwd: string = process.cwd()): string {
    if (rootDir) return rootDir;

    const rootPkgJSON = pkgUp.sync({ cwd });

    if (!rootPkgJSON) {
        throw new Error(`Unable to find root directory, run in the root of the repo. cwd is ${cwd}, rootPkgJSON is ${rootPkgJSON}`);
    }

    if (_getRootInfo(rootPkgJSON) != null) {
        rootDir = path.dirname(rootPkgJSON);
        return rootDir;
    }

    const upOne = path.join(path.dirname(rootPkgJSON), '..');

    if (!fse.existsSync(upOne) || !fse.statSync(upOne).isDirectory()) {
        throw new Error('Unable to find root directory');
    }

    return getRootDir(upOne);
}

function _getRootInfo(pkgJSONPath: string): RootPackageInfo | undefined {
    const pkg = fse.readJSONSync(pkgJSONPath);
    const isRoot = get(pkg, 'terascope.root', false);
{'fraction_non_alphanumeric': 0.1291499452754469, 'fraction_numerical': 0.0, 'mean_word_length': 4.134831460674158, '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': '654053', 'n_tokens_mistral': 889, 'n_tokens_neox': 865, 'n_words': 240}