From 3c89132158d3431c9b3617aff5cd4d5d3483d7d5 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Tue, 18 Oct 2016 10:09:25 -0700 Subject: [PATCH 1/4] suppress error messages by default --- .travis.yml | 1 - README.md | 7 +++---- lib/main.js | 12 ++++++------ package.json | 13 +++++++------ test/config.js | 4 ++-- test/main.js | 12 ++++++------ 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad2bcb83..d474408d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,4 @@ node_js: - 0.10 - 0.12 - 4 - - 5 - 6 diff --git a/README.md b/README.md index 23ba004e..9c04f8a1 100644 --- a/README.md +++ b/README.md @@ -71,15 +71,14 @@ _Alias: `load`_ ### Options -#### Silent +#### Verbose Default: `false` -Dotenv outputs a warning to your console if missing a `.env` file. Suppress -this warning using silent. +All errors are suppressed by default. Set this to `true` for more logging. ```js -require('dotenv').config({silent: true}) +require('dotenv').config({verbose: true}) ``` #### Path diff --git a/lib/main.js b/lib/main.js index bd50bde7..163ddd75 100644 --- a/lib/main.js +++ b/lib/main.js @@ -11,11 +11,11 @@ module.exports = { config: function (options) { var path = '.env' var encoding = 'utf8' - var silent = false + var verbose = false if (options) { - if (options.silent) { - silent = options.silent + if (options.verbose) { + verbose = options.verbose } if (options.path) { path = options.path @@ -35,8 +35,8 @@ module.exports = { return parsedObj } catch (e) { - if (!silent) { - console.error(e) + if (verbose) { + console.error('dotenv failed to parse and/or populate:' + e.message) } return false } @@ -63,7 +63,7 @@ module.exports = { // expand newlines in quoted values var len = value ? value.length : 0 - if (len > 0 && value.charAt(0) === '\"' && value.charAt(len - 1) === '\"') { + if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') { value = value.replace(/\\n/gm, '\n') } diff --git a/package.json b/package.json index 3f319121..022e1f1f 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Loads environment variables from .env file", "main": "lib/main.js", "scripts": { + "pretest": "npm run lint", "test": "lab test/* -r lcov | coveralls", - "posttest": "npm run lint", - "postlint": "npm run lint-md", "lint": "standard", + "postlint": "npm run lint-md", "lint-md": "standard-markdown" }, "repository": { @@ -29,12 +29,13 @@ "devDependencies": { "babel": "5.8.23", "coveralls": "^2.11.9", + "eslint": "3.7.1", "lab": "5.17.0", - "semver": "5.0.3", + "semver": "5.3.0", "should": "7.1.0", - "sinon": "1.16.1", - "standard": "5.3.0", - "standard-markdown": "^1.1.1" + "sinon": "1.17.6", + "standard": "8.4.0", + "standard-markdown": "2.2.0" }, "dependencies": {} } diff --git a/test/config.js b/test/config.js index 1f96300b..609b5a22 100644 --- a/test/config.js +++ b/test/config.js @@ -1,7 +1,7 @@ 'use strict' require('should') -var child_process = require('child_process') +var cp = require('child_process') var semver = require('semver') // var sinon = require('sinon') var Lab = require('lab') @@ -21,7 +21,7 @@ describe('config', function () { return done() } - child_process.exec( + cp.exec( nodeBinary + ' -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env', function (err, stdout, stderr) { if (err) { diff --git a/test/main.js b/test/main.js index 225a65bf..5209bdf4 100644 --- a/test/main.js +++ b/test/main.js @@ -79,16 +79,16 @@ describe('dotenv', function () { readFileSyncStub.throws() dotenv.config().should.eql(false) - errorStub.callCount.should.eql(1) + errorStub.called.should.be.false // because verbose is off done() }) - it('takes option for silencing errors', function (done) { + it('takes option for exposing errors', function (done) { var errorStub = s.stub(console, 'error') readFileSyncStub.throws() - dotenv.config({silent: true}).should.eql(false) - errorStub.called.should.be.false + dotenv.config({verbose: true}).should.eql(false) + errorStub.callCount.should.eql(1) done() }) }) @@ -157,8 +157,8 @@ describe('dotenv', function () { }) it('retains inner quotes', function (done) { - parsed.RETAIN_INNER_QUOTES.should.eql('{\"foo\": \"bar\"}') - parsed.RETAIN_INNER_QUOTES_AS_STRING.should.eql('{\"foo\": \"bar\"}') + parsed.RETAIN_INNER_QUOTES.should.eql('{"foo": "bar"}') + parsed.RETAIN_INNER_QUOTES_AS_STRING.should.eql('{"foo": "bar"}') done() }) From b84ed6170ac3531ebe576ba0db9dcd57c93dfe32 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Tue, 18 Oct 2016 10:20:51 -0700 Subject: [PATCH 2/4] downgrade to keep supporting older versions of node --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 022e1f1f..df002b66 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,11 @@ "devDependencies": { "babel": "5.8.23", "coveralls": "^2.11.9", - "eslint": "3.7.1", "lab": "5.17.0", "semver": "5.3.0", "should": "7.1.0", "sinon": "1.17.6", - "standard": "8.4.0", + "standard": "5.3.0", "standard-markdown": "2.2.0" }, "dependencies": {} From c40b5d79a39c41b85326c4157d87a468ea74888d Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Tue, 18 Oct 2016 10:30:15 -0700 Subject: [PATCH 3/4] drop support for older versions of node --- .travis.yml | 3 +-- package.json | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index d474408d..c7b60640 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: node_js node_js: - - 0.10 - - 0.12 - 4 - 6 + - 7 diff --git a/package.json b/package.json index df002b66..c7003f1a 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,15 @@ "devDependencies": { "babel": "5.8.23", "coveralls": "^2.11.9", - "lab": "5.17.0", + "lab": "11.1.0", "semver": "5.3.0", - "should": "7.1.0", + "should": "11.1.1", "sinon": "1.17.6", - "standard": "5.3.0", + "standard": "8.4.0", "standard-markdown": "2.2.0" }, - "dependencies": {} + "dependencies": {}, + "engines": { + "node": ">=4.6.0" + } } From 3485a237444a36097e9c1a79de374579bd3a3084 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Tue, 18 Oct 2016 10:33:35 -0700 Subject: [PATCH 4/4] no 7 yet --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c7b60640..02f04604 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,3 @@ language: node_js node_js: - 4 - 6 - - 7