IF Commons GitHub

physical/config-load

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-anyfs-cli-surfaces FR-004

How the program finds and loads its configuration (commons anyfs-cli 0004-anyfs-cli-surfaces FR-004): --config FILE, else the first anyfs.config.ts from the working folder up to the root of the checkout (the first folder that holds .git, which is searched too), else the one in the user's configuration folder. The file is imported as TypeScript (which Bun and Node 26 both run), its default export, or its export config, is read by parseConfig, and every way it can fail is a typed problem with its code. No file is not a problem: the program works on plain paths and addresses without one.

import { findConfigFile } from "./config-load.ts";
findConfigFile("/nowhere/at/all", undefined, () => undefined); // undefined

Source: commons/anyfs-cli/src/physical/config-load.ts

1 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ConfigProblemtypeno test imports it
type ConfigProblem = { readonly code: "E-CONFIG-LOAD" | "E-CONFIG-INVALID"; readonly message: string };

Why a configuration could not be had.

findConfigFilefunction
function findConfigFile(from: string, explicit: string | undefined, env: (name: string) => string | undefined): string | undefined

The configuration's file: the one --config names, else the first from a folder up to the root of the checkout, else the user's.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

loadConfigFilefunctionno test imports it
function loadConfigFile(file: string): Promise<Result<Config, ConfigProblem>>

Loads a configuration file, or says why it could not be. Each load is a fresh import of the file, so that a file that changed is read again in the same process.

Titles, headings, exports, tables, columns and requirements. Esc closes.