@saykit/config
API reference for the configuration package and CLI building blocks
@saykit/config exports defineConfig, loadConfig, messageKey and the config types. The saykit CLI and the build plugins are built on them.
import { defineConfig, loadConfig, messageKey } from '@saykit/config';
import type { ConfigInput, SayKitConfig, Bucket, Formatter, Transformer, Message } from '@saykit/config';Most application code only uses defineConfig and the types. loadConfig and messageKey are for plugin, formatter and transformer authors.
defineConfig(config)
Type a SayKit configuration. It returns the config unchanged and does not validate it; that happens in loadConfig.
import { defineConfig } from '@saykit/config';
import po from '@saykit/format-po';
import js from '@saykit/transform-js';
export default defineConfig({
locales: ['en', 'fr'],
buckets: [
{
include: ['src/**/*.ts'],
output: 'src/locales/{locale}.{extension}',
formatter: po(),
transformer: js(),
},
],
});Types
ConfigInput
Prop
Type
Bucket
Prop
Type
Formatter
Prop
Type
Transformer
Prop
Type
Message
Prop
Type
loadConfig(options?)
Search up from options.cwd (default process.cwd()) for saykit.config.{ts,mts,cts,js,mjs,cjs}, load it, validate it and return a SayKitConfig. Throws a readable error if the file is missing or invalid. Configs exported without defineConfig are accepted.
const config = loadConfig();
config.compile();The config is loaded from where it sits, so its relative imports and import.meta.dirname resolve against its own directory. Reading TypeScript requires Node 22.18+ or a runtime that loads it itself (Bun, Deno, tsx). The saykit CLI, unplugin-saykit and babel-plugin-saykit all load it this way.
SayKitConfig
root, the config file's folder. Relative paths in the config (output,include,exclude) resolve against it, not the working directoryfile,locales,sourceLocale(the first locale)buckets, the resolved buckets:include,exclude,output,formatter,transformer(merged) andmessages, plusincludes(file),cataloguePath(locale)andisCatalogue(path)compile(), compiles every bucket and locale into{locale}.jsand{locale}.d.ts, following the fallback chain, skipping writes that would not change a filefileChanged(path), recompiles the buckets that read a changed catalogue, or returns[]for any other filewatch(), recompiles whenever a catalogue changes and returns a function that stops watchingextract({ watch? }), extracts from source, writes the source locale, adds missing locales and compiles; withwatch, keeps goingclean(), prunes untranslated and stale entries from the other locales, assaykit cleandoestransform(code, file), runs the matching bucket's transformer, or returnsundefinedif no bucket includes the file. Accepts absolute or root-relative paths and ignores a?query
compile, fileChanged and watch return CompiledModules: { bucket, locale, path, sources, count, written }. sources lists the catalogue files read, most specific first, for a bundler's addWatchFile. Library calls only log errors; the CLI adds its own progress output.
messageKey(message)
The key SayKit stores a message under: its id if it has one, otherwise the 6-character hash of message and context. Formatters and transformers should key with it so catalogues match what the runtime looks up.
messageKey({ message: 'Hello', context: 'greeting' });@saykit/config/messages
The message types transformers work with (different from the public catalogue Message shape), plus helpers:
import {
compileMessage,
assignSequenceIdentifiers,
CompositeMessage,
LiteralMessage,
ArgumentMessage,
ChoiceMessage,
ElementMessage,
} from '@saykit/config/messages';compileMessage(icu), compiles one ICU message to the runtime'sMessageassignSequenceIdentifiers(message, { current: 0 }), numbers positional placeholders depth-first
These let custom transformers produce the same placeholder shape the built-in transformers do.
Next
- Configuration guide, how this schema is used in practice
- Custom formatter, implementing
Formatter - Custom transformer, implementing
Transformer