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 0.0.1-alpha to 0.1.0

readme.md

57

index.js

@@ -1,1 +0,56 @@

console.log('Work in progress.')
'use strict'
const fs = require('fs')
const path = require('path')
const PLATFORMS = ['win32', 'darwin']
// OS watcher.
let watchFolder = (workingDir, recursive, callback) => {
let options = { persistent: true, recursive: recursive }
fs.watch(workingDir, options, (event, fileName) => {
callback(path.join(workingDir, fileName))
})
}
// 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()) {
return
}
watchFolder(parent, false, callback)
// Iterate over list of children.
fs.readdir(parent, (err, children) => {
if (err) {
return
}
children.forEach((child) => {
child = path.resolve(parent, child)
watchFolderFallback(child, callback)
})
})
})
}
let watch = (workingDir, callback) => {
workingDir = path.resolve(workingDir)
if (PLATFORMS.indexOf(process.platform) !== -1) {
watchFolder(workingDir, true, callback)
} else {
watchFolderFallback(workingDir, callback)
}
}
module.exports = watch

6

package.json
{
"name": "simple-watcher",
"version": "0.0.1-alpha",
"description": "\"A simple file system watcher.\"",
"version": "0.1.0",
"description": "\"A simple recursive directory watcher.\"",
"main": "index.js",

@@ -13,2 +13,4 @@ "repository": {

"system",
"directory",
"recursive",
"watch",

@@ -15,0 +17,0 @@ "watcher"

Sorry, the diff of this file is not supported yet

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