Skip to content

Commit 451a1bb

Browse files
committed
Add isConsoleEntrypoint and useOnCli functions; refactor AuthModule for circular dependency
1 parent 2f15f06 commit 451a1bb

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Abstract, DynamicModule, ForwardReference, Provider, Type } from '@nestjs/common'
2+
import path from 'node:path'
3+
4+
export function isConsoleEntrypoint(): boolean {
5+
const entry =
6+
(require?.main?.filename ?? process.argv[1] ?? '').toLowerCase()
7+
const base = path.basename(entry)
8+
return /^(console)\.(t|j)s$/.test(base)
9+
}
10+
11+
export function useOnCli<
12+
T = Provider
13+
| (Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference<any>)
14+
| (string | symbol | Function | Provider | DynamicModule | Promise<DynamicModule> | ForwardReference<any> | Abstract<any>),
15+
>(items: T | T[]): T[] {
16+
if (isConsoleEntrypoint()) {
17+
return items instanceof Array ? items : [items]
18+
}
19+
return []
20+
}

apps/api/src/cli/agents.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ export class AgentsCommand extends CommandRunner {
6060
}
6161

6262
// eslint-disable-next-line @typescript-eslint/no-unused-vars
63-
async run(inputs: string[], options: any): Promise<void> {}
63+
async run(inputs: string[], options: any): Promise<void> { }
6464
}

apps/api/src/core/auth/auth.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module } from '@nestjs/common';
1+
import { Module, forwardRef } from '@nestjs/common';
22
import { AuthController } from './auth.controller';
33
import { AuthService } from './auth.service';
44
import { IAuthModuleOptions, PassportModule } from '@nestjs/passport';
@@ -26,10 +26,10 @@ import { KeyringsModule } from '../keyrings/keyrings.module';
2626
}),
2727
}),
2828
AgentsModule,
29-
KeyringsModule,
29+
forwardRef(() => KeyringsModule),
3030
],
3131
controllers: [AuthController],
3232
providers: [AuthService, JwtStrategy, LocalStrategy],
3333
exports: [AuthService],
3434
})
35-
export class AuthModule {}
35+
export class AuthModule { }

0 commit comments

Comments
 (0)