v2.0.0 - ESM + CommonJS Support
NodeSwarm v2.0.0 - Full ESM & CommonJS Support
π Dual Module System
NodeSwarm now supports both ESM (ES Modules) and CommonJS with proper conditional exports!
β¨ New Features
Module Support
- Full ESM support: Use
importin modern projects (Vite, Next.js App Router, etc.) - CommonJS support: Continue using
require()in legacy projects - Dual build system: Separate optimized builds for CJS (
dist/cjs) and ESM (dist/esm) - Proper conditional exports: Tree-shaking support in ESM builds
- Module type hints: package.json files in dist folders for better resolution
- Universal worker path resolution: Works seamlessly in both module systems
Technical Improvements
- Three separate build outputs:
dist/cjs,dist/esm,dist/types - Compatibility tests for both module systems
- Post-build fixes for cross-module compatibility
- Future-proof architecture for modern tooling
π¦ Package Exports
{
"main": "./dist/cjs/index.js", // CommonJS entry
"module": "./dist/esm/index.js", // ESM entry
"types": "./dist/types/index.d.ts" // TypeScript types
}π Usage
ESM (Modern)
import { ThreadPool } from 'nodeswarm';
const pool = new ThreadPool();
const result = await pool.thread((a, b) => a + b, 5, 10);
await pool.close();CommonJS (Legacy)
const { ThreadPool } = require('nodeswarm');
(async () => {
const pool = new ThreadPool();
const result = await pool.thread((a, b) => a + b, 5, 10);
await pool.close();
})();β Compatibility
- β Vite, Rollup, esbuild (ESM)
- β Webpack 5 (both)
- β Next.js App Router (ESM) & Pages Router (CJS)
- β Node.js 12.20+ (for conditional exports)
- β TypeScript (all module systems)
- β Backward compatible - existing code works without changes
π Migration
No migration needed! Your existing CommonJS code continues to work:
// This still works exactly as before
const { ThreadPool } = require('nodeswarm');New ESM projects can now use imports:
// New: Use ESM imports
import { ThreadPool } from 'nodeswarm';π§ Requirements
- Node.js 12.20+ for conditional exports support
- All features from v1.0.0 remain available
Full Changelog: v1.0.0...v2.0.0