Use node.execPath in runOutOfProcess()

This commit is contained in:
Thomas Goyne 2018-03-02 10:47:04 -08:00
parent 3934413180
commit 61126aef53

View File

@ -61,20 +61,16 @@ function copyFileToTempDir(filename) {
return tmpFile.name; return tmpFile.name;
} }
function runOutOfProcess(nodeJsFilePath) { function runOutOfProcess() {
var nodeArgs = Array.prototype.slice.call(arguments); const args = Array.prototype.slice.call(arguments);
let tmpDir = tmp.dirSync(); let tmpDir = tmp.dirSync();
let content = fs.readFileSync(nodeJsFilePath, 'utf8'); console.log(`runOutOfProcess : ${args.join(' ')}`);
let tmpFile = tmp.fileSync({ dir: tmpDir.name });
fs.appendFileSync(tmpFile.fd, content, { encoding: 'utf8' });
nodeArgs[0] = tmpFile.name;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
console.log('runOutOfProcess command\n node ' + nodeArgs.join(" ")); execFile(process.execPath, args, {cwd: tmpDir.name}, (error, stdout, stderr) => {
const child = execFile('node', nodeArgs, { cwd: tmpDir.name }, (error, stdout, stderr) => {
if (error) { if (error) {
console.error("runOutOfProcess failed\n" + error); console.error("runOutOfProcess failed\n", error);
reject(new Error(`Running ${nodeJsFilePath} failed. error: ${error}`)); reject(new Error(`Running ${modulePath} failed. error: ${error}`));
return; return;
} }