<commit_before>var path = require('path'),
    resolveBabelrc = require('./lib/babelrc-util').resolveBabelrc,
    pattern = 'test/**/*.js',
    packageData,
    testDir,
    babelrc,
    extension = '.js';

// Override extension via (eg: `mocha --compilers <extension>:espower-babel/guess`)
process.argv.forEach(function (arg) {
    // <extension>:espower-babel/guess
    var args = arg.split(':');
    if (args.length <= 1) {
        return;
    }
    var filePath = args[1];
    var compilerFilePath = require.resolve(filePath);
    var compilerFileExtension = args[0];
    if (compilerFilePath !== module.filename) {
        return;
    }
    extension = '.' + compilerFileExtension;
});

packageData = require(path.join(process.cwd(), 'package.json'));
if (packageData &&
    typeof packageData.directories === 'object' &&
    typeof packageData.directories.test === 'string') {
    testDir = packageData.directories.test;
    pattern = testDir + ((testDir.lastIndexOf('/', 0) === 0) ? '' : '/') + '**/*' + extension;
}

babelrc = resolveBabelrc(process.cwd(), {});

require('./index')({
    cwd: process.cwd(),
    pattern: pattern,
    babelrc: babelrc,
    extension: extension
});<commit_msg>Improve process.argv sniffing<commit_after>const COMPILER_NAME = require('./package.json').name + '/guess';
var path = require('path'),
    resolveBabelrc = require('./lib/babelrc-util').resolveBabelrc,
    pattern = 'test/**/*.js',
    packageData,
    testDir,
    babelrc,
    extension = '.js';

// When guess.js is loaded in a process
// with an argument like <extension>:espower-babel/guess,
// such as `mocha --compilers <extension>:espower-babel/guess`,
// override extension with the specified one.
process.argv.forEach(function (arg) {
    if (!~arg.indexOf(':')) {
        return;
    }

    var parts = arg.split(':');
    var ext = parts[0];
    var compilerPath = parts[1];

    // We should handle the relative path `./guess`
    // to make our very own tests work.
    if (compilerPath === './guess') {
        var compilerFullPath;

        try {
            compilerFullPath = require.resolve(compilerPath);
        } catch(err) {}

        if (compilerFullPath !== module.filename) {
            return;
        }

        compilerPath = COMPILER_NAME;
    }

    if (compilerPath !== COMPILER_NAME) {
        return;
    }

    extension = '.' + ext;
});

packageData = require(path.join(process.cwd(), 'package.json'));
if (packageData &&
    typeof packageData.directories === 'object' &&
    typeof packageData.directories.test === 'string') {
    testDir = packageData.directories.test;
    pattern = testDir + ((testDir.lastIndexOf('/', 0) === 0) ? '' : '/') + '**/*' + extension;
}

babelrc = resolveBabelrc(process.cwd(), {});

require('./index')({
    cwd: process.cwd(),
    pattern: pattern,
    babelrc: babelrc,
    extension: extension
});
{'fraction_non_alphanumeric': 0.17061281337047354, 'fraction_numerical': 0.0031337047353760445, 'mean_word_length': 3.0125698324022347, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '6728320', 'n_tokens_mistral': 914, 'n_tokens_neox': 888, 'n_words': 194}