@hyperfrontend/project-scope/project/config

config

Configuration-file detection and parsing for the common config formats encountered in JavaScript/TypeScript projects.

detectConfigs scans a project for the configuration files registered in CONFIG_PATTERNS (TypeScript, ESLint, Prettier, Vite, Webpack, Babel, Jest, Vitest, Tailwind, PostCSS, etc.) and returns a DetectedConfig[] with the file path, type, and detection metadata. findConfigFile(type) is the targeted lookup for a single config. parseConfig (plus the parseJsonConfig / parseYamlConfig specializations) reads and parses the located file into a typed ParsedConfig. The CONFIG_PATTERNS registry is exposed so consumers can extend or filter what counts as a config without forking the heuristic.

API Reference

ƒ Functions

§function

clearConfigDetectionCache(): void

Clear the config detection cache.
Useful for testing or when the project files have changed.

Example

Clearing the config detection cache

import { clearConfigDetectionCache } from '@hyperfrontend/project-scope'

// Reset cache after modifying config files
clearConfigDetectionCache()
§function

detectConfigs(rootPath: string, types?: ConfigType[], options?: DetectConfigOptions): DetectedConfig[]

Detect all configuration files in a directory.
Results are cached for 30 seconds per project path and options to avoid redundant file system operations on repeated calls.

Parameters

NameTypeDescription
§rootPath
string
Project root directory
§types?
ConfigType[]
Optional array of config types to check (defaults to all)
§options?
DetectConfigOptions
Detection options

Returns

DetectedConfig[]
Array of detected configuration files

Example

Detecting configuration files

import { detectConfigs } from '@hyperfrontend/project-scope'

// Detect all config files
const configs = detectConfigs('./my-project')
for (const config of configs) {
  console.log(`${config.type}: ${config.path}`)
}
// Output:
// typescript: tsconfig.json
// eslint: eslint.config.js
// jest: jest.config.ts

// Detect specific config types only
const tsConfigs = detectConfigs('./my-project', ['typescript', 'eslint'])
§function

findConfigFile(rootPath: string, type: ConfigType): string

Find a specific configuration file.

Parameters

NameTypeDescription
§rootPath
string
Project root directory
§type
ConfigType
Config type to find

Returns

string
Full path to config file or null if not found

Example

Finding a specific config file

import { findConfigFile } from '@hyperfrontend/project-scope'

const tsConfig = findConfigFile('/project', 'typescript')
// => '/project/tsconfig.json'

const eslint = findConfigFile('/project', 'eslint')
// => '/project/.eslintrc.js' or null if not found
§function

getConfigPatternsByType(types: ConfigType[]): string[]

Get patterns for specific config types.

Parameters

NameTypeDescription
§types
ConfigType[]
Array of config types to get patterns for

Returns

string[]
Array of file patterns

Example

Retrieving config patterns by type

import { getConfigPatternsByType } from '@hyperfrontend/project-scope'

const patterns = getConfigPatternsByType(['typescript', 'eslint'])
// => ['tsconfig.json', 'tsconfig.*.json', '.eslintrc', '.eslintrc.js', ...]
§function

parseConfig(filePath: string, type?: ConfigType): ParsedConfig

Parse configuration file.

Parameters

NameTypeDescription
§filePath
string
Path to config file
§type?
ConfigType
Optional config type (auto-detected if not provided)

Returns

ParsedConfig
Parsed configuration

Example

Parsing a configuration file

import { parseConfig } from '@hyperfrontend/project-scope'

const tsConfig = parseConfig('/project/tsconfig.json')
const eslintConfig = parseConfig('/project/.eslintrc.yml', 'eslint')
§function

parseJsonConfig(filePath: string, content: string, type?: ConfigType, format: "json" | "jsonc"): ParsedConfig

Parse JSON configuration file.

Parameters

NameTypeDescription
§filePath
string
Path to the JSON configuration file
§content
string
Raw file content to parse
§type?
ConfigType
Category of configuration (e.g., typescript, eslint)
§format
"json" | "jsonc"
Whether to strip comments (jsonc) or parse strictly (json)
(default: 'json')

Returns

ParsedConfig
Configuration object with parsed data and extends references

Example

Parsing JSON configuration

import { parseJsonConfig } from '@hyperfrontend/project-scope'

const config = parseJsonConfig(
  'tsconfig.json',
  '{ "extends": "./base.json", "compilerOptions": {} }',
  'typescript'
)
// => { type: 'typescript', path: 'tsconfig.json', data: {...}, extends: ['./base.json'] }
§function

parseYamlConfig(filePath: string, content: string, type?: ConfigType): ParsedConfig

Parse YAML configuration file.

Parameters

NameTypeDescription
§filePath
string
Path to the YAML configuration file
§content
string
Raw file content to parse
§type?
ConfigType
Category of configuration (e.g., github-actions, docker-compose)

Returns

ParsedConfig
Configuration object with parsed YAML data

Example

Parsing YAML configuration

import { parseYamlConfig } from '@hyperfrontend/project-scope'

const config = parseYamlConfig('.github/workflows/ci.yml', yamlContent, 'github-actions')
// => { type: 'github-actions', path: '...', format: 'yaml', data: {...} }

Interfaces

§interface

ConfigPatternInfo

Configuration pattern information.

Properties

§canExtend?:boolean
Whether config can extend others
§description:string
Human-readable description
§format?:"json" | "yaml" | "js" | "ts" | "jsonc" | "ini" | "dotenv" | "text"
Primary format (optional - auto-detected from file extension if not provided)
§patterns:string[]
File patterns to match
§sensitive?:boolean
Whether file may contain secrets
§interface

DetectConfigOptions

Options for config detection.

Properties

§includeHidden?:boolean
Include hidden directories
§maxDepth?:number
Maximum depth for recursive search
§skipCache?:boolean
Skip cache lookup (force fresh detection)
§interface

DetectedConfig

Detected configuration file.

Properties

§info:ConfigPatternInfo
Pattern info
§matchedPattern:string
Pattern that matched
§path:string
File path (relative to root)
§type:ConfigType
Config type
§interface

ParsedConfig

Result of parsing a configuration file.

Properties

§data?:Record<string, unknown>
Parsed data (for JSON/YAML formats)
§extends?:string[]
Extended config paths (if any)
§format:string
File format
§path:string
Source file path
§raw?:string
Raw content (for text formats or JS/TS configs)
§type:"unknown" | ConfigType
Config type

Types

§type

ConfigType

Configuration type identifier.
type ConfigType = "package.json" | "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock" | ".npmrc" | "tsconfig" | "nx" | "project.json" | "workspace.json" | "turbo" | "lerna" | "webpack" | "rollup" | "vite" | "esbuild" | "babel" | "swc" | "jest" | "vitest" | "cypress" | "playwright" | "next" | "angular" | "nuxt" | "svelte" | "astro" | "eslint" | "prettier" | "env" | ".gitignore" | ".gitattributes"

Variables

§type

CONFIG_PATTERNS

Known configuration file patterns organized by type.