Passed
Push — master ( 137d2e...d6c083 )
by Dmytro
01:57
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-next-line import/no-commonjs
2
const { Module } = require('module');
3
4
function clearRequireCache() {
5
    Object.keys(require.cache).forEach((key) => {
6
        delete require.cache[key];
7
    });
8
}
9
10
const ROOT_FOLDER = process.cwd();
11
12
function preventParentScopeModules() {
13
    const nodeModulePaths = Module._nodeModulePaths;
14
15
    Module._nodeModulePaths = function (from) {
16
        const originalPath = nodeModulePaths.call(this, from);
17
        const insideRootPaths = originalPath.filter(function (path) {
18
            return path.match(ROOT_FOLDER);
19
        });
20
21
        return insideRootPaths;
22
    };
23
}
24
25
clearRequireCache();
26
preventParentScopeModules();
27