<commit_before>'use strict';

// Iron-node does not work with forked processes
// This cli command will run a single file in the current process.
// Intended to be used with iron-node for profiling purposes.

const path = require('path');
const EventEmitter = require('events');
const meow = require('meow');
const Promise = require('bluebird');
const pkgConf = require('pkg-conf');
const findCacheDir = require('find-cache-dir');
const uniqueTempDir = require('unique-temp-dir');
const arrify = require('arrify');
const resolveCwd = require('resolve-cwd');
const babelConfigHelper = require('./lib/babel-config');
const CachingPrecompiler = require('./lib/caching-precompiler');
const globals = require('./lib/globals');

function resolveModules(modules) {
	return arrify(modules).map(name => {
		const modulePath = resolveCwd(name);

		if (modulePath === null) {
			throw new Error(`Could not resolve required module '${name}'`);
		}

		return modulePath;
	});
}

// Chrome gets upset when the `this` value is non-null for these functions
globals.setTimeout = setTimeout.bind(null);
globals.clearTimeout = clearTimeout.bind(null);

Promise.longStackTraces();

const conf = pkgConf.sync('ava', {
	defaults: {
		babel: 'default'
	}
});

// Define a minimal set of options from the main CLI
const cli = meow(`
	Usage
	  $ iron-node node_modules/ava/profile.js <test-file>

	Options
	  --fail-fast   Stop after first test failure
	  --serial, -s  Run tests serially

`, {
	string: [
		'_'
	],
	boolean: [
		'fail-fast',
		'verbose',
		'serial',
		'tap'
	],
	default: conf,
	alias: {
		s: 'serial'
	}
});

if (cli.input.length !== 1) {
	throw new Error('Specify a test file');
}

const file = path.resolve(cli.input[0]);
const cacheDir = findCacheDir({
	name: 'ava',
	files: [file]
}) || uniqueTempDir();

babelConfigHelper.build(process.cwd(), cacheDir, conf.babel, true)
	.then(result => {
		const precompiler = new CachingPrecompiler({<commit_msg>Allow extra input params during profiling (#1429)<commit_after>'use strict';

// Iron-node does not work with forked processes
// This cli command will run a single file in the current process.
// Intended to be used with iron-node for profiling purposes.

const path = require('path');
const EventEmitter = require('events');
const meow = require('meow');
const Promise = require('bluebird');
const pkgConf = require('pkg-conf');
const findCacheDir = require('find-cache-dir');
const uniqueTempDir = require('unique-temp-dir');
const arrify = require('arrify');
const resolveCwd = require('resolve-cwd');
const babelConfigHelper = require('./lib/babel-config');
const CachingPrecompiler = require('./lib/caching-precompiler');
const globals = require('./lib/globals');

function resolveModules(modules) {
	return arrify(modules).map(name => {
		const modulePath = resolveCwd(name);

		if (modulePath === null) {
			throw new Error(`Could not resolve required module '${name}'`);
		}

		return modulePath;
	});
}

// Chrome gets upset when the `this` value is non-null for these functions
globals.setTimeout = setTimeout.bind(null);
globals.clearTimeout = clearTimeout.bind(null);

Promise.longStackTraces();

const conf = pkgConf.sync('ava', {
	defaults: {
		babel: 'default'
	}
});

// Define a minimal set of options from the main CLI
const cli = meow(`
	Usage
	  $ iron-node node_modules/ava/profile.js <test-file>

	Options
	  --fail-fast   Stop after first test failure
	  --serial, -s  Run tests serially

`, {
	string: [
		'_'
	],
	boolean: [
		'fail-fast',
		'verbose',
		'serial',
		'tap'
	],
	default: conf,
	alias: {
		s: 'serial'
	}
});

if (cli.input.length === 0) {
	throw new Error('Specify a test file');
}

const file = path.resolve(cli.input[0]);
const cacheDir = findCacheDir({
	name: 'ava',
	files: [file]
}) || uniqueTempDir();

babelConfigHelper.build(process.cwd(), cacheDir, conf.babel, true)
	.then(result => {
		const precompiler = new CachingPrecompiler({
{'fraction_non_alphanumeric': 0.14885496183206107, 'fraction_numerical': 0.002035623409669211, 'mean_word_length': 4.392318244170096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6143377', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1240, 'n_words': 361}