forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-release-from-changeset.js
37 lines (30 loc) · 1005 Bytes
/
find-release-from-changeset.js
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
/**
*
* @param {string | undefined} publishedPackages
* @param {string | undefined} packageVersionToFollow
* @returns {string | undefined}
*/
function findReleaseFromChangeset(publishedPackages, packageVersionToFollow) {
if (!publishedPackages) {
throw new Error("No published packages found");
}
let packages = JSON.parse(publishedPackages);
if (!Array.isArray(packages)) {
throw new Error("Published packages is not an array");
}
/** @see https://github.com/changesets/action#outputs */
/** @type { { name: string; version: string }[] } */
let typed = packages.filter((pkg) => "name" in pkg && "version" in pkg);
let found = typed.find((pkg) => pkg.name === packageVersionToFollow);
if (!found) {
throw new Error(
`${packageVersionToFollow} was not found in the published packages`
);
}
console.log(found.version);
return found.version;
}
findReleaseFromChangeset(
process.env.PUBLISHED_PACKAGES,
process.env.PACKAGE_VERSION_TO_FOLLOW
);