Socket
Socket
Sign inDemoInstall

watch

Package Overview
Dependencies
0
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.0 to 0.9.0

test/test_monitorRootDirectory.js

16

main.js

@@ -50,3 +50,3 @@ // Copyright 2010-2011 Mikeal Rogers

if (options.ignoreDotFiles && path.basename(f)[0] === '.') return done && callback(null, callback.files);
if (options.filter && options.filter(f, stat)) return done && callback(null, callback.files);
if (options.filter && !options.filter(f, stat)) return done && callback(null, callback.files);
callback.files[f] = stat;

@@ -108,2 +108,4 @@ if (stat.isDirectory()) walk(f, options, callback);

var monitor = new events.EventEmitter();
var prevFile = {file: null,action: null};
exports.watchTree(root, options, function (f, curr, prev) {

@@ -114,9 +116,15 @@ if (typeof f == "object" && prev == null && curr === null) {

}
if (prev === null) {
if (prev === null && (prevFile.file != f || prevFile.action != "created")) {
prevFile = { file: f, action: "created" };
return monitor.emit("created", f, curr);
}
if (curr.nlink === 0) {
if (curr.nlink === 0 && (prevFile.file != f || prevFile.action != "removed")) {
prevFile = { file: f, action: "removed" };
return monitor.emit("removed", f, curr);
}
monitor.emit("changed", f, curr, prev);
if (prevFile.file != null) {
prevFile = {file: null,action: null};
} else {
monitor.emit("changed", f, curr, prev);
}
})

@@ -123,0 +131,0 @@ }

@@ -10,3 +10,3 @@ {

],
"version": "0.8.0",
"version": "0.9.0",
"homepage": "https://github.com/mikeal/watch",

@@ -13,0 +13,0 @@ "bugs": {

@@ -1,9 +0,20 @@

var watch = require('../main')
var fs = require('fs')
, watch = require('../main')
, assert = require('assert')
;
watch.watchTree(__dirname, function (f, curr, prev) {
// console.log('file '+f+' prev '+prev+' curr '+curr);
// console.dir(curr)
// console.dir(prev)
});
//
// Demonstrate that the function of 'filter' is semantically inconsistent with
// usual convention, that returning true means 'keep this'.
//
function isDirOrQ(f, stat) { return stat.isDirectory() || f === 'Q'; }
watch.watchTree(__dirname, { filter: isDirOrQ }, function (f, curr, prev) {
if (typeof f == 'object' && prev === null && curr === null) {
Object.keys(f).forEach(function(name) {
var stat = f[name];
assert(isDirOrQ(name, stat));
fs.unwatchFile(name);
});
}
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc