-
Notifications
You must be signed in to change notification settings - Fork 91
fix: (docgen) get types from more than just main entrypoint, fail gracefully-er #240
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
base: main
Are you sure you want to change the base?
fix: (docgen) get types from more than just main entrypoint, fail gracefully-er #240
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
well this works but by gawd is it slow for some repos with many subpath exports with types (like took maybe 20s for nuxt) |
| /** | ||
| * Extract types URLs from pre-fetched package exports. | ||
| */ | ||
| async function getSubpathTypesUrlsFromExports( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bottleneck. Going to think if there's a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather, it's a bottleneck that we have to run deno doc potentially on a bunch of subpath exports.
| } | ||
|
|
||
| const versionData = packument.versions?.[version] | ||
| const exports = versionData?.exports as Record<string, unknown> | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember exports can also be a string (one entrypoint so exports: "./foo.js" is like exports: {".": "./foo.js"} iirc)
Overview
(WIP)Noticed that I'm missing types for packages that have types spread across multiple entrypoints.
I wanted to address that here, as well as better explain what is happening at a high level. I will move this into the docs site later.
What is changing here
Before this only generated docs for the main types entrypoint for a given package, which works surprisingly well for most packages.
After this change it will do that for all subpath exports (max 10 until I can verify this isn't going to be crazy) that have
.d.tsentrypoints given to us by the esm x-typescript-types header (which is a fancy thing they have for helping with this that I use here.Limitations
lodash-eswill have many moreHigh level overview
The "docgen" system is a pipeline that transforms npm package types into rendered HTML documentation:
API Request → Types URL Discovery → @deno/doc WASM → Node Processing → HTML Rendering → Cached
Response
In more detail:
server/api/registry/docs/[...pkg].get.ts:7-70)server/utils/docs/index.ts:34-55)server/utils/docs/client.ts:67-138)esm.sh/{pkg}@{version}-> reads x-typescript-types header→ queries esm.sh for each subpath's types URL
server/utils/docs/client.ts:42-45)createLoader()to fetch modules via HTTPcreateResolver()to resolve imports (relative paths, bare specifiers via esm.sh)server/utils/docs/client.ts:157-212)server/utils/docs/processing.ts)flattenNamespaces(): Inlines namespace members (e.g., Utils.foo())mergeOverloads(): Groups function overloads, picks best JSDocbuildSymbolLookup(): Creates map for cross-reference linksserver/utils/docs/render.ts)