UNPKG

eslint-plugin-sonarjs

Version:
41 lines (40 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClosestDependencyManifestDir = getClosestDependencyManifestDir; /* * SonarQube JavaScript Plugin * Copyright (C) SonarSource Sàrl * mailto:info AT sonarsource DOT com * * You can redistribute and/or modify this program under the terms of * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the Sonar Source-Available License for more details. * * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ const files_js_1 = require("../files.js"); const index_js_1 = require("./index.js"); const closest_js_1 = require("../find-up/closest.js"); /** * Finds the closest directory containing at least one dependency manifest. */ function getClosestDependencyManifestDir(dir, topDir) { let closestManifestPath; for (const manifestName of index_js_1.DEPENDENCY_MANIFESTS) { const manifestPath = closest_js_1.closestPatternCache .get(manifestName) .get(topDir ?? (0, files_js_1.getPathRoot)(dir)) .get(dir)?.filePath; // All candidates are on the same ancestor chain of `dir`, so the longest path is the closest. if (manifestPath && (!closestManifestPath || manifestPath.length > closestManifestPath.length)) { closestManifestPath = manifestPath; } } return closestManifestPath ? (0, files_js_1.dirnamePath)(closestManifestPath) : undefined; }