1- import { getFilePaths , getFolderPaths } from "../../utils/get-paths" ;
2- import { EventHandlerOptions , EventHandlerData } from "./typings" ;
3- import "colors" ;
1+ import { getFilePaths , getFolderPaths } from '../../utils/get-paths' ;
2+ import { toFileURL } from '../../utils/resolve-file-url' ;
3+ import { EventHandlerOptions , EventHandlerData } from './typings' ;
4+ import 'colors' ;
45
56export class EventHandler {
67 #data: EventHandlerData ;
@@ -21,10 +22,10 @@ export class EventHandler {
2122 const eventFolderPaths = getFolderPaths ( this . #data. eventsPath ) ;
2223
2324 for ( const eventFolderPath of eventFolderPaths ) {
24- const eventName = eventFolderPath . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) as string ;
25+ const eventName = eventFolderPath . replace ( / \\ / g, '/' ) . split ( '/' ) . pop ( ) as string ;
2526
2627 const eventFilePaths = getFilePaths ( eventFolderPath , true ) . filter (
27- ( path ) => path . endsWith ( " .js" ) || path . endsWith ( " .ts" )
28+ ( path ) => path . endsWith ( ' .js' ) || path . endsWith ( ' .ts' )
2829 ) ;
2930
3031 const eventObj = {
@@ -35,10 +36,12 @@ export class EventHandler {
3536 this . #data. events . push ( eventObj ) ;
3637
3738 for ( const eventFilePath of eventFilePaths ) {
38- let eventFunction = ( await import ( eventFilePath ) ) . default ;
39+ const modulePath = toFileURL ( eventFilePath ) ;
40+
41+ let eventFunction = ( await import ( modulePath ) ) . default ;
3942 const compactFilePath = eventFilePath . split ( process . cwd ( ) ) [ 1 ] || eventFilePath ;
4043
41- if ( typeof eventFunction !== " function" ) {
44+ if ( typeof eventFunction !== ' function' ) {
4245 console . log ( `⏩ Ignoring: Event ${ compactFilePath } does not export a function.` . yellow ) ;
4346 continue ;
4447 }
0 commit comments