source: trip-planner-front/node_modules/@angular/compiler-cli/src/perform_watch.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 38.3 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8(function (factory) {
9 if (typeof module === "object" && typeof module.exports === "object") {
10 var v = factory(require, exports);
11 if (v !== undefined) module.exports = v;
12 }
13 else if (typeof define === "function" && define.amd) {
14 define("@angular/compiler-cli/src/perform_watch", ["require", "exports", "chokidar", "path", "typescript", "@angular/compiler-cli/src/perform_compile", "@angular/compiler-cli/src/transformers/api", "@angular/compiler-cli/src/transformers/entry_points", "@angular/compiler-cli/src/transformers/util"], factory);
15 }
16})(function (require, exports) {
17 "use strict";
18 Object.defineProperty(exports, "__esModule", { value: true });
19 exports.performWatchCompilation = exports.createPerformWatchHost = exports.FileChangeEvent = void 0;
20 var chokidar = require("chokidar");
21 var path = require("path");
22 var ts = require("typescript");
23 var perform_compile_1 = require("@angular/compiler-cli/src/perform_compile");
24 var api = require("@angular/compiler-cli/src/transformers/api");
25 var entry_points_1 = require("@angular/compiler-cli/src/transformers/entry_points");
26 var util_1 = require("@angular/compiler-cli/src/transformers/util");
27 function totalCompilationTimeDiagnostic(timeInMillis) {
28 var duration;
29 if (timeInMillis > 1000) {
30 duration = (timeInMillis / 1000).toPrecision(2) + "s";
31 }
32 else {
33 duration = timeInMillis + "ms";
34 }
35 return {
36 category: ts.DiagnosticCategory.Message,
37 messageText: "Total time: " + duration,
38 code: api.DEFAULT_ERROR_CODE,
39 source: api.SOURCE,
40 };
41 }
42 var FileChangeEvent;
43 (function (FileChangeEvent) {
44 FileChangeEvent[FileChangeEvent["Change"] = 0] = "Change";
45 FileChangeEvent[FileChangeEvent["CreateDelete"] = 1] = "CreateDelete";
46 FileChangeEvent[FileChangeEvent["CreateDeleteDir"] = 2] = "CreateDeleteDir";
47 })(FileChangeEvent = exports.FileChangeEvent || (exports.FileChangeEvent = {}));
48 function createPerformWatchHost(configFileName, reportDiagnostics, existingOptions, createEmitCallback) {
49 return {
50 reportDiagnostics: reportDiagnostics,
51 createCompilerHost: function (options) { return entry_points_1.createCompilerHost({ options: options }); },
52 readConfiguration: function () { return perform_compile_1.readConfiguration(configFileName, existingOptions); },
53 createEmitCallback: function (options) { return createEmitCallback ? createEmitCallback(options) : undefined; },
54 onFileChange: function (options, listener, ready) {
55 if (!options.basePath) {
56 reportDiagnostics([{
57 category: ts.DiagnosticCategory.Error,
58 messageText: 'Invalid configuration option. baseDir not specified',
59 source: api.SOURCE,
60 code: api.DEFAULT_ERROR_CODE
61 }]);
62 return { close: function () { } };
63 }
64 var watcher = chokidar.watch(options.basePath, {
65 // ignore .dotfiles, .js and .map files.
66 // can't ignore other files as we e.g. want to recompile if an `.html` file changes as well.
67 ignored: /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json|node_modules)/,
68 ignoreInitial: true,
69 persistent: true,
70 });
71 watcher.on('all', function (event, path) {
72 switch (event) {
73 case 'change':
74 listener(FileChangeEvent.Change, path);
75 break;
76 case 'unlink':
77 case 'add':
78 listener(FileChangeEvent.CreateDelete, path);
79 break;
80 case 'unlinkDir':
81 case 'addDir':
82 listener(FileChangeEvent.CreateDeleteDir, path);
83 break;
84 }
85 });
86 watcher.on('ready', ready);
87 return { close: function () { return watcher.close(); }, ready: ready };
88 },
89 setTimeout: (ts.sys.clearTimeout && ts.sys.setTimeout) || setTimeout,
90 clearTimeout: (ts.sys.setTimeout && ts.sys.clearTimeout) || clearTimeout,
91 };
92 }
93 exports.createPerformWatchHost = createPerformWatchHost;
94 /**
95 * The logic in this function is adapted from `tsc.ts` from TypeScript.
96 */
97 function performWatchCompilation(host) {
98 var cachedProgram; // Program cached from last compilation
99 var cachedCompilerHost; // CompilerHost cached from last compilation
100 var cachedOptions; // CompilerOptions cached from last compilation
101 var timerHandleForRecompilation; // Handle for 0.25s wait timer to trigger recompilation
102 var ignoreFilesForWatch = new Set();
103 var fileCache = new Map();
104 var firstCompileResult = doCompilation();
105 // Watch basePath, ignoring .dotfiles
106 var resolveReadyPromise;
107 var readyPromise = new Promise(function (resolve) { return resolveReadyPromise = resolve; });
108 // Note: ! is ok as options are filled after the first compilation
109 // Note: ! is ok as resolvedReadyPromise is filled by the previous call
110 var fileWatcher = host.onFileChange(cachedOptions.options, watchedFileChanged, resolveReadyPromise);
111 return { close: close, ready: function (cb) { return readyPromise.then(cb); }, firstCompileResult: firstCompileResult };
112 function cacheEntry(fileName) {
113 fileName = path.normalize(fileName);
114 var entry = fileCache.get(fileName);
115 if (!entry) {
116 entry = {};
117 fileCache.set(fileName, entry);
118 }
119 return entry;
120 }
121 function close() {
122 fileWatcher.close();
123 if (timerHandleForRecompilation) {
124 host.clearTimeout(timerHandleForRecompilation.timerHandle);
125 timerHandleForRecompilation = undefined;
126 }
127 }
128 // Invoked to perform initial compilation or re-compilation in watch mode
129 function doCompilation() {
130 if (!cachedOptions) {
131 cachedOptions = host.readConfiguration();
132 }
133 if (cachedOptions.errors && cachedOptions.errors.length) {
134 host.reportDiagnostics(cachedOptions.errors);
135 return cachedOptions.errors;
136 }
137 var startTime = Date.now();
138 if (!cachedCompilerHost) {
139 cachedCompilerHost = host.createCompilerHost(cachedOptions.options);
140 var originalWriteFileCallback_1 = cachedCompilerHost.writeFile;
141 cachedCompilerHost.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) {
142 if (sourceFiles === void 0) { sourceFiles = []; }
143 ignoreFilesForWatch.add(path.normalize(fileName));
144 return originalWriteFileCallback_1(fileName, data, writeByteOrderMark, onError, sourceFiles);
145 };
146 var originalFileExists_1 = cachedCompilerHost.fileExists;
147 cachedCompilerHost.fileExists = function (fileName) {
148 var ce = cacheEntry(fileName);
149 if (ce.exists == null) {
150 ce.exists = originalFileExists_1.call(this, fileName);
151 }
152 return ce.exists;
153 };
154 var originalGetSourceFile_1 = cachedCompilerHost.getSourceFile;
155 cachedCompilerHost.getSourceFile = function (fileName, languageVersion) {
156 var ce = cacheEntry(fileName);
157 if (!ce.sf) {
158 ce.sf = originalGetSourceFile_1.call(this, fileName, languageVersion);
159 }
160 return ce.sf;
161 };
162 var originalReadFile_1 = cachedCompilerHost.readFile;
163 cachedCompilerHost.readFile = function (fileName) {
164 var ce = cacheEntry(fileName);
165 if (ce.content == null) {
166 ce.content = originalReadFile_1.call(this, fileName);
167 }
168 return ce.content;
169 };
170 // Provide access to the file paths that triggered this rebuild
171 cachedCompilerHost.getModifiedResourceFiles = function () {
172 if (timerHandleForRecompilation === undefined) {
173 return undefined;
174 }
175 return timerHandleForRecompilation.modifiedResourceFiles;
176 };
177 }
178 ignoreFilesForWatch.clear();
179 var oldProgram = cachedProgram;
180 // We clear out the `cachedProgram` here as a
181 // program can only be used as `oldProgram` 1x
182 cachedProgram = undefined;
183 var compileResult = perform_compile_1.performCompilation({
184 rootNames: cachedOptions.rootNames,
185 options: cachedOptions.options,
186 host: cachedCompilerHost,
187 oldProgram: oldProgram,
188 emitCallback: host.createEmitCallback(cachedOptions.options)
189 });
190 if (compileResult.diagnostics.length) {
191 host.reportDiagnostics(compileResult.diagnostics);
192 }
193 var endTime = Date.now();
194 if (cachedOptions.options.diagnostics) {
195 var totalTime = (endTime - startTime) / 1000;
196 host.reportDiagnostics([totalCompilationTimeDiagnostic(endTime - startTime)]);
197 }
198 var exitCode = perform_compile_1.exitCodeFromResult(compileResult.diagnostics);
199 if (exitCode == 0) {
200 cachedProgram = compileResult.program;
201 host.reportDiagnostics([util_1.createMessageDiagnostic('Compilation complete. Watching for file changes.')]);
202 }
203 else {
204 host.reportDiagnostics([util_1.createMessageDiagnostic('Compilation failed. Watching for file changes.')]);
205 }
206 return compileResult.diagnostics;
207 }
208 function resetOptions() {
209 cachedProgram = undefined;
210 cachedCompilerHost = undefined;
211 cachedOptions = undefined;
212 }
213 function watchedFileChanged(event, fileName) {
214 var normalizedPath = path.normalize(fileName);
215 if (cachedOptions && event === FileChangeEvent.Change &&
216 // TODO(chuckj): validate that this is sufficient to skip files that were written.
217 // This assumes that the file path we write is the same file path we will receive in the
218 // change notification.
219 normalizedPath === path.normalize(cachedOptions.project)) {
220 // If the configuration file changes, forget everything and start the recompilation timer
221 resetOptions();
222 }
223 else if (event === FileChangeEvent.CreateDelete || event === FileChangeEvent.CreateDeleteDir) {
224 // If a file was added or removed, reread the configuration
225 // to determine the new list of root files.
226 cachedOptions = undefined;
227 }
228 if (event === FileChangeEvent.CreateDeleteDir) {
229 fileCache.clear();
230 }
231 else {
232 fileCache.delete(normalizedPath);
233 }
234 if (!ignoreFilesForWatch.has(normalizedPath)) {
235 // Ignore the file if the file is one that was written by the compiler.
236 startTimerForRecompilation(normalizedPath);
237 }
238 }
239 // Upon detecting a file change, wait for 250ms and then perform a recompilation. This gives batch
240 // operations (such as saving all modified files in an editor) a chance to complete before we kick
241 // off a new compilation.
242 function startTimerForRecompilation(changedPath) {
243 if (timerHandleForRecompilation) {
244 host.clearTimeout(timerHandleForRecompilation.timerHandle);
245 }
246 else {
247 timerHandleForRecompilation = {
248 modifiedResourceFiles: new Set(),
249 timerHandle: undefined
250 };
251 }
252 timerHandleForRecompilation.timerHandle = host.setTimeout(recompile, 250);
253 timerHandleForRecompilation.modifiedResourceFiles.add(changedPath);
254 }
255 function recompile() {
256 host.reportDiagnostics([util_1.createMessageDiagnostic('File change detected. Starting incremental compilation.')]);
257 doCompilation();
258 timerHandleForRecompilation = undefined;
259 }
260 }
261 exports.performWatchCompilation = performWatchCompilation;
262});
263//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVyZm9ybV93YXRjaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyLWNsaS9zcmMvcGVyZm9ybV93YXRjaC50cyJdLCJuY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NoYW5jZSB0byBjb21wbGV0ZSBiZWZvcmUgd2Uga2lja1xuICAvLyBvZmYgYSBuZXcgY29tcGlsYXRpb24uXG4gIGZ1bmN0aW9uIHN0YXJ0VGltZXJGb3JSZWNvbXBpbGF0aW9uKGNoYW5nZWRQYXRoOiBzdHJpbmcpIHtcbiAgICBpZiAodGltZXJIYW5kbGVGb3JSZWNvbXBpbGF0aW9uKSB7XG4gICAgICBob3N0LmNsZWFyVGltZW91dCh0aW1lckhhbmRsZUZvclJlY29tcGlsYXRpb24udGltZXJIYW5kbGUpO1xuICAgIH0gZWxzZSB7XG4gICAgICB0aW1lckhhbmRsZUZvclJlY29tcGlsYXRpb24gPSB7XG4gICAgICAgIG1vZGlmaWVkUmVzb3VyY2VGaWxlczogbmV3IFNldDxzdHJpbmc+KCksXG4gICAgICAgIHRpbWVySGFuZGxlOiB1bmRlZmluZWRcbiAgICAgIH07XG4gICAgfVxuICAgIHRpbWVySGFuZGxlRm9yUmVjb21waWxhdGlvbi50aW1lckhhbmRsZSA9IGhvc3Quc2V0VGltZW91dChyZWNvbXBpbGUsIDI1MCk7XG4gICAgdGltZXJIYW5kbGVGb3JSZWNvbXBpbGF0aW9uLm1vZGlmaWVkUmVzb3VyY2VGaWxlcy5hZGQoY2hhbmdlZFBhdGgpO1xuICB9XG5cbiAgZnVuY3Rpb24gcmVjb21waWxlKCkge1xuICAgIGhvc3QucmVwb3J0RGlhZ25vc3RpY3MoXG4gICAgICAgIFtjcmVhdGVNZXNzYWdlRGlhZ25vc3RpYygnRmlsZSBjaGFuZ2UgZGV0ZWN0ZWQuIFN0YXJ0aW5nIGluY3JlbWVudGFsIGNvbXBpbGF0aW9uLicpXSk7XG4gICAgZG9Db21waWxhdGlvbigpO1xuICAgIHRpbWVySGFuZGxlRm9yUmVjb21waWxhdGlvbiA9IHVuZGVmaW5lZDtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.