<commit_before>import buble from 'rollup-plugin-buble';
import path from 'path';
import chalk from 'chalk';
import * as rollup from 'rollup';
import batchWarnings from './batchWarnings';
import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import { InputOptions, OutputChunk } from '../../../src/rollup/index';

export default function loadConfigFile (configFile: string, silent = false): Promise<InputOptions[]> {
	const warnings = batchWarnings();

	return rollup
		.rollup({
			input: configFile,
			external: (id: string) => {
				return (
					(id[0] !== '.' && !path.isAbsolute(id)) ||
					id.slice(-5, id.length) === '.json'
				);
			},
			onwarn: warnings.add,
			plugins: [buble({ objectAssign: 'Object.assign' })]
		})
		.then((bundle: OutputChunk) => {
			if (!silent && warnings.count > 0) {
				stderr(chalk.bold(`loaded ${relativeId(configFile)} with warnings`));
				warnings.flush();
			}

			return bundle.generate({
				format: 'cjs'
			});
		})
		.then(({ code }: { code: string }) => {
			// temporarily override require<commit_msg>No longer use buble when parsing config files<commit_after>import path from 'path';
import chalk from 'chalk';
import * as rollup from 'rollup';
import batchWarnings from './batchWarnings';
import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import { InputOptions, OutputChunk } from '../../../src/rollup/index';

export default function loadConfigFile (configFile: string, silent = false): Promise<InputOptions[]> {
	const warnings = batchWarnings();

	return rollup
		.rollup({
			input: configFile,
			external: (id: string) => {
				return (
					(id[0] !== '.' && !path.isAbsolute(id)) ||
					id.slice(-5, id.length) === '.json'
				);
			},
			onwarn: warnings.add,
		})
		.then((bundle: OutputChunk) => {
			if (!silent && warnings.count > 0) {
				stderr(chalk.bold(`loaded ${relativeId(configFile)} with warnings`));
				warnings.flush();
			}

			return bundle.generate({
				format: 'cjs'
			});
		})
		.then(({ code }: { code: string }) => {
			// temporarily override require
{'fraction_non_alphanumeric': 0.17953488372093024, 'fraction_numerical': 0.0027906976744186047, 'mean_word_length': 3.490605427974948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1528069', 'n_tokens_mistral': 762, 'n_tokens_neox': 666, 'n_words': 176}