Agent skill

cosmiconfig-setup

Set up cosmiconfig for hierarchical configuration loading from multiple sources and formats.

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/cosmiconfig-setup

SKILL.md

Cosmiconfig Setup

Set up cosmiconfig for hierarchical config loading.

Capabilities

  • Configure cosmiconfig search paths
  • Set up format loaders (JSON, YAML, TOML)
  • Create TypeScript config support
  • Implement config caching
  • Handle config validation

Generated Patterns

typescript
import { cosmiconfig, cosmiconfigSync } from 'cosmiconfig';
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';

const moduleName = 'myapp';

const explorer = cosmiconfig(moduleName, {
  searchPlaces: [
    'package.json',
    `.${moduleName}rc`,
    `.${moduleName}rc.json`,
    `.${moduleName}rc.yaml`,
    `.${moduleName}rc.yml`,
    `.${moduleName}rc.js`,
    `.${moduleName}rc.ts`,
    `.${moduleName}rc.cjs`,
    `${moduleName}.config.js`,
    `${moduleName}.config.ts`,
    `${moduleName}.config.cjs`,
  ],
  loaders: {
    '.ts': TypeScriptLoader(),
  },
});

export async function loadConfig(searchFrom?: string) {
  const result = await explorer.search(searchFrom);
  if (!result || result.isEmpty) {
    return { config: getDefaultConfig(), filepath: null };
  }
  return { config: { ...getDefaultConfig(), ...result.config }, filepath: result.filepath };
}

Target Processes

  • configuration-management-system
  • cli-application-bootstrap
  • mcp-server-bootstrap

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results