Align dotenv parsing with Node#3435
Merged
proggeramlug merged 5 commits intoMay 31, 2026
Merged
Conversation
This was referenced May 30, 2026
f1feb2d to
c28afb9
Compare
Contributor
Author
|
Refreshed this branch for the latest mainline changes.
|
# Conflicts: # crates/perry-hir/src/stable_hash/expr.rs # crates/perry-runtime/src/process.rs # crates/perry-runtime/src/util_parse_env.rs # test-parity/node-suite/util/parse-env.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
util.parseEnvandprocess.loadEnvFile.exportprefixes, duplicate-key last-wins behavior, sorted result keys, inline#comment handling, and Node-style invalidcontenterrors forutil.parseEnv.process.loadEnvFileto accept string, Buffer, and file URL paths, default omitted/undefined/null to.env, reject non-file URLs and encoded/file URL paths with Node-style errors, preserve existingprocess.envvalues, and use the common fs path decoder for path-like inputs.process.loadEnvFile(path?: any): voidshape.Closes #3423.
Closes #2985.
Closes #3045.
Why batched
These issues share the same dotenv parser surface. Fixing
process.loadEnvFilewithout reusing theutil.parseEnvparser would leave two subtly different dotenv grammars in the runtime, so this PR cuts the common parser once and wires both APIs through it.Tests added
test-parity/node-suite/util/parse-env.tswith comments,export, duplicate keys, quoted hash values, actual multiline quoted values, and invalid argument cases.test-parity/node-suite/process/methods/load-env-file.tswith string/Buffer/file URL path inputs, default.envloading, null/undefined handling, non-overwrite behavior, encoded-slash file URL rejection, object/array/symbol invalid path inputs, and non-file URL rejection.Verification
RUSTC_WRAPPER= cargo test -p perry-runtime util_parse_env --libRUSTC_WRAPPER= cargo test -p perry-codegen --test manifest_consistencycargo fmt --all -- --checkRUSTC_WRAPPER= CARGO_TARGET_DIR=/tmp/perry-node-compat-3-target cargo build --release -p perry -p perry-runtime -p perry-stdlibgit diff --check./scripts/check_file_size.shnode --input-type=module < test-parity/node-suite/util/parse-env.tsnode --input-type=module < test-parity/node-suite/process/methods/load-env-file.tsRUSTC_WRAPPER= CARGO_TARGET_DIR=/tmp/perry-node-compat-3-target PERRY_ALLOW_UNIMPLEMENTED=1 /tmp/perry-node-compat-3-target/release/perry test-parity/node-suite/util/parse-env.ts -o /tmp/perry_parse_env_fixedand/tmp/perry_parse_env_fixedRUSTC_WRAPPER= CARGO_TARGET_DIR=/tmp/perry-node-compat-3-target PERRY_ALLOW_UNIMPLEMENTED=1 /tmp/perry-node-compat-3-target/release/perry test-parity/node-suite/process/methods/load-env-file.ts -o /tmp/perry_load_env_file_fixedand/tmp/perry_load_env_file_fixedKnown limitations
node --experimental-strip-typeswithERR_NO_TYPESCRIPT, so the wrapper reportedNode.js error: exit 1before running the Perry comparison. The same fixtures are plain JS and were compared successfully vianode --input-type=module < fileplus direct Perry fixture binaries.Non-goals
process.loadEnvFilebeyond Node's current sync API shape or change unrelated path validation behavior.