BREAKING CHANGE(watchers): Replace chokidar with native platform watchers and add cross-runtime support (Node.js, Deno, Bun); introduce write stabilization and internal glob matching
This commit is contained in:
44
readme.md
44
readme.md
@@ -1,6 +1,6 @@
|
||||
# @push.rocks/smartwatch
|
||||
# @push.rocks/smartchok
|
||||
|
||||
A smart wrapper for chokidar 5.x with glob pattern support, RxJS observable integration, and enhanced file watching features.
|
||||
A cross-runtime file watcher with glob pattern support for **Node.js**, **Deno**, and **Bun**. Built with native file watching APIs for maximum performance and zero heavyweight dependencies.
|
||||
|
||||
## Issue Reporting and Security
|
||||
|
||||
@@ -9,25 +9,27 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartwatch
|
||||
npm install @push.rocks/smartchok
|
||||
# or
|
||||
pnpm add @push.rocks/smartwatch
|
||||
pnpm add @push.rocks/smartchok
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
🔍 **Glob Pattern Support** - Watch files using glob patterns like `**/*.ts` or `src/**/*.js`
|
||||
🌐 **Cross-Runtime** - Works on Node.js 20+, Deno, and Bun
|
||||
🔍 **Glob Pattern Support** - Watch files using familiar patterns like `**/*.ts`
|
||||
📡 **RxJS Observables** - Subscribe to file system events using reactive streams
|
||||
🔄 **Dynamic Watching** - Add or remove watch patterns at runtime
|
||||
⚡ **Chokidar 5.x** - Built on the latest chokidar with improved performance
|
||||
⚡ **Native Performance** - Uses `fs.watch()` and `Deno.watchFs()` directly
|
||||
🎯 **TypeScript First** - Full TypeScript support with comprehensive type definitions
|
||||
📦 **Minimal Dependencies** - No heavyweight watcher libraries required
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```typescript
|
||||
import { Smartwatch } from '@push.rocks/smartwatch';
|
||||
import { Smartwatch } from '@push.rocks/smartchok';
|
||||
|
||||
// Create a watcher with glob patterns
|
||||
const watcher = new Smartwatch([
|
||||
@@ -80,7 +82,6 @@ unlinkObservable.subscribe(([path]) => {
|
||||
| `unlinkDir` | Directory has been removed |
|
||||
| `error` | Error occurred |
|
||||
| `ready` | Initial scan complete |
|
||||
| `raw` | Raw event from the underlying watcher |
|
||||
|
||||
### Dynamic Watch Management
|
||||
|
||||
@@ -107,7 +108,7 @@ await watcher.stop();
|
||||
### Complete Example
|
||||
|
||||
```typescript
|
||||
import { Smartwatch } from '@push.rocks/smartwatch';
|
||||
import { Smartwatch } from '@push.rocks/smartchok';
|
||||
|
||||
async function watchProject() {
|
||||
// Initialize with patterns
|
||||
@@ -152,13 +153,30 @@ watchProject();
|
||||
|
||||
## How It Works
|
||||
|
||||
Since chokidar 4.x+ no longer supports glob patterns natively, smartwatch handles glob pattern matching internally using [picomatch](https://github.com/micromatch/picomatch). This means you get the familiar glob syntax while benefiting from chokidar's efficient file watching capabilities.
|
||||
smartchok uses native file watching APIs for each runtime:
|
||||
|
||||
When you provide glob patterns:
|
||||
1. **Base path extraction** - smartwatch extracts the static base path from each pattern
|
||||
2. **Efficient watching** - chokidar watches the base directories
|
||||
| Runtime | API Used |
|
||||
|---------|----------|
|
||||
| **Node.js 20+** | `fs.watch({ recursive: true })` |
|
||||
| **Deno** | `Deno.watchFs()` |
|
||||
| **Bun** | Node.js compatibility layer |
|
||||
|
||||
Since native APIs don't support glob patterns, smartchok handles pattern matching internally using [picomatch](https://github.com/micromatch/picomatch):
|
||||
|
||||
1. **Base path extraction** - Extracts the static base path from each glob pattern
|
||||
2. **Efficient watching** - Native watchers monitor the base directories
|
||||
3. **Pattern filtering** - Events are filtered through picomatch matchers before being emitted
|
||||
|
||||
### Write Stabilization
|
||||
|
||||
smartchok includes built-in write stabilization (similar to chokidar's `awaitWriteFinish`). When a file is being written, events are held until the file size stabilizes, preventing multiple events for a single write operation.
|
||||
|
||||
## Requirements
|
||||
|
||||
- **Node.js 20+** - Required for native recursive watching
|
||||
- **Deno** - Any version with `Deno.watchFs()` support
|
||||
- **Bun** - Uses Node.js compatibility
|
||||
|
||||
## API Reference
|
||||
|
||||
### `Smartwatch`
|
||||
|
||||
Reference in New Issue
Block a user