<commit_before>import 'source-map-support/register';

import path from 'path';
import fs from 'fs';
import colors from 'colors/safe';
import deepExtend from 'deep-extend';

let onceApp = true;
let onceTemp = true;

let applicationConfigPath = '';
let temporaryConfig = {};

/**
 * Merges two configuration objects
 *
 * @param {!object} a - configuration object to merge into
 * @param {!object} b - configuration object that overwrites the other
 * @returns {object} The merged configuration object
 */
export function merge(a, b) {
    return deepExtend({}, a, b);
}

/**
 * Gets the application configuration by reading a file
 *
 * Will give a warning if ROC_CONFIG has been set since that will then be used as the path to get the configuration
 * file.
 *
 * Reads configuration files in this manner:
 * 1. Environment variable ROC_CONFIG
 * 2. A path that has been set using {@link setApplicationConfig}
 * 3. Default by trying to read "roc.config.js" in the current working directory
 * 4. Return a empty object
 *
 * @returns {object} The application configuration object
 * @throws {Error} When an invalid path override is specified
 */
export function getApplicationConfig() {
    if (applicationConfigPath && process.env.ROC_CONFIG && onceApp) {
        onceApp = false;
        console.log(colors.red('You have configured a location for the application configuration file but the ' +
            'environment variable ROC_CONFIG is set and that will be used instead. The path that will be used is ' +
            process.env.ROC_CONFIG
        ));
    }

    const configPath = process.env.ROC_CONFIG || applicationConfigPath;

    // path explicitly overriden. throw exception if override is invalid file
    if (configPath && !fs.statSync(configPath).isFile()) {
        throw new Error(`Configuration path points to unaccessable file: ${configPath}`);
    }

    // return correct project configuration with fallback to empty object
    try {
        return require(configPath || path.join(process.cwd(), 'roc.config.js')).config;
    } catch (error) {
        return {};
    }<commit_msg>Fixed a bug when the config file returns a obj w/o .config<commit_after>import 'source-map-support/register';

import path from 'path';
import fs from 'fs';
import colors from 'colors/safe';
import deepExtend from 'deep-extend';

let onceApp = true;
let onceTemp = true;

let applicationConfigPath = '';
let temporaryConfig = {};

/**
 * Merges two configuration objects
 *
 * @param {!object} a - configuration object to merge into
 * @param {!object} b - configuration object that overwrites the other
 * @returns {object} The merged configuration object
 */
export function merge(a, b) {
    return deepExtend({}, a, b);
}

/**
 * Gets the application configuration by reading a file
 *
 * Will give a warning if ROC_CONFIG has been set since that will then be used as the path to get the configuration
 * file.
 *
 * Reads configuration files in this manner:
 * 1. Environment variable ROC_CONFIG
 * 2. A path that has been set using {@link setApplicationConfig}
 * 3. Default by trying to read "roc.config.js" in the current working directory
 * 4. Return a empty object
 *
 * @returns {object} The application configuration object
 * @throws {Error} When an invalid path override is specified
 */
export function getApplicationConfig() {
    if (applicationConfigPath && process.env.ROC_CONFIG && onceApp) {
        onceApp = false;
        console.log(colors.red('You have configured a location for the application configuration file but the ' +
            'environment variable ROC_CONFIG is set and that will be used instead. The path that will be used is ' +
            process.env.ROC_CONFIG
        ));
    }

    const configPath = process.env.ROC_CONFIG || applicationConfigPath;

    // path explicitly overriden. throw exception if override is invalid file
    if (configPath && !fs.statSync(configPath).isFile()) {
        throw new Error(`Configuration path points to unaccessable file: ${configPath}`);
    }

    // return correct project configuration with fallback to empty object
    try {
        return require(configPath || path.join(process.cwd(), 'roc.config.js')).config || {};
    } catch (error) {
        return {};
    }
{'fraction_non_alphanumeric': 0.0939187602723644, 'fraction_numerical': 0.0018783752054472881, 'mean_word_length': 3.4842105263157896, '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': '5579235', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1106, 'n_words': 469}