From 0c7b68ea2db6da8ba1bf85ba9a86233d7325cc42 Mon Sep 17 00:00:00 2001 From: Romanos Tsouroplis Date: Sun, 26 Apr 2020 14:37:32 +0200 Subject: [PATCH] Only get vars from .env This way it won't parse through the rest of the process envs but only the ones that we have in our .env file. --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index e8224fc..944068e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,13 @@ const dotenv = require('dotenv'); module.exports = (filterPrefix = 'SAPPER_APP_', targetPrefix = 'process.env.', excluded = [], dotEnvOptions) => { - dotenv.config(dotEnvOptions); + const result = dotenv.config(dotEnvOptions); + if (result.error) { + throw result.error; + } + const SAPPER_APP_ENV_VARS = {}; - for (let key in process.env) { + for (let key in result.parsed) { if (key.includes(filterPrefix) && !excluded.includes(key)) SAPPER_APP_ENV_VARS[targetPrefix + key] = ("'" + process.env[key] + "'"); } return SAPPER_APP_ENV_VARS;