nitro-nightly 4.0.0-20251010-091516-7cafddba → 4.0.0-20251030-091344-d4418b98
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/{_chunks/build2.mjs → _build/build.mjs} +108 -58
- package/dist/_build/build2.mjs +556 -0
- package/dist/_build/info.mjs +1002 -0
- package/dist/_build/prepare.mjs +1511 -0
- package/dist/_build/snapshot.mjs +185 -0
- package/dist/{_chunks/plugin.mjs → _build/vite.mjs} +295 -296
- package/dist/_build/vite2.mjs +149 -0
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +189 -0
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +137 -0
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +231 -0
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +170 -0
- package/dist/_chunks/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +89 -0
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +2376 -0
- package/dist/_chunks/{index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +37 -0
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +133 -0
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +346 -0
- package/dist/_chunks/_deps/acorn.mjs +6225 -0
- package/dist/_chunks/_deps/c12.mjs +510 -0
- package/dist/_chunks/_deps/chokidar.mjs +1428 -0
- package/dist/_chunks/_deps/citty.mjs +460 -0
- package/dist/_chunks/_deps/commondir.mjs +77 -0
- package/dist/_chunks/_deps/compatx.mjs +76 -0
- package/dist/_chunks/_deps/confbox.mjs +300 -0
- package/dist/_chunks/_deps/debug.mjs +885 -0
- package/dist/_chunks/_deps/deepmerge.mjs +147 -0
- package/dist/_chunks/_deps/depd.mjs +550 -0
- package/dist/_chunks/_deps/dot-prop.mjs +282 -0
- package/dist/_chunks/_deps/dotenv.mjs +555 -0
- package/dist/_chunks/_deps/duplexer.mjs +1 -0
- package/dist/_chunks/_deps/ee-first.mjs +104 -0
- package/dist/_chunks/_deps/encodeurl.mjs +69 -0
- package/dist/_chunks/_deps/escape-html.mjs +87 -0
- package/dist/_chunks/_deps/escape-string-regexp.mjs +13 -0
- package/dist/_chunks/_deps/estree-walker.mjs +433 -0
- package/dist/_chunks/_deps/etag.mjs +147 -0
- package/dist/_chunks/_deps/exsolve.mjs +1416 -0
- package/dist/_chunks/_deps/fdir.mjs +569 -0
- package/dist/_chunks/_deps/fresh.mjs +145 -0
- package/dist/_chunks/_deps/function-bind.mjs +106 -0
- package/dist/_chunks/{index4.mjs → _deps/giget.mjs} +21 -776
- package/dist/_chunks/_deps/gzip-size.mjs +19 -0
- package/dist/_chunks/_deps/hasown.mjs +19 -0
- package/dist/_chunks/_deps/http-errors.mjs +307 -0
- package/dist/_chunks/_deps/httpxy.mjs +580 -0
- package/dist/_chunks/_deps/inherits.mjs +57 -0
- package/dist/_chunks/_deps/is-core-module.mjs +596 -0
- package/dist/_chunks/_deps/is-module.mjs +25 -0
- package/dist/_chunks/_deps/is-reference.mjs +31 -0
- package/dist/_chunks/_deps/js-tokens.mjs +411 -0
- package/dist/_chunks/_deps/klona.mjs +137 -0
- package/dist/_chunks/_deps/knitwork.mjs +172 -0
- package/dist/_chunks/_deps/local-pkg.mjs +163 -0
- package/dist/_chunks/_deps/magic-string.mjs +1296 -0
- package/dist/_chunks/_deps/mime-db.mjs +11685 -0
- package/dist/_chunks/_deps/mime-types.mjs +287 -0
- package/dist/_chunks/_deps/mime.mjs +1172 -0
- package/dist/_chunks/_deps/mlly.mjs +2413 -0
- package/dist/_chunks/_deps/ms.mjs +172 -0
- package/dist/_chunks/_deps/node-fetch-native.mjs +3 -0
- package/dist/_chunks/_deps/nypm.mjs +219 -0
- package/dist/_chunks/_deps/on-finished.mjs +246 -0
- package/dist/_chunks/_deps/parseurl.mjs +168 -0
- package/dist/_chunks/_deps/path-parse.mjs +85 -0
- package/dist/_chunks/{pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
- package/dist/_chunks/_deps/perfect-debounce.mjs +88 -0
- package/dist/_chunks/_deps/picomatch.mjs +2144 -0
- package/dist/_chunks/_deps/pkg-types.mjs +247 -0
- package/dist/_chunks/{snapshot.mjs → _deps/pretty-bytes.mjs} +1 -105
- package/dist/_chunks/_deps/quansync.mjs +99 -0
- package/dist/_chunks/_deps/range-parser.mjs +171 -0
- package/dist/_chunks/_deps/rc9.mjs +219 -0
- package/dist/_chunks/_deps/readdirp.mjs +245 -0
- package/dist/_chunks/_deps/resolve.mjs +1260 -0
- package/dist/_chunks/_deps/rou3.mjs +326 -0
- package/dist/_chunks/_deps/send.mjs +1022 -0
- package/dist/_chunks/_deps/serve-static.mjs +228 -0
- package/dist/_chunks/_deps/setprototypeof.mjs +26 -0
- package/dist/_chunks/_deps/statuses.mjs +457 -0
- package/dist/_chunks/_deps/std-env.mjs +3 -0
- package/dist/_chunks/_deps/strip-literal.mjs +67 -0
- package/dist/_chunks/_deps/supports-color.mjs +44 -0
- package/dist/_chunks/_deps/tinyexec.mjs +552 -0
- package/dist/_chunks/_deps/tinyglobby.mjs +293 -0
- package/dist/_chunks/_deps/toidentifier.mjs +41 -0
- package/dist/_chunks/_deps/ultrahtml.mjs +3 -0
- package/dist/_chunks/_deps/unimport.mjs +2267 -0
- package/dist/_chunks/_deps/unplugin-utils.mjs +65 -0
- package/dist/_chunks/_deps/unplugin.mjs +1294 -0
- package/dist/_chunks/_deps/untyped.mjs +375 -0
- package/dist/_chunks/{info.mjs → _deps/unwasm.mjs} +8 -4206
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +360 -0
- package/dist/_chunks/_presets/_all.mjs +59 -0
- package/dist/_chunks/_presets/_nitro.mjs +74 -0
- package/dist/_chunks/_presets/_resolve.mjs +64 -0
- package/dist/_chunks/_presets/_static.mjs +69 -0
- package/dist/_chunks/_presets/_types.mjs +3 -0
- package/dist/_chunks/_presets/_utils.mjs +31 -0
- package/dist/_chunks/_presets/alwaysdata.mjs +17 -0
- package/dist/_chunks/_presets/aws-amplify.mjs +111 -0
- package/dist/_chunks/_presets/aws-lambda.mjs +23 -0
- package/dist/_chunks/_presets/azure.mjs +162 -0
- package/dist/_chunks/_presets/bun.mjs +19 -0
- package/dist/_chunks/_presets/cleavr.mjs +15 -0
- package/dist/_chunks/_presets/cloudflare.mjs +608 -0
- package/dist/_chunks/_presets/deno.mjs +196 -0
- package/dist/_chunks/_presets/digitalocean.mjs +14 -0
- package/dist/_chunks/_presets/firebase.mjs +47 -0
- package/dist/_chunks/_presets/flightcontrol.mjs +14 -0
- package/dist/_chunks/_presets/genezio.mjs +13 -0
- package/dist/_chunks/_presets/heroku.mjs +14 -0
- package/dist/_chunks/_presets/iis.mjs +194 -0
- package/dist/_chunks/_presets/index.mjs +62 -0
- package/dist/_chunks/_presets/koyeb.mjs +14 -0
- package/dist/_chunks/_presets/netlify.mjs +241 -0
- package/dist/_chunks/_presets/node.mjs +54 -0
- package/dist/_chunks/_presets/platform.mjs +14 -0
- package/dist/_chunks/_presets/render.mjs +14 -0
- package/dist/_chunks/_presets/standard.mjs +23 -0
- package/dist/_chunks/_presets/stormkit.mjs +18 -0
- package/dist/_chunks/_presets/vercel.mjs +375 -0
- package/dist/_chunks/_presets/winterjs.mjs +22 -0
- package/dist/_chunks/_presets/zeabur.mjs +69 -0
- package/dist/_chunks/_presets/zerops.mjs +27 -0
- package/dist/_chunks/app.mjs +9 -19206
- package/dist/_chunks/{index3.mjs → builder.mjs} +560 -970
- package/dist/_chunks/server.mjs +6 -4
- package/dist/{cli → _cli}/build.mjs +3 -8
- package/dist/{cli → _cli}/dev.mjs +38 -12
- package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
- package/dist/{cli → _cli}/list.mjs +3 -4
- package/dist/{cli → _cli}/prepare.mjs +3 -4
- package/dist/{cli → _cli}/run.mjs +3 -4
- package/dist/{index.d.mts → builder.d.mts} +11 -11
- package/dist/builder.mjs +117 -0
- package/dist/cli/index.mjs +7 -464
- 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 +7 -3
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/hookable/dist/index.mjs +243 -266
- package/dist/node_modules/hookable/package.json +29 -26
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +4 -7
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +5 -4
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +7 -6
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -5
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +7 -10
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +21 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/node/runtime/node-server.mjs +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +3 -1
- package/dist/runtime/internal/app.mjs +90 -64
- package/dist/runtime/internal/error/prod.d.mts +3 -2
- package/dist/runtime/internal/error/prod.mjs +9 -13
- package/dist/runtime/internal/renderer.mjs +4 -4
- package/dist/runtime/internal/routes/dev-tasks.d.mts +30 -2
- package/dist/runtime/internal/shutdown.d.mts +1 -2
- package/dist/runtime/internal/shutdown.mjs +3 -2
- package/dist/runtime/internal/task.mjs +1 -2
- package/dist/types/index.d.mts +1603 -10
- package/dist/vite.d.mts +5 -0
- package/dist/vite.mjs +94 -30
- package/lib/index.mjs +1 -0
- package/lib/indexd.mts +1 -0
- package/lib/runtime/meta.mjs +35 -0
- package/package.json +40 -41
- package/dist/_chunks/build.mjs +0 -84
- package/dist/_chunks/build3.mjs +0 -6452
- package/dist/_chunks/detect-acorn.mjs +0 -503
- package/dist/_chunks/index.mjs +0 -22242
- package/dist/_chunks/json5.mjs +0 -68
- package/dist/_chunks/jsonc.mjs +0 -51
- package/dist/_chunks/toml.mjs +0 -259
- package/dist/_chunks/yaml.mjs +0 -86
- package/dist/index.mjs +0 -55
- package/dist/node_modules/klona/dist/index.mjs +0 -81
- package/dist/node_modules/klona/full/index.mjs +0 -53
- package/dist/node_modules/klona/package.json +0 -74
- package/dist/node_modules/std-env/dist/index.mjs +0 -1
- package/dist/node_modules/std-env/package.json +0 -46
- package/dist/presets.mjs +0 -2460
- package/dist/runtime/internal/debug.d.mts +0 -2
- package/dist/runtime/internal/debug.mjs +0 -5
- package/lib/runtime-meta.mjs +0 -38
- /package/dist/{cli → _cli}/common.mjs +0 -0
- /package/lib/{runtime-meta.d.mts → runtime/meta.d.mts} +0 -0
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { w as writeFile, d as defineNitroPreset } from './_utils.mjs';
|
|
2
|
+
import { presetsDir } from 'nitro/runtime/meta';
|
|
3
|
+
import { existsSync, promises } from 'node:fs';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { relative, dirname, extname, resolve as resolve$1 } from 'node:path';
|
|
6
|
+
import { c as findNearestFile, d as readGitConfig, r as readPackageJSON, e as findFile } from '../_deps/pkg-types.mjs';
|
|
7
|
+
import { defu } from 'defu';
|
|
8
|
+
import { p } from '../_deps/std-env.mjs';
|
|
9
|
+
import { g as glob } from '../_deps/tinyglobby.mjs';
|
|
10
|
+
import { withoutLeadingSlash, withTrailingSlash, joinURL, withLeadingSlash, hasProtocol } from 'ufo';
|
|
11
|
+
import { j as join, r as resolve } from '../_deps/pathe.mjs';
|
|
12
|
+
import { Q, b as h } from '../_deps/confbox.mjs';
|
|
13
|
+
import { h as fileURLToPath } from '../_deps/mlly.mjs';
|
|
14
|
+
import { r as resolveModulePath } from '../_deps/exsolve.mjs';
|
|
15
|
+
|
|
16
|
+
const builtnNodeModules = [
|
|
17
|
+
"node:_http_agent",
|
|
18
|
+
"node:_http_client",
|
|
19
|
+
"node:_http_common",
|
|
20
|
+
// Missing exports: CRLF, HTTPParser, freeParser, isLenient, parsers, prepareError
|
|
21
|
+
"node:_http_incoming",
|
|
22
|
+
// Missing exports: readStart, readStop
|
|
23
|
+
"node:_http_outgoing",
|
|
24
|
+
"node:_http_server",
|
|
25
|
+
"node:_stream_duplex",
|
|
26
|
+
"node:_stream_passthrough",
|
|
27
|
+
"node:_stream_readable",
|
|
28
|
+
"node:_stream_transform",
|
|
29
|
+
"node:_stream_writable",
|
|
30
|
+
"node:_tls_common",
|
|
31
|
+
"node:_tls_wrap",
|
|
32
|
+
// Missing exports: Server, createServer
|
|
33
|
+
"node:assert",
|
|
34
|
+
// Missing exports: Assert, CallTracker
|
|
35
|
+
"node:assert/strict",
|
|
36
|
+
// Missing exports: Assert, CallTracker
|
|
37
|
+
"node:async_hooks",
|
|
38
|
+
"node:buffer",
|
|
39
|
+
"node:constants",
|
|
40
|
+
// Missing exports: O_DIRECT, O_NOATIME, RTLD_DEEPBIND, SIGPOLL, SIGPWR, SIGSTKFLT, defaultCipherList
|
|
41
|
+
"node:crypto",
|
|
42
|
+
// Missing exports: argon2, argon2Sync, decapsulate, encapsulate
|
|
43
|
+
"node:diagnostics_channel",
|
|
44
|
+
"node:dns",
|
|
45
|
+
// Missing exports: resolveTlsa
|
|
46
|
+
"node:dns/promises",
|
|
47
|
+
// Missing exports: resolveTlsa
|
|
48
|
+
"node:events",
|
|
49
|
+
// Missing exports: captureRejections, init
|
|
50
|
+
"node:fs",
|
|
51
|
+
// Missing exports: Utf8Stream, mkdtempDisposableSync
|
|
52
|
+
"node:fs/promises",
|
|
53
|
+
// Missing exports: mkdtempDisposable
|
|
54
|
+
"node:http",
|
|
55
|
+
"node:http2",
|
|
56
|
+
"node:https",
|
|
57
|
+
"node:module",
|
|
58
|
+
"node:net",
|
|
59
|
+
"node:os",
|
|
60
|
+
"node:path",
|
|
61
|
+
"node:path/posix",
|
|
62
|
+
"node:path/win32",
|
|
63
|
+
"node:process",
|
|
64
|
+
"node:querystring",
|
|
65
|
+
"node:stream",
|
|
66
|
+
"node:stream/consumers",
|
|
67
|
+
"node:stream/promises",
|
|
68
|
+
"node:stream/web",
|
|
69
|
+
"node:string_decoder",
|
|
70
|
+
"node:test",
|
|
71
|
+
// Missing exports: after, afterEach, assert, before, beforeEach, describe, it, only, run, skip, snapshot, suite, test, todo
|
|
72
|
+
"node:timers",
|
|
73
|
+
"node:timers/promises",
|
|
74
|
+
"node:tls",
|
|
75
|
+
// Missing exports: getCACertificates, setDefaultCACertificates
|
|
76
|
+
"node:url",
|
|
77
|
+
// Missing exports: URLPattern, fileURLToPathBuffer
|
|
78
|
+
"node:util",
|
|
79
|
+
// Missing exports: diff, setTraceSigInt
|
|
80
|
+
"node:util/types",
|
|
81
|
+
"node:zlib"
|
|
82
|
+
// Missing exports: ZstdCompress, ZstdDecompress, createZstdCompress, createZstdDecompress, zstdCompress, zstdCompressSync, zstdDecompress, zstdDecompressSync
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const unencCfNodeCompat = {
|
|
86
|
+
meta: {
|
|
87
|
+
name: "nitro:cloudflare-node-compat"
|
|
88
|
+
},
|
|
89
|
+
external: builtnNodeModules,
|
|
90
|
+
alias: {
|
|
91
|
+
...Object.fromEntries(
|
|
92
|
+
builtnNodeModules.flatMap((m) => [
|
|
93
|
+
[m, m],
|
|
94
|
+
[m.replace("node:", ""), m]
|
|
95
|
+
])
|
|
96
|
+
)
|
|
97
|
+
},
|
|
98
|
+
inject: {
|
|
99
|
+
global: "unenv/polyfill/globalthis",
|
|
100
|
+
process: "node:process",
|
|
101
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
102
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
103
|
+
Buffer: ["node:buffer", "Buffer"]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const unenvCfExternals = {
|
|
107
|
+
meta: {
|
|
108
|
+
name: "nitro:cloudflare-externals"
|
|
109
|
+
},
|
|
110
|
+
external: [
|
|
111
|
+
"cloudflare:email",
|
|
112
|
+
"cloudflare:sockets",
|
|
113
|
+
"cloudflare:workers",
|
|
114
|
+
"cloudflare:workflows"
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
async function writeCFRoutes(nitro) {
|
|
119
|
+
const _cfPagesConfig = nitro.options.cloudflare?.pages || {};
|
|
120
|
+
const routes = {
|
|
121
|
+
version: _cfPagesConfig.routes?.version || 1,
|
|
122
|
+
include: _cfPagesConfig.routes?.include || ["/*"],
|
|
123
|
+
exclude: _cfPagesConfig.routes?.exclude || []
|
|
124
|
+
};
|
|
125
|
+
const writeRoutes = () => writeFile(
|
|
126
|
+
resolve(nitro.options.output.dir, "_routes.json"),
|
|
127
|
+
JSON.stringify(routes, void 0, 2),
|
|
128
|
+
true
|
|
129
|
+
);
|
|
130
|
+
if (_cfPagesConfig.defaultRoutes === false) {
|
|
131
|
+
await writeRoutes();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const explicitPublicAssets = nitro.options.publicAssets.filter(
|
|
135
|
+
(dir, index, array) => {
|
|
136
|
+
if (dir.fallthrough || !dir.baseURL) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const normalizedBase = withoutLeadingSlash(dir.baseURL);
|
|
140
|
+
return !array.some(
|
|
141
|
+
(otherDir, otherIndex) => otherIndex !== index && normalizedBase.startsWith(
|
|
142
|
+
withoutLeadingSlash(withTrailingSlash(otherDir.baseURL))
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
routes.exclude.push(
|
|
148
|
+
...explicitPublicAssets.map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/", "*")).sort(comparePaths)
|
|
149
|
+
);
|
|
150
|
+
const publicAssetFiles = await glob("**", {
|
|
151
|
+
cwd: nitro.options.output.dir,
|
|
152
|
+
absolute: false,
|
|
153
|
+
dot: true,
|
|
154
|
+
ignore: [
|
|
155
|
+
"_worker.js",
|
|
156
|
+
"_worker.js.map",
|
|
157
|
+
"nitro.json",
|
|
158
|
+
...routes.exclude.map(
|
|
159
|
+
(path) => withoutLeadingSlash(path.replace(/\/\*$/, "/**"))
|
|
160
|
+
)
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
routes.exclude.push(
|
|
164
|
+
...publicAssetFiles.map(
|
|
165
|
+
(i) => withLeadingSlash(i).replace(/\/index\.html$/, "").replace(/\.html$/, "") || "/"
|
|
166
|
+
).sort(comparePaths)
|
|
167
|
+
);
|
|
168
|
+
routes.exclude.splice(100 - routes.include.length);
|
|
169
|
+
await writeRoutes();
|
|
170
|
+
}
|
|
171
|
+
function comparePaths(a, b) {
|
|
172
|
+
return a.split("/").length - b.split("/").length || a.localeCompare(b);
|
|
173
|
+
}
|
|
174
|
+
async function writeCFHeaders(nitro, outdir) {
|
|
175
|
+
const headersPath = join(
|
|
176
|
+
outdir === "public" ? nitro.options.output.publicDir : nitro.options.output.dir,
|
|
177
|
+
"_headers"
|
|
178
|
+
);
|
|
179
|
+
const contents = [];
|
|
180
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
181
|
+
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
|
|
182
|
+
);
|
|
183
|
+
for (const [path, routeRules] of rules.filter(
|
|
184
|
+
([_, routeRules2]) => routeRules2.headers
|
|
185
|
+
)) {
|
|
186
|
+
const headers = [
|
|
187
|
+
joinURL(nitro.options.baseURL, path.replace("/**", "/*")),
|
|
188
|
+
...Object.entries({ ...routeRules.headers }).map(
|
|
189
|
+
([header, value]) => ` ${header}: ${value}`
|
|
190
|
+
)
|
|
191
|
+
].join("\n");
|
|
192
|
+
contents.push(headers);
|
|
193
|
+
}
|
|
194
|
+
if (existsSync(headersPath)) {
|
|
195
|
+
const currentHeaders = await readFile(headersPath, "utf8");
|
|
196
|
+
if (/^\/\* /m.test(currentHeaders)) {
|
|
197
|
+
nitro.logger.info(
|
|
198
|
+
"Not adding Nitro fallback to `_headers` (as an existing fallback was found)."
|
|
199
|
+
);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
nitro.logger.info(
|
|
203
|
+
"Adding Nitro fallback to `_headers` to handle all unmatched routes."
|
|
204
|
+
);
|
|
205
|
+
contents.unshift(currentHeaders);
|
|
206
|
+
}
|
|
207
|
+
await writeFile(headersPath, contents.join("\n"), true);
|
|
208
|
+
}
|
|
209
|
+
async function writeCFPagesRedirects(nitro) {
|
|
210
|
+
const redirectsPath = join(nitro.options.output.dir, "_redirects");
|
|
211
|
+
const staticFallback = existsSync(
|
|
212
|
+
join(nitro.options.output.publicDir, "404.html")
|
|
213
|
+
) ? `${joinURL(nitro.options.baseURL, "/*")} ${joinURL(nitro.options.baseURL, "/404.html")} 404` : "";
|
|
214
|
+
const contents = [staticFallback];
|
|
215
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
216
|
+
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
|
|
217
|
+
);
|
|
218
|
+
for (const [key, routeRules] of rules.filter(
|
|
219
|
+
([_, routeRules2]) => routeRules2.redirect
|
|
220
|
+
)) {
|
|
221
|
+
const code = routeRules.redirect.status;
|
|
222
|
+
const from = joinURL(nitro.options.baseURL, key.replace("/**", "/*"));
|
|
223
|
+
const to = hasProtocol(routeRules.redirect.to, { acceptRelative: true }) ? routeRules.redirect.to : joinURL(nitro.options.baseURL, routeRules.redirect.to);
|
|
224
|
+
contents.unshift(`${from} ${to} ${code}`);
|
|
225
|
+
}
|
|
226
|
+
if (existsSync(redirectsPath)) {
|
|
227
|
+
const currentRedirects = await readFile(redirectsPath, "utf8");
|
|
228
|
+
if (/^\/\* /m.test(currentRedirects)) {
|
|
229
|
+
nitro.logger.info(
|
|
230
|
+
"Not adding Nitro fallback to `_redirects` (as an existing fallback was found)."
|
|
231
|
+
);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
nitro.logger.info(
|
|
235
|
+
"Adding Nitro fallback to `_redirects` to handle all unmatched routes."
|
|
236
|
+
);
|
|
237
|
+
contents.unshift(currentRedirects);
|
|
238
|
+
}
|
|
239
|
+
await writeFile(redirectsPath, contents.join("\n"), true);
|
|
240
|
+
}
|
|
241
|
+
async function enableNodeCompat(nitro) {
|
|
242
|
+
nitro.options.cloudflare ??= {};
|
|
243
|
+
if (nitro.options.cloudflare.deployConfig === void 0 && p === "cloudflare_workers") {
|
|
244
|
+
nitro.options.cloudflare.deployConfig = true;
|
|
245
|
+
}
|
|
246
|
+
if (nitro.options.cloudflare.nodeCompat === void 0) {
|
|
247
|
+
const { config } = await readWranglerConfig(nitro);
|
|
248
|
+
const userCompatibilityFlags = new Set(config?.compatibility_flags || []);
|
|
249
|
+
if (userCompatibilityFlags.has("nodejs_compat") || userCompatibilityFlags.has("nodejs_compat_v2") || nitro.options.cloudflare.deployConfig) {
|
|
250
|
+
nitro.options.cloudflare.nodeCompat = true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!nitro.options.cloudflare.nodeCompat) {
|
|
254
|
+
if (nitro.options.cloudflare.nodeCompat === void 0) {
|
|
255
|
+
nitro.logger.warn("[cloudflare] Node.js compatibility is not enabled.");
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
nitro.options.unenv.push(unencCfNodeCompat);
|
|
260
|
+
}
|
|
261
|
+
const extensionParsers = {
|
|
262
|
+
".json": h,
|
|
263
|
+
".jsonc": h,
|
|
264
|
+
".toml": Q
|
|
265
|
+
};
|
|
266
|
+
async function readWranglerConfig(nitro) {
|
|
267
|
+
const configPath = await findNearestFile(
|
|
268
|
+
["wrangler.json", "wrangler.jsonc", "wrangler.toml"],
|
|
269
|
+
{
|
|
270
|
+
startingFrom: nitro.options.rootDir
|
|
271
|
+
}
|
|
272
|
+
).catch(() => void 0);
|
|
273
|
+
if (!configPath) {
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
const userConfigText = await readFile(configPath, "utf8");
|
|
277
|
+
const parser = extensionParsers[extname(configPath)];
|
|
278
|
+
if (!parser) {
|
|
279
|
+
throw new Error(`Unsupported config file format: ${configPath}`);
|
|
280
|
+
}
|
|
281
|
+
const config = parser(userConfigText);
|
|
282
|
+
return { configPath, config };
|
|
283
|
+
}
|
|
284
|
+
async function writeWranglerConfig(nitro, cfTarget) {
|
|
285
|
+
if (!nitro.options.cloudflare?.deployConfig) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const wranglerConfigDir = nitro.options.output.serverDir;
|
|
289
|
+
const wranglerConfigPath = join(wranglerConfigDir, "wrangler.json");
|
|
290
|
+
const defaults = {};
|
|
291
|
+
const overrides = {};
|
|
292
|
+
defaults.compatibility_date = nitro.options.compatibilityDate.cloudflare || nitro.options.compatibilityDate.default;
|
|
293
|
+
if (cfTarget === "pages") {
|
|
294
|
+
overrides.pages_build_output_dir = relative(
|
|
295
|
+
wranglerConfigDir,
|
|
296
|
+
nitro.options.output.dir
|
|
297
|
+
);
|
|
298
|
+
} else {
|
|
299
|
+
overrides.main = relative(
|
|
300
|
+
wranglerConfigDir,
|
|
301
|
+
join(nitro.options.output.serverDir, "index.mjs")
|
|
302
|
+
);
|
|
303
|
+
overrides.assets = {
|
|
304
|
+
binding: "ASSETS",
|
|
305
|
+
directory: relative(
|
|
306
|
+
wranglerConfigDir,
|
|
307
|
+
resolve(
|
|
308
|
+
nitro.options.output.publicDir,
|
|
309
|
+
"..".repeat(nitro.options.baseURL.split("/").filter(Boolean).length)
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const { config: userConfig = {} } = await readWranglerConfig(nitro);
|
|
315
|
+
const ctxConfig = nitro.options.cloudflare?.wrangler || {};
|
|
316
|
+
for (const key in overrides) {
|
|
317
|
+
if (key in userConfig || key in ctxConfig) {
|
|
318
|
+
nitro.logger.warn(
|
|
319
|
+
`[cloudflare] Wrangler config \`${key}\`${key in ctxConfig ? "set by config or modules" : ""} is overridden and will be ignored.`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const wranglerConfig = defu(
|
|
324
|
+
overrides,
|
|
325
|
+
ctxConfig,
|
|
326
|
+
userConfig,
|
|
327
|
+
defaults
|
|
328
|
+
);
|
|
329
|
+
if (!wranglerConfig.name) {
|
|
330
|
+
wranglerConfig.name = await generateWorkerName(nitro);
|
|
331
|
+
nitro.logger.info(
|
|
332
|
+
`Using auto generated worker name: \`${wranglerConfig.name}\``
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const compatFlags = new Set(wranglerConfig.compatibility_flags || []);
|
|
336
|
+
if (nitro.options.cloudflare?.nodeCompat) {
|
|
337
|
+
if (compatFlags.has("nodejs_compat_v2") && compatFlags.has("no_nodejs_compat_v2")) {
|
|
338
|
+
nitro.logger.warn(
|
|
339
|
+
"[cloudflare] Wrangler config `compatibility_flags` contains both `nodejs_compat_v2` and `no_nodejs_compat_v2`. Ignoring `nodejs_compat_v2`."
|
|
340
|
+
);
|
|
341
|
+
compatFlags.delete("nodejs_compat_v2");
|
|
342
|
+
}
|
|
343
|
+
if (compatFlags.has("nodejs_compat_v2")) {
|
|
344
|
+
nitro.logger.warn(
|
|
345
|
+
"[cloudflare] Please consider replacing `nodejs_compat_v2` with `nodejs_compat` in your `compatibility_flags` or USE IT AT YOUR OWN RISK as it can cause issues with nitro."
|
|
346
|
+
);
|
|
347
|
+
} else {
|
|
348
|
+
compatFlags.add("nodejs_compat");
|
|
349
|
+
compatFlags.add("no_nodejs_compat_v2");
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
wranglerConfig.compatibility_flags = [...compatFlags];
|
|
353
|
+
await writeFile(
|
|
354
|
+
wranglerConfigPath,
|
|
355
|
+
JSON.stringify(wranglerConfig, null, 2),
|
|
356
|
+
true
|
|
357
|
+
);
|
|
358
|
+
const configPath = join(
|
|
359
|
+
nitro.options.rootDir,
|
|
360
|
+
".wrangler/deploy/config.json"
|
|
361
|
+
);
|
|
362
|
+
await writeFile(
|
|
363
|
+
configPath,
|
|
364
|
+
JSON.stringify({
|
|
365
|
+
configPath: relative(dirname(configPath), wranglerConfigPath)
|
|
366
|
+
}),
|
|
367
|
+
true
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
async function generateWorkerName(nitro) {
|
|
371
|
+
const gitConfig = await readGitConfig(nitro.options.rootDir).catch(
|
|
372
|
+
() => void 0
|
|
373
|
+
);
|
|
374
|
+
const gitRepo = gitConfig?.remote?.origin?.url?.replace(/\.git$/, "").match(/[/:]([^/]+\/[^/]+)$/)?.[1];
|
|
375
|
+
const pkgJSON = await readPackageJSON(nitro.options.rootDir).catch(
|
|
376
|
+
() => void 0
|
|
377
|
+
);
|
|
378
|
+
const pkgName = pkgJSON?.name;
|
|
379
|
+
const subpath = relative(nitro.options.workspaceDir, nitro.options.rootDir);
|
|
380
|
+
return `${gitRepo || pkgName}/${subpath}`.toLowerCase().replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async function cloudflareDevModule(nitro) {
|
|
384
|
+
if (!nitro.options.dev) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const wranglerPath = await resolveModulePath("wrangler", {
|
|
388
|
+
from: nitro.options.nodeModulesDirs,
|
|
389
|
+
try: true
|
|
390
|
+
});
|
|
391
|
+
if (!wranglerPath) {
|
|
392
|
+
nitro.logger.warn(
|
|
393
|
+
"Wrangler is not installed. Please install it using `npx nypm i wrangler` to enable dev emulation."
|
|
394
|
+
);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const config = {
|
|
398
|
+
// compatibility with legacy nitro-cloudflare-dev module
|
|
399
|
+
...nitro.options.cloudflareDev,
|
|
400
|
+
...nitro.options.cloudflare?.dev
|
|
401
|
+
};
|
|
402
|
+
let configPath = config.configPath;
|
|
403
|
+
if (!configPath) {
|
|
404
|
+
configPath = await findFile(
|
|
405
|
+
["wrangler.json", "wrangler.jsonc", "wrangler.toml"],
|
|
406
|
+
{
|
|
407
|
+
startingFrom: nitro.options.srcDir
|
|
408
|
+
}
|
|
409
|
+
).catch(() => void 0);
|
|
410
|
+
}
|
|
411
|
+
const persistDir = resolve$1(
|
|
412
|
+
nitro.options.rootDir,
|
|
413
|
+
config.persistDir || ".wrangler/state/v3"
|
|
414
|
+
);
|
|
415
|
+
const gitIgnorePath = await findFile(".gitignore", {
|
|
416
|
+
startingFrom: nitro.options.rootDir
|
|
417
|
+
}).catch(() => void 0);
|
|
418
|
+
if (gitIgnorePath && persistDir === ".wrangler/state/v3") {
|
|
419
|
+
const gitIgnore = await promises.readFile(gitIgnorePath, "utf8");
|
|
420
|
+
if (!gitIgnore.includes(".wrangler/state/v3")) {
|
|
421
|
+
await promises.writeFile(gitIgnorePath, gitIgnore + "\n.wrangler/state/v3\n").catch(() => {
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
nitro.options.runtimeConfig.wrangler = {
|
|
426
|
+
...nitro.options.runtimeConfig.wrangler,
|
|
427
|
+
configPath,
|
|
428
|
+
persistDir,
|
|
429
|
+
environment: config.environment
|
|
430
|
+
};
|
|
431
|
+
nitro.options.externals.inline = nitro.options.externals.inline || [];
|
|
432
|
+
nitro.options.externals.inline.push(
|
|
433
|
+
fileURLToPath(new URL("runtime/", import.meta.url))
|
|
434
|
+
);
|
|
435
|
+
nitro.options.plugins = nitro.options.plugins || [];
|
|
436
|
+
nitro.options.plugins.unshift(
|
|
437
|
+
resolveModulePath("./cloudflare/runtime/plugin.dev", {
|
|
438
|
+
from: presetsDir,
|
|
439
|
+
extensions: [".mjs", ".ts"]
|
|
440
|
+
})
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const cloudflarePages = defineNitroPreset(
|
|
445
|
+
{
|
|
446
|
+
extends: "base-worker",
|
|
447
|
+
entry: "./cloudflare/runtime/cloudflare-pages",
|
|
448
|
+
exportConditions: ["workerd"],
|
|
449
|
+
commands: {
|
|
450
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
451
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
452
|
+
},
|
|
453
|
+
output: {
|
|
454
|
+
dir: "{{ rootDir }}/dist",
|
|
455
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}",
|
|
456
|
+
serverDir: "{{ output.dir }}/_worker.js"
|
|
457
|
+
},
|
|
458
|
+
unenv: [unenvCfExternals],
|
|
459
|
+
alias: {
|
|
460
|
+
// Hotfix: Cloudflare appends /index.html if mime is not found and things like ico are not in standard lite.js!
|
|
461
|
+
// https://github.com/nitrojs/nitro/pull/933
|
|
462
|
+
_mime: "mime/index.js"
|
|
463
|
+
},
|
|
464
|
+
wasm: {
|
|
465
|
+
lazy: false,
|
|
466
|
+
esmImport: true
|
|
467
|
+
},
|
|
468
|
+
rollupConfig: {
|
|
469
|
+
output: {
|
|
470
|
+
entryFileNames: "index.js",
|
|
471
|
+
format: "esm",
|
|
472
|
+
inlineDynamicImports: false
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
hooks: {
|
|
476
|
+
"build:before": async (nitro) => {
|
|
477
|
+
await enableNodeCompat(nitro);
|
|
478
|
+
},
|
|
479
|
+
async compiled(nitro) {
|
|
480
|
+
await writeWranglerConfig(nitro, "pages");
|
|
481
|
+
await writeCFRoutes(nitro);
|
|
482
|
+
await writeCFHeaders(nitro, "output");
|
|
483
|
+
await writeCFPagesRedirects(nitro);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
name: "cloudflare-pages",
|
|
489
|
+
stdName: "cloudflare_pages"
|
|
490
|
+
}
|
|
491
|
+
);
|
|
492
|
+
const cloudflarePagesStatic = defineNitroPreset(
|
|
493
|
+
{
|
|
494
|
+
extends: "static",
|
|
495
|
+
output: {
|
|
496
|
+
dir: "{{ rootDir }}/dist",
|
|
497
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}"
|
|
498
|
+
},
|
|
499
|
+
commands: {
|
|
500
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
501
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
502
|
+
},
|
|
503
|
+
hooks: {
|
|
504
|
+
async compiled(nitro) {
|
|
505
|
+
await writeCFHeaders(nitro, "output");
|
|
506
|
+
await writeCFPagesRedirects(nitro);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: "cloudflare-pages-static",
|
|
512
|
+
stdName: "cloudflare_pages",
|
|
513
|
+
static: true
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
const cloudflareDev = defineNitroPreset(
|
|
517
|
+
{
|
|
518
|
+
extends: "nitro-dev",
|
|
519
|
+
modules: [cloudflareDevModule],
|
|
520
|
+
esbuild: {
|
|
521
|
+
options: {
|
|
522
|
+
target: "es2022"
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
unenv: {
|
|
526
|
+
meta: {
|
|
527
|
+
name: "cloudflare-dev"
|
|
528
|
+
},
|
|
529
|
+
alias: {
|
|
530
|
+
"cloudflare:workers": resolve(
|
|
531
|
+
presetsDir,
|
|
532
|
+
"cloudflare/runtime/shims/workers.dev.mjs"
|
|
533
|
+
)
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "cloudflare-dev",
|
|
539
|
+
aliases: ["cloudflare-module", "cloudflare-durable", "cloudflare-pages"],
|
|
540
|
+
compatibilityDate: "2025-07-13",
|
|
541
|
+
dev: true
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
const cloudflareModule = defineNitroPreset(
|
|
545
|
+
{
|
|
546
|
+
extends: "base-worker",
|
|
547
|
+
entry: "./cloudflare/runtime/cloudflare-module",
|
|
548
|
+
output: {
|
|
549
|
+
publicDir: "{{ output.dir }}/public/{{ baseURL }}"
|
|
550
|
+
},
|
|
551
|
+
exportConditions: ["workerd"],
|
|
552
|
+
commands: {
|
|
553
|
+
preview: "npx wrangler --cwd ./ dev",
|
|
554
|
+
deploy: "npx wrangler --cwd ./ deploy"
|
|
555
|
+
},
|
|
556
|
+
unenv: [unenvCfExternals],
|
|
557
|
+
rollupConfig: {
|
|
558
|
+
output: {
|
|
559
|
+
format: "esm",
|
|
560
|
+
exports: "named",
|
|
561
|
+
inlineDynamicImports: false
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
wasm: {
|
|
565
|
+
lazy: false,
|
|
566
|
+
esmImport: true
|
|
567
|
+
},
|
|
568
|
+
hooks: {
|
|
569
|
+
"build:before": async (nitro) => {
|
|
570
|
+
await enableNodeCompat(nitro);
|
|
571
|
+
},
|
|
572
|
+
async compiled(nitro) {
|
|
573
|
+
await writeWranglerConfig(nitro, "module");
|
|
574
|
+
await writeCFHeaders(nitro, "public");
|
|
575
|
+
await writeFile(
|
|
576
|
+
resolve(nitro.options.output.dir, "package.json"),
|
|
577
|
+
JSON.stringify({ private: true, main: "./server/index.mjs" }, null, 2)
|
|
578
|
+
);
|
|
579
|
+
await writeFile(
|
|
580
|
+
resolve(nitro.options.output.dir, "package-lock.json"),
|
|
581
|
+
JSON.stringify({ lockfileVersion: 1 }, null, 2)
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
name: "cloudflare-module",
|
|
588
|
+
stdName: "cloudflare_workers"
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
const cloudflareDurable = defineNitroPreset(
|
|
592
|
+
{
|
|
593
|
+
extends: "cloudflare-module",
|
|
594
|
+
entry: "./cloudflare/runtime/cloudflare-durable"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: "cloudflare-durable"
|
|
598
|
+
}
|
|
599
|
+
);
|
|
600
|
+
const _cloudflare = [
|
|
601
|
+
cloudflarePages,
|
|
602
|
+
cloudflarePagesStatic,
|
|
603
|
+
cloudflareModule,
|
|
604
|
+
cloudflareDurable,
|
|
605
|
+
cloudflareDev
|
|
606
|
+
];
|
|
607
|
+
|
|
608
|
+
export { _cloudflare as _ };
|