env.ts

view source

Declarations
#

7 declarations

env_var_has_visibility
#

env.ts view source

(config: EnvVarConfig<any>, visibility: EnvVisibility): boolean import {env_var_has_visibility} from '@fuzdev/gro/env.js';

Whether a declared env var belongs to visibility - SvelteKit's vars are private unless declared public: true.

config

type EnvVarConfig<any>

visibility

returns

boolean

EnvVarDeclarations
#

EnvVisibility
#

env.ts view source

EnvVisibility

type "public" | "private"

import type {EnvVisibility} from '@fuzdev/gro/env.js';

load_env
#

env.ts view source

(dev: boolean, env_dir?: string | undefined, env_files?: string[], ambient_env?: Record<string, string | undefined>): Record<string, string> import {load_env} from '@fuzdev/gro/env.js';

Loads every env var from the env files plus the ambient env, later sources winning, so the ambient env overrides the files.

dev

picks the development or production mode files for the default env_files

type boolean

env_dir?

the directory the env files are resolved against, defaults to the cwd

type string
optional

env_files

the env files to load, in order, defaults to the same files as Vite

type string[]
default to_default_env_files(dev)

ambient_env

the env merged in last

type Record<string, string | undefined>
default process.env

returns

Record<string, string>

all loaded vars, unfiltered - resolve_env_vars picks out the declared ones

load_from_env
#

env.ts view source

(key: string, paths?: string[]): string | undefined import {load_from_env} from '@fuzdev/gro/env.js';

Loads a single env value without merging it into process.env. By default searches process.env, then a local .env if one exists, then ../.env if it exists. Empty strings are semantically the same as undefined for more ergonomic fallbacks.

key

type string

paths

type string[]
default ['.env', '../.env']

returns

string | undefined

resolve_env_vars
#

env.ts view source

(variables: EnvVarDeclarations, visibility: EnvVisibility, env: Record<string, string | undefined>): Record<string, unknown> import {resolve_env_vars} from '@fuzdev/gro/env.js';

Resolves the declared env vars of one visibility from env, validating each the way SvelteKit does: a var with no schema must be present, and one with a schema gets its Standard Schema result, so validators can transform values and make them optional.

variables

the declarations from the project's src/env.ts

visibility

which of the declared vars to resolve

env

the values to resolve them from, usually from load_env

type Record<string, string | undefined>

returns

Record<string, unknown>

the resolved values keyed by var name

throws

  • listing - every invalid var, so a misconfigured env fails all at once

to_default_env_files
#

Imported by
#