module-definition
Advanced tools
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); | ||
}); | ||
}; |
{ | ||
"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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1963
39
+ Addednode-source-walk@^1.0.0
+ Addedacorn@1.2.2(transitive)
+ Addednode-source-walk@1.4.2(transitive)
- Removedesprima@^1.0.4
- Removedesprima@1.2.5(transitive)