Skip to main content

@boost/config

build status npm version

Powerful convention based finder, loader, and manager of both configuration and ignore files.

import { Blueprint, Schemas } from '@boost/common';
import { Configuration } from '@boost/config';

interface ConfigFile {
debug: boolean;
sourceMaps: boolean;
}

class ConfigManager extends Configuration<ConfigFile> {
blueprint({ bool }: Schemas): Blueprint<ConfigFile> {
return {
debug: bool(),
sourceMaps: bool(),
};
}
}

const configManager = new ConfigManager('boost');

// Load `.config/boost.js`, `boost.production.json`, `.boost.yaml`, etc
const { config } = await configManager.loadConfigFromRoot('.');

// Load `.boostignore` files
const ignore = await configManager.loadIgnoreFromBranchToRoot('./some/deep/path');

Features

  • Loads root configs (.config/<name>.js) and branch configs (.<name>.js).
  • Loads ignore files (.<name>ignore).
  • Supports multiple config types: js, cjs, mjs, json, yaml
  • Supports environment and root-level based overrides.
  • Supports extending from other config files.
  • Finds files within each branch folder while traversing up the tree.
  • Caches finder results for increased efficiency.
  • Custom key-value setting processors.

Installation

yarn add @boost/config

Documentation

Index

Type Aliases

ConfigErrorCode

ConfigErrorCode: keyof typeof errors

ExtType

ExtType: cjs | js | json | json5 | mjs | ts | yaml | yml

ExtendsSetting

ExtendsSetting: string[] | string

FileGlob

FileGlob: string[] | string

FileSource

FileSource: branch | extended | overridden | root

FileType

FileType: branch | preset | root-file | root-folder

Handler

Handler<T>: (prev: T, next: T) => Promise<T | undefined> | T | undefined

Type parameters

  • T

Loader

Loader<T>: (path: Path, pkg: PackageStructure) => Promise<DeepPartial<T>>

Type parameters

  • T

LoaderType

LoaderType: Exclude<ExtType, yml>

OverridesSetting

OverridesSetting<T>: OverridesSettingItem<T>[]

Type parameters

  • T

PluginEntry

PluginEntry: string | [string, PluginOptions]

PluginOptions

PluginOptions: boolean | object

PluginsSetting

PluginsSettingList

PluginsSettingList: PluginEntry[]

PluginsSettingMap

PluginsSettingMap: Record<string, PluginOptions>

Variables

constConfigError

ConfigError: new (code: EXTENDS_ONLY_ROOT | EXTENDS_UNKNOWN_PATH | LOADER_UNSUPPORTED | PACKAGE_UNKNOWN_SCOPE | ROOT_INVALID | ROOT_INVALID_DIR | ROOT_NO_PACKAGE | ROOT_ONLY_OVERRIDES, params?: unknown[]) => Error & ScopedError<EXTENDS_ONLY_ROOT | EXTENDS_UNKNOWN_PATH | LOADER_UNSUPPORTED | PACKAGE_UNKNOWN_SCOPE | ROOT_INVALID | ROOT_INVALID_DIR | ROOT_NO_PACKAGE | ROOT_ONLY_OVERRIDES> = ...