Skip to content

Commit 82a1f0e

Browse files
authored
environment variable precedence and behavior (#58, reverts #55)
1 parent 8f37e8a commit 82a1f0e

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,19 @@ To this:
6565
}
6666
```
6767

68-
_The `betterScripts` script definition can either be a string or sub-object with `command` and `env` attributes._
68+
_The `betterScripts` script definition can either be a string or sub-object with `command` and `env` attributes. Values defined in the `env` block will override previously set environment variables._
6969

7070
# .env File
7171

72-
If you have an `.env` file in your project root it will be loaded on every command
72+
If you have an `.env` file in your project root it will be loaded on every command.
7373

7474
```
7575
NODE_PATH=./:./lib
7676
NODE_ENV=development
7777
PORT=5000
7878
```
7979

80-
Environment variables will be merged in the following order:
81-
* `package.json` options
82-
* `.env` file content
83-
* parent `process.env` values
84-
85-
Whoever comes last, will set the actual value.
80+
_Environment variables defined in the `betterScripts` script definition will take precedence over `.env` values._
8681

8782
# Shell scripts
8883

lib/exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function exec(script) {
1010

1111
script.env = script.env || {};
1212

13-
var env = objectAssign({}, script.env, process.env);
13+
var env = objectAssign({}, process.env, script.env);
1414

1515
var sh = 'sh', shFlag = '-c';
1616
if (process.platform === 'win32') {

test/env-extend.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ if (process.env.FOO !== 'bar') {
22
throw new Error("env variable is not provided");
33
}
44

5-
if (process.env.TEST_ENV !== "TEST_VALUE") {
6-
throw new Error(".env file variable is overridden");
7-
}
8-
9-
if(process.env.TEST_ENV2 !== "envvar") {
5+
if (process.env.TEST_ENV !== "overridden" || process.env.TEST_ENV2 !== "envvar") {
106
throw new Error("environment variable is overridden");
117
}

0 commit comments

Comments
 (0)