11const fs = require ( 'fs' )
22const path = require ( 'path' )
33const os = require ( 'os' )
4+ const packageJson = require ( '../package.json' )
5+
6+ const version = packageJson . version
47
58const LINE = / (?: ^ | ^ ) \s * (?: e x p o r t \s + ) ? ( [ \w . - ] + ) (?: \s * = \s * ?| : \s + ?) ( \s * ' (?: \\ ' | [ ^ ' ] ) * ' | \s * " (?: \\ " | [ ^ " ] ) * " | \s * ` (?: \\ ` | [ ^ ` ] ) * ` | [ ^ # \r \n ] + ) ? \s * (?: # .* ) ? (?: $ | $ ) / mg
69
@@ -44,7 +47,11 @@ function parse (src) {
4447}
4548
4649function _log ( message ) {
47- console . log ( `[dotenv][DEBUG] ${ message } ` )
50+ console . log ( `[dotenv@${ version } ][INFO] ${ message } ` )
51+ }
52+
53+ function _debug ( message ) {
54+ console . log ( `[dotenv@${ version } ][DEBUG] ${ message } ` )
4855}
4956
5057function _resolveHome ( envPath ) {
@@ -71,6 +78,8 @@ function config (options) {
7178 // Specifying an encoding returns a string instead of a buffer
7279 const parsed = DotenvModule . parse ( fs . readFileSync ( dotenvPath , { encoding } ) )
7380
81+ _log ( 'Loading env from .env' )
82+
7483 Object . keys ( parsed ) . forEach ( function ( key ) {
7584 if ( ! Object . prototype . hasOwnProperty . call ( process . env , key ) ) {
7685 process . env [ key ] = parsed [ key ]
@@ -81,9 +90,9 @@ function config (options) {
8190
8291 if ( debug ) {
8392 if ( override === true ) {
84- _log ( `"${ key } " is already defined in \`process.env\` and WAS overwritten` )
93+ _debug ( `"${ key } " is already defined in \`process.env\` and WAS overwritten` )
8594 } else {
86- _log ( `"${ key } " is already defined in \`process.env\` and was NOT overwritten` )
95+ _debug ( `"${ key } " is already defined in \`process.env\` and was NOT overwritten` )
8796 }
8897 }
8998 }
@@ -92,7 +101,7 @@ function config (options) {
92101 return { parsed }
93102 } catch ( e ) {
94103 if ( debug ) {
95- _log ( `Failed to load ${ dotenvPath } ${ e . message } ` )
104+ _debug ( `Failed to load ${ dotenvPath } ${ e . message } ` )
96105 }
97106
98107 return { error : e }
0 commit comments