[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.BuilderWatchPlugin = void 0;
|
---|
| 11 | class TimeInfoMap extends Map {
|
---|
| 12 | update(path, timestamp) {
|
---|
| 13 | this.set(path, Object.freeze({ safeTime: timestamp, timestamp }));
|
---|
| 14 | }
|
---|
| 15 | toTimestamps() {
|
---|
| 16 | const timestamps = new Map();
|
---|
| 17 | for (const [file, entry] of this) {
|
---|
| 18 | timestamps.set(file, entry.timestamp);
|
---|
| 19 | }
|
---|
| 20 | return timestamps;
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 | class BuilderWatchFileSystem {
|
---|
| 24 | constructor(watcherFactory, inputFileSystem) {
|
---|
| 25 | this.watcherFactory = watcherFactory;
|
---|
| 26 | this.inputFileSystem = inputFileSystem;
|
---|
| 27 | }
|
---|
| 28 | watch(files, directories, missing, startTime, _options, callback, callbackUndelayed) {
|
---|
| 29 | const watchedFiles = new Set(files);
|
---|
| 30 | const watchedDirectories = new Set(directories);
|
---|
| 31 | const watchedMissing = new Set(missing);
|
---|
| 32 | const timeInfo = new TimeInfoMap();
|
---|
| 33 | for (const file of files) {
|
---|
| 34 | timeInfo.update(file, startTime);
|
---|
| 35 | }
|
---|
| 36 | for (const directory of directories) {
|
---|
| 37 | timeInfo.update(directory, startTime);
|
---|
| 38 | }
|
---|
| 39 | const watcher = this.watcherFactory.watch(files, directories, (events) => {
|
---|
| 40 | if (events.length === 0) {
|
---|
| 41 | return;
|
---|
| 42 | }
|
---|
| 43 | if (callbackUndelayed) {
|
---|
| 44 | process.nextTick(() => { var _a; return callbackUndelayed(events[0].path, (_a = events[0].time) !== null && _a !== void 0 ? _a : Date.now()); });
|
---|
| 45 | }
|
---|
| 46 | process.nextTick(() => {
|
---|
| 47 | var _a, _b, _c;
|
---|
| 48 | const removals = new Set();
|
---|
| 49 | const fileChanges = new Set();
|
---|
| 50 | const directoryChanges = new Set();
|
---|
| 51 | const missingChanges = new Set();
|
---|
| 52 | for (const event of events) {
|
---|
| 53 | (_b = (_a = this.inputFileSystem).purge) === null || _b === void 0 ? void 0 : _b.call(_a, event.path);
|
---|
| 54 | if (event.type === 'deleted') {
|
---|
| 55 | timeInfo.delete(event.path);
|
---|
| 56 | removals.add(event.path);
|
---|
| 57 | }
|
---|
| 58 | else {
|
---|
| 59 | timeInfo.update(event.path, (_c = event.time) !== null && _c !== void 0 ? _c : Date.now());
|
---|
| 60 | if (watchedFiles.has(event.path)) {
|
---|
| 61 | fileChanges.add(event.path);
|
---|
| 62 | }
|
---|
| 63 | else if (watchedDirectories.has(event.path)) {
|
---|
| 64 | directoryChanges.add(event.path);
|
---|
| 65 | }
|
---|
| 66 | else if (watchedMissing.has(event.path)) {
|
---|
| 67 | missingChanges.add(event.path);
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | const timeInfoMap = new Map(timeInfo);
|
---|
| 72 | callback(undefined, timeInfoMap, timeInfoMap, new Set([...fileChanges, ...directoryChanges, ...missingChanges]), removals);
|
---|
| 73 | });
|
---|
| 74 | });
|
---|
| 75 | return {
|
---|
| 76 | close() {
|
---|
| 77 | watcher.close();
|
---|
| 78 | },
|
---|
| 79 | pause() { },
|
---|
| 80 | getFileTimeInfoEntries() {
|
---|
| 81 | return new Map(timeInfo);
|
---|
| 82 | },
|
---|
| 83 | getContextTimeInfoEntries() {
|
---|
| 84 | return new Map(timeInfo);
|
---|
| 85 | },
|
---|
| 86 | };
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | class BuilderWatchPlugin {
|
---|
| 90 | constructor(watcherFactory) {
|
---|
| 91 | this.watcherFactory = watcherFactory;
|
---|
| 92 | }
|
---|
| 93 | apply(compiler) {
|
---|
| 94 | compiler.hooks.environment.tap('BuilderWatchPlugin', () => {
|
---|
| 95 | compiler.watchFileSystem = new BuilderWatchFileSystem(this.watcherFactory, compiler.inputFileSystem);
|
---|
| 96 | });
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | exports.BuilderWatchPlugin = BuilderWatchPlugin;
|
---|