Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.watch = function(patterns, excludes, fileList) {
var options = {
ignorePermissionErrors: true,
ignored: createIgnore(excludes)
};
var chokidarWatcher = new chokidar.FSWatcher(options);
watchPatterns(patterns, chokidarWatcher);
var bind = function(fn) {
return function(path) {
return fn.call(fileList, helper.normalizeWinPath(path));
};
};
// register events
chokidarWatcher.on('add', bind(fileList.addFile))
.on('change', bind(fileList.changeFile))
.on('unlink', bind(fileList.removeFile));
return chokidarWatcher;
};
function init(options: EncodedFSWatcherOptions) {
let decodedOptions = decodeOptions(options);
watcher = new FSWatcher(decodedOptions);
watcher.on('all', sendEvent);
sendEvent('ready');
// only used for testing
watcher.once('ready', async () => {
// Wait an additional macrotask. This seems to be necessary before changes
// can be picked up.
await new Promise(resolve => setImmediate(resolve));
sendEvent('_chokidarReady');
});
}
return new rxjs_1.Observable(obs => {
const watcher = new FSWatcher({ persistent: true }).add(src_1.getSystemPath(path));
watcher
.on('change', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 0 /* Changed */,
});
})
.on('add', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 1 /* Created */,
});
})
.on('unlink', path => {
return new Observable_1.Observable(obs => {
const watcher = new FSWatcher({ persistent: true }).add(this._getSystemPath(path));
watcher
.on('change', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 0 /* Changed */,
});
})
.on('add', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 1 /* Created */,
});
})
.on('unlink', path => {
return new rxjs_1.Observable(obs => {
const opts = { persistent: false };
const watcher = new FSWatcher(opts).add(src_1.getSystemPath(path));
watcher
.on('change', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 0 /* Changed */,
});
})
.on('add', path => {
obs.next({
path: src_1.normalize(path),
time: new Date(),
type: 1 /* Created */,
});
})
.on('unlink', path => {
exports.watch = function(patterns, excludes, fileList, usePolling, emitter) {
var watchedPatterns = getWatchedPatterns(patterns);
var options = {
usePolling: usePolling,
ignorePermissionErrors: true,
ignoreInitial: true,
ignored: createIgnore(watchedPatterns, excludes)
};
var chokidarWatcher = new chokidar.FSWatcher(options);
watchPatterns(watchedPatterns, chokidarWatcher);
var bind = function(fn) {
return function(path) {
return fn.call(fileList, helper.normalizeWinPath(path));
};
};
// register events
chokidarWatcher.on('add', bind(fileList.addFile))
.on('change', bind(fileList.changeFile))
.on('unlink', bind(fileList.removeFile))
// If we don't subscribe; unhandled errors from Chokidar will bring Karma down
// (see GH Issue #959)
.on('error', function(e) {
function watch(dir, type, onChange) {
var extension = extensions[type];
var hashes = {};
var watcher = new chokidar.FSWatcher;
watcher
.on('add', checkModified)
.on('change', checkModified)
.on('unlink', checkModified)
.on('error', function(err) {
console.error('Watch error\n', err);
})
files(dir, extension).forEach(function(path) {
fs.readFile(path, 'utf8', function(err, file) {
if (err) return console.error('Watch error\n', err);
hashes[path] = hashFile(file);
watcher.add(path);
});
});
import chokidar from 'chokidar'
import walk from 'klaw'
import fs from 'fs-extra'
import directorySize from './directorySize'
import pathExists from './pathExists'
import pathIs from './pathIs'
import completeAssign from '../util/completeAssign'
const base = {
walk,
chokidarWatch: chokidar.watch,
FSWatcher: chokidar.FSWatcher
}
export default completeAssign(base, fs, directorySize, pathExists, pathIs)
Bundle.prototype.watchFile = function watchFile(filename, cb) {
if (!Bundle._fileWatcher) {
Bundle._fileWatcher = new chokidar.FSWatcher();
Bundle._fileWatcher.on('change', this._onFileChange);
}
if (Bundle._watchedFiles[filename]) {
Bundle._watchedFiles[filename].push(cb);
} else {
Bundle._watchedFiles[filename] = [cb];
Bundle._fileWatcher.add(filename);
}
};
constructor() {
super();
this.fileCaches = new Set();
this.resolverCaches = new Set();
this._fileWatcher = new FSWatcher({
ignored: /[\/\\]\./,
persistent: true
});
this._fileWatcher.on('change', this.onWatchChange.bind(this));
this._fileWatcher.on('unlink', this.onWatchDelete.bind(this));
this._fileWatcher.on('error', this.onWatchError.bind(this));
this.createCaches = this.createCaches.bind(this);
this.clear = this.clear.bind(this);
this.debouncedEmit = debounce(this.emit, 100, { trailing: true });
}