nitro-nightly 3.1.0-20251026-232057-ce388de2 → 3.1.0-20251027-232908-e0bb18f2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20217,27 +20217,21 @@ async function snapshotStorage(nitro) {
20217
20217
  return data;
20218
20218
  }
20219
20219
 
20220
- //#region src/object.ts
20221
20220
  const NullProtoObj = /* @__PURE__ */ (() => {
20222
20221
  const e = function() {};
20223
20222
  return e.prototype = Object.create(null), Object.freeze(e.prototype), e;
20224
20223
  })();
20225
20224
 
20226
- //#endregion
20227
- //#region src/context.ts
20228
20225
  /**
20229
20226
  * Create a new router context.
20230
20227
  */
20231
20228
  function createRouter() {
20232
- const ctx = {
20229
+ return {
20233
20230
  root: { key: "" },
20234
20231
  static: new NullProtoObj()
20235
20232
  };
20236
- return ctx;
20237
20233
  }
20238
20234
 
20239
- //#endregion
20240
- //#region src/operations/_utils.ts
20241
20235
  function splitPath(path) {
20242
20236
  const [_, ...s] = path.split("/");
20243
20237
  return s[s.length - 1] === "" ? s.slice(0, -1) : s;
@@ -20255,8 +20249,6 @@ function getMatchParams(segments, paramsMap) {
20255
20249
  return params;
20256
20250
  }
20257
20251
 
20258
- //#endregion
20259
- //#region src/operations/add.ts
20260
20252
  /**
20261
20253
  * Add a route to the router context.
20262
20254
  */
@@ -20325,11 +20317,9 @@ function addRoute(ctx, method = "", path, data) {
20325
20317
  }
20326
20318
  function getParamRegexp(segment) {
20327
20319
  const regex = segment.replace(/:(\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\./g, "\\.");
20328
- return new RegExp(`^${regex}$`);
20320
+ return /* @__PURE__ */ new RegExp(`^${regex}$`);
20329
20321
  }
20330
20322
 
20331
- //#endregion
20332
- //#region src/operations/find.ts
20333
20323
  /**
20334
20324
  * Find a route by path.
20335
20325
  */
@@ -20368,7 +20358,7 @@ function _lookupTree(ctx, node, method, segments, index) {
20368
20358
  if (pMap?.[pMap?.length - 1]?.[2]) return match;
20369
20359
  }
20370
20360
  }
20371
- return void 0;
20361
+ return;
20372
20362
  }
20373
20363
  const segment = segments[index];
20374
20364
  if (node.static) {
@@ -20389,11 +20379,8 @@ function _lookupTree(ctx, node, method, segments, index) {
20389
20379
  }
20390
20380
  }
20391
20381
  if (node.wildcard && node.wildcard.methods) return node.wildcard.methods[method] || node.wildcard.methods[""];
20392
- return;
20393
20382
  }
20394
20383
 
20395
- //#endregion
20396
- //#region src/operations/find-all.ts
20397
20384
  /**
20398
20385
  * Find all route patterns that match the given path.
20399
20386
  */
@@ -20433,7 +20420,6 @@ function _findAll(ctx, node, method, segments, index, matches = []) {
20433
20420
  return matches;
20434
20421
  }
20435
20422
 
20436
- //#region src/compiler.ts
20437
20423
  /**
20438
20424
  * Compiles the router instance into a faster route-matching function.
20439
20425
  *
@@ -20464,17 +20450,16 @@ function _findAll(ctx, node, method, segments, index, matches = []) {
20464
20450
  * // "const findRoute=(m, p) => {}"
20465
20451
  */
