2019-08-19 17:10:09 +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 {Logger} from '../logging/logger';
|
|
|
|
|
import {PackageJsonUpdater} from '../writing/package_json_updater';
|
|
|
|
|
|
2019-08-29 01:33:15 +03:00
|
|
|
import {AnalyzeEntryPointsFn, CreateCompileFn, Executor} from './api';
|
|
|
|
|
import {onTaskCompleted} from './utils';
|
2019-08-19 17:10:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Executor` that processes all tasks serially and completes synchronously.
|
|
|
|
|
*/
|
|
|
|
|
export class SingleProcessExecutor implements Executor {
|
|
|
|
|
constructor(private logger: Logger, private pkgJsonUpdater: PackageJsonUpdater) {}
|
|
|
|
|
|
2019-08-29 01:33:15 +03:00
|
|
|
execute(analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn): void {
|
2019-08-19 17:10:09 +03:00
|
|
|
this.logger.debug(`Running ngcc on ${this.constructor.name}.`);
|
|
|
|
|
|
2019-08-27 17:36:25 +03:00
|
|
|
const taskQueue = analyzeEntryPoints();
|
2019-08-29 15:28:00 +03:00
|
|
|
const compile =
|
|
|
|
|
createCompileFn((task, outcome) => onTaskCompleted(this.pkgJsonUpdater, task, outcome));
|
2019-08-19 17:10:09 +03:00
|
|
|
|
|
|
|
|
// Process all tasks.
|
2019-08-29 18:51:02 +03:00
|
|
|
this.logger.debug('Processing tasks...');
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
2019-08-27 17:36:25 +03:00
|
|
|
while (!taskQueue.allTasksCompleted) {
|
|
|
|
|
const task = taskQueue.getNextTask() !;
|
2019-08-19 17:10:09 +03:00
|
|
|
compile(task);
|
2019-08-27 17:36:25 +03:00
|
|
|
taskQueue.markTaskCompleted(task);
|
2019-08-19 17:10:09 +03:00
|
|
|
}
|
2019-08-29 18:51:02 +03:00
|
|
|
|
|
|
|
|
const duration = Math.round((Date.now() - startTime) / 1000);
|
|
|
|
|
this.logger.debug(`Processed tasks in ${duration}s.`);
|
2019-08-19 17:10:09 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-08-19 22:58:22 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Executor` that processes all tasks serially, but still completes asynchronously.
|
|
|
|
|
*/
|
|
|
|
|
export class AsyncSingleProcessExecutor extends SingleProcessExecutor {
|
|
|
|
|
async execute(...args: Parameters<Executor['execute']>): Promise<void> {
|
|
|
|
|
return super.execute(...args);
|
|
|
|
|
}
|
|
|
|
|
}
|