nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-121649-98b56dfe
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/dist/_build/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +747 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +56 -52
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import { T as resolve$1, _ as dirname$1, b as join$1, f as resolveModulePath, g as basename$1, n as debounce, w as relative$1, x as normalize$1, y as isAbsolute$1 } from "../_libs/c12.mjs";
|
|
2
|
+
import { f as sanitizeFilePath } from "../_libs/local-pkg.mjs";
|
|
3
|
+
import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
|
|
4
|
+
import { n as a, t as T } from "../_libs/std-env.mjs";
|
|
5
|
+
import { a as createNitro, n as prepare, r as copyPublicAssets } from "../_chunks/B-7HiF0V.mjs";
|
|
6
|
+
import { c as prettyPath, o as scanHandlers } from "../_chunks/B5ooyfLk.mjs";
|
|
7
|
+
import { t as createProxyServer } from "../_libs/httpxy.mjs";
|
|
8
|
+
import { i as NodeDevWorker, r as NitroDevApp } from "../_dev.mjs";
|
|
9
|
+
import { i as watch$1 } from "../_libs/chokidar.mjs";
|
|
10
|
+
import { t as alias } from "../_libs/plugin-alias.mjs";
|
|
11
|
+
import { t as inject } from "../_libs/plugin-inject.mjs";
|
|
12
|
+
import { i as replace, n as baseBuildPlugins, r as baseBuildConfig, t as writeBuildInfo } from "./common.mjs";
|
|
13
|
+
import { t as assetsPlugin } from "../_libs/vite-plugin-fullstack.mjs";
|
|
14
|
+
import consola$1 from "consola";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
import { existsSync, watch } from "node:fs";
|
|
17
|
+
import { mkdir, readFile, readlink, rm, writeFile } from "node:fs/promises";
|
|
18
|
+
import { defu } from "defu";
|
|
19
|
+
import { runtimeDependencies, runtimeDir } from "nitro/runtime/meta";
|
|
20
|
+
import { colors } from "consola/utils";
|
|
21
|
+
import { NodeRequest, sendNodeResponse } from "srvx/node";
|
|
22
|
+
import { DevEnvironment } from "vite";
|
|
23
|
+
import { getRandomPort } from "get-port-please";
|
|
24
|
+
import { spawn } from "node:child_process";
|
|
25
|
+
|
|
26
|
+
//#region src/build/vite/rollup.ts
|
|
27
|
+
/**
|
|
28
|
+
* Removed from base rollup config:
|
|
29
|
+
* - nodeResolve
|
|
30
|
+
* - commonjs
|
|
31
|
+
* - esbuild
|
|
32
|
+
* - sourcemapMininify
|
|
33
|
+
* - json
|
|
34
|
+
* - raw
|
|
35
|
+
*
|
|
36
|
+
* TODO: Reuse with rollup:
|
|
37
|
+
* - chunkFileNames
|
|
38
|
+
* - moduleSideEffects
|
|
39
|
+
*/
|
|
40
|
+
const getViteRollupConfig = (ctx) => {
|
|
41
|
+
const nitro$1 = ctx.nitro;
|
|
42
|
+
const base = baseBuildConfig(nitro$1);
|
|
43
|
+
const chunkNamePrefixes = [
|
|
44
|
+
[nitro$1.options.buildDir, "build"],
|
|
45
|
+
[base.buildServerDir, "app"],
|
|
46
|
+
[runtimeDir, "nitro"],
|
|
47
|
+
[base.presetsDir, "nitro"],
|
|
48
|
+
["\0nitro-wasm:", "wasm"],
|
|
49
|
+
["\0", "virtual"]
|
|
50
|
+
];
|
|
51
|
+
function getChunkGroup(id) {
|
|
52
|
+
if (id.startsWith(runtimeDir) || id.startsWith(base.presetsDir)) return "nitro";
|
|
53
|
+
}
|
|
54
|
+
let config = {
|
|
55
|
+
input: nitro$1.options.entry,
|
|
56
|
+
external: [...base.env.external],
|
|
57
|
+
plugins: [
|
|
58
|
+
ctx.pluginConfig.experimental?.virtualBundle && virtualBundlePlugin(ctx._serviceBundles),
|
|
59
|
+
...baseBuildPlugins(nitro$1, base),
|
|
60
|
+
alias({ entries: base.aliases }),
|
|
61
|
+
replace({
|
|
62
|
+
delimiters: base.replaceDelimiters,
|
|
63
|
+
preventAssignment: true,
|
|
64
|
+
values: base.replacements
|
|
65
|
+
}),
|
|
66
|
+
inject(base.env.inject)
|
|
67
|
+
].filter(Boolean),
|
|
68
|
+
treeshake: { moduleSideEffects(id) {
|
|
69
|
+
const normalizedId = normalize$1(id);
|
|
70
|
+
const idWithoutNodeModules = normalizedId.split("node_modules/").pop();
|
|
71
|
+
if (!idWithoutNodeModules) return false;
|
|
72
|
+
if (normalizedId.startsWith(runtimeDir) || idWithoutNodeModules.startsWith(runtimeDir)) return true;
|
|
73
|
+
return nitro$1.options.moduleSideEffects.some((m) => normalizedId.startsWith(m) || idWithoutNodeModules.startsWith(m));
|
|
74
|
+
} },
|
|
75
|
+
output: {
|
|
76
|
+
dir: nitro$1.options.output.serverDir,
|
|
77
|
+
entryFileNames: "index.mjs",
|
|
78
|
+
chunkFileNames(chunk) {
|
|
79
|
+
const id = normalize$1(chunk.moduleIds.at(-1) || "");
|
|
80
|
+
for (const [dir, name] of chunkNamePrefixes) if (id.startsWith(dir)) return `chunks/${name}/[name].mjs`;
|
|
81
|
+
const routeHandler = nitro$1.options.handlers.find((h) => id.startsWith(h.handler)) || nitro$1.scannedHandlers.find((h) => id.startsWith(h.handler));
|
|
82
|
+
if (routeHandler?.route) return `chunks/routes/${routeHandler.route.replace(/:([^/]+)/g, "_$1").replace(/\/[^/]+$/g, "") || "/"}/[name].mjs`.replace(/\/+/g, "/");
|
|
83
|
+
if (Object.entries(nitro$1.options.tasks).find(([_, task]) => task.handler === id)) return `chunks/tasks/[name].mjs`;
|
|
84
|
+
return `chunks/_/[name].mjs`;
|
|
85
|
+
},
|
|
86
|
+
manualChunks(id) {
|
|
87
|
+
return getChunkGroup(id);
|
|
88
|
+
},
|
|
89
|
+
inlineDynamicImports: nitro$1.options.inlineDynamicImports,
|
|
90
|
+
format: "esm",
|
|
91
|
+
exports: "auto",
|
|
92
|
+
intro: "",
|
|
93
|
+
outro: "",
|
|
94
|
+
generatedCode: { constBindings: true },
|
|
95
|
+
sanitizeFileName: sanitizeFilePath,
|
|
96
|
+
sourcemapExcludeSources: true,
|
|
97
|
+
sourcemapIgnoreList(relativePath) {
|
|
98
|
+
return relativePath.includes("node_modules");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
config = defu(nitro$1.options.rollupConfig, config);
|
|
103
|
+
if (config.output.inlineDynamicImports) delete config.output.manualChunks;
|
|
104
|
+
return {
|
|
105
|
+
config,
|
|
106
|
+
base
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
function virtualBundlePlugin(bundles) {
|
|
110
|
+
let _modules = null;
|
|
111
|
+
const getModules = () => {
|
|
112
|
+
if (_modules) return _modules;
|
|
113
|
+
_modules = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const bundle of Object.values(bundles)) for (const [fileName, content] of Object.entries(bundle)) if (content.type === "chunk") {
|
|
115
|
+
const virtualModule = {
|
|
116
|
+
code: content.code,
|
|
117
|
+
map: null
|
|
118
|
+
};
|
|
119
|
+
const maybeMap = bundle[`${fileName}.map`];
|
|
120
|
+
if (maybeMap && maybeMap.type === "asset") virtualModule.map = maybeMap.source;
|
|
121
|
+
_modules.set(fileName, virtualModule);
|
|
122
|
+
_modules.set(resolve$1(fileName), virtualModule);
|
|
123
|
+
}
|
|
124
|
+
return _modules;
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
name: "virtual-bundle",
|
|
128
|
+
resolveId(id, importer) {
|
|
129
|
+
const modules = getModules();
|
|
130
|
+
if (modules.has(id)) return resolve$1(id);
|
|
131
|
+
if (importer) {
|
|
132
|
+
const resolved = resolve$1(dirname$1(importer), id);
|
|
133
|
+
if (modules.has(resolved)) return resolved;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
},
|
|
137
|
+
load(id) {
|
|
138
|
+
const m = getModules().get(id);
|
|
139
|
+
if (!m) return null;
|
|
140
|
+
return m;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/build/vite/prod.ts
|
|
147
|
+
const BuilderNames = {
|
|
148
|
+
nitro: colors.magenta("Nitro"),
|
|
149
|
+
client: colors.green("Client"),
|
|
150
|
+
ssr: colors.blue("SSR")
|
|
151
|
+
};
|
|
152
|
+
async function buildEnvironments(ctx, builder) {
|
|
153
|
+
const nitro$1 = ctx.nitro;
|
|
154
|
+
for (const [envName, env] of Object.entries(builder.environments)) {
|
|
155
|
+
const fmtName = BuilderNames[envName] || (envName.length <= 3 ? envName.toUpperCase() : envName[0].toUpperCase() + envName.slice(1));
|
|
156
|
+
if (envName === "nitro" || !env.config.build.rollupOptions.input || env.isBuilt) {
|
|
157
|
+
if (![
|
|
158
|
+
"nitro",
|
|
159
|
+
"ssr",
|
|
160
|
+
"client"
|
|
161
|
+
].includes(envName)) nitro$1.logger.info(env.isBuilt ? `Skipping ${fmtName} (already built)` : `Skipping ${fmtName} (no input defined)`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!a && !T) console.log();
|
|
165
|
+
nitro$1.logger.start(`Building [${fmtName}]`);
|
|
166
|
+
await builder.build(env);
|
|
167
|
+
}
|
|
168
|
+
const nitroOptions = ctx.nitro.options;
|
|
169
|
+
const clientInput = builder.environments.client?.config?.build?.rollupOptions?.input;
|
|
170
|
+
if (nitroOptions.renderer?.template && nitroOptions.renderer?.template === clientInput) {
|
|
171
|
+
const outputPath = resolve$1(nitroOptions.output.publicDir, basename$1(clientInput));
|
|
172
|
+
if (existsSync(outputPath)) {
|
|
173
|
+
const html = await readFile(outputPath, "utf8").then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
|
|
174
|
+
await rm(outputPath);
|
|
175
|
+
const tmp = resolve$1(nitroOptions.buildDir, "vite/index.html");
|
|
176
|
+
await mkdir(dirname$1(tmp), { recursive: true });
|
|
177
|
+
await writeFile(tmp, html, "utf8");
|
|
178
|
+
nitroOptions.renderer.template = tmp;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await builder.writeAssetsManifest?.();
|
|
182
|
+
if (!a && !T) console.log();
|
|
183
|
+
const buildInfo = [["preset", nitro$1.options.preset], ["compatibility", formatCompatibilityDate(nitro$1.options.compatibilityDate)]].filter((e) => e[1]);
|
|
184
|
+
nitro$1.logger.start(`Building [${BuilderNames.nitro}] ${colors.dim(`(${buildInfo.map(([k, v]) => `${k}: \`${v}\``).join(", ")})`)}`);
|
|
185
|
+
await copyPublicAssets(nitro$1);
|
|
186
|
+
await builder.build(builder.environments.nitro);
|
|
187
|
+
await nitro$1.close();
|
|
188
|
+
await nitro$1.hooks.callHook("compiled", nitro$1);
|
|
189
|
+
await writeBuildInfo(nitro$1);
|
|
190
|
+
const rOutput = relative$1(process.cwd(), nitro$1.options.output.dir);
|
|
191
|
+
const rewriteRelativePaths = (input) => {
|
|
192
|
+
return input.replace(/([\s:])\.\/(\S*)/g, `$1${rOutput}/$2`);
|
|
193
|
+
};
|
|
194
|
+
if (!a && !T) console.log();
|
|
195
|
+
if (nitro$1.options.commands.preview) nitro$1.logger.success(`You can preview this build using \`${rewriteRelativePaths(nitro$1.options.commands.preview)}\``);
|
|
196
|
+
if (nitro$1.options.commands.deploy) nitro$1.logger.success(`You can deploy this build using \`${rewriteRelativePaths(nitro$1.options.commands.deploy)}\``);
|
|
197
|
+
}
|
|
198
|
+
function prodSetup(ctx) {
|
|
199
|
+
const services = ctx.pluginConfig.services || {};
|
|
200
|
+
const serviceEntries = Object.keys(services).map((name) => {
|
|
201
|
+
let entry;
|
|
202
|
+
if (ctx.pluginConfig.experimental?.virtualBundle) entry = ctx._entryPoints[name];
|
|
203
|
+
else entry = resolve$1(ctx.nitro.options.buildDir, "vite/services", name, ctx._entryPoints[name]);
|
|
204
|
+
return [name, entry];
|
|
205
|
+
});
|
|
206
|
+
return `
|
|
207
|
+
import { setupVite } from "${resolve$1(runtimeDir, "internal/vite/prod-setup.mjs")}";
|
|
208
|
+
|
|
209
|
+
const manifest = ${JSON.stringify(ctx._manifest || {})};
|
|
210
|
+
|
|
211
|
+
function lazyService(loader) {
|
|
212
|
+
let promise, mod
|
|
213
|
+
return {
|
|
214
|
+
fetch(req) {
|
|
215
|
+
if (mod) { return mod.fetch(req) }
|
|
216
|
+
if (!promise) {
|
|
217
|
+
promise = loader().then(_mod => (mod = _mod.default || _mod))
|
|
218
|
+
}
|
|
219
|
+
return promise.then(mod => mod.fetch(req))
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const services = {
|
|
225
|
+
${serviceEntries.map(([name, entry]) => `[${JSON.stringify(name)}]: lazyService(() => import(${JSON.stringify(entry)}))`).join(",\n")}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
setupVite({ manifest, services });
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/build/vite/dev.ts
|
|
234
|
+
function createFetchableDevEnvironment(name, config, devServer, entry) {
|
|
235
|
+
return new FetchableDevEnvironment(name, config, {
|
|
236
|
+
hot: true,
|
|
237
|
+
transport: createTransport(name, devServer)
|
|
238
|
+
}, devServer, entry);
|
|
239
|
+
}
|
|
240
|
+
var FetchableDevEnvironment = class extends DevEnvironment {
|
|
241
|
+
devServer;
|
|
242
|
+
constructor(name, config, context, devServer, entry) {
|
|
243
|
+
super(name, config, context);
|
|
244
|
+
this.devServer = devServer;
|
|
245
|
+
this.devServer.sendMessage({
|
|
246
|
+
type: "custom",
|
|
247
|
+
event: "nitro:vite-env",
|
|
248
|
+
data: {
|
|
249
|
+
name,
|
|
250
|
+
entry
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
async dispatchFetch(request) {
|
|
255
|
+
return this.devServer.fetch(request);
|
|
256
|
+
}
|
|
257
|
+
async init(...args) {
|
|
258
|
+
await this.devServer.init?.();
|
|
259
|
+
return super.init(...args);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
function createTransport(name, hooks) {
|
|
263
|
+
const listeners = /* @__PURE__ */ new WeakMap();
|
|
264
|
+
return {
|
|
265
|
+
send: (data) => hooks.sendMessage({
|
|
266
|
+
...data,
|
|
267
|
+
viteEnv: name
|
|
268
|
+
}),
|
|
269
|
+
on: (event, handler) => {
|
|
270
|
+
if (event === "connection") return;
|
|
271
|
+
const listener = (value) => {
|
|
272
|
+
if (value?.type === "custom" && value.event === event && value.viteEnv === name) handler(value.data, { send: (payload) => hooks.sendMessage({
|
|
273
|
+
...payload,
|
|
274
|
+
viteEnv: name
|
|
275
|
+
}) });
|
|
276
|
+
};
|
|
277
|
+
listeners.set(handler, listener);
|
|
278
|
+
hooks.onMessage(listener);
|
|
279
|
+
},
|
|
280
|
+
off: (event, handler) => {
|
|
281
|
+
if (event === "connection") return;
|
|
282
|
+
const listener = listeners.get(handler);
|
|
283
|
+
if (listener) {
|
|
284
|
+
hooks.offMessage(listener);
|
|
285
|
+
listeners.delete(handler);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async function configureViteDevServer(ctx, server) {
|
|
291
|
+
const nitro$1 = ctx.nitro;
|
|
292
|
+
const nitroEnv$1 = server.environments.nitro;
|
|
293
|
+
const nitroConfigFile = nitro$1.options._c12.configFile;
|
|
294
|
+
if (nitroConfigFile) server.config.configFileDependencies.push(nitroConfigFile);
|
|
295
|
+
const reload = debounce(async () => {
|
|
296
|
+
await scanHandlers(nitro$1);
|
|
297
|
+
nitro$1.routing.sync();
|
|
298
|
+
nitroEnv$1.moduleGraph.invalidateAll();
|
|
299
|
+
nitroEnv$1.hot.send({ type: "full-reload" });
|
|
300
|
+
});
|
|
301
|
+
const scanDirs = nitro$1.options.scanDirs.flatMap((dir) => [
|
|
302
|
+
join$1(dir, nitro$1.options.apiDir || "api"),
|
|
303
|
+
join$1(dir, nitro$1.options.routesDir || "routes"),
|
|
304
|
+
join$1(dir, "middleware"),
|
|
305
|
+
join$1(dir, "plugins"),
|
|
306
|
+
join$1(dir, "modules")
|
|
307
|
+
]);
|
|
308
|
+
const watchReloadEvents = new Set([
|
|
309
|
+
"add",
|
|
310
|
+
"addDir",
|
|
311
|
+
"unlink",
|
|
312
|
+
"unlinkDir"
|
|
313
|
+
]);
|
|
314
|
+
const scanDirsWatcher = watch$1(scanDirs, { ignoreInitial: true }).on("all", (event, path$1, stat$1) => {
|
|
315
|
+
if (watchReloadEvents.has(event)) reload();
|
|
316
|
+
});
|
|
317
|
+
const srcDirWatcher = watch(nitro$1.options.srcDir, { persistent: false }, (_event, filename) => {
|
|
318
|
+
if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) reload();
|
|
319
|
+
});
|
|
320
|
+
nitro$1.hooks.hook("close", () => {
|
|
321
|
+
scanDirsWatcher.close();
|
|
322
|
+
srcDirWatcher.close();
|
|
323
|
+
});
|
|
324
|
+
const hostIPC = { async transformHTML(html) {
|
|
325
|
+
return server.transformIndexHtml("/", html).then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
|
|
326
|
+
} };
|
|
327
|
+
nitroEnv$1.devServer.onMessage(async (payload) => {
|
|
328
|
+
if (payload.type === "custom" && payload.event === "nitro:vite-invoke") {
|
|
329
|
+
const res = await hostIPC[payload.data.name](payload.data.data).then((data) => ({ data })).catch((error) => ({ error }));
|
|
330
|
+
nitroEnv$1.devServer.sendMessage({
|
|
331
|
+
type: "custom",
|
|
332
|
+
event: "nitro:vite-invoke-response",
|
|
333
|
+
data: {
|
|
334
|
+
id: payload.data.id,
|
|
335
|
+
data: res
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
const nitroDevMiddleware = async (nodeReq, nodeRes, next) => {
|
|
341
|
+
if (/^\/@(?:vite|fs|id)\//.test(nodeReq.url) || nodeReq._nitroHandled) return next();
|
|
342
|
+
nodeReq._nitroHandled = true;
|
|
343
|
+
const req = new NodeRequest({
|
|
344
|
+
req: nodeReq,
|
|
345
|
+
res: nodeRes
|
|
346
|
+
});
|
|
347
|
+
const devAppRes = await ctx.devApp.fetch(req);
|
|
348
|
+
if (nodeRes.writableEnded || nodeRes.headersSent) return;
|
|
349
|
+
if (devAppRes.status !== 404) return await sendNodeResponse(nodeRes, devAppRes);
|
|
350
|
+
const envRes = await nitroEnv$1.dispatchFetch(req);
|
|
351
|
+
if (nodeRes.writableEnded || nodeRes.headersSent) return;
|
|
352
|
+
if (envRes.status !== 404) return await sendNodeResponse(nodeRes, envRes);
|
|
353
|
+
return next();
|
|
354
|
+
};
|
|
355
|
+
server.middlewares.use(function nitroDevMiddlewarePre(req, res, next) {
|
|
356
|
+
const fetchDest = req.headers["sec-fetch-dest"];
|
|
357
|
+
if (fetchDest) res.setHeader("vary", "sec-fetch-dest");
|
|
358
|
+
if (!((req.url || "").match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1] || "") && (!fetchDest || /^(document|iframe|frame|empty)$/.test(fetchDest))) nitroDevMiddleware(req, res, next);
|
|
359
|
+
else next();
|
|
360
|
+
});
|
|
361
|
+
return () => {
|
|
362
|
+
server.middlewares.use(nitroDevMiddleware);
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/build/vite/env.ts
|
|
368
|
+
function createDevWorker(ctx) {
|
|
369
|
+
return new NodeDevWorker({
|
|
370
|
+
name: "nitro-vite",
|
|
371
|
+
entry: resolve(runtimeDir, "internal/vite/dev-worker.mjs"),
|
|
372
|
+
hooks: {},
|
|
373
|
+
data: {
|
|
374
|
+
server: true,
|
|
375
|
+
globals: { __NITRO_RUNTIME_CONFIG__: ctx.nitro.options.runtimeConfig }
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function createNitroEnvironment(ctx) {
|
|
380
|
+
return {
|
|
381
|
+
consumer: "server",
|
|
382
|
+
build: {
|
|
383
|
+
rollupOptions: ctx.rollupConfig.config,
|
|
384
|
+
minify: ctx.nitro.options.minify,
|
|
385
|
+
emptyOutDir: false,
|
|
386
|
+
commonjsOptions: {
|
|
387
|
+
strictRequires: "auto",
|
|
388
|
+
esmExternals: (id) => !id.startsWith("unenv/"),
|
|
389
|
+
requireReturnsDefault: "auto",
|
|
390
|
+
...ctx.nitro.options.commonJS
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
resolve: {
|
|
394
|
+
noExternal: ctx.nitro.options.dev ? new RegExp(runtimeDependencies.join("|")) : true,
|
|
395
|
+
conditions: ctx.nitro.options.exportConditions,
|
|
396
|
+
externalConditions: ctx.nitro.options.exportConditions
|
|
397
|
+
},
|
|
398
|
+
dev: { createEnvironment: (envName, envConfig) => createFetchableDevEnvironment(envName, envConfig, ctx.devWorker, resolve(runtimeDir, "internal/vite/dev-entry.mjs")) }
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function createServiceEnvironment(ctx, name, serviceConfig) {
|
|
402
|
+
return {
|
|
403
|
+
consumer: "server",
|
|
404
|
+
build: {
|
|
405
|
+
rollupOptions: { input: serviceConfig.entry },
|
|
406
|
+
minify: ctx.nitro.options.minify,
|
|
407
|
+
outDir: join(ctx.nitro.options.buildDir, "vite", "services", name),
|
|
408
|
+
emptyOutDir: true
|
|
409
|
+
},
|
|
410
|
+
resolve: {
|
|
411
|
+
conditions: ctx.nitro.options.exportConditions,
|
|
412
|
+
externalConditions: ctx.nitro.options.exportConditions
|
|
413
|
+
},
|
|
414
|
+
dev: { createEnvironment: (envName, envConfig) => createFetchableDevEnvironment(envName, envConfig, ctx.devWorker, tryResolve(serviceConfig.entry)) }
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function createServiceEnvironments(ctx) {
|
|
418
|
+
return Object.fromEntries(Object.entries(ctx.pluginConfig.services || {}).map(([name, config]) => [name, createServiceEnvironment(ctx, name, config)]));
|
|
419
|
+
}
|
|
420
|
+
function tryResolve(id) {
|
|
421
|
+
if (/^[~#/\0]/.test(id) || isAbsolute$1(id)) return id;
|
|
422
|
+
return resolveModulePath(id, {
|
|
423
|
+
suffixes: ["", "/index"],
|
|
424
|
+
extensions: [
|
|
425
|
+
"",
|
|
426
|
+
".ts",
|
|
427
|
+
".mjs",
|
|
428
|
+
".cjs",
|
|
429
|
+
".js",
|
|
430
|
+
".mts",
|
|
431
|
+
".cts"
|
|
432
|
+
],
|
|
433
|
+
try: true
|
|
434
|
+
}) || id;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/build/vite/preview.ts
|
|
439
|
+
function nitroPreviewPlugin(ctx) {
|
|
440
|
+
return {
|
|
441
|
+
name: "nitro:preview",
|
|
442
|
+
apply: (_config, configEnv) => !!configEnv.isPreview,
|
|
443
|
+
config(config) {
|
|
444
|
+
return { preview: { port: config.preview?.port || 3e3 } };
|
|
445
|
+
},
|
|
446
|
+
async configurePreviewServer(server) {
|
|
447
|
+
const buildInfoPath = resolve$1(server.config.root, "node_modules/.nitro/last-build", "nitro.json");
|
|
448
|
+
if (!existsSync(buildInfoPath)) {
|
|
449
|
+
console.warn(`[nitro] No build found. Please build your project before previewing.`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const realBuildDir = await readlink("node_modules/.nitro/last-build");
|
|
453
|
+
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
454
|
+
const info = [
|
|
455
|
+
["Build Directory:", prettyPath(realBuildDir)],
|
|
456
|
+
["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
|
|
457
|
+
["Nitro Version:", buildInfo.versions.nitro],
|
|
458
|
+
["Nitro Preset:", buildInfo.preset],
|
|
459
|
+
buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
|
|
460
|
+
].filter((i) => i && i[1]);
|
|
461
|
+
consola$1.box({
|
|
462
|
+
title: " [Build Info] ",
|
|
463
|
+
message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
|
|
464
|
+
});
|
|
465
|
+
if (!buildInfo.commands?.preview) {
|
|
466
|
+
consola$1.warn("[nitro] No preview command found for this preset..");
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const randomPort = await getRandomPort();
|
|
470
|
+
consola$1.info(`Spawning preview server...`);
|
|
471
|
+
const [command, ...args] = buildInfo.commands.preview.split(" ");
|
|
472
|
+
let child;
|
|
473
|
+
consola$1.info(buildInfo.commands?.preview);
|
|
474
|
+
child = spawn(command, args, {
|
|
475
|
+
stdio: "inherit",
|
|
476
|
+
cwd: realBuildDir,
|
|
477
|
+
env: {
|
|
478
|
+
...process.env,
|
|
479
|
+
PORT: String(randomPort)
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
process.on("exit", () => {
|
|
483
|
+
child?.kill();
|
|
484
|
+
child = void 0;
|
|
485
|
+
});
|
|
486
|
+
child.on("exit", (code) => {
|
|
487
|
+
if (code && code !== 0) consola$1.error(`[nitro] Preview server exited with code ${code}`);
|
|
488
|
+
});
|
|
489
|
+
const proxy = createProxyServer({ target: `http://localhost:${randomPort}` });
|
|
490
|
+
server.middlewares.use((req, res, next) => {
|
|
491
|
+
if (child && !child.killed) proxy.web(req, res).catch(next);
|
|
492
|
+
else res.end(`Nitro preview server is not running.`);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/build/vite/plugin.ts
|
|
500
|
+
const DEFAULT_EXTENSIONS = [
|
|
501
|
+
".ts",
|
|
502
|
+
".js",
|
|
503
|
+
".mts",
|
|
504
|
+
".mjs",
|
|
505
|
+
".tsx",
|
|
506
|
+
".jsx"
|
|
507
|
+
];
|
|
508
|
+
const debug = process.env.NITRO_DEBUG ? (...args) => console.log("[nitro]", ...args) : () => {};
|
|
509
|
+
function nitro(pluginConfig = {}) {
|
|
510
|
+
const ctx = createContext(pluginConfig);
|
|
511
|
+
return [
|
|
512
|
+
nitroInit(ctx),
|
|
513
|
+
nitroEnv(ctx),
|
|
514
|
+
nitroMain(ctx),
|
|
515
|
+
nitroPrepare(ctx),
|
|
516
|
+
nitroService(ctx),
|
|
517
|
+
nitroPreviewPlugin(ctx),
|
|
518
|
+
pluginConfig.experimental?.assetsImport !== false && assetsPlugin({ experimental: { clientBuildFallback: false } })
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
function nitroInit(ctx) {
|
|
522
|
+
return {
|
|
523
|
+
name: "nitro:init",
|
|
524
|
+
sharedDuringBuild: true,
|
|
525
|
+
apply: (_config, configEnv) => !configEnv.isPreview,
|
|
526
|
+
async config(config, configEnv) {
|
|
527
|
+
if (!ctx._initialized) {
|
|
528
|
+
debug("[init] Initializing nitro");
|
|
529
|
+
ctx._initialized = true;
|
|
530
|
+
await setupNitroContext(ctx, configEnv, config);
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
applyToEnvironment(env) {
|
|
534
|
+
if (env.name === "nitro" && ctx.nitro?.options.dev) {
|
|
535
|
+
debug("[init] Adding rollup plugins for dev");
|
|
536
|
+
return [...ctx.rollupConfig?.config.plugins || []];
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function nitroEnv(ctx) {
|
|
542
|
+
return {
|
|
543
|
+
name: "nitro:env",
|
|
544
|
+
sharedDuringBuild: true,
|
|
545
|
+
apply: (_config, configEnv) => !configEnv.isPreview,
|
|
546
|
+
async config(userConfig, _configEnv) {
|
|
547
|
+
debug("[env] Extending config (environments)");
|
|
548
|
+
const environments = {
|
|
549
|
+
...createServiceEnvironments(ctx),
|
|
550
|
+
nitro: createNitroEnvironment(ctx)
|
|
551
|
+
};
|
|
552
|
+
environments.client = {
|
|
553
|
+
consumer: userConfig.environments?.client?.consumer ?? "client",
|
|
554
|
+
build: { rollupOptions: { input: userConfig.environments?.client?.build?.rollupOptions?.input ?? useNitro(ctx).options.renderer?.template } }
|
|
555
|
+
};
|
|
556
|
+
debug("[env] Environments:", Object.keys(environments).join(", "));
|
|
557
|
+
return { environments };
|
|
558
|
+
},
|
|
559
|
+
configEnvironment(name, config) {
|
|
560
|
+
if (config.consumer === "client") {
|
|
561
|
+
debug("[env] Configuring client environment", name === "client" ? "" : ` (${name})`);
|
|
562
|
+
config.build.emptyOutDir = false;
|
|
563
|
+
config.build.outDir = useNitro(ctx).options.output.publicDir;
|
|
564
|
+
} else if (ctx.pluginConfig.experimental?.virtualBundle && name in (ctx.pluginConfig.services || {})) {
|
|
565
|
+
debug("[env] Configuring service environment for virtual:", name);
|
|
566
|
+
config.build ??= {};
|
|
567
|
+
config.build.write = config.build.write ?? false;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function nitroMain(ctx) {
|
|
573
|
+
return {
|
|
574
|
+
name: "nitro:main",
|
|
575
|
+
sharedDuringBuild: true,
|
|
576
|
+
apply: (_config, configEnv) => !configEnv.isPreview,
|
|
577
|
+
async config(userConfig, _configEnv) {
|
|
578
|
+
debug("[main] Extending config (appType, resolve, server)");
|
|
579
|
+
if (!ctx.rollupConfig) throw new Error("Nitro rollup config is not initialized yet.");
|
|
580
|
+
return {
|
|
581
|
+
appType: userConfig.appType || "custom",
|
|
582
|
+
resolve: { alias: ctx.rollupConfig.base.aliases },
|
|
583
|
+
builder: { sharedConfigBuild: true },
|
|
584
|
+
server: {
|
|
585
|
+
port: Number.parseInt(process.env.PORT || "") || userConfig.server?.port || useNitro(ctx).options.devServer?.port || 3e3,
|
|
586
|
+
cors: false
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
configResolved(config) {
|
|
591
|
+
if (config.command === "build") {
|
|
592
|
+
debug("[main] Inferring caching routes");
|
|
593
|
+
for (const env of Object.values(config.environments)) if (env.consumer === "client") {
|
|
594
|
+
const rule = ctx.nitro.options.routeRules[`/${env.build.assetsDir}/**`] ??= {};
|
|
595
|
+
if (!rule.headers?.["cache-control"]) rule.headers = {
|
|
596
|
+
...rule.headers,
|
|
597
|
+
"cache-control": `public, max-age=31536000, immutable`
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
debug("[main] Syncing nitro routes");
|
|
602
|
+
ctx.nitro.routing.sync();
|
|
603
|
+
},
|
|
604
|
+
buildApp: {
|
|
605
|
+
order: "post",
|
|
606
|
+
handler(builder) {
|
|
607
|
+
debug("[main] Building environments");
|
|
608
|
+
return buildEnvironments(ctx, builder);
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
generateBundle: { handler(_options, bundle) {
|
|
612
|
+
const environment = this.environment;
|
|
613
|
+
debug("[main] Generating manifest and entry points for environment:", environment.name);
|
|
614
|
+
const { root } = environment.config;
|
|
615
|
+
const services = ctx.pluginConfig.services || {};
|
|
616
|
+
const isRegisteredService = Object.keys(services).includes(environment.name);
|
|
617
|
+
let entryFile;
|
|
618
|
+
for (const [_name, file] of Object.entries(bundle)) if (file.type === "chunk") {
|
|
619
|
+
if (isRegisteredService && file.isEntry) if (entryFile === void 0) entryFile = file.fileName;
|
|
620
|
+
else this.warn(`Multiple entry points found for service "${environment.name}"`);
|
|
621
|
+
const filteredModuleIds = file.moduleIds.filter((id) => id.startsWith(root));
|
|
622
|
+
for (const id of filteredModuleIds) {
|
|
623
|
+
const originalFile = relative$1(root, id);
|
|
624
|
+
ctx._manifest[originalFile] = { file: file.fileName };
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (isRegisteredService) {
|
|
628
|
+
if (entryFile === void 0) this.error(`No entry point found for service "${this.environment.name}".`);
|
|
629
|
+
ctx._entryPoints[this.environment.name] = entryFile;
|
|
630
|
+
ctx._serviceBundles[this.environment.name] = bundle;
|
|
631
|
+
}
|
|
632
|
+
} },
|
|
633
|
+
configureServer: (server) => {
|
|
634
|
+
debug("[main] Configuring dev server");
|
|
635
|
+
return configureViteDevServer(ctx, server);
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function nitroPrepare(ctx) {
|
|
640
|
+
return {
|
|
641
|
+
name: "nitro:prepare",
|
|
642
|
+
sharedDuringBuild: true,
|
|
643
|
+
applyToEnvironment: (env) => env.name === "nitro",
|
|
644
|
+
buildApp: {
|
|
645
|
+
order: "pre",
|
|
646
|
+
async handler() {
|
|
647
|
+
debug("[prepare] Preparing output directory");
|
|
648
|
+
const nitro$1 = ctx.nitro;
|
|
649
|
+
await prepare(nitro$1);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function nitroService(ctx) {
|
|
655
|
+
return {
|
|
656
|
+
name: "nitro:service",
|
|
657
|
+
enforce: "pre",
|
|
658
|
+
sharedDuringBuild: true,
|
|
659
|
+
applyToEnvironment: (env) => env.name === "nitro",
|
|
660
|
+
resolveId: { async handler(id) {
|
|
661
|
+
if (id === "#nitro-vite-setup") return {
|
|
662
|
+
id,
|
|
663
|
+
moduleSideEffects: true
|
|
664
|
+
};
|
|
665
|
+
if (id === "#nitro-vite-services") return id;
|
|
666
|
+
} },
|
|
667
|
+
load: { async handler(id) {
|
|
668
|
+
if (id === "#nitro-vite-setup") return prodSetup(ctx);
|
|
669
|
+
} }
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function createContext(pluginConfig) {
|
|
673
|
+
return {
|
|
674
|
+
pluginConfig,
|
|
675
|
+
_entryPoints: {},
|
|
676
|
+
_manifest: {},
|
|
677
|
+
_serviceBundles: {}
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function useNitro(ctx) {
|
|
681
|
+
if (!ctx.nitro) throw new Error("Nitro instance is not initialized yet.");
|
|
682
|
+
return ctx.nitro;
|
|
683
|
+
}
|
|
684
|
+
async function setupNitroContext(ctx, configEnv, userConfig) {
|
|
685
|
+
ctx.nitro = ctx.pluginConfig._nitro || await createNitro({
|
|
686
|
+
dev: configEnv.mode === "development",
|
|
687
|
+
rootDir: userConfig.root,
|
|
688
|
+
...defu(ctx.pluginConfig.config, userConfig.nitro)
|
|
689
|
+
});
|
|
690
|
+
if (!ctx.pluginConfig.services?.ssr) {
|
|
691
|
+
ctx.pluginConfig.services ??= {};
|
|
692
|
+
if (userConfig.environments?.ssr === void 0) {
|
|
693
|
+
const ssrEntry = resolveModulePath("./entry-server", {
|
|
694
|
+
from: [
|
|
695
|
+
"",
|
|
696
|
+
"app",
|
|
697
|
+
"src"
|
|
698
|
+
].flatMap((d) => ctx.nitro.options.scanDirs.map((s) => join$1(s, d) + "/")),
|
|
699
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
700
|
+
try: true
|
|
701
|
+
});
|
|
702
|
+
if (ssrEntry) {
|
|
703
|
+
ctx.pluginConfig.services.ssr = { entry: ssrEntry };
|
|
704
|
+
ctx.nitro.logger.info(`Using \`${prettyPath(ssrEntry)}\` as vite ssr entry.`);
|
|
705
|
+
}
|
|
706
|
+
} else {
|
|
707
|
+
let ssrEntry = getEntry(userConfig.environments.ssr.build?.rollupOptions?.input);
|
|
708
|
+
if (typeof ssrEntry === "string") {
|
|
709
|
+
ssrEntry = resolveModulePath(ssrEntry, {
|
|
710
|
+
from: ctx.nitro.options.scanDirs,
|
|
711
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
712
|
+
suffixes: ["", "/index"],
|
|
713
|
+
try: true
|
|
714
|
+
}) || ssrEntry;
|
|
715
|
+
ctx.pluginConfig.services.ssr = { entry: ssrEntry };
|
|
716
|
+
} else throw new TypeError(`Invalid input type for SSR entry point.`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (!ctx.nitro.options.renderer?.entry && !ctx.nitro.options.renderer?.template && ctx.pluginConfig.services.ssr?.entry) {
|
|
720
|
+
ctx.nitro.options.renderer ??= {};
|
|
721
|
+
ctx.nitro.options.renderer.entry = resolve$1(runtimeDir, "internal/vite/ssr-renderer");
|
|
722
|
+
}
|
|
723
|
+
const publicDistDir = ctx._publicDistDir = userConfig.build?.outDir || resolve$1(ctx.nitro.options.buildDir, "vite/public");
|
|
724
|
+
ctx.nitro.options.publicAssets.push({
|
|
725
|
+
dir: publicDistDir,
|
|
726
|
+
maxAge: 0,
|
|
727
|
+
baseURL: "/",
|
|
728
|
+
fallthrough: true
|
|
729
|
+
});
|
|
730
|
+
if (!ctx.nitro.options.dev) ctx.nitro.options.unenv.push({
|
|
731
|
+
meta: { name: "nitro-vite" },
|
|
732
|
+
polyfill: ["#nitro-vite-setup"]
|
|
733
|
+
});
|
|
734
|
+
await ctx.nitro.hooks.callHook("build:before", ctx.nitro);
|
|
735
|
+
ctx.rollupConfig = await getViteRollupConfig(ctx);
|
|
736
|
+
await ctx.nitro.hooks.callHook("rollup:before", ctx.nitro, ctx.rollupConfig.config);
|
|
737
|
+
if (ctx.nitro.options.dev && !ctx.devWorker) ctx.devWorker = createDevWorker(ctx);
|
|
738
|
+
if (ctx.nitro.options.dev && !ctx.devApp) ctx.devApp = new NitroDevApp(ctx.nitro);
|
|
739
|
+
}
|
|
740
|
+
function getEntry(input) {
|
|
741
|
+
if (typeof input === "string") return input;
|
|
742
|
+
else if (Array.isArray(input) && input.length > 0) return input[0];
|
|
743
|
+
else if (input && "index" in input) return input.index;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
//#endregion
|
|
747
|
+
export { nitro as t };
|