badge(npm): recognize index.d.ts for types (resolve #355) (#366)

* badge(npm): recognize index.d.ts for types (resolve #355)
* badge(npm): fix type detection
pull/367/head
晋晓炜 Amio / 2020-03-24 23:11:38 +08:00 zatwierdzone przez GitHub
rodzic 1bd20caabe
commit c835fbdeb7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 36 dodań i 22 usunięć

Wyświetl plik

@ -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',
}
}