HEX
Server: Apache
System: Linux pdx1-shared-a2-09 6.6.116-grsec-jammy-dirty #1 SMP Sat Nov 8 00:02:42 UTC 2025 x86_64
User: dh_pvsc7i (5084578)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/nodejs/parent-module/index.js
'use strict';
const callsites = require('callsites');

module.exports = filePath => {
	const stacks = callsites();

	if (!filePath) {
		return stacks[2].getFileName();
	}

	let hasSeenValue = 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) {
			hasSeenValue = true;
			continue;
		}

		// Skip native modules
		if (parentFilePath === 'module.js') {
			continue;
		}

		if (hasSeenValue && parentFilePath !== filePath) {
			return parentFilePath;
		}
	}
};