
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
require-swapper
Advanced tools
Browserify v2 transform to swap CommonJS require call to custom function call
npm install require-swapper browserify
Require-swapper swaps all CommonJS require() function calls in your code to specified custom function, or for certain module which matches given target module list.
Suppose you have following index.js and swapping require function to myrequire() for module aaa,
var aaa = require('aaa')
, bbb = require('./dir1/bbb')
, ccc = require('./dir2/ccc')
module.exports = function() {
aaa(bbb, ccc);
}
It will output the folowing content to downstream.
var aaa = myrequire('aaa')
, bbb = require('./dir1/bbb')
, ccc = require('./dir2/ccc')
module.exports = function() {
aaa(bbb, ccc);
}
As the loading function for module aaa become swapped, browserify worker will not resolve and bundle the module aaa statically.
It is anticipated that your custom loader function myrequire would resolve it.
Combining browserify CLI, you can use it like following:
browserify index.js -t [ require-swapper --fn 'myrequire' --module 'aaa' ] > bundle.js
options.fn
Specify your custom function name to swap require() call.
options.modules
A target module list or glob pattern to swap require(). If the option is not specified, all require() call will be replaced.
FAQs
Swap CommonJS require call to custom function call.
The npm package require-swapper receives a total of 486 weekly downloads. As such, require-swapper popularity was classified as not popular.
We found that require-swapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.