seniority
API reference

seniority/config

Every export of seniority/config, with its signature and doc comment: deepMerge, lineOf, loadWithExtends, candidates, discover, plus 3 types.

import { deepMerge, lineOf, loadWithExtends, … } 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;
}[];
ParameterType
dDiscovery

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>;
ParameterType
baseRecord<string, unknown>
overRecord<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>;
ParameterType
dDiscovery

Returns Promise<Loaded \| undefined>

lineOf

The line a top-level key is set on, one-based, or undefined.

Text, not a parse tree: a JSON parser that reported positions would be a parser, and JSON.parse reports none. The scan is exact about what it can answer — a "key": on a line — and silent about what it cannot, because a wrong line number in an error message is worse than no line number at all (R3, R12).

function lineOf(text: string, key: string): number | undefined;
ParameterType
textstring
keystring

Returns number \| undefined

loadWithExtends

Load a file and everything it extends, outermost first, the file's own keys winning.

The lines reported are the extending file's own (R3). A value a parent set and the child did not override is cited through chain at the parent's path; a line number borrowed across files would point confidently at the wrong text.

function loadWithExtends(path: string, options?: LoadConfigOptions, seen?: string[]): Promise<Loaded>;
ParameterType
pathstring
options (optional)LoadConfigOptions
seen (optional)string[]

Returns Promise<Loaded>

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[];
}

On this page