MCPcopy Index your code
hub / github.com/ilearnio/module-alias / reset

Function reset

index.js:118–145  ·  view source on GitHub ↗

* Reset any changes maded (resets all registered aliases * and custom module directories) * The function is undocumented and for testing purposes only

()

Source from the content-addressed store, hash-verified

116 * The function is undocumented and for testing purposes only
117 */
118function 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

Callers

nothing calls this directly

Calls 2

getMainModuleFunction · 0.85
removePathHelperFunction · 0.85

Tested by

no test coverage detected