<commit_before>'use strict';

const fs   = require('fs');
const path = require('path');

const libs = [];

module.exports = {
	
	require(file) {
		
		const resolved = resolve(file, libs);
		
		if ( ! resolved ) {
			throw new Error(`Can't locate sources for "${file}".`);
		}
		
		
	},
	
	libs(dir) {
		libs.push(dir);
	},
	
};<commit_msg>require wip<commit_after>'use strict';

const resolve = require('./resolve');
const Source = require('./source');


const libs = [];

const cache = {};

module.exports = {
	
	require(name) {
		
		const resolved = resolve(name, libs);
		
		if ( ! resolved ) {
			throw new Error(`Can't locate sources for "${name}".`);
		}
		
		return resolved.reduce((prev, file) => {
			const source = new Source(file);
			if (source.error) {
				throw new Error(source.error.toString());
			}
			if ( ! cache[file] ) {
				cache[file] = source;
			}
			Object.keys(source.compiled).forEach(k => {
				prev[k] = source.compiled[k];
			});
			return prev;
		}, {});
		
	},
	
	libs(dir) {
		libs.push(dir);
	},
	
};
{'fraction_non_alphanumeric': 0.18822393822393824, 'fraction_numerical': 0.0, 'mean_word_length': 2.928030303030303, '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': '3544301', 'n_tokens_mistral': 426, 'n_tokens_neox': 348, 'n_words': 78}