Skip to content

Commit

Permalink
chore: manually apply changes from #2524 to main
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 13, 2024
1 parent 0bd61f1 commit 1c220ef
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/core/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runtimeDir } from "nitro/runtime/meta";
import type { NitroConfig } from "nitro/types";
import { resolve } from "pathe";
import { join } from "pathe";
import { isDebug, isTest } from "std-env";

export const NitroDefaults: NitroConfig = {
Expand Down Expand Up @@ -58,8 +59,7 @@ export const NitroDefaults: NitroConfig = {
baseURL: process.env.NITRO_APP_BASE_URL || "/",
handlers: [],
devHandlers: [],
// errorHandler: "nitro/runtime/internal/error",
errorHandler: "#internal/nitro/internal/error",
errorHandler: join(runtimeDir, "internal/error"),
routeRules: {},
prerender: {
autoSubfolderIndex: true,
Expand Down
8 changes: 5 additions & 3 deletions src/core/config/resolvers/open-api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { runtimeDir } from "nitro/runtime/meta";
import type { NitroOptions } from "nitro/types";
import { join } from "pathe";

export async function resolveOpenAPIOptions(options: NitroOptions) {
if (options.dev && options.experimental.openAPI) {
options.handlers.push({
route: "/_nitro/openapi.json",
handler: "nitro/runtime/internal/routes/openapi",
handler: join(runtimeDir, "internal/routes/openapi"),
});
options.handlers.push({
route: "/_nitro/scalar",
handler: "nitro/runtime/internal/routes/scalar",
handler: join(runtimeDir, "internal/routes/scalar"),
});
options.handlers.push({
route: "/_nitro/swagger",
handler: "nitro/runtime/internal/routes/swagger",
handler: join(runtimeDir, "internal/routes/swagger"),
});
}
}
6 changes: 4 additions & 2 deletions src/core/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { consola } from "consola";
import { createDebugger, createHooks } from "hookable";
import { runtimeDir } from "nitro/runtime/meta";
import type {
LoadConfigOptions,
Nitro,
NitroConfig,
NitroDynamicConfig,
} from "nitro/types";
import { join } from "pathe";
import { createUnimport } from "unimport";
import { loadOptions } from "./config/loader";
import { updateNitroConfig } from "./config/update";
Expand Down Expand Up @@ -48,10 +50,10 @@ export async function createNitro(
// Debug and timing
if (nitro.options.debug) {
createDebugger(nitro.hooks, { tag: "nitro" });
nitro.options.plugins.push("nitro/runtime/internal/debug");
nitro.options.plugins.push(join(runtimeDir, "internal/debug"));
}
if (nitro.options.timing) {
nitro.options.plugins.push("nitro/runtime/internal/timing");
nitro.options.plugins.push(join(runtimeDir, "internal/timing"));
}

// Logger
Expand Down
8 changes: 5 additions & 3 deletions src/presets/_nitro/runtime/nitro-dev.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { runTask } from "nitro/runtime/internal/task";
import { startScheduleRunner } from "nitro/runtime/internal/task";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal/utils";
import { runTask } from "nitro/runtime";
import {
startScheduleRunner,
trapUnhandledNodeErrors,
} from "nitro/runtime/internal";
import { scheduledTasks, tasks } from "#nitro-internal-virtual/tasks";

import { mkdirSync } from "node:fs";
Expand Down
2 changes: 1 addition & 1 deletion src/presets/_nitro/runtime/nitro-prerenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal/utils";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal";

const nitroApp = useNitroApp();

Expand Down
2 changes: 1 addition & 1 deletion src/presets/aws-lambda/runtime/aws-lambda-streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNitroApp } from "nitro/runtime";
import {
normalizeLambdaIncomingHeaders,
normalizeLambdaOutgoingHeaders,
} from "nitro/runtime/internal/utils.lambda";
} from "nitro/runtime/internal";
import { withQuery } from "ufo";

declare global {
Expand Down
3 changes: 1 addition & 2 deletions src/presets/aws-lambda/runtime/aws-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import type {
} from "aws-lambda";
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { normalizeCookieHeader } from "nitro/runtime/internal/utils";
import {
normalizeCookieHeader,
normalizeLambdaIncomingHeaders,
normalizeLambdaOutgoingBody,
normalizeLambdaOutgoingHeaders,
} from "nitro/runtime/internal/utils.lambda";
} from "nitro/runtime/internal";
import { withQuery } from "ufo";

const nitroApp = useNitroApp();
Expand Down
6 changes: 4 additions & 2 deletions src/presets/azure/runtime/azure-functions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { getAzureParsedCookiesFromHeaders } from "nitro/runtime/internal/utils.azure";
import { normalizeLambdaOutgoingHeaders } from "nitro/runtime/internal/utils.lambda";
import {
getAzureParsedCookiesFromHeaders,
normalizeLambdaOutgoingHeaders,
} from "nitro/runtime/internal";

import type { HttpRequest, HttpResponse } from "@azure/functions";

Expand Down
6 changes: 4 additions & 2 deletions src/presets/azure/runtime/azure-swa.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { getAzureParsedCookiesFromHeaders } from "nitro/runtime/internal/utils.azure";
import { normalizeLambdaOutgoingHeaders } from "nitro/runtime/internal/utils.lambda";
import {
getAzureParsedCookiesFromHeaders,
normalizeLambdaOutgoingHeaders,
} from "nitro/runtime/internal";

import type { HttpRequest, HttpResponse } from "@azure/functions";
import { parseURL } from "ufo";
Expand Down
2 changes: 1 addition & 1 deletion src/presets/bun/runtime/bun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { startScheduleRunner } from "nitro/runtime/internal/task";
import { startScheduleRunner } from "nitro/runtime/internal";

import type {} from "bun";
import wsAdapter from "crossws/adapters/bun";
Expand Down
4 changes: 2 additions & 2 deletions src/presets/cloudflare/runtime/cloudflare-module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { useRuntimeConfig } from "nitro/runtime";
import { runCronTasks } from "nitro/runtime/internal/task";
import { requestHasBody } from "nitro/runtime/internal/utils";
import { runCronTasks } from "nitro/runtime/internal";
import { requestHasBody } from "nitro/runtime/internal";
import { getPublicAssetMeta } from "#nitro-internal-virtual/public-assets";

import {
Expand Down
3 changes: 1 addition & 2 deletions src/presets/cloudflare/runtime/cloudflare-pages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { runCronTasks } from "nitro/runtime/internal/task";
import { requestHasBody } from "nitro/runtime/internal/utils";
import { requestHasBody, runCronTasks } from "nitro/runtime/internal";
import { isPublicAssetURL } from "#nitro-internal-virtual/public-assets";

import type {
Expand Down
2 changes: 1 addition & 1 deletion src/presets/cloudflare/runtime/cloudflare-worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { useRuntimeConfig } from "nitro/runtime";
import { requestHasBody } from "nitro/runtime/internal/utils";
import { requestHasBody } from "nitro/runtime/internal";
import { getPublicAssetMeta } from "#nitro-internal-virtual/public-assets";

import {
Expand Down
3 changes: 0 additions & 3 deletions src/presets/deno/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const denoDeploy = defineNitroPreset(
deploy:
"cd ./ && deployctl deploy --project=<project_name> server/index.ts",
},
unenv: {
polyfill: ["nitro/runtime/internal/polyfill/deno-env"],
},
rollupConfig: {
preserveEntrySignatures: false,
external: (id) => id.startsWith("https://"),
Expand Down
2 changes: 1 addition & 1 deletion src/presets/deno/runtime/deno-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { useRuntimeConfig } from "nitro/runtime";
import { startScheduleRunner } from "nitro/runtime/internal/task";
import { startScheduleRunner } from "nitro/runtime/internal";

import type { Deno as _Deno } from "@deno/types";
import wsAdapter from "crossws/adapters/deno";
Expand Down
3 changes: 0 additions & 3 deletions src/presets/netlify/legacy/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ const netlifyEdge = defineNitroPreset(
format: "esm",
},
},
unenv: {
polyfill: ["nitro/runtime/internal/polyfill/deno-env"],
},
hooks: {
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
Expand Down
3 changes: 1 addition & 2 deletions src/presets/netlify/legacy/runtime/netlify-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { normalizeCookieHeader } from "nitro/runtime/internal/utils";
import {
normalizeCookieHeader,
normalizeLambdaIncomingHeaders,
normalizeLambdaOutgoingBody,
normalizeLambdaOutgoingHeaders,
} from "nitro/runtime/internal/utils.lambda";
} from "nitro/runtime/internal";

import type {
HandlerContext,
Expand Down
2 changes: 1 addition & 1 deletion src/presets/netlify/legacy/runtime/netlify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "#nitro-internal-pollyfills";
import { getRouteRulesForPath } from "nitro/runtime/internal/route-rules";
import { getRouteRulesForPath } from "nitro/runtime/internal";

import type { Handler } from "@netlify/functions/dist/main";
import { withQuery } from "ufo";
Expand Down
3 changes: 0 additions & 3 deletions src/presets/netlify/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ const netlifyEdge = defineNitroPreset(
format: "esm",
},
},
unenv: {
polyfill: ["nitro/runtime/internal/polyfill/deno-env"],
},
hooks: {
async compiled(nitro: Nitro) {
await writeHeaders(nitro);
Expand Down
3 changes: 1 addition & 2 deletions src/presets/netlify/runtime/netlify.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { getRouteRulesForPath } from "nitro/runtime/internal/route-rules";
import {
getRouteRulesForPath,
joinHeaders,
normalizeCookieHeader,
} from "nitro/runtime/internal/utils";
} from "nitro/runtime/internal";

const nitroApp = useNitroApp();

Expand Down
6 changes: 4 additions & 2 deletions src/presets/node/runtime/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import cluster from "node:cluster";
import os from "node:os";
import { getGracefulShutdownConfig } from "nitro/runtime/internal/shutdown";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal/utils";
import {
getGracefulShutdownConfig,
trapUnhandledNodeErrors,
} from "nitro/runtime/internal";

function runMaster() {
const numberOfWorkers =
Expand Down
6 changes: 4 additions & 2 deletions src/presets/node/runtime/node-listener.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import "#nitro-internal-pollyfills";
import { toNodeListener } from "h3";
import { useNitroApp } from "nitro/runtime";
import { startScheduleRunner } from "nitro/runtime/internal/task";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal/utils";
import {
startScheduleRunner,
trapUnhandledNodeErrors,
} from "nitro/runtime/internal";

const nitroApp = useNitroApp();

Expand Down
8 changes: 5 additions & 3 deletions src/presets/node/runtime/node-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import destr from "destr";
import { toNodeListener } from "h3";
import { useNitroApp } from "nitro/runtime";
import { useRuntimeConfig } from "nitro/runtime";
import { setupGracefulShutdown } from "nitro/runtime/internal/shutdown";
import { startScheduleRunner } from "nitro/runtime/internal/task";
import { trapUnhandledNodeErrors } from "nitro/runtime/internal/utils";
import {
setupGracefulShutdown,
startScheduleRunner,
trapUnhandledNodeErrors,
} from "nitro/runtime/internal";

const cert = process.env.NITRO_SSL_CERT;
const key = process.env.NITRO_SSL_KEY;
Expand Down
2 changes: 1 addition & 1 deletion src/presets/stormkit/runtime/stormkit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitro/runtime";
import { normalizeLambdaOutgoingBody } from "nitro/runtime/internal/utils.lambda";
import { normalizeLambdaOutgoingBody } from "nitro/runtime/internal";

import type { Handler } from "aws-lambda";

Expand Down
2 changes: 1 addition & 1 deletion src/presets/winterjs/runtime/winterjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import "#nitro-internal-pollyfills";
import { toPlainHandler } from "h3";
import { useNitroApp } from "nitro/runtime";
import { toBuffer } from "nitro/runtime/internal/utils";
import { toBuffer } from "nitro/runtime/internal";
import { hasProtocol, joinURL } from "ufo";

// Types are reverse engineered from runtime
Expand Down
4 changes: 3 additions & 1 deletion src/rollup/plugins/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { runtimeDir } from "nitro/runtime/meta";
import type { Nitro, NitroEventHandler, NitroRouteRules } from "nitro/types";
import { hash } from "ohash";
import { join } from "pathe";
import { virtual } from "./virtual";

export function handlers(nitro: Nitro) {
Expand Down Expand Up @@ -32,7 +34,7 @@ export function handlers(nitro: Nitro) {
if (nitro.options.serveStatic) {
handlers.unshift({
middleware: true,
handler: "nitro/runtime/internal/static",
handler: join(runtimeDir, "internal/static"),
});
}
if (nitro.options.renderer) {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"nitro": ["./src/core"],
// Runtime
"nitro/runtime": ["./src/runtime"],
"nitro/runtime/internal": ["./src/runtime/internal"],
// Runtime meta
"nitro/runtime/meta": ["./runtime-meta"],
// Kit
Expand Down

0 comments on commit 1c220ef

Please sign in to comment.