Comparing version 3.4.1 to 4.0.0
@@ -1,4 +0,3 @@ | ||
var through = require('through') | ||
, jstransform = require('jstransform') | ||
, createVisitors = require('./visitors') | ||
var esprima = require('esprima') | ||
, through = require('through') | ||
@@ -13,2 +12,3 @@ var processEnvPattern = /\bprocess\.env\b/ | ||
var Syntax = esprima.Syntax | ||
var buffer = [] | ||
@@ -23,2 +23,56 @@ argv = argv || {} | ||
function transform(source, envs) { | ||
var args = [].concat(envs[0]._ || []).concat(envs[1]._ || []) | ||
var purge = args.indexOf('purge') !== -1 | ||
var replacements = [] | ||
function match(node) { | ||
return ( | ||
node.type === Syntax.MemberExpression | ||
&& node.object.type === Syntax.MemberExpression | ||
&& node.object.computed === false | ||
&& node.object.object.type === Syntax.Identifier | ||
&& node.object.object.name === 'process' | ||
&& node.object.property.type === Syntax.Identifier | ||
&& node.object.property.name === 'env' | ||
&& (node.computed ? node.property.type === Syntax.Literal : node.property.type === Syntax.Identifier) | ||
) | ||
} | ||
esprima.parse(source, { tolerant: true }, function(node, meta) { | ||
if (match(node)) { | ||
var key = node.property.name || node.property.value | ||
for (var i = 0; i < envs.length; i++) { | ||
var value = envs[i][key] | ||
if (value !== undefined) { | ||
replacements.push({ node: node, meta: meta, value: JSON.stringify(value) }) | ||
return | ||
} | ||
} | ||
if (purge) { | ||
replacements.push({ node: node, meta: meta, value: undefined }) | ||
} | ||
} else if (node.type === Syntax.AssignmentExpression) { | ||
for (var i = 0; i < replacements.length; ++i) { | ||
if (replacements[i].node === node.left) { | ||
replacements.splice(i, 1) | ||
} | ||
} | ||
} | ||
}) | ||
var result = source | ||
if (replacements.length > 0) { | ||
replacements.sort(function (a, b) { | ||
return b.meta.start.offset - a.meta.start.offset | ||
}) | ||
for (var i = 0; i < replacements.length; i++) { | ||
var r = replacements[i] | ||
result = result.slice(0, r.meta.start.offset) + r.value + result.slice(r.meta.end.offset) | ||
} | ||
} | ||
return result | ||
} | ||
function flush() { | ||
@@ -29,4 +83,3 @@ var source = buffer.join('') | ||
try { | ||
var visitors = createVisitors([argv, rootEnv]) | ||
source = jstransform.transform(visitors, source).code | ||
source = transform(source, [argv, rootEnv]) | ||
} catch(err) { | ||
@@ -33,0 +86,0 @@ return this.emit('error', err) |
{ | ||
"name": "envify", | ||
"version": "3.4.1", | ||
"version": "4.0.0", | ||
"description": "Selectively replace Node-style environment variables with plain strings.", | ||
@@ -23,4 +23,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"through": "~2.3.4", | ||
"jstransform": "^11.0.3" | ||
"esprima": "~3.1.0", | ||
"through": "~2.3.4" | ||
}, | ||
@@ -27,0 +27,0 @@ "keywords": [ |
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
7773
78
6
+ Addedesprima@~3.1.0
- Removedjstransform@^11.0.3
- Removedacorn@5.7.4(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedast-types@0.9.6(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase62@1.2.8(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcommoner@0.10.8(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddetective@4.7.1(transitive)
- Removedesprima-fb@15001.1.0-dev-harmony-fb(transitive)
- Removedglob@5.0.15(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjstransform@11.0.3(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedobject-assign@2.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprivate@0.1.8(transitive)
- Removedq@1.5.1(transitive)
- Removedrecast@0.11.23(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsource-map@0.4.40.5.7(transitive)
- Removedwrappy@1.0.2(transitive)