@typed/test
Version:
Testing made simple.
21 lines • 1 kB
JavaScript
import { fork } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
const typeCheckCliBasePath = join(__dirname, 'typeCheckCli');
const tsPath = typeCheckCliBasePath + '.ts';
const jsPath = typeCheckCliBasePath + '.js';
const typeCheckCliPath = existsSync(jsPath) ? jsPath : tsPath;
export function typecheckInAnotherProcess(cwd, files) {
return runInAnotherProcess(typeCheckCliPath, [cwd, ...files]);
}
function runInAnotherProcess(filePath, args) {
return new Promise(resolve => {
const messages = [];
const errors = [];
const subprocess = 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