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
  • Loading branch information
rbnayax committed Aug 8, 2024
1 parent 1aec29a commit 6894a97
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
7 changes: 5 additions & 2 deletions 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 { VersionResult } from '../types/VersionResult'
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<VersionResult>, options: Options) {
const packageManager = getPackageManager(options, options.packageManager)
if (!packageManager.getEngines) return {}

Expand All @@ -23,7 +24,9 @@ async function getEnginesNodeFromRegistry(packageMap: Index<VersionSpec>, option
}

return Object.entries(packageMap).reduce(async (accumPromise, [pkg, version]) => {
const enginesNode = (await packageManager.getEngines!(pkg, version, options)).node
const enginesNode = version.version
? (await packageManager.getEngines!(pkg, version.version, options)).node
: undefined
if (bar) {
bar.tick()
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/getIgnoredUpgradesDueToEnginesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ 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)
const enginesNodes = await getEnginesNodeFromRegistry(latestVersionResults, options)
return Object.entries(upgradedLatestVersions)
.filter(
([pkgName, newVersion]) =>
Expand Down
12 changes: 7 additions & 5 deletions test/getEnginesNodeFromRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ chaiSetup()
describe('getEnginesNodeFromRegistry', function () {
it('single package', async () => {
await chalkInit()
const data = await getEnginesNodeFromRegistry({ del: '2.0.0' }, {})
const data = await getEnginesNodeFromRegistry({ del: { version: '2.0.0' } }, {})
data.should.deep.equal({
del: '>=0.10.0',
})
})

it('single package empty', async () => {
await chalkInit()
const data = await getEnginesNodeFromRegistry({ 'ncu-test-return-version': '1.0.0' }, {})
const data = await getEnginesNodeFromRegistry({ 'ncu-test-return-version': { version: '1.0.0' } }, {})
data.should.deep.equal({ 'ncu-test-return-version': undefined })
})

it('multiple packages', async () => {
await chalkInit()
const data = await getEnginesNodeFromRegistry(
{
'ncu-test-return-version': '1.0.0',
'ncu-test-peer': '1.0.0',
del: '2.0.0',
'ncu-test-return-version': { version: '1.0.0' },
'ncu-test-peer': { version: '1.0.0' },
del: { version: '2.0.0' },
npVersion: {},
},
{},
)
data.should.deep.equal({
'ncu-test-return-version': undefined,
'ncu-test-peer': undefined,
npVersion: undefined,
del: '>=0.10.0',
})
})
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 6894a97

Please sign in to comment.