New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mattisg.requirewith

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mattisg.requirewith - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

test/subfolder/recursive.js

18

index.js

@@ -12,4 +12,14 @@ var Module = require('module'), // capitalize to not override the `module` reference defined by `require`

function dispatch(filename, injected, recursive) {
return _dispatch(filename, injected, recursive, module.parent);
}
dispatch._withParent = function(parentModule) {
return function(filename, injected, recursive) {
return _dispatch(filename, injected, recursive, parentModule);
}
}
function _dispatch(filename, injected, recursive, parentModule) {
// Resolve full filename relative to the parent module
filename = Module._resolveFilename(filename, module.parent);
filename = Module._resolveFilename(filename, parentModule);

@@ -28,5 +38,5 @@ if (! injected)

function runInContext(filename, injected, recursive) {
function runInContext(filename, injected, recursive, parentModule) {
if (recursive !== false)
Module.wrapper[0] += 'require = require("mattisg.requirewith");'; // this is why the module has to be installed in order to work properly
Module.wrapper[0] += 'require = require("mattisg.requirewith")._withParent(module);'; // this is why the module has to be installed in order to work properly

@@ -37,3 +47,3 @@ for (var k in injected)

// Create loadedModule as it would be created by require()
var loadedModule = new Module(filename, module.parent);
var loadedModule = new Module(filename, parentModule);

@@ -40,0 +50,0 @@ loadedModule.load(loadedModule.id);

{
"name": "mattisg.requirewith",
"description": "Wrapper to require() modules with dependency injection.",
"version": "0.1.0",
"homepage": "https://github.com/MattiSG/requirewith",
"version": "0.1.1",
"author": "Matti Schneider <hi@mattischneider.fr> (http://mattischneider.fr)",

@@ -6,0 +7,0 @@ "contributors": [

@@ -23,2 +23,6 @@ var requireInContext = require('mattisg.requirewith'), // the module has to be installed in order to work properly

assert.strictEqual(requireInContext('./subfolder/recursive', {
halfPayload: HALF_PAYLOAD
}), PAYLOAD, "Recursively loaded modules paths are not evaluated against the correct module.");
console.log('All tests pass :)');
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc