ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / fsWatcher.js
Source Blame History 67 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var fsWatcher_exports = {};
f7eb47b… lmata 20 __export(fsWatcher_exports, {
f7eb47b… lmata 21 Watcher: () => Watcher
f7eb47b… lmata 22 });
f7eb47b… lmata 23 module.exports = __toCommonJS(fsWatcher_exports);
f7eb47b… lmata 24 var import_utilsBundle = require("./utilsBundle");
f7eb47b… lmata 25 class Watcher {
f7eb47b… lmata 26 constructor(onChange) {
f7eb47b… lmata 27 this._watchedPaths = [];
f7eb47b… lmata 28 this._ignoredFolders = [];
f7eb47b… lmata 29 this._collector = [];
f7eb47b… lmata 30 this._onChange = onChange;
f7eb47b… lmata 31 }
f7eb47b… lmata 32 async update(watchedPaths, ignoredFolders, reportPending) {
f7eb47b… lmata 33 if (JSON.stringify([this._watchedPaths, this._ignoredFolders]) === JSON.stringify([watchedPaths, ignoredFolders]))
f7eb47b… lmata 34 return;
f7eb47b… lmata 35 if (reportPending)
f7eb47b… lmata 36 this._reportEventsIfAny();
f7eb47b… lmata 37 this._watchedPaths = watchedPaths;
f7eb47b… lmata 38 this._ignoredFolders = ignoredFolders;
f7eb47b… lmata 39 void this._fsWatcher?.close();
f7eb47b… lmata 40 this._fsWatcher = void 0;
f7eb47b… lmata 41 this._collector.length = 0;
f7eb47b… lmata 42 clearTimeout(this._throttleTimer);
f7eb47b… lmata 43 this._throttleTimer = void 0;
f7eb47b… lmata 44 if (!this._watchedPaths.length)
f7eb47b… lmata 45 return;
f7eb47b… lmata 46 const ignored = [...this._ignoredFolders, "**/node_modules/**"];
f7eb47b… lmata 47 this._fsWatcher = import_utilsBundle.chokidar.watch(watchedPaths, { ignoreInitial: true, ignored }).on("all", async (event, file) => {
f7eb47b… lmata 48 if (this._throttleTimer)
f7eb47b… lmata 49 clearTimeout(this._throttleTimer);
f7eb47b… lmata 50 this._collector.push({ event, file });
f7eb47b… lmata 51 this._throttleTimer = setTimeout(() => this._reportEventsIfAny(), 250);
f7eb47b… lmata 52 });
f7eb47b… lmata 53 await new Promise((resolve, reject) => this._fsWatcher.once("ready", resolve).once("error", reject));
f7eb47b… lmata 54 }
f7eb47b… lmata 55 async close() {
f7eb47b… lmata 56 await this._fsWatcher?.close();
f7eb47b… lmata 57 }
f7eb47b… lmata 58 _reportEventsIfAny() {
f7eb47b… lmata 59 if (this._collector.length)
f7eb47b… lmata 60 this._onChange(this._collector.slice());
f7eb47b… lmata 61 this._collector.length = 0;
f7eb47b… lmata 62 }
f7eb47b… lmata 63 }
f7eb47b… lmata 64 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 65 0 && (module.exports = {
f7eb47b… lmata 66 Watcher
f7eb47b… lmata 67 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button