MCPcopy Create free account
hub / github.com/dataform-co/dataform / getCallerFile

Function getCallerFile

core/utils.ts:50–87  ·  view source on GitHub ↗
(rootDir: string)

Source from the content-addressed store, hash-verified

48}
49
50export function getCallerFile(rootDir: string) {
51 let lastfile: string;
52 const stack = getCurrentStack();
53 while (stack.length) {
54 const nextLastfile = stack.shift().getFileName();
55 if (!nextLastfile) {
56 continue;
57 }
58 if (!nextLastfile.includes(rootDir)) {
59 continue;
60 }
61 if (nextLastfile.includes("node_modules")) {
62 continue;
63 }
64 // If it's in the root directory we'll take it, but keep searching
65 // for a better match.
66 lastfile = nextLastfile;
67 if (
68 !(
69 nextLastfile.includes(`definitions${Path.separator}`) ||
70 nextLastfile.includes(`models${Path.separator}`)
71 )
72 ) {
73 continue;
74 }
75 break;
76 }
77 if (!lastfile) {
78 if ((global as any).__dataform_current_file) {
79 lastfile = (global as any).__dataform_current_file;
80 } else {
81 // This is likely caused by Session.compileError() being called inside Session.compile().
82 // If so, explicitly pass the filename to Session.compileError().
83 throw new Error("Unable to find valid caller file; please report this issue.");
84 }
85 }
86 return Path.relativePath(lastfile, rootDir);
87}
88
89function getCurrentStack(): NodeJS.CallSite[] {
90 const originalStackTraceLimit = Error.stackTraceLimit;

Callers

nothing calls this directly

Calls 2

getCurrentStackFunction · 0.85
getFileNameMethod · 0.45

Tested by

no test coverage detected