CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pnpm--worker

A worker for extracting package tarballs to the store using multi-threaded worker pools for high-performance package management operations

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

worker-pool.mddocs/

Worker Pool Management

Core worker pool lifecycle management for controlling the multi-threaded processing system used by @pnpm/worker.

Capabilities

Restart Worker Pool

Restarts the worker pool by finishing current workers and creating a new pool. This is useful for resetting the worker state or applying configuration changes.

/**
 * Restarts the worker pool by finishing current workers and creating a new pool
 * @returns Promise that resolves when the worker pool has been restarted
 */
function restartWorkerPool(): Promise<void>;

Usage Example:

import { restartWorkerPool } from "@pnpm/worker";

// Restart the worker pool (e.g., after configuration changes)
await restartWorkerPool();
console.log("Worker pool restarted successfully");

Finish Workers

Finishes all active workers in the pool. This should be called before process termination to ensure all workers complete their current tasks gracefully.

/**
 * Finishes all active workers in the pool
 * @returns Promise that resolves when all workers have finished
 */
function finishWorkers(): Promise<void>;

Usage Example:

import { finishWorkers } from "@pnpm/worker";

// Gracefully shutdown all workers before process exit
process.on('SIGTERM', async () => {
  await finishWorkers();
  process.exit(0);
});

Implementation Details

The worker pool is automatically created when needed and uses the following configuration:

  • Maximum Workers: Calculated based on availableParallelism() - 1 or configured via PNPM_WORKERS environment variable
  • Worker Script: Uses the internal worker.js compiled from worker.ts
  • Global Cleanup: Registers global cleanup handlers for proper worker termination
  • Worker Pool Library: Built on @rushstack/worker-pool for robust worker management

The PNPM_WORKERS environment variable can be set to control the number of idle CPUs to reserve:

  • If set, workers = max(2, availableParallelism() - abs(PNPM_WORKERS)) - 1
  • If not set, workers = max(1, availableParallelism() - 1)

Install with Tessl CLI

npx tessl i tessl/npm-pnpm--worker

docs

directory-operations.md

index.md

package-import-linking.md

tarball-processing.md

worker-pool.md

tile.json