Skip to content

Commit 40bddff

Browse files
pi0Copilot
andcommitted
refactor: split plugin definition
allows better dist bundling Co-authored-by: Copilot <copilot@github.com>
1 parent a94b7fb commit 40bddff

6 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎src/h3.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { callMiddleware, normalizeMiddleware } from "./middleware.ts";
55
import{requestWithBaseURL}from"./utils/request.ts";
66

77
importtype{ServerRequest}from"srvx";
8-
importtype{H3Config,H3CoreConfig,H3Plugin,MatchedRoute,RouterContext}from"./types/h3.ts";
8+
importtype{H3Config,H3CoreConfig,MatchedRoute,RouterContext}from"./types/h3.ts";
9+
importtype{H3Plugin}from"./plugin.ts";
910
importtype{H3EventContext}from"./types/context.ts";
1011
importtype{
1112
EventHandler,

‎src/index.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exporttype{
44
H3Config,
55
H3CoreConfig,
6-
H3Plugin,
76
H3Route,
87
H3RouteMeta,
98
HTTPMethod,
@@ -14,10 +13,13 @@ export type {
1413
MatchedRoute,
1514
}from"./types/h3.ts";
1615

17-
export{definePlugin}from"./types/h3.ts";
18-
1916
export{H3Core,H3}from"./h3.ts";
2017

18+
// Plugins
19+
20+
exporttype{H3Plugin}from"./plugin.ts";
21+
export{definePlugin}from"./plugin.ts";
22+
2123
// Event
2224

2325
exporttype{H3EventContext}from"./types/context.ts";

‎src/plugin.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
importtype{H3}from"./h3.ts";
2+
3+
exporttypeH3Plugin=(h3: H3)=>void;
4+
5+
exportfunctiondefinePlugin<T=unknown>(
6+
def: (h3: H3,options: T)=>void,
7+
): undefinedextendsT ? (options?: T)=>H3Plugin : (options: T)=>H3Plugin{
8+
return((opts?: any)=>(h3: H3)=>def(h3,opts))asany;
9+
}

‎src/tracing.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importtype{H3Event}from"./event.ts";
22
importtype{H3,H3Core}from"./h3.ts";
3-
import{typeH3Plugin,typeH3Route,typeMiddlewareOptions}from"./types/h3.ts";
3+
importtype{H3Plugin}from"./plugin.ts";
4+
importtype{H3Route,MiddlewareOptions}from"./types/h3.ts";
45
importtype{EventHandler,Middleware}from"./types/handler.ts";
56

67
/**

‎src/types/h3.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MaybePromise } from "./_utils.ts";
55
importtype{FetchHandler,ServerRequest}from"srvx";
66
// import type { MatchedRoute, RouterContext } from "rou3";
77
importtype{H3Event}from"../event.ts";
8+
importtype{H3Plugin}from"../plugin.ts";
89

910
// Inlined from rou3 for type portability
1011
exportinterfaceRouterContext{
@@ -57,16 +58,6 @@ export interface H3Route {
5758
handler: EventHandler;
5859
}
5960

60-
// --- H3 Plugins ---
61-
62-
exporttypeH3Plugin=(h3: H3)=>void;
63-
64-
exportfunctiondefinePlugin<T=unknown>(
65-
def: (h3: H3,options: T)=>void,
66-
): undefinedextendsT ? (options?: T)=>H3Plugin : (options: T)=>H3Plugin{
67-
return((opts?: any)=>(h3: H3)=>def(h3,opts))asany;
68-
}
69-
7061
// --- H3 App ---
7162

7263
exporttypeRouteOptions={

‎src/utils/route.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importtype{H3RouteMeta,HTTPMethod}from"../types/h3.ts";
22
importtype{EventHandler,Middleware}from"../types/handler.ts";
3-
importtype{H3Plugin,H3}from"../types/h3.ts";
3+
importtype{H3}from"../types/h3.ts";
4+
importtype{H3Plugin}from"../plugin.ts";
45
importtype{StandardSchemaV1}from"./internal/standard-schema.ts";
56
import{removeRouteas_removeRoute}from"rou3";
67
import{defineValidatedHandler}from"../handler.ts";

0 commit comments

Comments
 (0)