Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/cli-repl/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ async function main() {
process.env.TEST_USE_STDOUT_FOR_PASSWORD || process.stdout.isTTY
? process.stdout
: process.stderr,
// Node.js 20.0.0 made p.exit(undefined) behave as p.exit(0) rather than p.exit()
onExit: (code?: number | undefined) =>
code === undefined ? process.exit() : process.exit(code),
onExit,
shellHomePaths: shellHomePaths,
globalConfigPaths: globalConfigPaths,
});
Expand Down Expand Up @@ -341,3 +339,25 @@ function suppressExperimentalWarnings() {
};
}
}

function onExit(code?: number): never {
// Node.js 20.0.0 made p.exit(undefined) behave as p.exit(0) rather than p.exit(): (code?: number | undefined): never => {
try {
try {
if (code === undefined) process.exit();
else process.exit(code);
} finally {
if (code === undefined) process.exit();
else process.exit(code);
}
} catch (err) {
process.stderr.write(String(err) + '\n');
} finally {
// Should never be reachable anyway, but nyc monkey-patches process.exit()
// internals so that it can always write coverage files as part of the application
// shutdown, and that can throw an exception if the filesystem call to write
// the coverage file fails.
process.stderr.write('process.exit() returned -- aborting\n');
process.abort();
}
}
Loading