<commit_before>
(function(exports) {

    var fs = require("fs");
    var grunt = require("grunt");
    var file_utils = require("./file_utils").file_utils;
    var phantomizer_helper = require("./phantomizer_helper").phantomizer_helper;

    var regen_count  = 0;
    var optimizer = function(meta_manager, user_config){
        var meta_manager = meta_manager;


        this.meta_manager = function(meta_manager){
            meta_manager = meta_manager;
        }
        this.user_config = function(user_config){
            user_config = user_config;
        }
        this.is_built = function(build_profile, request_path){
            var retour = false;

            var meta_request_path = request_path+".meta"+build_profile;

            var fpath = user_config.out_dir+request_path+build_profile;
            if( meta_manager.has(meta_request_path) ){
                retour = grunt.file.isFile(fpath);
            }
            return retour
        }
        this.is_build_fresh = function(build_profile, request_path){
            var retour = false;

            var meta_request_path = request_path+".meta"+build_profile;
            var fpath = user_config.out_dir+request_path+build_profile;

            if( meta_manager.has(meta_request_path) ){
                var entry = meta_manager.load(meta_request_path);

                retour = entry.is_fresh() && fs.existsSync(fpath);
            }
            return retour
        }
        this.regen_build = function(build_profile, request_path, cb){

            var out_file = user_config.out_dir+request_path+build_profile;
            var meta_file =user_config.meta_dir+request_path+".meta"+build_profile;

            var options = grunt.file.readJSON(meta_file);

            build_profile = build_profile==""?"":"-"+build_profile;

            var tasks_json_file = user_config.meta_dir+request_path+build_profile+".json";
            var r_tasks_json_file = file_utils.relative_path(tasks_json_file, user_config.wd);
            var tasks = []
            var tasks_options = {};

            for( var i in options.build ){
                var task_name = options.build[i];
                var rtask_options = options.tasks_opts[task_name];
                var task_target = task_name.split(":")[1];
                task_name = task_name.split(":")[0];

                var o_options = grunt.config.get(task_name) || {};

                o_options[task_target] = {
                    options:rtask_options
                };

                grunt.config.set(task_name,o_options);
                tasks.push(task_name+":"+task_target);
            }

            grunt.tasks(tasks, {}, function(){
                if( cb != null ){
                    cb(out_file, grunt.file.read(out_file))
                }
            });
        }
        this.do_build = function(build_profile, request_path, cb){
            var str_build_profile=build_profile==""?"":"-"+build_profile;

            var options = grunt.util._.clone(user_config);

            var out_file = user_config.out_dir+request_path+str_build_profile;
            var meta_file = request_path+str_build_profile;

            options["phantomizer-html-builder"] = options["phantomizer-html-jitbuild"];
            if( ! options["phantomizer-html-builder"][build_profile] ){
                options["phantomizer-html-builder"][build_profile] = {
                    options:{}
                }
            }
            options["phantomizer-html-builder"]["options"]["in_request"] = request_path;

            var json_file = user_config.meta_dir+request_path+str_build_profile+".json";
            grunt.file.write( json_file, JSON.stringify(options, null, 4) );
            json_file = file_utils.relative_path(json_file, user_config.wd);

            grunt.tasks(["loader_builder:"+json_file+":phantomizer-html-builder:"+build_profile+":"+request_path], options, function(){
                if( cb != null ){
                    cb(out_file, grunt.file.read(out_file));
                }
            });
        }


        this.merge_files = function( tgt_file, deps, paths){
            var entry_path = tgt_file+".meta";
            var target_path = user_config.out_dir+tgt_file+"";
            if(meta_manager.is_fresh(entry_path) == false ){
                // materials required to create cache entry
                var entry = meta_manager.create([]);


                if ( grunt.file.exists(process.cwd()+"/Gruntfile.js")) {
                    entry.load_dependencies([process.cwd()+"/Gruntfile.js"]);
                }
                if ( grunt.file.exists(user_config.project_dir+"/../config.json")) {
                    entry.load_dependencies([user_config.project_dir+"/../config.json"]);
                }
                entry.load_dependencies([target_path]);

                var merge_content = "";
                for( var n in deps ){
                    var file_dep = file_utils.find_file(paths, deps[n]);
                    if( file_dep != false ){
                        merge_content += grunt.file.read(file_dep);
                        entry.load_dependencies([file_dep]);<commit_msg>Fixed error when a dependency of a configured merged asset is missing on fs<commit_after>
(function(exports) {

    var fs = require("fs");
    var grunt = require("grunt");
    var file_utils = require("./file_utils").file_utils;
    var phantomizer_helper = require("./phantomizer_helper").phantomizer_helper;

    var regen_count  = 0;
    var optimizer = function(meta_manager, user_config){
        var meta_manager = meta_manager;


        this.meta_manager = function(meta_manager){
            meta_manager = meta_manager;
        }
        this.user_config = function(user_config){
            user_config = user_config;
        }
        this.is_built = function(build_profile, request_path){
            var retour = false;

            var meta_request_path = request_path+".meta"+build_profile;

            var fpath = user_config.out_dir+request_path+build_profile;
            if( meta_manager.has(meta_request_path) ){
                retour = grunt.file.isFile(fpath);
            }
            return retour
        }
        this.is_build_fresh = function(build_profile, request_path){
            var retour = false;

            var meta_request_path = request_path+".meta"+build_profile;
            var fpath = user_config.out_dir+request_path+build_profile;

            if( meta_manager.has(meta_request_path) ){
                var entry = meta_manager.load(meta_request_path);

                retour = entry.is_fresh() && fs.existsSync(fpath);
            }
            return retour
        }
        this.regen_build = function(build_profile, request_path, cb){

            var out_file = user_config.out_dir+request_path+build_profile;
            var meta_file =user_config.meta_dir+request_path+".meta"+build_profile;

            var options = grunt.file.readJSON(meta_file);

            build_profile = build_profile==""?"":"-"+build_profile;

            var tasks_json_file = user_config.meta_dir+request_path+build_profile+".json";
            var r_tasks_json_file = file_utils.relative_path(tasks_json_file, user_config.wd);
            var tasks = []
            var tasks_options = {};

            for( var i in options.build ){
                var task_name = options.build[i];
                var rtask_options = options.tasks_opts[task_name];
                var task_target = task_name.split(":")[1];
                task_name = task_name.split(":")[0];

                var o_options = grunt.config.get(task_name) || {};

                o_options[task_target] = {
                    options:rtask_options
                };

                grunt.config.set(task_name,o_options);
                tasks.push(task_name+":"+task_target);
            }

            grunt.tasks(tasks, {}, function(){
                if( cb != null ){
                    cb(out_file, grunt.file.read(out_file))
                }
            });
        }
        this.do_build = function(build_profile, request_path, cb){
            var str_build_profile=build_profile==""?"":"-"+build_profile;

            var options = grunt.util._.clone(user_config);

            var out_file = user_config.out_dir+request_path+str_build_profile;
            var meta_file = request_path+str_build_profile;

            options["phantomizer-html-builder"] = options["phantomizer-html-jitbuild"];
            if( ! options["phantomizer-html-builder"][build_profile] ){
                options["phantomizer-html-builder"][build_profile] = {
                    options:{}
                }
            }
            options["phantomizer-html-builder"]["options"]["in_request"] = request_path;

            var json_file = user_config.meta_dir+request_path+str_build_profile+".json";
            grunt.file.write( json_file, JSON.stringify(options, null, 4) );
            json_file = file_utils.relative_path(json_file, user_config.wd);

            grunt.tasks(["loader_builder:"+json_file+":phantomizer-html-builder:"+build_profile+":"+request_path], options, function(){
                if( cb != null ){
                    cb(out_file, grunt.file.read(out_file));
                }
            });
        }


        this.merge_files = function( tgt_file, deps, paths){
            var entry_path = tgt_file+".meta";
            var target_path = user_config.out_dir+tgt_file+"";
            if(meta_manager.is_fresh(entry_path) == false ){
                // materials required to create cache entry
                var entry = meta_manager.create([]);


                if ( grunt.file.exists(process.cwd()+"/Gruntfile.js")) {
                    entry.load_dependencies([process.cwd()+"/Gruntfile.js"]);
                }
                if ( grunt.file.exists(user_config.project_dir+"/../config.json")) {
                    entry.load_dependencies([user_config.project_dir+"/../config.json"]);
                }
                entry.load_dependencies([target_path]);

                var merge_content = "";
                for( var n in deps ){
                    var file_dep = file_utils.find_file(paths, deps[n]);
                    if( file_dep ){
                        merge_content += grunt.file.read(file_dep);
                        entry.load_dependencies([file_dep]);
                    }else{
                        grunt.log.write("Missing dependency to build merged assset\n\t"+deps[n])
{'fraction_non_alphanumeric': 0.11489766777724893, 'fraction_numerical': 0.0007615421227986673, 'mean_word_length': 1.9736767619586753, 'pattern_counts': {'":': 14, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853247', 'n_tokens_mistral': 3065, 'n_tokens_neox': 2914, 'n_words': 450}