serverless-dotenv-plugin
Advanced tools
Comparing version 3.5.0 to 3.5.1
@@ -8,2 +8,3 @@ # Changelog | ||
* [Documentation](https://github.com/neverendingqs/serverless-dotenv-plugin/pulls?q=+is%3Apr+label%3Adocumentation) | ||
* [Refactor](https://github.com/neverendingqs/serverless-dotenv-plugin/pulls?q=label%3Arefactor+is%3Apr) | ||
@@ -10,0 +11,0 @@ ## Unreleased |
47
index.js
@@ -91,23 +91,3 @@ 'use strict' | ||
const envVars = envVarsArray.reduce( | ||
(acc, curr) => ({ ...acc, ...curr }), | ||
{}, | ||
) | ||
const missingRequiredEnvVars = (this.required.env || []).filter( | ||
(envVarName) => !envVars[envVarName] && !process.env[envVarName], | ||
) | ||
if (missingRequiredEnvVars.length > 0) { | ||
throw Object.assign( | ||
new Error( | ||
`Missing the following required environment variables: ${missingRequiredEnvVars.join( | ||
',', | ||
)}`, | ||
), | ||
{ type: errorTypes.HALT }, | ||
) | ||
} | ||
return envVars | ||
return envVarsArray.reduce((acc, curr) => ({ ...acc, ...curr }), {}) | ||
} | ||
@@ -153,3 +133,3 @@ | ||
'DOTENV: Loading environment variables from ' + | ||
envFileNames.reverse().join(', ') + | ||
[...envFileNames].reverse().join(', ') + | ||
':', | ||
@@ -168,2 +148,22 @@ ) | ||
/** | ||
* @param {string[]} envFileNames | ||
*/ | ||
validateEnvVars(envVars) { | ||
const missingRequiredEnvVars = (this.required.env || []).filter( | ||
(envVarName) => !envVars[envVarName] && !process.env[envVarName], | ||
) | ||
if (missingRequiredEnvVars.length > 0) { | ||
throw Object.assign( | ||
new Error( | ||
`Missing the following required environment variables: ${missingRequiredEnvVars.join( | ||
',', | ||
)}`, | ||
), | ||
{ type: errorTypes.HALT }, | ||
) | ||
} | ||
} | ||
/** | ||
* @param {string} env | ||
@@ -174,5 +174,6 @@ */ | ||
try { | ||
this.validateEnvFileNames(envFileNames) | ||
const envVars = this.parseEnvFiles(envFileNames) | ||
this.validateEnvVars(envVars) | ||
this.setProviderEnv(envVars) | ||
this.validateEnvFileNames(envFileNames) | ||
} catch (e) { | ||
@@ -179,0 +180,0 @@ if (e.type === errorTypes.HALT) { |
{ | ||
"name": "serverless-dotenv-plugin", | ||
"version": "3.5.0", | ||
"version": "3.5.1", | ||
"description": "Preload environment variables with dotenv into serverless.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
59600
1070