Skip to content

Commit 6eed460

Browse files
committed
refactor(@angular/ssr): move ignored messages as a global
Refactored the ignored log messages into a global constant.
1 parent 210bf4e commit 6eed460

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/angular/ssr/src/console.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@
88

99
import { ɵConsole } from '@angular/core';
1010

11+
/**
12+
* A set of log messages that should be ignored and not printed to the console.
13+
*/
14+
const IGNORED_LOGS = new Set(['Angular is running in development mode.']);
15+
1116
/**
1217
* Custom implementation of the Angular Console service that filters out specific log messages.
1318
*
1419
* This class extends the internal Angular `ɵConsole` class to provide customized logging behavior.
1520
* It overrides the `log` method to suppress logs that match certain predefined messages.
1621
*/
1722
export class Console extends ɵConsole {
18-
/**
19-
* A set of log messages that should be ignored and not printed to the console.
20-
*/
21-
private readonly ignoredLogs = new Set(['Angular is running in development mode.']);
22-
2323
/**
2424
* Logs a message to the console if it is not in the set of ignored messages.
2525
*
2626
* @param message - The message to log to the console.
2727
*
2828
* This method overrides the `log` method of the `ɵConsole` class. It checks if the
29-
* message is in the `ignoredLogs` set. If it is not, it delegates the logging to
29+
* message is in the `IGNORED_LOGS` set. If it is not, it delegates the logging to
3030
* the parent class's `log` method. Otherwise, the message is suppressed.
3131
*/
3232
override log(message: string): void {
33-
if (!this.ignoredLogs.has(message)) {
33+
if (!IGNORED_LOGS.has(message)) {
3434
super.log(message);
3535
}
3636
}

packages/angular/ssr/src/routes/ng-routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,11 @@ export async function getRoutesFromAngularRouterConfig(
476476
useValue: { document, url: `${protocol}//${host}/` },
477477
},
478478
{
479+
// An Angular Console Provider that does not print a set of predefined logs.
479480
provide: ɵConsole,
481+
// Using `useClass` would necessitate decorating `Console` with `@Injectable`,
482+
// which would require switching from `ts_library` to `ng_module`. This change
483+
// would also necessitate various patches of `@angular/bazel` to support ESM.
480484
useFactory: () => new Console(),
481485
},
482486
]);

0 commit comments

Comments
 (0)