Skip to content

Commit

Permalink
feat: ability to disable debug message in ConditionalModule
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dariusj18 committed Apr 2, 2024
1 parent 674b9c1 commit ec6970f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/conditional.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export class ConditionalModule {
static async registerWhen(
module: Required<ModuleMetadata>['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(
Expand All @@ -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;
}
Expand Down

1 comment on commit ec6970f

@mak7an
Copy link

@mak7an mak7an commented on ec6970f Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if (debug) {
        Logger.debug(
          `${condition.toString()} evaluated to false. Skipping the registration of ${module.toString()}`,
          ConditionalModule.name,
        );
}

Please sign in to comment.