<commit_before>'use strict';

const Glob = require('glob');
const Hoek = require('@hapi/hoek');
const Joi = require('@hapi/joi');
const Path = require('path');
const Util = require('util');
const Prefix = require('./prefix');

module.exports.getFiles = (baseDir, pattern) => {

    if (Array.isArray(baseDir)) {
        const files = baseDir.map(async (d) => await this.getFiles(d, pattern));
        return Promise.resolve(files);
    }

    const absolutePattern = Path.join(baseDir, pattern);
    const glob = Util.promisify(Glob);
    return glob(absolutePattern, {});
};
<commit_msg>Fix the way promises are handled here.<commit_after>'use strict';

const Glob = require('glob');
const Hoek = require('@hapi/hoek');
const Joi = require('@hapi/joi');
const Path = require('path');
const Util = require('util');
const Prefix = require('./prefix');

module.exports.getFiles = (baseDir, pattern) => {

    if (Array.isArray(baseDir)) {
        const promise = new Promise((resolve, reject) => {
            Promise.all(baseDir.map((d) => this.getFiles(d, pattern)))
                .then((value) => resolve(Hoek.flatten(value)))
                .catch((reason) => reject(reason));
        })
        return promise;
    }

    const absolutePattern = Path.join(baseDir, pattern);
    const glob = Util.promisify(Glob);
    return glob(absolutePattern, {});
};

{'fraction_non_alphanumeric': 0.16972814107274062, 'fraction_numerical': 0.0, 'mean_word_length': 3.585858585858586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '461866', 'n_tokens_mistral': 419, 'n_tokens_neox': 413, 'n_words': 97}