Skip to content

Commit

Permalink
fix: check if upgrade ignored due to engines fails due to usage of ra…
Browse files Browse the repository at this point in the history
…nges (#1447)

Co-authored-by: Raine Revere <[email protected]>
  • Loading branch information
rbnayax and raineorshine authored Aug 8, 2024
1 parent 1aec29a commit 369bbdf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lib/getEnginesNodeFromRegistry.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -11,7 +12,7 @@ import getPackageManager from './getPackageManager'
* @param [options={}] Options.
* @returns Promised {packageName: engines.node} collection
*/
async function getEnginesNodeFromRegistry(packageMap: Index<VersionSpec>, options: Options) {
async function getEnginesNodeFromRegistry(packageMap: Index<Version>, options: Options) {
const packageManager = getPackageManager(options, options.packageManager)
if (!packageManager.getEngines) return {}

Expand Down
15 changes: 13 additions & 2 deletions src/lib/getIgnoredUpgradesDueToEnginesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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]) =>
Expand Down
11 changes: 9 additions & 2 deletions test/getIgnoredUpgradesDueToEnginesNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ 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,
nodeEngineVersion: `^0.10.0`,
},
)
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',
Expand Down

0 comments on commit 369bbdf

Please sign in to comment.