UNPKG

@jsdevtools/npm-publish

Version:
33 lines 1.33 kB
import semverDifference from "semver/functions/diff.js"; import semverGreaterThan from "semver/functions/gt.js"; import semverValid from "semver/functions/valid.js"; import { STRATEGY_ALL } from "../options.js"; import { DIFFERENT, INITIAL } from "../results.js"; /** * Compare previously published versions with the package's current version. * * @param currentVersion The current package version. * @param publishedVersions The versions that have already been published. * @param options Configuration options * @returns The release type and previous version. */ export function compareVersions(currentVersion, publishedVersions, options) { const { versions, "dist-tags": tags } = publishedVersions ?? {}; const { strategy, tag: publishTag } = options; const oldVersion = semverValid(tags?.[publishTag.value]) ?? undefined; const isUnique = !versions?.includes(currentVersion); let type; if (isUnique) { if (!oldVersion) { type = INITIAL; } else if (semverGreaterThan(currentVersion, oldVersion)) { type = semverDifference(currentVersion, oldVersion) ?? DIFFERENT; } else if (strategy.value === STRATEGY_ALL) { type = DIFFERENT; } } return { type, oldVersion }; } //# sourceMappingURL=compare-versions.js.map