( configFileName: string, reportDiagnostics: (diagnostics: ReadonlyArray<ts.Diagnostic>) => void, existingOptions?: ts.CompilerOptions, createEmitCallback?: (options: api.CompilerOptions) => api.TsEmitCallback<CbEmitRes> | undefined, )
| 59 | } |
| 60 | |
| 61 | export function createPerformWatchHost<CbEmitRes extends ts.EmitResult = ts.EmitResult>( |
| 62 | configFileName: string, |
| 63 | reportDiagnostics: (diagnostics: ReadonlyArray<ts.Diagnostic>) => void, |
| 64 | existingOptions?: ts.CompilerOptions, |
| 65 | createEmitCallback?: (options: api.CompilerOptions) => api.TsEmitCallback<CbEmitRes> | undefined, |
| 66 | ): PerformWatchHost { |
| 67 | return { |
| 68 | reportDiagnostics: reportDiagnostics, |
| 69 | createCompilerHost: (options) => createCompilerHost({options}), |
| 70 | readConfiguration: () => readConfiguration(configFileName, existingOptions), |
| 71 | createEmitCallback: (options) => (createEmitCallback ? createEmitCallback(options) : undefined), |
| 72 | onFileChange: (options, listener, ready: () => void) => { |
| 73 | if (!options.basePath) { |
| 74 | reportDiagnostics([ |
| 75 | { |
| 76 | category: ts.DiagnosticCategory.Error, |
| 77 | messageText: 'Invalid configuration option. baseDir not specified', |
| 78 | source: api.SOURCE, |
| 79 | code: api.DEFAULT_ERROR_CODE, |
| 80 | file: undefined, |
| 81 | start: undefined, |
| 82 | length: undefined, |
| 83 | }, |
| 84 | ]); |
| 85 | return {close: () => {}}; |
| 86 | } |
| 87 | const watcher = chokidar.watch(options.basePath, { |
| 88 | // ignore .dotfiles, .js and .map files. |
| 89 | // can't ignore other files as we e.g. want to recompile if an `.html` file changes as well. |
| 90 | ignored: (path) => |
| 91 | /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json|node_modules)/.test(path), |
| 92 | ignoreInitial: true, |
| 93 | persistent: true, |
| 94 | }); |
| 95 | watcher.on('all', (event: string, path: string) => { |
| 96 | switch (event) { |
| 97 | case 'change': |
| 98 | listener(FileChangeEvent.Change, path); |
| 99 | break; |
| 100 | case 'unlink': |
| 101 | case 'add': |
| 102 | listener(FileChangeEvent.CreateDelete, path); |
| 103 | break; |
| 104 | case 'unlinkDir': |
| 105 | case 'addDir': |
| 106 | listener(FileChangeEvent.CreateDeleteDir, path); |
| 107 | break; |
| 108 | } |
| 109 | }); |
| 110 | watcher.on('ready', ready); |
| 111 | return {close: () => watcher.close(), ready}; |
| 112 | }, |
| 113 | setTimeout: (ts.sys.clearTimeout && ts.sys.setTimeout) || setTimeout, |
| 114 | clearTimeout: (ts.sys.setTimeout && ts.sys.clearTimeout) || clearTimeout, |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | interface CacheEntry { |
no test coverage detected
searching dependent graphs…