-
-
Notifications
You must be signed in to change notification settings - Fork 813
Expand file tree
/
Copy pathnitro.ts
More file actions
103 lines (95 loc) · 3.03 KB
/
nitro.ts
File metadata and controls
103 lines (95 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { ConsolaInstance } from "consola";
import type { HTTPMethod } from "h3";
import type { Hookable } from "hookable";
import type { PresetName, PresetOptions } from "../presets/index.ts";
import type { Unimport } from "unimport";
import type { NitroConfig, NitroOptions } from "./config.ts";
import type { NitroEventHandler } from "./handler.ts";
import type { NitroHooks } from "./hooks.ts";
import type { PrerenderRoute } from "./prerender.ts";
import type { TSConfig } from "pkg-types";
import type { Router } from "../routing.ts";
import type { NitroRouteRules } from "./route-rules.ts";
import type { WorkerAddress } from "./runner.ts";
type MaybeArray<T> = T | T[];
/** Nitro package metadata including version information. */
export interface NitroMeta {
version: string;
majorVersion: number;
}
/**
* The core Nitro instance available throughout the build lifecycle.
*
* Provides access to resolved options, hooks, the virtual file system,
* scanned handlers, and utility methods.
*
* @see https://nitro.build/docs/lifecycle
*/
export interface Nitro {
meta: NitroMeta;
options: NitroOptions;
scannedHandlers: NitroEventHandler[];
vfs: Map<string, { render: () => string | Promise<string> }>;
hooks: Hookable<NitroHooks>;
unimport?: Unimport;
logger: ConsolaInstance;
fetch: (input: Request) => Response | Promise<Response>;
close: () => Promise<void>;
updateConfig: (config: NitroDynamicConfig) => void | Promise<void>;
routing: Readonly<{
sync: () => void;
routeRules: Router<NitroRouteRules & { _route: string }>;
routes: Router<MaybeArray<NitroEventHandler & { _importHash: string }>>;
globalMiddleware: (NitroEventHandler & { _importHash: string })[];
routedMiddleware: Router<NitroEventHandler & { _importHash: string }>;
}>;
/* @internal */
_prerenderedRoutes?: PrerenderRoute[];
_prerenderMeta?: Record<string, { contentType?: string }>;
}
/**
* Subset of {@link NitroConfig} that can be updated at runtime via
* `nitro.updateConfig()`.
*/
export type NitroDynamicConfig = Pick<NitroConfig, "runtimeConfig" | "routeRules">;
export type NitroTypes = {
routes: Record<string, Partial<Record<HTTPMethod | "default", string[]>>>;
tsConfig?: TSConfig;
};
/**
* Metadata about the higher-level framework using Nitro (e.g. Nuxt).
*
* Used by presets and included in build info output.
*
* @see https://nitro.build/config#framework
*/
export interface NitroFrameworkInfo {
name?: "nitro" | (string & {});
version?: string;
}
/**
* Build info written to `.output/nitro.json` (production) or
* `node_modules/.nitro/nitro.dev.json` (development).
*
* Contains preset, framework, version, and command information.
*/
export interface NitroBuildInfo {
date: string;
preset: PresetName;
framework: NitroFrameworkInfo;
versions: {
nitro: string;
[key: string]: string;
};
commands?: {
preview?: string;
deploy?: string;
};
serverEntry?: string;
publicDir?: string;
dev?: {
pid: number;
workerAddress?: WorkerAddress;
};
config?: Partial<PresetOptions>;
}