<commit_before>var through = require('through2');
var vm = require('vm');
var Module = require('module');

module.exports = function(context) {
	return through.obj(function(file, enc, next) {
		var fileContent = file.contents.toString(enc);
		file.data = _eval(fileContent, file.relative, context);
		next(null, file);
	});
};

function _eval(content, filename, context) {
    var sandbox = {};

    sandbox.module = new Module(filename, module.parent);
    sandbox.exports = sandbox.module.exports;
    sandbox.require = sandbox.module.require;
	Object.assign(sandbox, context);

    var res = vm.runInNewContext(content, sandbox, {filename: filename});
    return res || sandbox.module.exports;
}

module.exports.eval = _eval;<commit_msg>Swtich to runInThisContext<commit_after>var through = require('through2');
var vm = require('vm');
var Module = require('module');

module.exports = function(context) {
	return through.obj(function(file, enc, next) {
		var fileContent = file.contents.toString(enc);
		file.data = _eval(fileContent, file.relative, context);
		next(null, file);
	});
};

function _eval(content, filename, context) {
    var sandbox = {};

    sandbox.module = new Module(filename, module.parent);
    sandbox.exports = sandbox.module.exports;
    sandbox.require = sandbox.module.require;
	Object.assign(sandbox, context);

    var res = vm.runInThisContext(content, {filename: filename});
    return res || sandbox.module.exports;
}

module.exports.eval = _eval;
{'fraction_non_alphanumeric': 0.14343434343434344, 'fraction_numerical': 0.0013468013468013469, 'mean_word_length': 4.75968992248062, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1927800', 'n_tokens_mistral': 469, 'n_tokens_neox': 455, 'n_words': 102}