<commit_before>'use strict';

const babel = require('babel-core').transform;
const readPkg = require('read-pkg-up');

const BABEL_REGEX = /(^babel-)(preset|plugin)-(.*)/i;

function getPlugins() {
	const pkg = readPkg.sync().pkg;
	return Object.keys(pkg.devDependencies || {});
}

function genConfig(deps) {
	const out = {};
	deps.forEach(dep => {
		const segs = BABEL_REGEX.exec(dep);
		if (segs) {
			const k = `${segs[2]}s`;
			out[k] = (out[k] || []).concat(segs[3]);
		}
	});
	return out;
}

module.exports = function () {
	let cache;
	let config;

	this.plugin('babel', {}, function * (file, opts) {
		if (opts.preload) {
			delete opts.preload;
			// get dependencies
			cache = cache || getPlugins();
			// attach any deps to babel options
			config = config || genConfig(cache);
			// update options
			Object.assign(opts, config);
		}

		// attach file's name
		opts.filename = file.name;

		// update file's data
		file.data = babel(file.data.toString(), opts);
	});
};<commit_msg>finalize plugin logic; incorporate sourcemapping<commit_after>'use strict';

const babel = require('babel-core').transform;
const readPkg = require('read-pkg-up');

const BABEL_REGEX = /(^babel-)(preset|plugin)-(.*)/i;

function getPlugins() {
	const pkg = readPkg.sync().pkg;
	return Object.keys(pkg.devDependencies || {});
}

function genConfig(deps) {
	const out = {};
	deps.forEach(dep => {
		const segs = BABEL_REGEX.exec(dep);
		if (segs) {
			const k = `${segs[2]}s`;
			out[k] = (out[k] || []).concat(segs[3]);
		}
	});
	return out;
}

module.exports = function () {
	let cache;
	let config;

	this.plugin('babel', {}, function * (file, opts) {
		if (opts.preload) {
			delete opts.preload;
			// get dependencies
			cache = cache || getPlugins();
			// attach any deps to babel options
			config = config || genConfig(cache);
			// update options
			Object.assign(opts, config);
		}

		// attach file's name
		opts.filename = file.base;

		const output = babel(file.data, opts);

		if (output.map) {
			const map = `${file.base}.map`;

			// append `sourceMappingURL` to original file
			if (opts.sourceMaps !== 'both') {
				output.code += new Buffer(`\n//# sourceMappingURL=${map}`);
			}

			// add sourcemap to `files` array
			this._.files.push({
				base: map,
				dir: file.dir,
				data: new Buffer(JSON.stringify(output.map))
			});
		}

		// update file's data
		file.data = new Buffer(output.code);
	});
};
{'fraction_non_alphanumeric': 0.1815550041356493, 'fraction_numerical': 0.0016542597187758478, 'mean_word_length': 3.3743218806509945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '269576', 'n_tokens_mistral': 967, 'n_tokens_neox': 859, 'n_words': 196}