/
utils.ts
51 lines (46 loc) 路 1.31 KB
/
utils.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
/**
* Shared utility functions and business logic
*/
import semverSatisfies from "semver/functions/satisfies";
import { VersionType } from "@changesets/types";
const bumpTypes = ["none", "patch", "minor", "major"];
/* Converts a bump type into a numeric level to indicate order */
function getBumpLevel(type: VersionType) {
const level = bumpTypes.indexOf(type);
if (level < 0) {
throw new Error(`Unrecognised bump type ${type}`);
}
return level;
}
export function shouldUpdateDependencyBasedOnConfig(
release: { version: string; type: VersionType },
{
depVersionRange,
depType,
}: {
depVersionRange: string;
depType:
| "dependencies"
| "devDependencies"
| "peerDependencies"
| "optionalDependencies";
},
{
minReleaseType,
onlyUpdatePeerDependentsWhenOutOfRange,
}: {
minReleaseType: "patch" | "minor";
onlyUpdatePeerDependentsWhenOutOfRange: boolean;
}
): boolean {
if (!semverSatisfies(release.version, depVersionRange)) {
// Dependencies leaving semver range should always be updated
return true;
}
const minLevel = getBumpLevel(minReleaseType);
let shouldUpdate = getBumpLevel(release.type) >= minLevel;
if (depType === "peerDependencies") {
shouldUpdate = !onlyUpdatePeerDependentsWhenOutOfRange;
}
return shouldUpdate;
}