Comparing version 0.2.1 to 0.2.2
@@ -26,2 +26,3 @@ /* | ||
depth: 0, | ||
atomic: false, | ||
ignorePermissionErrors: true | ||
@@ -28,0 +29,0 @@ }); |
{ | ||
"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(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31183
13
894
59
1
1
- Removedasync-each@0.1.6(transitive)
- Removedchokidar@0.12.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfsevents@0.3.8(transitive)
- Removedgraceful-fs@2.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.2.14(transitive)
- Removednan@2.22.0(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedreaddirp@1.3.0(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
Updatedchokidar@paulmillr/chokidar#f4c49296b708c6901429a6497b31a8b907bdd8c0