Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

envify

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envify - npm Package Compare versions

Comparing version 3.4.1 to 4.0.0

63

custom.js

@@ -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)

6

package.json
{
"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": [

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