diff --git a/lib/main.js b/lib/main.js index 87fedd4c..f36d0e63 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,6 +1,9 @@ const fs = require('fs') const path = require('path') const os = require('os') +const packageJson = require('../package.json') + +const version = packageJson.version const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg @@ -44,7 +47,11 @@ function parse (src) { } function _log (message) { - console.log(`[dotenv][DEBUG] ${message}`) + console.log(`[dotenv@${version}][INFO] ${message}`) +} + +function _debug (message) { + console.log(`[dotenv@${version}][DEBUG] ${message}`) } function _resolveHome (envPath) { @@ -71,6 +78,8 @@ function config (options) { // Specifying an encoding returns a string instead of a buffer const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding })) + _log('Loading env from .env') + Object.keys(parsed).forEach(function (key) { if (!Object.prototype.hasOwnProperty.call(process.env, key)) { process.env[key] = parsed[key] @@ -81,9 +90,9 @@ function config (options) { if (debug) { if (override === true) { - _log(`"${key}" is already defined in \`process.env\` and WAS overwritten`) + _debug(`"${key}" is already defined in \`process.env\` and WAS overwritten`) } else { - _log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`) + _debug(`"${key}" is already defined in \`process.env\` and was NOT overwritten`) } } } @@ -92,7 +101,7 @@ function config (options) { return { parsed } } catch (e) { if (debug) { - _log(`Failed to load ${dotenvPath} ${e.message}`) + _debug(`Failed to load ${dotenvPath} ${e.message}`) } return { error: e }