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

Project Configuration Finder

Build a tool that searches for project configuration files by traversing up the directory tree from a given starting point.

Problem

You need to implement a configuration file finder that can locate project-specific configuration files. The finder should start from a given directory and search upward through parent directories until it finds a configuration file or reaches a specified stopping point.

Your implementation should handle the following scenarios:

  • Search for configuration files starting from a specific directory
  • Continue searching up the directory tree through parent directories if no config is found
  • Stop searching when a configuration file is found
  • Stop searching when reaching a specified boundary directory
  • Return null if no configuration file is found within the search boundaries

Requirements

Search Functionality

Implement a configuration finder with the following behavior:

  1. Accept a starting directory path from which to begin the search
  2. Search for configuration files in the current directory
  3. If not found, move to the parent directory and continue searching
  4. Stop when a configuration file is found
  5. Stop when reaching a boundary directory (if specified)
  6. Return the configuration data and file path when found
  7. Return null when no configuration is found

Configuration File Locations

The finder should search for configuration files in these locations (in order):

  • package.json (with a specific property for your configuration)
  • .apprc.json
  • .config/apprc.json
  • app.config.js

API

Create a module that exports a function to create a configuration explorer. The explorer should have a search method that accepts an optional starting directory.

Test Cases

  • When a config file exists in the starting directory, it returns the config from that directory @test
  • When no config exists in the starting directory but exists in a parent directory, it finds the parent directory config @test
  • When no config file exists within the search boundaries, it returns null @test
  • When a stop directory is specified, search does not go beyond that boundary @test

Implementation

@generates

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file search and loading capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json