feat(helper/adapter): add `runtime` option to `env` (#1622)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* feat(helper/adapter): add `runtime` option to `env` * denoify
authored by Yusuke Wada · committed by GitHub · parent 0bc72b8 · Browse files · 4 files·+28 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+28 added−6 removed
- other:+28 added−6 removed
Provenance
- Commit
3ead9a7- Tree
9a35e70- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
0bc72b8
4 files changed+28 added−6 removed
modified:deno_dist/helper/adapter/index.ts+13 added-2 removed
1234567891011121341415161718192010212223242530 unmodified linesimport type { Context } from '../../context.ts'
export type Runtime = | 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other'
export const env = <T extends Record<string, string>, C extends Context = Context<{}>>( c: C c: C, runtime?: Runtime): T & C['env'] => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const global = globalThis as any const globalEnv = global?.process?.env as T
const runtime = getRuntimeKey() runtime ??= getRuntimeKey()
const runtimeEnvHandlers: Record<string, () => T> = { bun: () => globalEnv, node: () => globalEnv,30 unmodified linesmodified:deno_dist/context.ts+1 added-1 removed
1+import type { Runtime } from './helper/adapter/index.ts'2 import type { HonoRequest } from './request.ts'3 import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types.ts'4 import type { CookieOptions } from './utils/cookie.ts'5 import { serialize } from './utils/cookie.ts'6 import type { StatusCode } from './utils/http-status.ts'7 import { StreamingApi } from './utils/stream.ts'8 import type { JSONValue, InterfaceToType } from './utils/types.ts'9 9-type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other'10 type HeaderRecord = Record<string, string | string[]>11 type Data = string | ArrayBuffer | ReadableStream12 13 export interface ExecutionContext {458 unmodified linesmodified:src/helper/adapter/index.ts+13 added-2 removed
1234567891011121341415161718192010212223242530 unmodified linesimport type { Context } from '../../context'
export type Runtime = | 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other'
export const env = <T extends Record<string, string>, C extends Context = Context<{}>>( c: C c: C, runtime?: Runtime): T & C['env'] => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const global = globalThis as any const globalEnv = global?.process?.env as T
const runtime = getRuntimeKey() runtime ??= getRuntimeKey()
const runtimeEnvHandlers: Record<string, () => T> = { bun: () => globalEnv, node: () => globalEnv,30 unmodified linesmodified:src/context.ts+1 added-1 removed
1+import type { Runtime } from './helper/adapter'2 import type { HonoRequest } from './request'3 import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types'4 import type { CookieOptions } from './utils/cookie'5 import { serialize } from './utils/cookie'6 import type { StatusCode } from './utils/http-status'7 import { StreamingApi } from './utils/stream'8 import type { JSONValue, InterfaceToType } from './utils/types'9 9-type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other'10 type HeaderRecord = Record<string, string | string[]>11 type Data = string | ArrayBuffer | ReadableStream12 13 export interface ExecutionContext {458 unmodified lines