Last active
June 30, 2019 11:06
-
-
Save cevek/5d0134a3387f9114386d8ee4f55f3473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ts from 'typescript'; | |
const watchCompilerHost = ts.createWatchCompilerHost( | |
['index.ts'], | |
{strict: true, target: ts.ScriptTarget.ESNext}, | |
ts.sys, | |
); | |
const originalCreateProgram = watchCompilerHost.createProgram; | |
watchCompilerHost.watchFile = (path, callback) => { | |
// console.log('watchFile', path); | |
return { | |
close() {}, | |
}; | |
}; | |
watchCompilerHost.onWatchStatusChange = () => { | |
console.log('Updates'); | |
}; | |
const origAfterProgramCreate = watchCompilerHost.afterProgramCreate; | |
watchCompilerHost.afterProgramCreate = p => { | |
origAfterProgramCreate!(p); | |
console.log('done'); | |
}; | |
watchCompilerHost.createProgram = (...args) => { | |
const compilerHost = args[2]!; | |
compilerHost.writeFile = file => { | |
console.log('write', file); | |
}; | |
return originalCreateProgram(...args); | |
}; | |
const builder = ts.createWatchProgram(watchCompilerHost); | |
setTimeout(() => { | |
builder.updateRootFileNames(['x.ts']); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment