@nuxt/vite-server-nightly 4.6.0-2610061915-e634e1c → 4.6.0-2610071728-eec3725
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/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { addRoute, createRouter, findAllRoutes } from "rou3";
|
|
|
14
14
|
import { compileRouterToString } from "rou3/compiler";
|
|
15
15
|
import { NodeRequest, sendNodeResponse } from "srvx/node";
|
|
16
16
|
import { staticMiddleware } from "srvx/static";
|
|
17
|
+
import process from "node:process";
|
|
18
|
+
import { ERROR_CHANNEL_ENV, clearErrorReport, createDevErrorReporter, createErrorReport, setErrorChannelForwarding } from "nuxt/internal/dev-error";
|
|
17
19
|
//#region src/dirs.ts
|
|
18
20
|
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
19
21
|
if (/(?:chunks|shared)$/.test(_distDir)) _distDir = dirname(_distDir);
|
|
@@ -763,6 +765,58 @@ function disableUnsupported(nuxt) {
|
|
|
763
765
|
return unsupported;
|
|
764
766
|
}
|
|
765
767
|
//#endregion
|
|
768
|
+
//#region src/runtime/remote-dev-error.ts
|
|
769
|
+
const REMOTE_DEV_ERROR_EVENT = "nuxt:vite-server:dev-error";
|
|
770
|
+
const REMOTE_DEV_ERROR_REPORT_EVENT = "nuxt:vite-server:dev-error:report";
|
|
771
|
+
const REMOTE_DEV_ERROR_CLEAR_EVENT = "nuxt:vite-server:dev-error:clear";
|
|
772
|
+
function deserializeError(serialized) {
|
|
773
|
+
if (!serialized || typeof serialized !== "object") return serialized;
|
|
774
|
+
const { cause, ...properties } = serialized;
|
|
775
|
+
return Object.assign(new Error(serialized.message, cause === void 0 ? void 0 : { cause: deserializeError(cause) }), properties);
|
|
776
|
+
}
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/dev-errors.ts
|
|
779
|
+
/**
|
|
780
|
+
* Report errors raised by renders a deploy target runs outside this process, whose stacks
|
|
781
|
+
* arrive mapped to source positions.
|
|
782
|
+
*/
|
|
783
|
+
function listenForRemoteDevErrors(nuxt, server, channel) {
|
|
784
|
+
const forwarding = () => !!process.env[ERROR_CHANNEL_ENV];
|
|
785
|
+
setErrorChannelForwarding(forwarding);
|
|
786
|
+
const channelPath = () => process.env[ERROR_CHANNEL_ENV] || channel;
|
|
787
|
+
const observe = createDevErrorReporter({
|
|
788
|
+
cwd: nuxt.options.rootDir,
|
|
789
|
+
channel: channelPath,
|
|
790
|
+
createReport: (error, request) => createErrorReport(error, {
|
|
791
|
+
cwd: nuxt.options.rootDir,
|
|
792
|
+
context: { request }
|
|
793
|
+
}),
|
|
794
|
+
requestInfo: (request) => ({
|
|
795
|
+
method: request.method,
|
|
796
|
+
url: new URL(request.url),
|
|
797
|
+
headers: new Headers(request.headers)
|
|
798
|
+
})
|
|
799
|
+
});
|
|
800
|
+
for (const environment of Object.values(server.environments)) {
|
|
801
|
+
if (environment.config.consumer !== "server") continue;
|
|
802
|
+
environment.hot.on(REMOTE_DEV_ERROR_EVENT, async (message, client) => {
|
|
803
|
+
const error = deserializeError(message.error);
|
|
804
|
+
if (error instanceof Error && message.status !== void 0) Object.assign(error, { status: message.status });
|
|
805
|
+
const result = await observe(error, message.request).catch(() => void 0);
|
|
806
|
+
const [overlay, page] = result ? await Promise.all([result.overlay(""), result.page()]).catch(() => []) : [];
|
|
807
|
+
client.send(REMOTE_DEV_ERROR_REPORT_EVENT, {
|
|
808
|
+
id: message.id,
|
|
809
|
+
report: result?.report,
|
|
810
|
+
overlay,
|
|
811
|
+
page
|
|
812
|
+
});
|
|
813
|
+
});
|
|
814
|
+
environment.hot.on(REMOTE_DEV_ERROR_CLEAR_EVENT, () => {
|
|
815
|
+
clearErrorReport().catch(() => {});
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
//#endregion
|
|
766
820
|
//#region src/html.ts
|
|
767
821
|
const ESCAPES = {
|
|
768
822
|
"&": "&",
|
|
@@ -946,29 +1000,37 @@ function escape(path) {
|
|
|
946
1000
|
//#endregion
|
|
947
1001
|
//#region src/dev.ts
|
|
948
1002
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
* listener, so the listener is exposed to Vite for other plugins to attach to.
|
|
1003
|
+
* The ESM dependencies of the render, which a deploy target's environment loads as they
|
|
1004
|
+
* are rather than discovering and pre-bundling them as it reaches them.
|
|
952
1005
|
*/
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1006
|
+
const SERVER_RUNTIME_DEPS = [
|
|
1007
|
+
"vue",
|
|
1008
|
+
"vue-router",
|
|
1009
|
+
"@vue/shared",
|
|
1010
|
+
"@unhead/vue",
|
|
1011
|
+
"unhead",
|
|
1012
|
+
"vue-bundle-renderer",
|
|
1013
|
+
"cookie-es",
|
|
1014
|
+
"defu",
|
|
1015
|
+
"destr",
|
|
1016
|
+
"devalue",
|
|
1017
|
+
"errx",
|
|
1018
|
+
"hookable",
|
|
1019
|
+
"iron-webcrypto",
|
|
1020
|
+
"klona",
|
|
1021
|
+
"my-bad",
|
|
1022
|
+
"nostics",
|
|
1023
|
+
"ofetch",
|
|
1024
|
+
"pathe",
|
|
1025
|
+
"ufo",
|
|
1026
|
+
"unctx"
|
|
1027
|
+
];
|
|
966
1028
|
function setupDevServer(nuxt, serverEntry) {
|
|
967
1029
|
let viteServer;
|
|
968
1030
|
nuxt.hook("vite:serverCreated", (server) => {
|
|
969
1031
|
viteServer = server;
|
|
970
1032
|
});
|
|
971
|
-
const
|
|
1033
|
+
const staticMiddleware$1 = publicDirs(nuxt).map((dir) => staticMiddleware({ dir }));
|
|
972
1034
|
const shell = async (url) => {
|
|
973
1035
|
const html = await resolveDocument(nuxt);
|
|
974
1036
|
return new Response(viteServer ? await viteServer.transformIndexHtml(url, html) : html, { headers: { "content-type": "text/html;charset=utf-8" } });
|
|
@@ -986,17 +1048,54 @@ function setupDevServer(nuxt, serverEntry) {
|
|
|
986
1048
|
const respond = (request, url) => {
|
|
987
1049
|
return serverEntry && viteServer ? render(request) : shell(url);
|
|
988
1050
|
};
|
|
1051
|
+
const serveStatic = (request) => {
|
|
1052
|
+
const next = (index) => {
|
|
1053
|
+
const middleware = staticMiddleware$1[index];
|
|
1054
|
+
return Promise.resolve(middleware?.(request, () => next(index + 1)));
|
|
1055
|
+
};
|
|
1056
|
+
return next(0);
|
|
1057
|
+
};
|
|
1058
|
+
const isDocumentRequest = (req) => !serverEntry && (req.method === "GET" || req.method === "HEAD") && (req.headers["sec-fetch-mode"] === "navigate" || !!req.headers.accept?.includes("text/html"));
|
|
1059
|
+
nuxt.options.vite.plugins ||= [];
|
|
1060
|
+
nuxt.options.vite.plugins.push({
|
|
1061
|
+
name: "nuxt:vite-server:dev",
|
|
1062
|
+
enforce: "pre",
|
|
1063
|
+
apply: "serve",
|
|
1064
|
+
configEnvironment(name, config) {
|
|
1065
|
+
if (serverEntry && name !== "client" && name !== "ssr" && (config.consumer ?? "server") === "server") return { optimizeDeps: { exclude: [...SERVER_RUNTIME_DEPS] } };
|
|
1066
|
+
},
|
|
1067
|
+
configureServer: {
|
|
1068
|
+
order: "pre",
|
|
1069
|
+
handler(server) {
|
|
1070
|
+
server.httpServer ||= nuxt._devServerListener ?? null;
|
|
1071
|
+
if (serverEntry) listenForRemoteDevErrors(nuxt, server, errorChannel);
|
|
1072
|
+
return () => {
|
|
1073
|
+
server.middlewares.use(async function nuxtDevMiddleware(req, res, next) {
|
|
1074
|
+
const viteUrl = req.url;
|
|
1075
|
+
const url = req.url = req.originalUrl || req.url || "/";
|
|
1076
|
+
try {
|
|
1077
|
+
const request = new NodeRequest({
|
|
1078
|
+
req,
|
|
1079
|
+
res
|
|
1080
|
+
});
|
|
1081
|
+
const response = await serveStatic(request) ?? (isDocumentRequest(req) ? await shell(url) : void 0);
|
|
1082
|
+
if (response) return await sendNodeResponse(res, response);
|
|
1083
|
+
req.url = viteUrl;
|
|
1084
|
+
next();
|
|
1085
|
+
} catch (error) {
|
|
1086
|
+
next(error);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
989
1093
|
nuxt.server = { handler: async (req, res) => {
|
|
990
1094
|
if (viteServer && await handledByVite(viteServer, req, res)) return;
|
|
991
|
-
|
|
1095
|
+
await sendNodeResponse(res, await respond(new NodeRequest({
|
|
992
1096
|
req,
|
|
993
1097
|
res
|
|
994
|
-
});
|
|
995
|
-
const next = (index) => {
|
|
996
|
-
const handler = middleware[index];
|
|
997
|
-
return handler ? handler(request, () => next(index + 1)) : respond(request, req.url || "/");
|
|
998
|
-
};
|
|
999
|
-
await sendNodeResponse(res, await next(0));
|
|
1098
|
+
}), req.url || "/"));
|
|
1000
1099
|
} };
|
|
1001
1100
|
}
|
|
1002
1101
|
function handledByVite(server, req, res) {
|
|
@@ -1077,7 +1176,7 @@ function bundle(nuxt) {
|
|
|
1077
1176
|
});
|
|
1078
1177
|
setupAppManifest(nuxt, prerender);
|
|
1079
1178
|
nuxt.options.vite.plugins ||= [];
|
|
1080
|
-
nuxt.options.vite.plugins.push(BuildEnvironmentsPlugin(nuxt)
|
|
1179
|
+
nuxt.options.vite.plugins.push(BuildEnvironmentsPlugin(nuxt));
|
|
1081
1180
|
if (!nuxt.options.dev) {
|
|
1082
1181
|
const client = defu(nuxt.options.vite.$client, { build: {
|
|
1083
1182
|
outDir: publicDir,
|
|
@@ -1120,13 +1219,11 @@ function bundle(nuxt) {
|
|
|
1120
1219
|
/**
|
|
1121
1220
|
* Resolves `#server-entry` to the render as a module for a deploy target's own environment
|
|
1122
1221
|
* to build, so that the app is compiled with that target's export conditions and nothing
|
|
1123
|
-
* spells a path inside the build directory.
|
|
1124
|
-
*
|
|
1125
|
-
* In development it resolves to a stub answering every request with a 503: the dev server
|
|
1126
|
-
* serves the app there, and a target rendering would render from a second module graph.
|
|
1222
|
+
* spells a path inside the build directory. In development, the target's environment runs it
|
|
1223
|
+
* from its own module graph.
|
|
1127
1224
|
*/
|
|
1128
1225
|
function addServerEntryAlias(nuxt, entry) {
|
|
1129
|
-
nuxt.options.alias["#server-entry"] =
|
|
1226
|
+
nuxt.options.alias["#server-entry"] = entry;
|
|
1130
1227
|
addTypeTemplate({
|
|
1131
1228
|
filename: "types/server-entry.d.ts",
|
|
1132
1229
|
getContents: () => [
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ERROR_CHANNEL_ENV, clearErrorReport, createDevErrorReporter, createErrorReport, serializeErrorCause, setErrorChannelForwarding, useErrorChannel } from "nuxt/internal/dev-error";
|
|
1
|
+
import { REMOTE_DEV_ERROR_CLEAR_EVENT, REMOTE_DEV_ERROR_EVENT, REMOTE_DEV_ERROR_REPORT_EVENT } from "./remote-dev-error.mjs";
|
|
2
|
+
import { ERROR_CHANNEL_ENV, clearErrorReport as clearErrorReport$1, createDevErrorReporter, createErrorReport, serializeErrorCause, setErrorChannelForwarding, useErrorChannel } from "nuxt/internal/dev-error";
|
|
3
3
|
import { isLoopbackAddress } from "nuxt/internal/dev/peer";
|
|
4
4
|
//#region src/runtime/dev-error.ts
|
|
5
5
|
let context;
|
|
6
|
+
const env = () => globalThis.process?.env ?? {};
|
|
6
7
|
/** Whether a dev server in front owns the channel. */
|
|
7
|
-
const forwarding = () => !!
|
|
8
|
+
const forwarding = () => !!env()[ERROR_CHANNEL_ENV];
|
|
9
|
+
const hot = import.meta.hot;
|
|
8
10
|
setErrorChannelForwarding(forwarding);
|
|
9
11
|
/** Install the dev server the app renders from. */
|
|
10
12
|
function setDevErrorContext(next) {
|
|
@@ -31,8 +33,15 @@ async function fetchErrorChannel(request) {
|
|
|
31
33
|
* every later consumer sees source positions.
|
|
32
34
|
*/
|
|
33
35
|
function observeDevError(error, request, observe) {
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
36
|
+
if (context) return reporter(error, request, observe);
|
|
37
|
+
if (hot && !observe?.expected) return requestRemoteReport(error, request).catch(() => void 0);
|
|
38
|
+
return Promise.resolve(void 0);
|
|
39
|
+
}
|
|
40
|
+
/** Retire the current report, dismissing overlays showing it. */
|
|
41
|
+
function clearErrorReport() {
|
|
42
|
+
if (context || !hot) return clearErrorReport$1();
|
|
43
|
+
hot.send(REMOTE_DEV_ERROR_CLEAR_EVENT);
|
|
44
|
+
return Promise.resolve();
|
|
36
45
|
}
|
|
37
46
|
const reporter = createDevErrorReporter({
|
|
38
47
|
get cwd() {
|
|
@@ -47,6 +56,39 @@ const reporter = createDevErrorReporter({
|
|
|
47
56
|
}),
|
|
48
57
|
mapStack: (error) => fixStacktraces(error, context.server)
|
|
49
58
|
});
|
|
59
|
+
/** Ask the dev server to build, publish and render the report, as only it can read the sources. */
|
|
60
|
+
function requestRemoteReport(error, request) {
|
|
61
|
+
const id = crypto.randomUUID();
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const settle = (reply) => {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
hot.off(REMOTE_DEV_ERROR_REPORT_EVENT, listener);
|
|
66
|
+
const { report, overlay = "", page = "" } = reply ?? {};
|
|
67
|
+
if (!report) return reject(/* @__PURE__ */ new Error("The dev server did not report the error."));
|
|
68
|
+
resolve({
|
|
69
|
+
report,
|
|
70
|
+
overlay: (html) => {
|
|
71
|
+
const index = html.lastIndexOf("</body>");
|
|
72
|
+
return Promise.resolve(index === -1 ? html + overlay : html.slice(0, index) + overlay + html.slice(index));
|
|
73
|
+
},
|
|
74
|
+
page: () => Promise.resolve(page)
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const listener = (reply) => reply.id === id && settle(reply);
|
|
78
|
+
const timer = setTimeout(settle, 1e4);
|
|
79
|
+
hot.on(REMOTE_DEV_ERROR_REPORT_EVENT, listener);
|
|
80
|
+
hot.send(REMOTE_DEV_ERROR_EVENT, {
|
|
81
|
+
id,
|
|
82
|
+
error: serializeErrorCause(error),
|
|
83
|
+
status: error?.status,
|
|
84
|
+
request: request && {
|
|
85
|
+
method: request.method,
|
|
86
|
+
url: request.url,
|
|
87
|
+
headers: [...request.headers]
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
50
92
|
async function buildReport(error) {
|
|
51
93
|
const { viteLoader } = await import("my-bad/vite");
|
|
52
94
|
return createErrorReport(error, {
|
|
@@ -86,7 +128,7 @@ function errorCause(error) {
|
|
|
86
128
|
return serializeErrorCause(error?.cause);
|
|
87
129
|
}
|
|
88
130
|
function channelPath() {
|
|
89
|
-
return
|
|
131
|
+
return env()[ERROR_CHANNEL_ENV] || context.channel;
|
|
90
132
|
}
|
|
91
133
|
//#endregion
|
|
92
134
|
export { clearErrorReport, errorCause, fetchErrorChannel, isErrorChannelRequest, observeDevError, setDevErrorContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/runtime/remote-dev-error.ts
|
|
2
|
+
const REMOTE_DEV_ERROR_EVENT = "nuxt:vite-server:dev-error";
|
|
3
|
+
const REMOTE_DEV_ERROR_REPORT_EVENT = "nuxt:vite-server:dev-error:report";
|
|
4
|
+
const REMOTE_DEV_ERROR_CLEAR_EVENT = "nuxt:vite-server:dev-error:clear";
|
|
5
|
+
function deserializeError(serialized) {
|
|
6
|
+
if (!serialized || typeof serialized !== "object") return serialized;
|
|
7
|
+
const { cause, ...properties } = serialized;
|
|
8
|
+
return Object.assign(new Error(serialized.message, cause === void 0 ? void 0 : { cause: deserializeError(cause) }), properties);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { REMOTE_DEV_ERROR_CLEAR_EVENT, REMOTE_DEV_ERROR_EVENT, REMOTE_DEV_ERROR_REPORT_EVENT, deserializeError };
|
|
@@ -31,6 +31,7 @@ var NuxtServerError = class extends Error {
|
|
|
31
31
|
function createRendererOptions(runtimeConfig, matchRouteRules, prerender) {
|
|
32
32
|
globalThis.__buildAssetsURL = buildAssetsURL;
|
|
33
33
|
globalThis.__publicAssetsURL = publicAssetsURL;
|
|
34
|
+
const devErrors = import.meta.dev ? import("./dev-error.mjs") : void 0;
|
|
34
35
|
return {
|
|
35
36
|
runtimeConfig,
|
|
36
37
|
buildAssetsURL,
|
|
@@ -43,13 +44,13 @@ function createRendererOptions(runtimeConfig, matchRouteRules, prerender) {
|
|
|
43
44
|
createResponse: (body, init) => new Response(body, init),
|
|
44
45
|
createError: (init) => new NuxtServerError(init),
|
|
45
46
|
prerender,
|
|
46
|
-
onRenderSuccess:
|
|
47
|
-
|
|
47
|
+
onRenderSuccess: devErrors ? () => {
|
|
48
|
+
devErrors.then(({ clearErrorReport }) => clearErrorReport()).catch(() => {});
|
|
48
49
|
} : void 0,
|
|
49
50
|
captureError: (error) => {
|
|
50
51
|
if (!import.meta.dev) console.error(error);
|
|
51
52
|
},
|
|
52
|
-
onDevError:
|
|
53
|
+
onDevError: devErrors ? (error, event, options) => devErrors.then(({ observeDevError }) => observeDevError(error, event.req, options)) : void 0
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/vite-server-nightly",
|
|
3
|
-
"version": "4.6.0-
|
|
3
|
+
"version": "4.6.0-2610071728-eec3725",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nuxt/kit": "npm:@nuxt/kit-nightly@4.6.0-
|
|
22
|
+
"@nuxt/kit": "npm:@nuxt/kit-nightly@4.6.0-2610071728-eec3725",
|
|
23
23
|
"clickable-path": "^0.1.1",
|
|
24
24
|
"defu": "^6.1.7",
|
|
25
25
|
"exsolve": "^1.1.3",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"ultrahtml": "^1.7.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-
|
|
36
|
-
"nuxt": "npm:nuxt-nightly@4.6.0-
|
|
35
|
+
"@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-2610071728-eec3725",
|
|
36
|
+
"nuxt": "npm:nuxt-nightly@4.6.0-2610071728-eec3725",
|
|
37
37
|
"tsdown": "0.23.0",
|
|
38
38
|
"vite": "^8.3.2",
|
|
39
39
|
"vitest": "5.0.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"nuxt": "npm:nuxt-nightly@4.6.0-
|
|
42
|
+
"nuxt": "npm:nuxt-nightly@4.6.0-2610071728-eec3725",
|
|
43
43
|
"vite": "^8.3.2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/dev-handler.ts
|
|
2
|
-
/** Stands in for the render in development, where the dev server serves the app. */
|
|
3
|
-
const fetch = () => Promise.resolve(new Response("The Nuxt server handler is only emitted by a build. In development the app is served by the Nuxt dev server.", {
|
|
4
|
-
status: 503,
|
|
5
|
-
headers: { "content-type": "text/plain;charset=utf-8" }
|
|
6
|
-
}));
|
|
7
|
-
var dev_handler_default = { fetch };
|
|
8
|
-
//#endregion
|
|
9
|
-
export { dev_handler_default as default, fetch };
|