<commit_before>var child = require('child_process');
var path = require('path');
var util = require('util');
var which = require('which');

var debug = util.debuglog('compiler_process');

var compilers = {
  babel: {
    options: {
      outfile: '--out-file',
      watch: '--watch',
    },
  },

  coffee: {
    options: {
      watch: '--watch',
      outfile: ['--compile', '--join'],
    },
  },

  tsc: {
    options: {
      outfile: '--out',
      watch: '--watch',
    }
  },

  watchify: {
    options: {
      outfile: '--outfile',
    }
  },

  webpack: {
    options: {
      outfile: '--output-file',
      watch: '--watch',
    }
  }
};

function find(command, callback) {
  which(command, callback);
}

module.exports.find = find;

function options(command, options) {
  command = path.basename(command);

  var compiler = compilers[command];
  if (!compiler) {
    throw new TypeError('Bad compiler command');
  }

  var args = [];

  var keys = Object.keys(options);
  keys.forEach(function(key) {
    var value = options[key];

    if (value !== undefined) {
      var option = compiler.options[key];

      if (option === undefined) {
        return;
      }

      if (value === true) {
        args.unshift(option);
      } else if (util.isArray(option)) {
        args.unshift.apply(args, option.concat(value));
      } else {
        args.unshift(option, value);
      }
    }
  });

  return args;
}

module.exports.options = options;

function spawn(command, args, options, callback) {
  if (typeof args === 'function') {
    callback = args;
    args = undefined;
  } else if (typeof options === 'function') {
    callback = options;
    options = undefined;
  }

  if (typeof args === 'undefined') {
    args = [];
  }

  if (typeof options === 'undefined') {
    options = { };
  }

  debug('spawn %s %s', command, args.join(' '));
  find(command, function(error, command) {
    if (error) {
      return callback(error);
    }

    var ps = child.spawn(command, args, options);
    ps.once('error', function(error) {
      callback(error);<commit_msg>lib: spawn node instead of a shell process<commit_after>var child = require('child_process');
var path = require('path');
var util = require('util');
var which = require('which');

var debug = util.debuglog('compiler_process');

var compilers = {
  babel: {
    options: {
      outfile: '--out-file',
      watch: '--watch',
    },
  },

  coffee: {
    options: {
      watch: '--watch',
      outfile: ['--compile', '--join'],
    },
  },

  tsc: {
    options: {
      outfile: '--out',
      watch: '--watch',
    }
  },

  watchify: {
    options: {
      outfile: '--outfile',
    }
  },

  webpack: {
    options: {
      outfile: '--output-file',
      watch: '--watch',
    }
  }
};

function find(command, callback) {
  which(command, callback);
}

module.exports.find = find;

function options(command, options) {
  command = path.basename(command);

  var compiler = compilers[command];
  if (!compiler) {
    throw new TypeError('Bad compiler command');
  }

  var args = [];

  var keys = Object.keys(options);
  keys.forEach(function(key) {
    var value = options[key];

    if (value !== undefined) {
      var option = compiler.options[key];

      if (option === undefined) {
        return;
      }

      if (value === true) {
        args.unshift(option);
      } else if (util.isArray(option)) {
        args.unshift.apply(args, option.concat(value));
      } else {
        args.unshift(option, value);
      }
    }
  });

  return args;
}

module.exports.options = options;

function spawn(command, args, options, callback) {
  if (typeof args === 'function') {
    callback = args;
    args = undefined;
  } else if (typeof options === 'function') {
    callback = options;
    options = undefined;
  }

  if (typeof args === 'undefined') {
    args = [];
  }

  if (typeof options === 'undefined') {
    options = { };
  }
  debug('spawn %s %s', command, args.join(' '));
  find(command, function(error, command) {
    if (error) {
      return callback(error);
    }

    if (path.extname(command).toLowerCase() == '.cmd') {
      var content = '' + fs.readFileSync(command);
      var link = (/node  "%~dp0\\(.*?)"/.exec(content) || [])[1];

      if (link) {
        command = path.resolve(path.dirname(command), link);
      }
    }

    var ps = child.spawn('node', [command].concat(args), options);
    ps.once('error', function(error) {
      callback(error);
{'fraction_non_alphanumeric': 0.17515638963360142, 'fraction_numerical': 0.00044682752457551384, 'mean_word_length': 2.4921996879875197, 'pattern_counts': {'":': 0, '<': 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': '4685867', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1440, 'n_words': 332}