nitro 3.0.260429-beta → 3.0.260522-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_build/common.mjs +119 -21
- package/dist/_build/rolldown.mjs +6 -6
- package/dist/_build/rollup.mjs +11 -11
- package/dist/_build/vite.build.mjs +3 -3
- package/dist/_build/vite.dev.mjs +149 -0
- package/dist/_build/vite.env.mjs +177 -0
- package/dist/_chunks/nitro.mjs +239 -12
- package/dist/_chunks/nitro2.mjs +117 -90
- package/dist/_chunks/utils.mjs +4 -4
- package/dist/_common.mjs +1 -1
- package/dist/_dev.d.mts +1 -1
- package/dist/_dev.mjs +5 -5
- package/dist/_libs/c12+rc9.mjs +11 -10
- package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
- package/dist/_libs/citty.mjs +1 -1
- package/dist/_libs/common.d.mts +37 -0
- package/dist/_libs/commondir+is-reference.mjs +3 -3
- package/dist/_libs/compatx.d.mts +1 -1
- package/dist/_libs/compatx.mjs +1 -1
- package/dist/_libs/estree+pluginutils.d.mts +1 -1
- package/dist/_libs/estree-walker.mjs +1 -1
- package/dist/_libs/hasown+resolve+deepmerge.mjs +15 -15
- package/dist/_libs/httpxy.d.mts +1 -1
- package/dist/_libs/httpxy.mjs +8 -4
- package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
- package/dist/_libs/klona.mjs +1 -1
- package/dist/_libs/magic-string.d.mts +1 -1
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +92 -99
- package/dist/_libs/openapi-types.d.mts +730 -0
- package/dist/_libs/perfect-debounce.mjs +1 -1
- package/dist/_libs/pkg-types.d.mts +1 -1
- package/dist/_libs/plugin-alias.mjs +2 -2
- package/dist/_libs/plugin-inject.mjs +3 -3
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils.mjs +16 -5
- package/dist/_libs/readdirp+chokidar.mjs +2 -2
- package/dist/_libs/remapping.mjs +2 -2
- package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
- package/dist/_libs/rou3.d.mts +1 -1
- package/dist/_libs/rou3.mjs +1 -1
- package/dist/_libs/std-env.d.mts +1 -1
- package/dist/_libs/tsconfck.mjs +1 -1
- package/dist/_libs/ultrahtml.mjs +1 -1
- package/dist/_libs/{unimport+unplugin+oxc-parser.mjs → unimport+unplugin.mjs} +18 -8
- package/dist/_libs/unplugin+unimport.d.mts +3 -3
- package/dist/_libs/unwasm.d.mts +1 -1
- package/dist/_presets.mjs +117 -91
- package/dist/builder.d.mts +1 -1
- package/dist/builder.mjs +3 -3
- package/dist/cli/_chunks/build.mjs +3 -3
- package/dist/cli/_chunks/common.mjs +1 -1
- package/dist/cli/_chunks/deploy.mjs +2 -2
- package/dist/cli/_chunks/dev.mjs +4 -4
- package/dist/cli/_chunks/docs.mjs +1 -1
- package/dist/cli/_chunks/list.mjs +2 -2
- package/dist/cli/_chunks/prepare.mjs +3 -3
- package/dist/cli/_chunks/preview.mjs +4 -4
- package/dist/cli/_chunks/run.mjs +2 -2
- package/dist/cli/_chunks/task.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
- package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
- package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
- package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
- package/dist/runtime/internal/app.mjs +4 -111
- package/dist/runtime/virtual/app.d.mts +4 -0
- package/dist/runtime/virtual/app.mjs +32 -0
- package/dist/types/index.d.mts +21 -1756
- package/dist/vite.mjs +23 -337
- package/package.json +37 -39
- package/dist/THIRD-PARTY-LICENSES.md +0 -1676
- package/dist/_chunks/nitro3.mjs +0 -136
- package/dist/_chunks/nitro4.mjs +0 -127
package/dist/vite.mjs
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { runtimeDependencies, runtimeDir } from "nitro/meta";
|
|
11
|
-
import { existsSync, watch } from "node:fs";
|
|
1
|
+
import { NODE_MODULES_RE, baseBuildConfig, baseBuildPlugins, basename, copyPublicAssets, dirname, getChunkName, join, libChunkName, m, prepare, prettyPath, resolve, resolveModulePath, v, writeBuildInfo } from "./_build/common.mjs";
|
|
2
|
+
import { formatCompatibilityDate } from "./_libs/compatx.mjs";
|
|
3
|
+
import { createNitro, prerender } from "./_chunks/nitro.mjs";
|
|
4
|
+
import { NitroDevApp } from "./_dev.mjs";
|
|
5
|
+
import { createNitroEnvironment, createServiceEnvironment, createServiceEnvironments, getEnvRunner, initEnvRunner, nitroServiceProxy } from "./_build/vite.env.mjs";
|
|
6
|
+
import { startPreview } from "./_chunks/nitro2.mjs";
|
|
7
|
+
import { assetsPlugin } from "./_libs/pluginutils.mjs";
|
|
8
|
+
import { runtimeDir } from "nitro/meta";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
12
10
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
13
|
-
import { join, resolve } from "node:path";
|
|
14
11
|
import { defu } from "defu";
|
|
15
|
-
import { withBase } from "ufo";
|
|
16
12
|
import { colors } from "consola/utils";
|
|
17
|
-
import { RunnerManager, loadRunner } from "env-runner";
|
|
18
|
-
import { NodeRequest, sendNodeResponse } from "srvx/node";
|
|
19
|
-
import "node:http";
|
|
20
|
-
import { DevEnvironment } from "vite";
|
|
21
|
-
import { createViteHotChannel } from "env-runner/vite";
|
|
22
13
|
const getBundlerConfig = async (ctx) => {
|
|
23
14
|
const nitro = ctx.nitro;
|
|
24
15
|
const base = baseBuildConfig(nitro);
|
|
@@ -56,8 +47,8 @@ const getBundlerConfig = async (ctx) => {
|
|
|
56
47
|
rolldownConfig
|
|
57
48
|
};
|
|
58
49
|
} else {
|
|
59
|
-
const inject = (await import("./_libs/plugin-inject.mjs").then((n) => n.
|
|
60
|
-
const alias = (await import("./_libs/plugin-alias.mjs").then((n) => n.
|
|
50
|
+
const inject = (await import("./_libs/plugin-inject.mjs").then((n) => n.es_exports)).default;
|
|
51
|
+
const alias = (await import("./_libs/plugin-alias.mjs").then((n) => n.dist_exports)).default;
|
|
61
52
|
const rollupConfig = defu({
|
|
62
53
|
plugins: [inject(base.env.inject), alias({ entries: base.aliases })],
|
|
63
54
|
output: {
|
|
@@ -100,12 +91,12 @@ async function buildEnvironments(ctx, builder) {
|
|
|
100
91
|
const nitroOptions = ctx.nitro.options;
|
|
101
92
|
const clientInput = builder.environments.client?.config?.build?.rollupOptions?.input;
|
|
102
93
|
if (nitroOptions.renderer?.template && nitroOptions.renderer?.template === clientInput) {
|
|
103
|
-
const outputPath = resolve
|
|
94
|
+
const outputPath = resolve(nitroOptions.output.publicDir, basename(clientInput));
|
|
104
95
|
if (existsSync(outputPath)) {
|
|
105
96
|
const html = await readFile(outputPath, "utf8").then((r) => r.replace("<!--ssr-outlet-->", `{{{ globalThis.__nitro_vite_envs__?.["ssr"]?.fetch($REQUEST) || "" }}}`));
|
|
106
97
|
await rm(outputPath);
|
|
107
|
-
const tmp = resolve
|
|
108
|
-
await mkdir(dirname
|
|
98
|
+
const tmp = resolve(nitroOptions.buildDir, "vite/index.html");
|
|
99
|
+
await mkdir(dirname(tmp), { recursive: true });
|
|
109
100
|
await writeFile(tmp, html, "utf8");
|
|
110
101
|
nitroOptions.renderer.template = tmp;
|
|
111
102
|
}
|
|
@@ -117,7 +108,7 @@ async function buildEnvironments(ctx, builder) {
|
|
|
117
108
|
await copyPublicAssets(nitro);
|
|
118
109
|
const assetDirs = new Set(Object.values(builder.environments).filter((env) => env.config.consumer === "client").map((env) => env.config.build.assetsDir).filter(Boolean));
|
|
119
110
|
for (const assetsDir of assetDirs) {
|
|
120
|
-
if (!existsSync(resolve
|
|
111
|
+
if (!existsSync(resolve(nitro.options.output.publicDir, assetsDir))) continue;
|
|
121
112
|
const rule = ctx.nitro.options.routeRules[`/${assetsDir}/**`] ??= {};
|
|
122
113
|
if (!rule.headers?.["cache-control"]) rule.headers = {
|
|
123
114
|
...rule.headers,
|
|
@@ -151,319 +142,13 @@ function lazyService(loader) {
|
|
|
151
142
|
|
|
152
143
|
const services = {
|
|
153
144
|
${Object.keys(ctx.services).map((name) => {
|
|
154
|
-
return [name, resolve
|
|
145
|
+
return [name, resolve(ctx.nitro.options.buildDir, "vite/services", name, ctx._entryPoints[name])];
|
|
155
146
|
}).map(([name, entry]) => `[${JSON.stringify(name)}]: lazyService(() => import(${JSON.stringify(entry)}))`).join(",\n")}
|
|
156
147
|
};
|
|
157
148
|
|
|
158
149
|
globalThis.__nitro_vite_envs__ = services;
|
|
159
150
|
`;
|
|
160
151
|
}
|
|
161
|
-
const ASSET_EXT_RE = /^(?:[jt]sx?|mjs|cjs|css|s[ac]ss|less|styl|vue|svelte|astro|mdx?|map|wasm|png|jpe?g|gif|svg|webp|avif|ico|bmp|woff2?|ttf|otf|eot|mp[34]|webm|wav|ogg|m4a)$/i;
|
|
162
|
-
function createFetchableDevEnvironment(name, config, devServer, entry, opts) {
|
|
163
|
-
return new FetchableDevEnvironment(name, config, {
|
|
164
|
-
hot: true,
|
|
165
|
-
transport: createViteHotChannel(devServer, name)
|
|
166
|
-
}, devServer, entry, opts);
|
|
167
|
-
}
|
|
168
|
-
var FetchableDevEnvironment = class extends DevEnvironment {
|
|
169
|
-
devServer;
|
|
170
|
-
#entry;
|
|
171
|
-
#preventExternalize;
|
|
172
|
-
constructor(name, config, context, devServer, entry, opts) {
|
|
173
|
-
super(name, config, context);
|
|
174
|
-
this.devServer = devServer;
|
|
175
|
-
this.#entry = entry;
|
|
176
|
-
this.#preventExternalize = opts?.preventExternalize ?? false;
|
|
177
|
-
}
|
|
178
|
-
async fetchModule(id, importer, options) {
|
|
179
|
-
if (this.#preventExternalize && !id.startsWith("file://") && importer && id[0] !== "." && id[0] !== "/") {
|
|
180
|
-
const resolved = await this.pluginContainer.resolveId(id, importer);
|
|
181
|
-
if (resolved && !resolved.external) return super.fetchModule(resolved.id, importer, options);
|
|
182
|
-
}
|
|
183
|
-
return super.fetchModule(id, importer, options);
|
|
184
|
-
}
|
|
185
|
-
async dispatchFetch(request) {
|
|
186
|
-
return this.devServer.fetch(request);
|
|
187
|
-
}
|
|
188
|
-
async init(...args) {
|
|
189
|
-
await this.devServer.init?.();
|
|
190
|
-
await super.init(...args);
|
|
191
|
-
this.devServer.sendMessage({
|
|
192
|
-
type: "custom",
|
|
193
|
-
event: "nitro:vite-env",
|
|
194
|
-
data: {
|
|
195
|
-
name: this.name,
|
|
196
|
-
entry: this.#entry
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
async function configureViteDevServer(ctx, server) {
|
|
202
|
-
const nitro = ctx.nitro;
|
|
203
|
-
const nitroEnv = server.environments.nitro;
|
|
204
|
-
const nitroConfigFile = nitro.options._c12.configFile;
|
|
205
|
-
if (nitroConfigFile) server.config.configFileDependencies.push(nitroConfigFile);
|
|
206
|
-
if (nitro.options.features.websocket ?? nitro.options.experimental.websocket) server.httpServer.on("upgrade", (req, socket, head) => {
|
|
207
|
-
if (req.headers["sec-websocket-protocol"]?.startsWith("vite-")) return;
|
|
208
|
-
getEnvRunner(ctx).upgrade?.({ node: {
|
|
209
|
-
req,
|
|
210
|
-
socket,
|
|
211
|
-
head
|
|
212
|
-
} });
|
|
213
|
-
});
|
|
214
|
-
const reload = debounce(async () => {
|
|
215
|
-
await scanHandlers(nitro);
|
|
216
|
-
nitro.routing.sync();
|
|
217
|
-
nitroEnv.moduleGraph.invalidateAll();
|
|
218
|
-
nitroEnv.hot.send({ type: "full-reload" });
|
|
219
|
-
});
|
|
220
|
-
const scanDirs = nitro.options.scanDirs.flatMap((dir) => [
|
|
221
|
-
join$1(dir, nitro.options.apiDir || "api"),
|
|
222
|
-
join$1(dir, nitro.options.routesDir || "routes"),
|
|
223
|
-
join$1(dir, "middleware"),
|
|
224
|
-
join$1(dir, "plugins"),
|
|
225
|
-
join$1(dir, "modules")
|
|
226
|
-
]);
|
|
227
|
-
const watchReloadEvents = new Set([
|
|
228
|
-
"add",
|
|
229
|
-
"addDir",
|
|
230
|
-
"unlink",
|
|
231
|
-
"unlinkDir"
|
|
232
|
-
]);
|
|
233
|
-
const scanDirsWatcher = watch$1(scanDirs, { ignoreInitial: true }).on("all", (event, path, stat) => {
|
|
234
|
-
if (watchReloadEvents.has(event)) reload();
|
|
235
|
-
});
|
|
236
|
-
const rootDirWatcher = watch(nitro.options.rootDir, { persistent: false }, (_event, filename) => {
|
|
237
|
-
if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) reload();
|
|
238
|
-
});
|
|
239
|
-
nitro.hooks.hook("close", () => {
|
|
240
|
-
scanDirsWatcher.close();
|
|
241
|
-
rootDirWatcher.close();
|
|
242
|
-
});
|
|
243
|
-
nitroEnv.devServer.onMessage(async (message) => {
|
|
244
|
-
if (message?.__rpc === "transformHTML") try {
|
|
245
|
-
const html = (await server.transformIndexHtml("/", message.data)).replace("<!--ssr-outlet-->", `{{{ globalThis.__nitro_vite_envs__?.["ssr"]?.fetch($REQUEST) || "" }}}`);
|
|
246
|
-
nitroEnv.devServer.sendMessage({
|
|
247
|
-
__rpc_id: message.__rpc_id,
|
|
248
|
-
data: html
|
|
249
|
-
});
|
|
250
|
-
} catch (error) {
|
|
251
|
-
nitroEnv.devServer.sendMessage({
|
|
252
|
-
__rpc_id: message.__rpc_id,
|
|
253
|
-
error: error instanceof Error ? error.message : String(error)
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
const nitroDevMiddleware = async (nodeReq, nodeRes, next) => {
|
|
258
|
-
if (!nodeReq.url || /^\/@(?:vite|fs|id)\//.test(nodeReq.url) || nodeReq._nitroHandled || server.middlewares.stack.map((mw) => mw.route).some((base) => base && nodeReq.url.startsWith(base))) return next();
|
|
259
|
-
nodeReq._nitroHandled = true;
|
|
260
|
-
const baseURL = nitro.options.baseURL || "/";
|
|
261
|
-
const originalURL = nodeReq.url;
|
|
262
|
-
if (baseURL !== "/") nodeReq.url = withBase(nodeReq.url, baseURL);
|
|
263
|
-
try {
|
|
264
|
-
const req = new NodeRequest({
|
|
265
|
-
req: nodeReq,
|
|
266
|
-
res: nodeRes
|
|
267
|
-
});
|
|
268
|
-
const devAppRes = await ctx.devApp.fetch(req);
|
|
269
|
-
if (nodeRes.writableEnded || nodeRes.headersSent) return;
|
|
270
|
-
if (devAppRes.status !== 404) return await sendNodeResponse(nodeRes, devAppRes);
|
|
271
|
-
const envRes = await nitroEnv.dispatchFetch(req);
|
|
272
|
-
if (nodeRes.writableEnded || nodeRes.headersSent) return;
|
|
273
|
-
return await sendNodeResponse(nodeRes, envRes);
|
|
274
|
-
} catch (error) {
|
|
275
|
-
return next(error);
|
|
276
|
-
} finally {
|
|
277
|
-
if (baseURL !== "/") nodeReq.url = originalURL;
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
server.middlewares.use(function nitroDevMiddlewarePre(req, res, next) {
|
|
281
|
-
const fetchDest = req.headers["sec-fetch-dest"];
|
|
282
|
-
const accept = req.headers["accept"];
|
|
283
|
-
const ext = req.url.match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1];
|
|
284
|
-
const isNitroRoute = ext ? !!nitro.routing.routes.match(req.method || "", new URL(withBase(req.url, nitro.options.baseURL), "http://localhost").pathname) : false;
|
|
285
|
-
const isDocumentLike = fetchDest ? /^(document|iframe|frame|empty)$/.test(fetchDest) : !(ext && ASSET_EXT_RE.test(ext) && !(typeof accept === "string" && /\btext\/html\b/.test(accept)));
|
|
286
|
-
res.setHeader("vary", "sec-fetch-dest, accept");
|
|
287
|
-
if (isDocumentLike && (!ext || isNitroRoute) && !/^\/(?:__|@)/.test(req.url)) nitroDevMiddleware(req, res, next);
|
|
288
|
-
else {
|
|
289
|
-
if (!isDocumentLike) req._nitroHandled = true;
|
|
290
|
-
next();
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
return () => {
|
|
294
|
-
server.middlewares.use(nitroDevMiddleware);
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function createNitroEnvironment(ctx) {
|
|
298
|
-
const isWorkerdRunner = _isWorkerdRunner(ctx);
|
|
299
|
-
return {
|
|
300
|
-
consumer: "server",
|
|
301
|
-
build: {
|
|
302
|
-
rollupOptions: ctx.bundlerConfig.rollupConfig,
|
|
303
|
-
rolldownOptions: ctx.bundlerConfig.rolldownConfig,
|
|
304
|
-
minify: ctx.nitro.options.minify,
|
|
305
|
-
emptyOutDir: false,
|
|
306
|
-
sourcemap: ctx.nitro.options.sourcemap,
|
|
307
|
-
commonjsOptions: ctx.nitro.options.commonJS,
|
|
308
|
-
copyPublicDir: false
|
|
309
|
-
},
|
|
310
|
-
resolve: {
|
|
311
|
-
noExternal: ctx.nitro.options.dev ? isWorkerdRunner ? true : [
|
|
312
|
-
/^nitro$/,
|
|
313
|
-
new RegExp(`^(${runtimeDependencies.join("|")})$`),
|
|
314
|
-
...ctx.bundlerConfig.base.noExternal
|
|
315
|
-
] : true,
|
|
316
|
-
conditions: isWorkerdRunner ? [
|
|
317
|
-
"workerd",
|
|
318
|
-
"worker",
|
|
319
|
-
...ctx.nitro.options.exportConditions.filter((c) => c !== "node")
|
|
320
|
-
] : ctx.nitro.options.exportConditions,
|
|
321
|
-
externalConditions: ctx.nitro.options.exportConditions?.filter((c) => !/browser|wasm|module/.test(c))
|
|
322
|
-
},
|
|
323
|
-
define: { "process.env.NODE_ENV": JSON.stringify(ctx.nitro.options.dev ? "development" : "production") },
|
|
324
|
-
dev: { createEnvironment: (envName, envConfig) => {
|
|
325
|
-
const entry = resolve(runtimeDir, "internal/vite/dev-entry.mjs");
|
|
326
|
-
const env = createFetchableDevEnvironment(envName, envConfig, getEnvRunner(ctx), entry, { preventExternalize: isWorkerdRunner });
|
|
327
|
-
ctx._transformRequest = (id) => env.transformRequest(id);
|
|
328
|
-
(ctx._viteEnvs ??= /* @__PURE__ */ new Map()).set(envName, entry);
|
|
329
|
-
return env;
|
|
330
|
-
} }
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
function createServiceEnvironment(ctx, name, serviceConfig) {
|
|
334
|
-
const isWorkerdRunner = _isWorkerdRunner(ctx);
|
|
335
|
-
return {
|
|
336
|
-
consumer: "server",
|
|
337
|
-
build: {
|
|
338
|
-
rollupOptions: {
|
|
339
|
-
input: { index: serviceConfig.entry },
|
|
340
|
-
external: [/^nitro(\/|$)/]
|
|
341
|
-
},
|
|
342
|
-
minify: ctx.nitro.options.minify,
|
|
343
|
-
sourcemap: ctx.nitro.options.sourcemap,
|
|
344
|
-
outDir: join(ctx.nitro.options.buildDir, "vite/services", name),
|
|
345
|
-
emptyOutDir: true,
|
|
346
|
-
copyPublicDir: false
|
|
347
|
-
},
|
|
348
|
-
resolve: {
|
|
349
|
-
...isWorkerdRunner ? { noExternal: true } : {},
|
|
350
|
-
conditions: isWorkerdRunner ? [
|
|
351
|
-
"workerd",
|
|
352
|
-
"worker",
|
|
353
|
-
...ctx.nitro.options.exportConditions.filter((c) => c !== "node")
|
|
354
|
-
] : ctx.nitro.options.exportConditions,
|
|
355
|
-
externalConditions: ctx.nitro.options.exportConditions?.filter((c) => !/browser|wasm|module/.test(c))
|
|
356
|
-
},
|
|
357
|
-
dev: { createEnvironment: (envName, envConfig) => {
|
|
358
|
-
const entry = tryResolve(serviceConfig.entry);
|
|
359
|
-
(ctx._viteEnvs ??= /* @__PURE__ */ new Map()).set(envName, entry);
|
|
360
|
-
return createFetchableDevEnvironment(envName, envConfig, getEnvRunner(ctx), entry, { preventExternalize: isWorkerdRunner });
|
|
361
|
-
} }
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function createServiceEnvironments(ctx) {
|
|
365
|
-
return Object.fromEntries(Object.entries(ctx.services).map(([name, config]) => [name, createServiceEnvironment(ctx, name, config)]));
|
|
366
|
-
}
|
|
367
|
-
async function initEnvRunner(ctx) {
|
|
368
|
-
if (ctx._envRunner) return ctx._envRunner;
|
|
369
|
-
if (!ctx._initPromise) ctx._initPromise = (async () => {
|
|
370
|
-
const manager = new RunnerManager();
|
|
371
|
-
let _retries = 0;
|
|
372
|
-
manager.onClose((_runner, cause) => {
|
|
373
|
-
if (_retries++ < 3) {
|
|
374
|
-
ctx.nitro.logger.info("Restarting env runner...", cause ? `Cause: ${cause}` : "");
|
|
375
|
-
_loadRunner(ctx, manager);
|
|
376
|
-
} else ctx.nitro.logger.error("Env runner failed after 3 retries.", cause ? `Last cause: ${cause}` : "");
|
|
377
|
-
});
|
|
378
|
-
manager.onReady(() => {
|
|
379
|
-
_retries = 0;
|
|
380
|
-
if (ctx._viteEnvs) for (const [name, entry] of ctx._viteEnvs) manager.sendMessage({
|
|
381
|
-
type: "custom",
|
|
382
|
-
event: "nitro:vite-env",
|
|
383
|
-
data: {
|
|
384
|
-
name,
|
|
385
|
-
entry
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
await _loadRunner(ctx, manager);
|
|
390
|
-
ctx._envRunner = manager;
|
|
391
|
-
return manager;
|
|
392
|
-
})();
|
|
393
|
-
return await ctx._initPromise;
|
|
394
|
-
}
|
|
395
|
-
function getEnvRunner(ctx) {
|
|
396
|
-
if (!ctx._envRunner) throw new Error("Env runner not initialized. Call initEnvRunner() first.");
|
|
397
|
-
return ctx._envRunner;
|
|
398
|
-
}
|
|
399
|
-
async function _loadRunner(ctx, manager) {
|
|
400
|
-
const runnerName = ctx.nitro.options.devServer.runner || process.env.NITRO_DEV_RUNNER || "node-worker";
|
|
401
|
-
const entry = resolve(runtimeDir, "internal/vite/dev-worker.mjs");
|
|
402
|
-
let runner;
|
|
403
|
-
if (runnerName === "miniflare") {
|
|
404
|
-
const { MiniflareEnvRunner } = await import("env-runner/runners/miniflare");
|
|
405
|
-
runner = new MiniflareEnvRunner({
|
|
406
|
-
name: "nitro-vite",
|
|
407
|
-
data: { entry }
|
|
408
|
-
});
|
|
409
|
-
} else runner = await loadRunner(runnerName, {
|
|
410
|
-
name: "nitro-vite",
|
|
411
|
-
data: { entry }
|
|
412
|
-
});
|
|
413
|
-
await manager.reload(runner);
|
|
414
|
-
}
|
|
415
|
-
const NITRO_PROXY_PREFIX = "\0nitro-env-proxy:";
|
|
416
|
-
function nitroServiceProxy() {
|
|
417
|
-
return {
|
|
418
|
-
name: "nitro:service-proxy",
|
|
419
|
-
enforce: "pre",
|
|
420
|
-
applyToEnvironment: (env) => env.name !== "nitro" && env.config.consumer === "server",
|
|
421
|
-
apply: (_config, configEnv) => configEnv.command === "serve",
|
|
422
|
-
resolveId: {
|
|
423
|
-
filter: { id: /^nitro(\/|$)/ },
|
|
424
|
-
handler(id) {
|
|
425
|
-
if (id === "nitro" || id.startsWith("nitro/")) return {
|
|
426
|
-
id: NITRO_PROXY_PREFIX + id,
|
|
427
|
-
moduleSideEffects: false
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
},
|
|
431
|
-
load: {
|
|
432
|
-
filter: { id: /^\0nitro-env-proxy:/ },
|
|
433
|
-
handler(id) {
|
|
434
|
-
if (!id.startsWith(NITRO_PROXY_PREFIX)) return;
|
|
435
|
-
const originalId = id.slice(17);
|
|
436
|
-
return {
|
|
437
|
-
code: [
|
|
438
|
-
`const _mod = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__("nitro", ${JSON.stringify(originalId)});`,
|
|
439
|
-
`__vite_ssr_exportAll__(_mod);`,
|
|
440
|
-
`export default _mod.default;`
|
|
441
|
-
].join("\n"),
|
|
442
|
-
map: null
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
function _isWorkerdRunner(ctx) {
|
|
449
|
-
return (ctx.nitro.options.devServer.runner || process.env.NITRO_DEV_RUNNER || "node-worker") === "miniflare";
|
|
450
|
-
}
|
|
451
|
-
function tryResolve(id) {
|
|
452
|
-
if (/^[~#/\0]/.test(id) || isAbsolute$1(id)) return id;
|
|
453
|
-
return resolveModulePath(id, {
|
|
454
|
-
suffixes: ["", "/index"],
|
|
455
|
-
extensions: [
|
|
456
|
-
"",
|
|
457
|
-
".ts",
|
|
458
|
-
".mjs",
|
|
459
|
-
".cjs",
|
|
460
|
-
".js",
|
|
461
|
-
".mts",
|
|
462
|
-
".cts"
|
|
463
|
-
],
|
|
464
|
-
try: true
|
|
465
|
-
}) || id;
|
|
466
|
-
}
|
|
467
152
|
function nitroPreviewPlugin(ctx) {
|
|
468
153
|
return {
|
|
469
154
|
name: "nitro:preview",
|
|
@@ -579,7 +264,7 @@ function nitroEnv(ctx) {
|
|
|
579
264
|
configResolved() {
|
|
580
265
|
if (!ctx.nitro.options.renderer?.handler && !ctx.nitro.options.renderer?.template && ctx.services.ssr?.entry) {
|
|
581
266
|
ctx.nitro.options.renderer ??= {};
|
|
582
|
-
ctx.nitro.options.renderer.handler = resolve
|
|
267
|
+
ctx.nitro.options.renderer.handler = resolve(runtimeDir, "internal/vite/ssr-renderer");
|
|
583
268
|
ctx.nitro.routing.sync();
|
|
584
269
|
}
|
|
585
270
|
}
|
|
@@ -615,9 +300,9 @@ function nitroMain(ctx) {
|
|
|
615
300
|
debug("[main] Generating manifest and entry points for environment:", environment.name);
|
|
616
301
|
const isRegisteredService = Object.keys(ctx.services).includes(environment.name);
|
|
617
302
|
let entryFile;
|
|
618
|
-
const serviceEntry = isRegisteredService && ctx.services[environment.name]?.entry ? resolve
|
|
303
|
+
const serviceEntry = isRegisteredService && ctx.services[environment.name]?.entry ? resolve(ctx.services[environment.name].entry) : void 0;
|
|
619
304
|
for (const [_name, file] of Object.entries(bundle)) if (file.type === "chunk" && isRegisteredService && file.isEntry) {
|
|
620
|
-
if (serviceEntry && file.facadeModuleId && resolve
|
|
305
|
+
if (serviceEntry && file.facadeModuleId && resolve(file.facadeModuleId) === serviceEntry) {
|
|
621
306
|
entryFile = file.fileName;
|
|
622
307
|
break;
|
|
623
308
|
}
|
|
@@ -628,8 +313,9 @@ function nitroMain(ctx) {
|
|
|
628
313
|
ctx._entryPoints[this.environment.name] = entryFile;
|
|
629
314
|
}
|
|
630
315
|
} },
|
|
631
|
-
configureServer: (server) => {
|
|
316
|
+
configureServer: async (server) => {
|
|
632
317
|
debug("[main] Configuring dev server");
|
|
318
|
+
const { configureViteDevServer } = await import("./_build/vite.dev.mjs");
|
|
633
319
|
return configureViteDevServer(ctx, server);
|
|
634
320
|
},
|
|
635
321
|
async hotUpdate({ server, modules, timestamp }) {
|
|
@@ -719,7 +405,7 @@ async function setupNitroContext(ctx, configEnv, userConfig) {
|
|
|
719
405
|
"app",
|
|
720
406
|
"src",
|
|
721
407
|
""
|
|
722
|
-
].flatMap((d) => [ctx.nitro.options.rootDir, ...ctx.nitro.options.scanDirs].map((s) => join
|
|
408
|
+
].flatMap((d) => [ctx.nitro.options.rootDir, ...ctx.nitro.options.scanDirs].map((s) => join(s, d) + "/")),
|
|
723
409
|
extensions: DEFAULT_EXTENSIONS,
|
|
724
410
|
try: true
|
|
725
411
|
});
|
|
@@ -743,7 +429,7 @@ async function setupNitroContext(ctx, configEnv, userConfig) {
|
|
|
743
429
|
ctx.nitro.logger.warn(`Nitro server entry and Vite SSR both set to ${prettyPath(ctx.services.ssr.entry)}. Use a separate SSR entry (e.g. \`src/server.ts\`).`);
|
|
744
430
|
ctx.nitro.options.serverEntry = false;
|
|
745
431
|
}
|
|
746
|
-
const publicDistDir = ctx._publicDistDir = userConfig.build?.outDir || resolve
|
|
432
|
+
const publicDistDir = ctx._publicDistDir = userConfig.build?.outDir || resolve(ctx.nitro.options.buildDir, "vite/public");
|
|
747
433
|
ctx.nitro.options.publicAssets.push({
|
|
748
434
|
dir: publicDistDir,
|
|
749
435
|
maxAge: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.260522-beta",
|
|
4
4
|
"description": "Build and Deploy Universal JavaScript Servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-routes",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"gen-node-compat": "node scripts/gen-node-compat.ts",
|
|
59
59
|
"gen-presets": "obuild --stub && node ./scripts/gen-presets.ts",
|
|
60
60
|
"lint": "oxlint . && oxfmt --check .",
|
|
61
|
-
"
|
|
61
|
+
"fmt": "automd && oxlint --fix . && oxfmt .",
|
|
62
62
|
"nitro": "node ./src/cli/index.ts",
|
|
63
63
|
"release": "node ./scripts/release.ts",
|
|
64
64
|
"stub": "obuild --stub",
|
|
@@ -71,46 +71,49 @@
|
|
|
71
71
|
"consola": "^3.4.2",
|
|
72
72
|
"crossws": "^0.4.5",
|
|
73
73
|
"db0": "^0.3.4",
|
|
74
|
-
"env-runner": "^0.1.
|
|
75
|
-
"h3": "^2.0.1-rc.
|
|
74
|
+
"env-runner": "^0.1.9",
|
|
75
|
+
"h3": "^2.0.1-rc.22",
|
|
76
76
|
"hookable": "^6.1.1",
|
|
77
|
-
"nf3": "^0.3.
|
|
77
|
+
"nf3": "^0.3.17",
|
|
78
78
|
"ocache": "^0.1.4",
|
|
79
79
|
"ofetch": "^2.0.0-alpha.3",
|
|
80
80
|
"ohash": "^2.0.11",
|
|
81
|
-
"rolldown": "^1.0.
|
|
81
|
+
"rolldown": "^1.0.2",
|
|
82
82
|
"srvx": "^0.11.15",
|
|
83
83
|
"unenv": "^2.0.0-rc.24",
|
|
84
84
|
"unstorage": "^2.0.0-alpha.7"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@apphosting/common": "^0.0.9",
|
|
87
88
|
"@azure/functions": "^3.5.1",
|
|
88
89
|
"@azure/static-web-apps-cli": "^2.0.9",
|
|
89
|
-
"@cloudflare/workers-types": "^4.
|
|
90
|
+
"@cloudflare/workers-types": "^4.20260521.1",
|
|
91
|
+
"@cloudflare/workers-utils": "^0.21.0",
|
|
90
92
|
"@deno/types": "^0.0.1",
|
|
91
93
|
"@hiogawa/vite-plugin-fullstack": "^0.0.11",
|
|
92
|
-
"@netlify/edge-functions": "^3.0.
|
|
93
|
-
"@netlify/functions": "^5.2.
|
|
94
|
+
"@netlify/edge-functions": "^3.0.7",
|
|
95
|
+
"@netlify/functions": "^5.2.2",
|
|
94
96
|
"@rollup/plugin-alias": "^6.0.0",
|
|
95
97
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
96
98
|
"@rollup/plugin-inject": "^5.0.5",
|
|
97
99
|
"@rollup/plugin-json": "^6.1.0",
|
|
98
100
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
99
101
|
"@rollup/plugin-replace": "^6.0.3",
|
|
100
|
-
"@scalar/api-reference": "^1.
|
|
102
|
+
"@scalar/api-reference": "^1.57.2",
|
|
103
|
+
"@scalar/openapi-types": "^0.8.0",
|
|
101
104
|
"@types/aws-lambda": "^8.10.161",
|
|
102
|
-
"@types/estree": "^1.0.
|
|
105
|
+
"@types/estree": "^1.0.9",
|
|
103
106
|
"@types/etag": "^1.8.4",
|
|
104
107
|
"@types/http-proxy": "^1.17.17",
|
|
105
|
-
"@types/node": "^25.
|
|
108
|
+
"@types/node": "^25.9.1",
|
|
106
109
|
"@types/node-fetch": "^2.6.13",
|
|
107
110
|
"@types/semver": "^7.7.1",
|
|
108
111
|
"@types/xml2js": "^0.4.14",
|
|
109
|
-
"@typescript/native-preview": "
|
|
110
|
-
"@vercel/queue": "^0.
|
|
111
|
-
"@vitest/coverage-v8": "^4.1.
|
|
112
|
+
"@typescript/native-preview": "7.0.0-dev.20260521.1",
|
|
113
|
+
"@vercel/queue": "^0.2.0",
|
|
114
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
112
115
|
"automd": "^0.4.3",
|
|
113
|
-
"c12": "^4.0.0-beta.
|
|
116
|
+
"c12": "^4.0.0-beta.5",
|
|
114
117
|
"changelogen": "^0.6.2",
|
|
115
118
|
"chokidar": "^5.0.0",
|
|
116
119
|
"citty": "^0.2.2",
|
|
@@ -129,29 +132,29 @@
|
|
|
129
132
|
"get-port-please": "^3.2.0",
|
|
130
133
|
"giget": "^3.2.0",
|
|
131
134
|
"gzip-size": "^7.0.0",
|
|
132
|
-
"httpxy": "^0.5.
|
|
135
|
+
"httpxy": "^0.5.3",
|
|
133
136
|
"klona": "^2.0.6",
|
|
134
137
|
"knitwork": "^1.3.0",
|
|
135
138
|
"magic-string": "^0.30.21",
|
|
136
139
|
"mdzilla": "^0.2.1",
|
|
137
140
|
"mime": "^4.1.0",
|
|
138
|
-
"miniflare": "^4.
|
|
141
|
+
"miniflare": "^4.20260520.0",
|
|
139
142
|
"mlly": "^1.8.2",
|
|
140
143
|
"nypm": "^0.6.6",
|
|
141
|
-
"obuild": "^0.4.
|
|
142
|
-
"oxc-parser": "
|
|
143
|
-
"oxfmt": "^0.
|
|
144
|
-
"oxlint": "^1.
|
|
144
|
+
"obuild": "^0.4.36",
|
|
145
|
+
"oxc-parser": "link:shims/oxc-parser",
|
|
146
|
+
"oxfmt": "^0.51.0",
|
|
147
|
+
"oxlint": "^1.66.0",
|
|
145
148
|
"pathe": "^2.0.3",
|
|
146
149
|
"perfect-debounce": "^2.1.0",
|
|
147
150
|
"pkg-types": "^2.3.1",
|
|
148
151
|
"pretty-bytes": "^7.1.0",
|
|
149
|
-
"react": "^19.2.
|
|
152
|
+
"react": "^19.2.6",
|
|
150
153
|
"rendu": "^0.1.0",
|
|
151
|
-
"rollup": "^4.60.
|
|
154
|
+
"rollup": "^4.60.4",
|
|
152
155
|
"rou3": "^0.8.1",
|
|
153
156
|
"scule": "^1.3.0",
|
|
154
|
-
"semver": "^7.
|
|
157
|
+
"semver": "^7.8.0",
|
|
155
158
|
"serve-placeholder": "^2.0.2",
|
|
156
159
|
"source-map": "^0.7.6",
|
|
157
160
|
"std-env": "^4.1.0",
|
|
@@ -162,24 +165,24 @@
|
|
|
162
165
|
"ultrahtml": "^1.6.0",
|
|
163
166
|
"uncrypto": "^0.1.3",
|
|
164
167
|
"unctx": "^2.5.0",
|
|
165
|
-
"unimport": "^6.
|
|
168
|
+
"unimport": "^6.3.0",
|
|
166
169
|
"untyped": "^2.0.0",
|
|
167
170
|
"unwasm": "^0.5.3",
|
|
168
|
-
"vite": "^8.0.
|
|
171
|
+
"vite": "^8.0.14",
|
|
169
172
|
"vite7": "npm:vite@^7.3.2",
|
|
170
|
-
"vitest": "^4.1.
|
|
171
|
-
"wrangler": "^4.
|
|
173
|
+
"vitest": "^4.1.7",
|
|
174
|
+
"wrangler": "^4.93.1",
|
|
172
175
|
"xml2js": "^0.6.2",
|
|
173
176
|
"youch": "^4.1.1",
|
|
174
177
|
"youch-core": "^0.3.3",
|
|
175
|
-
"zephyr-agent": "^1.
|
|
178
|
+
"zephyr-agent": "^1.1.1"
|
|
176
179
|
},
|
|
177
180
|
"peerDependencies": {
|
|
178
|
-
"@vercel/queue": "^0.
|
|
181
|
+
"@vercel/queue": "^0.2.0",
|
|
179
182
|
"dotenv": "*",
|
|
180
183
|
"giget": "*",
|
|
181
184
|
"jiti": "^2.6.1",
|
|
182
|
-
"rollup": "^4.60.
|
|
185
|
+
"rollup": "^4.60.3",
|
|
183
186
|
"vite": "^7 || ^8",
|
|
184
187
|
"xml2js": "^0.6.2",
|
|
185
188
|
"zephyr-agent": "^0.2.0"
|
|
@@ -210,15 +213,10 @@
|
|
|
210
213
|
"optional": true
|
|
211
214
|
}
|
|
212
215
|
},
|
|
213
|
-
"resolutions": {
|
|
214
|
-
"cookie-es": "^3.1.1",
|
|
215
|
-
"nitro": "link:.",
|
|
216
|
-
"oxc-parser": "link:./shims/oxc-parser"
|
|
217
|
-
},
|
|
218
216
|
"engines": {
|
|
219
217
|
"node": "^20.19.0 || >=22.12.0"
|
|
220
218
|
},
|
|
221
|
-
"packageManager": "pnpm@
|
|
219
|
+
"packageManager": "pnpm@11.1.3",
|
|
222
220
|
"compatiblePackages": {
|
|
223
221
|
"schemaVersion": 1,
|
|
224
222
|
"vite": {
|
|
@@ -231,7 +229,7 @@
|
|
|
231
229
|
},
|
|
232
230
|
"rolldown": {
|
|
233
231
|
"type": "compatible",
|
|
234
|
-
"versions": ">=1.0.0
|
|
232
|
+
"versions": ">=1.0.0"
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
}
|