Test Failed
Push — master ( 4acb94...dc896f )
by Dmytro
01:39
created

tests/init.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 25
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
mnd 0
bc 0
fnc 5
dl 0
loc 25
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A init.js ➔ preventParentScopeModules 0 14 3
A init.js ➔ clearRequireCache 0 5 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
function preventParentScopeModules() {
11
    const nodeModulePaths = Module._nodeModulePaths; // backup the original method
12
13
    Module._nodeModulePaths = function (from) {
14
        let paths = nodeModulePaths.call(this, from); // call the original method
15
16
        // add your logic here to exclude parent dirs, I did a simple match with current dir
17
        paths = paths.filter(function (path) {
18
            return path.match(__dirname);
19
        });
20
21
        return paths;
22
    };
23
}
24
25
clearRequireCache();
26
preventParentScopeModules();
27