<commit_before>'use strict';

const path = require('path');
const Module = require('module');
const vm = require('vm');

const minimist = require('minimist');
const rc = require('rc');

const startDebug = require('./embedded-agents');

const Debug = vm.runInDebugContext('Debug');

const argv = minimist(process.argv.slice(2), {
  boolean: [ 'brk' ],
  stopEarly: true,
});
const config = rc('bugger', {
  port: 8058,
}, argv);
const debugBreak = config.brk;

if (!config._.length) {
  process.stderr.write(`Usage:
  bugger [ <bugger options> ] <filename> [ <program arguments> ]\n`);
  process.exit(1);
}

const resolvedArgv = require.resolve(path.resolve(process.cwd(), config._.shift()));
process.argv = [ process.argv[0], resolvedArgv ].concat(config._);

const agents = startDebug();
agents.get('Debugger'); // To make sure we capture break events

// Run the file contents in the correct scope or sandbox. Expose
// the correct helper variables (require, module, exports) to
// the file.
// Returns exception, if any.
Module.prototype._compile = function _compile(content, filename) {
  /* eslint no-param-reassign:0 */
  const self = this;
  // remove shebang
  content = content.replace(/^\#\!.*/, '');

  function require(request) {
    return self.require(request);
  }

  require.resolve = function resolve(request) {
    return Module._resolveFilename(request, self);
  };

  Object.defineProperty(require, 'paths', { get: function get() {<commit_msg>Explain why we are patching Module::_compile<commit_after>'use strict';

const path = require('path');
const Module = require('module');
const vm = require('vm');

const minimist = require('minimist');
const rc = require('rc');

const startDebug = require('./embedded-agents');

const Debug = vm.runInDebugContext('Debug');

const argv = minimist(process.argv.slice(2), {
  boolean: [ 'brk' ],
  stopEarly: true,
});
const config = rc('bugger', {
  port: 8058,
}, argv);
const debugBreak = config.brk;

if (!config._.length) {
  process.stderr.write(`Usage:
  bugger [ <bugger options> ] <filename> [ <program arguments> ]\n`);
  process.exit(1);
}

const resolvedArgv = require.resolve(path.resolve(process.cwd(), config._.shift()));
process.argv = [ process.argv[0], resolvedArgv ].concat(config._);

const agents = startDebug();
agents.get('Debugger'); // To make sure we capture break events

// Patching this so we can properly break on the first line.
Module.prototype._compile = function _compile(content, filename) {
  /* eslint no-param-reassign:0 */
  const self = this;
  // remove shebang
  content = content.replace(/^\#\!.*/, '');

  function require(request) {
    return self.require(request);
  }

  require.resolve = function resolve(request) {
    return Module._resolveFilename(request, self);
  };

  Object.defineProperty(require, 'paths', { get: function get() {
{'fraction_non_alphanumeric': 0.1639747191011236, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 4.468330134357005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7163887', 'n_tokens_mistral': 887, 'n_tokens_neox': 868, 'n_words': 235}