Skip to content

Commit

Permalink
fix: use the exact same default params for dotenv parse; to ensure us…
Browse files Browse the repository at this point in the history
…ing dotenv.parse instead of dotenv.cofig introduces no breaking change
  • Loading branch information
Platane committed Mar 24, 2019
1 parent 615444b commit b0b3bda
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var fs = require('fs');
var pathResolve = require('path').resolve;

var dotenvContent;

Expand Down Expand Up @@ -33,8 +34,19 @@ module.exports = function (options) {
if(t.isAssignmentExpression(path.parent) && path.parent.left == path.node) return;
if (path.get("object").matchesPattern("process.env")) {
if (!dotenvContent) {
var envFilePath = state.opts.path || './.env'
dotenvContent = require('dotenv').parse(fs.readFileSync(envFilePath));
var dotenvPath = pathResolve(process.cwd(), '.env')
var encoding = 'utf8'
var debug = false
if (state.opts.path != null) {
dotenvPath = state.opts.path
}
if (state.opts.encoding != null) {
encoding = state.opts.encoding
}
if (state.opts.debug != null) {
debug = true
}
dotenvContent = require('dotenv').parse(fs.readFileSync(dotenvPath, {encoding:encoding}), {debug:debug});
var dotenvExpand;
try { dotenvExpand = require('dotenv-expand'); } catch(e) {}
if (dotenvExpand)
Expand Down

0 comments on commit b0b3bda

Please sign in to comment.