node-env-file
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -62,5 +62,4 @@ 'use strict' | ||
try { | ||
// lines = fs.readFileSync(env_file, 'utf8').match(/((?:\s*\#\s*)?.*[\w+]+)\s*\=(\n|.*)/gmi) || [] | ||
lines = (fs.readFileSync(env_file, 'utf8') || '') | ||
.split("\n") | ||
.split(/\r?\n|\r/) | ||
.filter(function (line) { | ||
@@ -67,0 +66,0 @@ return /\s*=\s*/i.test(line) |
{ | ||
"name": "node-env-file", | ||
"description": "Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.", | ||
"keywords": ["process", "env", "file", "files", ".env", "ENV", "process.env", "parse", "load", "export", "exports"], | ||
"version": "0.1.6", | ||
"keywords": [ | ||
"process", | ||
"env", | ||
"file", | ||
"files", | ||
".env", | ||
"ENV", | ||
"process.env", | ||
"parse", | ||
"load", | ||
"export", | ||
"exports" | ||
], | ||
"version": "0.1.7", | ||
"homepage": "https://github.com/grimen/node-env-file", | ||
@@ -38,3 +50,5 @@ "repository": { | ||
"dependencies": { | ||
"chai": "latest" | ||
"chai": "latest", | ||
"glob": "^4.3.5", | ||
"temp": "^0.8.1" | ||
}, | ||
@@ -41,0 +55,0 @@ "devDependencies": { |
@@ -70,3 +70,3 @@ # NODE-ENV-FILE [![Build Status](https://secure.travis-ci.org/grimen/node-env-file.png)](http://travis-ci.org/grimen/node-env-file) | ||
```javascript | ||
env('./path/to/.env', {verbose: true, overwrite: true}); | ||
env('./path/to/.env', {verbose: true, overwrite: true, raise: false, logger: console}); | ||
``` | ||
@@ -105,32 +105,2 @@ | ||
## Notes | ||
### Bash based approach: | ||
**`Makefile`** | ||
```bash | ||
define LOAD_ENV | ||
ENV_FILE=$${2:-'.env'} | ||
echo "LOAD: $$ENV_FILE" | ||
if [ -f $$ENV_FILE ]; then | ||
while read line || [ -n "$$line" ]; do | ||
if [[ "$$line" == *=* ]] && [[ "$$line" != #* ]]; then | ||
# TODO: handle exports case | ||
echo " export $$line" | ||
eval "export $$line" | ||
fi | ||
done < "$$ENV_FILE" | ||
fi | ||
endef | ||
export LOAD_ENV | ||
env: | ||
eval "$$LOAD_ENV" | ||
... | ||
``` | ||
## License | ||
@@ -137,0 +107,0 @@ |
@@ -8,4 +8,48 @@ 'use strict' | ||
var temp = require('temp') | ||
var path = require('path') | ||
var fs = require('fs') | ||
var glob = require('glob') | ||
var env = require('../') | ||
var defaultTestPath = path.join(__dirname, 'fixtures') | ||
var windowsCRTestPath = temp.mkdirSync('node-env-file.windows-cr') | ||
function _fixture(filename, type) { | ||
var _fixturesPath; | ||
var types = ['windows-cr', 'default'] | ||
if (!type) { | ||
type = types[Math.floor(Math.random() * types.length)] | ||
} | ||
switch (type) { | ||
case 'windows-cr': | ||
_fixturesPath = windowsCRTestPath | ||
break | ||
default: | ||
_fixturesPath = defaultTestPath | ||
} | ||
return path.join(_fixturesPath, filename) | ||
} | ||
function _prepareFixtures() { | ||
// Prepare: Windows CR/newline tests | ||
glob.sync(path.join(defaultTestPath, '*'), {dot: true}) | ||
.forEach(function(fixtureFile) { | ||
var tmpEnvFile = path.join(windowsCRTestPath, path.basename(fixtureFile)) | ||
var fixtureData = fs.readFileSync(fixtureFile, 'utf-8') | ||
var fixtureDataWithCR = fixtureData.replace(/\n/gmi, "\r\n") | ||
console.log(tmpEnvFile) | ||
// console.log(tmpEnvFile, fixtureDataWithCR) | ||
fs.writeFileSync(tmpEnvFile, fixtureDataWithCR, 'utf-8') | ||
}) | ||
} | ||
// temp.track() | ||
// ----------------------- | ||
@@ -18,2 +62,4 @@ // Test | ||
before: function() { | ||
_prepareFixtures() | ||
expect(env).to.be.a('function') | ||
@@ -37,3 +83,3 @@ }, | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.100', {raise: false}) | ||
env(_fixture('.env.100'), {raise: false}) | ||
}).to.not.throw(Error) | ||
@@ -47,3 +93,3 @@ }, | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.100') | ||
env(_fixture('.env.100')) | ||
}).to.throw(Error) | ||
@@ -60,3 +106,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.100', {}) | ||
env(_fixture('.env.100'), {}) | ||
}).to.throw(Error) | ||
@@ -73,3 +119,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.100', {overwrite: true}) | ||
env(_fixture('.env.100'), {overwrite: true}) | ||
}).to.throw(Error) | ||
@@ -84,3 +130,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.100', {raise: false}) | ||
env(_fixture('.env.100'), {raise: false}) | ||
}).to.not.throw(Error) | ||
@@ -93,3 +139,3 @@ } | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.0') | ||
env(_fixture('.env.0')) | ||
}).to.not.throw(Error) | ||
@@ -106,3 +152,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.0', {}) | ||
env(_fixture('.env.0'), {}) | ||
}).to.not.throw(Error) | ||
@@ -119,3 +165,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.0', {overwrite: true}) | ||
env(_fixture('.env.0'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -132,3 +178,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.1') | ||
env(_fixture('.env.1')) | ||
}).to.not.throw(Error) | ||
@@ -145,3 +191,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.1', {}) | ||
env(_fixture('.env.1'), {}) | ||
}).to.not.throw(Error) | ||
@@ -158,3 +204,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.1', {overwrite: true}) | ||
env(_fixture('.env.1'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -171,3 +217,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.2') | ||
env(_fixture('.env.2')) | ||
}).to.not.throw(Error) | ||
@@ -184,3 +230,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.2', {}) | ||
env(_fixture('.env.2'), {}) | ||
}).to.not.throw(Error) | ||
@@ -197,3 +243,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.2', {overwrite: true}) | ||
env(_fixture('.env.2'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -210,3 +256,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.3') | ||
env(_fixture('.env.3')) | ||
}).to.not.throw(Error) | ||
@@ -223,3 +269,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.4') | ||
env(_fixture('.env.4')) | ||
}).to.not.throw(Error) | ||
@@ -237,3 +283,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.5') | ||
env(_fixture('.env.5')) | ||
}).to.not.throw(Error) | ||
@@ -251,3 +297,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.0') | ||
env(_fixture('.env.exports.0')) | ||
}).to.not.throw(Error) | ||
@@ -264,3 +310,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.0', {}) | ||
env(_fixture('.env.exports.0'), {}) | ||
}).to.not.throw(Error) | ||
@@ -277,3 +323,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.0', {overwrite: true}) | ||
env(_fixture('.env.exports.0'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -290,3 +336,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.1') | ||
env(_fixture('.env.exports.1')) | ||
}).to.not.throw(Error) | ||
@@ -303,3 +349,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.1', {}) | ||
env(_fixture('.env.exports.1'), {}) | ||
}).to.not.throw(Error) | ||
@@ -316,3 +362,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.1', {overwrite: true}) | ||
env(_fixture('.env.exports.1'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -329,3 +375,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.2') | ||
env(_fixture('.env.exports.2')) | ||
}).to.not.throw(Error) | ||
@@ -342,3 +388,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.2', {}) | ||
env(_fixture('.env.exports.2'), {}) | ||
}).to.not.throw(Error) | ||
@@ -355,3 +401,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.2', {overwrite: true}) | ||
env(_fixture('.env.exports.2'), {overwrite: true}) | ||
}).to.not.throw(Error) | ||
@@ -368,3 +414,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.3') | ||
env(_fixture('.env.exports.3')) | ||
}).to.not.throw(Error) | ||
@@ -381,3 +427,3 @@ | ||
expect(function() { | ||
env(__dirname + '/fixtures/.env.exports.4') | ||
env(_fixture('.env.exports.4')) | ||
}).to.not.throw(Error) | ||
@@ -384,0 +430,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27329
473
0
3
111
169
+ Addedglob@^4.3.5
+ Addedtemp@^0.8.1
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@4.5.37.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@2.0.103.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.6.3(transitive)
+ Addedtemp@0.8.4(transitive)
+ Addedwrappy@1.0.2(transitive)