UNPKG

@mdf.js/utils

Version:

MMS - API Core - Common utils tools

33 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findNodeModule = findNodeModule; const tslib_1 = require("tslib"); /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); /** * Find the path to a node module in every parent directory (node_modules). * @param module - Module name * @param dir - Directory to start searching from * @returns Path to the module or undefined if not found */ function findNodeModule(module, dir = __dirname) { let modulePath; let currentDir = dir; let prevDir; while (currentDir !== prevDir) { const nodeModules = path_1.default.join(currentDir, 'node_modules', module); if (fs_1.default.existsSync(nodeModules)) { modulePath = nodeModules; } prevDir = currentDir; currentDir = path_1.default.dirname(currentDir); } return modulePath; } //# sourceMappingURL=findNodeModule.js.map