UNPKG

envase

Version:

Type-safe environment variable validation with Standard Schema compliance

28 lines 1.25 kB
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { if (typeof path === "string" && /^\.\.?\//.test(path)) { return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); }); } return path; }; import { existsSync } from 'node:fs'; import { resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; /** * Loads an environment schema from a file using dynamic import. */ export const loadSchema = async (filePath) => { const absolutePath = resolve(process.cwd(), filePath); if (!existsSync(absolutePath)) { throw new Error(`Schema file not found: ${filePath}`); } const fileUrl = pathToFileURL(absolutePath).href; const module = await import(__rewriteRelativeImportExtension(fileUrl)); const schema = module.default; if (typeof schema !== 'object' || schema === null) { throw new Error('No schema export found. Please export your schema as: "export default { ... }"'); } return schema; }; //# sourceMappingURL=load-schema.js.map