Innovenergy_trunk/frontend/node_modules/testcafe/lib/live/file-watcher/index.js

69 lines
8.5 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = __importDefault(require("events"));
const fs_1 = __importDefault(require("fs"));
const modules_graph_1 = __importDefault(require("./modules-graph"));
const node_modules_folder_name_1 = __importDefault(require("../../utils/node-modules-folder-name"));
const to_posix_path_1 = __importDefault(require("../../utils/to-posix-path"));
const WATCH_LOCKED_TIMEOUT = 700;
let instance = null;
const BABEL_PRESET_STAGE_2_MODULE_PATH = 'lib/compiler/babel/preset-stage-2.js';
class FileWatcher extends events_1.default {
constructor() {
super();
if (!instance) {
this.watchers = {};
this.lockedFiles = {};
this.modulesGraph = null;
this.lastChangedFiles = [];
instance = this;
}
return instance;
}
_onChanged(controller, file) {
const cache = require.cache;
if (!this.modulesGraph) {
this.modulesGraph = new modules_graph_1.default();
this.modulesGraph.build(cache, Object.keys(this.watchers));
}
else {
this.lastChangedFiles.forEach(changedFile => this.modulesGraph.rebuildNode(cache, changedFile));
this.lastChangedFiles = [];
}
this.lastChangedFiles.push(file);
this.modulesGraph.clearParentsCache(cache, file);
controller.runTests(true);
}
_watch(controller, file) {
if (this.lockedFiles[file])
return;
this.lockedFiles[file] = setTimeout(() => {
this._onChanged(controller, file);
delete this.lockedFiles[file];
}, WATCH_LOCKED_TIMEOUT);
}
stop() {
Object.values(this.watchers).forEach(watcher => {
watcher.close();
});
}
addFile(controller, file) {
if (this.watchers[file] || !FileWatcher.shouldWatchFile(file))
return;
if (this.modulesGraph) {
this.lastChangedFiles.push(file);
this.modulesGraph.addNode(file, require.cache);
}
this.watchers[file] = fs_1.default.watch(file, () => this._watch(controller, file));
}
static shouldWatchFile(file) {
return !file.includes(node_modules_folder_name_1.default) &&
!(0, to_posix_path_1.default)(file).includes(BABEL_PRESET_STAGE_2_MODULE_PATH);
}
}
exports.default =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