<commit_before>var fs = require('fs');
var path = require('path');
var webmake = require('webmake');


var PACKAGE_FILE = 'package.json';
var DEFAULT_ENTRY_POINT = 'index.js';


function _BuildRef() {
}


function resolveEntryPoint(fileOrPath) {
  if (typeof fileOrPath === 'undefined') {
    fileOrPath = '.';
  }

  // Try reading entry point from package
  if (fileOrPath === '.' || fs.lstatSync(fileOrPath).isDirectory()) {
    var entryPoint = null;
    try {
      entryPoint = require(path.resolve(path.join(fileOrPath, PACKAGE_FILE))).main;
    } catch(ex) {
    }
    if (!entryPoint) {
      entryPoint = path.join(fileOrPath, DEFAULT_ENTRY_POINT);
    }
    return path.resolve(entryPoint);
  }

  return path.resolve(fileOrPath);
}


function Builder(entryPoint) {
  entryPoint = resolveEntryPoint(entryPoint);
  this.entryPoint = entryPoint;
  this.path = path.dirname(entryPoint);
  this._readyQueue = [];
  this._latestBuild = null;
  this._lastOutput = null;
  this._lastError = null;
}
Builder.prototype._prebuild = function() {
  var latestBuild = new _BuildRef();
  this._latestBuild = latestBuild;
  return latestBuild;
};
Builder.prototype._postbuild = function(err, output) {
  var readyQueue = this._readyQueue;

  this._latestBuild = null;
  this._readyQueue = [];
  this._lastOutput = output;
  this._lastError = err;

  // Call all whenReady callbacks
  for (var index = 0; index < readyQueue.length; index++) {
    var callback = readyQueue[index];
    try {
      callback(err, output);
    } catch(ex) {
      console.log('Error in whenReady callback: ' + ex);
    }
  }
};
Builder.prototype.isBuilding = function() {
  return this._latestBuild !== null;
};
Builder.prototype.lastOutput = function() {
  return this._lastOutput;
};
Builder.prototype.lastError = function() {
  return this._lastError;
};
Builder.prototype.ready = function(callback) {
  // Enqueue callback if building, otherwise call immediately
  if (this.isBuilding()) {
    this._readyQueue.push(callback);
  } else {
    callback(this._lastError, this._lastOutput);
  }
};
Builder.prototype.build = function(callback) {
  var self = this;

  var currentBuild = self._prebuild();
  webmake(self.entryPoint, function(err, output) {
    // Handle post-build only if this is the latest build
    if (currentBuild === self._latestBuild) {
      self._postbuild(err, output, callback);
    }

    // Always call callback of current build
    if (typeof callback === 'function') {
      callback(err, output);
    }
  });
};


module.exports = {
  DEFAULT_ENTRY_POINT: DEFAULT_ENTRY_POINT,
  Builder: Builder,
  resolveEntryPoint: resolveEntryPoint
};<commit_msg>Fix outdated code and comments.<commit_after>var fs = require('fs');
var path = require('path');
var webmake = require('webmake');


var PACKAGE_FILE = 'package.json';
var DEFAULT_ENTRY_POINT = 'index.js';


function _BuildRef() {
}


function resolveEntryPoint(fileOrPath) {
  if (typeof fileOrPath === 'undefined') {
    fileOrPath = '.';
  }

  // Try reading entry point from package
  if (fileOrPath === '.' || fs.lstatSync(fileOrPath).isDirectory()) {
    var entryPoint = null;
    try {
      entryPoint = require(path.resolve(path.join(fileOrPath, PACKAGE_FILE))).main;
    } catch(ex) {
    }
    if (!entryPoint) {
      entryPoint = path.join(fileOrPath, DEFAULT_ENTRY_POINT);
    }
    return path.resolve(entryPoint);
  }

  return path.resolve(fileOrPath);
}


function Builder(entryPoint) {
  entryPoint = resolveEntryPoint(entryPoint);
  this.entryPoint = entryPoint;
  this.path = path.dirname(entryPoint);
  this._readyQueue = [];
  this._latestBuild = null;
  this._lastOutput = null;
  this._lastError = null;
}
Builder.prototype._prebuild = function() {
  var latestBuild = new _BuildRef();
  this._latestBuild = latestBuild;
  return latestBuild;
};
Builder.prototype._postbuild = function(err, output) {
  var readyQueue = this._readyQueue;

  this._latestBuild = null;
  this._readyQueue = [];
  this._lastOutput = output;
  this._lastError = err;

  // Call all ready callbacks
  for (var index = 0; index < readyQueue.length; index++) {
    var callback = readyQueue[index];
    try {
      callback(err, output);
    } catch(ex) {
      console.log('Error in ready callback: ' + ex);
    }
  }
};
Builder.prototype.isBuilding = function() {
  return this._latestBuild !== null;
};
Builder.prototype.lastOutput = function() {
  return this._lastOutput;
};
Builder.prototype.lastError = function() {
  return this._lastError;
};
Builder.prototype.ready = function(callback) {
  // Enqueue callback if building, otherwise call immediately
  if (this.isBuilding()) {
    this._readyQueue.push(callback);
  } else {
    callback(this._lastError, this._lastOutput);
  }
};
Builder.prototype.build = function(callback) {
  var self = this;

  var currentBuild = self._prebuild();
  webmake(self.entryPoint, function(err, output) {
    // Handle post-build only if this is the latest build
    if (currentBuild === self._latestBuild) {
      self._postbuild(err, output);
    }

    // Always call callback of current build
    if (typeof callback === 'function') {
      callback(err, output);
    }
  });
};


module.exports = {
  DEFAULT_ENTRY_POINT: DEFAULT_ENTRY_POINT,
  Builder: Builder,
  resolveEntryPoint: resolveEntryPoint
};
{'fraction_non_alphanumeric': 0.13215361445783133, 'fraction_numerical': 0.00037650602409638556, 'mean_word_length': 3.74798927613941, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7172801', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1622, 'n_words': 371}