Skip to content

v2.0.0 - ESM + CommonJS Support

Choose a tag to compare

@mdwekat mdwekat released this 20 Nov 00:38
· 51 commits to main since this release
4dada44

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 import in 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