Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miniflare/watcher

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/watcher - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

2

dist/src/index.d.ts
export declare class Watcher {
#private;
constructor(callback: WatcherCallback, options?: WatcherOptions);
watch(paths: string | Iterable<string>): Promise<void>;
watch(paths: string | Iterable<string>): void;
unwatch(paths: string | Iterable<string>): void;

@@ -6,0 +6,0 @@ dispose(): void;

@@ -33,3 +33,2 @@ var __create = Object.create;

var import_util = __toModule(require("util"));
var fsp = import_fs.default.promises;
var log = (0, import_util.debuglog)("mf-watch");

@@ -40,11 +39,10 @@ function withinDir(dir, file) {

}
async function walkDirs(root, callback) {
function walkDirs(root, callback) {
callback(root);
const names = await fsp.readdir(root);
await Promise.all(names.map(async (name) => {
for (const name of import_fs.default.readdirSync(root)) {
const filePath = import_path.default.join(root, name);
if (!(await fsp.stat(filePath)).isDirectory())
if (!import_fs.default.statSync(filePath).isDirectory())
return;
return walkDirs(filePath, callback);
}));
walkDirs(filePath, callback);
}
}

@@ -93,3 +91,3 @@ var PathWatcher = class {

}
listener = async (event, fileName) => {
listener = (event, fileName) => {
log(`${this.filePath}: ${event}: ${fileName}`);

@@ -99,3 +97,3 @@ if (fileName) {

const resolved = import_path.default.resolve(this.filePath, fileName);
const mtime = (await fsp.stat(resolved)).mtimeMs;
const mtime = import_fs.default.statSync(resolved).mtimeMs;
const previousMtime = this.lastMtimes?.get(resolved);

@@ -133,3 +131,3 @@ if (previousMtime === mtime) {

}
async startRecursiveWatcher() {
startRecursiveWatcher() {
(0, import_assert.default)(!this.watching);

@@ -139,6 +137,6 @@ log(`${this.filePath}: recursively watching...`);

this.lastMtimes = new Map();
const update = async (dir, event, fileName) => {
const update = (dir, event, fileName) => {
let dirIsDirectory = false;
try {
dirIsDirectory = (await fsp.stat(dir)).isDirectory();
dirIsDirectory = import_fs.default.statSync(dir).isDirectory();
} catch {

@@ -150,10 +148,10 @@ }

this.dispose();
await this.start();
this.start();
return;
}
const filePath = import_path.default.join(dir, fileName);
await this.listener(event, filePath);
this.listener(event, filePath);
try {
if ((await fsp.stat(filePath)).isDirectory()) {
await walkDirs(filePath, walkCallback);
if (import_fs.default.statSync(filePath).isDirectory()) {
walkDirs(filePath, walkCallback);
}

@@ -178,3 +176,3 @@ } catch (e) {

try {
await walkDirs(this.filePath, walkCallback);
walkDirs(this.filePath, walkCallback);
this.startDeletedWatcher();

@@ -188,8 +186,7 @@ } catch (e) {

}
async start() {
start() {
try {
const stat = await fsp.stat(this.filePath);
if (stat.isDirectory()) {
if (import_fs.default.statSync(this.filePath).isDirectory()) {
if (this.options.forceRecursive) {
return await this.startRecursiveWatcher();
return this.startRecursiveWatcher();
} else {

@@ -207,3 +204,3 @@ return this.startPlatformRecursiveWatcher();

if (e.code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM") {
return await this.startRecursiveWatcher();
return this.startRecursiveWatcher();
}

@@ -243,3 +240,3 @@ throw e;

}
async watch(paths) {
watch(paths) {
if (typeof paths === "string")

@@ -261,3 +258,3 @@ paths = [paths];

this.#watchers.set(resolved, watcher);
await watcher.start();
watcher.start();
}

@@ -264,0 +261,0 @@ }

{
"name": "@miniflare/watcher",
"version": "2.0.0",
"version": "2.1.0",
"description": "File-system watcher module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

@@ -38,7 +38,7 @@ "keywords": [

"dependencies": {
"@miniflare/shared": "2.0.0"
"@miniflare/shared": "2.1.0"
},
"devDependencies": {
"@miniflare/shared-test": "2.0.0"
"@miniflare/shared-test": "2.1.0"
}
}

@@ -17,6 +17,6 @@ # `@miniflare/watcher`

// Add recursive directory watcher
await watcher.watch("./dir");
watcher.watch("./dir");
// Add file watchers
await watcher.watch(/* any iterable */ ["./file1.txt", "./file2.txt"]);
watcher.watch(/* any iterable */ ["./file1.txt", "./file2.txt"]);

@@ -23,0 +23,0 @@ // Remove watchers

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