Skip to content
Commit Detail

Commit 22c1ca0

Author
Dan Lapid <dlapid@cloudflare.com> 2026-04-16 02:40:06 +0100
Parents
78dfd27
Tree
3663fd0
Improve Node.js compatibility for process, fs, http, events, and navigator (#6575)

* Improve Node.js compatibility for process, fs, http, events, and navigator

Add missing properties and constants identified by the node_compat matrix
to close gaps between workerd and Node.js. All changes are additive — they
either populate previously missing properties with Node.js-compatible values
or fix export wiring so existing values are reachable. I believe no
compat flag should be needed because:

- New properties on existing objects (process.config.variables, stdio
  socket-like properties, EventEmitter.domain, globalAgent options fields)
  cannot break existing code since the keys didn't exist before, and all
  values match Node.js defaults.
- process.config previously had empty target_defaults/variables objects,
  so code reading specific config keys got undefined before and gets the
  correct value now. Code checking for emptiness is unlikely since the
  empty stub was useless.
- fs.promises.constants was missing due to an export wiring issue — the
  constants existed in the internal module but weren't re-exported through
  the promises entry point.
- The HTTP/HTTPS Agent constructor changes align with Node.js's actual
  initialization order (setting defaultPort/protocol/path/proxyEnv on
  this.options), which fixes missing keys on agent.options without
  changing any observable behavior for existing Agent usage.

Specific changes:
- process.config: Populate with representative Node.js build config stubs
- process.stdout/stderr/stdin: Add socket-like properties (bytesRead,
  connecting, readyState, writable*, readable*, etc.)
- fs.promises.constants: Re-export constants from internal_fs_promises
- http/https Agent: Match Node.js constructor flow for options.path,
  options.proxyEnv, options.defaultPort, options.protocol; add
  agentKeepAliveTimeoutBuffer and maxCachedSessions
- EventEmitter: Set domain = null in init() matching Node.js
- navigator.platform: Add read-only property returning "Linux"
- module.prototype.isPreloading: Add boolean stub
- events: Export captureRejections as named export

Files changed