From 1c220ef4dc461910cd89b16d22f0206a20e42993 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 13 Jun 2024 23:27:02 +0200 Subject: [PATCH] chore: manually apply changes from #2524 to main --- src/core/config/defaults.ts | 4 ++-- src/core/config/resolvers/open-api.ts | 8 +++++--- src/core/nitro.ts | 6 ++++-- src/presets/_nitro/runtime/nitro-dev.ts | 8 +++++--- src/presets/_nitro/runtime/nitro-prerenderer.ts | 2 +- src/presets/aws-lambda/runtime/aws-lambda-streaming.ts | 2 +- src/presets/aws-lambda/runtime/aws-lambda.ts | 3 +-- src/presets/azure/runtime/azure-functions.ts | 6 ++++-- src/presets/azure/runtime/azure-swa.ts | 6 ++++-- src/presets/bun/runtime/bun.ts | 2 +- src/presets/cloudflare/runtime/cloudflare-module.ts | 4 ++-- src/presets/cloudflare/runtime/cloudflare-pages.ts | 3 +-- src/presets/cloudflare/runtime/cloudflare-worker.ts | 2 +- src/presets/deno/preset.ts | 3 --- src/presets/deno/runtime/deno-server.ts | 2 +- src/presets/netlify/legacy/preset.ts | 3 --- src/presets/netlify/legacy/runtime/netlify-lambda.ts | 3 +-- src/presets/netlify/legacy/runtime/netlify.ts | 2 +- src/presets/netlify/preset.ts | 3 --- src/presets/netlify/runtime/netlify.ts | 3 +-- src/presets/node/runtime/cluster.ts | 6 ++++-- src/presets/node/runtime/node-listener.ts | 6 ++++-- src/presets/node/runtime/node-server.ts | 8 +++++--- src/presets/stormkit/runtime/stormkit.ts | 2 +- src/presets/winterjs/runtime/winterjs.ts | 2 +- src/rollup/plugins/handlers.ts | 4 +++- tsconfig.json | 1 + 27 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/core/config/defaults.ts b/src/core/config/defaults.ts index 47e178e840..b774cc1998 100644 --- a/src/core/config/defaults.ts +++ b/src/core/config/defaults.ts @@ -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 = { @@ -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, diff --git a/src/core/config/resolvers/open-api.ts b/src/core/config/resolvers/open-api.ts index 7d406f2ade..187f94bf07 100644 --- a/src/core/config/resolvers/open-api.ts +++ b/src/core/config/resolvers/open-api.ts @@ -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"), }); } } diff --git a/src/core/nitro.ts b/src/core/nitro.ts index 372680a6cd..00022655da 100644 --- a/src/core/nitro.ts +++ b/src/core/nitro.ts @@ -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"; @@ -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 diff --git a/src/presets/_nitro/runtime/nitro-dev.ts b/src/presets/_nitro/runtime/nitro-dev.ts index a778f3b7d9..cdfaf64aad 100644 --- a/src/presets/_nitro/runtime/nitro-dev.ts +++ b/src/presets/_nitro/runtime/nitro-dev.ts @@ -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"; diff --git a/src/presets/_nitro/runtime/nitro-prerenderer.ts b/src/presets/_nitro/runtime/nitro-prerenderer.ts index dd2330f41d..dd4648dbb6 100644 --- a/src/presets/_nitro/runtime/nitro-prerenderer.ts +++ b/src/presets/_nitro/runtime/nitro-prerenderer.ts @@ -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(); diff --git a/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts b/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts index 4e9965480e..3f00195ae0 100644 --- a/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts +++ b/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts @@ -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 { diff --git a/src/presets/aws-lambda/runtime/aws-lambda.ts b/src/presets/aws-lambda/runtime/aws-lambda.ts index 67cbe740c0..bdd002baab 100644 --- a/src/presets/aws-lambda/runtime/aws-lambda.ts +++ b/src/presets/aws-lambda/runtime/aws-lambda.ts @@ -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(); diff --git a/src/presets/azure/runtime/azure-functions.ts b/src/presets/azure/runtime/azure-functions.ts index 71be2849eb..23481cd98f 100644 --- a/src/presets/azure/runtime/azure-functions.ts +++ b/src/presets/azure/runtime/azure-functions.ts @@ -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"; diff --git a/src/presets/azure/runtime/azure-swa.ts b/src/presets/azure/runtime/azure-swa.ts index 5dc99f0a6e..4f291ea708 100644 --- a/src/presets/azure/runtime/azure-swa.ts +++ b/src/presets/azure/runtime/azure-swa.ts @@ -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"; diff --git a/src/presets/bun/runtime/bun.ts b/src/presets/bun/runtime/bun.ts index cf4b04b70c..10f70306ae 100644 --- a/src/presets/bun/runtime/bun.ts +++ b/src/presets/bun/runtime/bun.ts @@ -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"; diff --git a/src/presets/cloudflare/runtime/cloudflare-module.ts b/src/presets/cloudflare/runtime/cloudflare-module.ts index d3a0e1a628..3b552f55b5 100644 --- a/src/presets/cloudflare/runtime/cloudflare-module.ts +++ b/src/presets/cloudflare/runtime/cloudflare-module.ts @@ -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 { diff --git a/src/presets/cloudflare/runtime/cloudflare-pages.ts b/src/presets/cloudflare/runtime/cloudflare-pages.ts index e94e81e1a7..9ac78d459f 100644 --- a/src/presets/cloudflare/runtime/cloudflare-pages.ts +++ b/src/presets/cloudflare/runtime/cloudflare-pages.ts @@ -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 { diff --git a/src/presets/cloudflare/runtime/cloudflare-worker.ts b/src/presets/cloudflare/runtime/cloudflare-worker.ts index 3dc7c99372..40b285ce99 100644 --- a/src/presets/cloudflare/runtime/cloudflare-worker.ts +++ b/src/presets/cloudflare/runtime/cloudflare-worker.ts @@ -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 { diff --git a/src/presets/deno/preset.ts b/src/presets/deno/preset.ts index 051abfec67..5737ce0157 100644 --- a/src/presets/deno/preset.ts +++ b/src/presets/deno/preset.ts @@ -20,9 +20,6 @@ const denoDeploy = defineNitroPreset( deploy: "cd ./ && deployctl deploy --project= server/index.ts", }, - unenv: { - polyfill: ["nitro/runtime/internal/polyfill/deno-env"], - }, rollupConfig: { preserveEntrySignatures: false, external: (id) => id.startsWith("https://"), diff --git a/src/presets/deno/runtime/deno-server.ts b/src/presets/deno/runtime/deno-server.ts index fcbb1282d5..6613a5ca6c 100644 --- a/src/presets/deno/runtime/deno-server.ts +++ b/src/presets/deno/runtime/deno-server.ts @@ -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"; diff --git a/src/presets/netlify/legacy/preset.ts b/src/presets/netlify/legacy/preset.ts index 62e3c2bcc3..b6885bfb1f 100644 --- a/src/presets/netlify/legacy/preset.ts +++ b/src/presets/netlify/legacy/preset.ts @@ -91,9 +91,6 @@ const netlifyEdge = defineNitroPreset( format: "esm", }, }, - unenv: { - polyfill: ["nitro/runtime/internal/polyfill/deno-env"], - }, hooks: { "rollup:before": (nitro: Nitro) => { deprecateSWR(nitro); diff --git a/src/presets/netlify/legacy/runtime/netlify-lambda.ts b/src/presets/netlify/legacy/runtime/netlify-lambda.ts index b0d886a433..a1864e6319 100644 --- a/src/presets/netlify/legacy/runtime/netlify-lambda.ts +++ b/src/presets/netlify/legacy/runtime/netlify-lambda.ts @@ -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, diff --git a/src/presets/netlify/legacy/runtime/netlify.ts b/src/presets/netlify/legacy/runtime/netlify.ts index d7666e41c5..7f738aefec 100644 --- a/src/presets/netlify/legacy/runtime/netlify.ts +++ b/src/presets/netlify/legacy/runtime/netlify.ts @@ -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"; diff --git a/src/presets/netlify/preset.ts b/src/presets/netlify/preset.ts index 967d004c16..71e0089dc8 100644 --- a/src/presets/netlify/preset.ts +++ b/src/presets/netlify/preset.ts @@ -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); diff --git a/src/presets/netlify/runtime/netlify.ts b/src/presets/netlify/runtime/netlify.ts index 9ed3f4db6e..99b978a44d 100644 --- a/src/presets/netlify/runtime/netlify.ts +++ b/src/presets/netlify/runtime/netlify.ts @@ -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(); diff --git a/src/presets/node/runtime/cluster.ts b/src/presets/node/runtime/cluster.ts index 29c0779177..d7fee6e9e6 100644 --- a/src/presets/node/runtime/cluster.ts +++ b/src/presets/node/runtime/cluster.ts @@ -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 = diff --git a/src/presets/node/runtime/node-listener.ts b/src/presets/node/runtime/node-listener.ts index dce81fe781..7f11d6d16d 100644 --- a/src/presets/node/runtime/node-listener.ts +++ b/src/presets/node/runtime/node-listener.ts @@ -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(); diff --git a/src/presets/node/runtime/node-server.ts b/src/presets/node/runtime/node-server.ts index cb197908be..77c6470ec9 100644 --- a/src/presets/node/runtime/node-server.ts +++ b/src/presets/node/runtime/node-server.ts @@ -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; diff --git a/src/presets/stormkit/runtime/stormkit.ts b/src/presets/stormkit/runtime/stormkit.ts index df68921e38..01cd8958ac 100644 --- a/src/presets/stormkit/runtime/stormkit.ts +++ b/src/presets/stormkit/runtime/stormkit.ts @@ -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"; diff --git a/src/presets/winterjs/runtime/winterjs.ts b/src/presets/winterjs/runtime/winterjs.ts index f6a680fb57..c670b3023e 100644 --- a/src/presets/winterjs/runtime/winterjs.ts +++ b/src/presets/winterjs/runtime/winterjs.ts @@ -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 diff --git a/src/rollup/plugins/handlers.ts b/src/rollup/plugins/handlers.ts index bf1ea2b72c..47fff2636e 100644 --- a/src/rollup/plugins/handlers.ts +++ b/src/rollup/plugins/handlers.ts @@ -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) { @@ -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) { diff --git a/tsconfig.json b/tsconfig.json index c0c37afcef..bb579d2859 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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