<commit_before>var path = require('path');
var bowerJson = require('bower-json');
var Q = require('q');

// The valid options are the same as bower-json#readFile.
// If the "assume" option is passed, it will be used if no json file was found

// This promise is resolved with [json, deprecated, assumed]
// - json: The read json
// - deprecated: The deprecated filename being used or false otherwise
// - assumed: True if a dummy json was returned if no json file was found, false otherwise
function readJson(file, options) {
    options = options || {};

    // Read
    return Q.nfcall(bowerJson.read, file, options)
    .spread(function (json, jsonFile) {
        var deprecated;

        if (options.logger) {
            var issues = bowerJson.getIssues(json);

            issues.warnings.forEach(function (warning) {
                options.logger.warn('invalid-meta', warning);
            });
        }

        jsonFile = path.basename(jsonFile);
        deprecated = jsonFile === 'component.json' ? jsonFile : false;

        return [json, deprecated, false];
    }, function (err) {
        // No json file was found, assume one
        if (err.code === 'ENOENT' && options.assume) {
            return [bowerJson.parse(options.assume, options), false, true];
        }

        err.details = err.message;

        if (err.file) {
            err.message = 'Failed to read ' + err.file;
            err.data = { filename: err.file };
        } else {
            err.message = 'Failed to read json from ' + file;
        }

        throw err;
    });
}

module.exports = readJson;
<commit_msg>Show in warning message location of malformed bower.json (#2357)<commit_after>var path = require('path');
var bowerJson = require('bower-json');
var Q = require('q');

// The valid options are the same as bower-json#readFile.
// If the "assume" option is passed, it will be used if no json file was found

// This promise is resolved with [json, deprecated, assumed]
// - json: The read json
// - deprecated: The deprecated filename being used or false otherwise
// - assumed: True if a dummy json was returned if no json file was found, false otherwise
function readJson(file, options) {
    options = options || {};

    // Read
    return Q.nfcall(bowerJson.read, file, options)
    .spread(function (json, jsonFile) {
        var deprecated;

        if (options.logger) {
            var issues = bowerJson.getIssues(json);
            if (issues.warnings.length > 0){
                options.logger.warn('invalid-meta', 'for:' + jsonFile);
            }
            issues.warnings.forEach(function (warning) {
                options.logger.warn('invalid-meta', warning);
            });
        }

        jsonFile = path.basename(jsonFile);
        deprecated = jsonFile === 'component.json' ? jsonFile : false;

        return [json, deprecated, false];
    }, function (err) {
        // No json file was found, assume one
        if (err.code === 'ENOENT' && options.assume) {
            return [bowerJson.parse(options.assume, options), false, true];
        }

        err.details = err.message;

        if (err.file) {
            err.message = 'Failed to read ' + err.file;
            err.data = { filename: err.file };
        } else {
            err.message = 'Failed to read json from ' + file;
        }

        throw err;
    });
}

module.exports = readJson;

{'fraction_non_alphanumeric': 0.12149808316130935, 'fraction_numerical': 0.001474491300501327, 'mean_word_length': 2.2335557673975215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2930702', 'n_tokens_mistral': 973, 'n_tokens_neox': 937, 'n_words': 308}