Skip to content

[SC-1504] Make .env loading optional with autoLoadEnv constructor flag #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zZoMROT
Copy link
Contributor

@zZoMROT zZoMROT commented Jun 5, 2025

Static Code Analysis (readability, compactness):

  • Introduced an autoLoadEnv flag in the Networks constructor to control whether environment variables should be automatically loaded via dotenv.config().
  • Added a loadEnv() utility function that loads environment variables, by default from .env, but accepts standard dotenv.config options (e.g., custom path or encoding).

These changes remove hidden side effects, improve clarity, and preserve backward compatibility.

Dynamic Code Analysis (external APIs, interaction flows):

Previously, environment variables were always loaded implicitly during Networks instantiation, which could lead to issues if process.env was accessed before that (e.g., in hardhat.config.ts). The new approach allows developers to load environment variables explicitly using loadEnv(options?) at the appropriate point in the setup flow.

Efficiency (gas costs, computational complexity, memory requirements):

No impact. The change only affects how environment variables are loaded during setup and does not impact runtime or on-chain behavior.

Opinion, trade-offs and other thoughts (optional):

This change slightly increases the API surface but improves flexibility and makes environment handling explicit and predictable. It aligns with library design best practices by avoiding implicit side effects and supporting more advanced dotenv usage via options.

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (948af77) to head (618ea75).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #189   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          346       346           
  Branches        65        65           
=========================================
  Hits           346       346           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zZoMROT zZoMROT requested review from SevenSwen and byshape June 5, 2025 21:25
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.

3 participants