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

Configuration Migration Utility

Build a command-line utility that helps developers migrate from Cosmiconfig to Lilconfig by verifying API compatibility and testing configuration loading behavior.

Requirements

Your utility should:

  1. Initialize explorers: Create both a Cosmiconfig explorer and a Lilconfig explorer for a given module name (e.g., "myapp")

  2. Search for configuration: Implement a function that searches for configuration files starting from a specified directory using both explorers

  3. Compare results: Compare the results from both explorers and verify they return equivalent data structures (filepath, config, isEmpty fields)

  4. Test both sync and async: Implement the comparison for both synchronous and asynchronous search methods

  5. Handle edge cases: Properly handle cases where:

    • No configuration is found (null result)
    • Configuration is found and successfully loaded
    • Empty configuration files are encountered

Implementation Details

  • Create a main async function compareExplorers(moduleName, searchFrom) that returns a comparison report object
  • The report should indicate whether both libraries behave identically for async search
  • Create a sync function compareExplorersSync(moduleName, searchFrom) for synchronous comparison
  • The report object should have a compatible boolean field and a details object with comparison results
  • Handle errors gracefully and report any differences in behavior

Dependencies { .dependencies }

lilconfig { .dependency }

A zero-dependency alternative to cosmiconfig for loading configuration files.

cosmiconfig { .dependency }

Configuration file search and loading library (for comparison testing).

Test Cases { .tests }

Test 1: Basic async search comparison @test

// test/config-migration.test.js
// Given a directory with a .myapprc.json file containing {"setting": "value"}
// When comparing async search results from both libraries
// Then both should return identical filepath and config values

Test 2: Sync search comparison @test

// test/config-migration.test.js
// Given a directory with a myapp.config.js file exporting {mode: "production"}
// When comparing sync search results from both libraries
// Then both should return identical filepath and config values

Test 3: No config found scenario @test

// test/config-migration.test.js
// Given a directory with no configuration files
// When searching with both libraries (async)
// Then both should return null

Notes

  • Focus on API compatibility between the two libraries
  • Both libraries should provide the same explorer methods and return the same result structure
  • The utility should demonstrate that Lilconfig can be a drop-in replacement for Cosmiconfig in most scenarios

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json