eslint-plugin-path
Version:
An ESLint plugin for enforcing consistent imports across project. In other words, it helps to replace all relatives import with absolutes dependinng on settings.
22 lines • 907 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPackagePath = getPackagePath;
const path_1 = require("path");
const fs_1 = require("fs");
const constants_1 = require("./constants");
/**
* Package.json directory finder
* @param {string} filePath - path to directory where packages.json is located
* @returns {string} path to directory where packages.json is located
*/
function getPackagePath(filePath) {
let dir = (0, path_1.resolve)(filePath || "", constants_1.FILES.package);
do {
dir = (0, path_1.dirname)(dir);
} while (!(0, fs_1.existsSync)((0, path_1.join)(dir, constants_1.FILES.package)) && dir !== "/");
if (!(0, fs_1.existsSync)((0, path_1.join)(dir, constants_1.FILES.package))) {
return (process === null || process === void 0 ? void 0 : process.cwd()) || "";
}
return dir;
}
//# sourceMappingURL=package.js.map