<commit_before>'use strict'

const browserify = require('./browserify')
const uglifyjs   = require('./uglifyjs')

/*
 * Load, transform, bundle and compress JS.
 * @public
 * @param {String} filePath - Absolute path to the requested file.
 * @param {String} srcPath - Absolute path to the source folder.
 * @param {String} distPath - Absolute path to the export folder.
 * @param {Object} route - The route which matched the request URL.
 * @param {Function} next - The callback that handles the response. Receives the following properties: err, result, savePath.
 */
module.exports = function(filePath, srcPath, distPath, route, next) {

	let savePath = null

	const optimize = (distPath==null ? false : true)
	const opts     = { optimize }

	Promise.resolve().then(() => {

		// Prepare file paths

		savePath = filePath.replace(srcPath, distPath)

	}).then(() => {

		// Process data with browserify

		return browserify(filePath, opts)

	}).then((str) => {

		// Process data with uglifyjs

		return uglifyjs(str, opts)

	}).then(

		// Return processed data and catch errors
		// Avoid .catch as we don't want to catch errors of the callback

		(str) => next(null, str, savePath),
		(err) => next(err, null, null)

	)

}

/**
 * Attach an array to the function, which contains a list of
 * extensions used by the handler. The array will be used by Rosid for caching purposes.
 */
module.exports.cache = [
	'.js',
	'.json'
]<commit_msg>Replaced callback with promise return<commit_after>'use strict'

const browserify = require('./browserify')
const uglifyjs   = require('./uglifyjs')

/*
 * Load, transform, bundle and compress JS.
 * @public
 * @param {String} filePath - Absolute path to the requested file.
 * @param {String} srcPath - Absolute path to the source folder.
 * @param {String} distPath - Absolute path to the export folder.
 * @param {Object} route - The route which matched the request URL.
 * @returns {Promise} Returns the following properties if resolved: {Object}.
 */
module.exports = function(filePath, srcPath, distPath, route) {

	let savePath = null

	const optimize = (distPath==null ? false : true)
	const opts     = { optimize }

	return Promise.resolve().then(() => {

		// Prepare file paths

		savePath = filePath.replace(srcPath, distPath)

	}).then(() => {

		// Process data with browserify

		return browserify(filePath, opts)

	}).then((str) => {

		// Process data with uglifyjs

		return uglifyjs(str, opts)

	}).then((str) => {

		return {
			data     : str,
			savePath : savePath
		}

	})

}

/**
 * Attach an array to the function, which contains a list of
 * extensions used by the handler. The array will be used by Rosid for caching purposes.
 */
module.exports.cache = [
	'.js',
	'.json'
]
{'fraction_non_alphanumeric': 0.12509117432531, 'fraction_numerical': 0.0, 'mean_word_length': 3.4385113268608416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '2792086', 'n_tokens_mistral': 872, 'n_tokens_neox': 806, 'n_words': 304}