feat(wip): add per-entrypoint API docs pages for multi-export packages#1728
feat(wip): add per-entrypoint API docs pages for multi-export packages#1728
Conversation
Packages with only subpath exports (no root export) previously got no
docs because esm.sh returns 404 for their root URL. Fix by falling back
to the npm registry field to discover typed subpath entries.
Additionally, multi-entrypoint packages now get separate docs pages per
subpath with an EntrypointSelector dropdown, instead of dumping all
symbols into one flat page. The base URL redirects to the first
entrypoint.
URL structure: /package-docs/{pkg}/v/{version}/{entrypoint}
Closes #1479
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
|
||
| // Mock encodePackageName | ||
| vi.mock('#shared/utils/npm', () => ({ | ||
| encodePackageName: (name: string) => name.replace('/', '%2f'), |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High documentation test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, when escaping or encoding characters with String.prototype.replace, use a regular expression with the global (g) flag so that all occurrences are replaced, not just the first one. For URL-style encoding of all / characters, the pattern should be /\//g.
For this specific case, update the mocked encodePackageName implementation in test/unit/server/utils/docs/client.spec.ts so that it replaces every / in name, not just the first. Change:
- Line 11 from
name.replace('/', '%2f') - To
name.replace(/\//g, '%2f')
No additional imports or helper methods are required; this uses built-in JavaScript regex support. This preserves existing behavior for inputs with zero or one /, while correctly handling inputs with multiple / characters.
| @@ -8,7 +8,7 @@ | ||
|
|
||
| // Mock encodePackageName | ||
| vi.mock('#shared/utils/npm', () => ({ | ||
| encodePackageName: (name: string) => name.replace('/', '%2f'), | ||
| encodePackageName: (name: string) => name.replace(/\//g, '%2f'), | ||
| })) | ||
|
|
||
| // Mock Nitro globals before importing the module. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🔗 Linked issue
Fixes #1479
🧭 Context
Packages with only subpath exports (no
.export) previously got no docs because esm.sh (our source of truth for this) returns 404 for their root URL.📚 Description
Fall back to the npm registry
exportsfield to discover typed subpath entries.Additionally, multi-entrypoint packages now get separate docs pages per subpath with an entrypoint selector dropdown, as dumping all symbols into one flat page would be misleading. The base URL redirects to the "first" entrypoint (arbitrary).
The route now looks like
/package-docs/:pkg/v/:version/:entrypoint.Warning
Don't look at the diff. This was a quick AI spike to play with the approach 😶.