Skip to content

Instantly share code, notes, and snippets.

@cevek
Last active June 30, 2019 11:06
Show Gist options
  • Save cevek/5d0134a3387f9114386d8ee4f55f3473 to your computer and use it in GitHub Desktop.
Save cevek/5d0134a3387f9114386d8ee4f55f3473 to your computer and use it in GitHub Desktop.
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