Skip to content

Commit

Permalink
fix(node): add ppid getter for node:process (#22167)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
magurotuna authored and littledivy committed Feb 1, 2024
1 parent 5c7bb34 commit 0d1e586
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions ext/node/polyfills/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0d1e586

Please sign in to comment.