Passed
Push — master ( a3cf99...dec494 )
by Dmytro
02:02
created

init.js ➔ clearRequireCache   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 2
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