kopia lustrzana https://github.com/badgen/badgen.net
* badge(npm): recognize index.d.ts for types (resolve #355) * badge(npm): fix type detectionpull/367/head
rodzic
1bd20caabe
commit
c835fbdeb7
58
api/npm.ts
58
api/npm.ts
|
@ -163,30 +163,44 @@ const parseDependents = (html: string) => {
|
|||
}
|
||||
|
||||
async function typesDefinition(pkg: string, tag = 'latest') {
|
||||
let meta = await pkgJson(pkg, tag)
|
||||
|
||||
if (typeof meta.types === 'string' || typeof meta.typings === "string") {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: 'included',
|
||||
color: '0074c1'
|
||||
}
|
||||
}
|
||||
|
||||
const typesPkg = '@types/' + (pkg.charAt(0) === "@" ? pkg.slice(1).replace('/', '__') : pkg)
|
||||
meta = await pkgJson(typesPkg).catch(err => false)
|
||||
|
||||
if (meta && meta.name === typesPkg) {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: meta.name,
|
||||
color: 'cyan',
|
||||
}
|
||||
}
|
||||
let meta = await pkgJson(pkg, tag)
|
||||
|
||||
if (typeof meta.types === 'string' || typeof meta.typings === "string") {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: 'missing',
|
||||
color: 'orange',
|
||||
status: 'included',
|
||||
color: '0074c1'
|
||||
}
|
||||
}
|
||||
|
||||
const hasIndexDTSFile = await got.head(`https://unpkg.com/${pkg}/index.d.ts`)
|
||||
.then(res => res.statusCode === 200)
|
||||
.catch(e => false)
|
||||
|
||||
console.log(hasIndexDTSFile)
|
||||
|
||||
if (hasIndexDTSFile) {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: 'included',
|
||||
color: '0074c1'
|
||||
}
|
||||
}
|
||||
|
||||
const typesPkg = '@types/' + (pkg.charAt(0) === "@" ? pkg.slice(1).replace('/', '__') : pkg)
|
||||
meta = await pkgJson(typesPkg).catch(e => false)
|
||||
|
||||
if (meta?.name === typesPkg) {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: meta.name,
|
||||
color: 'cyan',
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
subject: 'types',
|
||||
status: 'missing',
|
||||
color: 'orange',
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue