<commit_before>const { EventEmitter } = require('events');
const { spawn } = require('child_process');
const os = require('os');
const shortid = require('shortid');

const PSCommand = require('./PSCommand');

const {
  isWin, isCriticalPSError, logger,
  ShellStreamBuffer, shellSafeWrite,
  getType, convertToPSOption,
} = require('./utils');

const {
  PS_PROC_ERROR,
  PS_ARG_MISS_ERROR,
  PS_ARG_TYPE_ERROR,
  PS_CMD_FAIL_ERROR,
} = require('./errors');

class Shell extends EventEmitter {
  constructor(options = {}) {
    super();

    this.pid = -1;
    this.streams = [];
    this.commands = [];
    this.history = [];
    this.hadErrors = false;
    this.invocationStateInfo = 'NotStarted';
    this.verbose = false;

    let psProc = !isWin ? 'pwsh' : 'powershell';
    let psOpts = ['-NoLogo', '-NoExit', '-Command', '-'];

    if(options.pwsh) {
      psProc = 'pwsh';
    }

    if(options.pwshPrev && !options.pwsh) {
      psProc = 'pwsh-preview';
    }

    if(process.env.NPS) {
      psProc = process.env.NPS;
    }

    if(Object.hasOwnProperty.call(options, 'debugMsg')) {
      logger.warn(`debugMsg will be deprecated soon. use verbose instead.\n
      https://rannn505.gitbook.io/node-powershell/shell/initialize`);
      this.verbose = options.debugMsg;
    }

    if(options.verbose) {
      this.verbose = true;
    }

    Object.keys(options).forEach(optKey => {
      if(['pwsh', 'pwshPrev', 'debugMsg', 'verbose', 'inputEncoding', 'outputEncoding'].includes(optKey)) {
        return;
      }
      const optVal = options[optKey];
      psOpts = [...convertToPSOption(optKey, optVal), ...psOpts];
    });

    const proc = spawn(`${psProc}${!isWin ? '' : '.exe'}`, psOpts, { stdio: 'pipe' });
    this.pid = proc.pid;

    // make sure the PS process start successfully
    if(!this.pid) {
      throw new PS_PROC_ERROR();
    }<commit_msg>fix travis<commit_after>const { EventEmitter } = require('events');
const { spawn } = require('child_process');
const os = require('os');
const shortid = require('shortid');

const PSCommand = require('./PSCommand');

const {
  isWin, isCriticalPSError, logger,
  ShellStreamBuffer, shellSafeWrite,
  getType, convertToPSOption,
} = require('./utils');

const {
  PS_PROC_ERROR,
  PS_ARG_MISS_ERROR,
  PS_ARG_TYPE_ERROR,
  PS_CMD_FAIL_ERROR,
} = require('./errors');

class Shell extends EventEmitter {
  constructor(options = {}) {
    super();

    this.pid = -1;
    this.streams = [];
    this.commands = [];
    this.history = [];
    this.hadErrors = false;
    this.invocationStateInfo = 'NotStarted';
    this.verbose = false;

    let psProc = !isWin ? 'pwsh' : 'powershell';
    let psOpts = ['-NoLogo', '-NoExit', '-Command', '-'];

    if(options.pwsh) {
      psProc = 'pwsh';
    }

    if(options.pwshPrev && !options.pwsh) {
      psProc = 'pwsh-preview';
    }

    if(process.env.NPS) {
      psProc = process.env.NPS;
    }

    if(Object.hasOwnProperty.call(options, 'debugMsg')) {
      logger.warn(`debugMsg will be deprecated soon. use verbose instead.\n
      https://rannn505.gitbook.io/node-powershell/shell/initialize`);
      this.verbose = options.debugMsg;
    }

    if(options.verbose) {
      this.verbose = true;
    }

    Object.keys(options).forEach(optKey => {
      if(['pwsh', 'pwshPrev', 'debugMsg', 'verbose', 'inputEncoding', 'outputEncoding'].includes(optKey)) {
        return;
      }
      const optVal = options[optKey];
      psOpts = [...convertToPSOption(optKey, optVal), ...psOpts];
    });

    console.log(`${psProc}${!isWin ? '' : '.exe'}`);
    console.log(psOpts);
    const proc = spawn(`${psProc}${!isWin ? '' : '.exe'}`, psOpts, { stdio: 'pipe' });
    this.pid = proc.pid;

    // make sure the PS process start successfully
    if(!this.pid) {
      throw new PS_PROC_ERROR();
    }
{'fraction_non_alphanumeric': 0.16889588250721216, 'fraction_numerical': 0.002098085496984002, 'mean_word_length': 3.053134962805526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1295955', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1275, 'n_words': 240}