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

r42

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

r42 - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

14

lib/index.js

@@ -30,3 +30,5 @@ 'use strict';

async.map(deps, mc.getModule.bind(mc), callback);
async.map(deps, function (val, done) {
mc.getModule(optName, val, done);
}, callback);
}

@@ -81,2 +83,12 @@

},
dumpDeps: function () {
_.each(mc.$modules, function (mod, name) {
console.log(name + ' is required by:', _.map(mod.dependent, function (val) {
if (val === null) {
return '__r42.inject';
}
return val;
}));
});
}
};

25

lib/moduleContext.js

@@ -24,2 +24,4 @@ 'use strict';

_.bindAll(this);
this.$modules = {};

@@ -36,3 +38,6 @@ this.$baseDir = config.baseDir;

}
this.$modules[resolvedName] = null;
this.$modules[resolvedName] = {
dependent: [],
content: {},
};
moduleFn(function (err, module) {

@@ -42,9 +47,16 @@ if (err) {

}
callback(null, this.$modules[resolvedName] = module);
if (module.constructor.name === 'Object') {
_.extend(this.$modules[resolvedName].content, module);
}
else {
this.$modules[resolvedName] = module;
}
callback(null, this.$modules[resolvedName].content);
}.bind(this));
};
ModuleContext.prototype.getModule = function (name, callback) {
ModuleContext.prototype.getModule = function (callee, name, callback) {
name = this.$mm.resolve(name);
if (name in this.$modules) {
return callback(null, this.$modules[name]);
this.$modules[name].dependent.push(callee);
return callback(null, this.$modules[name].content);
}

@@ -64,3 +76,4 @@

this.$define, function (err) {
callback(err, this.$modules[name]);
this.$modules[name].dependent.push(callee);
callback(err, this.$modules[name].content);
}.bind(this)

@@ -82,3 +95,3 @@ ),

define.apply(null, arguments);
}
}.bind(this)
}, function (err) {

@@ -85,0 +98,0 @@ if (err) {

@@ -5,3 +5,2 @@ 'use strict';

var fs = require('fs');
var vm = require('vm');
var path = require('path');

@@ -11,41 +10,10 @@

run.runString = function runString(filename, fileContent, ext, callback) {
function myRequire(dep) {
if (dep[0] === '.') {
dep = path.resolve(path.dirname(filename), dep);
}
return require(dep);
}
run.runFile = function runFile(filename, ext, callback) {
try {
vm.runInNewContext(
fileContent,
_.extend(
{},
global,
{
__dirname: path.dirname(filename),
require: myRequire,
},
ext
),
filename
);
_.extend(global, ext);
require(filename);
callback(null);
} catch (e) {
if (e.constructor.name === 'SyntaxError' || e.constructor.name === 'ReferenceError') {
e.message += '\n at Object.<anonymous> (' + filename + ':?:?)';
}
callback(new e.constructor(e.message));
callback(e);
}
}
run.runFile = function runFile(filename, ext, callback) {
fs.readFile(filename, function (err, fileContent) {
if (err) {
return callback(new Error('Error reading file ' + filename));
}
run.runString(filename, fileContent.toString('utf8'), ext, callback);
});
};
{
"name": "r42",
"version": "0.0.9",
"version": "0.0.10",
"description": "Dependency injection done right.",

@@ -25,3 +25,3 @@ "author": "Quentin Raynaud <npm@qraynaud.eu>",

"dependencies": {
"lodash": "~2.2.1",
"lodash": "~2.3.0",
"async": "~0.2.9"

@@ -28,0 +28,0 @@ },

@@ -100,1 +100,61 @@ ## r42

```
##### Circular dependencies
Those are working "automatically" but you NEED to exports barebone objects on both modules
for it to work.
Here is an example:
In a module 'a.js'
```js
define(function (b) {
// here b might be empty if it was loaded before a, so don't use it
return {
aFn: function () {
// here b should be fully usable
b.bFn();
},
};
});
```
In a module 'b.js'
```js
define(function (a) {
// here a might be empty if it was loaded before b, so don't use it
return {
bFn: function () {
// here a should be fully usable
a.bFn();
},
};
});
```
#### Special APIs
##### Printing dependencies
Right now, even if the output is rather horrible, it might give some useful information so here is how to use it:
**BEWARE:** This really can go away in between versions right now, maybe replaced by something achieving
the same purpose but better designed. Don't use this for other purposes than debugging.
This function does not print modules handled by NPM right now.
```js
var r42 = require('r42');
r42.config({
// Your config HERE
});
// Let's get started
r42.inject(function (/* Your dependencies */) {
// Dump dependencies using console.log
r42.dumpDeps();
});
```
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