CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lilconfig

A zero-dependency alternative to cosmiconfig for loading configuration files

89

1.21x
Overview
Eval results
Files

task.mdevals/scenario-4/

Project Configuration Finder

Build a tool that finds project-specific configuration files by searching up the directory tree from a given starting point.

Requirements

Your tool should find configuration files for a hypothetical "devtools" project. The tool must:

  1. Accept a starting directory path as input (defaults to current working directory if not provided)
  2. Search for configuration files by traversing up the directory tree from the starting directory
  3. Stop searching when a configuration file is found or when a boundary is reached
  4. Return the configuration file path and its contents when found, or null if no configuration exists
  5. Support multiple configuration file formats in this priority order:
    • .devtoolsrc.json - JSON format
    • .devtoolsrc.js - JavaScript module
    • devtools.config.js - JavaScript module
  6. Handle both synchronous and asynchronous operations

Test Cases

  • When a .devtoolsrc.json file exists in the current directory, it finds and loads the configuration @test
  • When no configuration exists in the current directory but exists in a parent directory, it finds the parent's configuration @test
  • When multiple configuration file types exist in the same directory, it returns the highest priority one @test
  • When no configuration file exists anywhere in the directory tree up to the boundary, it returns null @test

@generates

API

/**
 * Creates a configuration finder for the specified tool name
 * @param {string} toolName - The name of the tool to find config for
 * @returns {Object} An explorer object with search methods
 */
function createConfigFinder(toolName) {
  // Returns an object with search methods
}

/**
 * Synchronously searches for a configuration file starting from searchFrom directory
 * @param {string} [searchFrom] - Directory to start searching from (defaults to process.cwd())
 * @returns {Object|null} Result object with filepath and config, or null if not found
 */
function searchSync(searchFrom) {
  // Implementation here
}

/**
 * Asynchronously searches for a configuration file starting from searchFrom directory
 * @param {string} [searchFrom] - Directory to start searching from (defaults to process.cwd())
 * @returns {Promise<Object|null>} Promise resolving to result object or null
 */
async function search(searchFrom) {
  // Implementation here
}

module.exports = {
  createConfigFinder
};

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file search and loading capabilities for Node.js applications.

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json