1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(node): add missing process.reallyExit method (#19326)

This PR adds the missing `process.reallyExit()` method to node's
`process` object.

Was [pinged on
twitter](https://twitter.com/biwanczuk/status/1663326659787862017)
regarding running the `fastify` test suite in node. They use `node-tap`
which has been around arguably the longest of the test frameworks and
relies on a couple of old APIs. They have `signal-exit` as a dependency
which in turn [makes use of
`process.reallyExit()`](8fa7fc9a9c/src/index.ts (L19)).
That function cannot be found anywhere in their documentation, but
exists at runtime. See
6a6b3c5402/lib/internal/bootstrap/node.js (L172)

This doesn't yet make `node-tap` work, but gets us one step closer.
This commit is contained in:
Marvin Hagemeister 2023-05-31 12:20:38 +02:00 committed by Bartek Iwańczuk
parent fae10bf3ae
commit f89b2c5ca6
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
3 changed files with 37 additions and 1 deletions

View file

@ -727,3 +727,22 @@ Deno.test({
assertEquals(stripColor(decoder.decode(stdout).trim()), "exit");
},
});
Deno.test({
name: "process.reallyExit",
async fn() {
const command = new Deno.Command(Deno.execPath(), {
args: [
"run",
"--quiet",
"--unstable",
"./testdata/process_really_exit.ts",
],
cwd: testDir,
});
const { stdout } = await command.output();
const decoder = new TextDecoder();
assertEquals(stripColor(decoder.decode(stdout).trim()), "really exited");
},
});

View file

@ -0,0 +1,10 @@
import process from "node:process";
//deno-lint-ignore no-undef
// @ts-ignore - Node typings don't even have this because it's
// been deprecated for 4 years. But it's used in `signal-exit`,
// which in turn is used in `node-tap`.
process.reallyExit = function () {
console.info("really exited");
};
process.exit();

View file

@ -91,7 +91,7 @@ export const exit = (code?: number | string) => {
process.emit("exit", process.exitCode || 0);
}
Deno.exit(process.exitCode || 0);
process.reallyExit(process.exitCode || 0);
};
function addReadOnlyProcessAlias(
@ -380,6 +380,13 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_exit_code */
exit = exit;
// Undocumented Node API that is used by `signal-exit` which in turn
// is used by `node-tap`. It was marked for removal a couple of years
// ago. See https://github.com/nodejs/node/blob/6a6b3c54022104cc110ab09044a2a0cecb8988e7/lib/internal/bootstrap/node.js#L172
reallyExit = (code: number) => {
return Deno.exit(code || 0);
};
_exiting = _exiting;
/** https://nodejs.org/api/process.html#processexitcode_1 */