Skip to content

Commit d06b90b

Browse files
committed
refactor: use isolated declaration for runtime
1 parent 5fc63f0 commit d06b90b

File tree

16 files changed

+51
-35
lines changed

16 files changed

+51
-35
lines changed

build.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default defineBuildConfig({
4040
input: "src/presets/",
4141
outDir: "dist/presets",
4242
filter: (id) => id.includes("runtime/"),
43+
dts: false,
4344
},
4445
],
4546
hooks: {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"miniflare": "^4.20260217.0",
137137
"mlly": "^1.8.0",
138138
"nypm": "^0.6.5",
139-
"obuild": "^0.4.28",
139+
"obuild": "^0.4.31",
140140
"oxfmt": "^0.33.0",
141141
"oxlint": "^1.48.0",
142142
"pathe": "^2.0.3",
@@ -200,8 +200,8 @@
200200
},
201201
"resolutions": {
202202
"nitro": "link:.",
203-
"vite": "8.0.0-beta.14",
204-
"rolldown": "^1.0.0-rc.5"
203+
"rolldown": "^1.0.0-rc.5",
204+
"vite": "8.0.0-beta.14"
205205
},
206206
"engines": {
207207
"node": "^20.19.0 || >=22.12.0"

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/internal/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { ServerRequest } from "srvx";
33

44
import { AsyncLocalStorage } from "node:async_hooks";
55
import { HTTPError } from "h3";
6-
import { getContext } from "unctx";
6+
import { getContext, type UseContext } from "unctx";
77

8-
export const nitroAsyncContext = /* @__PURE__ */ (() =>
8+
export const nitroAsyncContext: UseContext<NitroAsyncContext> = /* @__PURE__ */ (() =>
99
getContext<NitroAsyncContext>("nitro-app", {
1010
asyncContext: import.meta._asyncContext,
1111
AsyncLocalStorage: import.meta._asyncContext ? AsyncLocalStorage : undefined,

src/runtime/internal/error/dev.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ import { SourceMapConsumer } from "source-map";
99
import { defineNitroErrorHandler } from "./utils.ts";
1010
import type { InternalHandlerResponse } from "./utils.ts";
1111
import { FastResponse } from "srvx";
12+
import type { NitroErrorHandler } from "nitro/types";
13+
14+
const errorHandler: NitroErrorHandler = defineNitroErrorHandler(
15+
async function defaultNitroErrorHandler(error, event) {
16+
const res = await defaultHandler(error, event);
17+
return new FastResponse(
18+
typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
19+
res
20+
);
21+
}
22+
);
1223

13-
export default defineNitroErrorHandler(async function defaultNitroErrorHandler(error, event) {
14-
const res = await defaultHandler(error, event);
15-
return new FastResponse(
16-
typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
17-
res
18-
);
19-
});
24+
export default errorHandler;
2025

2126
export async function defaultHandler(
2227
error: HTTPError,
@@ -106,7 +111,7 @@ export async function defaultHandler(
106111

107112
// ---- Source Map support ----
108113

109-
export async function loadStackTrace(error: any) {
114+
export async function loadStackTrace(error: any): Promise<void> {
110115
if (!(error instanceof Error)) {
111116
return;
112117
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useNitroApp } from "../app.ts";
22

3-
function _captureError(error: Error, type: string) {
3+
function _captureError(error: Error, type: string): void {
44
console.error(`[${type}]`, error);
55
useNitroApp().captureError?.(error, { tags: [type] });
66
}
77

8-
export function trapUnhandledErrors() {
8+
export function trapUnhandledErrors(): void {
99
process.on("unhandledRejection", (error: Error) => _captureError(error, "unhandledRejection"));
1010
process.on("uncaughtException", (error: Error) => _captureError(error, "uncaughtException"));
1111
}

src/runtime/internal/meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NitroRouteMeta } from "nitro/types";
22

3-
export function defineRouteMeta(meta: NitroRouteMeta) {
3+
export function defineRouteMeta(meta: NitroRouteMeta): NitroRouteMeta {
44
return meta;
55
}

src/runtime/internal/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NitroAppPlugin } from "nitro/types";
22

3-
export function defineNitroPlugin(def: NitroAppPlugin) {
3+
export function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin {
44
return def;
55
}
66

7-
export const nitroPlugin = defineNitroPlugin;
7+
export const nitroPlugin: (def: NitroAppPlugin) => NitroAppPlugin = defineNitroPlugin;

src/runtime/internal/route-rules.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { defineCachedHandler } from "./cache.ts";
99
type RouteRuleCtor<T extends keyof NitroRouteRules> = (m: MatchedRouteRule<T>) => Middleware;
1010

1111
// Headers route rule
12-
export const headers = ((m) =>
12+
export const headers: RouteRuleCtor<"headers"> = ((m) =>
1313
function headersRouteRule(event) {
1414
for (const [key, value] of Object.entries(m.options || {})) {
1515
event.res.headers.set(key, value);
1616
}
1717
}) satisfies RouteRuleCtor<"headers">;
1818

1919
// Redirect route rule
20-
export const redirect = ((m) =>
20+
export const redirect: RouteRuleCtor<"redirect"> = ((m) =>
2121
function redirectRouteRule(event) {
2222
let target = m.options?.to;
2323
if (!target) {
@@ -37,7 +37,7 @@ export const redirect = ((m) =>
3737
}) satisfies RouteRuleCtor<"redirect">;
3838

3939
// Proxy route rule
40-
export const proxy = ((m) =>
40+
export const proxy: RouteRuleCtor<"proxy"> = ((m) =>
4141
function proxyRouteRule(event) {
4242
let target = m.options?.to;
4343
if (!target) {
@@ -59,7 +59,7 @@ export const proxy = ((m) =>
5959
}) satisfies RouteRuleCtor<"proxy">;
6060

6161
// Cache route rule
62-
export const cache = ((m) =>
62+
export const cache: RouteRuleCtor<"cache"> = ((m) =>
6363
function cacheRouteRule(event, next) {
6464
if (!event.context.matchedRoute) {
6565
return next();

src/runtime/internal/routes/dev-tasks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { runTask } from "../task.ts";
33

44
import { scheduledTasks, tasks } from "#nitro/virtual/tasks";
55

6-
export default new H3()
6+
const app: H3 = new H3()
77
.get("/_nitro/tasks", async () => {
88
const _tasks = await Promise.all(
99
Object.entries(tasks).map(async ([name, task]) => {
@@ -28,3 +28,5 @@ export default new H3()
2828
payload,
2929
});
3030
});
31+
32+
export default app;

0 commit comments

Comments
 (0)