Compare commits

...

2 Commits

Author SHA1 Message Date
aab3ce213b v1.2.0
Some checks failed
Default (tags) / security (push) Failing after 17s
Default (tags) / test (push) Failing after 12s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2025-11-29 21:05:51 +00:00
6d02ef3ddc feat(core): Migrate to chokidar 5.x, add picomatch filtering and update test/dev dependencies 2025-11-29 21:05:51 +00:00
7 changed files with 2833 additions and 2511 deletions

View File

@@ -1,5 +1,15 @@
# Changelog
## 2025-11-29 - 1.2.0 - feat(core)
Migrate to chokidar 5.x, add picomatch filtering and update test/dev dependencies
- Upgrade runtime dependencies: chokidar -> ^5.0.0 and picomatch -> ^4.0.3; bumped related @push.rocks packages versions.
- Upgrade devDependencies: @git.zone/tsbuild, @git.zone/tsrun and @git.zone/tstest to newer v2/v3 releases; updated @types/node.
- Updated README and readme.hints to document migration to chokidar 5.x and dev dependency changes.
- Tests updated to use @git.zone/tstest/tapbundle (import change) and test runner start changed to export default tap.start().
- Smartchok implementation updated to extract glob base paths, watch base directories and filter events via picomatch matchers (shouldWatchPath + event filtering).
- Note: ts/00_commitinfo_data.ts still references chokidar 4.x in the description and should be updated to reflect the migration.
## 2025-06-26 - 1.1.1 - fix(package.json)
Add packageManager field to package.json for pnpm configuration

View File

