2 const callsites = require('callsites');
4 module.exports = filepath => {
5 const stacks = callsites();
8 return stacks[2].getFileName();
13 // Skip the first stack as it's this function
16 for (const stack of stacks) {
17 const parentFilepath = stack.getFileName();
19 if (typeof parentFilepath !== 'string') {
23 if (parentFilepath === filepath) {
28 // Skip native modules
29 if (parentFilepath === 'module.js') {
33 if (seenVal && parentFilepath !== filepath) {
34 return parentFilepath;