UNPKG

nx

Version:

The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.

53 lines (52 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DIST_TAGS = void 0; exports.isLegacyEra = isLegacyEra; exports.normalizeVersion = normalizeVersion; exports.normalizeVersionWithTagCheck = normalizeVersionWithTagCheck; const semver_1 = require("semver"); const resolve_package_version_1 = require("./resolve-package-version"); exports.DIST_TAGS = ['latest', 'next', 'canary']; const LEGACY_ERA_BOUNDARY = '14.0.0-beta.0'; // Pre-14 (legacy) installs used `@nrwl/workspace` as the canonical Nx package. // Non-semver values (e.g. dist-tags or the literal `'latest'` sentinel before // tag resolution) are treated as modern era. function isLegacyEra(targetVersion) { return (0, semver_1.valid)(targetVersion) && (0, semver_1.lt)(targetVersion, LEGACY_ERA_BOUNDARY); } function normalizeVersion(version) { const [semver, ...prereleaseTagParts] = version.split('-'); // Handle versions like 1.0.0-beta-next.2 const prereleaseTag = prereleaseTagParts.join('-'); const [major, minor, patch] = semver.split('.'); const newSemver = `${major || 0}.${minor || 0}.${patch || 0}`; const newVersion = prereleaseTag ? `${newSemver}-${prereleaseTag}` : newSemver; const withoutPatch = `${major || 0}.${minor || 0}.0`; const withoutPatchAndMinor = `${major || 0}.0.0`; const variationsToCheck = [ newVersion, newSemver, withoutPatch, withoutPatchAndMinor, ]; for (const variation of variationsToCheck) { try { if ((0, semver_1.gt)(variation, '0.0.0')) { return variation; } } catch { } } return '0.0.0'; } async function normalizeVersionWithTagCheck(pkg, version) { // Treat non-parseable inputs (e.g. dist-tags like `latest`/`next`) as // registry references and resolve them. Throws on registry failure; // callers that need to tolerate registry outages must wrap. if (version && !(0, semver_1.parse)(version)) { return (0, resolve_package_version_1.resolvePackageVersionRespectingMinReleaseAge)(pkg, version); } return normalizeVersion(version); }