const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');

module.exports = {
  execNodeJsScriptWithInheritedOutput,
  execFileWithInheritedOutput
};

async function execNodeJsScriptWithInheritedOutput(command, args) {
  return new Promise((resolve, reject) => {
    const child = childProcess.fork(command, args, { stdio: 'inherit' });
    child.on('close', code => {
      if (code !== 0) {
        reject(new Error(`Child process failed with exit-code ${code}`));
      }
      resolve();
    });
  });
}

async function execFileWithInheritedOutput(command, args) {
  return new Promise((resolve, reject) => {
    const resolvedCommand = preferLocalDependencies(command);
    const child = childProcess.spawn(resolvedCommand, args, {
      stdio: 'inherit'
    });
    child.on('exit', code => {
      if (code !== 0) {
        reject(new Error(`Child process failed with exit-code ${code}`));
      }
      resolve();
    });
  });
}

function preferLocalDependencies(command) {
  const localCandidate = resolveLocalCandidate(command);

  if (fs.existsSync(localCandidate)) {
    return localCandidate;
  }
  return command;
}

function resolveLocalCandidate(command) {
  if (process.platform === 'win32') {
    return path.join('node_modules', '.bin', command + '.cmd');
  }
  return path.join('node_modules', '.bin', command);
}

@@ -43,64 +43,8 @@
 s');
-%0Aconst fs = require('fs');%0Aconst path = require('path');
 %0A%0Amo
@@ -101,39 +101,8 @@
 tput
-,%0A  execFileWithInheritedOutput
 %0A%7D;%0A
@@ -463,831 +463,4 @@
 ;%0A%7D%0A
-%0Aasync function execFileWithInheritedOutput(command, args) %7B%0A  return new Promise((resolve, reject) =%3E %7B%0A    const resolvedCommand = preferLocalDependencies(command);%0A    const child = childProcess.spawn(resolvedCommand, args, %7B%0A      stdio: 'inherit'%0A    %7D);%0A    child.on('exit', code =%3E %7B%0A      if (code !== 0) %7B%0A        reject(new Error(%60Child process failed with exit-code $%7Bcode%7D%60));%0A      %7D%0A      resolve();%0A    %7D);%0A  %7D);%0A%7D%0A%0Afunction preferLocalDependencies(command) %7B%0A  const localCandidate = resolveLocalCandidate(command);%0A%0A  if (fs.existsSync(localCandidate)) %7B%0A    return localCandidate;%0A  %7D%0A  return command;%0A%7D%0A%0Afunction resolveLocalCandidate(command) %7B%0A  if (process.platform === 'win32') %7B%0A    return path.join('node_modules', '.bin', command + '.cmd');%0A  %7D%0A  return path.join('node_modules', '.bin', command);%0A%7D%0A

Remove unused parser tests