@hyperfrontend/project-scope/project/configconfig
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
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()detectConfigs(rootPath: string, types?: ConfigType[], options?: DetectConfigOptions): DetectedConfig[]
Results are cached for 30 seconds per project path and options to avoid redundant file system operations on repeated calls.
Parameters
Returns
DetectedConfig[]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'])Parameters
Returns
stringExample
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 foundParameters
| Name | Type | Description |
|---|---|---|
§types | ConfigType[] | Array of config types to get patterns for |
Returns
string[]Example
Retrieving config patterns by type
import { getConfigPatternsByType } from '@hyperfrontend/project-scope'
const patterns = getConfigPatternsByType(['typescript', 'eslint'])
// => ['tsconfig.json', 'tsconfig.*.json', '.eslintrc', '.eslintrc.js', ...]Parameters
Returns
ParsedConfigExample
Parsing a configuration file
import { parseConfig } from '@hyperfrontend/project-scope'
const tsConfig = parseConfig('/project/tsconfig.json')
const eslintConfig = parseConfig('/project/.eslintrc.yml', 'eslint')parseJsonConfig(filePath: string, content: string, type?: ConfigType, format: "json" | "jsonc"): ParsedConfig
Parameters
Returns
ParsedConfigExample
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'] }Parameters
Returns
ParsedConfigExample
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
Properties
format?:"json" | "yaml" | "js" | "ts" | "jsonc" | "ini" | "dotenv" | "text"— ◆ Types
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"