Socket
Socket
Sign inDemoInstall

module-definition

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-definition - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

50

index.js

@@ -1,34 +0,4 @@

var esprima = require('esprima'),
var Walker = require('node-source-walk'),
fs = require('fs');
// From node-detective
function traverse(node, cb) {
if (Array.isArray(node)) {
node.forEach(function (x) {
if(x != null) {
// Mark that the node has been visited
x.parent = node;
traverse(x, cb);
}
});
} else if (node && typeof node === 'object') {
cb(node);
Object.keys(node).forEach(function (key) {
// Avoid visited nodes
if (key === 'parent' || ! node[key]) return;
node[key].parent = node;
traverse(node[key], cb);
});
}
}
// Executes the passed callback for every traversed node of the ast
function walk(src, cb) {
var ast = esprima.parse(src);
traverse(ast, cb);
}
function isExports(node) {

@@ -53,2 +23,4 @@ var c = node.object;

var walker = new Walker();
// Read file

@@ -62,22 +34,18 @@ fs.readFile(file, function (err, data) {

var src = data.toString(),
type = 'none',
alreadyDeduced = false;
type = 'none';
// Note: this is blocking
walk(src, function (node) {
if (alreadyDeduced) return;
// TODO: Figure out how to modify walk such that we can
// stop walking once we've deduced the module type
walker.walk(src, function (node) {
if (isExports(node)) {
type = 'commonjs';
alreadyDeduced = true;
walker.stopWalking();
} else if (isDefine(node)) {
type = 'amd';
alreadyDeduced = true;
walker.stopWalking();
}
});
cb(type);
cb && cb(type);
});
};

4

package.json
{
"name": "module-definition",
"version": "1.0.1",
"version": "1.0.2",
"description": "Determines if a file is using a CommonJS or AMD module definition",

@@ -17,4 +17,4 @@ "main": "index.js",

"dependencies": {
"esprima": "^1.0.4"
"node-source-walk": "^1.0.0"
}
}
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