Socket
Book a DemoInstallSign in
Socket

hotswap-module

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotswap-module

Replace a Node.js module with another module without any code changes

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

hotswap-module

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

npm build status js-standard-style

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')

// Call hotswap() with the name of the module you wish to replace and
// the exports object of the replacement 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

Keywords

debug

FAQs

Package last updated on 09 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts