HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //proc/self/root/usr/local/lib/node_modules/@capacitor/cli/dist/util/monorepotools.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNXMonorepo = exports.isMonorepo = exports.findPackageRelativePathInMonorepo = exports.findPackagePath = exports.findNXMonorepoRoot = exports.findMonorepoRoot = void 0;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
/**
 * Finds the monorepo root from the given path.
 * @param currentPath - The current path to start searching from.
 * @returns The path to the monorepo root.
 * @throws An error if the monorepo root is not found.
 */
function findMonorepoRoot(currentPath) {
    const packageJsonPath = (0, node_path_1.join)(currentPath, 'package.json');
    const pnpmWorkspacePath = (0, node_path_1.join)(currentPath, 'pnpm-workspace.yaml');
    if ((0, node_fs_1.existsSync)(pnpmWorkspacePath) ||
        ((0, node_fs_1.existsSync)(packageJsonPath) &&
            JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, 'utf-8')).workspaces)) {
        return currentPath;
    }
    const parentPath = (0, node_path_1.dirname)(currentPath);
    if (parentPath === currentPath) {
        throw new Error('Monorepo root not found');
    }
    return findMonorepoRoot(parentPath);
}
exports.findMonorepoRoot = findMonorepoRoot;
/**
 * Finds the NX monorepo root from the given path.
 * @param currentPath - The current path to start searching from.
 * @returns The path to the monorepo root.
 * @throws An error if the monorepo root is not found.
 */
function findNXMonorepoRoot(currentPath) {
    const nxJsonPath = (0, node_path_1.join)(currentPath, 'nx.json');
    if ((0, node_fs_1.existsSync)(nxJsonPath)) {
        return currentPath;
    }
    const parentPath = (0, node_path_1.dirname)(currentPath);
    if (parentPath === currentPath) {
        throw new Error('Monorepo root not found');
    }
    return findNXMonorepoRoot(parentPath);
}
exports.findNXMonorepoRoot = findNXMonorepoRoot;
/**
 * Finds the path to a package within the node_modules folder,
 * searching up the directory hierarchy until the last possible directory is reached.
 * @param packageName - The name of the package to find.
 * @param currentPath - The current path to start searching from.
 * @param lastPossibleDirectory - The last possible directory to search for the package.
 * @returns The path to the package, or null if not found.
 */
function findPackagePath(packageName, currentPath, lastPossibleDirectory) {
    const nodeModulesPath = (0, node_path_1.join)(currentPath, 'node_modules', packageName);
    if ((0, node_fs_1.existsSync)(nodeModulesPath)) {
        return nodeModulesPath;
    }
    if (currentPath === lastPossibleDirectory) {
        return null;
    }
    const parentPath = (0, node_path_1.dirname)(currentPath);
    return findPackagePath(packageName, parentPath, lastPossibleDirectory);
}
exports.findPackagePath = findPackagePath;
/**
 * Finds the relative path to a package from the current directory,
 * using the monorepo root as the last possible directory.
 * @param packageName - The name of the package to find.
 * @param currentPath - The current path to start searching from.
 * @returns The relative path to the package, or null if not found.
 */
function findPackageRelativePathInMonorepo(packageName, currentPath) {
    const monorepoRoot = findMonorepoRoot(currentPath);
    const packagePath = findPackagePath(packageName, currentPath, monorepoRoot);
    if (packagePath) {
        return (0, node_path_1.relative)(currentPath, packagePath);
    }
    return null;
}
exports.findPackageRelativePathInMonorepo = findPackageRelativePathInMonorepo;
/**
 * Detects if the current directory is part of a monorepo (npm, yarn, pnpm).
 * @param currentPath - The current path to start searching from.
 * @returns True if the current directory is part of a monorepo, false otherwise.
 */
function isMonorepo(currentPath) {
    try {
        findMonorepoRoot(currentPath);
        return true;
    }
    catch (error) {
        return false;
    }
}
exports.isMonorepo = isMonorepo;
/**
 * Detects if the current directory is part of a nx integrated monorepo.
 * @param currentPath - The current path to start searching from.
 * @returns True if the current directory is part of a monorepo, false otherwise.
 */
function isNXMonorepo(currentPath) {
    try {
        findNXMonorepoRoot(currentPath);
        return true;
    }
    catch (error) {
        return false;
    }
}
exports.isNXMonorepo = isNXMonorepo;