import { n as __require } from "./chunk-DEq-mXcV.js";
//#region src/util/processShim.ts
/**
* Browser-safe process shim module.
*
* This module provides a shimmed process object that works in both Node.js and browser
* environments. In Node.js, it provides full functionality including process.mainModule.require.
* In browsers, it returns a minimal shim that throws helpful errors when Node.js-specific
* features are accessed.
*
* This separation is necessary because:
* 1. The promptfoo webui imports httpTransforms.ts which needs getProcessShim()
* 2. httpTransforms.ts is designed to be frontend-importable for testing transforms in the UI
* 3. The Node.js implementation uses createRequire from 'node:module' which doesn't exist in browsers
*
* By using runtime environment detection and dynamic imports, we can:
* - Avoid top-level imports of Node.js-only modules that would break browser bundling
* - Provide appropriate functionality for each environment
*/
/**
* Detects if the current environment is a browser or web worker.
* Handles test environments (jsdom/happy-dom) that define window in Node.js.
*/
function isBrowserEnvironment() {
	if (typeof process !== "undefined" && typeof process.versions?.node === "string") return false;
	return typeof window !== "undefined" || typeof self !== "undefined" && typeof self.importScripts === "function";
}
/**
* Creates a minimal process shim for browser environments.
* This shim provides helpful error messages when Node.js-specific features are accessed.
*/
function createBrowserProcessShim() {
	return {
		env: {},
		mainModule: {
			require: () => {
				throw new Error("require() is not available in browser transforms. Use standard JavaScript instead.");
			},
			exports: {},
			id: ".",
			filename: "",
			loaded: true,
			children: [],
			paths: []
		}
	};
}
let cachedNodeProcessShim = null;
/**
* Returns a shimmed process object that works in both Node.js and browser environments.
*
* In Node.js:
* - Returns a proxy with process.mainModule.require shimmed for ESM compatibility
* - Allows inline transforms to use require() even in ESM context
*
* In browsers:
* - Returns a minimal shim with helpful error messages
* - Allows simple transforms that don't use require() to work
*
* @example
* // In Node.js - can use require
* const fn = new Function('data', 'process', `return process.mainModule.require('fs')`);
* fn(data, getProcessShim());
*
* @example
* // In browser - simple transforms work
* const fn = new Function('data', 'process', `return data.toUpperCase()`);
* fn(data, getProcessShim());
*/
function getProcessShim() {
	if (isBrowserEnvironment()) return createBrowserProcessShim();
	if (!cachedNodeProcessShim) try {
		const esmRequire = __require("node:module").createRequire(import.meta.url);
		cachedNodeProcessShim = new Proxy(process, { get(target, prop) {
			if (prop === "mainModule") return {
				require: esmRequire,
				exports: {},
				id: ".",
				filename: "",
				loaded: true,
				children: [],
				paths: []
			};
			return Reflect.get(target, prop);
		} });
	} catch {
		return createBrowserProcessShim();
	}
	return cachedNodeProcessShim;
}
//#endregion
export { getProcessShim as t };

//# sourceMappingURL=processShim-DwdcSYEj.js.map