feat(process): implement process.loadEnvFile as no-op stub (#1399)#1505
Merged
Conversation
Node 20.12+ exposes `process.loadEnvFile(path?)` to read a `.env` file from disk and add its KEY=value entries to process.env. Perry was reading it as a bare number, so `typeof process.loadEnvFile === "function"` returned false and call sites crashed with "value is not a function". Perry today doesn't persist `process.env.X = v` writes (tracked in #1344), so eagerly loading a `.env` would be moot. Returning undefined is the closest no-op for the probe-and-call pattern. Real `.env` loading is tracked separately — this PR closes the typeof / call-doesn't-crash gap. - Call lowering (`native_module.rs`): folds to `Expr::Undefined`, sitting next to the `ref` / `unref` / `setSourceMapsEnabled` / `getBuiltinModule` / `dlopen` / `hasUncaughtExceptionCaptureCallback` / `setUncaughtExceptionCaptureCallback` arms. - Typeof fold (`lower_expr.rs`): adds `loadEnvFile` to the same process-method-as-function list. Test: test-parity/node-suite/process/methods/load-env-file.ts (in the granular suite from #1331) now passes — byte-identical to `node --experimental-strip-types`.
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
Node 20.12+ exposes
process.loadEnvFile(path?)to read a.envfile from disk and add its KEY=value entries toprocess.env. Perry was reading it as a bare number —typeof process.loadEnvFile === "function"returned false and call sites crashed with "value is not a function".Perry today doesn't persist
process.env.X = vwrites (tracked in #1344), so eagerly loading a.envwould be moot. Returning undefined is the closest no-op for the probe-and-call pattern. Real.envloading is tracked separately — this PR closes the typeof / call-doesn't-crash gap.Closes #1399.
Changes
native_module.rs): folds toExpr::Undefined, sitting next to theref/unref/setSourceMapsEnabled/getBuiltinModule/dlopen/hasUncaughtExceptionCaptureCallback/setUncaughtExceptionCaptureCallbackarms.lower_expr.rs): addsloadEnvFileto the same process-method-as-function list.Test plan
test-parity/node-suite/process/methods/load-env-file.ts(in the granular suite from test(parity): add node:process granular suite #1331) now passes — byte-identical tonode --experimental-strip-types.cargo fmt --all -- --checkclean.