Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / macros/config.macro / loadConfigsSync

Function: loadConfigsSync()

loadConfigsSync(configDir): Record<string, Record<string, unknown>>

Defined in: macros/config.macro.ts:38

Bun macro — scan a config directory and return all configs as a static object.

⚠️ USE ONLY WITH bun build --compile. This macro is evaluated at bundle time and is primarily intended for baking config values into a self-contained binary. Do NOT use it in zt.ts for development or test workflows — it fails on Windows when the argument contains a runtime expression like ${process.cwd()}.

For development (and for all apps not compiled to a binary), import configs directly instead:

// zt.ts — preferred approach (works everywhere)
import appConfig      from './config/app.ts';
import databaseConfig from './config/database.ts';
app.useConfig({ app: appConfig, database: databaseConfig, ... });

For compiled binaries only:

import { loadConfigsSync } from '@zerotal/core/macros/config' with { type: 'macro' };
const configs = loadConfigsSync('/absolute/path/to/config');
app.useConfig(configs);

Note: config files that read Bun.env capture their values from the environment at macro-evaluation time. For bun build --compile this is the CI/CD environment — the same intended behaviour as any immutable artifact.

Parameters

configDir

string

Returns

Record<string, Record<string, unknown>>