20466
20452
  function compileRouterToString(router, functionName, opts) {
20467
- const ctx = {
20453
+ const compiled = `(m,p)=>{${compileRouteMatch({
20468
20454
  opts: opts || {},
20469
20455
  router,
20470
20456
  deps: void 0
20471
- };
20472
- const compiled = `(m,p)=>{${compileRouteMatch(ctx)}}`;
20457
+ })}}`;
20473
20458
  return functionName ? `const ${functionName}=${compiled};` : compiled;
20474
20459
  }
20475
20460
  function compileRouteMatch(ctx) {
20476
20461
  let code = "";
20477
- const staticNodes = new Set();
20462
+ const staticNodes = /* @__PURE__ */ new Set();
20478
20463
  for (const key in ctx.router.static) {
20479
20464
  const node = ctx.router.static[key];
20480
20465
  if (node?.methods) {
@@ -20505,8 +20490,7 @@ function compileFinalMatch(ctx, data, currentIdx, params) {
20505
20490
  const conditions = [];
20506
20491
  const { paramsMap, paramsRegexp } = data;
20507
20492
  if (paramsMap && paramsMap.length > 0) {
20508
- const required = !paramsMap[paramsMap.length - 1][2] && currentIdx !== -1;
20509
- if (required) conditions.push(`l>=${currentIdx}`);
20493
+ if (!paramsMap[paramsMap.length - 1][2] && currentIdx !== -1) conditions.push(`l>=${currentIdx}`);
20510
20494
  for (let i = 0; i < paramsRegexp.length; i++) {
20511
20495
  const regexp = paramsRegexp[i];
20512
20496
  if (!regexp) continue;
@@ -20519,9 +20503,8 @@ function compileFinalMatch(ctx, data, currentIdx, params) {
20519
20503
  }
20520
20504
  ret += "}";
20521
20505
  }
20522
- const code = (conditions.length > 0 ? `if(${conditions.join("&&")})` : "") + (ctx.opts?.matchAll ? `r.unshift(${ret}});` : `return ${ret}};`);
20523
20506
  return {
20524
- code,
20507
+ code: (conditions.length > 0 ? `if(${conditions.join("&&")})` : "") + (ctx.opts?.matchAll ? `r.unshift(${ret}});` : `return ${ret}};`),
20525
20508
  weight: conditions.length
20526
20509
  };
20527
20510
  }
@@ -10350,7 +10350,8 @@ function routing(nitro) {
10350
10350
  "_importHash"
10351
10351
  );
10352
10352
  const h3Imports = [
10353
- (nitro.options.serverEntry || allHandlers.some((h) => !h.lazy)) && "toEventHandler",
10353
+ allHandlers.some((h) => !h.lazy) && "toEventHandler",
10354
+ nitro.options.serverEntry && "toMiddleware",
10354
10355
  allHandlers.some((h) => h.lazy) && "defineLazyEventHandler"
10355
10356
  ].filter(Boolean);
10356
10357
  return (
@@ -10382,11 +10383,10 @@ export const hasRoutedMiddleware = ${nitro.routing.routedMiddleware.hasRoutes()
10382
10383
  export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({ serialize: serializeHandler, matchAll: true })};
10383
10384
 
10384
10385
  export const hasGlobalMiddleware = ${nitro.routing.globalMiddleware.length > 0 || nitro.options.serverEntry ? "true" : "false"};
10385
- export const globalMiddleware = [${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}];
10386
-
10387
- ${nitro.options.serverEntry && /* js */
10388
- `const serverEntry = toEventHandler(__serverEntry__);
10389
- if (serverEntry) { globalMiddleware.push(serverEntry) }`}
10386
+ export const globalMiddleware = [
10387
+ ${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}
10388
+ ${nitro.options.serverEntry ? `,toMiddleware(__serverEntry__)` : ""}
10389
+ ].filter(Boolean);
10390
10390
  `
10391
10391
  );
10392
10392
  },
@@ -1,5 +1,5 @@
1
1
  import "#nitro-internal-pollyfills";
2
2
  declare const _default: {
3
- fetch: any;
3
+ fetch: (req: Request) => any;
4
4
  };
5
5
  export default _default;
@@ -2,5 +2,5 @@ import "#nitro-internal-pollyfills";
2
2
  import { useNitroApp } from "nitro/runtime";
3
3
  const nitroApp = useNitroApp();
4
4
  export default {
5
- fetch: nitroApp.fetch
5
+ fetch: (req) => nitroApp.fetch(req)
6
6
  };
@@ -63,7 +63,7 @@ function createNitroApp() {
63
63
  let fetchHandler = (req) => {
64
64
  req.context ??= {};
65
65
  req.context.nitro = req.context.nitro || { errors: [] };
66
- return h3App.request(req, void 0, req.context);
66
+ return h3App.fetch(req);
67
67
  };
68
68
  if (import.meta._asyncContext) {
69
69
  const originalFetchHandler = fetchHandler;
@@ -101,34 +101,31 @@ function createNitroApp() {
101
101
  }
102
102
  function createH3App(config) {
103
103
  const h3App = new H3Core(config);
104
- if (hasRoutes) {
105
- h3App._findRoute = (event) => findRoute(event.req.method, event.url.pathname);
106
- }
107
- h3App._getMiddleware = (event, route) => {
108
- const needsRouting = hasRouteRules || hasRoutedMiddleware;
109
- const pathname = needsRouting ? event.url.pathname : void 0;
110
- const method = needsRouting ? event.req.method : void 0;
111
- const middleware = [];
112
- if (hasRouteRules) {
113
- const routeRules = getRouteRules(method, pathname);
114
- event.context.routeRules = routeRules?.routeRules;
115
- if (routeRules?.routeRuleMiddleware.length) {
116
- middleware.push(...routeRules.routeRuleMiddleware);
104
+ hasRoutes && (h3App["~findRoute"] = (event) => findRoute(event.req.method, event.url.pathname));
105
+ hasGlobalMiddleware && h3App["~middleware"].push(...globalMiddleware);
106
+ if (hasRouteRules || hasRoutedMiddleware) {
107
+ h3App["~getMiddleware"] = (event, route) => {
108
+ const needsRouting = hasRouteRules || hasRoutedMiddleware;
109
+ const pathname = needsRouting ? event.url.pathname : void 0;
110
+ const method = needsRouting ? event.req.method : void 0;
111
+ const middleware = [];
112
+ if (hasRouteRules) {
113
+ const routeRules = getRouteRules(method, pathname);
114
+ event.context.routeRules = routeRules?.routeRules;
115
+ if (routeRules?.routeRuleMiddleware.length) {
116
+ middleware.push(...routeRules.routeRuleMiddleware);
117
+ }
117
118
  }
118
- }
119
- if (hasGlobalMiddleware) {
120
- middleware.push(...globalMiddleware);
121
- }
122
- if (hasRoutedMiddleware) {
123
- middleware.push(
119
+ hasGlobalMiddleware && middleware.push(...h3App["~middleware"]);
120
+ hasRoutedMiddleware && middleware.push(
124
121
  ...findRoutedMiddleware(method, pathname).map((r) => r.data)
125
122
  );
126
- }
127
- if (route?.data?.middleware?.length) {
128
- middleware.push(...route.data.middleware);
129
- }
130
- return middleware;
131
- };
123
+ if (hasRoutes && route?.data?.middleware?.length) {
124
+ middleware.push(...route.data.middleware);
125
+ }
126
+ return middleware;
127
+ };
128
+ }
132
129
  return h3App;
133
130
  }
134
131
  function getRouteRules(method, pathname) {
@@ -1,7 +1,8 @@
1
1
  import type { HTTPError, HTTPEvent } from "h3";
2
2
  import type { InternalHandlerResponse } from "./utils.mjs";
3
- declare const _default: NitroErrorHandler;
4
- export default _default;
3
+ import type { NitroErrorHandler } from "nitro/types";
4
+ declare const errorHandler: NitroErrorHandler;
5
+ export default errorHandler;
5
6
  export declare function defaultHandler(error: HTTPError, event: HTTPEvent, opts?: {
6
7
  silent?: boolean;
7
8
  json?: boolean;
@@ -1,16 +1,16 @@
1
- import { getRequestURL } from "h3";
2
- import { defineNitroErrorHandler } from "./utils.mjs";
3
1
  import { FastResponse } from "srvx";
4
- export default defineNitroErrorHandler(
5
- function defaultNitroErrorHandler(error, event) {
6
- const res = defaultHandler(error, event);
7
- return new FastResponse(JSON.stringify(res.body, null, 2), res);
8
- }
9
- );
2
+ const errorHandler = (error, event) => {
3
+ const res = defaultHandler(error, event);
4
+ return new FastResponse(
5
+ typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
6
+ res
7
+ );
8
+ };
9
+ export default errorHandler;
10
10
  export function defaultHandler(error, event, opts) {
11
11
  const isSensitive = error.unhandled;
12
12
  const status = error.status || 500;
13
- const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true });
13
+ const url = event.url || new URL(event.req.url);
14
14
  if (status === 404) {
15
15
  const baseURL = import.meta.baseURL || "/";
16
16
  if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
@@ -33,13 +33,9 @@ export function defaultHandler(error, event, opts) {
33
33
  }
34
34
  const headers = {
35
35
  "content-type": "application/json",
36
- // Prevent browser from guessing the MIME types of resources.
37
36
  "x-content-type-options": "nosniff",
38
- // Prevent error page from being embedded in an iframe
39
37
  "x-frame-options": "DENY",
40
- // Prevent browsers from sending the Referer header
41
38
  "referrer-policy": "no-referrer",
42
- // Disable the execution of any js
43
39
  "content-security-policy": "script-src 'none'; frame-ancestors 'none';"
44
40
  };
45
41
  if (status === 404 || !event.res.headers.has("cache-control")) {
@@ -1,3 +1,31 @@
1
- import { H3 } from "h3";
2
- declare const _default: H3;
1
+ declare const _default: {
2
+ "~rou3": import("h3").RouterContext;
3
+ request(request: import("srvx").ServerRequest | URL | string, options?: RequestInit, context?: import("h3").H3EventContext): Response | Promise<Response>;
4
+ use(route: string, handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
5
+ use(handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
6
+ on(method: import("h3").HTTPMethod | Lowercase<import("h3").HTTPMethod> | "", route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
7
+ register(plugin: import("h3").H3Plugin): /*elided*/ any;
8
+ mount(base: string, input: import("srvx").FetchHandler | {
9
+ fetch: import("srvx").FetchHandler;
10
+ } | /*elided*/ any): /*elided*/ any;
11
+ all(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
12
+ get(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
13
+ post(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
14
+ put(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
15
+ delete(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
16
+ patch(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
17
+ head(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
18
+ options(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
19
+ connect(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
20
+ trace(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
21
+ readonly config: import("h3").H3Config;
22
+ "~middleware": import("h3").Middleware[];
23
+ "~routes": import("h3").H3Route[];
24
+ fetch(_request: import("srvx").ServerRequest): Response | Promise<Response>;
25
+ handler(event: import("h3").H3Event): unknown | Promise<unknown>;
26
+ "~request"(request: import("srvx").ServerRequest, context?: import("h3").H3EventContext): Response | Promise<Response>;
27
+ "~findRoute"(_event: import("h3").H3Event): import("h3").MatchedRoute<import("h3").H3Route> | void;
28
+ "~getMiddleware"(event: import("h3").H3Event, route: import("h3").MatchedRoute<import("h3").H3Route> | undefined): import("h3").Middleware[];
29
+ "~addRoute"(_route: import("h3").H3Route): void;
30
+ };
3
31
  export default _default;
@@ -3800,8 +3800,6 @@ interface PrerenderRoute {
3800
3800
  /** @deprecated Internal type will be removed in future versions */
3801
3801
  type PrerenderGenerateRoute = PrerenderRoute;
3802
3802
 
3803
- //#endregion
3804
- //#region src/compiler.d.ts
3805
3803
  interface RouterCompilerOptions<T = any> {
3806
3804
  matchAll?: boolean;
3807
3805
  serialize?: (data: T) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-nightly",
3
- "version": "3.1.0-20251026-232057-ce388de2",
3
+ "version": "3.1.0-20251027-232908-e0bb18f2",
4
4
  "description": "Build and Deploy Universal JavaScript Servers",
5
5
  "homepage": "https://nitro.build",
6
6
  "repository": "nitrojs/nitro",
@@ -58,17 +58,17 @@
58
58
  "db0": "^0.3.4",
59
59
  "esbuild": "^0.25.11",
60
60
  "fetchdts": "^0.1.7",
61
- "h3": "^2.0.1-rc.4",
61
+ "h3": "2.0.1-rc.5",
62
62
  "jiti": "^2.6.1",
63
- "nf3": "^0.1.2",
63
+ "nf3": "^0.1.3",
64
64
  "ofetch": "^1.4.1",
65
65
  "ohash": "^2.0.11",
66
66
  "rendu": "^0.0.6",
67
67
  "rollup": "^4.52.5",
68
68
  "srvx": "^0.9.1",
69
69
  "undici": "^7.16.0",
70
- "unenv": "^2.0.0-rc.22",
71
- "unstorage": "^2.0.0-alpha.3"
70
+ "unenv": "2.0.0-rc.22",
71
+ "unstorage": "2.0.0-alpha.3"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@azure/functions": "^3.5.1",
@@ -86,7 +86,6 @@
86
86
  "@rollup/plugin-replace": "^6.0.2",
87
87
  "@rollup/plugin-terser": "^0.4.4",
88
88
  "@scalar/api-reference": "^1.38.1",
89
- "@types/archiver": "^6.0.4",
90
89
  "@types/aws-lambda": "^8.10.156",
91
90
  "@types/estree": "^1.0.8",
92
91
  "@types/etag": "^1.8.4",
@@ -95,9 +94,9 @@
95
94
  "@types/node": "^24.9.1",
96
95
  "@types/node-fetch": "^2.6.13",
97
96
  "@types/semver": "^7.7.1",
98
- "@types/serve-static": "^1.15.10",
97
+ "@types/serve-static": "^2.2.0",
99
98
  "@types/xml2js": "^0.4.14",
100
- "@vitest/coverage-v8": "^4.0.3",
99
+ "@vitest/coverage-v8": "^4.0.4",
101
100
  "automd": "^0.4.2",
102
101
  "c12": "^3.3.1",
103
102
  "changelogen": "^0.6.2",
@@ -120,12 +119,11 @@
120
119
  "fs-extra": "^11.3.2",
121
120
  "get-port-please": "^3.2.0",
122
121
  "gzip-size": "^7.0.0",
123
- "hookable": "^6.0.0-rc.1",
122
+ "hookable": "6.0.0-rc.1",
124
123
  "httpxy": "^0.1.7",
125
124
  "klona": "^2.0.6",
126
125
  "knitwork": "^1.2.0",
127
126
  "magic-string": "^0.30.21",
128
- "magicast": "^0.3.5",
129
127
  "mime": "^4.1.0",
130
128
  "miniflare": "^4.20251011.1",
131
129
  "mlly": "^1.8.0",
@@ -135,8 +133,8 @@
135
133
  "prettier": "^3.6.2",
136
134
  "pretty-bytes": "^7.1.0",
137
135
  "react": "^19.2.0",
138
- "rolldown": "1.0.0-beta.44",
139
- "rou3": "^0.7.8",
136
+ "rolldown": "1.0.0-beta.45",
137
+ "rou3": "^0.7.9",
140
138
  "scule": "^1.3.0",
141
139
  "semver": "^7.7.3",
142
140
  "serve-placeholder": "^2.0.2",
@@ -154,7 +152,7 @@
154
152
  "unplugin-utils": "^0.3.1",
155
153
  "untyped": "^2.0.0",
156
154
  "unwasm": "^0.3.11",
157
- "vitest": "^4.0.3",
155
+ "vitest": "^4.0.4",
158
156
  "wrangler": "^4.45.0",
159
157
  "xml2js": "^0.6.2",
160
158
  "youch": "4.1.0-beta.11",