From ec6970f5b8abc76ea4bea0453611560d5f3a0d4b Mon Sep 17 00:00:00 2001 From: Tyler Clendenin Date: Tue, 2 Apr 2024 12:13:44 -0400 Subject: [PATCH] feat: ability to disable debug message in ConditionalModule Add an option `debug` defaulted to true to the `registerWhen` method and only create debug log when it is set to true. Also fix type for options.timeout to be optional. --- lib/conditional.module.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/conditional.module.ts b/lib/conditional.module.ts index 9e8d8af9..c7e10047 100644 --- a/lib/conditional.module.ts +++ b/lib/conditional.module.ts @@ -11,9 +11,9 @@ export class ConditionalModule { static async registerWhen( module: Required['imports'][number], condition: string | ((env: NodeJS.ProcessEnv) => boolean), - options?: { timeout: number }, + options?: { timeout?: number; debug?: boolean }, ) { - const { timeout = 5000 } = options ?? {}; + const { timeout = 5000, debug = true } = options ?? {}; const timer = setTimeout(() => { throw new Error( @@ -38,10 +38,12 @@ export class ConditionalModule { returnModule.imports.push(module); returnModule.exports.push(module); } else { - Logger.debug( - `${condition.toString()} evaluated to false. Skipping the registration of ${module.toString()}`, - ConditionalModule.name, - ); + if (debug) { + Logger.debug( + `${condition.toString()} evaluated to false. Skipping the registration of ${module.toString()}`, + ConditionalModule.name, + ); + } } return returnModule; }