Skip to content

Commit

Permalink
[continuous-delivery] enforced npm api to get published version for e…
Browse files Browse the repository at this point in the history
…very package via lone request
  • Loading branch information
msereniti committed Aug 1, 2022
1 parent e8979e0 commit 26a5c79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions tools/continuous-delivery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"fs-extra": "9.0.1",
"marked-ast": "0.3.0",
"marked-ast-markdown": "2.1.0",
"p-limit": "4.0.0",
"semver": "5.6.0",
"simple-git": "3.5.0",
"tsm": "2.2.2"
Expand Down
35 changes: 29 additions & 6 deletions tools/continuous-delivery/src/fetchVersionsFromNpm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import axios from 'axios';
import pLimit from 'p-limit';

export const fetchVersionsFromNpm = async () => {
const { data: npmSearchResult } = await axios.get<
{},
{ data: { total: number; objects: { package: { name: string; version: string } }[] } }
{
data: {
total: number;
objects: {
package: {
name: string;
/**
* @deprecated
* NPM hadrly caches search results so version in search result
* may be outdated for several horus
*/
version: string;
};
}[];
};
}
>(`https://registry.npmjs.org/-/v1/search?text=@semcore/&size=250`);

if (npmSearchResult.total !== npmSearchResult.objects.length) {
Expand All @@ -14,11 +30,18 @@ export const fetchVersionsFromNpm = async () => {

const currentVersions: { [packageName: string]: string } = {};

for (const {
package: { name, version },
} of npmSearchResult.objects) {
currentVersions[name] = version;
}
const limit = pLimit(5);
await Promise.all(
npmSearchResult.objects.map(
async ({ package: { name } }) =>
await limit(async () => {
const npmResponse = await axios.get<{ 'dist-tags': { latest: string } }>(
`https://registry.npmjs.org/${name}`,
);
currentVersions[name] = npmResponse.data['dist-tags'].latest;
}),
),
);

return currentVersions;
};

0 comments on commit 26a5c79

Please sign in to comment.