UNPKG

residence

Version:

Find project root given current working directory

26 lines (25 loc) 656 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const fs = require("fs"); exports.r2gSmokeTest = () => { return true; }; exports.findRootDir = (pth, f) => { let possiblePkgDotJsonPath = path.resolve(pth + '/' + f); try { if (fs.statSync(possiblePkgDotJsonPath).isFile()) { return pth; } } catch (err) { } let subPath = path.resolve(pth + '/../'); if (subPath === pth) { return null; } return exports.findRootDir(subPath, f); }; exports.findProjectRoot = (pth) => { return exports.findRootDir(pth, 'package.json'); };