MCPcopy
hub / github.com/angular/angular / createPerformWatchHost

Function createPerformWatchHost

packages/compiler-cli/src/perform_watch.ts:61–116  ·  view source on GitHub ↗
(
  configFileName: string,
  reportDiagnostics: (diagnostics: ReadonlyArray<ts.Diagnostic>) => void,
  existingOptions?: ts.CompilerOptions,
  createEmitCallback?: (options: api.CompilerOptions) => api.TsEmitCallback<CbEmitRes> | undefined,
)

Source from the content-addressed store, hash-verified

59}
60
61export 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
118interface CacheEntry {

Callers 1

watchModeFunction · 0.90

Calls 7

readConfigurationFunction · 0.90
createCompilerHostFunction · 0.85
watchMethod · 0.80
listenerFunction · 0.50
testMethod · 0.45
onMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…