Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
inject-loader
Advanced tools
A Webpack loader for injecting code into modules via their dependencies
This is particularly useful for writing tests where mocking things inside your module-under-test is sometimes necessary before execution.
inject-loader
was inspired by, and builds upon ideas introduced in jauco/webpack-injectable.
Use the inject loader by adding the inject-loader!
inline loader when you use require
, this will return a function that can used in test code to modify the injected module.
By default all require
statements in an injected module will be altered to be replaced with an injector, though if a replacement it not specified the default values will be used.
Given some code in a module like this:
// MyStore.js
var Dispatcher = require('lib/dispatcher');
var EventEmitter = require('events').EventEmitter;
var handleAction = require('lib/handle_action');
Dispatcher.register(handleAction, 'MyStore');
You can manipulate it’s dependencies when you come to write tests as follows:
// If no flags are provided when using the loader then
// all require statements will be wrapped in an injector
MyModuleInjector = require('inject-loader!MyStore')
MyModule = MyModuleInjector({
'lib/dispatcher': DispatcherMock,
'events': EventsMock,
'lib/handle_action': HandleActionMock
})
There are a few examples of complete test setups for both Webpack 1, 2, 3 & 4 in the example
folder.
4.0.1
FAQs
A Webpack loader for injecting code into modules via their dependencies
We found that inject-loader 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.