Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 32 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /* eslint-disable import/no-commonjs */ |
||
2 | const path = require('path'); |
||
3 | const { Module } = require('module'); |
||
4 | const dotenv = require('dotenv'); |
||
5 | |||
6 | function clearRequireCache() { |
||
7 | Object.keys(require.cache).forEach((key) => { |
||
8 | delete require.cache[key]; |
||
9 | }); |
||
10 | } |
||
11 | |||
12 | const ROOT_FOLDER = process.cwd(); |
||
13 | |||
14 | function preventParentScopeModules() { |
||
15 | const nodeModulePaths = Module._nodeModulePaths; |
||
16 | |||
17 | Module._nodeModulePaths = function (from) { |
||
18 | const originalPath = nodeModulePaths.call(this, from); |
||
19 | const insideRootPaths = originalPath.filter(function (p) { |
||
20 | return p.match(ROOT_FOLDER); |
||
21 | }); |
||
22 | |||
23 | return insideRootPaths; |
||
24 | }; |
||
25 | } |
||
26 | |||
27 | function initEnv() { |
||
28 | dotenv.config({ path: path.join(__dirname, './test.env') }); |
||
29 | } |
||
30 | |||
31 | clearRequireCache(); |
||
32 | preventParentScopeModules(); |
||
33 | initEnv(); |
||
34 |