UNPKG

1.37 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
7const config = require('./config');
8
9const dotenv = require('dotenv');
10
11const variableExpansion = require('dotenv-expand');
12
13function loadEnv(_x) {
14 return _loadEnv.apply(this, arguments);
15}
16
17function _loadEnv() {
18 _loadEnv = (0, _asyncToGenerator2.default)(function* (filepath) {
19 const NODE_ENV = process.env.NODE_ENV || 'development';
20 const dotenvFiles = [`.env.${NODE_ENV}.local`, `.env.${NODE_ENV}`, // Don't include `.env.local` for `test` environment
21 // since normally you expect tests to produce the same
22 // results for everyone
23 NODE_ENV !== 'test' && '.env.local', '.env'].filter(Boolean);
24 yield Promise.all(dotenvFiles.map(
25 /*#__PURE__*/
26 function () {
27 var _ref = (0, _asyncToGenerator2.default)(function* (dotenvFile) {
28 const envPath = yield config.resolve(filepath, [dotenvFile]);
29
30 if (envPath) {
31 const envs = dotenv.config({
32 path: envPath
33 });
34 variableExpansion(envs);
35 }
36 });
37
38 return function (_x2) {
39 return _ref.apply(this, arguments);
40 };
41 }()));
42 });
43 return _loadEnv.apply(this, arguments);
44}
45
46module.exports = loadEnv;
\No newline at end of file