diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index a7c6d36d..7bf406c9 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -1,20 +1,19 @@ import { Result } from 'ts-results-es'; import { type Observable, from, mergeMap, ObservableInput } from 'rxjs'; import { readdir, stat } from 'fs/promises'; -import { basename, extname, join, resolve, parse } from 'path'; +import { basename, extname, join, resolve, parse, dirname } from 'path'; import assert from 'assert'; import { createRequire } from 'node:module'; import type { ImportPayload, Wrapper } from '../types/core'; import type { Module } from '../types/core-modules'; import { existsSync } from 'fs'; -import { fileURLToPath } from 'node:url'; export const shouldHandle = (path: string, fpath: string) => { - const newPath = new URL(fpath+extname(path), path).href; - return { - exists: existsSync(fileURLToPath(newPath)), - path: newPath - } + const file_name = fpath+extname(path); + let newPath = join(dirname(path), file_name) + .replace(/file:\\?/, ""); + return { exists: existsSync(newPath), + path: 'file:///'+newPath }; } @@ -79,11 +78,9 @@ const isSkippable = (filename: string) => { async function deriveFileInfo(dir: string, file: string) { const fullPath = join(dir, file); - return { - fullPath, - fileStats: await stat(fullPath), - base: basename(file), - }; + return { fullPath, + fileStats: await stat(fullPath), + base: basename(file) }; } async function* readPaths(dir: string): AsyncGenerator { @@ -131,10 +128,8 @@ export function loadConfig(wrapper: Wrapper | 'file'): Wrapper { console.log('Events path is set to', eventsPath); } - return { - defaultPrefix: config.defaultPrefix, - commands: commandsPath, - events: eventsPath, - }; + return { defaultPrefix: config.defaultPrefix, + commands: commandsPath, + events: eventsPath }; } diff --git a/src/sern.ts b/src/sern.ts index d6fe0d59..495e331c 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -34,6 +34,7 @@ export function init(maybeWrapper: Wrapper | 'file') { if (wrapper.events !== undefined) { eventsHandler(dependencies, Files.getFullPathTree(wrapper.events)); } + const initCallsite = callsites()[1].getFileName(); const presencePath = Files.shouldHandle(initCallsite!, "presence"); //Ready event: load all modules and when finished, time should be taken and logged