@@ -1,8 +1,8 @@
{
"name": "@push.rocks/smartchok",
"version": "1.1.1",
"version": "1.2.0",
"private": false,
"description": "A smart wrapper for chokidar 4.x with glob pattern support and enhanced features.",
"description": "A smart wrapper for chokidar 5.x with glob pattern support and enhanced features.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
@@ -22,19 +22,18 @@
},
"homepage": "https://code.foss.global/push.rocks/smartchok",
"dependencies": {
"@push.rocks/lik": "^6.0.2",
"@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrx": "^3.0.2",
"chokidar": "^4.0.3",
"picomatch": "^4.0.2"
"@push.rocks/lik": "^6.2.2",
"@push.rocks/smartpromise": "^4.2.3",
"@push.rocks/smartrx": "^3.0.10",
"chokidar": "^5.0.0",
"picomatch": "^4.0.3"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@git.zone/tsbuild": "^3.1.2",
"@git.zone/tsrun": "^2.0.0",
"@git.zone/tstest": "^3.1.3",
"@push.rocks/smartfile": "^11.0.4",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.11.8"
"@types/node": "^24.10.1"
},
"files": [
"ts/**/*",

5059
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,15 @@
# smartchok - Technical Hints
## Chokidar 4.x Migration (2024)
## Chokidar 5.x Migration (2024)
The module has been migrated from `@tempfix/watcher` to `chokidar` 4.x. Key changes:
The module has been migrated to `chokidar` 5.x (from 4.x). Key changes:
### Dependencies
- **Removed**: `@tempfix/watcher` (a fork of fabiospampinato/watcher)
- **Added**: `chokidar` 4.x and `picomatch`
- **Current**: `chokidar` 5.x and `picomatch`
- **Historical**: Was previously using `@tempfix/watcher` before chokidar 4.x
### Why picomatch?
Chokidar 4.x removed built-in glob pattern support. We use `picomatch` to maintain backward compatibility and provide glob pattern matching functionality.
Chokidar 4.x+ removed built-in glob pattern support. We use `picomatch` to maintain backward compatibility and provide glob pattern matching functionality.
### Implementation Details
1. **Glob pattern extraction**: The `getGlobBase()` method extracts base directories from glob patterns
@@ -18,12 +18,16 @@ Chokidar 4.x removed built-in glob pattern support. We use `picomatch` to mainta
4. **Path normalization**: Paths are normalized to handle different formats (with/without leading ./)
### Event Handling
Chokidar 4.x events are mapped 1:1 with smartchok events:
Chokidar 5.x events are mapped 1:1 with smartchok events:
- `add`, `change`, `unlink`: File events
- `addDir`, `unlinkDir`: Directory events
- `addDir`, `unlinkDir`: Directory events
- `error`: Error events
- `raw`: Raw events from underlying watchers
- `ready`: Emitted when initial scan is complete
### Testing
All existing tests pass without modification, confirming backward compatibility is maintained.
All existing tests pass without modification, confirming backward compatibility is maintained.
## Dev Dependencies (2024)
- Using `@git.zone/tstest` v3.x with tapbundle (`import { tap, expect } from '@git.zone/tstest/tapbundle'`)
- Removed deprecated `@push.rocks/tapbundle`

224
readme.md
View File

@@ -1,121 +1,195 @@
# @push.rocks/smartchok
smart wrapper for chokidar
A smart wrapper for chokidar 5.x with glob pattern support, RxJS observable integration, and enhanced file watching features.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Install
Install the package by running the following command in your terminal:
```sh
npm install @push.rocks/smartchok --save
npm install @push.rocks/smartchok
# or
pnpm add @push.rocks/smartchok
```
This command adds `@push.rocks/smartchok` to your project's dependencies, ensuring that your project can use its functionality and that it will be installed when running `npm install` in your project root.
## Features
🔍 **Glob Pattern Support** - Watch files using glob patterns like `**/*.ts` or `src/**/*.js`
📡 **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
🎯 **TypeScript First** - Full TypeScript support with comprehensive type definitions
## Usage
The `@push.rocks/smartchok` package provides a convenient and smart wrapper around the popular `chokidar` library (v4.x) for file watching with enhanced features such as observable support for filesystem events and glob pattern matching support. This guide will introduce you to the usage of `@push.rocks/smartchok`, leveraging TypeScript for type safety and better developer experience.
### Setting Up Your Project
To use `@push.rocks/smartchok`, ensure your project is set up to use TypeScript and ECMAScript modules (ESM). You need to have a `tsconfig.json` file at the root of your project with the following minimum settings:
```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"declaration": true,
"outDir": "./dist",
"strict": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
```
This configuration enables TypeScript compilation targeting the latest ECMAScript standards and includes all TypeScript files (`*.ts`) in your `src` directory.
### Basic Setup
To start using `smartchok`, first import it into your TypeScript file:
```typescript
import { Smartchok } from '@push.rocks/smartchok';
```
#### Initializing Smartchok
Create an instance of `Smartchok` by specifying an array of glob patterns to watch:
```typescript
const smartchokInstance = new Smartchok([
'./src/**/*.ts', // Watch all TypeScript files in the src directory
'./public/assets/**/*' // Watch all files in the public/assets directory
// Create a watcher with glob patterns
const watcher = new Smartchok([
'./src/**/*.ts', // Watch all TypeScript files in src
'./public/assets/**/*' // Watch all files in public/assets
]);
// Start watching
await watcher.start();
```
#### Adding and Removing Files Dynamically
### Subscribing to File Events
You can dynamically add and remove paths from being watched by using the `add` and `remove` methods:
Use RxJS observables to react to file system changes:
```typescript
// Add additional files or patterns
smartchokInstance.add(['./tests/**/*.spec.ts']);
// Remove specific patterns from watch
smartchokInstance.remove('./src/**/*.test.ts');
```
#### Handling Filesystem Events
`smartchok` leverages RxJS observables to notify about filesystem events. This allows you to respond to various events such as file additions, changes, and deletions with ease.
First, start the watcher:
```typescript
await smartchokInstance.start();
```
Then, subscribe to an event:
```typescript
const changeObservable = await smartchokInstance.getObservableFor('change');
// Get an observable for file changes
const changeObservable = await watcher.getObservableFor('change');
changeObservable.subscribe({
next: ([path, stats]) => {
console.log(`File changed: ${path}`);
},
error: (err) => {
console.error(`An error occurred: ${err}`);
console.error(`Error: ${err}`);
}
});
// Watch for new files
const addObservable = await watcher.getObservableFor('add');
addObservable.subscribe(([path]) => {
console.log(`File added: ${path}`);
});
// Watch for deleted files
const unlinkObservable = await watcher.getObservableFor('unlink');
unlinkObservable.subscribe(([path]) => {
console.log(`File deleted: ${path}`);
});
```
Supported events include 'add', 'change', 'unlink' (for deletions), 'addDir', 'unlinkDir', 'error', 'ready', and 'raw'. Since chokidar 4.x no longer supports glob patterns natively, smartchok handles glob pattern matching internally using picomatch.
### Supported Events
#### Stopping the Watcher
| Event | Description |
|-------|-------------|
| `add` | File has been added |
| `addDir` | Directory has been added |
| `change` | File has been changed |
| `unlink` | File has been removed |
| `unlinkDir` | Directory has been removed |
| `error` | Error occurred |
| `ready` | Initial scan complete |
| `raw` | Raw event from the underlying watcher |
To stop watching for file changes, simply call:
### Dynamic Watch Management
Add or remove patterns while the watcher is running:
```typescript
await smartchokInstance.stop();
const watcher = new Smartchok(['./src/**/*.ts']);
await watcher.start();
// Add more patterns to watch
watcher.add(['./tests/**/*.spec.ts', './config/*.json']);
// Remove a pattern
watcher.remove('./src/**/*.test.ts');
```
### Advanced Usage
### Stopping the Watcher
Beyond the basics, `smartchok` allows for more complex monitoring scenarios, such as debounced notifications for rapid changes, filtering events, and integrating with other observables for complex asynchronous workflows.
```typescript
// Stop watching when done
await watcher.stop();
```
### Conclusion
### Complete Example
`@push.rocks/smartchok` provides a robust, observable-based wrapper around `chokidar` 4.x, making it an excellent choice for projects requiring efficient and flexible file monitoring. Its integration with RxJS opens up a wide array of possibilities for handling file system events in a reactive manner, making your code more concise, readable, and maintainable. The package maintains backward compatibility by implementing glob pattern support that was removed in chokidar 4.x.
```typescript
import { Smartchok } from '@push.rocks/smartchok';
By following the guidelines provided in this document, you should now be equipped to integrate `@push.rocks/smartchok` into your TypeScript project, enhancing its capabilities with efficient file system monitoring.
async function watchProject() {
// Initialize with patterns
const watcher = new Smartchok([
'./src/**/*.ts',
'./package.json'
]);
// Start the watcher
await watcher.start();
console.log('👀 Watching for changes...');
// Subscribe to changes
const changes = await watcher.getObservableFor('change');
changes.subscribe(([path, stats]) => {
console.log(`📝 Modified: ${path}`);
console.log(` Size: ${stats?.size ?? 'unknown'} bytes`);
});
// Subscribe to new files
const additions = await watcher.getObservableFor('add');
additions.subscribe(([path]) => {
console.log(`✨ New file: ${path}`);
});
// Subscribe to deletions
const deletions = await watcher.getObservableFor('unlink');
deletions.subscribe(([path]) => {
console.log(`🗑️ Deleted: ${path}`);
});
// Handle graceful shutdown
process.on('SIGINT', async () => {
console.log('\n🛑 Stopping watcher...');
await watcher.stop();
process.exit(0);
});
}
watchProject();
```
## How It Works
Since chokidar 4.x+ no longer supports glob patterns natively, smartchok 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.
When you provide glob patterns:
1. **Base path extraction** - smartchok extracts the static base path from each pattern
2. **Efficient watching** - chokidar watches the base directories
3. **Pattern filtering** - Events are filtered through picomatch matchers before being emitted
## API Reference
### `Smartchok`
#### Constructor
```typescript
new Smartchok(patterns: string[])
```
Creates a new Smartchok instance with the given glob patterns.
#### Methods
| Method | Returns | Description |
|--------|---------|-------------|
| `start()` | `Promise<void>` | Starts watching for file changes |
| `stop()` | `Promise<void>` | Stops the file watcher |
| `add(patterns: string[])` | `void` | Adds patterns to watch |
| `remove(pattern: string)` | `void` | Removes a pattern from watching |
| `getObservableFor(event: TFsEvent)` | `Promise<Observable<[string, Stats]>>` | Returns an RxJS observable for the specified event |
#### Properties
| Property | Type | Description |
|----------|------|-------------|
| `status` | `'idle' \| 'starting' \| 'watching'` | Current watcher status |
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
@@ -125,7 +199,7 @@ This project is owned and maintained by Task Venture Capital GmbH. The names and
### Company Information
Task Venture Capital GmbH
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

View File

@@ -1,4 +1,4 @@
import { tap, expect } from '@push.rocks/tapbundle';
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartchok from '../ts/index.js';
import * as smartfile from '@push.rocks/smartfile';
import * as smartpromise from '@push.rocks/smartpromise';
@@ -47,4 +47,4 @@ tap.test('should stop the watch process', async (tools) => {
testSmartchok.stop();
});
tap.start();
export default tap.start();

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartchok',
version: '1.1.1',
description: 'A smart wrapper for chokidar 4.x with glob pattern support and enhanced features.'
version: '1.2.0',
description: 'A smart wrapper for chokidar 5.x with glob pattern support and enhanced features.'
}