<commit_before>var _ = require('underscore');
var async = require('async');
var config = require('./config');
var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');

var META_KEYS = ['__VERSION__', '__PIPE__'];

var pruneManifest = function (manifest) {
  return _.reduce(manifest, function (manifest, val, key) {
    if (_.include(META_KEYS, key)) {
      manifest[key] = val;
    } else if (val.targetPaths && val.hash) {
      manifest[key] = _.omit(val, 'buffer');
    }
    return manifest;
  }, {});
};

module.exports = function (cb) {
  var manifestPath = config.get().manifestPath;
  if (!manifestPath) return cb(null, false);

  const data = JSON.stringify(pruneManifest(config.get().manifest));
  const checkEquality = _cb =>
    async.waterfall([
      _.partial(fs.readFile, manifestPath, 'utf8'),
      (existing, _cb) => data === existing ? cb(null, false) : _cb()
    ], _.bind(_cb, null));

  async.series([
    checkEquality,
    _.partial(mkdirp, path.dirname(manifestPath)),
    _.partial(fs.writeFile, manifestPath, data)
  ], _.partial(cb, _, true));
};<commit_msg>Use better equality check<commit_after>var _ = require('underscore');
var async = require('async');
var config = require('./config');
var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');

var META_KEYS = ['__VERSION__', '__PIPE__'];

var pruneManifest = function (manifest) {
  return _.reduce(manifest, function (manifest, val, key) {
    if (_.include(META_KEYS, key)) {
      manifest[key] = val;
    } else if (val.targetPaths && val.hash) {
      manifest[key] = _.omit(val, 'buffer');
    }
    return manifest;
  }, {});
};

module.exports = function (cb) {
  var manifestPath = config.get().manifestPath;
  if (!manifestPath) return cb(null, false);

  const data = JSON.stringify(pruneManifest(config.get().manifest));
  const checkEquality = _cb =>
    async.waterfall([
      _.partial(fs.readFile, manifestPath, 'utf8'),
      (existing, _cb) =>
        _.isEqual(JSON.parse(data), JSON.parse(existing)) ?
        cb(null, false) :
        _cb()
    ], _.bind(_cb, null));

  async.series([
    checkEquality,
    _.partial(mkdirp, path.dirname(manifestPath)),
    _.partial(fs.writeFile, manifestPath, data)
  ], _.partial(cb, _, true));
};
{'fraction_non_alphanumeric': 0.1743478260869565, 'fraction_numerical': 0.0008695652173913044, 'mean_word_length': 3.8544303797468356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2057268', 'n_tokens_mistral': 767, 'n_tokens_neox': 742, 'n_words': 171}