@angular-modernizer/worker
v0.1.3
Published
Worker thread script for parallel analysis in the Angular Modernization Platform
Maintainers
Readme
@angular-modernizer/worker
Worker thread script for parallel analysis in the Angular Modernization Platform.
Overview
This package contains the analysis worker script that runs in Node.js worker threads for parallel code analysis. It depends on all plugin packages and is therefore the last package built in the monorepo.
Why a Separate Package?
Worker threads run in isolated V8 contexts and need access to all analysis plugins. Since plugins depend on core, and core contains the WorkerPool, placing the worker script in core would create a circular dependency.
This package resolves that by:
- Depending on all plugin packages (builds last)
- Exporting a helper function to get the worker script path
- Being used by both programmatic API users and the MCP adapter
Usage
import { getWorkerScriptPath } from '@angular-modernizer/worker';
import { WorkerPool } from '@angular-modernizer/core';
const pool = new WorkerPool({
tsConfigPath: '/path/to/tsconfig.json',
workerScriptPath: getWorkerScriptPath(),
maxWorkers: 4,
});
const result = await pool.executeTask({
id: 'task-1',
filePath: '/path/to/file.ts',
pluginIds: ['architecture', 'solid'],
});
await pool.terminate();Mode Selection
- Less than 100 files: Promise mode (worker overhead exceeds benefit)
- 100-500 files: Adaptive mode (auto-selects based on available memory)
- More than 500 files: Worker mode (5-10x speedup)
Memory pressure: at 85% heap usage, the pool reduces worker count or pauses new tasks.
Build Order
This package builds last in the monorepo:
1. core
2. plugin-system
3. api
4. plugin-analyzer, plugin-solid, plugin-angular, plugin-standalone, plugin-architecture, orchestration
5. worker (this package)
6. adapter-mcpExports
getWorkerScriptPath()- Returns the absolute path to the compiled worker script- Re-exports
WorkerTask,WorkerResulttypes from@angular-modernizer/core
Requirements
All workspace packages must be built before using workers. Run pnpm build from the monorepo root.
Testing
Worker tests are skipped by default to keep CI fast. Set ENABLE_WORKER_TESTS=true to run the full worker pool suite:
ENABLE_WORKER_TESTS=true pnpm --filter @angular-modernizer/worker testImplementation Notes
Workers require ContextFactory.createAnalysisContext() — not a bare { sourceFile, project, config } object. Rules that access context.api will throw when given a bare object.
Data crossing the thread boundary must be JSON-serializable. Functions, class instances, circular references, and Symbols cannot be serialized and will cause DataCloneError.
