Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
create-require
Advanced tools
The create-require npm package is designed to dynamically create a `require` function at a given path. This is particularly useful in scenarios where you need to resolve modules or require files relative to a specific directory, rather than the current working directory of the process. It can be used to simulate the behavior of Node.js's `require` in different contexts or to dynamically load modules from various locations in a filesystem.
Creating a custom require function for a specific directory
This feature allows you to create a new `require` function that resolves modules as if it was called from the specified directory. This is useful for loading modules from a directory different from the current script's directory.
const createRequire = require('create-require');
const myRequire = createRequire('/path/to/my/directory');
const myModule = myRequire('./myModule');
Similar to create-require, import-fresh allows you to require a module afresh, ensuring that it is re-evaluated. It's useful for testing and situations where you need to bypass Node's require cache. However, it doesn't allow specifying a directory for module resolution like create-require does.
Proxyquire is designed for overriding dependencies during testing. It allows you to create a custom `require` function that can return mock modules instead of the real ones. While it serves a different primary purpose (mocking for tests), it shares the concept of creating a custom require function with create-require.
create-require
Polyfill for Node.js module.createRequire
(<= v12.2.0)
yarn add create-require
npm install create-require
function createRequire (filename: string | URL): NodeRequire;
const createRequire = require('create-require')
const myRequire = createRequire('path/to/test.js')
const myModule = myRequire('./test-sibling-module')
FAQs
Polyfill for Node.js module.createRequire (<= v12.2.0)
We found that create-require 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.