From 66e6ed65e9c9281a68b548ab01a2214d5a0aa1e3 Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Thu, 1 Feb 2024 12:48:27 +0900 Subject: fix(node): add `ppid` getter for `node:process` (#22167) This commit adds `ppid` getter for `node:process` to improve Node compatibility one step further. There is one problem though, which is that `Deno.ppid`, which `process.ppid` internally calls, is actually of type `bigint` although it's supposed to be `number`. I filed an issue for this (#22166). For the time being, explciit type conversion from `bigint` to `number` is applied to match the Node.js behavior. --- cli/tests/unit_node/process_test.ts | 8 ++++++++ ext/node/polyfills/process.ts | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 23bf73864..21f873260 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -121,6 +121,14 @@ Deno.test({ }, }); +Deno.test({ + name: "process.ppid", + fn() { + assertEquals(typeof process.ppid, "number"); + assertEquals(process.ppid, Deno.ppid); + }, +}); + Deno.test({ name: "process.on", async fn() { diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index 312b8e845..20399bdf9 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -558,6 +558,11 @@ class Process extends EventEmitter { return pid; } + /** https://nodejs.org/api/process.html#processppid */ + get ppid() { + return Deno.ppid; + } + /** https://nodejs.org/api/process.html#process_process_platform */ get platform() { if (!platform) { -- cgit v1.2.3