Skip to content
Myr

ts-resolve.mjs

This file

Path

benchmarks/fetch/ts-resolve.mjs

26 lines · 878 bytes · JavaScript

Last changed by

chore(benchmark): add app.fetch() overhead benchmark (#5117)Yusuke Wadabefore adoptionc285f9a

History of this file

Take it

chore(benchmark): add app.fetch() overhead benchmark (#5117)Yusuke Wadabefore adoptionc285f9a

lines 1–26why, one step back
1// Resolve extensionless TypeScript imports (e.g. `./request` -> `./request.ts`)
2// so that Node's built-in type stripping can run hono's src directly.3// Import this once at the top of a bench file, then load hono via dynamic import().4// No-op on Bun, which resolves extensionless imports natively.5import * as mod from 'node:module'67if (typeof mod.registerHooks === 'function') {8 mod.registerHooks({9 resolve(specifier, context, nextResolve) {10 try {11 return nextResolve(specifier, context)12 } catch (err) {13 if (specifier.startsWith('.') || specifier.startsWith('file:')) {14 for (const suffix of ['.ts', '/index.ts']) {15 try {16 return nextResolve(specifier + suffix, context)17 } catch {18 // try the next suffix19 }20 }21 }22 throw err23 }24 },25 })26}