<commit_before>import postcss from 'postcss';
import cosmiconfig from 'cosmiconfig';
import isResolvable from 'is-resolvable';
import defaultPreset from 'lerna:cssnano-preset-default';

const cssnano = 'cssnano';

const explorer = cosmiconfig(cssnano, {
    rc: false,
    argv: false,
});

function initializePlugin (plugin, css, result) {
    if (Array.isArray(plugin)) {
        const [processor, opts] = plugin;
        if (
            typeof opts === 'undefined' ||
            (typeof opts === 'object' && !opts.exclude)
        ) {
            return Promise.resolve(
                processor(opts)(css, result)
            );
        }
    } else {
        return Promise.resolve(
            plugin()(css, result)
        );
    }
    // Handle excluded plugins
    return Promise.resolve();
}

function fromFile (css, result) {
    const filePath = css.source.input && css.source.input.file || process.cwd();
    result.messages.push({
        type: 'debug',
        plugin: cssnano,
        message: `Using config relative to "${filePath}"`,
    });
    return filePath;
}

/*
 * preset can be one of four possibilities:
 * preset = 'default'
 * preset = ['default', {}]
 * preset = function <- to be invoked
 * preset = {plugins: []} <- already invoked function
 */

function resolvePreset (preset) {
    let fn, options;
    if (Array.isArray(preset)) {
        fn = preset[0];
        options = preset[1];
    } else {
        fn = preset;
        options = {};
    }
    // For JS setups where we invoked the preset already
    if (preset.plugins) {
        return Promise.resolve(preset.plugins);
    }<commit_msg>Fix resolveConfig for Root without source<commit_after>import postcss from 'postcss';
import cosmiconfig from 'cosmiconfig';
import isResolvable from 'is-resolvable';
import defaultPreset from 'lerna:cssnano-preset-default';

const cssnano = 'cssnano';

const explorer = cosmiconfig(cssnano, {
    rc: false,
    argv: false,
});

function initializePlugin (plugin, css, result) {
    if (Array.isArray(plugin)) {
        const [processor, opts] = plugin;
        if (
            typeof opts === 'undefined' ||
            (typeof opts === 'object' && !opts.exclude)
        ) {
            return Promise.resolve(
                processor(opts)(css, result)
            );
        }
    } else {
        return Promise.resolve(
            plugin()(css, result)
        );
    }
    // Handle excluded plugins
    return Promise.resolve();
}

function fromFile (css, result) {
    const filePath = css.source && css.source.input && css.source.input.file || process.cwd();
    result.messages.push({
        type: 'debug',
        plugin: cssnano,
        message: `Using config relative to "${filePath}"`,
    });
    return filePath;
}

/*
 * preset can be one of four possibilities:
 * preset = 'default'
 * preset = ['default', {}]
 * preset = function <- to be invoked
 * preset = {plugins: []} <- already invoked function
 */

function resolvePreset (preset) {
    let fn, options;
    if (Array.isArray(preset)) {
        fn = preset[0];
        options = preset[1];
    } else {
        fn = preset;
        options = {};
    }
    // For JS setups where we invoked the preset already
    if (preset.plugins) {
        return Promise.resolve(preset.plugins);
    }
{'fraction_non_alphanumeric': 0.13036902601330913, 'fraction_numerical': 0.0012099213551119178, 'mean_word_length': 2.3710499490316006, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1757238', 'n_tokens_mistral': 985, 'n_tokens_neox': 977, 'n_words': 268}