From 3938f308a1fad83d8bf023eebe764c6569bac75f Mon Sep 17 00:00:00 2001 From: Jacek Puchta Date: Thu, 26 Oct 2023 12:24:02 +0200 Subject: [PATCH] Improved fetching license information for npm packages Signed-off-by: Jacek Puchta --- utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils.js b/utils.js index 4ea712e642..fa35f62290 100644 --- a/utils.js +++ b/utils.js @@ -330,8 +330,11 @@ export const getNpmMetadata = async function (pkgList) { body = res.body; metadata_cache[key] = body; } - p.description = body.description; - p.license = body.license; + p.description = body.versions?.[p.version]?.description || body.description; + p.license = + body.versions?.[p.version]?.license || + body.license || + (await getRepoLicense(body.repository?.url, undefined)); if (body.repository && body.repository.url) { p.repository = { url: body.repository.url }; } @@ -3095,6 +3098,9 @@ export const getRepoLicense = async function (repoUrl, repoMetadata) { if (!repoUrl) { repoUrl = toGitHubUrl(repoMetadata); } + if (repoUrl.startsWith("git://") && repoUrl.endsWith(".git")) { + repoUrl = repoUrl.replace("git://", "https://").slice(0, -4); + } // Perform github lookups if (repoUrl.indexOf("github.com") > -1) { let apiUrl = repoUrl.replace(