diff --git a/api/npm.ts b/api/npm.ts index 6d3894d..965ce1a 100644 --- a/api/npm.ts +++ b/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', + } }