Urara-Blog/node_modules/.pnpm-store/v3/files/db/09df09bfec73b58a35cb5bfdf903f37944b219e638370e0deecb4d0bc47b6ff0036971382ee11d86c64779bd9a8722d677af7a07f533eeef4cd5f9b28a4d9e
2022-08-14 01:14:53 +08:00

37 lines
641 B
Text

'use strict';
const callsites = require('callsites');
module.exports = filepath => {
const stacks = callsites();
if (!filepath) {
return stacks[2].getFileName();
}
let seenVal = false;
// Skip the first stack as it's this function
stacks.shift();
for (const stack of stacks) {
const parentFilepath = stack.getFileName();
if (typeof parentFilepath !== 'string') {
continue;
}
if (parentFilepath === filepath) {
seenVal = true;
continue;
}
// Skip native modules
if (parentFilepath === 'module.js') {
continue;
}
if (seenVal && parentFilepath !== filepath) {
return parentFilepath;
}
}
};