import { isObject } from "../predicates/schema.predicate.ts"; import { pathToFileURL } from "node:url"; export interface LoadedSource { readonly file: string; readonly exports: Readonly> | null; readonly error: string | null; } export const importSource = async function importSource(file: string): Promise { try { const loaded: unknown = await import(pathToFileURL(file).href); return { error: null, exports: isObject(loaded) ? loaded : {}, file }; } catch (error) { return { error: String(error), exports: null, file }; } }; export const importSources = async function importSources(files: readonly string[]): Promise { return Promise.all(files.map(importSource)); };