A TypeScript implementation of the PolyBus messaging library, providing a unified interface for message transport across different messaging systems. This package is designed to work seamlessly in both Node.js and browser environments.
- Node.js 14.0+ (tested with Node.js 14-20)
- npm or yarn package manager
- Any IDE that supports TypeScript development (VS Code, WebStorm, etc.)
# Navigate to the typescript directory
cd src/typescript
# Install dependencies
npm install
# Or with yarn:
yarn install# Build all formats (CommonJS, ESM, UMD, types)
npm run build
# Build and watch for changes
npm run dev
# Clean build artifacts
npm run clean# Run all tests
npm test
# Or: npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Run tests for CI/CD
npm run test:ciThis project includes comprehensive code analysis and formatting tools:
# Run ESLint to check code quality
npm run lint
# Auto-fix linting issues
npm run lint:fix
# TypeScript type checking is performed during build
npm run build- Install the ESLint extension
- Install the TypeScript extension (usually built-in)
- Open the
src/typescriptfolder in VS Code - Auto-formatting and linting will work automatically
- Open the
src/typescriptfolder as a project - Enable ESLint integration (Settings → Languages & Frameworks → JavaScript → Code Quality Tools → ESLint)
- TypeScript support is built-in
The project uses modern TypeScript packaging with dual module support:
- Target: ES2018
- Module Formats: CommonJS, ESM, UMD (browser)
- Node Version: 14.0+
- Type Safety: Strict mode enabled
- Decorators: Experimental decorators enabled
The package exports multiple formats for maximum compatibility:
{
"main": "./dist/index.js", // CommonJS for Node.js
"module": "./dist/index.mjs", // ES Module for bundlers
"browser": "./dist/index.umd.js", // UMD for browsers
"types": "./dist/index.d.ts" // TypeScript definitions
}Code style is enforced through:
- ESLint with TypeScript plugin
- TypeScript strict mode
- Consistent formatting rules (2-space indentation, single quotes, semicolons)
Jest configuration includes:
- Test Environment: Node.js
- Preset: ts-jest with ESM support
- Coverage: HTML, LCOV, JSON, text reports
- Coverage Thresholds: 50% for branches, functions, lines, statements
- Test Discovery:
**/*.test.ts,**/*.spec.ts
reflect-metadata(^0.2.2) - Metadata reflection for decorators
typescript(^5.2.2) - TypeScript compilerjest(^30.2.0) - Testing frameworkts-jest(^29.4.5) - TypeScript support for Jesteslint(^9.39.0) - Code linting@typescript-eslint/eslint-plugin(^8.46.2) - TypeScript ESLint rulesrollup(^4.1.4) - Module bundler@rollup/plugin-typescript(^11.1.5) - Rollup TypeScript plugin@types/node(^20.8.0) - Node.js type definitions@types/jest(^30.0.0) - Jest type definitions
# Development
npm install # Install dependencies
npm run build # Build all formats
npm run dev # Build and watch for changes
npm run clean # Clean build artifacts
# Testing
npm test # Run tests once
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run test:dev # Run tests without thresholds (for development)
# Code Quality
npm run lint # Check code with ESLint
npm run lint:fix # Auto-fix linting issues
# Package Management
npm run prepublishOnly # Clean and build (runs before npm publish)-
TypeScript Errors: Check your TypeScript version
npx tsc --version
-
Module Resolution Issues: Clear node_modules and reinstall
rm -rf node_modules package-lock.json npm install
-
Build Cache Issues: Clean and rebuild
npm run clean npm run build
-
Jest Configuration: Ensure Jest and ts-jest are properly installed
npm install --save-dev jest ts-jest @types/jest
-
ES Module Issues: Check that
"type": "module"is in package.json -
Coverage Threshold Errors: Use
test:devduring development to bypass thresholdsnpm run test:dev
-
ESLint Errors: Auto-fix where possible
npm run lint:fix
-
TypeScript Strict Mode: The project uses strict mode; add proper type annotations
const { PolyBus } = require('poly-bus');
const bus = new PolyBus();
// Use the bus...import { PolyBus } from 'poly-bus';
const bus = new PolyBus();
// Use the bus...import { PolyBus } from 'poly-bus';
const bus = new PolyBus();
// Use the bus...<script src="path/to/poly-bus/dist/index.umd.js"></script>
<script>
const bus = new PolyBus.PolyBus();
// Use the bus...
</script>- Follow the established code style (enforced by ESLint)
- Run
npm run lint:fixbefore committing - Ensure all tests pass:
npm test - Maintain or improve code coverage
- Add tests for new functionality
- Add JSDoc comments for public APIs
- Update TypeScript types as needed
- Update documentation as needed
After running tests with coverage (npm run test:coverage):
- Terminal: Coverage summary displayed in terminal
- HTML: Detailed report available in
coverage/index.html - LCOV: Machine-readable report in
coverage/lcov.info - JSON: Detailed JSON report in
coverage/coverage-final.json
- TypeScript Documentation
- Jest Documentation
- ESLint Documentation
- Rollup Documentation
- TESTING.md - Detailed testing guide
See the main project LICENSE file for licensing information.