Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1 to 0.2.2

.travis.yml

1

lib/DirectoryWatcher.js

@@ -26,2 +26,3 @@ /*

depth: 0,
atomic: false,
ignorePermissionErrors: true

@@ -28,0 +29,0 @@ });

4

package.json
{
"name": "watchpack",
"version": "0.2.1",
"version": "0.2.2",
"description": "",

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

"async": "^0.9.0",
"chokidar": "^0.12.0",
"chokidar": "paulmillr/chokidar#f4c49296b708c6901429a6497b31a8b907bdd8c0",
"graceful-fs": "^3.0.2"
}
}

@@ -5,2 +5,4 @@ # watchpack

[![Build Status](https://travis-ci.org/webpack/watchpack.svg?branch=master)](https://travis-ci.org/webpack/watchpack) [![Build status](https://ci.appveyor.com/api/projects/status/e5u2qvmugtv0r647/branch/master?svg=true)](https://ci.appveyor.com/project/sokra/watchpack/branch/master)
## Concept

@@ -11,6 +13,8 @@

* The high level API requests `DirectoryWatchers` from a `WatcherManager`, which ensures that only a single `DirectoryWatcher` per directory is created.
* A `FileWatcher` can be obtained from a `DirectoryWatcher` and provides a filtered view on the `DirectoryWatcher`.
* Reference-counting is used on the `DirectoryWatcher` and `FileWatcher` to decide when to close them.
* A user-faced `Watcher` can be obtained from a `DirectoryWatcher` and provides a filtered view on the `DirectoryWatcher`.
* Reference-counting is used on the `DirectoryWatcher` and `Watcher` to decide when to close them.
* The real watchers (currently chokidar) are created by the `DirectoryWatcher`.
* Files are never watched directly. This should keep the watcher count low.
* Watching can be started in the past. This way watching can start after file reading.
* Symlinks are not followed, instead the symlink is watched.

@@ -17,0 +21,0 @@ ## API

var should = require("should");
var path = require("path");
var TestHelper = require("./helpers/TestHelper");
var DirectoryWatcher = require("../lib/DirectoryWatcher");
var OrgDirectoryWatcher = require("../lib/DirectoryWatcher");

@@ -9,2 +9,18 @@ var fixtures = path.join(__dirname, "fixtures");

var openWatchers = [];
DirectoryWatcher = function(p) {
var d = new OrgDirectoryWatcher(p);
openWatchers.push(d);
var orgClose = d.close;
d.close = function() {
orgClose.call(this);
var idx = openWatchers.indexOf(d);
if(idx < 0)
throw new Error("DirectoryWatcher was already closed");
openWatchers.splice(idx, 1);
}
return d;
}
describe("DirectoryWatcher", function() {

@@ -14,2 +30,8 @@ this.timeout(10000);

afterEach(testHelper.after);
afterEach(function() {
openWatchers.forEach(function(d) {
console.log("DirectoryWatcher (" + d.path + ") was not closed.");
d.close();
})
})

@@ -86,26 +108,34 @@ it("should detect a file creation", function(done) {

it("should detect multiple file changes", function(done) {
var d = new DirectoryWatcher(fixtures);
testHelper.file("a");
testHelper.tick(function() {
var a = d.watch(path.join(fixtures, "a"));
var count = 20;
var wasChanged = false;
a.on("change", function(mtime) {
mtime.should.be.type("number");
if(!wasChanged) return;
wasChanged = false;
if(count-- <= 0) {
a.close();
done();
} else {
testHelper.tick(function() {
wasChanged = true;
testHelper.file("a");
});
}
});
var timings = {
slow: 300,
fast: 50,
// reallyFast: 5,
};
Object.keys(timings).forEach(function(name) {
var time = timings[name];
it("should detect multiple file changes (" + name + ")", function(done) {
var d = new DirectoryWatcher(fixtures);
testHelper.file("a");
testHelper.tick(function() {
wasChanged = true;
testHelper.file("a");
var a = d.watch(path.join(fixtures, "a"));
var count = 20;
var wasChanged = false;
a.on("change", function(mtime) {
mtime.should.be.type("number");
if(!wasChanged) return;
wasChanged = false;
if(count-- <= 0) {
a.close();
done();
} else {
testHelper.tick(time, function() {
wasChanged = true;
testHelper.file("a");
});
}
});
testHelper.tick(function() {
wasChanged = true;
testHelper.file("a");
});
});

@@ -112,0 +142,0 @@ });

@@ -29,6 +29,6 @@ var fs = require("fs");

TestHelper.prototype._after = function after(done) {
this.tick(function() {
this.tick(300, function() {
rimraf.sync(this.testdir);
Object.keys(watcherManager.directoryWatchers).should.be.eql([]);
done();
this.tick(300, done);
}.bind(this));

@@ -35,0 +35,0 @@ };

var should = require("should");
var path = require("path");
var TestHelper = require("./helpers/TestHelper");
var Watchpack = require("../lib/Watchpack");
var Watchpack = require("../lib/watchpack");

@@ -46,3 +46,3 @@ var fixtures = path.join(__dirname, "fixtures");

w.on("aggregated", function(changes) {
changes.should.be.eql([path.join(fixtures, "a"), path.join(fixtures, "b")]);
changes.sort().should.be.eql([path.join(fixtures, "a"), path.join(fixtures, "b")]);
changeEvents.should.be.eql([

@@ -197,3 +197,3 @@ path.join(fixtures, "a"),

changes.should.be.eql([path.join(fixtures, "a")]);
changeEvents.should.be.eql(1);
changeEvents.should.be.greaterThan(0);
w.close();

@@ -200,0 +200,0 @@ done();

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