From 0e869a6605e4842b23de40b97d4721eb5be462f9 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 28 Feb 2024 16:51:01 +0100 Subject: [PATCH] refactor: Exclude `isSemVerRange` utility --- lib/setup-dependency/index.js | 11 +++-------- lib/utils/is-sem-ver-range.js | 8 ++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 lib/utils/is-sem-ver-range.js diff --git a/lib/setup-dependency/index.js b/lib/setup-dependency/index.js index b43219f..55d7eca 100644 --- a/lib/setup-dependency/index.js +++ b/lib/setup-dependency/index.js @@ -2,11 +2,11 @@ const { resolve } = require("path") , log = require("log").get("npm-cross-link") - , semver = require("semver") , getNpmModulesPath = require("../get-npm-modules-path") , setupExternal = require("./setup-external") , setupLocal = require("./setup-local") - , resolveLogLevel = require("./resolve-log-level"); + , resolveLogLevel = require("./resolve-log-level") + , isSemVerRange = require("../utils/is-sem-ver-range"); const getVersionRange = ({ dependentContext, name }) => { if ( @@ -30,11 +30,6 @@ const getVersionRange = ({ dependentContext, name }) => { return null; }; -const isSemVerValidRange = versionRange => { - if (versionRange === "latest") return true; - return semver.validRange(versionRange); -}; - module.exports = async (dependencyContext, userConfiguration, inputOptions, progressData) => { const { dependentContext, name, isExternal } = dependencyContext; @@ -46,7 +41,7 @@ module.exports = async (dependencyContext, userConfiguration, inputOptions, prog if (!dependencyContext.versionRange) dependencyContext.versionRange = packageJsonVersionRange; const { versionRange } = dependencyContext; if (versionRange) { - dependencyContext.isSemVerVersionRange = isSemVerValidRange(dependencyContext.versionRange); + dependencyContext.isSemVerVersionRange = isSemVerRange(dependencyContext.versionRange); if (!dependencyContext.isSemVerVersionRange) { log[resolveLogLevel(dependentContext, progressData)]( "%s references %s not by semver range %s", dependentContext.name, name, versionRange diff --git a/lib/utils/is-sem-ver-range.js b/lib/utils/is-sem-ver-range.js new file mode 100644 index 0000000..b66357e --- /dev/null +++ b/lib/utils/is-sem-ver-range.js @@ -0,0 +1,8 @@ +"use strict"; + +const semver = require("semver"); + +module.exports = versionRange => { + if (versionRange === "latest") return true; + return semver.validRange(versionRange); +};