xiaohongshu
xiaohongshu
Ryan Dahlのイベント駆動・非同期I/O思想に基づくファイルシステム監視の専門知識。 Chokidarライブラリを中心に、Observer Patternによる効率的なファイル変更検知、 クロスプラットフォーム対応、EventEmitterによる疎結合な通知システムを提供。 使用タイミング: - Chokidarによるファイル監視システムを設計・実装する時 - Observer Patternでイベント通知を設計する時 - ファイルシステムイベントのハンドリングを実装する時 - クロスプラットフォーム対応の監視設定を決定する時 - 監視方式(native fsevents vs p...
Full skill instructions
このスキルは、Node.js におけるイベント駆動型ファイル監視の設計と実装に関する専門知識を提供します。Ryan Dahl が提唱する非同期 I/O モデルに基づき、効率的で信頼性の高い監視システムを構築するための原則とパターンを定義します。
Ryan Dahl の設計原則:
| 技術 | 特性 | 推奨度 |
|---|---|---|
| Chokidar | クロスプラットフォーム、安定性、豊富な設定 | ✅ 推奨 |
| fs.watch | ネイティブ API、プラットフォーム依存、不安定 | ⚠️ 限定的 |
| fs.watchFile | polling 方式、高 CPU、遅延 | ❌ 非推奨 |
// 基本構造
class FileWatcher extends EventEmitter {
private watcher: FSWatcher | null = null;
constructor(private config: WatcherConfig) {
super();
this.setMaxListeners(10); // メモリリーク防止
}
// カスタムイベントタイプ
// - fileAdded: 新規ファイル追加
// - fileChanged: ファイル変更
// - fileRemoved: ファイル削除
// - error: エラー発生
// - ready: 初期スキャン完了
}
interface ChokidarOptions {
// 除外パターン
ignored: string | RegExp | ((path: string) => boolean) | Array<...>;
// 監視継続(デフォルト: false)
persistent: boolean;
// 初期スキャンでイベント発火(デフォルト: false)
ignoreInitial: boolean;
// 書き込み完了待機
awaitWriteFinish: false | {
stabilityThreshold: number; // 安定性閾値(ms)
pollInterval: number; // チェック間隔(ms)
};
// 監視方式
usePolling: boolean; // polling使用(NFS/Docker向け)
interval: number; // pollingインターバル
// パーミッション
ignorePermissionErrors: boolean;
// シンボリックリンク
followSymlinks: boolean;
// ディレクトリ深度
depth: number | undefined; // undefined = 無制限
}
// 開発環境(ローカルファイルシステム)
const devConfig: ChokidarOptions = {
persistent: true,
ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 100,
pollInterval: 50,
},
usePolling: false, // ネイティブfsevents使用
ignored: ["**/node_modules/**", "**/.git/**", "**/dist/**"],
};
// 本番環境(NFS/Docker volumes)
const prodConfig: ChokidarOptions = {
persistent: true,
ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 500,
pollInterval: 100,
},
usePolling: true, // ネットワークFS向け
interval: 1000,
ignored: ["**/node_modules/**", "**/.git/**"],
};
| イベント | 発火条件 | 典型的なハンドリング |
|---|---|---|
add | ファイル追加 | 同期キュー追加 |
change | ファイル変更 | 差分同期 |
unlink | ファイル削除 | リモート削除通知 |
addDir | ディレクトリ追加 | ディレクトリ構造同期 |
unlinkDir | ディレクトリ削除 | リモート削除 |
ready | 初期スキャン完了 | 監視準備完了通知 |
error | エラー発生 | エラーログ・リカバリー |
raw | 低レベルイベント | デバッグ用 |
// 型安全なイベントハンドラー
type FileEventHandler = (path: string, stats?: fs.Stats) => void;
type ErrorHandler = (error: Error) => void;
type ReadyHandler = () => void;
// イベント登録の模範例
watcher
.on("add", (path, stats) => this.emit("fileAdded", { path, stats }))
.on("change", (path, stats) => this.emit("fileChanged", { path, stats }))
.on("unlink", (path) => this.emit("fileRemoved", { path }))
.on("error", (error) => this.emit("error", error))
.on("ready", () => this.emit("ready"));
// ファイルイベント構造
interface FileEvent {
type: "add" | "change" | "unlink";
path: string;
stats?: fs.Stats;
timestamp: string; // ISO8601
}
// 監視設定
interface WatcherConfig {
watchPath: string;
ignored: string[];
awaitWriteFinish: {
stabilityThreshold: number;
pollInterval: number;
};
usePolling: boolean;
persistent: boolean;
}
// エラー情報
interface WatcherError {
code: string; // EACCES, ENOENT等
message: string;
path?: string;
recoverable: boolean;
}
.claude/skills/debounce-throttle-patterns/SKILL.md - イベント最適化.claude/skills/file-exclusion-patterns/SKILL.md - 除外パターン設計.claude/skills/graceful-shutdown-patterns/SKILL.md - シャットダウン処理.claude/skills/nodejs-stream-processing/SKILL.md - ストリーム処理詳細な実装例やテンプレートが必要な場合:
# Chokidar設定リファレンス
cat .claude/skills/event-driven-file-watching/resources/chokidar-config-reference.md
# EventEmitter実装パターン
cat .claude/skills/event-driven-file-watching/resources/event-emitter-patterns.md
# 監視システムテンプレート
cat .claude/skills/event-driven-file-watching/templates/watcher-template.ts
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience