ancesdir
Version:
Find a specific ancestor/root directory given a starting location and a search parameter
3 lines (2 loc) • 696 B
JavaScript
import*as t from"path";import*as n from"fs";var o=new Map;const r=(t,n)=>{throw new Error(`Could not find marker, "${n}", from given starting location "${t}"`)};function s(s,e){t.isAbsolute(s)||(t=>{throw new Error(`The starting path must be absolute, but "${t}" is relative`)})(s);const i=[];let a=null;for(;null==a;){const l=`${s}:${e}`;i.push(l);const u=o.get(l);if(null!=u){a=u;continue}o.has(l)&&r(s,e);const f=t.dirname(s);if(f===s||null==f){for(const t of i)o.set(t,null);r(s,e)}const c=t.join(f,e);if(n.existsSync(c)){for(const t of i)o.set(t,f);a=f}else s=f}return a}function e(t,n){return s(t=t||e(__dirname),n=n||"package.json")}export{e as default};
//# sourceMappingURL=index.js.map