From 2675763493d3ad99e1d8a21a4fd328cad17090c9 Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Mon, 23 Jan 2023 23:11:57 +0300 Subject: [PATCH] Add `spawnCallback` option --- index.d.ts | 7 +++++++ index.js | 4 ++++ readme.md | 2 ++ 3 files changed, 13 insertions(+) diff --git a/index.d.ts b/index.d.ts index 75abd3c..dbe76ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,4 @@ +import { ChildProcess } from 'child_process' import { Readable, Transform } from 'stream' /** @@ -39,6 +40,12 @@ export interface LatexOptions { * to. */ errorLogs?: string + + /** + * A function to call on each LaTeX invocation. The only argument is an instance + * of ChildProcess. + */ + spawnCallback?: (proc: ChildProcess) => void } /** diff --git a/index.js b/index.js index b77e7b9..6f8a01d 100644 --- a/index.js +++ b/index.js @@ -162,6 +162,10 @@ function latex(src, options) { const runLatex = (inputStream) => { const tex = spawn(cmd, args, opts) + if (options.spawnCallback) { + options.spawnCallback(tex); + } + inputStream.pipe(tex.stdin) // Prevent Node from crashing on compilation error. diff --git a/readme.md b/readme.md index 13ce34d..ef51c47 100644 --- a/readme.md +++ b/readme.md @@ -48,5 +48,7 @@ View more examples [here](https://github.com/saadq/node-latex/tree/master/exampl **options.errorLogs** \[String] - The path to the file where you want to save the contents of the error log to. +**options.spawnCallback** \[Function] - A function to call on each LaTeX invocation. The only argument is an instance of `ChildProcess`. + ## License MIT