<commit_before>var fs = require('fs');
var Promise = require('bluebird');
var readTextFile = require('./read-text-file');
var Step = require('step');

/**
 * @param {object} options
 * @param {string} options.code
 * @param {string} options.inputPath
 * @param {string} options.outputPath
 * @param {string} options.bundleDir
 * @param {string} options.nodeModulesPath
 * @param {boolean} options.outputBundleOnly
 * @param {boolean} options.outputBundleStats
 * @param {object} options.bundleStatsCollector
 * @param {boolean} options.sourceMap
 * @param {string} options.siteRoot
 * @param {boolean} options.useTemplateDirs
 * @param {function} processFn
 */
function processAsync(options, processFn) {

    return new Promise(function(resolve, reject) {

        Step(
            function doesOutputFileExist() {
                fs.exists(options.outputPath, this);
            },
            function (outputFileExists) {

                var next = this;

                if (!outputFileExists) {

                    next(!outputFileExists);

                } else {

                    fs.stat(options.inputPath, function (err, inputFileStat) {

                        if (err) {
                            throw err;
                        }

                        fs.stat(options.outputPath, function (err, outputFileStat) {

                            if (err) {
                                throw err;
                            }

                            var shouldReprocess = outputFileStat.mtime.getTime() < inputFileStat.mtime.getTime();

                            if (options.outputBundleStats && !shouldReprocess) {

                                var imports = options.bundleStatsCollector.GetImportsForFile(options.inputPath) || [];

                                for (var i = 0; i < imports.length; i++) {

                                    var importStat = fs.statSync(imports[i]);

                                    shouldReprocess = outputFileStat.mtime.getTime() < importStat.mtime.getTime();

                                    if (shouldReprocess) {
                                        break;
                                    }
                                }

                            }

                            next(shouldReprocess);

                        });
                    });
                }

            },
            function (shouldRecompile) {

                if (shouldRecompile) {

                    var onAfterProcessed = function(code) {

                        if (options.outputBundleOnly) {

                            resolve(code);

                        } else {

                            fs.writeFile(options.outputPath, code, 'utf-8', function(err) {

                                if (err) {
                                    reject(err);
                                }

                                resolve(code);

                            });

                        }
                    };

                    processFn(options)
                        .then(onAfterProcessed)
                        .catch(reject);

                } else {
<commit_msg>Name functions for stack trace.<commit_after>var fs = require('fs');
var Promise = require('bluebird');
var readTextFile = require('./read-text-file');
var Step = require('step');

/**
 * @param {object} options
 * @param {string} options.code
 * @param {string} options.inputPath
 * @param {string} options.outputPath
 * @param {string} options.bundleDir
 * @param {string} options.nodeModulesPath
 * @param {boolean} options.outputBundleOnly
 * @param {boolean} options.outputBundleStats
 * @param {object} options.bundleStatsCollector
 * @param {boolean} options.sourceMap
 * @param {string} options.siteRoot
 * @param {boolean} options.useTemplateDirs
 * @param {function} processFn
 */
function processAsync(options, processFn) {

    return new Promise(function(resolve, reject) {

        Step(
            function doesOutputFileExist() {
                fs.exists(options.outputPath, this);
            },
            function shouldProcessCode(outputFileExists) {

                var next = this;

                if (!outputFileExists) {

                    next(!outputFileExists);

                } else {

                    fs.stat(options.inputPath, function (err, inputFileStat) {

                        if (err) {
                            throw err;
                        }

                        fs.stat(options.outputPath, function (err, outputFileStat) {

                            if (err) {
                                throw err;
                            }

                            var shouldReprocess = outputFileStat.mtime.getTime() < inputFileStat.mtime.getTime();

                            if (options.outputBundleStats && !shouldReprocess) {

                                var imports = options.bundleStatsCollector.GetImportsForFile(options.inputPath) || [];

                                for (var i = 0; i < imports.length; i++) {

                                    var importStat = fs.statSync(imports[i]);

                                    shouldReprocess = outputFileStat.mtime.getTime() < importStat.mtime.getTime();

                                    if (shouldReprocess) {
                                        break;
                                    }
                                }

                            }

                            next(shouldReprocess);

                        });
                    });
                }

            },
            function processCode(shouldProcessCode) {

                if (shouldProcessCode) {

                    var onAfterProcessed = function(code) {

                        if (options.outputBundleOnly) {

                            resolve(code);

                        } else {

                            fs.writeFile(options.outputPath, code, 'utf-8', function(err) {

                                if (err) {
                                    reject(err);
                                }

                                resolve(code);

                            });

                        }
                    };

                    processFn(options)
                        .then(onAfterProcessed)
                        .catch(reject);

                } else {

{'fraction_non_alphanumeric': 0.09202740579258797, 'fraction_numerical': 0.0006228589224540642, 'mean_word_length': 1.0772962483829236, 'pattern_counts': {'":': 0, '<': 9, '<?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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4492490', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1395, 'n_words': 280}