fix: use jsdelivr when npm has a truncated readme#1459
fix: use jsdelivr when npm has a truncated readme#1459danielroe merged 3 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR computes a resolvedVersion (from an explicit version or dist-tag) and adopts a jsDelivr-first strategy to fetch README content for that resolvedVersion (pkg@version). It removes reliance on version-specific readme fields and readmeFilename from the npm packument. If jsDelivr yields no content, it falls back to the packument readme — preferring the versioned packument readme when a specific version was requested, otherwise the top-level packument readme — and excludes sentinel missing values. If no readmeContent is obtained, it returns the packageName, version, and undefined markdown/repoInfo. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
c69847e to
6ed4a8a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6ed4a8a to
bb2d24b
Compare
bb2d24b to
ed04df7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/unit/server/utils/readme-loaders.spec.ts (1)
186-207: Consider adding a test for whenpackageData.versionsis undefined.All current tests provide
versions: {}or with specific entries. Adding a test whereversionsis omitted entirely would help catch potential TypeError regressions when falling back to packument readme for a specific version.🧪 Suggested test case
it('handles undefined versions gracefully when falling back', async () => { fetchNpmPackageMock.mockResolvedValue({ 'readme': '# Top-level readme', 'repository': undefined, // versions intentionally omitted 'dist-tags': { latest: '1.0.0' }, }) parseRepositoryInfoMock.mockReturnValue(undefined) const fetchMock = vi.fn().mockResolvedValue({ ok: false }) vi.stubGlobal('fetch', fetchMock) const result = await resolvePackageReadmeSource('pkg/v/1.0.0') expect(result).toMatchObject({ packageName: 'pkg', version: '1.0.0', markdown: undefined, // falls through since versions?.['1.0.0'] is undefined }) })
ed04df7 to
475ef42
Compare
The npm registry truncates the packument readme field at exactly 65,536 characters, causing large READMEs to render incomplete. Fetch the actual README file from jsDelivr CDN (npm tarball) as the primary source, falling back to the packument field when jsDelivr doesn't have it. Closes npmx-dev#1458
…cated The npm registry truncates the packument readme field at 65,536 characters. When the readme length exceeds 64,000 characters, fetch the full file from jsDelivr CDN instead. Closes npmx-dev#1458
Head branch was pushed to by a user without write access
8b8f782 to
cbba528
Compare
Move the length comparison into the if condition so JS short-circuits past it when the earlier checks already trigger the jsDelivr fetch.
|
Thanks for your first contribution, @lukeocodes! ⭐ We'd love to welcome you to the npmx community. Come and say hi on Discord! And once you've joined, visit npmx.wamellow.com to claim the contributor role. |
Summary
Large READMEs are being cut off because the npm registry silently truncates the
readmefield in packument responses at exactly 65,536 characters. For example,vue-data-uihas an 80KB README but only 64K makes it through.This switches the README handler to fetch the actual file from jsDelivr CDN (which serves from the npm tarball without truncation) as the primary source, keeping the packument
readmefield as a fallback for packages where jsDelivr doesn't have the file.Closes #1458
Test plan
vue-data-ui— full README now renders