Huge News!Announcing our $40M Series B led by Abstract Ventures.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 0.1.0 to 0.1.1

59

index.js

@@ -12,17 +12,16 @@ 'use strict'

fs.watch(workingDir, options, (event, fileName) => {
let w = fs.watch(workingDir, options, (event, fileName) => {
callback(path.join(workingDir, fileName))
})
w.on('error', (e) => {
w.close()
})
}
// Attach watchers recursively.
// This code is synchronous in order to be able tell when it actuall ends.
let watchFolderFallback = (parent, callback) => {
// Skip if not a directory.
if (!fs.statSync(parent).isDirectory()) {
return
}
fs.stat(parent, (err, stats) => {
if (err || !stats.isDirectory()) {
// This code is synchronous to be able to tell when it actually finishes.
try {
// Skip if not a directory.
if (!fs.statSync(parent).isDirectory()) {
return

@@ -34,13 +33,9 @@ }

// Iterate over list of children.
fs.readdir(parent, (err, children) => {
if (err) {
return
}
children.forEach((child) => {
child = path.resolve(parent, child)
watchFolderFallback(child, callback)
})
fs.readdirSync(parent).forEach((child) => {
child = path.resolve(parent, child)
watchFolderFallback(child, callback)
})
})
} catch (err) {
console.error(err)
}
}

@@ -51,9 +46,27 @@

let cache = {}
if (PLATFORMS.indexOf(process.platform) !== -1) {
watchFolder(workingDir, true, callback)
} else {
watchFolderFallback(workingDir, callback)
return watchFolder(workingDir, true, callback)
}
watchFolderFallback(workingDir, (localPath) => {
fs.stat(localPath, (err, stat) => {
// Delete cache entry.
if (err) {
delete cache[localPath]
return
}
// Add new handler for new directory and save in cache.
if (stat.isDirectory() && !cache[localPath]) {
cache[localPath] = true
watchFolder(localPath, false, callback)
}
})
callback(localPath)
})
}
module.exports = watch
{
"name": "simple-watcher",
"version": "0.1.0",
"version": "0.1.1",
"description": "\"A simple recursive directory watcher.\"",

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

@@ -40,3 +40,3 @@ # Simple Watcher

let now = Date.now()
if (filePath === last.fileName && now - last.timestamp < delta) {
if (filePath === last.filePath && now - last.timestamp < delta) {
return

@@ -43,0 +43,0 @@ }

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