Skip to content

Commit c975020

Browse files
committed
fix: resolve TypeScript errors in markdown utilities
1 parent 4f66bb1 commit c975020

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

server/middleware/markdown.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,20 @@ async function handleMarkdownRequest(packagePath: string): Promise<string> {
149149
targetVersion = packageData['dist-tags']?.latest
150150
}
151151

152-
if (!targetVersion || !packageData.versions[targetVersion]) {
152+
if (!targetVersion) {
153153
throw createError({
154154
statusCode: 404,
155155
statusMessage: 'Package version not found',
156156
})
157157
}
158158

159159
const versionData = packageData.versions[targetVersion]
160+
if (!versionData) {
161+
throw createError({
162+
statusCode: 404,
163+
statusMessage: 'Package version not found',
164+
})
165+
}
160166

161167
let readmeContent: string | undefined
162168

server/utils/markdown.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Packument, PackumentVersion } from '#shared/types'
22
import type { RepositoryInfo } from '#shared/utils/git-providers'
33
import { joinURL } from 'ufo'
44

5-
const SPARKLINE_CHARS = [' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']
5+
const SPARKLINE_CHARS = [' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'] as const
66
const MAX_README_SIZE = 500 * 1024 // 500KB, matching MAX_FILE_SIZE in file API
77

88
export function generateSparkline(data: number[]): string {
@@ -247,9 +247,11 @@ export function generatePackageMarkdown(options: PackageMarkdownOptions): string
247247
lines.push('## Maintainers')
248248
lines.push('')
249249
for (const maintainer of pkg.maintainers.slice(0, 10)) {
250-
const name = maintainer.name || maintainer.username || 'Unknown'
251-
if (maintainer.username) {
252-
lines.push(`- [${name}](https://www.npmjs.com/~${maintainer.username})`)
250+
// npm API returns username but @npm/types Contact doesn't include it
251+
const username = (maintainer as { username?: string }).username
252+
const name = maintainer.name || username || 'Unknown'
253+
if (username) {
254+
lines.push(`- [${name}](https://www.npmjs.com/~${username})`)
253255
} else {
254256
lines.push(`- ${name}`)
255257
}

0 commit comments

Comments
 (0)