UNPKG

upgrade-dependents

Version:
39 lines (38 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const semver = require("semver"); const semverUtils = require("semver-utils"); const createRange_1 = require("./createRange"); const designations_1 = require("./designations"); const getDependencyDesignation_1 = require("./getDependencyDesignation"); const logs = require("./logs"); function isComplexRange(range) { const parsedRange = semverUtils.parseRange(range); return parsedRange.length > 1; } function createDependentPackageDeterminer({ workingPackageMeta, logger, force }) { const { name: dependencyName, version: dependencyVersion } = workingPackageMeta; return function isDependentPackage(info) { const { meta: dependentMeta } = info; const designation = getDependencyDesignation_1.getDependencyDesignation(dependencyName, dependentMeta); if (!designation) { return false; } if (force) { return true; } const property = designations_1.packagePropertyByDesignation[designation]; const dependencies = dependentMeta[property]; const dependentRange = dependencies[dependencyName]; if (isComplexRange(dependentRange)) { logger.warn(logs.skipPackageWithComplexRange(dependentMeta)); return false; } const upgradedRange = createRange_1.createRange(dependentRange, dependencyVersion); if (dependentRange === upgradedRange) { return false; } return semver.satisfies(dependencyVersion, dependentRange); }; } exports.createDependentPackageDeterminer = createDependentPackageDeterminer;