Typescript transformer & watch: Implement simple C-like header file

20 Views Asked by At

Basically what I am trying is to make some ts file (global.ts) act like a "header file":

// global.ts
function mylog(msg: any) {
    console.log(String(msg))
}

// a.ts
mylog("a")

// b.ts
mylog("b")

gets

// a.js
function mylog(msg) {
    console.log(String(msg))
}
mylog("a")

// b.js
function mylog(msg) {
    console.log(String(msg))
}
mylog("b")

I am creating a watch compiler using createWatchCompilerHost and createWatchProgram, injecting transformers by "intercepting createProgram and overriding its emit method" hacking: TypeScript custom transformers with ts.createWatchProgram

There are 3 key requirements:

  1. No emitting for the "header file". (I know d.ts, but the "header file" contains implementations.)
  2. (On the first run) Run transformer first on the "header file" (to grab AST), then other files.
  3. Recompile all files when the "header file" changes.

Current progress:

  1. Don't know
  2. Don't know
  3. Recompilation only triggered by symbolic changes of the "header file"; implementation changes alone won't trigger.

Anyone give some help?

0

There are 0 best solutions below