refactor(@angular/ssr): move ignored messages as a global

Refactored the ignored log messages into a global constant.
This commit is contained in:
Alan Agius 2024-12-11 08:20:39 +00:00 committed by Alan Agius
parent 210bf4e2b4
commit 6eed4609f4
2 changed files with 11 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -476,7 +476,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(),
},
]);