* Reset any changes maded (resets all registered aliases * and custom module directories) * The function is undocumented and for testing purposes only
()
| 116 | * The function is undocumented and for testing purposes only |
| 117 | */ |
| 118 | function reset () { |
| 119 | var mainModule = getMainModule() |
| 120 | |
| 121 | // Reset all changes in paths caused by addPath function |
| 122 | modulePaths.forEach(function (path) { |
| 123 | if (mainModule) { |
| 124 | removePathHelper(path, mainModule.paths) |
| 125 | } |
| 126 | |
| 127 | // Delete from require.cache if the module has been required before. |
| 128 | // This is required for node >= 11 |
| 129 | Object.getOwnPropertyNames(require.cache).forEach(function (name) { |
| 130 | if (name.indexOf(path) !== -1) { |
| 131 | delete require.cache[name] |
| 132 | } |
| 133 | }) |
| 134 | |
| 135 | var parent = module.parent |
| 136 | while (parent && parent !== mainModule) { |
| 137 | removePathHelper(path, parent.paths) |
| 138 | parent = parent.parent |
| 139 | } |
| 140 | }) |
| 141 | |
| 142 | modulePaths = [] |
| 143 | moduleAliases = {} |
| 144 | moduleAliasNames = [] |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Import aliases from package.json |
nothing calls this directly
no test coverage detected