semver#validRange TypeScript Examples
The following examples show how to use
semver#validRange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dependency-version-compare.ts From eslint-config-kit with MIT License | 6 votes |
export function toVersion(versionOrRange: string): string {
if (valid(versionOrRange)) {
return versionOrRange
}
if (validRange(versionOrRange)) {
const versionObject = minVersion(versionOrRange)
if (!versionObject) throw new InvalidVersionError()
return versionObject.version
}
throw new InvalidVersionError()
}
Example #2
Source File: dependency-version-compare.ts From eslint-config-kit with MIT License | 6 votes |
function compare(
versionOrRange: string,
target: string,
sign: '<' | '>'
): boolean {
if (valid(versionOrRange)) {
return satisfies(versionOrRange, sign + target)
}
if (validRange(versionOrRange)) {
const matches = satisfies(target, versionOrRange)
return subset(versionOrRange, sign + target) || (sign === '>' && matches)
}
throw new InvalidVersionError()
}
Example #3
Source File: binPreconditionsFactory.ts From cli with Apache License 2.0 | 5 votes |
export function getBinVersionPrecondition(
binaryName: string,
options: BinPreconditionsOptions,
versionExtractor: (stdout: string) => string = (stdout) => stdout
) {
const appliedOptions: Required<BinPreconditionsOptions> = {
...defaultOptions,
...options,
prettyName: options.prettyName,
};
return function (versionRange: string) {
return async function (target: Command) {
if (!validRange(versionRange)) {
const message = dedent`
Required version invalid: "${versionRange}".
Please report this error to Coveo: https://github.com/coveo/cli/issues/new
`;
throw new PreconditionError(message, {
category: PreconditionErrorCategory.InvalidBinVersionRange,
});
}
const output = await spawnProcessOutput(
binaryName,
appliedOptions.params
);
await checkIfBinIsInstalled(target, binaryName, appliedOptions, output);
const version = versionExtractor(output.stdout);
if (!satisfies(version, versionRange)) {
const message = dedent`
${target.id} needs a ${
appliedOptions.prettyName
} version in this range: "${versionRange}"
Version detected: ${version}
${warnHowToInstallBin(appliedOptions)}
`;
throw new PreconditionError(message, {
category: PreconditionErrorCategory.InvalidBinVersionRange,
});
}
};
};
}