Skip to content

Commit 3ab1b26

Browse files
committed
fix dotenv priority
1 parent ea11fd9 commit 3ab1b26

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

__tests__/__fixtures__/local-env/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
API_KEY=never
2+
DEV_USERNAME=default
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
API_KEY=local-key
2-
DEV_USERNAME=username123456
1+
API_KEY=username123456
2+
DEV_USERNAME=local-key
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
API_KEY=abc123456
1+
API_KEY=username123456

__tests__/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('react-native-dotenv', () => {
5858

5959
it('should load local env files', () => {
6060
const {code} = transformFileSync(FIXTURES + 'local-env/source.js')
61-
expect(code).toBe('console.log("local-key");\nconsole.log("username123456");')
61+
expect(code).toBe('console.log("username123456");\nconsole.log("local-key");')
6262
})
6363

6464
it('should support `as alias` import syntax', () => {

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ module.exports = ({types: t}) => ({
3737
const babelMode = process.env.APP_ENV || (process.env.BABEL_ENV && process.env.BABEL_ENV !== 'undefined' && process.env.BABEL_ENV) || process.env.NODE_ENV || 'development'
3838
if (this.opts.safe) {
3939
const parsed = parseDotenvFile(this.opts.path, this.opts.verbose)
40-
const modeParsed = parseDotenvFile(this.opts.path + '.' + babelMode)
4140
const localParsed = parseDotenvFile(this.opts.path + '.local')
41+
const modeParsed = parseDotenvFile(this.opts.path + '.' + babelMode)
4242
this.env = Object.assign(Object.assign(parsed, modeParsed), localParsed)
4343
} else {
4444
dotenv.config({
45-
path: this.opts.path + '.local',
45+
path: this.opts.path + '.' + babelMode,
4646
silent: true
4747
})
4848
dotenv.config({
49-
path: this.opts.path + '.' + babelMode,
49+
path: this.opts.path + '.local',
5050
silent: true
5151
})
5252
dotenv.config({

0 commit comments

Comments
 (0)