<commit_before>import { rollup  } from 'rollup';
import { uglify } from 'rollup-plugin-uglify';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import fs from 'fs';
import nodeResolve from 'rollup-plugin-node-resolve';
import path from 'path';
import replace from 'rollup-plugin-replace';

let cache;

async function rollupWithCache(options) {
	const bundle = await rollup({
		cache,
		...options
	});
	cache = bundle.cache;
	return bundle;
}

export default async function renderDirectoryResourceJs(directoryResource) {
	const jsPaths = [
		path.join(directoryResource.physicalPath, '_index.js'),
		path.join(directoryResource.physicalPath, 'index.js')
	];

	const jsPath = jsPaths.find(path => fs.existsSync(path));

	if (!jsPath){
		throw new Error('directory has no _index.js or index.js');
	}

	const inputOptions = {
		input: jsPath,
		plugins: [
			babel(),
			nodeResolve({
				jsnext: false,
				main: true
			}),
			commonjs({
				include: 'node_modules/**'
			}),
			replace({
				'process.env.NODE_ENV': JSON.stringify('production')
			}),
			uglify()
		]
	};

	const outputOptions = {
		format: 'iife'
	};

	const bundle = await rollupWithCache(inputOptions);
	const { code } = await bundle.generate(outputOptions);

	return code;
}
<commit_msg>trims new lines<commit_after>import { rollup  } from 'rollup';
import { uglify } from 'rollup-plugin-uglify';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import fs from 'fs';
import nodeResolve from 'rollup-plugin-node-resolve';
import path from 'path';
import replace from 'rollup-plugin-replace';

let cache;

async function rollupWithCache(options) {
	const bundle = await rollup({
		cache,
		...options
	});
	cache = bundle.cache;
	return bundle;
}

export default async function renderDirectoryResourceJs(directoryResource) {
	const jsPaths = [
		path.join(directoryResource.physicalPath, '_index.js'),
		path.join(directoryResource.physicalPath, 'index.js')
	];

	const jsPath = jsPaths.find(path => fs.existsSync(path));

	if (!jsPath){
		throw new Error('directory has no _index.js or index.js');
	}

	const inputOptions = {
		input: jsPath,
		plugins: [
			babel(),
			nodeResolve({
				jsnext: false,
				main: true
			}),
			commonjs({
				include: 'node_modules/**'
			}),
			replace({
				'process.env.NODE_ENV': JSON.stringify('production')
			}),
			uglify()
		]
	};

	const outputOptions = {
		format: 'iife'
	};

	const bundle = await rollupWithCache(inputOptions);
	const { code } = await bundle.generate(outputOptions);

	return trimNewLines(code);
}

function trimNewLines(val) {
	return val
		.replace(/^\n+/, '')
		.replace(/\n+$/, '');
}
{'fraction_non_alphanumeric': 0.14026646928201333, 'fraction_numerical': 0.0, 'mean_word_length': 4.138783269961977, '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': '3753046', 'n_tokens_mistral': 973, 'n_tokens_neox': 879, 'n_words': 216}