@plugjs/plug
Version:
PlugJS Build System ===================
33 lines (32 loc) • 1.08 kB
JavaScript
// utils/caller.ts
import { statSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { assert } from "../asserts.mjs";
import { $p } from "../logging.mjs";
import { assertAbsolutePath } from "../paths.mjs";
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 file2 = nullableFileOrUrl.startsWith("file:/") ? fileURLToPath(nullableFileOrUrl) : nullableFileOrUrl;
assertAbsolutePath(file2);
return file2;
};
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;
}
}
export {
findCaller
};
//# sourceMappingURL=caller.mjs.map