UNPKG

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