There is a CLI that runs on Node and can be executed via command
on the command line. In its code, some functionality is deactivated for Windows users by if (process.platform === 'win32') { process.exit(1); }
. Now I want to disable this check, and allow Windows users to use the "hidden" functionality (usually the the required software is not installed on Windows, but I have a special setup where it is).
Is there some way, to lie to this CLI and simulate that it is running on e.g. Linux or macOS?
Of course I could fork the CLI, remove the check and work with my own version - but this would require repeating this process for each release. As this functionality should also be available to other users, I would have to publish the forked and modified CLI which could be a frequent source of confusion for its users (What about version numbers? Do I use the same command
?) - 99.9% of the code will stay untouched.
Could I maybe write my own CLI, that does something to "fake" the environment, then executes the installed, original CLI, and cleans up afterwards?
I created an example package that works identical to the CLI, but only does exactly that part that I am investigating:
- https://github.com/janpio/nodejs-cli-nowin
- https://www.npmjs.com/package/nodejs-cli-nowin
Install via npm i -g nodejs-cli-nowin
.