@@ -5,14 +5,16 @@ import { commands } from "../../../index";
55
66const commandsPath = path . join ( __dirname , ".." , ".." , ".." , "commands" ) ;
77
8- export default function loader ( file : string , customPath ?: string ) {
8+ export default async function loader ( file : string , customPath ?: string ) {
99 if ( / \. j s $ | \. t s $ / . test ( file ) ) {
1010 const filePath = path . join ( customPath || commandsPath , file ) ;
1111
12- if ( require . cache [ require . resolve ( filePath ) ] )
13- delete require . cache [ require . resolve ( filePath ) ] ;
12+ const resolvedPath = path . resolve ( filePath ) ;
13+ if ( require . cache [ resolvedPath ] ) {
14+ delete require . cache [ resolvedPath ] ;
15+ }
1416
15- const commandModule = require ( filePath ) ;
17+ const commandModule = await import ( filePath ) ;
1618
1719 if (
1820 typeof commandModule . default === "function" &&
@@ -35,6 +37,9 @@ export default function loader(file: string, customPath?: string) {
3537
3638export async function mapCommands ( ) {
3739 const files = await fs . readdir ( commandsPath ) ;
40+ await Promise . all ( files . map ( ( file ) => loader ( file ) ) ) ;
41+ }
3842
39- Promise . all ( files . map ( ( file ) => loader ( file ) ) ) ;
40- }
43+ export function mapCommandsBackground ( ) {
44+ mapCommands ( ) . catch ( err => log . error ( "MapCommandLoader" , err ) ) ;
45+ }
0 commit comments