seniority/config
Every export of seniority/config, with its signature and doc comment: deepMerge, lineOf, packageLayer, loadWithExtends, candidates, discover, plus 3 types.
import { deepMerge, lineOf, packageLayer, … } from 'seniority/config';Functions
candidates
The discovery order as candidate paths, first hit wins; each entry says why it was tried.
function candidates(d: Discovery): {
path: string;
reason: string;
}[];| Parameter | Type |
|---|---|
d | Discovery |
Returns { path: string; reason: string; }[]
deepMerge
Objects merge recursively; anything else, the later value wins.
function deepMerge(base: Record<string, unknown>, over: Record<string, unknown>): Record<string, unknown>;| Parameter | Type |
|---|---|
base | Record<string, unknown> |
over | Record<string, unknown> |
Returns Record<string, unknown>
discover
Discover and load. package.json#<name> is not a file here — the engine reads the
owning package.json itself and treats the field as its own layer, below config.
function discover(d: Discovery): Promise<Loaded | undefined>;| Parameter | Type |
|---|---|
d | Discovery |
Returns Promise<Loaded \| undefined>
lineOf
The line a top-level key is set on, one-based, or undefined. See keyLines for what it will and will not match.
function lineOf(text: string, key: string): number | undefined;| Parameter | Type |
|---|---|
text | string |
key | string |
Returns number \| undefined
loadWithExtends
Load a file and everything it extends, outermost first, the file's own keys winning.
function loadWithExtends(path: string, options?: LoadConfigOptions, seen?: string[]): Promise<Loaded>;| Parameter | Type |
|---|---|
path | string |
options (optional) | LoadConfigOptions |
seen (optional) | string[] |
Returns Promise<Loaded>
packageLayer
The package.json field named after a program, as the layer below the config file, with the
line each of its keys is set on (R3). Without the line, explain could say a value came from
package.json and not where in it, which is the one file in a project long enough for that to
matter.
function packageLayer(path: string, name: string, manifest?: Record<string, unknown>): Layer | undefined;| Parameter | Type |
|---|---|
path | string |
name | string |
manifest (optional) | Record<string, unknown> |
Returns Layer \| undefined
Interfaces
Discovery
interface Discovery {
name: string;
cwd: string;
env: Record<string, string | undefined>;
/** `--config <path>`. */
explicit?: string;
/** `--no-config`. */
disabled?: boolean;
/** Extra loaders, by extension, merged over the four builtins (R6). */
loaders?: Readonly<Record<string, Loader>>;
/**
* The extensions tried in the current directory, in order. Defaults to the four Node can
* read; a program that injected a `.yaml` loader adds `.yaml` here. The two are separate
* because supplying a parser and asking discovery to look for that format are different
* decisions, and a program may want either without the other.
*/
extensions?: readonly string[];
/**
* Walk up from `cwd` looking for the same names (R5). **Off by default**: a config found
* in a directory the user did not name is the kind of surprise `--explain` exists to
* prevent, so it is a program's decision rather than an ambient behaviour.
*/
upward?: boolean;
/** The highest directory an upward walk may look in, inclusive. Defaults to the filesystem root (Y10). */
stopAt?: string;
}LoadConfigOptions
Options that reach a load, threaded through extends so every file in a chain reads the same way.
interface LoadConfigOptions {
loaders?: Readonly<Record<string, Loader>>;
}Loaded
interface Loaded extends Layer {
/** The files merged, outermost first — what `--explain` shows. */
chain: string[];
}