UNPKG

@nx/rspack

Version:

The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.

54 lines (53 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInstalledRspackMajorVersion = getInstalledRspackMajorVersion; exports.getInstalledRspackVersionRuntime = getInstalledRspackVersionRuntime; exports.getRspackVersionsForInstalledMajor = getRspackVersionsForInstalledMajor; const internal_1 = require("@nx/devkit/internal"); const semver_1 = require("semver"); const versions_1 = require("./versions"); const RSPACK_CORE_PACKAGE = '@rspack/core'; /** * Returns the declared @rspack/core major version from the workspace's * package.json when it matches a supported major, or `undefined` otherwise * (fresh install, dist tag, unknown major). Below-floor enforcement is * handled at generator entry points via `assertSupportedRspackVersion`. */ function getInstalledRspackMajorVersion(tree) { const declared = (0, internal_1.getDeclaredPackageVersion)(tree, RSPACK_CORE_PACKAGE); if (!declared) { return undefined; } const installedMajor = (0, semver_1.major)(declared); return installedMajor in versions_1.backwardCompatibleRspackVersions ? installedMajor : undefined; } /** * Returns the installed @rspack/core major version resolved at runtime from * node_modules. For use in executors and runtime code where no Tree is * available. Returns `null` when @rspack/core can't be resolved or the * installed major isn't supported. */ function getInstalledRspackVersionRuntime() { const version = (0, internal_1.getInstalledPackageVersion)(RSPACK_CORE_PACKAGE); if (!version) { return null; } const installedMajor = (0, semver_1.major)(version); return installedMajor in versions_1.backwardCompatibleRspackVersions ? installedMajor : null; } /** * Returns the version-map entry for the installed major, falling back to the * latest supported map when no installed version is detected (fresh install) * or the detected major is outside the supported window. */ function getRspackVersionsForInstalledMajor(tree) { const installed = getInstalledRspackMajorVersion(tree); if (installed === undefined) { return versions_1.latestRspackVersions; } return versions_1.backwardCompatibleRspackVersions[installed]; }