Socket
Socket
Sign inDemoInstall

watchpack

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchpack - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

8

lib/DirectoryWatcher.js

@@ -43,3 +43,3 @@ /*

function DirectoryWatcher(directoryPath /*, options */) {
function DirectoryWatcher(directoryPath, options) {
EventEmitter.call(this);

@@ -55,3 +55,5 @@ this.path = directoryPath;

atomic: false,
ignorePermissionErrors: true
ignorePermissionErrors: true,
usePolling: options.poll ? true : undefined,
interval: typeof options.poll === "number" ? options.poll : undefined
});

@@ -137,3 +139,3 @@ this.watcher.on("add", this.onFileAdded.bind(this));

DirectoryWatcher.prototype.createNestedWatcher = function(directoryPath) {
this.directories[directoryPath] = watcherManager.watchDirectory(directoryPath, 1);
this.directories[directoryPath] = watcherManager.watchDirectory(directoryPath, this.options, 1);
this.directories[directoryPath].on("change", function(filePath, mtime) {

@@ -140,0 +142,0 @@ if(this.watchers[withoutCase(this.path)]) {

@@ -11,22 +11,24 @@ /*

WatcherManager.prototype.getDirectoryWatcher = function(directory) {
WatcherManager.prototype.getDirectoryWatcher = function(directory, options) {
var DirectoryWatcher = require("./DirectoryWatcher");
if(!this.directoryWatchers[directory]) {
this.directoryWatchers[directory] = new DirectoryWatcher(directory, {});
this.directoryWatchers[directory].on("closed", function() {
delete this.directoryWatchers[directory];
options = options || {};
var key = directory + " " + JSON.stringify(options);
if(!this.directoryWatchers[key]) {
this.directoryWatchers[key] = new DirectoryWatcher(directory, options);
this.directoryWatchers[key].on("closed", function() {
delete this.directoryWatchers[key];
}.bind(this));
}
return this.directoryWatchers[directory];
return this.directoryWatchers[key];
};
WatcherManager.prototype.watchFile = function watchFile(p, startTime) {
WatcherManager.prototype.watchFile = function watchFile(p, options, startTime) {
var directory = path.dirname(p);
return this.getDirectoryWatcher(directory).watch(p, startTime);
return this.getDirectoryWatcher(directory, options).watch(p, startTime);
};
WatcherManager.prototype.watchDirectory = function watchDirectory(directory, startTime) {
return this.getDirectoryWatcher(directory).watch(directory, startTime);
WatcherManager.prototype.watchDirectory = function watchDirectory(directory, options, startTime) {
return this.getDirectoryWatcher(directory, options).watch(directory, startTime);
};
module.exports = new WatcherManager();

@@ -13,2 +13,5 @@ /*

this.options = options;
this.watcherOptions = {
poll: options.poll
};
this.fileWatchers = [];

@@ -32,6 +35,6 @@ this.dirWatchers = [];

this.fileWatchers = files.map(function(file) {
return this._fileWatcher(file, watcherManager.watchFile(file, startTime));
return this._fileWatcher(file, watcherManager.watchFile(file, this.watcherOptions, startTime));
}, this);
this.dirWatchers = directories.map(function(dir) {
return this._dirWatcher(dir, watcherManager.watchDirectory(dir, startTime));
return this._dirWatcher(dir, watcherManager.watchDirectory(dir, this.watcherOptions, startTime));
}, this);

@@ -38,0 +41,0 @@ oldFileWatchers.forEach(function(w) {

{
"name": "watchpack",
"version": "0.2.6",
"version": "0.2.7",
"description": "",

@@ -5,0 +5,0 @@ "main": "./lib/watchpack.js",

@@ -28,2 +28,9 @@ # watchpack

// fire "aggregated" event when after a change for 1000ms no additonal change occured
// aggregated defaults to undefined, which doesn't fire an "aggregated" event
poll: true
// poll: true - use polling with the default interval
// poll: 10000 - use polling with an interval of 10s
// poll defaults to undefined, which prefer native watching methods
// Note: enable polling when watching on a network path
});

@@ -30,0 +37,0 @@

@@ -12,4 +12,4 @@ /*globals describe it beforeEach afterEach */

var DirectoryWatcher = function(p) {
var d = new OrgDirectoryWatcher(p);
var DirectoryWatcher = function(p, options) {
var d = new OrgDirectoryWatcher(p, options);
openWatchers.push(d);

@@ -39,3 +39,3 @@ var orgClose = d.close;

it("should detect a file creation", function(done) {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
var a = d.watch(path.join(fixtures, "a"));

@@ -56,3 +56,3 @@ a.on("change", function(mtime) {

it("should detect a file change", function(done) {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
testHelper.file("a");

@@ -73,3 +73,3 @@ var a = d.watch(path.join(fixtures, "a"));

testHelper.tick(function() {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
var a = d.watch(path.join(fixtures, "a"));

@@ -91,3 +91,3 @@ a.on("change", function() {

testHelper.tick(1000, function() {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
var a = d.watch(path.join(fixtures, "a"), start);

@@ -105,3 +105,3 @@ a.on("change", function() {

testHelper.tick(function() {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
var a = d.watch(path.join(fixtures, "a"));

@@ -125,3 +125,3 @@ a.on("change", function() {

it("should detect multiple file changes (" + name + ")", function(done) {
var d = new DirectoryWatcher(fixtures);
var d = new DirectoryWatcher(fixtures, {});
testHelper.file("a");

@@ -128,0 +128,0 @@ testHelper.tick(function() {

@@ -105,2 +105,32 @@ /*globals describe it beforeEach afterEach */

it("should watch a file than a directory", function(done) {
var w = new Watchpack({
aggregateTimeout: 1000
});
var changeEvents = [];
w.on("change", function(file) {
if(changeEvents[changeEvents.length - 1] === file)
return;
changeEvents.push(file);
});
w.on("aggregated", function(changes) {
changes.should.be.eql([path.join(fixtures, "dir")]);
changeEvents.should.be.eql([path.join(fixtures, "dir", "a")]);
w.close();
done();
});
testHelper.dir("dir");
testHelper.dir(path.join("dir", "subdir"));
testHelper.file(path.join("dir", "a"));
testHelper.tick(function() {
w.watch([path.join(fixtures, "dir", "a")], []);
testHelper.tick(function() {
w.watch([path.join(fixtures, "dir")], [path.join(fixtures, "dir")]);
testHelper.tick(function() {
testHelper.file(path.join("dir", "a"));
});
});
});
});
it("should watch a directory (delete file)", function(done) {

@@ -107,0 +137,0 @@ var w = new Watchpack({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc