forked from renovatebot/renovate
/
package.ts
62 lines (60 loc) · 2.01 KB
/
package.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import is from '@sindresorhus/is';
import { dequal } from 'dequal';
import { getPkgReleases } from '../../datasource';
import * as datasourceGithubTags from '../../datasource/github-tags';
import { logger } from '../../logger';
import { NodeJsPolicies, getPolicies } from '../../versioning/node/schedule';
import { getSatisfyingVersion, isVersion } from '../../versioning/semver';
import type { PackageUpdateConfig, PackageUpdateResult } from '../types';
export async function getPackageUpdates(
config: PackageUpdateConfig
): Promise<PackageUpdateResult> {
logger.trace('travis.getPackageUpdates()');
const { supportPolicy } = config;
if (!supportPolicy?.length) {
return { updates: [] };
}
const policies = getPolicies();
for (const policy of supportPolicy) {
if (!Object.keys(policies).includes(policy)) {
logger.warn({ policy }, `Unknown supportPolicy`);
return { updates: [] };
}
}
logger.debug({ supportPolicy }, `supportPolicy`);
let newValue: any[] = (supportPolicy as (keyof NodeJsPolicies)[])
.map((policy) => policies[policy])
.reduce((result, policy) => result.concat(policy), [])
.sort((a, b) => a - b);
const newMajor: number = newValue[newValue.length - 1];
if (config.rangeStrategy === 'pin' || isVersion(config.currentValue[0])) {
const versions = (
await getPkgReleases({
...config,
datasource: datasourceGithubTags.id,
depName: 'nodejs/node',
})
).releases.map((release) => release.version);
newValue = newValue
.map(String)
.map((value) => getSatisfyingVersion(versions, value));
}
if (is.string(config.currentValue[0])) {
newValue = newValue.map(String);
}
newValue.sort((a, b) => a - b);
(config.currentValue as any).sort((a, b) => a - b);
if (dequal(config.currentValue, newValue)) {
return { updates: [] };
}
return {
sourceUrl: 'https://github.com/nodejs/node',
updates: [
{
newValue: newValue.join(','),
newMajor,
isRange: true,
},
],
};
}