Contributing to isolated-workers
Thank you for your interest in contributing to isolated-workers! This guide will help you get started with development and understand our workflow.
Getting Started
Prerequisites
- Node.js 18.0 or later
- pnpm 10.x (the project uses pnpm workspaces)
- Git
Clone and Setup
# Clone the repository
git clone https://github.com/YOUR_USERNAME/isolated-workers.git
cd isolated-workers
# Install dependencies
pnpm install
# Build all packages
pnpm nx run-many -t buildVerify Your Setup
Run the test suite to ensure everything is working:
pnpm nx run-many -t testProject Structure
The repository is organized as an Nx monorepo:
isolated-workers/
├── packages/
│ └── isolated-workers/ # Main library package
├── examples/ # Runnable usage examples
├── docs/ # Documentation (markdown files)
├── docs-site/ # Documentation website (Vike + Pagefind)
├── e2e/ # End-to-end tests
└── .ai/ # AI context and design decisionsKey Directories
- packages/isolated-workers: The core library containing type-safe worker management code
- examples/: Self-contained examples demonstrating library features
- docs/: Markdown documentation rendered by the docs site
- docs-site/: The Vike-based documentation website with search powered by Pagefind
- e2e/: Integration tests that verify full workflows
Development Workflow
Running Tests
# Run all unit tests
pnpm nx run-many -t test
# Run tests for a specific package
pnpm nx run isolated-workers:test
# Run end-to-end tests
pnpm nx run-many -t e2eRunning Examples
Examples are located in the examples/ directory. Each example is a self-contained demonstration of a feature.
# Run a specific example
pnpm nx run examples:run-example --example=basic-ping
# List available examples
ls examples/Building the Documentation Site
# Build the docs site
pnpm nx run docs-site:build
# Preview the docs site locally
pnpm nx run docs-site:previewLinting and Type Checking
# Run linting across all packages
pnpm nx run-many -t lint
# Run type checking
pnpm nx run-many -t buildCode Standards
TypeScript
This project uses TypeScript strict mode. Key rules:
- No
anytypes: Use concrete types for all public APIs - Explicit return types: Functions should have explicit return types
- Meaningful names: Use descriptive variable and function names (e.g.,
userIDnotid) - Early returns: Reduce nesting with early return statements
ESLint Configuration
The project enforces several TypeScript-specific rules:
@typescript-eslint/no-explicit-any: Disallowsanytype@typescript-eslint/no-unused-vars: Flags unused variables (allows_prefix for intentionally unused)@typescript-eslint/no-non-null-assertion: Disallows non-null assertions (!)
Formatting
Code is formatted with Prettier using single quotes. Format your code before committing:
pnpm prettier --write .Submitting Changes
Fork and Branch
- Fork the repository on GitHub
- Clone your fork locally
- Create a feature branch:
git checkout -b feature/your-feature-nameDevelopment Process
- Make your changes in the feature branch
- Write tests for new functionality
- Update documentation if you're changing APIs or adding features
- Ensure all checks pass:
pnpm nx run-many -t lint,build,testCreating a Pull Request
- Push your branch to your fork
- Open a Pull Request against the
mainbranch - Fill out the PR template with:
- Description of changes
- Related issues (if any)
- Testing performed
- Wait for review and address feedback
Commit Messages
Write clear, descriptive commit messages:
feat(workers): add graceful shutdown with configurable timeout
- Add shutdown() method to WorkerConnection
- Support configurable timeout (default 5s)
- Clean up pending operations on shutdownAdding Examples
Examples help users understand how to use the library. Each example lives in its own directory under examples/.
Example Structure
examples/
└── my-example/
├── meta.yml # Example metadata
├── content.md # Documentation content
├── host.ts # Host process code
├── worker.ts # Worker process code
└── messages.ts # Shared message definitionsmeta.yml Format
id: my-example
title: My Example Title
description: |
A clear description of what this example demonstrates
and what users will learn from it.
entryPoint: host.ts
fileMap:
'./messages.ts': 'messages.ts'
'./host.ts': 'host.ts'
'./worker.ts': 'worker.ts'
commands:
- command: 'pnpm run:my-example'
title: 'Run the example'
assertions:
- contains: 'Expected output'content.md Format
Write documentation that explains the example:
# My Example Title
Brief introduction to what this example shows.
## Overview
- Key concept 1
- Key concept 2
## Files
### Shared Message Definitions
{% file messages.ts %}
### Host (Client)
{% file host.ts %}
### Worker
{% file worker.ts %}
## Running the Example
\`\`\`bash
pnpm nx run examples:run-example --example=my-example
\`\`\`Region Markers for Code Embedding
Use region markers to embed specific code sections in documentation:
// #region message-definitions
export type Messages = DefineMessages<{
ping: { payload: { value: string }; result: { pong: string } };
}>;
// #endregion message-definitionsReference in markdown:
{% file messages.ts region="message-definitions" %}Getting Help
- Check existing issues for similar problems
- Review the documentation for usage guidance
- Open a new issue if you find a bug or have a feature request
License
By contributing to isolated-workers, you agree that your contributions will be licensed under the MIT License.