import { diff } from "./_chunks/libs/ohash.mjs"; import { DownloadTemplateOptions } from "giget"; interface DotenvOptions { /** * The project root directory (either absolute or relative to the current working directory). * * Defaults to `options.cwd` in `loadConfig` context, or `process.cwd()` when used as standalone. */ cwd?: string; /** * What file or files to look in for environment variables (either absolute or relative * to the current working directory). For example, `.env`. * With the array type, the order enforce the env loading priority (last one overrides). */ fileName?: string | string[]; /** * Whether to interpolate variables within .env. * * Enabled by default through `loadConfig` and `setupDotenv`, but must be set explicitly * when calling `loadDotenv` directly. * * Supported syntax is `$VAR`, `${VAR}` and `\${VAR}` (escaped, resolves to a literal `${VAR}`). * * An unbraced `$VAR` ends at the first character that is not a word character, so `$HOST:$PORT` * resolves both references. Use braces (`${VAR}`) for names that contain a `:`. * * Within braces, a default value can be provided with `${VAR:-default}` (used when `VAR` is * unset **or** empty) or `${VAR-default}` (used when `VAR` is unset only). Default values can * themselves contain interpolations. * * A reference that cannot be resolved is kept as-is rather than replaced with an empty value. * * @example * ```env * BASE_DIR="/test" * # resolves to "/test/further" * ANOTHER_DIR="${BASE_DIR}/further" * # resolves to "/test/fallback" when UNSET_DIR is unset or empty * FALLBACK_DIR="${UNSET_DIR:-${BASE_DIR}/fallback}" * ``` */ interpolate?: boolean; /** * An object describing environment variables (key, value pairs). */ env?: NodeJS.ProcessEnv; /** * Resolve `_FILE` suffixed environment variables by reading the file at the * specified path and assigning its trimmed content to the base key. * * This is useful for container secrets (e.g. Docker, Kubernetes) where * sensitive values are mounted as files. * * @default false * * @example * ```env * DATABASE_PASSWORD_FILE="/run/secrets/db_password" * # resolves to DATABASE_PASSWORD= * ``` */ expandFileReferences?: boolean; /** * Custom `.env` file parser. * * By default, `node:util.parseEnv` is used when available, falling back to the `dotenv` package. * * @example * ```ts * import { parse } from "dotenv"; * * await setupDotenv({ parse }); * ``` */ parse?: DotenvParseFn; } /** Parses the contents of a `.env` file into key/value pairs. */ type DotenvParseFn = (src: string) => Record; type Env = typeof process.env; /** * Load and interpolate environment variables into `process.env`. * If you need more control (or access to the values), consider using `loadDotenv` instead * */ export declare function setupDotenv(options: DotenvOptions): Promise; /** Load environment variables into an object. */ export declare function loadDotenv(options: DotenvOptions): Promise; declare global { var __c12_dotenv_vars__: Map, Set>; } type JitiOptions = NonNullable[1]>; export interface ConfigLayerMeta { name?: string; [key: string]: any; } export type UserInputConfig = Record; export interface C12InputConfig { $test?: T; $development?: T; $production?: T; $env?: Record; $meta?: MT; } export type InputConfig = C12InputConfig & T; export interface SourceOptions { /** Custom meta for layer */ meta?: MT; /** Layer config overrides */ overrides?: InputConfig; [key: string]: any; /** * Options for cloning remote sources * * @see https://giget.unjs.io */ giget?: DownloadTemplateOptions; /** * Install dependencies after cloning * * Pass `true` to install with c12's defaults (`ignoreWorkspace: true`), or pass an object * to forward arbitrary nypm install options. * * @see https://nypm.unjs.io */ install?: NonNullable; /** * Token for cloning private sources * * @see https://giget.unjs.io#providing-token-for-private-repositories */ auth?: string; } export interface ConfigLayer { config: T | null; source?: string; sourceOptions?: SourceOptions; meta?: MT; cwd?: string; configFile?: string; } export interface ResolvedConfig extends ConfigLayer { config: T; layers?: ConfigLayer[]; cwd?: string; _configFile?: string; } export type ConfigSource = "overrides" | "main" | "rc" | "packageJson" | "defaultConfig"; export interface ConfigFunctionContext { [key: string]: any; } export interface ResolvableConfigContext { configs: Record; rawConfigs: Record | null | undefined>; } type MaybePromise = T | Promise; export type ResolvableConfig = MaybePromise | ((ctx: ResolvableConfigContext) => MaybePromise); export interface LoadConfigOptions { name?: string; cwd?: string; configFile?: string; rcFile?: false | string; globalRc?: boolean; dotenv?: boolean | DotenvOptions; /** * Environment name(s) used to apply `$` and `$env.` overrides. * * When an array is given, later names have higher priority. * * Default: `process.env.NODE_ENV` */ envName?: string | string[] | false; packageJson?: boolean | string | string[]; defaults?: T; defaultConfig?: ResolvableConfig; overrides?: ResolvableConfig, MT>>; omit$Keys?: boolean; /** Context passed to config functions */ context?: ConfigFunctionContext; resolve?: (id: string, options: LoadConfigOptions) => null | undefined | ResolvedConfig | Promise | undefined | null>; /** Custom import function used to load configuration files */ import?: (id: string) => Promise; /** Custom resolver for picking which export to use from the loaded module. Default: `mod.default` if the module has a `default` export, otherwise `mod` */ resolveModule?: (mod: any) => any; /** Options to override defaults when c12 falls back to [jiti](https://github.com/unjs/jiti) for loading config files. */ jitiOptions?: JitiOptions; giget?: false | DownloadTemplateOptions; merger?: (...sources: Array) => T; /** * Custom merger used to apply environment-specific overrides (`$` and `$env.`) onto the config. * * Only applies when merging the env keys of a layer (or of `overrides`) onto that same layer. Layers (`extends`), `overrides`, RC, `package.json` and `defaults` are still combined with `merger`. * * Defaults to `merger` (or `defu`). */ envMerger?: (...sources: Array) => T; extend?: false | { extendKey?: string | string[]; /** * Load each extended layer only once, keeping the first occurrence. * * @default true */ dedupe?: boolean; }; configFileRequired?: boolean; /** * [Standard Schema](https://standardschema.dev) (zod, valibot, arktype, ...) used to validate the final merged config. * * The validated output replaces `config` (schema defaults and transforms are applied). */ schema?: StandardSchemaV1; } export type DefineConfig = (input: InputConfig) => InputConfig; export declare function createDefineConfig(): DefineConfig; /** * Minimal [Standard Schema](https://standardschema.dev) v1 interface. */ export interface StandardSchemaV1 { readonly "~standard": { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown) => StandardSchemaV1Result | Promise>; }; } export type StandardSchemaV1Result = { readonly value: Output; readonly issues?: undefined; } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined; }>; }; export declare const SUPPORTED_EXTENSIONS: string[]; export declare function loadConfig(options: LoadConfigOptions): Promise>; type DiffEntries = ReturnType; type WatchEventType = "created" | "updated" | "removed"; type ConfigWatcher = ResolvedConfig & { watchingFiles: string[]; unwatch: () => Promise; }; interface WatchConfigOptions extends LoadConfigOptions { debounce?: false | number; onWatch?: (event: { type: WatchEventType; path: string; }) => void | Promise; acceptHMR?: (context: { getDiff: () => DiffEntries; newConfig: ResolvedConfig; oldConfig: ResolvedConfig; }) => void | boolean | Promise; onUpdate?: (context: { getDiff: () => ReturnType; newConfig: ResolvedConfig; oldConfig: ResolvedConfig; }) => void | Promise; } export declare function watchConfig(options: WatchConfigOptions): Promise>; export type { ConfigWatcher, DotenvOptions, DotenvParseFn, Env, WatchConfigOptions };