Skip to content

Commit

Permalink
refactor: set content type based on entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Apr 4, 2024
1 parent 4bb993d commit 9a70d79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ app.setNotFoundHandler(async (req, res) => {
if (!minified) {
if (validExt(path)) {
content = Buffer.from(content, 'base64').toString('utf-8')
} else {
} else if (entryPoint.endsWith('ts')) {
contentType = filePathToContentType('.ts')
content = `export * from 'https://deno.re/${user}/${repo}@${tag}${entryPoint}'`
} else {
contentType = filePathToContentType('.js')
content = `export * from 'https://deno.re/${user}/${repo}@${tag}${entryPoint}'`
}
}

Expand Down
16 changes: 13 additions & 3 deletions test/registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ test('specific tag', async () => {
assert.strictEqual(actual, expected)
})

test('omit entry point', async () => {
const actual = await fetchStr('http://localhost:3000/esbuild/[email protected]')
test('omit entry point', async (t) => {
await t.test('js', async () => {
const res = await fetch('http://localhost:3000/esbuild/[email protected]')

assert.strictEqual(actual, `export * from 'https://deno.re/esbuild/[email protected]/mod.js'`)
assert.strictEqual(await res.text(), `export * from 'https://deno.re/esbuild/[email protected]/mod.js'`)
assert.strictEqual(res.headers.get('content-type'), 'text/javascript; charset=utf-8')
})

await t.test('ts', async () => {
const res = await fetch('http://localhost:3000/[email protected]/crypto')

assert.strictEqual(await res.text(), `export * from 'https://deno.re/[email protected]/crypto/mod.ts'`)
assert.strictEqual(res.headers.get('content-type'), 'text/typescript; charset=utf-8')
})
})

test('type header', async () => {
Expand Down

0 comments on commit 9a70d79

Please sign in to comment.