From 544d13928e7d1929fd643c02e444481b915190e2 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 11 Dec 2024 08:20:39 +0000 Subject: [PATCH] refactor(@angular/ssr): move ignored messages as a global Refactored the ignored log messages into a global constant. (cherry picked from commit 6eed4609f4d617801d0825b7477570b10e238022) --- packages/angular/ssr/src/console.ts | 14 +++++++------- packages/angular/ssr/src/routes/ng-routes.ts | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/angular/ssr/src/console.ts b/packages/angular/ssr/src/console.ts index 9a61a912615c..4173b8e51c2d 100644 --- a/packages/angular/ssr/src/console.ts +++ b/packages/angular/ssr/src/console.ts @@ -8,6 +8,11 @@ import { ɵConsole } from '@angular/core'; +/** + * A set of log messages that should be ignored and not printed to the console. + */ +const IGNORED_LOGS = new Set(['Angular is running in development mode.']); + /** * Custom implementation of the Angular Console service that filters out specific log messages. * @@ -15,22 +20,17 @@ import { ɵConsole } from '@angular/core'; * It overrides the `log` method to suppress logs that match certain predefined messages. */ export class Console extends ɵConsole { - /** - * A set of log messages that should be ignored and not printed to the console. - */ - private readonly ignoredLogs = new Set(['Angular is running in development mode.']); - /** * Logs a message to the console if it is not in the set of ignored messages. * * @param message - The message to log to the console. * * This method overrides the `log` method of the `ɵConsole` class. It checks if the - * message is in the `ignoredLogs` set. If it is not, it delegates the logging to + * message is in the `IGNORED_LOGS` set. If it is not, it delegates the logging to * the parent class's `log` method. Otherwise, the message is suppressed. */ override log(message: string): void { - if (!this.ignoredLogs.has(message)) { + if (!IGNORED_LOGS.has(message)) { super.log(message); } } diff --git a/packages/angular/ssr/src/routes/ng-routes.ts b/packages/angular/ssr/src/routes/ng-routes.ts index 1f4f7c7d5613..da808ce743cf 100644 --- a/packages/angular/ssr/src/routes/ng-routes.ts +++ b/packages/angular/ssr/src/routes/ng-routes.ts @@ -410,7 +410,11 @@ export async function getRoutesFromAngularRouterConfig( useValue: { document, url: `${protocol}//${host}/` }, }, { + // An Angular Console Provider that does not print a set of predefined logs. provide: ɵConsole, + // Using `useClass` would necessitate decorating `Console` with `@Injectable`, + // which would require switching from `ts_library` to `ng_module`. This change + // would also necessitate various patches of `@angular/bazel` to support ESM. useFactory: () => new Console(), }, ]);