How unlib-js/unreliable works
Main components
• Core Library Module:
• Unreliable Core: Represented by files like src/Unreliable.ts and its corresponding header definitions (src/Unreliable.h.ts). This module encapsulates the state management and lifecycle methods (start, stop, state transitions).
• Daemon Module: The daemon-specific implementation (src/Daemon.ts, src/Daemon.h.ts) builds upon the core, exemplified in its test file (src/Daemon.test.ts), demonstrating how to manage an unreliable daemon.
• Utility/Helper: Components such as stopOnExit (src/stopOnExit.ts) that extend the behavior of managed processes.
• Scripts and Exports:
• Entry and Export Generation Scripts (scripts/entry.ts, scripts/gen-exports.ts) which likely prepare the library for CLI exposure or facilitate module export bundling.
• Configuration and Build Setup:
• Build and bundling configurations are in tsconfig.json, tsup.config.ts, package.json, and pnpm-lock.yaml.
• GitHub workflows (.github/workflows/release-package.yml) are used for CI/CD or automated release handling.
Relationships and interactions
• The core “Unreliable” class is the central piece, with Daemon extending or utilizing it to manage specific processes.
• Utility functions like stopOnExit hook into the Unreliable lifecycle to ensure cleanup on process exit.
• The scripts in the “scripts” directory interface with the core library, possibly providing CLI commands or automated export generation during the build/deployment phase.
• The test files (e.g., Daemon.test.ts) serve as both usage examples and demonstrate how the system components interact.
Architectural patterns and design principles
• The project utilizes an object-oriented pattern (class inheritance and composition) to abstract external process management.
• State management is explicit, with defined states (init, starting, running, etc.) and corresponding configuration for transitions.
• The system follows modular design principles by separating core functionality, specific implementations (daemon), and helper utilities.
• Emphasis is on lifecycle management and error handling (e.g., process spawn and death events).
Relevant technologies and dependencies
• Node.js built-in modules like child_process.
• The once utility from Node.js events.
• TypeScript as the primary language, with configuration for build (tsconfig.json) and bundling (tsup.config.ts).