Skip to content

Commit

Permalink
fix: getLatestMeta fallbacks to npm manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 19, 2023
1 parent f6c08a9 commit eae8771
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/js/api/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions src/main/js/processor/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}

0 comments on commit eae8771

Please sign in to comment.