Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Promptfoo Promptfoo ESM Loader

From Leeroopedia
Revision as of 13:43, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Promptfoo_Promptfoo_ESM_Loader.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Module_System, Runtime
Last Updated 2026-02-14 07:45 GMT

Overview

Concrete tool for loading ESM and CJS modules dynamically, resolving wrapper script paths, and handling module system interoperability across development and production environments.

Description

The ESM_Loader module (esm.ts) provides utilities for dynamic module loading that work correctly in both ESM and CJS contexts. It handles importing user-defined JavaScript/TypeScript modules (custom providers, assertions, transforms), resolving paths to language-specific wrapper scripts (Python, Ruby, Go), and providing the current directory reference that works across bundled and source environments. Results are cached for performance.

Usage

Import these utilities when code needs to dynamically load user-provided modules or locate wrapper scripts for non-JavaScript providers.

Code Reference

Source Location

Signature

export type WrapperType = 'python' | 'ruby' | 'golang';

export function getDirectory(): string

export function getWrapperDir(type: WrapperType): string

export async function importModule(
  modulePath: string,
  functionName?: string
): Promise<any>

Import

import { getDirectory, getWrapperDir, importModule } from './esm';

I/O Contract

Inputs

Name Type Required Description
type WrapperType Yes Language wrapper type: 'python', 'ruby', or 'golang'
modulePath string Yes Path to the module to import (file:// or relative)
functionName string No Specific named export to retrieve

Outputs

Name Type Description
directory string Absolute path to the current module directory
wrapperDir string Absolute path to the wrapper scripts directory
module any The imported module or specific exported function

Usage Examples

import { importModule, getWrapperDir } from './esm';

// Import a user's custom provider
const provider = await importModule('./my-provider.ts', 'default');

// Get Python wrapper script directory
const pythonDir = getWrapperDir('python');
// e.g., "/path/to/promptfoo/dist/src/python"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment