nitro-nightly 3.0.1-alpha.2 → 3.0.260415-beta
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.
- package/LICENSE +6 -0
- package/README.md +2 -2
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +7259 -3815
- package/dist/_build/rolldown.mjs +32 -42
- package/dist/_build/rollup.mjs +28 -48
- package/dist/_build/vite.build.mjs +10 -10
- package/dist/_chunks/nitro.mjs +102 -327
- package/dist/_chunks/nitro2.mjs +8 -9
- package/dist/_chunks/nitro3.mjs +136 -0
- package/dist/_chunks/nitro4.mjs +127 -0
- package/dist/_chunks/utils.mjs +40 -29
- package/dist/_common.mjs +13 -25
- package/dist/_dev.d.mts +0 -3
- package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -330
- package/dist/_libs/_.mjs +2 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +2 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +2 -0
- package/dist/_libs/_6.mjs +2 -0
- package/dist/_libs/_7.mjs +2 -0
- package/dist/_libs/c12+rc9.mjs +814 -0
- package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +49 -40
- package/dist/_libs/citty.mjs +142 -41
- package/dist/_libs/commondir+is-reference.mjs +60 -56
- package/dist/_libs/compatx.d.mts +0 -2
- package/dist/_libs/compatx.mjs +1 -4
- package/dist/_libs/esbuild.d.mts +0 -1
- package/dist/_libs/escape-string-regexp.mjs +1 -4
- package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +0 -5
- package/dist/_libs/estree-walker.mjs +4 -92
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +160 -246
- package/dist/_libs/httpxy.d.mts +20 -13
- package/dist/_libs/httpxy.mjs +519 -95
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +1 -4
- package/dist/_libs/magic-string.d.mts +0 -2
- package/dist/_libs/mlly.d.mts +0 -2
- package/dist/_libs/nypm+tinyexec.mjs +822 -0
- package/dist/_libs/perfect-debounce.mjs +68 -0
- package/dist/_libs/pkg-types.d.mts +0 -3
- package/dist/_libs/plugin-alias.mjs +1 -5
- package/dist/_libs/plugin-inject.mjs +1 -7
- package/dist/_libs/plugin-json.mjs +1 -5
- package/dist/_libs/pluginutils.mjs +3 -35
- package/dist/_libs/readdirp+chokidar.mjs +187 -365
- package/dist/_libs/remapping.mjs +1 -5
- package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -53
- package/dist/_libs/rou3.d.mts +1 -4
- package/dist/_libs/rou3.mjs +223 -78
- package/dist/_libs/std-env.d.mts +8 -2
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +21 -334
- package/dist/_libs/ultrahtml.mjs +3 -16
- package/dist/_libs/unimport+unplugin.mjs +244 -388
- package/dist/_libs/unplugin+unimport.d.mts +5 -15
- package/dist/_libs/unwasm.d.mts +0 -3
- package/dist/_presets.mjs +575 -488
- package/dist/builder.d.mts +5 -25
- package/dist/builder.mjs +3 -8
- package/dist/cli/_chunks/build.mjs +22 -25
- package/dist/cli/_chunks/common.mjs +1 -4
- package/dist/cli/_chunks/deploy.mjs +37 -0
- package/dist/cli/_chunks/dev.mjs +6 -11
- package/dist/cli/_chunks/docs.mjs +28 -0
- package/dist/cli/_chunks/list.mjs +4 -8
- package/dist/cli/_chunks/prepare.mjs +2 -6
- package/dist/cli/_chunks/preview.mjs +48 -0
- package/dist/cli/_chunks/run.mjs +7 -11
- package/dist/cli/_chunks/task.mjs +1 -5
- package/dist/cli/index.mjs +5 -6
- package/dist/docs/0.docs/0.index/index.md +56 -0
- package/dist/docs/0.docs/1.quick-start.md +110 -0
- package/dist/docs/0.docs/10.lifecycle.md +204 -0
- package/dist/docs/0.docs/11.openapi.md +291 -0
- package/dist/docs/0.docs/12.plugins.md +164 -0
- package/dist/docs/0.docs/13.tasks.md +277 -0
- package/dist/docs/0.docs/14.websocket.md +386 -0
- package/dist/docs/0.docs/15.migration.md +213 -0
- package/dist/docs/0.docs/16.nightly.md +31 -0
- package/dist/docs/0.docs/2.renderer.md +322 -0
- package/dist/docs/0.docs/3.routing.md +711 -0
- package/dist/docs/0.docs/4.server-entry.md +239 -0
- package/dist/docs/0.docs/5.cache.md +408 -0
- package/dist/docs/0.docs/6.storage.md +261 -0
- package/dist/docs/0.docs/7.assets.md +166 -0
- package/dist/docs/0.docs/8.configuration.md +256 -0
- package/dist/docs/0.docs/9.database.md +185 -0
- package/dist/docs/1.deploy/0.index/index.md +64 -0
- package/dist/docs/1.deploy/1.runtimes/0.node.md +63 -0
- package/dist/docs/1.deploy/1.runtimes/1.bun.md +15 -0
- package/dist/docs/1.deploy/1.runtimes/2.deno.md +19 -0
- package/dist/docs/1.deploy/2.providers/0.alwaysdata.md +50 -0
- package/dist/docs/1.deploy/2.providers/1.aws.md +47 -0
- package/dist/docs/1.deploy/2.providers/10.flightcontrol.md +67 -0
- package/dist/docs/1.deploy/2.providers/11.genezio.md +67 -0
- package/dist/docs/1.deploy/2.providers/12.github-pages.md +68 -0
- package/dist/docs/1.deploy/2.providers/13.gitlab-pages.md +37 -0
- package/dist/docs/1.deploy/2.providers/14.heroku.md +84 -0
- package/dist/docs/1.deploy/2.providers/15.iis.md +38 -0
- package/dist/docs/1.deploy/2.providers/16.koyeb.md +109 -0
- package/dist/docs/1.deploy/2.providers/17.netlify.md +47 -0
- package/dist/docs/1.deploy/2.providers/18.platform-sh.md +37 -0
- package/dist/docs/1.deploy/2.providers/19.render.md +37 -0
- package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +81 -0
- package/dist/docs/1.deploy/2.providers/20.stormkit.md +24 -0
- package/dist/docs/1.deploy/2.providers/21.vercel.md +270 -0
- package/dist/docs/1.deploy/2.providers/22.zeabur.md +19 -0
- package/dist/docs/1.deploy/2.providers/23.zephyr.md +99 -0
- package/dist/docs/1.deploy/2.providers/24.zerops.md +102 -0
- package/dist/docs/1.deploy/2.providers/3.azure.md +72 -0
- package/dist/docs/1.deploy/2.providers/4.cleavr.md +33 -0
- package/dist/docs/1.deploy/2.providers/5.cloudflare.md +369 -0
- package/dist/docs/1.deploy/2.providers/6.deno-deploy.md +66 -0
- package/dist/docs/1.deploy/2.providers/7.digitalocean.md +46 -0
- package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
- package/dist/docs/1.deploy/2.providers/9.firebase.md +32 -0
- package/dist/docs/2.config/0.index/index.md +1221 -0
- package/dist/docs/3.examples/0.index/index.md +3 -0
- package/dist/docs/3.examples/1.api-routes.md +145 -0
- package/dist/docs/3.examples/10.hono.md +74 -0
- package/dist/docs/3.examples/11.import-alias.md +97 -0
- package/dist/docs/3.examples/12.middleware.md +91 -0
- package/dist/docs/3.examples/13.mono-jsx.md +68 -0
- package/dist/docs/3.examples/14.nano-jsx.md +70 -0
- package/dist/docs/3.examples/15.plugins.md +91 -0
- package/dist/docs/3.examples/16.renderer.md +113 -0
- package/dist/docs/3.examples/17.runtime-config.md +97 -0
- package/dist/docs/3.examples/18.server-fetch.md +87 -0
- package/dist/docs/3.examples/19.shiki.md +198 -0
- package/dist/docs/3.examples/2.auto-imports.md +92 -0
- package/dist/docs/3.examples/20.virtual-routes.md +74 -0
- package/dist/docs/3.examples/21.vite-nitro-plugin.md +79 -0
- package/dist/docs/3.examples/22.vite-rsc.md +1041 -0
- package/dist/docs/3.examples/23.vite-ssr-html.md +217 -0
- package/dist/docs/3.examples/24.vite-ssr-preact.md +247 -0
- package/dist/docs/3.examples/25.vite-ssr-react.md +226 -0
- package/dist/docs/3.examples/26.vite-ssr-solid.md +256 -0
- package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +442 -0
- package/dist/docs/3.examples/28.vite-ssr-tss-react.md +444 -0
- package/dist/docs/3.examples/29.vite-ssr-vue-router.md +617 -0
- package/dist/docs/3.examples/3.cached-handler.md +81 -0
- package/dist/docs/3.examples/30.vite-trpc.md +335 -0
- package/dist/docs/3.examples/31.websocket.md +282 -0
- package/dist/docs/3.examples/4.custom-error-handler.md +98 -0
- package/dist/docs/3.examples/5.database.md +157 -0
- package/dist/docs/3.examples/6.elysia.md +70 -0
- package/dist/docs/3.examples/7.express.md +78 -0
- package/dist/docs/3.examples/8.fastify.md +79 -0
- package/dist/docs/3.examples/9.hello-world.md +68 -0
- package/dist/docs/README.md +86 -0
- package/dist/docs/index.md +121 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
- package/dist/node_modules/@poppinss/dumper/package.json +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
- package/dist/node_modules/@speed-highlight/core/package.json +1 -1
- package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
- package/dist/node_modules/cookie-es/package.json +26 -23
- package/dist/node_modules/croner/dist/croner.js +1 -1
- package/dist/node_modules/croner/package.json +11 -1
- package/dist/node_modules/defu/dist/defu.mjs +2 -2
- package/dist/node_modules/defu/package.json +33 -28
- package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
- package/dist/node_modules/rendu/dist/index.mjs +5 -112
- package/dist/node_modules/rendu/package.json +25 -24
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +204 -351
- package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +35 -32
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +12 -57
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +1 -2
- package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
- package/dist/presets/azure/runtime/_utils.mjs +5 -5
- package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
- package/dist/presets/bun/runtime/bun.mjs +9 -6
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
- package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
- package/dist/presets/deno/runtime/deno-server.mjs +9 -6
- package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -3
- package/dist/presets/netlify/runtime/netlify.mjs +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +5 -4
- package/dist/presets/node/runtime/node-middleware.mjs +1 -1
- package/dist/presets/node/runtime/node-server.mjs +8 -5
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
- package/dist/presets/vercel/runtime/vercel.web.mjs +3 -5
- package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/internal/app.mjs +12 -11
- package/dist/runtime/internal/cache.d.mts +0 -4
- package/dist/runtime/internal/cache.mjs +32 -256
- package/dist/runtime/internal/context.d.mts +3 -1
- package/dist/runtime/internal/context.mjs +1 -9
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +47 -49
- package/dist/runtime/internal/error/hooks.d.mts +1 -1
- package/dist/runtime/internal/error/prod.d.mts +2 -5
- package/dist/runtime/internal/error/prod.mjs +19 -33
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/route-rules.d.mts +11 -4
- package/dist/runtime/internal/route-rules.mjs +15 -5
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -10
- package/dist/runtime/internal/routes/openapi.mjs +2 -2
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
- package/dist/runtime/internal/routes/scalar.mjs +3 -3
- package/dist/runtime/internal/routes/swagger.mjs +7 -4
- package/dist/runtime/internal/runtime-config.d.mts +1 -1
- package/dist/runtime/internal/runtime-config.mjs +2 -2
- package/dist/runtime/internal/static.mjs +5 -4
- package/dist/runtime/internal/task.d.mts +3 -1
- package/dist/runtime/internal/task.mjs +7 -7
- package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/meta.d.mts +1 -0
- package/dist/runtime/meta.mjs +2 -0
- package/dist/runtime/nitro.d.mts +2 -0
- package/dist/runtime/nitro.mjs +4 -2
- package/dist/runtime/virtual/error-handler.mjs +1 -1
- package/dist/runtime/virtual/renderer-template.mjs +1 -1
- package/dist/runtime/virtual/server-assets.d.mts +2 -1
- package/dist/runtime/virtual/tracing.d.mts +5 -0
- package/dist/runtime/virtual/tracing.mjs +1 -0
- package/dist/runtime/vite.d.mts +1 -1
- package/dist/types/index.d.mts +215 -195
- package/dist/types/index.mjs +1 -11
- package/dist/vite.d.mts +3 -8
- package/dist/vite.mjs +285 -253
- package/lib/tsconfig.json +3 -5
- package/package.json +97 -80
- package/dist/_libs/confbox.mjs +0 -2509
- package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
- package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
- package/dist/node_modules/hookable/dist/index.mjs +0 -266
- package/dist/node_modules/hookable/package.json +0 -52
- package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
- package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
- package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
- package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
- package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
- package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
- package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
- package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
- package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
- package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
- package/dist/presets/azure/runtime/_utils.d.mts +0 -2
- package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
- package/dist/presets/bun/runtime/bun.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
- package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
- package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
- package/dist/presets/node/runtime/node-server.d.mts +0 -3
- package/dist/presets/standard/runtime/server.d.mts +0 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
- package/dist/presets/vercel/runtime/isr.d.mts +0 -2
- package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
- package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
- package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
- package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
- package/dist/runtime/internal/vite/node-runner.mjs +0 -359
|
@@ -1,229 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import consola
|
|
6
|
-
import { createReadStream
|
|
7
|
-
import { readFile,
|
|
1
|
+
import { A as src_default, H as v, V as m, ct as join$1, dt as resolve$1, g as writeDevBuildInfo, ot as extname$1 } from "./_build/common.mjs";
|
|
2
|
+
import { n as watch$1 } from "./_libs/readdirp+chokidar.mjs";
|
|
3
|
+
import { t as debounce } from "./_libs/perfect-debounce.mjs";
|
|
4
|
+
import { t as createProxyServer } from "./_libs/httpxy.mjs";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import { createReadStream } from "node:fs";
|
|
7
|
+
import { readFile, stat as stat$1 } from "node:fs/promises";
|
|
8
8
|
import { dirname, resolve } from "node:path";
|
|
9
9
|
import { joinURL } from "ufo";
|
|
10
10
|
import { createBrotliCompress, createGzip } from "node:zlib";
|
|
11
|
-
import {
|
|
11
|
+
import { RunnerManager, loadRunner } from "env-runner";
|
|
12
12
|
import { H3, HTTPError, defineHandler, fromNodeHandler, getRequestIP, getRequestURL, serveStatic, toEventHandler } from "h3";
|
|
13
|
-
import { Agent } from "undici";
|
|
14
13
|
import { serve } from "srvx/node";
|
|
15
|
-
import { ErrorParser } from "youch-core";
|
|
16
|
-
import { Youch } from "youch";
|
|
17
|
-
import { SourceMapConsumer } from "source-map";
|
|
18
14
|
import { FastResponse } from "srvx";
|
|
19
|
-
|
|
20
|
-
//#region src/runner/proxy.ts
|
|
21
|
-
function createHTTPProxy(defaults = {}) {
|
|
22
|
-
const proxy = createProxyServer(defaults);
|
|
23
|
-
proxy.on("proxyReq", (proxyReq, req) => {
|
|
24
|
-
if (!proxyReq.hasHeader("x-forwarded-for")) {
|
|
25
|
-
const address = req.socket.remoteAddress;
|
|
26
|
-
if (address) proxyReq.appendHeader("x-forwarded-for", address);
|
|
27
|
-
}
|
|
28
|
-
if (!proxyReq.hasHeader("x-forwarded-port")) {
|
|
29
|
-
if (req?.socket?.localPort) proxyReq.setHeader("x-forwarded-port", req.socket.localPort);
|
|
30
|
-
}
|
|
31
|
-
if (!proxyReq.hasHeader("x-forwarded-Proto")) {
|
|
32
|
-
const encrypted = (req?.connection)?.encrypted;
|
|
33
|
-
proxyReq.setHeader("x-forwarded-proto", encrypted ? "https" : "http");
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
proxy,
|
|
38
|
-
async handleEvent(event, opts) {
|
|
39
|
-
try {
|
|
40
|
-
return await fromNodeHandler((req, res) => proxy.web(req, res, opts))(event);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
event.res.headers.set("refresh", "3");
|
|
43
|
-
throw new HTTPError({
|
|
44
|
-
status: 503,
|
|
45
|
-
message: "Dev server is unavailable.",
|
|
46
|
-
cause: error
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
async function fetchAddress(addr, input, inputInit) {
|
|
53
|
-
let url;
|
|
54
|
-
let init;
|
|
55
|
-
if (input instanceof Request) {
|
|
56
|
-
url = new URL(input.url);
|
|
57
|
-
init = {
|
|
58
|
-
method: input.method,
|
|
59
|
-
headers: input.headers,
|
|
60
|
-
body: input.body,
|
|
61
|
-
...inputInit
|
|
62
|
-
};
|
|
63
|
-
} else {
|
|
64
|
-
url = new URL(input);
|
|
65
|
-
init = inputInit;
|
|
66
|
-
}
|
|
67
|
-
init = {
|
|
68
|
-
duplex: "half",
|
|
69
|
-
redirect: "manual",
|
|
70
|
-
...init
|
|
71
|
-
};
|
|
72
|
-
let res;
|
|
73
|
-
if (addr.socketPath) {
|
|
74
|
-
url.protocol = "http:";
|
|
75
|
-
res = await fetch(url, {
|
|
76
|
-
...init,
|
|
77
|
-
...fetchSocketOptions(addr.socketPath)
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
const origin = `http://${addr.host}${addr.port ? `:${addr.port}` : ""}`;
|
|
81
|
-
const outURL = new URL(url.pathname + url.search, origin);
|
|
82
|
-
res = await fetch(outURL, init);
|
|
83
|
-
}
|
|
84
|
-
const headers = new Headers(res.headers);
|
|
85
|
-
headers.delete("transfer-encoding");
|
|
86
|
-
return new Response(res.body, {
|
|
87
|
-
status: res.status,
|
|
88
|
-
statusText: res.statusText,
|
|
89
|
-
headers
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function fetchSocketOptions(socketPath) {
|
|
93
|
-
if ("Bun" in globalThis) return { unix: socketPath };
|
|
94
|
-
if ("Deno" in globalThis) return { client: Deno.createHttpClient({
|
|
95
|
-
transport: "unix",
|
|
96
|
-
path: socketPath
|
|
97
|
-
}) };
|
|
98
|
-
return { dispatcher: new Agent({ connect: { socketPath } }) };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/runner/node.ts
|
|
103
|
-
var NodeEnvRunner = class {
|
|
104
|
-
closed = false;
|
|
105
|
-
#name;
|
|
106
|
-
#entry;
|
|
107
|
-
#data;
|
|
108
|
-
#hooks;
|
|
109
|
-
#worker;
|
|
110
|
-
#address;
|
|
111
|
-
#proxy;
|
|
112
|
-
#messageListeners;
|
|
113
|
-
constructor(opts) {
|
|
114
|
-
this.#name = opts.name;
|
|
115
|
-
this.#entry = opts.entry;
|
|
116
|
-
this.#data = opts.data;
|
|
117
|
-
this.#hooks = opts.hooks || {};
|
|
118
|
-
this.#proxy = createHTTPProxy();
|
|
119
|
-
this.#messageListeners = /* @__PURE__ */ new Set();
|
|
120
|
-
this.#initWorker();
|
|
121
|
-
}
|
|
122
|
-
get ready() {
|
|
123
|
-
return Boolean(!this.closed && this.#address && this.#proxy && this.#worker);
|
|
124
|
-
}
|
|
125
|
-
async fetch(input, init) {
|
|
126
|
-
for (let i = 0; i < 5 && !(this.#address && this.#proxy); i++) await new Promise((r) => setTimeout(r, 100 * Math.pow(2, i)));
|
|
127
|
-
if (!(this.#address && this.#proxy)) return new Response("Node env runner worker is unavailable", { status: 503 });
|
|
128
|
-
return fetchAddress(this.#address, input, init);
|
|
129
|
-
}
|
|
130
|
-
upgrade(req, socket, head) {
|
|
131
|
-
if (!this.ready) return;
|
|
132
|
-
return this.#proxy.proxy.ws(req, socket, {
|
|
133
|
-
target: this.#address,
|
|
134
|
-
xfwd: true
|
|
135
|
-
}, head).catch((error) => {
|
|
136
|
-
consola$1.error("WebSocket proxy error:", error);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
sendMessage(message) {
|
|
140
|
-
if (!this.#worker) throw new Error("Node env worker should be initialized before sending messages.");
|
|
141
|
-
this.#worker.postMessage(message);
|
|
142
|
-
}
|
|
143
|
-
onMessage(listener) {
|
|
144
|
-
this.#messageListeners.add(listener);
|
|
145
|
-
}
|
|
146
|
-
offMessage(listener) {
|
|
147
|
-
this.#messageListeners.delete(listener);
|
|
148
|
-
}
|
|
149
|
-
async close(cause) {
|
|
150
|
-
if (this.closed) return;
|
|
151
|
-
this.closed = true;
|
|
152
|
-
this.#hooks.onClose?.(this, cause);
|
|
153
|
-
this.#hooks = {};
|
|
154
|
-
const onError = (error) => consola$1.error(error);
|
|
155
|
-
await this.#closeWorker().catch(onError);
|
|
156
|
-
await this.#closeProxy().catch(onError);
|
|
157
|
-
await this.#closeSocket().catch(onError);
|
|
158
|
-
}
|
|
159
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
160
|
-
const status = this.closed ? "closed" : this.ready ? "ready" : "pending";
|
|
161
|
-
return `NodeEnvRunner#${this.#name}(${status})`;
|
|
162
|
-
}
|
|
163
|
-
#initWorker() {
|
|
164
|
-
if (!existsSync(this.#entry)) {
|
|
165
|
-
this.close(`worker entry not found in "${this.#entry}".`);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const worker = new Worker(this.#entry, {
|
|
169
|
-
env: { ...process.env },
|
|
170
|
-
workerData: {
|
|
171
|
-
name: this.#name,
|
|
172
|
-
...this.#data
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
worker.once("exit", (code) => {
|
|
176
|
-
worker._exitCode = code;
|
|
177
|
-
this.close(`worker exited with code ${code}`);
|
|
178
|
-
});
|
|
179
|
-
worker.once("error", (error) => {
|
|
180
|
-
consola$1.error(`Worker error:`, error);
|
|
181
|
-
this.close(error);
|
|
182
|
-
});
|
|
183
|
-
worker.on("message", (message) => {
|
|
184
|
-
if (message?.address) {
|
|
185
|
-
this.#address = message.address;
|
|
186
|
-
this.#hooks.onReady?.(this, this.#address);
|
|
187
|
-
}
|
|
188
|
-
for (const listener of this.#messageListeners) listener(message);
|
|
189
|
-
});
|
|
190
|
-
this.#worker = worker;
|
|
191
|
-
}
|
|
192
|
-
async #closeProxy() {
|
|
193
|
-
this.#proxy?.proxy?.close(() => {});
|
|
194
|
-
this.#proxy = void 0;
|
|
195
|
-
}
|
|
196
|
-
async #closeSocket() {
|
|
197
|
-
const socketPath = this.#address?.socketPath;
|
|
198
|
-
if (socketPath && socketPath[0] !== "\0" && !socketPath.startsWith(String.raw`\\.\pipe`)) await rm(socketPath).catch(() => {});
|
|
199
|
-
this.#address = void 0;
|
|
200
|
-
}
|
|
201
|
-
async #closeWorker() {
|
|
202
|
-
if (!this.#worker) return;
|
|
203
|
-
this.#worker.postMessage({ event: "shutdown" });
|
|
204
|
-
if (!this.#worker._exitCode && !a && !T) await new Promise((resolve$2) => {
|
|
205
|
-
const gracefulShutdownTimeoutMs = Number.parseInt(process.env.NITRO_SHUTDOWN_TIMEOUT || "", 10) || 5e3;
|
|
206
|
-
const timeout = setTimeout(() => {
|
|
207
|
-
consola$1.warn(`force closing node env runner worker...`);
|
|
208
|
-
resolve$2();
|
|
209
|
-
}, gracefulShutdownTimeoutMs);
|
|
210
|
-
this.#worker?.on("message", (message) => {
|
|
211
|
-
if (message.event === "exit") {
|
|
212
|
-
clearTimeout(timeout);
|
|
213
|
-
resolve$2();
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
this.#worker.removeAllListeners();
|
|
218
|
-
await this.#worker.terminate().catch((error) => {
|
|
219
|
-
consola$1.error(error);
|
|
220
|
-
});
|
|
221
|
-
this.#worker = void 0;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
//#endregion
|
|
226
|
-
//#region src/dev/vfs.ts
|
|
227
15
|
function createVFSHandler(nitro) {
|
|
228
16
|
return defineHandler(async (event) => {
|
|
229
17
|
const { socket } = event.runtime?.node?.req || {};
|
|
@@ -242,9 +30,9 @@ function createVFSHandler(nitro) {
|
|
|
242
30
|
const content = id ? await nitro.vfs.get(id)?.render() : void 0;
|
|
243
31
|
if (isJson) return {
|
|
244
32
|
rootDir: nitro.options.rootDir,
|
|
245
|
-
entries: [...nitro.vfs.keys()].map((id
|
|
246
|
-
id
|
|
247
|
-
path: "/_vfs.json/" + encodeURIComponent(id
|
|
33
|
+
entries: [...nitro.vfs.keys()].map((id) => ({
|
|
34
|
+
id,
|
|
35
|
+
path: "/_vfs.json/" + encodeURIComponent(id)
|
|
248
36
|
})),
|
|
249
37
|
current: id ? {
|
|
250
38
|
id,
|
|
@@ -261,8 +49,8 @@ function createVFSHandler(nitro) {
|
|
|
261
49
|
currentDir = currentDir[segment];
|
|
262
50
|
}
|
|
263
51
|
}
|
|
264
|
-
const generateHTML = (directory, path
|
|
265
|
-
const subpath = [...path
|
|
52
|
+
const generateHTML = (directory, path = []) => Object.entries(directory).map(([fname, value = {}]) => {
|
|
53
|
+
const subpath = [...path, fname];
|
|
266
54
|
const key = subpath.join("/");
|
|
267
55
|
const encodedUrl = encodeURIComponent(key);
|
|
268
56
|
const linkClass = url === `/${encodedUrl}` ? "bg-gray-700 text-white" : "hover:bg-gray-800 text-gray-200";
|
|
@@ -353,22 +141,16 @@ const editorTemplate = (options) => `
|
|
|
353
141
|
}, 0);
|
|
354
142
|
<\/script>
|
|
355
143
|
`;
|
|
356
|
-
|
|
357
|
-
//#endregion
|
|
358
|
-
//#region src/runtime/internal/error/utils.ts
|
|
359
144
|
function defineNitroErrorHandler(handler) {
|
|
360
145
|
return handler;
|
|
361
146
|
}
|
|
362
|
-
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/runtime/internal/error/dev.ts
|
|
365
|
-
var dev_default = defineNitroErrorHandler(async function defaultNitroErrorHandler(error, event) {
|
|
147
|
+
const errorHandler = defineNitroErrorHandler(async function defaultNitroErrorHandler(error, event) {
|
|
366
148
|
const res = await defaultHandler(error, event);
|
|
367
149
|
return new FastResponse(typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2), res);
|
|
368
150
|
});
|
|
369
151
|
async function defaultHandler(error, event, opts) {
|
|
370
|
-
const
|
|
371
|
-
const status =
|
|
152
|
+
const unhandled = error.unhandled ?? !HTTPError.isError(error);
|
|
153
|
+
const { status = 500, statusText = "" } = unhandled ? {} : error;
|
|
372
154
|
const url = getRequestURL(event, {
|
|
373
155
|
xForwardedHost: true,
|
|
374
156
|
xForwardedProto: true
|
|
@@ -378,58 +160,63 @@ async function defaultHandler(error, event, opts) {
|
|
|
378
160
|
if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) return {
|
|
379
161
|
status: 302,
|
|
380
162
|
statusText: "Found",
|
|
381
|
-
headers: { location: `${baseURL}${url.pathname.slice(1)}${url.search}` },
|
|
163
|
+
headers: new Headers({ location: `${baseURL}${url.pathname.slice(1)}${url.search}` }),
|
|
382
164
|
body: `Redirecting...`
|
|
383
165
|
};
|
|
384
166
|
}
|
|
385
|
-
await loadStackTrace(error).catch(consola
|
|
167
|
+
await loadStackTrace(error).catch(consola.error);
|
|
168
|
+
const { Youch } = await import("youch");
|
|
386
169
|
const youch = new Youch();
|
|
387
|
-
if (
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
consola$1.error(`[request error] ${tags} [${event.req.method}] ${url}\n\n`, ansiError);
|
|
170
|
+
if (unhandled && !opts?.silent) {
|
|
171
|
+
const ansiError = (await youch.toANSI(error)).replaceAll(process.cwd(), ".");
|
|
172
|
+
consola.error(`[request error] [${event.req.method}] ${url}\n\n`, ansiError);
|
|
391
173
|
}
|
|
392
174
|
const useJSON = opts?.json ?? !event.req.headers.get("accept")?.includes("text/html");
|
|
393
|
-
const headers = {
|
|
394
|
-
|
|
395
|
-
"
|
|
396
|
-
"
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
} });
|
|
175
|
+
const headers = new Headers(unhandled ? {} : error.headers);
|
|
176
|
+
if (useJSON) {
|
|
177
|
+
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
178
|
+
const jsonBody = typeof error.toJSON === "function" ? error.toJSON() : {
|
|
179
|
+
status,
|
|
180
|
+
statusText,
|
|
181
|
+
message: error.message
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
status,
|
|
185
|
+
statusText,
|
|
186
|
+
headers,
|
|
187
|
+
body: {
|
|
188
|
+
error: true,
|
|
189
|
+
stack: error.stack?.split("\n").map((line) => line.trim()),
|
|
190
|
+
...jsonBody
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
414
195
|
return {
|
|
415
196
|
status,
|
|
416
|
-
statusText: error.statusText,
|
|
197
|
+
statusText: unhandled ? "" : error.statusText,
|
|
417
198
|
headers,
|
|
418
|
-
body
|
|
199
|
+
body: await youch.toHTML(error, { request: {
|
|
200
|
+
url: url.href,
|
|
201
|
+
method: event.req.method,
|
|
202
|
+
headers: Object.fromEntries(event.req.headers.entries())
|
|
203
|
+
} })
|
|
419
204
|
};
|
|
420
205
|
}
|
|
421
206
|
async function loadStackTrace(error) {
|
|
422
207
|
if (!(error instanceof Error)) return;
|
|
208
|
+
const { ErrorParser } = await import("youch-core");
|
|
423
209
|
const parsed = await new ErrorParser().defineSourceLoader(sourceLoader).parse(error);
|
|
424
210
|
const stack = error.message + "\n" + parsed.frames.map((frame) => fmtFrame(frame)).join("\n");
|
|
425
211
|
Object.defineProperty(error, "stack", { value: stack });
|
|
426
|
-
if (error.cause) await loadStackTrace(error.cause).catch(consola
|
|
212
|
+
if (error.cause) await loadStackTrace(error.cause).catch(consola.error);
|
|
427
213
|
}
|
|
428
214
|
async function sourceLoader(frame) {
|
|
429
215
|
if (!frame.fileName || frame.fileType !== "fs" || frame.type === "native") return;
|
|
430
216
|
if (frame.type === "app") {
|
|
431
217
|
const rawSourceMap = await readFile(`${frame.fileName}.map`, "utf8").catch(() => {});
|
|
432
218
|
if (rawSourceMap) {
|
|
219
|
+
const { SourceMapConsumer } = await import("source-map");
|
|
433
220
|
const originalPosition = (await new SourceMapConsumer(rawSourceMap)).originalPositionFor({
|
|
434
221
|
line: frame.lineNumber,
|
|
435
222
|
column: frame.columnNumber
|
|
@@ -449,9 +236,6 @@ function fmtFrame(frame) {
|
|
|
449
236
|
const src = `${frame.fileName || ""}:${frame.lineNumber}:${frame.columnNumber})`;
|
|
450
237
|
return frame.functionName ? `at ${frame.functionName} (${src}` : `at ${src}`;
|
|
451
238
|
}
|
|
452
|
-
|
|
453
|
-
//#endregion
|
|
454
|
-
//#region src/dev/app.ts
|
|
455
239
|
var NitroDevApp = class {
|
|
456
240
|
nitro;
|
|
457
241
|
fetch;
|
|
@@ -464,9 +248,9 @@ var NitroDevApp = class {
|
|
|
464
248
|
const app = new H3({
|
|
465
249
|
debug: true,
|
|
466
250
|
onError: async (error, event) => {
|
|
467
|
-
const errorHandler = this.nitro.options.devErrorHandler ||
|
|
251
|
+
const errorHandler$1 = this.nitro.options.devErrorHandler || errorHandler;
|
|
468
252
|
await loadStackTrace(error).catch(() => {});
|
|
469
|
-
return errorHandler(error, event, { defaultHandler });
|
|
253
|
+
return errorHandler$1(error, event, { defaultHandler });
|
|
470
254
|
}
|
|
471
255
|
});
|
|
472
256
|
for (const h of this.nitro.options.devHandlers) {
|
|
@@ -509,11 +293,11 @@ function serveStaticDir(event, opts) {
|
|
|
509
293
|
return serveStatic(event, {
|
|
510
294
|
fallthrough: opts.fallthrough,
|
|
511
295
|
getMeta: async (id) => {
|
|
512
|
-
const path
|
|
513
|
-
if (!path
|
|
514
|
-
const s = await stat$1(path
|
|
296
|
+
const path = r(id);
|
|
297
|
+
if (!path) return;
|
|
298
|
+
const s = await stat$1(path).catch(() => null);
|
|
515
299
|
if (!s?.isFile()) return;
|
|
516
|
-
const ext = extname$1(path
|
|
300
|
+
const ext = extname$1(path);
|
|
517
301
|
return {
|
|
518
302
|
size: s.size,
|
|
519
303
|
mtime: s.mtime,
|
|
@@ -521,9 +305,9 @@ function serveStaticDir(event, opts) {
|
|
|
521
305
|
};
|
|
522
306
|
},
|
|
523
307
|
getContents(id) {
|
|
524
|
-
const path
|
|
525
|
-
if (!path
|
|
526
|
-
const stream = createReadStream(path
|
|
308
|
+
const path = r(id);
|
|
309
|
+
if (!path) return;
|
|
310
|
+
const stream = createReadStream(path);
|
|
527
311
|
const acceptEncoding = event.req.headers.get("accept-encoding") || "";
|
|
528
312
|
if (acceptEncoding.includes("br")) {
|
|
529
313
|
event.res.headers.set("Content-Encoding", "br");
|
|
@@ -540,9 +324,29 @@ function serveStaticDir(event, opts) {
|
|
|
540
324
|
}
|
|
541
325
|
});
|
|
542
326
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
327
|
+
function createHTTPProxy(defaults = {}) {
|
|
328
|
+
const proxy = createProxyServer({
|
|
329
|
+
xfwd: true,
|
|
330
|
+
...defaults
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
proxy,
|
|
334
|
+
async handleEvent(event, opts) {
|
|
335
|
+
try {
|
|
336
|
+
return await fromNodeHandler((req, res) => {
|
|
337
|
+
return proxy.web(req, res, opts);
|
|
338
|
+
})(event);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
event.res.headers.set("refresh", "3");
|
|
341
|
+
throw new HTTPError({
|
|
342
|
+
status: 503,
|
|
343
|
+
message: "Dev server is unavailable.",
|
|
344
|
+
cause: error
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
546
350
|
function createDevServer(nitro) {
|
|
547
351
|
return new NitroDevServer(nitro);
|
|
548
352
|
}
|
|
@@ -551,17 +355,21 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
551
355
|
#workerData = {};
|
|
552
356
|
#listeners = [];
|
|
553
357
|
#watcher;
|
|
554
|
-
#
|
|
358
|
+
#manager;
|
|
555
359
|
#workerIdCtr = 0;
|
|
556
360
|
#workerError;
|
|
361
|
+
#workerRetries = 0;
|
|
557
362
|
#building = true;
|
|
558
363
|
#buildError;
|
|
559
|
-
#
|
|
364
|
+
#reloadPromise;
|
|
560
365
|
constructor(nitro) {
|
|
561
366
|
super(nitro, async (event) => {
|
|
562
|
-
|
|
563
|
-
if (
|
|
564
|
-
return
|
|
367
|
+
if (this.#building) await this.#waitForBuild();
|
|
368
|
+
if (this.#reloadPromise) await this.#reloadPromise;
|
|
369
|
+
if (this.#buildError) return this.#generateError();
|
|
370
|
+
const response = await this.#manager.fetch(event.req);
|
|
371
|
+
if (response.status === 503 && !this.#manager.ready) return this.#generateError();
|
|
372
|
+
return response;
|
|
565
373
|
});
|
|
566
374
|
for (const key of Object.getOwnPropertyNames(NitroDevServer.prototype)) {
|
|
567
375
|
const value = this[key];
|
|
@@ -569,6 +377,20 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
569
377
|
}
|
|
570
378
|
nitro.fetch = this.fetch.bind(this);
|
|
571
379
|
this.#entry = resolve$1(nitro.options.output.dir, nitro.options.output.serverDir, "index.mjs");
|
|
380
|
+
this.#manager = new RunnerManager();
|
|
381
|
+
this.#manager.onReady(async (_runner, addr) => {
|
|
382
|
+
this.#workerRetries = 0;
|
|
383
|
+
writeDevBuildInfo(this.nitro, addr).catch((error) => {
|
|
384
|
+
this.nitro.logger.warn(`Failed to write dev build info: ${error instanceof Error ? error.message : String(error)}`);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
this.#manager.onClose((_runner, cause) => {
|
|
388
|
+
this.#workerError = cause;
|
|
389
|
+
if (this.#workerRetries++ < 3) {
|
|
390
|
+
this.nitro.logger.info("Restarting dev worker...", cause ? `Cause: ${cause}` : "");
|
|
391
|
+
this.reload();
|
|
392
|
+
} else this.nitro.logger.error("Dev worker failed after 3 retries.", cause ? `Last cause: ${cause}` : "");
|
|
393
|
+
});
|
|
572
394
|
nitro.hooks.hook("close", () => this.close());
|
|
573
395
|
nitro.hooks.hook("dev:start", () => {
|
|
574
396
|
this.#building = true;
|
|
@@ -584,7 +406,6 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
584
406
|
nitro.hooks.hook("dev:error", (cause) => {
|
|
585
407
|
this.#buildError = cause;
|
|
586
408
|
this.#building = false;
|
|
587
|
-
for (const worker of this.#workers) worker.close();
|
|
588
409
|
});
|
|
589
410
|
const devWatch = nitro.options.devServer.watch;
|
|
590
411
|
if (devWatch && devWatch.length > 0) {
|
|
@@ -594,16 +415,15 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
594
415
|
}
|
|
595
416
|
}
|
|
596
417
|
async upgrade(req, socket, head) {
|
|
597
|
-
|
|
598
|
-
if (!worker) throw new HTTPError({
|
|
599
|
-
status: 503,
|
|
600
|
-
statusText: "No worker available."
|
|
601
|
-
});
|
|
602
|
-
if (!worker.upgrade) throw new HTTPError({
|
|
418
|
+
if (!this.#manager.upgrade) throw new HTTPError({
|
|
603
419
|
status: 501,
|
|
604
420
|
statusText: "Worker does not support upgrades."
|
|
605
421
|
});
|
|
606
|
-
return
|
|
422
|
+
return this.#manager.upgrade({ node: {
|
|
423
|
+
req,
|
|
424
|
+
socket,
|
|
425
|
+
head
|
|
426
|
+
} });
|
|
607
427
|
}
|
|
608
428
|
listen(opts) {
|
|
609
429
|
const server = serve({
|
|
@@ -620,58 +440,42 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
620
440
|
Promise.all(this.#listeners.map((l) => l.close())).then(() => {
|
|
621
441
|
this.#listeners = [];
|
|
622
442
|
}),
|
|
623
|
-
|
|
624
|
-
this.#workers = [];
|
|
625
|
-
}),
|
|
443
|
+
this.#manager.close(),
|
|
626
444
|
Promise.resolve(this.#watcher?.close()).then(() => {
|
|
627
445
|
this.#watcher = void 0;
|
|
628
446
|
})
|
|
629
447
|
].map((p) => p.catch((error) => {
|
|
630
|
-
consola
|
|
448
|
+
consola.error(error);
|
|
631
449
|
})));
|
|
632
450
|
}
|
|
633
451
|
reload() {
|
|
634
|
-
|
|
635
|
-
|
|
452
|
+
const nextReload = (this.#reloadPromise ?? Promise.resolve()).catch(() => {}).then(() => this.#reload());
|
|
453
|
+
this.#reloadPromise = nextReload.finally(() => {
|
|
454
|
+
if (this.#reloadPromise === nextReload) this.#reloadPromise = void 0;
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
async #reload() {
|
|
458
|
+
const runner = await loadRunner(this.nitro.options.devServer.runner || process.env.NITRO_DEV_RUNNER || "node-worker", {
|
|
636
459
|
name: `Nitro_${this.#workerIdCtr++}`,
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
onClose: (worker$1, cause) => {
|
|
641
|
-
this.#workerError = cause;
|
|
642
|
-
const index = this.#workers.indexOf(worker$1);
|
|
643
|
-
if (index !== -1) this.#workers.splice(index, 1);
|
|
644
|
-
},
|
|
645
|
-
onReady: async (_worker, addr) => {
|
|
646
|
-
writeDevBuildInfo(this.nitro, addr).catch(() => {});
|
|
647
|
-
}
|
|
460
|
+
data: {
|
|
461
|
+
entry: this.#entry,
|
|
462
|
+
...this.#workerData
|
|
648
463
|
}
|
|
649
464
|
});
|
|
650
|
-
|
|
651
|
-
for (const listener of this.#messageListeners) worker.onMessage(listener);
|
|
652
|
-
this.#workers.unshift(worker);
|
|
653
|
-
}
|
|
465
|
+
await this.#manager.reload(runner);
|
|
654
466
|
}
|
|
655
467
|
sendMessage(message) {
|
|
656
|
-
|
|
468
|
+
this.#manager.sendMessage(message);
|
|
657
469
|
}
|
|
658
470
|
onMessage(listener) {
|
|
659
|
-
this.#
|
|
660
|
-
for (const worker of this.#workers) worker.onMessage(listener);
|
|
471
|
+
this.#manager.onMessage(listener);
|
|
661
472
|
}
|
|
662
473
|
offMessage(listener) {
|
|
663
|
-
this.#
|
|
664
|
-
for (const worker of this.#workers) worker.offMessage(listener);
|
|
474
|
+
this.#manager.offMessage(listener);
|
|
665
475
|
}
|
|
666
|
-
async #
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
while (this.#building || ++retry < maxRetries) {
|
|
670
|
-
if ((this.#workers.length === 0 || this.#buildError) && !this.#building) return;
|
|
671
|
-
const activeWorker = this.#workers.find((w) => w.ready);
|
|
672
|
-
if (activeWorker) return activeWorker;
|
|
673
|
-
await new Promise((resolve$2) => setTimeout(resolve$2, 600));
|
|
674
|
-
}
|
|
476
|
+
async #waitForBuild() {
|
|
477
|
+
const timeout = v || m ? 6e4 : 6e3;
|
|
478
|
+
await this.#manager.waitForReady(timeout);
|
|
675
479
|
}
|
|
676
480
|
#generateError() {
|
|
677
481
|
const error = this.#buildError || this.#workerError;
|
|
@@ -702,6 +506,4 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
|
|
|
702
506
|
});
|
|
703
507
|
}
|
|
704
508
|
};
|
|
705
|
-
|
|
706
|
-
//#endregion
|
|
707
|
-
export { NodeEnvRunner as i, createDevServer as n, NitroDevApp as r, NitroDevServer as t };
|
|
509
|
+
export { createDevServer as n, NitroDevApp as r, NitroDevServer as t };
|
package/dist/_libs/_.mjs
ADDED