import { createRequire } from "node:module";

//#region src/utils/resolve-module.ts
/**
* Wrapper around `createRequire()` for optional dependency loading.
*
* This package ships as ESM, so bare `require()` is not available at runtime.
* Keeping this in a single module lets tests vi.mock() optional resolution.
*
* In bundler environments (Turbopack, Webpack, etc.) `createRequire` or
* `import.meta.url` may be rewritten to nonsensical values, so we wrap
* the initialisation in a try-catch and degrade gracefully to `null`.
*/
let localRequire = null;
try {
	localRequire = createRequire(import.meta.url);
} catch {}
const isBundlerEnvironment = localRequire == null;
function tryRequire(name) {
	if (localRequire == null) return null;
	try {
		return localRequire(name);
	} catch {
		return null;
	}
}

//#endregion
export { isBundlerEnvironment, tryRequire };
//# sourceMappingURL=resolve-module.js.map