<commit_before>'use strict';

var fs           = require('fs')
  , resolve      = require('path').resolve
  , match        = require('es5-ext/lib/Function/prototype/match')
  , lock         = require('es5-ext/lib/Function/prototype/lock')
  , partial      = require('es5-ext/lib/Function/prototype/partial')
  , invoke       = require('es5-ext/lib/Function/invoke')
  , deferred     = require('deferred')
  , getFiles     = deferred.promisify(require('next/lib/fs/readdir-files-deep'))
  , ee           = require('event-emitter')

  , findTestPath = require('./find-test-path')
  , findContext  = require('./find-context')

  , stat = deferred.promisify(fs.stat)

  , configure;

configure = ee();

module.exports = function (paths) {
	var o, emitdata, emitend;
	if (typeof paths === 'string') {
		paths = arguments;
	}

	o = Object.create(configure);
	emitdata = o.emit.bind(o, 'data');
	emitend = lock.call(o.emit.bind(o, 'end'));

	deferred.reduce(paths, function (ignore, p) {
		var emit, tmp;
		emit = partial.call(emitdata, p);
		return stat(p)(function (stats) {
			if (stats.isFile()) {
				return [p];
			} else if (stats.isDirectory()) {
				return getFiles(p)(invoke('filter', function (file) {
					return file.slice(-3) === '.js';
				}))(invoke('map', function (file) {
					return resolve(p, file);
				}));
			} else {
				return new Error('Invalid path');
			}
		})(function (paths) {
			return deferred.reduce(paths, function (ignore, testee) {
				emit = partial.call(emitdata, p, testee);
				return deferred(tmp = findTestPath(testee),
					tmp(partial.call(findContext, testee))).match(emit, emit);
			}, null);<commit_msg>Update up to changes in next package<commit_after>'use strict';

var fs           = require('fs')
  , resolve      = require('path').resolve
  , match        = require('es5-ext/lib/Function/prototype/match')
  , lock         = require('es5-ext/lib/Function/prototype/lock')
  , partial      = require('es5-ext/lib/Function/prototype/partial')
  , invoke       = require('es5-ext/lib/Function/invoke')
  , deferred     = require('deferred')
  , readdir      = require('next/lib/fs/readdir')
  , ee           = require('event-emitter')

  , findTestPath = require('./find-test-path')
  , findContext  = require('./find-context')

  , stat = deferred.promisify(fs.stat)

  , configure, readdirOpts;

readdirOpts = { depth: Infinity, type: { file: true } };
configure = ee();

module.exports = function (paths) {
	var o, emitdata, emitend;
	if (typeof paths === 'string') {
		paths = arguments;
	}

	o = Object.create(configure);
	emitdata = o.emit.bind(o, 'data');
	emitend = lock.call(o.emit.bind(o, 'end'));

	deferred.reduce(paths, function (ignore, p) {
		var emit, tmp;
		emit = partial.call(emitdata, p);
		return stat(p)(function (stats) {
			if (stats.isFile()) {
				return [p];
			} else if (stats.isDirectory()) {
				return readdir(p, readdirOpts)(invoke('filter', function (file) {
					return file.slice(-3) === '.js';
				}))(invoke('map', function (file) {
					return resolve(p, file);
				}));
			} else {
				return new Error('Invalid path');
			}
		})(function (paths) {
			return deferred.reduce(paths, function (ignore, testee) {
				emit = partial.call(emitdata, p, testee);
				return deferred(tmp = findTestPath(testee),
					tmp(partial.call(findContext, testee))).match(emit, emit);
			}, null);
{'fraction_non_alphanumeric': 0.17449464922711058, 'fraction_numerical': 0.002972651605231867, 'mean_word_length': 3.3030690537084397, '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': '1598889', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1102, 'n_words': 227}