browserify-optional
Advanced tools
Comparing version 1.0.0 to 1.0.1
17
index.js
var astTransform = require('ast-transform'); | ||
var astTypes = require('ast-types'); | ||
var path = require('path'); | ||
var resolve = require('browser-resolve'); | ||
module.exports = astTransform(function (file) { | ||
if (path.extname(file) !== '.js') return; | ||
return function(ast, next) { | ||
@@ -15,6 +18,6 @@ astTypes.visit(ast, { | ||
return this.traverse(path); | ||
var module = node.arguments[0].value; | ||
var p = path; | ||
while (p = p.parent) { | ||
@@ -24,7 +27,7 @@ var parent = p.value; | ||
break; | ||
if (parent.type === 'TryStatement') { | ||
try { | ||
resolve.sync(module, { filename: file }); | ||
} catch (e) { | ||
} catch (e) { | ||
path.replace({ | ||
@@ -56,13 +59,13 @@ type: 'CallExpression', | ||
} | ||
break; | ||
} | ||
} | ||
return false; | ||
} | ||
}); | ||
next(null, ast); | ||
} | ||
}); |
{ | ||
"name": "browserify-optional", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A browserify transform that allows optional dependencies in try..catch blocks", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
13035
9
103