@@ -39,13 +39,13 @@ export const config = options => {
3939 environmentData = loadEnvironmentFile ( options . path , options . encoding , options . silent ) ;
4040
4141 let configData = Object . assign ( { } , defaultsData , environmentData ) ;
42+ const config = options . includeProcessEnv ? Object . assign ( { } , configData , process . env ) : configData ;
43+ const configOnlyKeys = Object . keys ( configData ) ;
44+ const configKeys = Object . keys ( config ) ;
4245
4346 if ( options . errorOnMissing || options . errorOnExtra || options . errorOnRegex ) {
4447 const schema = loadEnvironmentFile ( options . schema , options . encoding , options . silent ) ;
45- const config = options . includeProcessEnv ? Object . assign ( { } , configData , process . env ) : configData ;
4648 const schemaKeys = Object . keys ( schema ) ;
47- const configOnlyKeys = Object . keys ( configData ) ;
48- const configKeys = Object . keys ( config ) ;
4949
5050 let missingKeys = schemaKeys . filter ( function ( key ) {
5151 return configKeys . indexOf ( key ) < 0 ;
@@ -74,6 +74,14 @@ export const config = options => {
7474 }
7575 }
7676
77+ // the returned configData object should include process.env that override
78+ if ( options . includeProcessEnv && ! options . overrideProcessEnv ) {
79+ for ( let i = 0 ; i < configKeys . length ; i ++ ) {
80+ if ( typeof process . env [ configKeys [ i ] ] !== 'undefined' )
81+ configData [ configKeys [ i ] ] = process . env [ configKeys [ i ] ] ;
82+ }
83+ }
84+
7785 if ( options . assignToProcessEnv ) {
7886 if ( options . overrideProcessEnv ) {
7987 Object . assign ( process . env , configData ) ;
0 commit comments