Skip to content

Commit

Permalink
use either process.send or writeFile fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
wclr committed Dec 9, 2020
1 parent 2fd13c2 commit d1cab45
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/child-require-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,27 @@ const waitForFile = function (fileName: string) {
}
}

const compile = (code: string, fileName: string) => {
const compiledPath = getCompiledPath(code, fileName, compiledDir)
process.send &&
process.send({
compile: fileName,
compiledPath: compiledPath,
})
const sendFsCompileRequest = (fileName: string, compiledPath: string) => {
const compileRequestFile = [compiledDir, compilationId + '.req'].join(sep)
fs.writeFileSync(compileRequestFile, [fileName, compiledPath].join('\n'))
}

const compile = (code: string, fileName: string) => {
const compiledPath = getCompiledPath(code, fileName, compiledDir)
if (process.send) {
try {
process.send({
compile: fileName,
compiledPath: compiledPath,
})
} catch (e) {
console.warn('Error while sending compile request via process.send')
sendFsCompileRequest(fileName, compiledPath)
}
} else {
sendFsCompileRequest(fileName, compiledPath)
}

waitForFile(compiledPath + '.done')
const compiled = fs.readFileSync(compiledPath, 'utf-8')
return compiled
Expand Down

0 comments on commit d1cab45

Please sign in to comment.