'use strict';constpath=require('path');constresolveFrom=require('resolve-from');constparentModule=require('parent-module');module.exports=moduleId=>{if(typeofmoduleId!=='string'){thrownewTypeError('Expected a string');}constparentPath=parentModule(__filename);constfilePath=resolveFrom(path.dirname(parentPath),moduleId);constoldModule=require.cache[filePath];// Delete itself from module parentif(oldModule&&oldModule.parent){leti=oldModule.parent.children.length;while(i--){if(oldModule.parent.children[i].id===filePath){oldModule.parent.children.splice(i,1);}}}deleterequire.cache[filePath];// Delete module from cacheconstparent=require.cache[parentPath];// If `filePath` and `parentPath` are the same, cache will already be deleted so we won't get a memory leak in next stepreturnparent===undefined?require(filePath):parent.require(filePath);// In case cache doesn't have parent, fall back to normal require};