UNPKG

@plugjs/plug

Version:
33 lines 1.19 kB
import { statSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { assert } from "../asserts.js"; import { $p } from "../logging.js"; import { assertAbsolutePath } from "../paths.js"; export function findCaller(of) { const oldPrepareStackTrace = Error.prepareStackTrace; try { Error.prepareStackTrace = (_, stackTraces) => { const [stackTrace] = stackTraces; if (!stackTrace) return; const nullableFileOrUrl = stackTrace.getFileName(); if (!nullableFileOrUrl) return; const file = nullableFileOrUrl.startsWith('file:/') ? fileURLToPath(nullableFileOrUrl) : nullableFileOrUrl; assertAbsolutePath(file); return file; }; const record = {}; Error.captureStackTrace(record, of); const file = record.stack; assert(file, 'Unable to determine build file name'); assert(statSync(file).isFile(), `Build file ${$p(file)} not found`); return file; } finally { Error.prepareStackTrace = oldPrepareStackTrace; } } //# sourceMappingURL=caller.js.map