George Kalpakas e367593a26 refactor(ngcc): support running callback before writing transformed files (#36626)
This commit enhances the `CompileFn`, which is used to process each
entry-point, to support running a passed-in callback (and wait for it to
complete) before proceeding with writing the transformed files to disk.

This functionality is currently not used. In a subsequent commit, it
will be used for passing info from worker processes to the master
process that will allow ngcc to recover when a worker process crashes in
the middle of processing a task.

PR Close #36626
2020-04-29 14:28:26 -07:00

35 lines
1.3 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {FileToWrite} from '../rendering/utils';
import {Task, TaskCompletedCallback, TaskQueue} from './tasks/api';
/**
* The type of the function that analyzes entry-points and creates the list of tasks.
*
* @return A list of tasks that need to be executed in order to process the necessary format
* properties for all entry-points.
*/
export type AnalyzeEntryPointsFn = () => TaskQueue;
/** The type of the function that can process/compile a task. */
export type CompileFn<T> = (task: Task) => void|T;
/** The type of the function that creates the `CompileFn` function used to process tasks. */
export type CreateCompileFn = <T extends void|Promise<void>>(
beforeWritingFiles: (transformedFiles: FileToWrite[]) => T,
onTaskCompleted: TaskCompletedCallback) => CompileFn<T>;
/**
* A class that orchestrates and executes the required work (i.e. analyzes the entry-points,
* processes the resulting tasks, does book-keeping and validates the final outcome).
*/
export interface Executor {
execute(analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn):
void|Promise<void>;
}