Skip to content

Align dotenv parsing with Node#3435

Merged
proggeramlug merged 5 commits into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-dotenv-parser
May 31, 2026
Merged

Align dotenv parsing with Node#3435
proggeramlug merged 5 commits into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-dotenv-parser

Conversation

@andrewtdiz
Copy link
Copy Markdown
Contributor

@andrewtdiz andrewtdiz commented May 30, 2026

Summary

  • Implements a shared Node-compatible dotenv parser for util.parseEnv and process.loadEnvFile.
  • Adds multiline quoted values, export prefixes, duplicate-key last-wins behavior, sorted result keys, inline # comment handling, and Node-style invalid content errors for util.parseEnv.
  • Updates process.loadEnvFile to 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 existing process.env values, and use the common fs path decoder for path-like inputs.
  • Updates the API manifest signature for the optional process.loadEnvFile(path?: any): void shape.

Closes #3423.
Closes #2985.
Closes #3045.

Why batched

These issues share the same dotenv parser surface. Fixing process.loadEnvFile without reusing the util.parseEnv parser 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

  • Expanded test-parity/node-suite/util/parse-env.ts with comments, export, duplicate keys, quoted hash values, actual multiline quoted values, and invalid argument cases.
  • Expanded test-parity/node-suite/process/methods/load-env-file.ts with string/Buffer/file URL path inputs, default .env loading, 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 --lib
  • RUSTC_WRAPPER= cargo test -p perry-codegen --test manifest_consistency
  • cargo fmt --all -- --check
  • RUSTC_WRAPPER= CARGO_TARGET_DIR=/tmp/perry-node-compat-3-target cargo build --release -p perry -p perry-runtime -p perry-stdlib
  • git diff --check
  • ./scripts/check_file_size.sh
  • node --input-type=module < test-parity/node-suite/util/parse-env.ts
  • node --input-type=module < test-parity/node-suite/process/methods/load-env-file.ts
  • RUSTC_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_fixed and /tmp/perry_parse_env_fixed
  • RUSTC_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_fixed and /tmp/perry_load_env_file_fixed

Known limitations

  • The parity wrapper was attempted for both fixtures, but this local Node v22.22.1 build fails node --experimental-strip-types with ERR_NO_TYPESCRIPT, so the wrapper reported Node.js error: exit 1 before running the Perry comparison. The same fixtures are plain JS and were compared successfully via node --input-type=module < file plus direct Perry fixture binaries.
  • The normal release build initially hit local sccache/default-target infrastructure failures; the isolated no-wrapper build listed above completed successfully.

Non-goals

  • This PR does not expand process.loadEnvFile beyond Node's current sync API shape or change unrelated path validation behavior.

@andrewtdiz
Copy link
Copy Markdown
Contributor Author

Refreshed this branch for the latest mainline changes.

  • Merged current origin/main, including the util/sys manifest mirror fix that was failing cargo-test.
  • Applied the ReflectIsExtensible stable-hash tag correction required while current mainline still has the duplicate tag.
  • Regenerated the API manifest docs after the merge.
  • Local checks passed: CARGO_TARGET_DIR=/root/perry/target cargo test -p perry-api-manifest sys_alias_mirrors_util_manifest, CARGO_TARGET_DIR=/root/perry/target cargo test -p perry-hir stable_hash::tests::expr_variant_stable_hash_tags_are_unique, CARGO_TARGET_DIR=/root/perry/target cargo test -p perry-runtime util_parse_env::tests::parses_node_compatible, cargo fmt --all -- --check, git diff --check against the branch merge-base, git diff --check, scripts/check_file_size.sh, and workflow YAML parsing.

# 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
@proggeramlug proggeramlug merged commit 4ec10bb into PerryTS:main May 31, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants