New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-watcher

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-watcher - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

26

index.js

@@ -12,15 +12,21 @@ 'use strict'

let options = { persistent: true, recursive: recursive }
let last = { filePath: null, timestamp: null }
let last = { filePath: null, timestamp: -1 }
let w = fs.watch(workingDir, options, (event, fileName) => {
// On Windows fileName may actually be empty.
// In such case assume this is the working dir change.
let filePath = fileName ? path.join(workingDir, fileName) : workingDir
// Eliminate double reporting.
if (tolerance) {
// Compare last modified time.
let stat = fs.statSync(filePath)
let timestamp = (new Date(stat.mtime)).getTime()
if (filePath === last.filePath && timestamp - last.timestamp < tolerance) {
return
if (!tolerance) {
return callback(filePath)
}
fs.stat(filePath, (err, stat) => {
// If error, the file was likely deleted.
let timestamp = err ? -1 : (new Date(stat.mtime)).getTime()
let timePassed = timestamp - last.timestamp < tolerance || timestamp === -1
let fileMatches = filePath === last.FilePath
if (fileMatches && timePassed) {
callback(filePath)
}

@@ -30,5 +36,3 @@

last.timestamp = timestamp
}
callback(filePath)
})
})

@@ -35,0 +39,0 @@

{
"name": "simple-watcher",
"version": "1.0.2",
"version": "1.0.3",
"description": "\"A simple recursive directory watcher.\"",

@@ -5,0 +5,0 @@ "main": "index.js",

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