hotswap-module
Replace the return value of require('some-module') with the return
value of another module in any app without any code changes.

Installation
npm install hotswap-module --global
CLI Usage
The following three commands all run the script.js file and replace
any call to require('stream') with require('readable-stream').
If hotswap-module isn't installed, simply use npx to run it:
npx hotswap-module stream readable-stream script.js
If hotswap-module is installed globally:
hotswap-module stream readable-stream script.js
If hotswap-module is installed as a dependency:
HOTSWAP=stream,readable-stream node -r hotswap-module script.js
If the script for which you wish to hotswap a module is being started
indirectly, e.g via npm test, you can use the NODE_OPTIONS
environment variable to require the hotswap-module:
HOTSWAP=stream,readable-stream NODE_OPTIONS="-r hotswap-module" npm test
Programmatic Usage
const hotswap = require('hotswap-module')
hotswap('stream', require('readable-stream'))
CLI API
hotswap-module <old-name> <new-name> <script>
Programmatic API
hotswap(name, exports)
Arguments:
name - The name of the module you whish to replace
exports - The new value of the modules exports object
It's important that you call the hotswap function before the module
defined by name is required for the first time.
License
MIT