import type { RangeStrategy } from '../../../types/versioning.ts'; import { api as npm } from '../npm/index.ts'; import type { NewValueConfig, VersioningApi } from '../types.ts'; export const id = 'deno'; export const displayName = 'deno'; export const urls = [ '[Deno - Package versions](https://docs.deno.com/runtime/fundamentals/modules/#package-versions)', ]; export const supportsRanges = true; export const supportedRangeStrategies: RangeStrategy[] = [ 'bump', 'pin', 'replace', ]; // If this is left as an alias, inputs like "17.04.0" throw errors export function isValid(input: string): boolean { // Allow "latest" as a valid version // https://github.com/denoland/deno_semver/blob/fe7c48e72e09116d17a64f9e58e6b28d1669b8e5/src/npm.rs#L1486 if (input === 'latest') { return true; } // the other, see the following test cases // https://github.com/denoland/deno_semver/blob/fe7c48e72e09116d17a64f9e58e6b28d1669b8e5/src/npm.rs#L621 return npm.isValid(input); } export function getNewValue({ currentValue, rangeStrategy, currentVersion, newVersion, isReplacement, }: NewValueConfig): string | null { if (currentValue === 'latest') { if (rangeStrategy === 'replace' || rangeStrategy === 'pin') { return newVersion; } if (rangeStrategy === 'update-lockfile') { return currentValue; // keep "latest" as is } // For other strategies (auto, future, in-range-only), treat as null return null; } if (currentValue === '*') { if (rangeStrategy === 'pin') { return newVersion; } if (rangeStrategy === 'update-lockfile') { return currentValue; // keep "*" as is } // For other strategies (auto, future, in-range-only), treat as null return null; } return npm.getNewValue({ currentValue, rangeStrategy, currentVersion, newVersion, isReplacement, }); } export const api: VersioningApi = { ...npm, isValid, getNewValue, }; export default api;