-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm type support not working for main field in package.json is not index.js #510
Comments
Peek inside According to TypeScript publishing documentation there is no way for other tools to discover included typings because they aren't properly advertised. As a result official typings search tool also fails to discover it: https://www.typescriptlang.org/dt/search?search=markdown-read I don't think this is a badgen.net bug, try adding |
Typescriptlang and npmjs.com both discover included typings. It's main field is links:
// https://github.com/badgen/badgen.net/blob/master/api/npm.ts#L194
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 hasIndexDTSFile = await got.head(`https://unpkg.com/${pkg}/index.d.ts`)
.then(res => res.statusCode === 200)
.catch(e => false)
if (hasIndexDTSFile) {
return {
subject: 'types',
status: 'included',
color: '0074c1'
}
}
// ... other code
} |
Ok, let me first start with saying that I really appreciate constructive answers backed with factual research, big kudos for that 👍 However, here is the thing, correct me if I'm wrong but both typescriptlang.org type search server component and npm's server API aren't opensource so we can't really peek into it and see how they resolve typings. Alternatively, we might do either:
and I'm kind of reluctant to do any of those two things due to the following reasons. Your approach is sound but is something you came up with, it isn't backed by spec or precedence in other words it is non-standard and we should avoid those things if we can. OTOH shields.io folks are essentially playing the guessing game and it is too easy to trick that check. What I would like to do instead is to reuse the typescript's own resolution algorithm. I'm guessing that logic we need to extract is buried somewhere inside this code: https://github.com/microsoft/TypeScript/blob/v4.2.2/src/compiler/moduleNameResolver.ts If you have few free cycles to burn any help is more than welcome. |
For example: https://badgen.net/npm/types/markdown-read
The text was updated successfully, but these errors were encountered: