class TransformationPipeline

Executes an ordered sequence of named transformations over a rule array, with optional lifecycle hooks, exclusion/inclusion pattern filtering, and event emission.

Execution order

Requested transformation types are always sorted into a fixed canonical order (see getOrderedTransformations) regardless of the order in which they appear in the configuration. This guarantees consistent, reproducible output.

Hook integration

The pipeline holds an optional TransformationHookManager. On each iteration the following sequence occurs:

emitProgress(…)
hookManager.executeBeforeHooks(beforeContext)   ← before transformation
try {
  rules = await transformation.execute(rules, ctx)
} catch (e) {
  await hookManager.executeErrorHooks(errorContext)
  throw e
}
hookManager.executeAfterHooks(afterContext)     ← after transformation

When no hooks are registered (hookManager.hasHooks() === false) the three execute calls are skipped entirely. The default is a NoOpHookManager so hook overhead is zero unless you pass a real hook manager.

Event emission

ICompilerEvents.onTransformationStart / onTransformationComplete events are now emitted through the hook system rather than by direct calls inside the loop. FilterCompiler and WorkerCompiler achieve this by automatically registering a createEventBridgeHook on the hook manager when ICompilerEvents listeners are present.

Constructors

new
TransformationPipeline(
logger?: ILogger,
eventEmitter?: CompilerEventEmitter,
)

Creates a new TransformationPipeline.

All parameters are optional; sane defaults are used when omitted:

  • registry defaults to a new TransformationRegistry with all built-in transformations pre-registered.
  • logger defaults to the module-level default logger.
  • eventEmitter defaults to a NoOpEventEmitter (no-overhead singleton).
  • hookManager defaults to a NoOpHookManager (no-overhead, skips all hook code paths).

In practice you will rarely construct this directly — FilterCompiler and WorkerCompiler build and configure the pipeline for you.

Properties

Methods

private
applyExclusions(
rules: string[],
configuration: IConfiguration | ISource,
): Promise<string[]>

Applies exclusion patterns. Optimized to partition patterns by type for faster matching.

private
applyInclusions(
rules: string[],
configuration: IConfiguration | ISource,
): Promise<string[]>

Applies inclusion patterns. Optimized to partition patterns by type for faster matching.

private
applyPatternFilter(
rules: string[],
patterns?: string[],
patternSources?: string[],
mode?: "exclude" | "include",
): Promise<string[]>

Common pattern matching logic for exclusions and inclusions. Partitions patterns by type for optimized matching. Uses combined regex for better performance with many patterns.

Gets transformations in the correct execution order.

transform(
rules: string[],
configuration: IConfiguration | ISource,
transformations?: TransformationType[],
): Promise<string[]>

Apply exclusion/inclusion pattern filters and then execute the requested transformations in canonical order.

The method follows a three-phase approach:

  1. Exclusions — rules matching any exclusion pattern are removed.
  2. Inclusions — if inclusion patterns are configured, only rules matching at least one pattern are kept.
  3. Transformations — each requested transformation is executed in the fixed canonical order, with before/after/error hooks invoked around each execution.

The method uses a readonly string[] internally during the transformation loop to avoid unnecessary array copies; it only materialises a mutable copy at the very end.