npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@esengine/worker-generator

v1.0.2

Published

CLI tool to generate Worker files from WorkerEntitySystem classes for WeChat Mini Game and other platforms

Readme

@esengine/worker-generator

CLI tool to generate Worker files from WorkerEntitySystem classes for WeChat Mini Game and other platforms that don't support dynamic Worker scripts.

Why This Tool?

WeChat Mini Game has strict Worker limitations:

  • Cannot create Workers from Blob URLs or dynamic scripts
  • Worker scripts must be pre-compiled files in the code package
  • Maximum 1 Worker allowed

This tool extracts your workerProcess method and generates compatible Worker files automatically.

Installation

npm install -D @esengine/worker-generator
# or
pnpm add -D @esengine/worker-generator

Usage

1. Configure your WorkerEntitySystem

Add workerScriptPath to specify where the Worker file should be generated:

@ECSSystem('Physics')
class PhysicsWorkerSystem extends WorkerEntitySystem<PhysicsData> {
  constructor() {
    super(Matcher.all(Position, Velocity), {
      enableWorker: true,
      workerScriptPath: 'workers/physics-worker.js', // Output path
      systemConfig: {
        gravity: 100,
        friction: 0.95
      }
    });
  }

  protected workerProcess(
    entities: PhysicsData[],
    deltaTime: number,
    config: any
  ): PhysicsData[] {
    return entities.map(entity => {
      entity.vy += config.gravity * deltaTime;
      entity.x += entity.vx * deltaTime;
      entity.y += entity.vy * deltaTime;
      return entity;
    });
  }
}

2. Run the Generator

# Basic usage
npx esengine-worker-gen --src ./src --wechat

# Full options
npx esengine-worker-gen \
  --src ./src \           # Source directory to scan
  --out ./workers \       # Default output directory (if no workerScriptPath)
  --wechat \              # Generate WeChat Mini Game compatible code (ES5)
  --mapping \             # Generate worker-mapping.json
  --verbose               # Verbose output

3. Configure game.json (WeChat Mini Game)

{
  "workers": "workers"
}

CLI Options

| Option | Description | Default | |--------|-------------|---------| | -s, --src <dir> | Source directory to scan | ./src | | -o, --out <dir> | Output directory for Worker files | ./workers | | -w, --wechat | Generate WeChat Mini Game compatible code | false | | -m, --mapping | Generate worker-mapping.json file | true | | -t, --tsconfig <path> | Path to tsconfig.json | Auto-detect | | -v, --verbose | Verbose output | false |

Output

The tool generates:

  1. Worker files - JavaScript files containing the extracted workerProcess logic
  2. worker-mapping.json - Mapping of class names to Worker file paths

Example output:

workers/
├── physics-worker.js
└── worker-mapping.json

Important Notes

  1. Pure Functions: Your workerProcess must be a pure function - it cannot use this or external variables

    // Correct
    protected workerProcess(entities, deltaTime, config) {
      return entities.map(e => {
        e.y += config.gravity * deltaTime; // Use config parameter
        return e;
      });
    }
    
    // Wrong
    protected workerProcess(entities, deltaTime, config) {
      return entities.map(e => {
        e.y += this.gravity * deltaTime; // Cannot access this!
        return e;
      });
    }
  2. Re-run after changes: Run the generator again after modifying workerProcess

  3. ES5 Conversion: When using --wechat, the tool converts:

    • Arrow functions → regular functions
    • const/letvar
    • Spread operator → Object.assign
    • Template literals → string concatenation

License

MIT