nitro-nightly 3.0.1-alpha.1 → 3.0.1-alpha.2
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/README.md +2 -0
- package/dist/_build/common.mjs +24924 -52
- package/dist/_build/rolldown.mjs +29 -63
- package/dist/_build/rollup.mjs +22 -110
- package/dist/_build/vite.build.mjs +3 -43
- package/dist/{_dev.mjs → _chunks/dev.mjs} +45 -43
- package/dist/_chunks/{B-D1JOIz.mjs → nitro.mjs} +144 -308
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +254 -0
- package/dist/{_chunks/Bqks5huO.mjs → _common.mjs} +24 -10
- package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
- package/dist/_libs/citty.mjs +140 -110
- package/dist/_libs/{plugin-commonjs.mjs → commondir+is-reference.mjs} +59 -250
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/confbox.mjs +388 -799
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/{plugin-node-resolve.mjs → hasown+resolve+deepmerge.mjs} +497 -78
- package/dist/_libs/httpxy.d.mts +79 -0
- package/dist/_libs/httpxy.mjs +6 -1
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +4 -2
- package/dist/_libs/plugin-inject.mjs +5 -5
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
- package/dist/_libs/{vite-plugin-fullstack.mjs → pluginutils.mjs} +244 -153
- package/dist/_libs/rc9+c12+dotenv.mjs +972 -0
- package/dist/_libs/{chokidar.mjs → readdirp+chokidar.mjs} +237 -187
- package/dist/_libs/remapping.mjs +1 -1
- package/dist/_libs/{gen-mapping.mjs → resolve-uri+gen-mapping.mjs} +2 -166
- package/dist/_libs/rou3.d.mts +43 -0
- package/dist/_libs/rou3.mjs +9 -6
- package/dist/_libs/std-env.d.mts +4 -0
- package/dist/_libs/tsconfck.mjs +3 -3
- package/dist/_libs/{unimport.mjs → unimport+unplugin.mjs} +226 -1961
- package/dist/_libs/unplugin+unimport.d.mts +426 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +130 -80
- package/dist/builder.d.mts +4 -4
- package/dist/builder.mjs +6 -30
- package/dist/cli/_chunks/build.mjs +1 -1
- package/dist/cli/_chunks/dev.mjs +5 -11
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/node_modules/@poppinss/colors/build/index.js +130 -160
- package/dist/node_modules/@poppinss/colors/package.json +20 -18
- package/dist/node_modules/@poppinss/exception/build/index.js +36 -55
- package/dist/node_modules/@poppinss/exception/package.json +19 -16
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +46 -5
- package/dist/node_modules/@sindresorhus/is/package.json +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
- package/dist/node_modules/@speed-highlight/core/package.json +2 -2
- package/dist/node_modules/hookable/dist/index.mjs +5 -6
- package/dist/node_modules/hookable/package.json +13 -13
- package/dist/node_modules/ufo/dist/index.mjs +16 -9
- package/dist/node_modules/ufo/package.json +15 -14
- package/dist/node_modules/unctx/package.json +16 -16
- package/dist/node_modules/youch/build/{chunk-4XB2BYKC.js → chunk-7QV3D5YX.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-PUHGL6HA.js → chunk-AUGPHE32.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-F4I6KX4R.js → chunk-CM7DWJNZ.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-YYEJ3AGB.js → chunk-EJH674NB.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-EUJBVOYB.js → chunk-OIJ3WD7L.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-HFSXRSKS.js → chunk-P36L72PL.js} +5 -3
- package/dist/node_modules/youch/build/{chunk-4YEN7HVQ.js → chunk-PE3GG3TN.js} +5 -1
- package/dist/node_modules/youch/build/{chunk-PINJDICN.js → chunk-X53OIOJH.js} +2 -4
- package/dist/node_modules/youch/build/index.js +8 -9
- package/dist/node_modules/youch/build/public/error_info/style.css +1 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +2 -3
- package/dist/node_modules/youch/package.json +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +5 -6
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -1
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +2 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -1
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -5
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +9 -11
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +1 -1
- package/dist/presets/azure/runtime/azure-swa.d.mts +1 -1
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/bun/runtime/bun.d.mts +1 -1
- package/dist/presets/bun/runtime/bun.mjs +7 -8
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +3 -3
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +19 -17
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +17 -16
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +8 -9
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +12 -18
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-deploy.mjs +4 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-server.mjs +5 -6
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +1 -2
- package/dist/presets/netlify/runtime/netlify-edge.mjs +3 -2
- package/dist/presets/netlify/runtime/netlify.d.mts +3 -2
- package/dist/presets/netlify/runtime/netlify.mjs +3 -1
- package/dist/presets/node/runtime/node-cluster.d.mts +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +5 -6
- package/dist/presets/node/runtime/node-middleware.d.mts +1 -1
- package/dist/presets/node/runtime/node-middleware.mjs +4 -5
- package/dist/presets/node/runtime/node-server.d.mts +1 -1
- package/dist/presets/node/runtime/node-server.mjs +5 -6
- package/dist/presets/standard/runtime/server.d.mts +1 -1
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/presets/stormkit/runtime/stormkit.d.mts +1 -1
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
- package/dist/presets/vercel/runtime/isr.d.mts +2 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.node.mjs +16 -7
- package/dist/presets/vercel/runtime/vercel.web.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.web.mjs +18 -13
- package/dist/presets/winterjs/runtime/winterjs.d.mts +1 -2
- package/dist/presets/winterjs/runtime/winterjs.mjs +1 -1
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +1 -1
- package/dist/runtime/app.d.mts +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +7 -3
- package/dist/runtime/internal/app.mjs +29 -22
- package/dist/runtime/internal/database.mjs +1 -1
- package/dist/runtime/internal/error/dev.d.mts +0 -1
- package/dist/runtime/internal/error/dev.mjs +1 -1
- package/dist/runtime/internal/route-rules.d.mts +0 -4
- package/dist/runtime/internal/routes/dev-tasks.mjs +1 -1
- package/dist/runtime/internal/routes/openapi.d.mts +0 -1
- package/dist/runtime/internal/routes/openapi.mjs +3 -3
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +1 -1
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +0 -1
- package/dist/runtime/internal/routes/scalar.mjs +4 -4
- package/dist/runtime/internal/routes/swagger.d.mts +0 -1
- package/dist/runtime/internal/routes/swagger.mjs +3 -3
- package/dist/runtime/internal/runtime-config.mjs +8 -8
- package/dist/runtime/internal/static.mjs +1 -1
- package/dist/runtime/internal/storage.mjs +1 -1
- package/dist/runtime/internal/task.mjs +1 -1
- package/dist/runtime/internal/vite/dev-entry.mjs +3 -4
- package/dist/runtime/internal/vite/{dev-worker.mjs → node-runner.mjs} +51 -6
- package/dist/runtime/meta.d.mts +1 -1
- package/dist/runtime/meta.mjs +1 -1
- package/dist/runtime/nitro.d.mts +0 -3
- package/dist/runtime/nitro.mjs +1 -1
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +6 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/types/index.d.mts +292 -371
- package/dist/types/index.mjs +10 -0
- package/dist/vite.d.mts +7 -12
- package/dist/vite.mjs +734 -41
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +82 -53
- package/dist/_build/common2.mjs +0 -772
- package/dist/_build/vite.plugin.mjs +0 -768
- package/dist/_chunks/ANM1K1bE.mjs +0 -304
- package/dist/_chunks/BX9-zVkM.mjs +0 -59
- package/dist/_chunks/C7CbzoI1.mjs +0 -39
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/c12.mjs +0 -2858
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/giget.mjs +0 -19289
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -32
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -1686
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/node-fetch-native.mjs +0 -173
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -41
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/plugin-replace.mjs +0 -104
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5836
- package/dist/cli/_chunks/detect-acorn.mjs +0 -12
- package/dist/cli/_chunks/dist.mjs +0 -3
- package/dist/cli/_chunks/dist2.mjs +0 -3
- package/dist/cli/_chunks/dist3.mjs +0 -3
- package/dist/cli/_chunks/dist4.mjs +0 -4
- package/dist/cli/_chunks/dist5.mjs +0 -4
- package/dist/cli/_chunks/esm.mjs +0 -3
- package/dist/cli/_chunks/json5.mjs +0 -4
- package/dist/cli/_chunks/jsonc.mjs +0 -4
- package/dist/cli/_chunks/multipart-parser.mjs +0 -6
- package/dist/cli/_chunks/toml.mjs +0 -4
- package/dist/cli/_chunks/yaml.mjs +0 -4
- package/dist/node_modules/kleur/index.js +0 -110
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +0 -6
- package/lib/deps/ofetch.mjs +0 -1
- package/lib/deps/ofetch.mts +0 -1
- /package/dist/runtime/{vite-runtime.d.mts → vite.d.mts} +0 -0
- /package/dist/runtime/{vite-runtime.mjs → vite.mjs} +0 -0
- /package/lib/{deps/h3.d.mts → h3.d.mts} +0 -0
- /package/lib/{deps/h3.mjs → h3.mjs} +0 -0
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as createUnimport } from "../_libs/unimport.mjs";
|
|
4
|
-
import { t as glob } from "../_libs/tinyglobby.mjs";
|
|
1
|
+
import { $ as resolveModulePath, A as compressPublicAssets, H as d, I as prettyPath, L as resolveNitroPath, M as build, R as writeFile$1, V as a, at as join, ct as resolve, et as resolveModuleURL, j as src_default, k as scanUnprefixedPublicAssets, p as runParallel, q as findWorkspaceDir, st as relative } from "../_build/common.mjs";
|
|
2
|
+
import { n as loadConfig, r as watchConfig } from "../_libs/rc9+c12+dotenv.mjs";
|
|
5
3
|
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
6
4
|
import { t as klona } from "../_libs/klona.mjs";
|
|
7
|
-
import { i as d, r as a } from "../_libs/std-env.mjs";
|
|
8
5
|
import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
|
|
9
6
|
import { n as parse, t as TSConfckCache } from "../_libs/tsconfck.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { i as scanHandlers, r as scanAndSyncOptions, t as runParallel } from "./ANM1K1bE.mjs";
|
|
7
|
+
import { n as scanHandlers, t as scanAndSyncOptions } from "./nitro2.mjs";
|
|
12
8
|
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
13
|
-
import { t as src_default } from "../_libs/mime.mjs";
|
|
14
9
|
import { n as z, t as P } from "../_libs/ultrahtml.mjs";
|
|
15
10
|
import { createRequire } from "node:module";
|
|
16
11
|
import consola$1, { consola } from "consola";
|
|
17
12
|
import { Hookable, createDebugger } from "hookable";
|
|
18
|
-
import { existsSync
|
|
19
|
-
import {
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
20
15
|
import { pathToFileURL } from "node:url";
|
|
21
|
-
import fsp, { readFile } from "node:fs/promises";
|
|
22
16
|
import { defu } from "defu";
|
|
23
|
-
import {
|
|
17
|
+
import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
18
|
+
import { runtimeDir } from "nitro/meta";
|
|
24
19
|
import { colors } from "consola/utils";
|
|
25
|
-
import { ofetch } from "ofetch";
|
|
26
20
|
import { hash } from "ohash";
|
|
27
|
-
import
|
|
21
|
+
import http from "node:http";
|
|
28
22
|
import { toRequest } from "h3";
|
|
29
23
|
|
|
30
24
|
//#region src/config/defaults.ts
|
|
@@ -58,6 +52,7 @@ const NitroDefaults = {
|
|
|
58
52
|
virtual: {},
|
|
59
53
|
compressPublicAssets: false,
|
|
60
54
|
ignore: [],
|
|
55
|
+
wasm: {},
|
|
61
56
|
dev: false,
|
|
62
57
|
devServer: { watch: [] },
|
|
63
58
|
watchOptions: { ignoreInitial: true },
|
|
@@ -88,6 +83,7 @@ const NitroDefaults = {
|
|
|
88
83
|
replace: {},
|
|
89
84
|
node: true,
|
|
90
85
|
sourcemap: false,
|
|
86
|
+
traceDeps: [],
|
|
91
87
|
typescript: {
|
|
92
88
|
strict: true,
|
|
93
89
|
generateRuntimeConfigTypes: false,
|
|
@@ -95,7 +91,6 @@ const NitroDefaults = {
|
|
|
95
91
|
tsconfigPath: "tsconfig.json",
|
|
96
92
|
tsConfig: void 0
|
|
97
93
|
},
|
|
98
|
-
nodeModulesDirs: [],
|
|
99
94
|
hooks: {},
|
|
100
95
|
commands: {},
|
|
101
96
|
framework: {
|
|
@@ -142,6 +137,7 @@ async function resolveCompatibilityOptions(options) {
|
|
|
142
137
|
//#region src/config/resolvers/database.ts
|
|
143
138
|
async function resolveDatabaseOptions(options) {
|
|
144
139
|
if (options.experimental.database && options.imports) {
|
|
140
|
+
options.imports.presets ??= [];
|
|
145
141
|
options.imports.presets.push({
|
|
146
142
|
from: "nitro/database",
|
|
147
143
|
imports: ["useDatabase"]
|
|
@@ -163,7 +159,7 @@ async function resolveExportConditionsOptions(options) {
|
|
|
163
159
|
options.exportConditions = _resolveExportConditions(options.exportConditions || [], {
|
|
164
160
|
dev: options.dev,
|
|
165
161
|
node: options.node,
|
|
166
|
-
wasm: options.
|
|
162
|
+
wasm: options.wasm !== false
|
|
167
163
|
});
|
|
168
164
|
}
|
|
169
165
|
function _resolveExportConditions(conditions, opts) {
|
|
@@ -173,7 +169,7 @@ function _resolveExportConditions(conditions, opts) {
|
|
|
173
169
|
if (opts.node) resolvedConditions.push("node");
|
|
174
170
|
else resolvedConditions.push("wintercg", "worker", "web", "browser", "workerd", "edge-light", "netlify", "edge-routine", "deno");
|
|
175
171
|
if (opts.wasm) resolvedConditions.push("wasm", "unwasm");
|
|
176
|
-
resolvedConditions.push("import", "default");
|
|
172
|
+
resolvedConditions.push("import", "default", "module");
|
|
177
173
|
if ("Bun" in globalThis) resolvedConditions.push("bun");
|
|
178
174
|
else if ("Deno" in globalThis) resolvedConditions.push("deno");
|
|
179
175
|
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
|
|
@@ -239,7 +235,7 @@ async function resolveOpenAPIOptions(options) {
|
|
|
239
235
|
async function resolveTsconfig(options) {
|
|
240
236
|
const root = resolve(options.rootDir || ".") + "/";
|
|
241
237
|
if (!options.typescript.tsConfig) options.typescript.tsConfig = await loadTsconfig(root);
|
|
242
|
-
if (options.experimental.tsconfigPaths
|
|
238
|
+
if (options.experimental.tsconfigPaths && options.typescript.tsConfig.compilerOptions?.paths) options.alias = {
|
|
243
239
|
...tsConfigToAliasObj(options.typescript.tsConfig, root),
|
|
244
240
|
...options.alias
|
|
245
241
|
};
|
|
@@ -309,12 +305,6 @@ async function resolvePathOptions(options) {
|
|
|
309
305
|
options.output.dir = resolveNitroPath(options.output.dir || NitroDefaults.output.dir, options, options.rootDir) + "/";
|
|
310
306
|
options.output.publicDir = resolveNitroPath(options.output.publicDir || NitroDefaults.output.publicDir, options, options.rootDir) + "/";
|
|
311
307
|
options.output.serverDir = resolveNitroPath(options.output.serverDir || NitroDefaults.output.serverDir, options, options.rootDir) + "/";
|
|
312
|
-
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
313
|
-
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
314
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "dist/node_modules"));
|
|
315
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
316
|
-
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
317
|
-
options.nodeModulesDirs = [...new Set(options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir) + "/"))];
|
|
318
308
|
options.plugins = options.plugins.map((p) => resolveNitroPath(p, options));
|
|
319
309
|
if (options.serverDir) options.scanDirs.unshift(options.serverDir);
|
|
320
310
|
options.scanDirs = options.scanDirs.map((dir) => resolve(options.rootDir, dir));
|
|
@@ -330,43 +320,53 @@ async function resolvePathOptions(options) {
|
|
|
330
320
|
h.handler = resolveNitroPath(h.handler, options);
|
|
331
321
|
return [route, h];
|
|
332
322
|
}));
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
323
|
+
if (options.serverEntry !== false) {
|
|
324
|
+
if (typeof options?.serverEntry === "string") options.serverEntry = { handler: options.serverEntry };
|
|
325
|
+
if (options.serverEntry?.handler) options.serverEntry.handler = resolveNitroPath(options.serverEntry.handler, options);
|
|
326
|
+
else {
|
|
327
|
+
const detected = resolveModulePath("./server", {
|
|
328
|
+
try: true,
|
|
329
|
+
from: options.rootDir,
|
|
330
|
+
extensions: RESOLVE_EXTENSIONS.flatMap((ext) => [ext, `.node${ext}`])
|
|
331
|
+
});
|
|
332
|
+
if (detected) {
|
|
333
|
+
options.serverEntry ??= { handler: "" };
|
|
334
|
+
options.serverEntry.handler = detected;
|
|
335
|
+
consola$1.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
|
|
343
336
|
}
|
|
344
337
|
}
|
|
338
|
+
if (options.serverEntry?.handler && !options.serverEntry?.format) {
|
|
339
|
+
const isNode = /\.(node)\.\w+$/.test(options.serverEntry.handler);
|
|
340
|
+
options.serverEntry.format = isNode ? "node" : "web";
|
|
341
|
+
}
|
|
345
342
|
}
|
|
346
|
-
if (options.renderer
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
else if (!options.renderer?.handler) {
|
|
355
|
-
const defaultIndex = resolveModulePath("./index.html", {
|
|
343
|
+
if (options.renderer === false) options.renderer = void 0;
|
|
344
|
+
else {
|
|
345
|
+
if (options.renderer?.handler) options.renderer.handler = resolveModulePath(resolveNitroPath(options.renderer?.handler, options), {
|
|
346
|
+
from: [options.rootDir, ...options.scanDirs],
|
|
347
|
+
extensions: RESOLVE_EXTENSIONS
|
|
348
|
+
});
|
|
349
|
+
if (options.renderer?.template) options.renderer.template = resolveModulePath(resolveNitroPath(options.renderer?.template, options), {
|
|
356
350
|
from: [options.rootDir, ...options.scanDirs],
|
|
357
|
-
extensions: [".html"]
|
|
358
|
-
try: true
|
|
351
|
+
extensions: [".html"]
|
|
359
352
|
});
|
|
360
|
-
if (
|
|
353
|
+
else if (!options.renderer?.handler) {
|
|
354
|
+
const defaultIndex = resolveModulePath("./index.html", {
|
|
355
|
+
from: [options.rootDir, ...options.scanDirs],
|
|
356
|
+
extensions: [".html"],
|
|
357
|
+
try: true
|
|
358
|
+
});
|
|
359
|
+
if (defaultIndex) {
|
|
360
|
+
options.renderer ??= {};
|
|
361
|
+
options.renderer.template = defaultIndex;
|
|
362
|
+
consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (options.renderer?.template && !options.renderer?.handler) {
|
|
361
366
|
options.renderer ??= {};
|
|
362
|
-
options.renderer.
|
|
363
|
-
consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
367
|
+
options.renderer.handler = join(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
364
368
|
}
|
|
365
369
|
}
|
|
366
|
-
if (options.renderer?.template && !options.renderer?.handler) {
|
|
367
|
-
options.renderer ??= {};
|
|
368
|
-
options.renderer.handler = join(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
369
|
-
}
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
//#endregion
|
|
@@ -428,6 +428,7 @@ function normalizeRuntimeConfig(config) {
|
|
|
428
428
|
openAPI: config.openAPI
|
|
429
429
|
}
|
|
430
430
|
});
|
|
431
|
+
runtimeConfig.nitro ??= {};
|
|
431
432
|
runtimeConfig.nitro.routeRules = config.routeRules;
|
|
432
433
|
checkSerializableRuntimeConfig(runtimeConfig);
|
|
433
434
|
return runtimeConfig;
|
|
@@ -517,16 +518,15 @@ async function resolveUnenv(options) {
|
|
|
517
518
|
//#endregion
|
|
518
519
|
//#region src/config/resolvers/builder.ts
|
|
519
520
|
const VALID_BUILDERS = [
|
|
520
|
-
"rollup",
|
|
521
521
|
"rolldown",
|
|
522
|
-
"
|
|
523
|
-
"
|
|
522
|
+
"rollup",
|
|
523
|
+
"vite"
|
|
524
524
|
];
|
|
525
525
|
async function resolveBuilder(options) {
|
|
526
526
|
options.builder ??= process.env.NITRO_BUILDER;
|
|
527
527
|
if (options.builder) {
|
|
528
528
|
if (!VALID_BUILDERS.includes(options.builder)) throw new Error(`Invalid nitro builder "${options.builder}". Valid builders are: ${VALID_BUILDERS.join(", ")}.`);
|
|
529
|
-
const pkg = options.builder
|
|
529
|
+
const pkg = options.builder;
|
|
530
530
|
if (!isPkgInstalled(pkg, options.rootDir)) {
|
|
531
531
|
if (!await consola$1.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
|
|
532
532
|
type: "confirm",
|
|
@@ -567,8 +567,8 @@ function isPkgInstalled(pkg, root) {
|
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
async function installPkg(pkg, root) {
|
|
570
|
-
const { addDevDependency } = await import("../
|
|
571
|
-
return addDevDependency(pkg
|
|
570
|
+
const { addDevDependency } = await import("../_libs/nypm+giget+tinyexec.mjs").then((n) => n.n);
|
|
571
|
+
return addDevDependency(pkg, { cwd: root });
|
|
572
572
|
}
|
|
573
573
|
|
|
574
574
|
//#endregion
|
|
@@ -702,71 +702,6 @@ async function _resolveNitroModule(mod, nitroOptions) {
|
|
|
702
702
|
};
|
|
703
703
|
}
|
|
704
704
|
|
|
705
|
-
//#endregion
|
|
706
|
-
//#region src/task.ts
|
|
707
|
-
/** @experimental */
|
|
708
|
-
async function runTask(taskEvent, opts) {
|
|
709
|
-
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
710
|
-
method: "POST",
|
|
711
|
-
body: taskEvent
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
/** @experimental */
|
|
715
|
-
async function listTasks(opts) {
|
|
716
|
-
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
717
|
-
}
|
|
718
|
-
function addNitroTasksVirtualFile(nitro) {
|
|
719
|
-
nitro.options.virtual["#nitro-internal-virtual/tasks"] = () => {
|
|
720
|
-
const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {}).map(([cron, _tasks]) => {
|
|
721
|
-
return {
|
|
722
|
-
cron,
|
|
723
|
-
tasks: (Array.isArray(_tasks) ? _tasks : [_tasks]).filter((name) => {
|
|
724
|
-
if (!nitro.options.tasks[name]) {
|
|
725
|
-
nitro.logger.warn(`Scheduled task \`${name}\` is not defined!`);
|
|
726
|
-
return false;
|
|
727
|
-
}
|
|
728
|
-
return true;
|
|
729
|
-
})
|
|
730
|
-
};
|
|
731
|
-
}).filter((e) => e.tasks.length > 0);
|
|
732
|
-
const scheduledTasks = _scheduledTasks.length > 0 ? _scheduledTasks : false;
|
|
733
|
-
return `
|
|
734
|
-
export const scheduledTasks = ${JSON.stringify(scheduledTasks)};
|
|
735
|
-
|
|
736
|
-
export const tasks = {
|
|
737
|
-
${Object.entries(nitro.options.tasks).map(([name, task]) => `"${name}": {
|
|
738
|
-
meta: {
|
|
739
|
-
description: ${JSON.stringify(task.description)},
|
|
740
|
-
},
|
|
741
|
-
resolve: ${task.handler ? `() => import("${normalize(task.handler)}").then(r => r.default || r)` : "undefined"},
|
|
742
|
-
}`).join(",\n")}
|
|
743
|
-
};`;
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
const _devHint = `(is dev server running?)`;
|
|
747
|
-
async function _getTasksContext(opts) {
|
|
748
|
-
const buildInfoPath = resolve(resolve(resolve(process.cwd(), opts?.cwd || "."), opts?.buildDir || "node_modules/.nitro"), "nitro.dev.json");
|
|
749
|
-
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
750
|
-
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
751
|
-
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
752
|
-
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
753
|
-
return {
|
|
754
|
-
buildInfo,
|
|
755
|
-
devFetch: ofetch.create({
|
|
756
|
-
baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`,
|
|
757
|
-
socketPath: buildInfo.dev.workerAddress.socketPath
|
|
758
|
-
})
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
function _pidIsRunning(pid) {
|
|
762
|
-
try {
|
|
763
|
-
process.kill(pid, 0);
|
|
764
|
-
return true;
|
|
765
|
-
} catch {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
705
|
//#endregion
|
|
771
706
|
//#region src/routing.ts
|
|
772
707
|
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
@@ -805,6 +740,12 @@ function initNitroRouting(nitro) {
|
|
|
805
740
|
...nitro.options.handlers,
|
|
806
741
|
...nitro.scannedHandlers
|
|
807
742
|
].filter((h) => h && !h.middleware && matchesEnv(h));
|
|
743
|
+
if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
|
|
744
|
+
route: "/**",
|
|
745
|
+
lazy: false,
|
|
746
|
+
format: nitro.options.serverEntry.format,
|
|
747
|
+
handler: nitro.options.serverEntry.handler
|
|
748
|
+
});
|
|
808
749
|
if (nitro.options.renderer?.handler) _routes.push({
|
|
809
750
|
route: "/**",
|
|
810
751
|
lazy: true,
|
|
@@ -867,10 +808,17 @@ var Router = class {
|
|
|
867
808
|
return this._routes.length > 0;
|
|
868
809
|
}
|
|
869
810
|
compileToString(opts) {
|
|
870
|
-
|
|
871
|
-
this._compiled
|
|
872
|
-
if (this.
|
|
873
|
-
|
|
811
|
+
const key = opts ? hash(opts) : "";
|
|
812
|
+
this._compiled ||= {};
|
|
813
|
+
if (this._compiled[key]) return this._compiled[key];
|
|
814
|
+
this._compiled[key] = compileRouterToString(this._router, void 0, opts);
|
|
815
|
+
if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
|
|
816
|
+
const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
|
|
817
|
+
let retCode = `{data,params:{"_":p.slice(1)}}`;
|
|
818
|
+
if (opts?.matchAll) retCode = `[${retCode}]`;
|
|
819
|
+
this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
|
|
820
|
+
}
|
|
821
|
+
return this._compiled[key];
|
|
874
822
|
}
|
|
875
823
|
match(method, path) {
|
|
876
824
|
return findRoute(this._router, method, path)?.data;
|
|
@@ -917,7 +865,7 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
917
865
|
const nitro = {
|
|
918
866
|
options: await loadOptions(config, opts),
|
|
919
867
|
hooks: new Hookable(),
|
|
920
|
-
vfs:
|
|
868
|
+
vfs: /* @__PURE__ */ new Map(),
|
|
921
869
|
routing: {},
|
|
922
870
|
logger: consola.withTag("nitro"),
|
|
923
871
|
scannedHandlers: [],
|
|
@@ -935,9 +883,9 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
935
883
|
if (nitro.options.debug) createDebugger(nitro.hooks, { tag: "nitro" });
|
|
936
884
|
if (nitro.options.logLevel !== void 0) nitro.logger.level = nitro.options.logLevel;
|
|
937
885
|
nitro.hooks.addHooks(nitro.options.hooks);
|
|
938
|
-
addNitroTasksVirtualFile(nitro);
|
|
939
886
|
await installModules(nitro);
|
|
940
887
|
if (nitro.options.imports) {
|
|
888
|
+
const { createUnimport } = await import("../_build/common.mjs").then((n) => n.v);
|
|
941
889
|
nitro.unimport = createUnimport(nitro.options.imports);
|
|
942
890
|
await nitro.unimport.init();
|
|
943
891
|
nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
|
|
@@ -948,180 +896,6 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
948
896
|
return nitro;
|
|
949
897
|
}
|
|
950
898
|
|
|
951
|
-
//#endregion
|
|
952
|
-
//#region src/build/build.ts
|
|
953
|
-
async function build(nitro) {
|
|
954
|
-
switch (nitro.options.builder) {
|
|
955
|
-
case "rollup": {
|
|
956
|
-
const { rollupBuild } = await import("../_build/rollup.mjs");
|
|
957
|
-
return rollupBuild(nitro);
|
|
958
|
-
}
|
|
959
|
-
case "rolldown": {
|
|
960
|
-
const { rolldownBuild } = await import("../_build/rolldown.mjs");
|
|
961
|
-
return rolldownBuild(nitro);
|
|
962
|
-
}
|
|
963
|
-
case "vite":
|
|
964
|
-
case "rolldown-vite": {
|
|
965
|
-
const { viteBuild } = await import("../_build/vite.build.mjs");
|
|
966
|
-
return viteBuild(nitro);
|
|
967
|
-
}
|
|
968
|
-
default: throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
//#endregion
|
|
973
|
-
//#region src/utils/compress.ts
|
|
974
|
-
async function compressPublicAssets(nitro) {
|
|
975
|
-
const publicFiles = await glob("**", {
|
|
976
|
-
cwd: nitro.options.output.publicDir,
|
|
977
|
-
absolute: false,
|
|
978
|
-
dot: true,
|
|
979
|
-
ignore: ["**/*.gz", "**/*.br"]
|
|
980
|
-
});
|
|
981
|
-
await Promise.all(publicFiles.map(async (fileName) => {
|
|
982
|
-
const filePath = resolve(nitro.options.output.publicDir, fileName);
|
|
983
|
-
if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) return;
|
|
984
|
-
const mimeType = src_default.getType(fileName) || "text/plain";
|
|
985
|
-
const fileContents = await fsp.readFile(filePath);
|
|
986
|
-
if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) return;
|
|
987
|
-
const { gzip, brotli } = nitro.options.compressPublicAssets || {};
|
|
988
|
-
const encodings = [gzip !== false && "gzip", brotli !== false && "br"].filter(Boolean);
|
|
989
|
-
await Promise.all(encodings.map(async (encoding) => {
|
|
990
|
-
const compressedPath = filePath + ("." + (encoding === "gzip" ? "gz" : "br"));
|
|
991
|
-
if (existsSync(compressedPath)) return;
|
|
992
|
-
const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
|
|
993
|
-
const brotliOptions = {
|
|
994
|
-
[zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
|
|
995
|
-
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
996
|
-
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
|
|
997
|
-
};
|
|
998
|
-
const compressedBuff = await new Promise((resolve$1, reject) => {
|
|
999
|
-
const cb = (error, result) => error ? reject(error) : resolve$1(result);
|
|
1000
|
-
if (encoding === "gzip") zlib.gzip(fileContents, gzipOptions, cb);
|
|
1001
|
-
else zlib.brotliCompress(fileContents, brotliOptions, cb);
|
|
1002
|
-
});
|
|
1003
|
-
await fsp.writeFile(compressedPath, compressedBuff);
|
|
1004
|
-
}));
|
|
1005
|
-
}));
|
|
1006
|
-
}
|
|
1007
|
-
function isTextMime(mimeType) {
|
|
1008
|
-
return /text|javascript|json|xml/.test(mimeType);
|
|
1009
|
-
}
|
|
1010
|
-
const COMPRESSIBLE_MIMES_RE = new Set([
|
|
1011
|
-
"application/dash+xml",
|
|
1012
|
-
"application/eot",
|
|
1013
|
-
"application/font",
|
|
1014
|
-
"application/font-sfnt",
|
|
1015
|
-
"application/javascript",
|
|
1016
|
-
"application/json",
|
|
1017
|
-
"application/opentype",
|
|
1018
|
-
"application/otf",
|
|
1019
|
-
"application/pdf",
|
|
1020
|
-
"application/pkcs7-mime",
|
|
1021
|
-
"application/protobuf",
|
|
1022
|
-
"application/rss+xml",
|
|
1023
|
-
"application/truetype",
|
|
1024
|
-
"application/ttf",
|
|
1025
|
-
"application/vnd.apple.mpegurl",
|
|
1026
|
-
"application/vnd.mapbox-vector-tile",
|
|
1027
|
-
"application/vnd.ms-fontobject",
|
|
1028
|
-
"application/wasm",
|
|
1029
|
-
"application/xhtml+xml",
|
|
1030
|
-
"application/xml",
|
|
1031
|
-
"application/x-font-opentype",
|
|
1032
|
-
"application/x-font-truetype",
|
|
1033
|
-
"application/x-font-ttf",
|
|
1034
|
-
"application/x-httpd-cgi",
|
|
1035
|
-
"application/x-javascript",
|
|
1036
|
-
"application/x-mpegurl",
|
|
1037
|
-
"application/x-opentype",
|
|
1038
|
-
"application/x-otf",
|
|
1039
|
-
"application/x-perl",
|
|
1040
|
-
"application/x-ttf",
|
|
1041
|
-
"font/eot",
|
|
1042
|
-
"font/opentype",
|
|
1043
|
-
"font/otf",
|
|
1044
|
-
"font/ttf",
|
|
1045
|
-
"image/svg+xml",
|
|
1046
|
-
"text/css",
|
|
1047
|
-
"text/csv",
|
|
1048
|
-
"text/html",
|
|
1049
|
-
"text/javascript",
|
|
1050
|
-
"text/js",
|
|
1051
|
-
"text/plain",
|
|
1052
|
-
"text/richtext",
|
|
1053
|
-
"text/tab-separated-values",
|
|
1054
|
-
"text/xml",
|
|
1055
|
-
"text/x-component",
|
|
1056
|
-
"text/x-java-source",
|
|
1057
|
-
"text/x-script",
|
|
1058
|
-
"vnd.apple.mpegurl"
|
|
1059
|
-
]);
|
|
1060
|
-
function isCompressibleMime(mimeType) {
|
|
1061
|
-
return COMPRESSIBLE_MIMES_RE.has(mimeType);
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/build/assets.ts
|
|
1066
|
-
const NEGATION_RE = /^(!?)(.*)$/;
|
|
1067
|
-
const PARENT_DIR_GLOB_RE = /!?\.\.\//;
|
|
1068
|
-
async function scanUnprefixedPublicAssets(nitro) {
|
|
1069
|
-
const scannedPaths = [];
|
|
1070
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1071
|
-
if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) continue;
|
|
1072
|
-
if (!await isDirectory(asset.dir)) continue;
|
|
1073
|
-
const publicAssets = await glob(getIncludePatterns(nitro, asset.dir), {
|
|
1074
|
-
cwd: asset.dir,
|
|
1075
|
-
absolute: false,
|
|
1076
|
-
dot: true
|
|
1077
|
-
});
|
|
1078
|
-
scannedPaths.push(...publicAssets.map((file) => join(asset.baseURL || "/", file)));
|
|
1079
|
-
}
|
|
1080
|
-
return scannedPaths;
|
|
1081
|
-
}
|
|
1082
|
-
async function copyPublicAssets(nitro) {
|
|
1083
|
-
if (nitro.options.noPublicDir) return;
|
|
1084
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1085
|
-
const assetDir = asset.dir;
|
|
1086
|
-
const dstDir = join(nitro.options.output.publicDir, asset.baseURL);
|
|
1087
|
-
if (await isDirectory(assetDir)) {
|
|
1088
|
-
const publicAssets = await glob(getIncludePatterns(nitro, assetDir), {
|
|
1089
|
-
cwd: assetDir,
|
|
1090
|
-
absolute: false,
|
|
1091
|
-
dot: true
|
|
1092
|
-
});
|
|
1093
|
-
await Promise.all(publicAssets.map(async (file) => {
|
|
1094
|
-
const src = join(assetDir, file);
|
|
1095
|
-
const dst = join(dstDir, file);
|
|
1096
|
-
if (!existsSync(dst)) await promises.cp(src, dst);
|
|
1097
|
-
}));
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1101
|
-
nitro.logger.success("Generated public " + prettyPath(nitro.options.output.publicDir));
|
|
1102
|
-
}
|
|
1103
|
-
function getIncludePatterns(nitro, assetDir) {
|
|
1104
|
-
return ["**", ...nitro.options.ignore.map((p) => {
|
|
1105
|
-
const [_, negation, pattern] = p.match(NEGATION_RE) || [];
|
|
1106
|
-
return (negation ? "" : "!") + (pattern.startsWith("*") ? pattern : relative(assetDir, resolve(nitro.options.rootDir, pattern)));
|
|
1107
|
-
})].filter((p) => !PARENT_DIR_GLOB_RE.test(p));
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
//#endregion
|
|
1111
|
-
//#region src/build/prepare.ts
|
|
1112
|
-
async function prepare(nitro) {
|
|
1113
|
-
await prepareDir(nitro.options.output.dir);
|
|
1114
|
-
if (!nitro.options.noPublicDir) await prepareDir(nitro.options.output.publicDir);
|
|
1115
|
-
if (!nitro.options.static) await prepareDir(nitro.options.output.serverDir);
|
|
1116
|
-
}
|
|
1117
|
-
async function prepareDir(dir) {
|
|
1118
|
-
await fsp.rm(dir, {
|
|
1119
|
-
recursive: true,
|
|
1120
|
-
force: true
|
|
1121
|
-
});
|
|
1122
|
-
await fsp.mkdir(dir, { recursive: true });
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
899
|
//#endregion
|
|
1126
900
|
//#region src/prerender/utils.ts
|
|
1127
901
|
const allowedExtensions = new Set(["", ".json"]);
|
|
@@ -1235,7 +1009,9 @@ async function prerender(nitro) {
|
|
|
1235
1009
|
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
1236
1010
|
const canPrerender = (route = "/") => {
|
|
1237
1011
|
if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
|
|
1238
|
-
|
|
1012
|
+
if (nitro.options.prerender.ignore) {
|
|
1013
|
+
for (const pattern of nitro.options.prerender.ignore) if (matchesIgnorePattern(route, pattern)) return false;
|
|
1014
|
+
}
|
|
1239
1015
|
if (publicAssetBases.some((base) => route.startsWith(base))) return false;
|
|
1240
1016
|
if (scannedPublicAssets.has(route)) return false;
|
|
1241
1017
|
if (_getRouteRules(route).prerender === false) return false;
|
|
@@ -1322,7 +1098,7 @@ async function prerender(nitro) {
|
|
|
1322
1098
|
nitro._prerenderedRoutes.push(_route);
|
|
1323
1099
|
} else _route.skip = true;
|
|
1324
1100
|
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
1325
|
-
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks);
|
|
1101
|
+
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks ?? false);
|
|
1326
1102
|
for (const _link of extractedLinks) if (canPrerender(_link)) routes.add(_link);
|
|
1327
1103
|
}
|
|
1328
1104
|
await nitro.hooks.callHook("prerender:route", _route);
|
|
@@ -1332,7 +1108,7 @@ async function prerender(nitro) {
|
|
|
1332
1108
|
};
|
|
1333
1109
|
nitro.logger.info(nitro.options.prerender.crawlLinks ? `Prerendering ${routes.size} initial routes with crawler` : `Prerendering ${routes.size} routes`);
|
|
1334
1110
|
await runParallel(routes, generateRoute, {
|
|
1335
|
-
concurrency: nitro.options.prerender.concurrency,
|
|
1111
|
+
concurrency: nitro.options.prerender.concurrency || 1,
|
|
1336
1112
|
interval: nitro.options.prerender.interval
|
|
1337
1113
|
});
|
|
1338
1114
|
await prerenderer.close();
|
|
@@ -1352,4 +1128,64 @@ async function prerender(nitro) {
|
|
|
1352
1128
|
}
|
|
1353
1129
|
|
|
1354
1130
|
//#endregion
|
|
1355
|
-
|
|
1131
|
+
//#region src/task.ts
|
|
1132
|
+
/** @experimental */
|
|
1133
|
+
async function runTask(taskEvent, opts) {
|
|
1134
|
+
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
1135
|
+
method: "POST",
|
|
1136
|
+
body: taskEvent
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
/** @experimental */
|
|
1140
|
+
async function listTasks(opts) {
|
|
1141
|
+
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
1142
|
+
}
|
|
1143
|
+
const _devHint = `(is dev server running?)`;
|
|
1144
|
+
async function _getTasksContext(opts) {
|
|
1145
|
+
const buildInfoPath = resolve(resolve(resolve(process.cwd(), opts?.cwd || "."), opts?.buildDir || "node_modules/.nitro"), "nitro.dev.json");
|
|
1146
|
+
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
1147
|
+
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
1148
|
+
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
1149
|
+
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
1150
|
+
const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`;
|
|
1151
|
+
const socketPath = buildInfo.dev.workerAddress.socketPath;
|
|
1152
|
+
const devFetch = (path, options) => {
|
|
1153
|
+
return new Promise((resolve$1, reject) => {
|
|
1154
|
+
let url = withBase(path, baseURL);
|
|
1155
|
+
if (options?.query) url = withQuery(url, options.query);
|
|
1156
|
+
const request = http.request(url, {
|
|
1157
|
+
socketPath,
|
|
1158
|
+
method: options?.method,
|
|
1159
|
+
headers: {
|
|
1160
|
+
Accept: "application/json",
|
|
1161
|
+
"Content-Type": "application/json"
|
|
1162
|
+
}
|
|
1163
|
+
}, (response) => {
|
|
1164
|
+
if (!response.statusCode || response.statusCode >= 400 && response.statusCode < 600) {
|
|
1165
|
+
reject(new Error(response.statusMessage));
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
let data = "";
|
|
1169
|
+
response.on("data", (chunk) => data += chunk).on("end", () => resolve$1(JSON.parse(data))).on("error", (e) => reject(e));
|
|
1170
|
+
});
|
|
1171
|
+
request.on("error", (e) => reject(e));
|
|
1172
|
+
if (options?.body) request.write(JSON.stringify(options.body));
|
|
1173
|
+
request.end();
|
|
1174
|
+
});
|
|
1175
|
+
};
|
|
1176
|
+
return {
|
|
1177
|
+
buildInfo,
|
|
1178
|
+
devFetch
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
function _pidIsRunning(pid) {
|
|
1182
|
+
try {
|
|
1183
|
+
process.kill(pid, 0);
|
|
1184
|
+
return true;
|
|
1185
|
+
} catch {
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
//#endregion
|
|
1191
|
+
export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
|