Skip to content

fix(runtime): implement process.loadEnvFile to actually read .env (#2135)#2286

Merged
proggeramlug merged 1 commit into
mainfrom
worktree-fix-2135-load-env-file
May 28, 2026
Merged

fix(runtime): implement process.loadEnvFile to actually read .env (#2135)#2286
proggeramlug merged 1 commit into
mainfrom
worktree-fix-2135-load-env-file

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

  • process.loadEnvFile(path?) was lowered to Expr::Undefined per node:process — implement process.loadEnvFile(path?) #1399's note that process.env.X = v writes 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 through std::env::set_var, making the no-op stub a real parity gap.
  • Implement the runtime path. HIR defaults the optional argument to ".env" (Node's default) so the dispatch-table row's single NA_STR arg stays satisfied for the no-arg call form. js_process_load_env_file reads the file, parses each non-comment line on the first =, strips a matched surrounding quote pair, and writes each KEY=value through std::env::set_var so process.env.KEY reads back in subsequent code.
  • Missing files throw a Node-shaped Error (code: "ENOENT", syscall: "open", path: <target>).

Closes one of the #2135 process-tracker stubbed-method gaps.

Test plan

  • New gap test test-files/test_issue_2135_load_env_file.ts byte-identical with Node — covers quoted / unquoted / spaced / empty / =-in-value lines, comments, key-trim, and the missing-file ENOENT path.
  • cargo fmt --all -- --check clean.
  • cargo test --release -p perry-runtime --lib — 738 tests pass.
  • scripts/regen_api_docs.sh clean (the table row registers via the iter_native_module_table iterator, but the manifest text didn't change).

@proggeramlug proggeramlug force-pushed the worktree-fix-2135-load-env-file branch 2 times, most recently from 0d5de0d to 9bf4fcc Compare May 28, 2026 19:22
)

`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.
@proggeramlug proggeramlug force-pushed the worktree-fix-2135-load-env-file branch from 9bf4fcc to 8f9b9c8 Compare May 28, 2026 19:30
@proggeramlug proggeramlug merged commit da002e1 into main May 28, 2026
11 checks passed
@proggeramlug proggeramlug deleted the worktree-fix-2135-load-env-file branch May 28, 2026 19:45
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