UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

45 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkDoesFoundValuePassesMinVersionCheck = exports.isCheckMinVersionExpression = exports.getMinVersionFromCheckMinVersionExpression = exports.isLinkedDependencyVersion = void 0; const defineMinPackageVersionRegex_1 = require("../../../../../../domain.operations/declaration/publicFileCheckFunctionUtilities/defineMinPackageVersionRegex"); /** * .what = checks if a version string is a linked dependency version * .why = linked versions (link:.) indicate the repo IS the package, * so they satisfy any minVersion check by definition */ const isLinkedDependencyVersion = (input) => { if (typeof input.value !== 'string') return false; return input.value.startsWith('link:'); }; exports.isLinkedDependencyVersion = isLinkedDependencyVersion; /** * grabs the `x.y.z` part from strings that match the shape `@declapract{check.minVersion('x.y.z')}` * * returns null if no match */ const getMinVersionFromCheckMinVersionExpression = (value) => (new RegExp(/^@declapract\{check\.minVersion\('([0-9.]+)'\)\}$/).exec(value) ?? [])[1] ?? null; exports.getMinVersionFromCheckMinVersionExpression = getMinVersionFromCheckMinVersionExpression; /** * checks whether the string matches the form "@declapract{check.minVersion('x.y.z')}" (with nothing before and nothing after, too) */ const isCheckMinVersionExpression = (value) => !!(0, exports.getMinVersionFromCheckMinVersionExpression)(value); exports.isCheckMinVersionExpression = isCheckMinVersionExpression; /** * .what = evaluates a foundValue against a minVersion, to check if it passes it or not * .why = enables validation of package versions against minimum requirements */ const checkDoesFoundValuePassesMinVersionCheck = ({ foundValue, minVersion, }) => { // linked versions always satisfy minVersion checks (the repo IS the package) const isLinked = (0, exports.isLinkedDependencyVersion)({ value: foundValue }); if (isLinked) return true; // define the regex to check against const minVersionRegexp = (0, defineMinPackageVersionRegex_1.defineMinPackageVersionRegex)(minVersion); // if foundValue does not match it, return the error message if (typeof foundValue !== 'string') return false; return minVersionRegexp.test(foundValue); }; exports.checkDoesFoundValuePassesMinVersionCheck = checkDoesFoundValuePassesMinVersionCheck; //# sourceMappingURL=check.minVersion.js.map