I have a JS/Node based CLI that was initially developed to run on macOS and Linux. I now want to make it work on Windows, but because of complicated and fixed reasons I have to achieve this without changing the app's source code.
A first step was to lie to the program about its process.platform
, which works great by messing with its Module
(suggested by @estus) and wrapping the original CLI in another CLI that is then actually used on Windows.
Now I stumbled over some code that runs shelljs.which('ruby')
and compares the result to a specific string (/usr/bin/ruby
) and outputs an error message or even fails the program when it does not match. I don't know how to overcome that yet.
How can I manipulate what shell.which()
returns?
One approach that I could take would be to manipulate require('shelljs')
to load my own fork of shelljs
that returns whatever I want (via using override-require
, which I already used to replace child_process
with cross-spawn
which works much better on Windows). But I want to avoid maintaining my own fork of shelljs
of course - it would be much more practical if I could somehow just manipulate shelljs.which
.
I created a super small demo project that is similar to the CLI I am using and can be used to experiment with possible solutions: https://github.com/janpio/nodejs-cli-wrongruby - fake.js
would be where I would want to manipulate shelljs.which
somehow.