fix(runtime): implement process.loadEnvFile to actually read .env (#2135)#2286
Merged
Conversation
0d5de0d to
9bf4fcc
Compare
) `process.loadEnvFile(path?)` was lowered to `Expr::Undefined` per #1399's original note that `process.env.X = v` writes didn't persist (#1344) — so eager loading would be moot. #1344 has since wired writes through `std::env::set_var`, making the no-op stub a real parity gap. Now lower to a `NativeMethodCall` that calls the new `js_process_load_env_file` runtime. The runtime reads the file (defaulting to `.env` when the optional path is omitted via HIR), parses each non-comment line on the first `=`, strips a matched surrounding quote pair, and writes each `KEY=value` pair via `std::env::set_var` so `process.env.KEY` reads back in subsequent code (Node-compatible). Missing files throw a Node-shaped Error (`code: "ENOENT"`, `syscall: "open"`, `path: <target>`), matching libuv's wording. Closes one of the #2135 process-tracker stubbed-method gaps.
9bf4fcc to
8f9b9c8
Compare
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
process.loadEnvFile(path?)was lowered toExpr::Undefinedper node:process — implement process.loadEnvFile(path?) #1399's note thatprocess.env.X = vwrites didn't persist — so eager loading would be moot. node:process — process.env.X = v does not persist (assignment lowering) #1344 has since wired writes throughstd::env::set_var, making the no-op stub a real parity gap.".env"(Node's default) so the dispatch-table row's singleNA_STRarg stays satisfied for the no-arg call form.js_process_load_env_filereads the file, parses each non-comment line on the first=, strips a matched surrounding quote pair, and writes eachKEY=valuethroughstd::env::set_varsoprocess.env.KEYreads back in subsequent code.code: "ENOENT",syscall: "open",path: <target>).Closes one of the #2135 process-tracker stubbed-method gaps.
Test plan
test-files/test_issue_2135_load_env_file.tsbyte-identical with Node — covers quoted / unquoted / spaced / empty /=-in-value lines, comments, key-trim, and the missing-file ENOENT path.cargo fmt --all -- --checkclean.cargo test --release -p perry-runtime --lib— 738 tests pass.scripts/regen_api_docs.shclean (the table row registers via theiter_native_module_tableiterator, but the manifest text didn't change).