Skip to content

Conversation

@PatrickHeneise
Copy link
Member

Summary

Follow-up to #12 - Improves the merge implementation with bug fixes, performance optimizations, and better error handling.

Changes

🐛 Bug Fixes

  • Fixed whitespace handling bug: Changed from stripping all whitespace (replace(/\s/g, '')) to trimming only leading/trailing whitespace (.trim())
    • Previously broke values like MESSAGE=Hello World (became HelloWorld)
    • Previously broke database URLs with spaces in passwords
    • Now correctly preserves internal spaces in values

⚡ Performance Improvements

  • Optimized duplicate checking: Replaced O(n²) .some() loop with O(n) Set-based lookup
    • Before: checked every key against every example key in nested loop
    • After: build Set once, use O(1) .has() lookups
    • Significant improvement for large .env files

🛡️ Better Error Handling

  • Distinguish error types: Added check for ENOENT vs unexpected errors
    • Silently handles expected "file not found" (creates new .env)
    • Logs warnings for unexpected errors (permissions, corruption)
    • Helps users debug issues without failing silently

📚 Documentation Updates

  • README.md: Added clear explanation of merge behavior
    • Users upgrading from v1.0.0 now understand the new behavior
    • Explains what happens to existing keys
  • CLAUDE.md: Added implementation details and development notes
    • Documents performance optimizations
    • Explains whitespace handling
    • Notes about ESLint version strategy

✅ Test Coverage

  • Added test for space preservation in values
  • Added integration test for merge with spaces in both new and existing values
  • All 12 tests passing

Why These Changes Matter

  1. Whitespace bug is critical: Without this fix, any .env value with spaces gets corrupted
  2. Performance matters: Large .env files would experience quadratic slowdown
  3. Error handling: Users need to know if something unexpected happens vs normal "file not found"

Test Plan

  • All 12 tests passing (4 new tests added)
  • Lint passing
  • Tested with .env files containing spaces in values
  • Verified performance improvement with large .env files

🤖 Generated with Claude Code

- Fix whitespace handling: trim instead of stripping all spaces to preserve
  values like "Hello World" and database URLs with spaces
- Add better error handling: distinguish between expected (ENOENT) and
  unexpected errors (permissions, corruption)
- Optimize performance: use Set-based lookup (O(n)) instead of .some() loop (O(n²))
- Update README.md with merge behavior documentation
- Update CLAUDE.md with implementation details and development notes
- Add comprehensive tests for space preservation and edge cases

All 12 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@PatrickHeneise PatrickHeneise merged commit 2f54f1d into main Nov 21, 2025
1 check passed
@PatrickHeneise PatrickHeneise deleted the fix/improve-merge-implementation branch November 21, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants