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-1/

Configuration Loader Utility

Build a synchronous configuration loader utility that searches for and loads application configuration files from the filesystem. The utility should handle common configuration scenarios and provide a simple interface for retrieving configuration data.

Requirements

Your utility should provide the following functionality:

  1. Configuration Search

    • Search for configuration files starting from a specified directory
    • Return the configuration data along with the file path where it was found
    • Return null if no configuration file is found
  2. Direct File Loading

    • Load a configuration file from a specific file path
    • Support loading JavaScript and JSON configuration files
    • Return the configuration data along with the file path
  3. Cache Management

    • Provide a way to clear any cached configuration data
    • Ensure that clearing the cache allows fresh configuration data to be loaded on subsequent calls

Implementation

@generates

API

/**
 * Searches for a configuration file starting from the given directory
 * @param {string} searchFrom - The directory path to start searching from
 * @returns {Object|null} Configuration result with 'config' and 'filepath' properties, or null if not found
 */
function findConfig(searchFrom) {
  // Implementation here
}

/**
 * Loads a configuration file from the specified path
 * @param {string} filepath - The path to the configuration file
 * @returns {Object} Configuration result with 'config' and 'filepath' properties
 */
function loadConfig(filepath) {
  // Implementation here
}

/**
 * Clears all cached configuration data
 */
function clearCache() {
  // Implementation here
}

module.exports = {
  findConfig,
  loadConfig,
  clearCache
};

Test Cases

  • When searching from a directory containing a .myapprc.json file, the utility returns the parsed configuration and the file path @test
  • When searching from a directory with no configuration files, the utility returns null @test
  • When loading a specific configuration file path, the utility returns the parsed configuration and the file path @test
  • After clearing the cache and modifying a configuration file, the utility returns the updated configuration on the next load @test

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file search and loading support.

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json