diff --git a/src/lib/getEnginesNodeFromRegistry.ts b/src/lib/getEnginesNodeFromRegistry.ts index 3e1126f6..399f7f10 100644 --- a/src/lib/getEnginesNodeFromRegistry.ts +++ b/src/lib/getEnginesNodeFromRegistry.ts @@ -1,6 +1,7 @@ import ProgressBar from 'progress' import { Index } from '../types/IndexType' import { Options } from '../types/Options' +import { Version } from '../types/Version' import { VersionSpec } from '../types/VersionSpec' import getPackageManager from './getPackageManager' @@ -11,7 +12,7 @@ import getPackageManager from './getPackageManager' * @param [options={}] Options. * @returns Promised {packageName: engines.node} collection */ -async function getEnginesNodeFromRegistry(packageMap: Index, options: Options) { +async function getEnginesNodeFromRegistry(packageMap: Index, options: Options) { const packageManager = getPackageManager(options, options.packageManager) if (!packageManager.getEngines) return {} diff --git a/src/lib/getIgnoredUpgradesDueToEnginesNode.ts b/src/lib/getIgnoredUpgradesDueToEnginesNode.ts index 9f9b9f39..9a8d81c1 100644 --- a/src/lib/getIgnoredUpgradesDueToEnginesNode.ts +++ b/src/lib/getIgnoredUpgradesDueToEnginesNode.ts @@ -6,6 +6,7 @@ import { Options } from '../types/Options' import { Version } from '../types/Version' import { VersionSpec } from '../types/VersionSpec' import getEnginesNodeFromRegistry from './getEnginesNodeFromRegistry' +import keyValueBy from './keyValueBy' import upgradePackageDefinitions from './upgradePackageDefinitions' /** Checks if package.json min node version satisfies given package engine.node spec */ @@ -21,13 +22,23 @@ export async function getIgnoredUpgradesDueToEnginesNode( if (!options.nodeEngineVersion) return {} const optionsEnginesNodeMinVersion = minVersion(options.nodeEngineVersion)?.version if (!optionsEnginesNodeMinVersion) return {} - const [upgradedLatestVersions] = await upgradePackageDefinitions(current, { + const [upgradedLatestVersions, latestVersionResults] = await upgradePackageDefinitions(current, { ...options, enginesNode: false, nodeEngineVersion: undefined, loglevel: 'silent', }) - const enginesNodes = await getEnginesNodeFromRegistry(upgradedLatestVersions, options) + + // Use the latest versions since getEnginesNodeFromRegistry requires exact versions. + // Filter down to only the upgraded latest versions, as there is no point in checking the engines.node for packages that have been filtered out, e.g. by options.minimal or options.filterResults. + const latestVersions = keyValueBy(latestVersionResults, (dep, result) => + upgradedLatestVersions[dep] && result?.version + ? { + [dep]: result.version, + } + : null, + ) + const enginesNodes = await getEnginesNodeFromRegistry(latestVersions, options) return Object.entries(upgradedLatestVersions) .filter( ([pkgName, newVersion]) => diff --git a/test/getIgnoredUpgradesDueToEnginesNode.test.ts b/test/getIgnoredUpgradesDueToEnginesNode.test.ts index d597da45..132e17bc 100644 --- a/test/getIgnoredUpgradesDueToEnginesNode.test.ts +++ b/test/getIgnoredUpgradesDueToEnginesNode.test.ts @@ -8,13 +8,15 @@ describe('getIgnoredUpgradesDueToEnginesNode', function () { const data = await getIgnoredUpgradesDueToEnginesNode( { 'ncu-test-return-version': '1.0.0', - 'ncu-test-peer': '1.0.0', + 'ncu-test-peer': '^1.0.0', del: '2.2.2', + '@typescript-eslint/eslint-plugin': '^7.18.0', }, { 'ncu-test-return-version': '2.0.0', - 'ncu-test-peer': '1.1.0', + 'ncu-test-peer': '^1.1.0', del: '2.2.2', + '@typescript-eslint/eslint-plugin': '^8.1.0', }, { enginesNode: true, @@ -22,6 +24,11 @@ describe('getIgnoredUpgradesDueToEnginesNode', function () { }, ) data.should.deep.equal({ + '@typescript-eslint/eslint-plugin': { + enginesNode: '^18.18.0 || ^20.9.0 || >=21.1.0', + from: '^7.18.0', + to: '^8.0.1', + }, del: { enginesNode: '>=14.16', from: '2.2.2',