From eae877103df33b6b96d20924f7ff8cd4825b8877 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 19 Dec 2023 21:48:15 +0300 Subject: [PATCH] fix: getLatestMeta fallbacks to npm manifest --- src/main/js/api/npm.js | 2 +- src/main/js/processor/meta.js | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/js/api/npm.js b/src/main/js/api/npm.js index a5e7ea3..5336814 100644 --- a/src/main/js/api/npm.js +++ b/src/main/js/api/npm.js @@ -38,7 +38,7 @@ export const fetchPkg = async (pkg) => { export const fetchManifest = async (pkg, {nothrow} = {}) => { const {npmRegistry, npmToken, npmConfig} = pkg.config const bearerToken = getBearerToken(npmRegistry, npmToken, npmConfig) - const url = getManifestUrl(npmRegistry, pkg.name, pkg.version || 'latest') + const url = getManifestUrl(npmRegistry, pkg.name.replace('/', '%2f'), pkg.version || 'latest') const reqOpts = bearerToken ? {headers: {authorization: bearerToken}} : {} try { diff --git a/src/main/js/processor/meta.js b/src/main/js/processor/meta.js index 7b069ad..d524279 100644 --- a/src/main/js/processor/meta.js +++ b/src/main/js/processor/meta.js @@ -216,22 +216,22 @@ export const parseDateTag = (date) => new Date(date.replaceAll('.', '-')+'Z') export const getArtifactPath = (tag) => tag.toLowerCase().replace(/[^a-z0-9-]/g, '-') export const getLatestMeta = async (pkg, tag) => { - if (!tag) return - - const {absPath: cwd, config: {ghBasicAuth: basicAuth}} = pkg - const {repoName} = await getRepo(cwd, {basicAuth}) - - try { - return JSON.parse(await ghGetAsset({repoName, tag, name: 'meta.json'})) - } catch {} - - try { - const _cwd = await fetchRepo({cwd, branch: 'meta', basicAuth}) - return await Promise.any([ - fs.readJson(path.resolve(_cwd, `${getArtifactPath(tag)}.json`)), - fs.readJson(path.resolve(_cwd, getArtifactPath(tag), 'meta.json')) - ]) - } catch {} + if (tag) { + const {absPath: cwd, config: {ghBasicAuth: basicAuth}} = pkg + const {repoName} = await getRepo(cwd, {basicAuth}) + + try { + return JSON.parse(await ghGetAsset({repoName, tag, name: 'meta.json'})) + } catch {} + + try { + const _cwd = await fetchRepo({cwd, branch: 'meta', basicAuth}) + return await Promise.any([ + fs.readJson(path.resolve(_cwd, `${getArtifactPath(tag)}.json`)), + fs.readJson(path.resolve(_cwd, getArtifactPath(tag), 'meta.json')) + ]) + } catch {} + } return fetchManifest(pkg, {nothrow: true}) }