2019-08-07 22:46:35 +03:00
|
|
|
/**
|
|
|
|
|
* @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 {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
|
|
|
|
|
|
|
|
|
|
/** The type of the function that analyzes entry-points and creates the list of tasks. */
|
2019-08-09 15:01:57 +03:00
|
|
|
export type AnalyzeEntryPointsFn = () => {
|
2019-08-07 22:46:35 +03:00
|
|
|
processingMetadataPerEntryPoint: Map<string, EntryPointProcessingMetadata>;
|
|
|
|
|
tasks: Task[];
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-09 15:01:57 +03:00
|
|
|
/** The type of the function that can process/compile a task. */
|
|
|
|
|
export type CompileFn = (task: Task) => void;
|
|
|
|
|
|
|
|
|
|
/** The type of the function that creates the `CompileFn` function used to process tasks. */
|
|
|
|
|
export type CreateCompileFn = (onTaskCompleted: TaskCompletedCallback) => CompileFn;
|
2019-08-07 22:46:35 +03:00
|
|
|
|
2019-08-19 17:10:09 +03:00
|
|
|
/** Options related to the orchestration/execution of tasks. */
|
|
|
|
|
export interface ExecutionOptions {
|
|
|
|
|
compileAllFormats: boolean;
|
|
|
|
|
propertiesToConsider: string[];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/**
|
2019-08-19 17:10:09 +03:00
|
|
|
* 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).
|
2019-08-07 22:46:35 +03:00
|
|
|
*/
|
2019-08-19 17:10:09 +03:00
|
|
|
export interface Executor {
|
|
|
|
|
execute(
|
|
|
|
|
analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn,
|
refactor(ngcc): add support for asynchronous execution (#32427)
Previously, `ngcc`'s programmatic API would run and complete
synchronously. This was necessary for specific usecases (such as how the
`@angular/cli` invokes `ngcc` as part of the TypeScript module
resolution process), but not for others (e.g. running `ivy-ngcc` as a
`postinstall` script).
This commit adds a new option (`async`) that enables turning on
asynchronous execution. I.e. it signals that the caller is OK with the
function call to complete asynchronously, which allows `ngcc` to
potentially run in a more efficient mode.
Currently, there is no difference in the way tasks are executed in sync
vs async mode, but this change sets the ground for adding new execution
options (that require asynchronous operation), such as processing tasks
in parallel on multiple processes.
NOTE:
When using the programmatic API, the default value for `async` is
`false`, thus retaining backwards compatibility.
When running `ngcc` from the command line (i.e. via the `ivy-ngcc`
script), it runs in async mode (to be able to take advantage of future
optimizations), but that is transparent to the caller.
PR Close #32427
2019-08-19 22:58:22 +03:00
|
|
|
options: ExecutionOptions): void|Promise<void>;
|
2019-08-19 17:10:09 +03:00
|
|
|
}
|
2019-08-07 22:46:35 +03:00
|
|
|
|
|
|
|
|
/** Represents metadata related to the processing of an entry-point. */
|
|
|
|
|
export interface EntryPointProcessingMetadata {
|
|
|
|
|
/**
|
|
|
|
|
* Whether the typings for the entry-point have been successfully processed (or were already
|
|
|
|
|
* processed).
|
|
|
|
|
*/
|
|
|
|
|
hasProcessedTypings: boolean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether at least one format has been successfully processed (or was already processed) for the
|
|
|
|
|
* entry-point.
|
|
|
|
|
*/
|
|
|
|
|
hasAnyProcessedFormat: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Represents a unit of work: processing a specific format property of an entry-point. */
|
|
|
|
|
export interface Task {
|
|
|
|
|
/** The `EntryPoint` which needs to be processed as part of the task. */
|
|
|
|
|
entryPoint: EntryPoint;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The `package.json` format property to process (i.e. the property which points to the file that
|
|
|
|
|
* is the program entry-point).
|
|
|
|
|
*/
|
|
|
|
|
formatProperty: EntryPointJsonProperty;
|
|
|
|
|
|
2019-08-08 03:23:46 +03:00
|
|
|
/**
|
|
|
|
|
* The list of all format properties (including `task.formatProperty`) that should be marked as
|
|
|
|
|
* processed once the taksk has been completed, because they point to the format-path that will be
|
|
|
|
|
* processed as part of the task.
|
|
|
|
|
*/
|
|
|
|
|
formatPropertiesToMarkAsProcessed: EntryPointJsonProperty[];
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/** Whether to also process typings for this entry-point as part of the task. */
|
|
|
|
|
processDts: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 15:01:57 +03:00
|
|
|
/** A function to be called once a task has been processed. */
|
|
|
|
|
export type TaskCompletedCallback = (task: Task, outcome: TaskProcessingOutcome) => void;
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/** Represents the outcome of processing a `Task`. */
|
|
|
|
|
export const enum TaskProcessingOutcome {
|
|
|
|
|
/** The target format property was already processed - didn't have to do anything. */
|
|
|
|
|
AlreadyProcessed,
|
|
|
|
|
|
|
|
|
|
/** Successfully processed the target format property. */
|
|
|
|
|
Processed,
|
|
|
|
|
}
|