dotenv-vscode icon indicating copy to clipboard operation
dotenv-vscode copied to clipboard

Add monorepo support for .env file discovery

Open pete-the-pete opened this issue 2 months ago • 0 comments

Summary

Addresses #90, specifically this comment requesting support for loading .env files from nested directories in monorepo setups.

Changes

This PR adds comprehensive monorepo support to intelligently locate and load .env files in multi-package workspaces.

Core Functionality:

  • Smart .env File Discovery: Implements findNearestEnvFile() that walks up the directory tree from the active file to locate the nearest .env file, respecting workspace boundaries
  • Priority System: Establishes a priority order for .env files (.env.local > .env > others), allowing package-specific overrides while falling back to shared root configuration
  • Caching Layer: Adds memoization for discovered .env files to improve performance

Configuration:

  • Adds new setting dotenv.enableMonorepoSupport (enabled by default)
  • When enabled, uses the active file's directory as the starting point for .env discovery
  • When disabled, falls back to original behavior of using workspace root

File Watching:

  • Implements file system watcher for .env* files to detect changes
  • Automatically clears the memoization cache when files change

🤖 Generated with Claude Code

pete-the-pete avatar Jan 10 '26 01:01 pete-the-pete