Comparing version 0.2.0 to 1.0.0
var through = require('through') | ||
, falafel = require('falafel') | ||
, recast = require('recast') | ||
, n = recast.types.namedTypes | ||
, b = recast.types.builders | ||
, traverse = recast.types.traverse | ||
, processEnvPattern = /\bprocess\.env\b/ | ||
module.exports = function(env) { | ||
env = env || process.env || {} | ||
return envify | ||
function envify(file) { | ||
if (/\.json$/.test(file)) return through(); | ||
return function envify(file) { | ||
if (/\.json$/.test(file)) return through() | ||
var buffer = '' | ||
var buffer = [] | ||
return through(function(data) { | ||
buffer += data | ||
buffer.push(data) | ||
}, function processFile() { | ||
var output = falafel(buffer, function(node) { | ||
if (!( | ||
node.type === 'Identifier' && | ||
node.name === 'process' && | ||
node.parent && | ||
node.parent.property && | ||
node.parent.property.type === 'Identifier' && | ||
node.parent.property.name === 'env' && | ||
node.parent.parent && | ||
node.parent.parent.property && | ||
( node.parent.parent.property.name || | ||
node.parent.parent.property.value ) && | ||
(!node.parent.parent.parent | ||
? true | ||
:!( | ||
node.parent.parent.parent.type === 'AssignmentExpression' && | ||
node.parent.parent.parent.left.type === 'MemberExpression' && | ||
node.parent.parent.parent.left.object.object && | ||
node.parent.parent.parent.left.object.object.name === 'process' | ||
)))) return | ||
var source = buffer.join('') | ||
var key = node.parent.parent.property.name || | ||
node.parent.parent.property.value | ||
if (processEnvPattern.test(source)) { | ||
var ast = recast.parse(source) | ||
if (!(key in env)) return | ||
traverse(ast, function(node) { | ||
if ( | ||
n.MemberExpression.check(node) | ||
&& !node.computed | ||
&& n.Identifier.check(node.property) | ||
&& n.MemberExpression.check(node.object) | ||
&& n.Identifier.check(node.object.object) | ||
&& node.object.object.name === 'process' | ||
&& n.Identifier.check(node.object.property) | ||
&& node.object.property.name === 'env' | ||
) { | ||
var key = node.property.name | ||
if (key in env) { | ||
this.replace(b.literal(env[key])) | ||
return false | ||
} | ||
} | ||
}); | ||
node.parent.parent.update( | ||
env[key] ? JSON.stringify(env[key]) : | ||
env[key] === false ? 'false' : | ||
env[key] === null ? 'null' : | ||
env[key] === '' ? '""' : | ||
env[key] === 0 ? '0' : | ||
'undefined' | ||
) | ||
}) | ||
source = recast.print(ast).code | ||
} | ||
this.queue(String(output)) | ||
this.queue(source) | ||
this.queue(null) | ||
@@ -54,0 +48,0 @@ }) |
{ | ||
"name": "envify", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Selectively replace Node-style environment variables with plain strings.", | ||
@@ -19,7 +19,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tape": "~0.3.3" | ||
"tape": "~2.3.2" | ||
}, | ||
"dependencies": { | ||
"through": "~2.3.4", | ||
"falafel": "~0.2.1" | ||
"recast": "~0.5.6" | ||
}, | ||
@@ -26,0 +26,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
# envify # | ||
# envify [![Build Status](https://secure.travis-ci.org/hughsk/envify.png?branch=master)](http://travis-ci.org/hughsk/envify) [![stable](http://hughsk.github.io/stability-badges/dist/stable.svg)](http://github.com/hughsk/stability-badges) # | ||
@@ -79,3 +79,3 @@ Selectively replace Node-style environment variables with plain strings. | ||
var bundle = browserify('main.js') | ||
var b = browserify('main.js') | ||
, output = fs.createWriteStream('bundle.js') | ||
@@ -82,0 +82,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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7
1
6668
116
+ Addedrecast@~0.5.6
+ Addedamdefine@1.0.1(transitive)
+ Addedast-types@0.3.38(transitive)
+ Addedcls@0.1.5(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedrecast@0.5.27(transitive)
+ Addedsource-map@0.1.32(transitive)
- Removedfalafel@~0.2.1
- Removedfalafel@0.2.1(transitive)