Skip to content

Possible feature request: patch process.exit directly instead of offering a replacement function? #10

@dead-claudia

Description

@dead-claudia

I'm pretty sure that you could directly patch the process global itself for this (although that breaks every styleguide in existence), only requiring a single import statement for the entire program in its "index.js"/equivalent.

I have verified that it actually patches the property globally, as this code works as you would think:

// a.js
console.log('typeof process.exit: ' + typeof process.exit);
var exit = require('./b');
console.log('typeof process.exit: ' + typeof process.exit);
console.log('process.exit value: ' + process.exit);
process.exit = exit;
exit();
// b.js
var exit = process.exit;
process.exit = 1;
module.exports = exit;
Output:
typeof process.exit: function
typeof process.exit: number
process.exit value: 1

I'm not sure if this would be a good idea or not, so this is more of a conceptual proposal than anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions