Skip to content

Commit

Permalink
add dotenv-expand support
Browse files Browse the repository at this point in the history
  • Loading branch information
jzimmek committed Dec 15, 2017
1 parent 5272858 commit a7c2067
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env
@@ -1 +1,2 @@
EXAMPLE_ENV_VAR="simple example"
EXAMPLE_ENV_VAR="simple example"
EXAMPLE_ENV_VAR_EXPAND=$EXAMPLE_ENV_VAR-expand
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,6 +28,7 @@
"babel-eslint": "^8.0.1",
"babel-preset-es2015": "^6.1.18",
"babel-register": "^6.2.0",
"mocha": "^4.0.1"
"mocha": "^4.0.1",
"dotenv-expand": "^4.0.1"
}
}
4 changes: 4 additions & 0 deletions src/index.js
Expand Up @@ -12,6 +12,10 @@ module.exports = function (options) {
if (path.get("object").matchesPattern("process.env")) {
if (!dotenv) {
dotenv = require('dotenv').config(state.opts);
var dotenvExpand;
try { dotenvExpand = require('dotenv-expand'); } catch(e) {}
if (dotenvExpand)
dotenvExpand(dotenv);
}
var key = path.toComputedKey();
if (t.isStringLiteral(key)) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/code-simple-env-variable/actual.js
Expand Up @@ -6,6 +6,7 @@
// A base class is defined using the new reserved 'class' keyword

const EXAMPLE_ENV_VAR = process.env.EXAMPLE_ENV_VAR;
const EXAMPLE_ENV_VAR_EXPAND = process.env.EXAMPLE_ENV_VAR_EXPAND;

class Polygon {
// ..and an (optional) custom class constructor. If one is
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/code-simple-env-variable/expected.js
Expand Up @@ -6,6 +6,7 @@
// A base class is defined using the new reserved 'class' keyword

const EXAMPLE_ENV_VAR = process && process.env && process.env.EXAMPLE_ENV_VAR || "simple example";
const EXAMPLE_ENV_VAR_EXPAND = process && process.env && process.env.EXAMPLE_ENV_VAR_EXPAND || "simple example-expand";

class Polygon {
// ..and an (optional) custom class constructor. If one is
Expand Down

0 comments on commit a7c2067

Please sign in to comment.