@santana-org/config
v0.2.0
Published
Lightweight config file discovery and loading for Santana Org CLIs — supports JSON, JSONC, JS/TS, and package.json fields
Maintainers
Readme
@santana-org/config
Lightweight config file discovery and loading for Santana Org CLIs.
Walks up from cwd looking for config in the standard places, in order:
package.json— field matching the tool name.toolrc— JSON or JSONC.toolrc.json/.toolrc.jsonctool.config.jsontool.config.js/.mjs/.ts— default export
Install
npm install @santana-org/configUsage
import { loadConfig, loadConfigOrThrow, defineConfig } from "@santana-org/config"
// finds config for "mytool" walking up from cwd
const result = await loadConfig({ name: "mytool" })
if (result) {
console.log(result.config) // the parsed config object
console.log(result.filepath) // where it was found
console.log(result.source) // "package.json" | "rc" | "json" | "js" | "ts"
}
// throws if no config found
const { config } = await loadConfigOrThrow({
name: "mytool",
defaults: { port: 3000, debug: false },
})TypeScript config files
Users can write mytool.config.ts:
import { defineConfig } from "@santana-org/config"
export default defineConfig({
port: 4000,
debug: true,
})defineConfig is a no-op identity function that gives TypeScript autocompletion when paired with a generic type:
// mytool.config.ts
import { defineConfig } from "@santana-org/config"
import type { MyToolConfig } from "mytool"
export default defineConfig<MyToolConfig>({ port: 4000 })