Skip to main content

@boost/config

Build Status npm version npm deps

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

import { Blueprint, Predicates } from '@boost/common';import { Configuration } from '@boost/config';
interface ConfigFile {    debug: boolean;    sourceMaps: boolean;}
class ConfigManager extends Configuration<ConfigFile> {    blueprint({ bool }: Predicates): Blueprint<ConfigFile> {        return {            debug: bool(),            sourceMaps: bool(),        };    }}
const configManager = new ConfigManager('boost');
// Load `.config/boost.js`, `boost.production.json`, `.boost.yaml`, etcconst { config } = await configManager.loadConfigFromRoot('.');
// Load `.boostignore` filesconst 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

Handler

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

Type parameters

  • T

Loader

Loader<T>: (path: Path, pkg: PackageStructure) => Promise<Partial<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_NO_PACKAGE | ROOT_ONLY_OVERRIDES, params?: unknown[]) => Error & ScopedError<EXTENDS_ONLY_ROOT | EXTENDS_UNKNOWN_PATH | LOADER_UNSUPPORTED | PACKAGE_UNKNOWN_SCOPE | ROOT_INVALID | ROOT_NO_PACKAGE | ROOT_ONLY_OVERRIDES> = ...