Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement →
Sign In

@nasriya/overwatch

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nasriya/overwatch - npm Package Compare versions

Comparing version
1.0.4
to
1.0.5
+6
-0
dist/@types/docs/docs.d.ts
export interface WatchOptions {
include?: (RegExp | string)[];
exclude?: (RegExp | string)[];
onChange?: onWatchedDataChangeHandler;
onUpdate?: OnWatchedDataUpdateHandler;
onRemove?: onWatchedDataRemoveHandler;
onRename?: onWatchedDataRenameHandler;
onAdd?: onWatchedDataAddHandler;
onRootRemoved?: () => any | Promise<any>;
}

@@ -5,0 +11,0 @@ export type OnWatchedDataUpdateHandler = (event: UpdateEvent) => any | Promise<any>;

+14
-17

@@ -7,10 +7,8 @@ import Watcher from "./watcher/Watcher";

/**
* Watches a specific file or folder for changes. This method is internally used by
* `watchFile` and `watchFolder` and handles all registration logic with the VOM.
* Registers a watcher for the specified path, which can be a file or directory.
*
* @param path_ - The absolute or relative path to the file or folder to watch.
* @param path_ - The absolute or relative path to the file or directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Optional filtering options to include or exclude specific files or folders.
* These only take effect if the path points to a directory.
* All filter rules (both strings and RegExp) are matched against the **absolute normalized paths** of files and subfolders.
* @param options - Optional configuration options for the watcher.
* If watching a directory, you can specify filters to include or exclude specific paths.
* @returns A `Watcher` instance for the specified path.

@@ -25,17 +23,16 @@ * @throws Will throw an error if the path does not exist or cannot be resolved.

* The path will be resolved and normalized before being tracked.
* @returns A `Watcher` instance for the file.
* @throws Will throw an error if the path is invalid or not a file.
* @param options - Optional configuration options excluding `exclude` and `include` filters.
* These filters are irrelevant since a file is not a directory.
* @returns A `Watcher` instance for the specified file.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/
watchFile(path_: string): Promise<Watcher>;
watchFile(path_: string, options?: Exclude<WatchOptions, 'exclude' | 'include'>): Promise<Watcher>;
/**
* Registers a watcher for the specified folder path, with optional filtering rules
* to control which files or folders inside it should trigger change events.
* Registers a watcher for the specified directory path.
*
* @param path_ - The absolute or relative path to the folder to watch.
* @param path_ - The absolute or relative path to the directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Filtering options to include or exclude specific paths.
* Filter rules may be exact strings or regular expressions,
* and are matched against the **absolute normalized path** of each affected file or folder.
* @returns A `Watcher` instance for the folder.
* @throws Will throw an error if the path is invalid or not a directory.
* @param options - Optional configuration options including filters to restrict which files and folders are watched.
* @returns A `Watcher` instance for the specified directory.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/

@@ -42,0 +39,0 @@ watchFolder(path_: string, options?: WatchOptions): Promise<Watcher>;

@@ -153,10 +153,8 @@ "use strict";

/**
* Watches a specific file or folder for changes. This method is internally used by
* `watchFile` and `watchFolder` and handles all registration logic with the VOM.
* Registers a watcher for the specified path, which can be a file or directory.
*
* @param path_ - The absolute or relative path to the file or folder to watch.
* @param path_ - The absolute or relative path to the file or directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Optional filtering options to include or exclude specific files or folders.
* These only take effect if the path points to a directory.
* All filter rules (both strings and RegExp) are matched against the **absolute normalized paths** of files and subfolders.
* @param options - Optional configuration options for the watcher.
* If watching a directory, you can specify filters to include or exclude specific paths.
* @returns A `Watcher` instance for the specified path.

@@ -193,6 +191,8 @@ * @throws Will throw an error if the path does not exist or cannot be resolved.

* The path will be resolved and normalized before being tracked.
* @returns A `Watcher` instance for the file.
* @throws Will throw an error if the path is invalid or not a file.
* @param options - Optional configuration options excluding `exclude` and `include` filters.
* These filters are irrelevant since a file is not a directory.
* @returns A `Watcher` instance for the specified file.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/
async watchFile(path_) {
async watchFile(path_, options) {
try {

@@ -210,12 +210,9 @@ const watcher = await this.watch(path_);

/**
* Registers a watcher for the specified folder path, with optional filtering rules
* to control which files or folders inside it should trigger change events.
* Registers a watcher for the specified directory path.
*
* @param path_ - The absolute or relative path to the folder to watch.
* @param path_ - The absolute or relative path to the directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Filtering options to include or exclude specific paths.
* Filter rules may be exact strings or regular expressions,
* and are matched against the **absolute normalized path** of each affected file or folder.
* @returns A `Watcher` instance for the folder.
* @throws Will throw an error if the path is invalid or not a directory.
* @param options - Optional configuration options including filters to restrict which files and folders are watched.
* @returns A `Watcher` instance for the specified directory.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/

@@ -222,0 +219,0 @@ async watchFolder(path_, options) {

@@ -46,2 +46,20 @@ "use strict";

this.#_filters.exclude = this.#_filters.exclude.map(rule => this.#_helpers.normalizeFilterRule(rule));
if (utils_1.default.hasOwnProperty(watchOptions, 'onChange')) {
this.onChange(watchOptions?.onChange);
}
if (utils_1.default.hasOwnProperty(watchOptions, 'onUpdate')) {
this.onUpdate(watchOptions?.onUpdate);
}
if (utils_1.default.hasOwnProperty(watchOptions, 'onRemove')) {
this.onRemove(watchOptions?.onRemove);
}
if (utils_1.default.hasOwnProperty(watchOptions, 'onRename')) {
this.onRename(watchOptions?.onRename);
}
if (utils_1.default.hasOwnProperty(watchOptions, 'onAdd')) {
this.onAdd(watchOptions?.onAdd);
}
if (utils_1.default.hasOwnProperty(watchOptions, 'onRootRemoved')) {
this.onRootRemoved(watchOptions?.onRootRemoved);
}
}

@@ -48,0 +66,0 @@ /**

@@ -148,10 +148,8 @@ import VirtualObjectManager from "./vom/vom.js";

/**
* Watches a specific file or folder for changes. This method is internally used by
* `watchFile` and `watchFolder` and handles all registration logic with the VOM.
* Registers a watcher for the specified path, which can be a file or directory.
*
* @param path_ - The absolute or relative path to the file or folder to watch.
* @param path_ - The absolute or relative path to the file or directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Optional filtering options to include or exclude specific files or folders.
* These only take effect if the path points to a directory.
* All filter rules (both strings and RegExp) are matched against the **absolute normalized paths** of files and subfolders.
* @param options - Optional configuration options for the watcher.
* If watching a directory, you can specify filters to include or exclude specific paths.
* @returns A `Watcher` instance for the specified path.

@@ -188,6 +186,8 @@ * @throws Will throw an error if the path does not exist or cannot be resolved.

* The path will be resolved and normalized before being tracked.
* @returns A `Watcher` instance for the file.
* @throws Will throw an error if the path is invalid or not a file.
* @param options - Optional configuration options excluding `exclude` and `include` filters.
* These filters are irrelevant since a file is not a directory.
* @returns A `Watcher` instance for the specified file.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/
async watchFile(path_) {
async watchFile(path_, options) {
try {

@@ -205,12 +205,9 @@ const watcher = await this.watch(path_);

/**
* Registers a watcher for the specified folder path, with optional filtering rules
* to control which files or folders inside it should trigger change events.
* Registers a watcher for the specified directory path.
*
* @param path_ - The absolute or relative path to the folder to watch.
* @param path_ - The absolute or relative path to the directory to watch.
* The path will be resolved and normalized before being tracked.
* @param options - Filtering options to include or exclude specific paths.
* Filter rules may be exact strings or regular expressions,
* and are matched against the **absolute normalized path** of each affected file or folder.
* @returns A `Watcher` instance for the folder.
* @throws Will throw an error if the path is invalid or not a directory.
* @param options - Optional configuration options including filters to restrict which files and folders are watched.
* @returns A `Watcher` instance for the specified directory.
* @throws Will throw an error if the path does not exist or cannot be resolved.
*/

