style(ngcc): reformat of ngcc after clang update (#36447)

PR Close #36447
This commit is contained in:
Pete Bacon Darwin
2020-04-06 08:30:08 +01:00
committed by Kara Erickson
parent bfa55162de
commit 74b7a8eaf5
118 changed files with 1386 additions and 1046 deletions

View File

@ -44,7 +44,7 @@ export interface UpdatePackageJsonMessage extends JsonObject {
}
/** The type of messages sent from cluster workers to the cluster master. */
export type MessageFromWorker = ErrorMessage | TaskCompletedMessage | UpdatePackageJsonMessage;
export type MessageFromWorker = ErrorMessage|TaskCompletedMessage|UpdatePackageJsonMessage;
/** The type of messages sent from the cluster master to cluster workers. */
export type MessageToWorker = ProcessTaskMessage;

View File

@ -35,8 +35,8 @@ export class ClusterExecutor implements Executor {
if (cluster.isMaster) {
// This process is the cluster master.
return this.lockFile.lock(() => {
this.logger.debug(
`Running ngcc on ${this.constructor.name} (using ${this.workerCount} worker processes).`);
this.logger.debug(`Running ngcc on ${this.constructor.name} (using ${
this.workerCount} worker processes).`);
const master = new ClusterMaster(
this.workerCount, this.logger, this.pkgJsonUpdater, analyzeEntryPoints,
this.createTaskCompletedCallback);

View File

@ -262,7 +262,7 @@ export class ClusterMaster {
*/
private wrapEventHandler<Args extends unknown[]>(fn: (...args: Args) => void|Promise<void>):
(...args: Args) => Promise<void> {
return async(...args: Args) => {
return async (...args: Args) => {
try {
await fn(...args);
} catch (err) {

View File

@ -12,7 +12,7 @@ import * as cluster from 'cluster';
import {AbsoluteFsPath} from '../../../../src/ngtsc/file_system';
import {JsonObject} from '../../packages/entry_point';
import {PackageJsonChange, PackageJsonUpdate, PackageJsonUpdater, applyChange} from '../../writing/package_json_updater';
import {applyChange, PackageJsonChange, PackageJsonUpdate, PackageJsonUpdater} from '../../writing/package_json_updater';
import {sendMessageToMaster} from './utils';

View File

@ -23,14 +23,14 @@ export class Deferred<T> {
*
* @param value The value to resolve the promise with.
*/
resolve !: (value: T) => void;
resolve!: (value: T) => void;
/**
* Rejects the associated promise with the specified reason.
*
* @param reason The rejection reason.
*/
reject !: (reason: any) => void;
reject!: (reason: any) => void;
/** The `Promise` instance associated with this deferred. */
promise = new Promise<T>((resolve, reject) => {

View File

@ -30,7 +30,7 @@ export abstract class SingleProcessorExecutorBase {
const startTime = Date.now();
while (!taskQueue.allTasksCompleted) {
const task = taskQueue.getNextTask() !;
const task = taskQueue.getNextTask()!;
compile(task);
taskQueue.markTaskCompleted(task);
}
@ -65,6 +65,6 @@ export class SingleProcessExecutorAsync extends SingleProcessorExecutorBase impl
}
async execute(analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn):
Promise<void> {
await this.lockFile.lock(async() => this.doExecute(analyzeEntryPoints, createCompileFn));
await this.lockFile.lock(async () => this.doExecute(analyzeEntryPoints, createCompileFn));
}
}

View File

@ -66,7 +66,7 @@ export type CreateTaskCompletedCallback = (taskQueue: TaskQueue) => TaskComplete
* A function to be called once a task has been processed.
*/
export type TaskCompletedCallback =
(task: Task, outcome: TaskProcessingOutcome, message: string | null) => void;
(task: Task, outcome: TaskProcessingOutcome, message: string|null) => void;
/**
* Represents the outcome of processing a `Task`.

View File

@ -8,8 +8,9 @@
import {FileSystem, resolve} from '../../../../src/ngtsc/file_system';
import {Logger} from '../../logging/logger';
import {markAsProcessed} from '../../packages/build_marker';
import {PackageJsonFormatProperties, getEntryPointFormat} from '../../packages/entry_point';
import {getEntryPointFormat, PackageJsonFormatProperties} from '../../packages/entry_point';
import {PackageJsonUpdater} from '../../writing/package_json_updater';
import {Task, TaskCompletedCallback, TaskProcessingOutcome, TaskQueue} from './api';
/**
@ -18,7 +19,7 @@ import {Task, TaskCompletedCallback, TaskProcessingOutcome, TaskQueue} from './a
* These functions can be composed using the `composeTaskCompletedCallbacks()`
* to create a `TaskCompletedCallback` function that can be passed to an `Executor`.
*/
export type TaskCompletedHandler = (task: Task, message: string | null) => void;
export type TaskCompletedHandler = (task: Task, message: string|null) => void;
/**
* Compose a group of TaskCompletedHandlers into a single TaskCompletedCallback.
@ -30,11 +31,11 @@ export type TaskCompletedHandler = (task: Task, message: string | null) => void;
*/
export function composeTaskCompletedCallbacks(
callbacks: Record<TaskProcessingOutcome, TaskCompletedHandler>): TaskCompletedCallback {
return (task: Task, outcome: TaskProcessingOutcome, message: string | null): void => {
return (task: Task, outcome: TaskProcessingOutcome, message: string|null): void => {
const callback = callbacks[outcome];
if (callback === undefined) {
throw new Error(
`Unknown task outcome: "${outcome}" - supported outcomes: ${JSON.stringify(Object.keys(callbacks))}`);
throw new Error(`Unknown task outcome: "${outcome}" - supported outcomes: ${
JSON.stringify(Object.keys(callbacks))}`);
}
callback(task, message);
};
@ -64,10 +65,11 @@ export function createMarkAsProcessedHandler(pkgJsonUpdater: PackageJsonUpdater)
* Create a handler that will throw an error.
*/
export function createThrowErrorHandler(fs: FileSystem): TaskCompletedHandler {
return (task: Task, message: string | null): void => {
return (task: Task, message: string|null): void => {
const format = getEntryPointFormat(fs, task.entryPoint, task.formatProperty);
throw new Error(
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${format})` +
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${
format})` +
(message !== null ? ` due to ${message}` : ''));
};
}
@ -77,11 +79,12 @@ export function createThrowErrorHandler(fs: FileSystem): TaskCompletedHandler {
*/
export function createLogErrorHandler(
logger: Logger, fs: FileSystem, taskQueue: TaskQueue): TaskCompletedHandler {
return (task: Task, message: string | null): void => {
return (task: Task, message: string|null): void => {
taskQueue.markAsFailed(task);
const format = getEntryPointFormat(fs, task.entryPoint, task.formatProperty);
logger.error(
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${format})` +
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${
format})` +
(message !== null ? ` due to ${message}` : ''));
};
}

View File

@ -38,9 +38,9 @@ export abstract class BaseTaskQueue implements TaskQueue {
}
// We are skipping this task so mark it as complete
this.markTaskCompleted(nextTask);
const failedTask = this.tasksToSkip.get(nextTask) !;
this.logger.warn(
`Skipping processing of ${nextTask.entryPoint.name} because its dependency ${failedTask.entryPoint.name} failed to compile.`);
const failedTask = this.tasksToSkip.get(nextTask)!;
this.logger.warn(`Skipping processing of ${nextTask.entryPoint.name} because its dependency ${
failedTask.entryPoint.name} failed to compile.`);
nextTask = this.computeNextTask();
}
return nextTask;
@ -48,7 +48,7 @@ export abstract class BaseTaskQueue implements TaskQueue {
markAsFailed(task: Task) {
if (this.dependencies.has(task)) {
for (const dependentTask of this.dependencies.get(task) !) {
for (const dependentTask of this.dependencies.get(task)!) {
this.skipDependentTasks(dependentTask, task);
}
}
@ -81,7 +81,7 @@ export abstract class BaseTaskQueue implements TaskQueue {
protected skipDependentTasks(task: Task, failedTask: Task) {
this.tasksToSkip.set(task, failedTask);
if (this.dependencies.has(task)) {
for (const dependentTask of this.dependencies.get(task) !) {
for (const dependentTask of this.dependencies.get(task)!) {
this.skipDependentTasks(dependentTask, failedTask);
}
}

View File

@ -49,9 +49,9 @@ export class ParallelTaskQueue extends BaseTaskQueue {
}
// Unblock the tasks that are dependent upon `task`
for (const dependentTask of this.dependencies.get(task) !) {
for (const dependentTask of this.dependencies.get(task)!) {
if (this.blockedTasks.has(dependentTask)) {
const blockingTasks = this.blockedTasks.get(dependentTask) !;
const blockingTasks = this.blockedTasks.get(dependentTask)!;
// Remove the completed task from the lists of tasks blocking other tasks.
blockingTasks.delete(task);
if (blockingTasks.size === 0) {

View File

@ -10,8 +10,8 @@ import {EntryPoint} from '../../packages/entry_point';
import {PartiallyOrderedTasks, Task, TaskDependencies} from './api';
/** Stringify a task for debugging purposes. */
export const stringifyTask = (task: Task): string =>
`{entryPoint: ${task.entryPoint.name}, formatProperty: ${task.formatProperty}, processDts: ${task.processDts}}`;
export const stringifyTask = (task: Task): string => `{entryPoint: ${
task.entryPoint.name}, formatProperty: ${task.formatProperty}, processDts: ${task.processDts}}`;
/**
* Compute a mapping of tasks to the tasks that are dependent on them (if any).
@ -45,7 +45,7 @@ export function computeTaskDependencies(
// Find the earlier tasks (`candidateDependencies`) that this task depends upon.
const deps = graph.dependenciesOf(entryPointPath);
const taskDependencies = deps.filter(dep => candidateDependencies.has(dep))
.map(dep => candidateDependencies.get(dep) !);
.map(dep => candidateDependencies.get(dep)!);
// If this task has dependencies, add it to the dependencies and dependents maps.
if (taskDependencies.length > 0) {
@ -61,7 +61,7 @@ export function computeTaskDependencies(
// dependency of other tasks), so the following should theoretically never happen, but check
// just in case.
if (candidateDependencies.has(entryPointPath)) {
const otherTask = candidateDependencies.get(entryPointPath) !;
const otherTask = candidateDependencies.get(entryPointPath)!;
throw new Error(
'Invariant violated: Multiple tasks are assigned generating typings for ' +
`'${entryPointPath}':\n - ${stringifyTask(otherTask)}\n - ${stringifyTask(task)}`);
@ -73,7 +73,7 @@ export function computeTaskDependencies(
// This task is not generating typings so we need to add it to the dependents of the task that
// does generate typings, if that exists
if (candidateDependencies.has(entryPointPath)) {
const typingsTask = candidateDependencies.get(entryPointPath) !;
const typingsTask = candidateDependencies.get(entryPointPath)!;
const typingsTaskDependents = getDependentsSet(dependencies, typingsTask);
typingsTaskDependents.add(task);
}
@ -87,7 +87,7 @@ export function getDependentsSet(map: TaskDependencies, task: Task): Set<Task> {
if (!map.has(task)) {
map.set(task, new Set());
}
return map.get(task) !;
return map.get(task)!;
}
/**
@ -125,13 +125,13 @@ export function sortTasksByPriority(
tasks: PartiallyOrderedTasks, dependencies: TaskDependencies): PartiallyOrderedTasks {
const priorityPerTask = new Map<Task, [number, number]>();
const computePriority = (task: Task, idx: number):
[number, number] => [dependencies.has(task) ? dependencies.get(task) !.size : 0, idx];
[number, number] => [dependencies.has(task) ? dependencies.get(task)!.size : 0, idx];
tasks.forEach((task, i) => priorityPerTask.set(task, computePriority(task, i)));
return tasks.slice().sort((task1, task2) => {
const [p1, idx1] = priorityPerTask.get(task1) !;
const [p2, idx2] = priorityPerTask.get(task2) !;
const [p1, idx1] = priorityPerTask.get(task1)!;
const [p2, idx2] = priorityPerTask.get(task2)!;
return (p2 - p1) || (idx1 - idx2);
});