feat(node): node:process as the global process
Jason Schwarzenberger authored 1 parent 1a74a6bcommit 71285b418e8001fe2a49beb1eaf6163d32d0033cBrowse files
6 files changed+49−0
Files (6)
modifiedHOMEFLARE.md+1−0View file
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | | `node:net` `isIP` / `isIPv4` / `isIPv6`; `node:dns` and `node:dns/promises` `lookup()` | Fedify checks a URL's host with both before fetching it, so palm's remote lookups failed with `node:net.isIP is not implemented in celld`. `lookup()` uses the node's resolver through a new `__dns_lookup` op, with `connect()`'s egress rules. | |
| 23 | 23 | | `Response.clone()` on a streaming body | celld threw `Cannot clone a streaming response before consumption`; workerd tees the body, as celld's `Request.clone()` already did. palm's media proxy returns a fetched image and caches `response.clone()`. | |
| 24 | 24 | | `node:url` (all but the legacy `parse` / `resolve`) | celld had no `node:url`; Fedify's WebFinger handler calls `domainToASCII` and `domainToUnicode`. Both run Node's own steps (the input set as a `ws://x` hostname) through new host ops on the `url` crate. | |
| 25 | +| `node:process` as the global `process` | The module was the throwing stub while `globalThis.process` existed, so Fedify's User-Agent (`Node.js/${process.versions.node}`, taken when the global has a Node version) threw on every outgoing request. Found by listing palm's bundle imports. | | |
| 25 | 26 | |
| 26 | 27 | ## Building |
| 27 | 28 |
modifiedcrates/celld/js/modules.rs+8−0View file
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | static_source!(NODE_NET_SOURCE, "node_net.js"); |
| 25 | 25 | static_source!(NODE_DNS_SOURCE, "node_dns.js"); |
| 26 | 26 | static_source!(NODE_URL_SOURCE, "node_url.js"); |
| 27 | +static_source!(NODE_PROCESS_SOURCE, "node_process.js"); | |
| 27 | 28 | static_source!(NODE_PATH_SOURCE, "node_path.js"); |
| 28 | 29 | static_source!(NODE_BUFFER_SOURCE, "node_buffer.js"); |
| 29 | 30 | static_source!(NODE_CRYPTO_SOURCE, "node_crypto.js"); |
| @@ -53,6 +54,7 @@ | ||
| 53 | 54 | ("node_net.js", &NODE_NET_SOURCE), |
| 54 | 55 | ("node_dns.js", &NODE_DNS_SOURCE), |
| 55 | 56 | ("node_url.js", &NODE_URL_SOURCE), |
| 57 | + ("node_process.js", &NODE_PROCESS_SOURCE), | |
| 56 | 58 | ("node_path.js", &NODE_PATH_SOURCE), |
| 57 | 59 | ("node_buffer.js", &NODE_BUFFER_SOURCE), |
| 58 | 60 | ("node_crypto.js", &NODE_CRYPTO_SOURCE), |
| @@ -416,7 +418,13 @@ | ||
| 416 | 418 | global: "__urlModule", |
| 417 | 419 | source: &NODE_URL_SOURCE, |
| 418 | 420 | }, |
| 421 | + // Homeflare patch: node:process is the global process. | |
| 419 | 422 | LazyModule { |
| 423 | + specs: &["process", "node:process"], | |
| 424 | + global: "__processModule", | |
| 425 | + source: &NODE_PROCESS_SOURCE, | |
| 426 | + }, | |
| 427 | + LazyModule { | |
| 420 | 428 | specs: &["path", "node:path", "path/posix", "node:path/posix"], |
| 421 | 429 | global: "__pathModule", |
| 422 | 430 | source: &NODE_PATH_SOURCE, |
addedcrates/celld/js/node_process.js+10−0View file
| @@ -1,0 +1,10 @@ | ||
| 1 | +// node:process for celld (Homeflare patch). | |
| 2 | +// | |
| 3 | +// The module is the global process object, as in Node and workerd: the | |
| 4 | +// harness builds it at startup with workerd's values, so `import process | |
| 5 | +// from "node:process"` and `globalThis.process` are the same object, and a | |
| 6 | +// named import reads the same field. | |
| 7 | +(() => { | |
| 8 | + "use strict"; | |
| 9 | + __celld.__processModule = globalThis.process; | |
| 10 | +})(); |
modifieddocs/cloudflare-compat.md+1−0View file
| @@ -160,6 +160,7 @@ | ||
| 160 | 160 | `domainToUnicode`, `fileURLToPath`, `pathToFileURL`, `urlToHttpOptions` and |
| 161 | 161 | `format`. The legacy `parse`, `resolve` and `resolveObject` are not |
| 162 | 162 | implemented (Homeflare patch). |
| 163 | +- `node:process` is the global `process` object (Homeflare patch). | |
| 163 | 164 | - `node:fs` provides `access`, `mkdir`, `realpath`, `stat`, `lstat`, and |
| 164 | 165 | `readFile`. It exposes an empty, request-local `/tmp` and a read-only |
| 165 | 166 | `/bundle` that contains the Worker modules. |
addedhomeflare/smoke/node-process/index.js+23−0View file
| @@ -1,0 +1,23 @@ | ||
| 1 | +// Smoke test for the node:process patch: the module is the global process. | |
| 2 | +// Fedify builds its User-Agent from `${process.versions.node}`. | |
| 3 | +import process from "node:process"; | |
| 4 | +import { env, versions, nextTick } from "node:process"; | |
| 5 | +import * as namespace from "node:process"; | |
| 6 | + | |
| 7 | +const expectEqual = (name, got, want) => ({ name, ok: JSON.stringify(got) === JSON.stringify(want), got }); | |
| 8 | + | |
| 9 | +export default { | |
| 10 | + async fetch() { | |
| 11 | + const checks = [ | |
| 12 | + expectEqual("default is the global", process === globalThis.process, true), | |
| 13 | + expectEqual("versions.node in a template", `Node.js/${process.versions.node}`, `Node.js/${globalThis.process.versions.node}`), | |
| 14 | + expectEqual("named env", env === globalThis.process.env, true), | |
| 15 | + expectEqual("named versions", versions.node, globalThis.process.versions.node), | |
| 16 | + expectEqual("nextTick runs", await new Promise((resolve) => nextTick(resolve, "ticked")), "ticked"), | |
| 17 | + expectEqual("namespace platform", namespace.platform, globalThis.process.platform), | |
| 18 | + expectEqual("dynamic import", (await import("node:process")).default === globalThis.process, true), | |
| 19 | + ]; | |
| 20 | + const failed = checks.filter((c) => !c.ok); | |
| 21 | + return Response.json({ ok: failed.length === 0, failed, checks }, { status: failed.length ? 500 : 200 }); | |
| 22 | + }, | |
| 23 | +}; |
addedhomeflare/smoke/node-process/wrangler.jsonc+6−0View file
| @@ -1,0 +1,6 @@ | ||
| 1 | +{ | |
| 2 | + "name": "node-process", | |
| 3 | + "main": "index.js", | |
| 4 | + "compatibility_date": "2026-01-01", | |
| 5 | + "compatibility_flags": ["nodejs_compat"] | |
| 6 | +} |