Compare commits

...

2 Commits

Author SHA1 Message Date
2ae297e5fa v4.0.0
Some checks failed
Default (tags) / security (push) Failing after 16s
Default (tags) / test (push) Failing after 12s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2025-11-30 17:32:45 +00:00
9130613941 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 2025-11-30 17:32:44 +00:00
5 changed files with 50 additions and 15 deletions

View File

@@ -1,5 +1,15 @@
# Changelog
## 2025-11-30 - 4.0.0 - 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
- Replaced chokidar-based implementation with native file watching APIs (Node.js fs.watch, Deno.watchFs).
- Added platform-specific watchers: NodeWatcher and DenoWatcher (Bun uses Node compatibility).
- Implemented polling-based write stabilization (awaitWriteFinish replacement) to avoid duplicate events during writes.
- Keep glob pattern support by matching events internally using picomatch; base-path extraction used to limit watch scope.
- API/runtime requirement increased: Node.js >= 20.0.0 is required for native recursive fs.watch.
- Package/documentation name and examples updated to @push.rocks/smartchok and export the Smartwatch class.
## 2025-11-30 - 3.0.0 - BREAKING CHANGE(smartwatch)
Introduce Smartwatch: cross-runtime native file watching for Node.js, Deno and Bun; rename smartchok to smartwatch and bump major version to 2.0.0

View File

@@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartchok",
"version": "3.0.0",
"version": "4.0.0",
"private": false,
"description": "A cross-runtime file watcher with glob pattern support for Node.js, Deno, and Bun.",
"main": "dist_ts/index.js",

View File

@@ -4,6 +4,13 @@
The module now uses native file watching APIs instead of chokidar, providing cross-runtime support for Node.js, Deno, and Bun.
### Exported Class
The package exports the `Smartwatch` class (not `Smartchok`):
```typescript
import { Smartwatch } from '@push.rocks/smartchok';
```
### Architecture
```

View File

@@ -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`

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartchok',
version: '3.0.0',
version: '4.0.0',
description: 'A cross-runtime file watcher with glob pattern support for Node.js, Deno, and Bun.'
}