"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findInstalledPackageFromList = findInstalledPackageFromList;
exports.hasPackageInstalled = hasPackageInstalled;
exports.getPackageVersion = getPackageVersion;
/**
 * Checks if @param packageJson has any of the @param packageNamesList package names
 * listed as a dependency, devDependency, or optionalDependency.
 * If so, it returns the first package name that is found, including the
 * version (range) specified in the package.json.
 */
function findInstalledPackageFromList(packageNamesList, packageJson) {
    return packageNamesList
        .map((packageName) => ({
        name: packageName,
        version: getPackageVersion(packageName, packageJson),
    }))
        .find((sdkPackage) => !!sdkPackage.version);
}
function hasPackageInstalled(packageName, packageJson) {
    return getPackageVersion(packageName, packageJson) !== undefined;
}
function getPackageVersion(packageName, packageJson) {
    return (packageJson?.dependencies?.[packageName] ||
        packageJson?.devDependencies?.[packageName] ||
        packageJson?.optionalDependencies?.[packageName]);
}