@@ -217,0 +214,0 @@ async watchFolder(path_, options) {

@@ -41,2 +41,20 @@ import utils from "../utils/utils.js";

this.#_filters.exclude = this.#_filters.exclude.map(rule => this.#_helpers.normalizeFilterRule(rule));
if (utils.hasOwnProperty(watchOptions, 'onChange')) {
this.onChange(watchOptions?.onChange);
}
if (utils.hasOwnProperty(watchOptions, 'onUpdate')) {
this.onUpdate(watchOptions?.onUpdate);
}
if (utils.hasOwnProperty(watchOptions, 'onRemove')) {
this.onRemove(watchOptions?.onRemove);
}
if (utils.hasOwnProperty(watchOptions, 'onRename')) {
this.onRename(watchOptions?.onRename);
}
if (utils.hasOwnProperty(watchOptions, 'onAdd')) {
this.onAdd(watchOptions?.onAdd);
}
if (utils.hasOwnProperty(watchOptions, 'onRootRemoved')) {
this.onRootRemoved(watchOptions?.onRootRemoved);
}
}

@@ -43,0 +61,0 @@ /**

{
"name": "@nasriya/overwatch",
"version": "1.0.4",
"version": "1.0.5",
"description": "A high-performance, dependency-free file system watcher that monitors file and directory changes efficiently across platforms.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -115,2 +115,13 @@ [![N|Solid](https://static.wixstatic.com/media/72ffe6_da8d2142d49c42b29c96ba80c8a91a6c~mv2.png)](https://nasriya.net)

You can also pass the handlers when you create the watcher:
```ts
const projectWatcher = await overwatch.watchFolder(process.cwd(), {
include: ['**/*.ts'], // Accepts globs, regex, or absolute paths
exclude: [/node_modules/, '**/*.test.ts'],
onRename: (event) => {
console.log(`${event.type} renamed: ${event.oldPath} -> ${event.newPath}`);
}
});
```
### 3. Handling Root Deletion

@@ -117,0 +128,0 @@ If the root directory being watched is deleted, a special event is triggered: