fix: Drop dotenv package and use native process.loadEnvFile #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR removes the
dotenvpackage dependency and replaces it with Node.js's nativeprocess.loadEnvFile()function, which has been available since Node.js 20.12.0.Motivation
As mentioned in #[issue_number], the dotenv package has started including non-silencable, misleading upselling comments in CLI output that break MCP server functionality. Since Node.js v20 natively supports loading
.envfiles via theprocess.loadEnvFile()API (introduced in v20.12.0), and this project already requires Node.js >= 20, we can safely migrate to the native implementation.Changes
Code Changes
dotenvimportdotenv.config({ path: filePath })withprocess.loadEnvFile(filePath)ENOENTerrors (file not found), maintaining the same behavior as dotenvundefinedto".env"whenCROSSPOST_DOTENV=1(functionally equivalent since dotenv defaults to.envwhen path is undefined)Dependency Changes
dotenvfrom dependenciesDocumentation Changes
Backward Compatibility
This change is fully backward compatible. The
CROSSPOST_DOTENVenvironment variable continues to work exactly as before:CROSSPOST_DOTENV=1- loads.envfrom the current working directoryCROSSPOST_DOTENV=/path/to/file.env- loads the specified.envfileTesting
✅ All 298 existing tests pass
✅ Linter passes with no errors
✅ Build completes successfully
✅ Manually verified
.envfile loading with custom paths✅ Manually verified non-existent files are handled gracefully
✅ Manually verified
CROSSPOST_DOTENV=1defaults to.envfileBenefits
Original prompt
Fixes #151
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.