<commit_before>const childProcess = require('child_process');
const path = require('path');
const shelljs = require('shelljs');

const util = require('./util.js');

const TEMP = path.join(process.cwd(), 'node_modules', '.npm-install-version-temp');

function install (npmPackage, options = {}) {
  const {
    destination = util.sanitize(npmPackage),
    overwrite = false,
    quiet = false
  } = options;

  const log = quiet ? () => {} : (...args) => console.log(...args);

  if (!npmPackage) util.error();
  const destinationPath = path.join(process.cwd(), 'node_modules', destination);
  if (!overwrite && util.directoryExists(destinationPath)) {
    return log(`Directory at ${destinationPath} already exists, skipping`);
  }

  var errored = false;
  try {
    // make temp install dir
    shelljs.rm('-rf', TEMP);
    shelljs.mkdir('-p', path.join(TEMP, 'node_modules'));

    // install package to temp dir
    const installOptions = {
      cwd: TEMP,
      stdio: [null, null, null]
    };
    childProcess.spawnSync('npm', ['install', npmPackage], installOptions);

    // get real package name
    const packageName = util.getPackageName(npmPackage);

    // move deps inside package
    shelljs.mkdir(path.join(TEMP, 'node_modules', packageName, 'node_modules'));
    shelljs.ls(path.join(TEMP, 'node_modules'))
      .forEach(dep => {
        if (dep === packageName) return;
        const from = path.join(TEMP, 'node_modules', dep).toString();
        const to = path.join(TEMP, 'node_modules', packageName, 'node_modules', dep).toString();
        shelljs.mv(from, to);
      });

    // copy to node_modules/
    shelljs.rm('-rf', destinationPath);
    shelljs.mv(path.join(TEMP, 'node_modules', packageName), destinationPath);

    log(`Installed ${npmPackage} to ${destinationPath}`);
  } catch (err) {
    errored = true;
    console.error(`Error installing ${npmPackage}`);
    console.error(err.toString());
  } finally {
    // clean up temp install dir
    shelljs.rm('-rf', TEMP);

    if (errored) process.exit(1);
  }
}

module.exports = install;
<commit_msg>added -p flag to mkdir<commit_after>const childProcess = require('child_process');
const path = require('path');
const shelljs = require('shelljs');

const util = require('./util.js');

const TEMP = path.join(process.cwd(), 'node_modules', '.npm-install-version-temp');

function install (npmPackage, options = {}) {
  const {
    destination = util.sanitize(npmPackage),
    overwrite = false,
    quiet = false
  } = options;

  const log = quiet ? () => {} : (...args) => console.log(...args);

  if (!npmPackage) util.error();
  const destinationPath = path.join(process.cwd(), 'node_modules', destination);
  if (!overwrite && util.directoryExists(destinationPath)) {
    return log(`Directory at ${destinationPath} already exists, skipping`);
  }

  var errored = false;
  try {
    // make temp install dir
    shelljs.rm('-rf', TEMP);
    shelljs.mkdir('-p', path.join(TEMP, 'node_modules'));

    // install package to temp dir
    const installOptions = {
      cwd: TEMP,
      stdio: [null, null, null]
    };
    childProcess.spawnSync('npm', ['install', npmPackage], installOptions);

    // get real package name
    const packageName = util.getPackageName(npmPackage);

    // move deps inside package
    shelljs.mkdir('-p', path.join(TEMP, 'node_modules', packageName, 'node_modules'));
    shelljs.ls(path.join(TEMP, 'node_modules'))
      .forEach(dep => {
        if (dep === packageName) return;
        const from = path.join(TEMP, 'node_modules', dep).toString();
        const to = path.join(TEMP, 'node_modules', packageName, 'node_modules', dep).toString();
        shelljs.mv(from, to);
      });

    // copy to node_modules/
    shelljs.rm('-rf', destinationPath);
    shelljs.mv(path.join(TEMP, 'node_modules', packageName), destinationPath);

    log(`Installed ${npmPackage} to ${destinationPath}`);
  } catch (err) {
    errored = true;
    console.error(`Error installing ${npmPackage}`);
    console.error(err.toString());
  } finally {
    // clean up temp install dir
    shelljs.rm('-rf', TEMP);

    if (errored) process.exit(1);
  }
}

module.exports = install;

{'fraction_non_alphanumeric': 0.16296826533047004, 'fraction_numerical': 0.0004772130756382725, 'mean_word_length': 3.4978540772532187, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6763996', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1293, 'n_words': 309}