Skip to content

fix: preserve env values when preload override is false#1019

Open
Gares95 wants to merge 1 commit into
motdotla:masterfrom
Gares95:fix-override-false-preload
Open

fix: preserve env values when preload override is false#1019
Gares95 wants to merge 1 commit into
motdotla:masterfrom
Gares95:fix-override-false-preload

Conversation

@Gares95

@Gares95 Gares95 commented May 24, 2026

Copy link
Copy Markdown

Summary

This updates preload override handling so explicit string false values are treated the same as the documented boolean false case.

It also adds focused coverage for environment and CLI preload options.

What changed

  • lib/main.js now uses the existing boolean parser when deciding whether populate should overwrite existing values.
  • tests/test-config-cli.js now covers:
    • DOTENV_CONFIG_OVERRIDE=false preserving an existing value.
    • dotenv_config_override=false preserving an existing value.
    • DOTENV_CONFIG_OVERRIDE=true continuing to overwrite an existing value.

Why

Preload options arrive as strings from environment variables and CLI arguments. The existing parser already treats strings such as false, 0, no, off, and an empty string as false for other boolean options.

Applying that same parser to override makes preload behavior line up with the documented default while keeping string true behavior unchanged.

Tests run

  • Focused Docker validation with npm ci --ignore-scripts:
    tests/test-config-cli.js
    • Result: 6 total, 6 pass.
  • Broader Docker validation subset with npm ci --ignore-scripts:
    tests/test-config-cli.js, tests/test-config.js,
    tests/test-populate.js, tests/test-env-options.js,
    tests/test-cli-options.js
    • Result: 89 total, 89 pass.

Risk/compatibility notes

  • This is a small behavior change for string-valued override options.
  • String true still enables override.
  • Boolean true and boolean false behavior remains consistent with the documented option.
  • Users who intentionally relied on any non-empty override string enabling override would see false, 0, no, off, and empty-string values treated as false.
  • The option extraction helpers continue to return string values; normalization remains at the point where overwrite behavior is decided.

Maintainer notes

  • I kept this change scoped to populate so env and CLI option parsing behavior remains unchanged.
  • I added coverage at the preload level because that is where string-valued options are user-visible.
  • Happy to adjust the test placement if a lower-level populate test would be preferred.

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.

1 participant