My custom TypeScript watcher is set up like this:
const compilerHost = typescript.createWatchCompilerHost(config.fileNames, config.options, typescript.sys, undefined, reportDiagnostic)
typescript.createWatchProgram(compilerHost)
I am trying to integrate a custom transformer into the watcher for when it compiles my .ts
files. If I was compiling just once, I would include the transformer as shown below.
const program = typescript.createProgram(config.fileNames, config.options)
const emitResult = program.emit(undefined, undefined, undefined, undefined, { before: [ transformer(program) ] })
However, I can't figure out how to add the transformer to either the compiler host or the watch program creation process.
Is there a way to attach a custom transformer to a watch compiler host?
One potential approach might involve supplying a custom CreateProgram
function to the createWatchCompilerHost
, which overrides the emit
function with my custom transformer. However, I'm unsure of the feasibility of this method and am seeking alternative solutions.