"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const path_1 = require("path");
const typeCheckCliBasePath = path_1.join(__dirname, 'typeCheckCli');
const tsPath = typeCheckCliBasePath + '.ts';
const jsPath = typeCheckCliBasePath + '.js';
const typeCheckCliPath = fs_1.existsSync(jsPath) ? jsPath : tsPath;
function typecheckInAnotherProcess(cwd, files) {
    return runInAnotherProcess(typeCheckCliPath, [cwd, ...files]);
}
exports.typecheckInAnotherProcess = typecheckInAnotherProcess;
function runInAnotherProcess(filePath, args) {
    return new Promise(resolve => {
        const messages = [];
        const errors = [];
        const subprocess = child_process_1.fork(filePath, args, { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] });
        subprocess.stdout.on('data', msg => messages.push(msg.toString()));
        subprocess.stderr.on('data', msg => errors.push(msg.toString()));
        subprocess.on('close', exitCode => resolve({ exitCode, stdout: messages.join(''), stderr: errors.join('') }));
    });
}
//# sourceMappingURL=typeCheckInAnotherProcess.js.map