@nuxt/nitro-server 4.3.0 → 4.3.1

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
@@ -19,34 +19,23 @@ import { isWindows } from "std-env";
19
19
  import { ImpoundPlugin } from "impound";
20
20
  import { resolveModulePath } from "exsolve";
21
21
  import { runtimeDependencies } from "nitropack/runtime/meta";
22
-
23
- //#region package.json
24
- var version = "4.3.0";
25
-
26
- //#endregion
27
- //#region src/utils.ts
22
+ var version = "4.3.1";
28
23
  function toArray(value) {
29
24
  return Array.isArray(value) ? value : [value];
30
25
  }
31
26
  let _distDir = dirname(fileURLToPath(import.meta.url));
32
27
  if (/(?:chunks|shared)$/.test(_distDir)) _distDir = dirname(_distDir);
33
28
  const distDir = _distDir;
34
-
35
- //#endregion
36
- //#region ../ui-templates/dist/templates/spa-loading-icon.ts
37
29
  const template = () => {
38
30
  return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"80\" fill=\"none\" class=\"nuxt-spa-loading\" viewBox=\"0 0 37 25\"><path d=\"M24.236 22.006h10.742L25.563 5.822l-8.979 14.31a4 4 0 0 1-3.388 1.874H2.978l11.631-20 5.897 10.567\"/></svg><style>.nuxt-spa-loading{left:50%;position:fixed;top:50%;transform:translate(-50%,-50%)}.nuxt-spa-loading>path{animation:nuxt-spa-loading-move 3s linear infinite;fill:none;stroke:#00dc82;stroke-dasharray:128;stroke-dashoffset:128;stroke-linecap:round;stroke-linejoin:round;stroke-width:4px}@keyframes nuxt-spa-loading-move{to{stroke-dashoffset:-128}}</style>";
39
31
  };
40
-
41
- //#endregion
42
- //#region ../nuxt/src/core/plugins/import-protection.ts
43
32
  function createImportProtectionPatterns(nuxt, options) {
44
33
  const patterns = [];
45
34
  const context = contextFlags[options.context];
46
35
  patterns.push([/^(nuxt|nuxt3|nuxt-nightly)$/, `\`nuxt\`, or \`nuxt-nightly\` cannot be imported directly in ${context}.` + (options.context === "nuxt-app" ? " Instead, import runtime Nuxt composables from `#app` or `#imports`." : "")]);
47
36
  patterns.push([/^((~|~~|@|@@)?\/)?nuxt\.config(\.|$)/, "Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module."]);
48
37
  patterns.push([/(^|node_modules\/)@vue\/composition-api/]);
49
- for (const mod of nuxt.options._installedModules) if (mod.entryPath) patterns.push([/* @__PURE__ */ new RegExp(`^${escapeRE(mod.entryPath)}$`), "Importing directly from module entry-points is not allowed."]);
38
+ for (const mod of nuxt.options._installedModules) if (mod.entryPath) patterns.push([new RegExp(`^${escapeRE(mod.entryPath)}$`), "Importing directly from module entry-points is not allowed."]);
50
39
  for (const i of [
51
40
  /(^|node_modules\/)@nuxt\/(cli|kit|test-utils)/,
52
41
  /(^|node_modules\/)nuxi/,
@@ -55,7 +44,7 @@ function createImportProtectionPatterns(nuxt, options) {
55
44
  ]) patterns.push([i, `This module cannot be imported in ${context}.`]);
56
45
  if (options.context === "nitro-app" || options.context === "shared") for (const i of ["#app", /^#build(\/|$)/]) patterns.push([i, `Vue app aliases are not allowed in ${context}.`]);
57
46
  if (options.context === "nuxt-app" || options.context === "shared") {
58
- patterns.push([/* @__PURE__ */ new RegExp(escapeRE(relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || "server"))) + "\\/(api|routes|middleware|plugins)\\/"), `Importing from server is not allowed in ${context}.`]);
47
+ patterns.push([new RegExp(escapeRE(relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || "server"))) + "\\/(api|routes|middleware|plugins)\\/"), `Importing from server is not allowed in ${context}.`]);
59
48
  patterns.push([/^#server(\/|$)/, `Server aliases are not allowed in ${context}.`]);
60
49
  }
61
50
  return patterns;
@@ -65,9 +54,6 @@ const contextFlags = {
65
54
  "nuxt-app": "the Vue part of your app",
66
55
  "shared": "the #shared directory"
67
56
  };
68
-
69
- //#endregion
70
- //#region src/templates.ts
71
57
  const nitroSchemaTemplate = {
72
58
  filename: "types/nitro-nuxt.d.ts",
73
59
  async getContents({ nuxt }) {
@@ -77,12 +63,9 @@ const nitroSchemaTemplate = {
77
63
  references,
78
64
  declarations
79
65
  });
80
- const sourceDir = join(nuxt.options.buildDir, "types");
66
+ const typesDir = join(nuxt.options.buildDir, "types");
81
67
  return `
82
- ${[...references.map((ref) => {
83
- if ("path" in ref && isAbsolute(ref.path)) ref.path = relative(sourceDir, ref.path);
84
- return `/// <reference ${renderAttrs(ref)} />`;
85
- }), ...declarations].join("\n")}
68
+ ${[...references.map((ref) => renderReference(ref, typesDir)), ...declarations].join("\n")}
86
69
 
87
70
  import type { RuntimeConfig } from 'nuxt/schema'
88
71
  import type { H3Event } from 'h3'
@@ -144,17 +127,9 @@ declare module 'nitropack/types' {
144
127
  `;
145
128
  }
146
129
  };
147
- function renderAttr(key, value) {
148
- return value ? `${key}="${value}"` : "";
149
- }
150
- function renderAttrs(obj) {
151
- const attrs = [];
152
- for (const key in obj) attrs.push(renderAttr(key, obj[key]));
153
- return attrs.join(" ");
130
+ function renderReference(ref, baseDir) {
131
+ return `/// <reference ${"path" in ref ? `path="${isAbsolute(ref.path) ? relative(baseDir, ref.path) : ref.path}"` : `types="${ref.types}"`} />`;
154
132
  }
155
-
156
- //#endregion
157
- //#region src/index.ts
158
133
  const logLevelMapReverse = {
159
134
  silent: 0,
160
135
  info: 3,
@@ -171,7 +146,7 @@ async function bundle(nuxt) {
171
146
  }
172
147
  const layerPublicAssetsDirs = [];
173
148
  for (const dirs of layerDirs) if (existsSync(dirs.public)) layerPublicAssetsDirs.push({ dir: dirs.public });
174
- const excludePattern = excludePaths.length ? [/* @__PURE__ */ new RegExp(`node_modules\\/(?!${excludePaths.join("|")})`)] : [/node_modules/];
149
+ const excludePattern = excludePaths.length ? [new RegExp(`node_modules\\/(?!${excludePaths.join("|")})`)] : [/node_modules/];
175
150
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
176
151
  const moduleEntryPaths = [];
177
152
  for (const m of nuxt.options._installedModules) {
@@ -448,18 +423,18 @@ async function bundle(nuxt) {
448
423
  }
449
424
  });
450
425
  if (nuxt.options.experimental.payloadExtraction) {
451
- if (nuxt.options.dev) nuxt.hook("nitro:config", (nitroConfig$1) => {
452
- nitroConfig$1.prerender ||= {};
453
- nitroConfig$1.prerender.routes ||= [];
454
- nitroConfig$1.routeRules ||= {};
455
- for (const route of nitroConfig$1.prerender.routes) {
426
+ if (nuxt.options.dev) nuxt.hook("nitro:config", (nitroConfig) => {
427
+ nitroConfig.prerender ||= {};
428
+ nitroConfig.prerender.routes ||= [];
429
+ nitroConfig.routeRules ||= {};
430
+ for (const route of nitroConfig.prerender.routes) {
456
431
  if (!route) continue;
457
- nitroConfig$1.routeRules[route] = defu(nitroConfig$1.routeRules[route], { prerender: true });
432
+ nitroConfig.routeRules[route] = defu(nitroConfig.routeRules[route], { prerender: true });
458
433
  }
459
434
  });
460
- nuxt.hook("nitro:init", (nitro$1) => {
461
- nitro$1.hooks.hook("build:before", (nitro$2) => {
462
- for (const [route, value] of Object.entries(nitro$2.options.routeRules)) if (!route.endsWith("*") && !route.endsWith("/_payload.json")) {
435
+ nuxt.hook("nitro:init", (nitro) => {
436
+ nitro.hooks.hook("build:before", (nitro) => {
437
+ for (const [route, value] of Object.entries(nitro.options.routeRules)) if (!route.endsWith("*") && !route.endsWith("/_payload.json")) {
463
438
  if (value.isr || value.cache || value.prerender && nuxt.options.dev) {
464
439
  const payloadKey = route + "/_payload.json";
465
440
  const defaults = {};
@@ -468,7 +443,7 @@ async function bundle(nuxt) {
468
443
  "cache",
469
444
  ...nuxt.options.dev ? ["prerender"] : []
470
445
  ]) if (key in value) defaults[key] = value[key];
471
- nitro$2.options.routeRules[payloadKey] = defu(nitro$2.options.routeRules[payloadKey], defaults);
446
+ nitro.options.routeRules[payloadKey] = defu(nitro.options.routeRules[payloadKey], defaults);
472
447
  }
473
448
  }
474
449
  });
@@ -500,13 +475,13 @@ async function bundle(nuxt) {
500
475
  config.alias ||= {};
501
476
  config.alias["#app-manifest"] = join(tempDir, `meta/${buildId}.json`);
502
477
  });
503
- nuxt.hook("nitro:init", (nitro$1) => {
504
- nitro$1.hooks.hook("rollup:before", async (nitro$2) => {
478
+ nuxt.hook("nitro:init", (nitro) => {
479
+ nitro.hooks.hook("rollup:before", async (nitro) => {
505
480
  const prerenderedRoutes = /* @__PURE__ */ new Set();
506
481
  const routeRulesMatcher = getRouteRulesRouter();
507
- if (nitro$2._prerenderedRoutes?.length) {
482
+ if (nitro._prerenderedRoutes?.length) {
508
483
  const payloadSuffix = nuxt.options.experimental.renderJsonPayloads ? "/_payload.json" : "/_payload.js";
509
- for (const route of nitro$2._prerenderedRoutes) if (!route.error && route.route.endsWith(payloadSuffix)) {
484
+ for (const route of nitro._prerenderedRoutes) if (!route.error && route.route.endsWith(payloadSuffix)) {
510
485
  const url = route.route.slice(0, -payloadSuffix.length) || "/";
511
486
  if (!defu({}, ...findAllRoutes(routeRulesMatcher, void 0, url).reverse()).prerender) prerenderedRoutes.add(url);
512
487
  }
@@ -541,8 +516,8 @@ async function bundle(nuxt) {
541
516
  const relativeSharedDir = withTrailingSlash(relative(nuxt.options.rootDir, resolve(nuxt.options.rootDir, nuxt.options.dir.shared)));
542
517
  const sharedPatterns = [
543
518
  /^#shared\//,
544
- /* @__PURE__ */ new RegExp("^" + escapeRE(sharedDir)),
545
- /* @__PURE__ */ new RegExp("^" + escapeRE(relativeSharedDir))
519
+ new RegExp("^" + escapeRE(sharedDir)),
520
+ new RegExp("^" + escapeRE(relativeSharedDir))
546
521
  ];
547
522
  nitroConfig.rollupConfig.plugins.push(ImpoundPlugin.rollup({
548
523
  cwd: nuxt.options.rootDir,
@@ -666,12 +641,12 @@ async function bundle(nuxt) {
666
641
  handler: resolve(distDir, "runtime/handlers/renderer")
667
642
  });
668
643
  if (nuxt.options.experimental.chromeDevtoolsProjectSettings) {
669
- const cacheDir$1 = resolve(nuxt.options.rootDir, "node_modules/.cache/nuxt");
670
- let projectConfiguration = await readFile(join(cacheDir$1, "chrome-workspace.json"), "utf-8").then((r) => JSON.parse(r)).catch(() => null);
644
+ const cacheDir = resolve(nuxt.options.rootDir, "node_modules/.cache/nuxt");
645
+ let projectConfiguration = await readFile(join(cacheDir, "chrome-workspace.json"), "utf-8").then((r) => JSON.parse(r)).catch(() => null);
671
646
  if (!projectConfiguration) {
672
647
  projectConfiguration = { uuid: randomUUID() };
673
- await mkdir(cacheDir$1, { recursive: true });
674
- await writeFile(join(cacheDir$1, "chrome-workspace.json"), JSON.stringify(projectConfiguration), "utf-8");
648
+ await mkdir(cacheDir, { recursive: true });
649
+ await writeFile(join(cacheDir, "chrome-workspace.json"), JSON.stringify(projectConfiguration), "utf-8");
675
650
  }
676
651
  nitro.options.devHandlers.push({
677
652
  route: "/.well-known/appspecific/com.chrome.devtools.json",
@@ -681,14 +656,14 @@ async function bundle(nuxt) {
681
656
  } }))
682
657
  });
683
658
  }
684
- if (!nuxt.options.dev && nuxt.options.experimental.noVueServer) nitro.hooks.hook("rollup:before", (nitro$1) => {
685
- if (nitro$1.options.preset === "nitro-prerender") {
686
- nitro$1.options.errorHandler = resolve(distDir, "runtime/handlers/error");
659
+ if (!nuxt.options.dev && nuxt.options.experimental.noVueServer) nitro.hooks.hook("rollup:before", (nitro) => {
660
+ if (nitro.options.preset === "nitro-prerender") {
661
+ nitro.options.errorHandler = resolve(distDir, "runtime/handlers/error");
687
662
  return;
688
663
  }
689
- const nuxtErrorHandler = nitro$1.options.handlers.findIndex((h) => h.route === "/__nuxt_error");
690
- if (nuxtErrorHandler >= 0) nitro$1.options.handlers.splice(nuxtErrorHandler, 1);
691
- nitro$1.options.renderer = void 0;
664
+ const nuxtErrorHandler = nitro.options.handlers.findIndex((h) => h.route === "/__nuxt_error");
665
+ if (nuxtErrorHandler >= 0) nitro.options.handlers.splice(nuxtErrorHandler, 1);
666
+ nitro.options.renderer = void 0;
692
667
  });
693
668
  nitro.hooks.hook("types:extend", (types) => {
694
669
  types.tsConfig ||= {};
@@ -716,14 +691,14 @@ async function bundle(nuxt) {
716
691
  for (const route of ["/200.html", "/404.html"]) routes.add(route);
717
692
  if (!nuxt.options.ssr) routes.add("/index.html");
718
693
  });
719
- if (!nuxt.options.dev) nitro.hooks.hook("rollup:before", async (nitro$1) => {
720
- await copyPublicAssets(nitro$1);
721
- await nuxt.callHook("nitro:build:public-assets", nitro$1);
694
+ if (!nuxt.options.dev) nitro.hooks.hook("rollup:before", async (nitro) => {
695
+ await copyPublicAssets(nitro);
696
+ await nuxt.callHook("nitro:build:public-assets", nitro);
722
697
  });
723
698
  async function symlinkDist() {
724
699
  if (nitro.options.static) {
725
- const distDir$1 = resolve(nuxt.options.rootDir, "dist");
726
- if (!existsSync(distDir$1)) await promises.symlink(nitro.options.output.publicDir, distDir$1, "junction").catch(() => {});
700
+ const distDir = resolve(nuxt.options.rootDir, "dist");
701
+ if (!existsSync(distDir)) await promises.symlink(nitro.options.output.publicDir, distDir, "junction").catch(() => {});
727
702
  }
728
703
  }
729
704
  nuxt.hook("build:done", async () => {
@@ -761,7 +736,7 @@ async function bundle(nuxt) {
761
736
  }));
762
737
  });
763
738
  nuxt.server = createDevServer(nitro);
764
- const waitUntilCompile = new Promise((resolve$1) => nitro.hooks.hook("compiled", () => resolve$1()));
739
+ const waitUntilCompile = new Promise((resolve) => nitro.hooks.hook("compiled", () => resolve()));
765
740
  nuxt.hook("build:done", () => waitUntilCompile);
766
741
  }
767
742
  }
@@ -775,14 +750,12 @@ async function spaLoadingTemplatePath(nuxt) {
775
750
  }
776
751
  async function spaLoadingTemplate(nuxt) {
777
752
  if (nuxt.options.spaLoadingTemplate === false) return "";
778
- const spaLoadingTemplate$1 = await spaLoadingTemplatePath(nuxt);
753
+ const spaLoadingTemplate = await spaLoadingTemplatePath(nuxt);
779
754
  try {
780
- if (existsSync(spaLoadingTemplate$1)) return readFileSync(spaLoadingTemplate$1, "utf-8").trim();
755
+ if (existsSync(spaLoadingTemplate)) return readFileSync(spaLoadingTemplate, "utf-8").trim();
781
756
  } catch {}
782
757
  if (nuxt.options.spaLoadingTemplate === true) return template();
783
758
  if (nuxt.options.spaLoadingTemplate) logger.warn(`Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${nuxt.options.spaLoadingTemplate}\`.`);
784
759
  return "";
785
760
  }
786
-
787
- //#endregion
788
- export { bundle };
761
+ export { bundle };
@@ -25,8 +25,8 @@ export default (async function errorhandler(error, event, { defaultHandler }) {
25
25
  // remove proto/hostname/port from URL
26
26
  const url = new URL(errorObject.url);
27
27
  errorObject.url = withoutBase(url.pathname, useRuntimeConfig(event).app.baseURL) + url.search + url.hash;
28
- // add default server message
29
- errorObject.message ||= "Server Error";
28
+ // add default server message (keep sanitized for unhandled errors)
29
+ errorObject.message = error.unhandled ? errorObject.message || "Server Error" : error.message || errorObject.message || "Server Error";
30
30
  // we will be rendering this error internally so we can pass along the error.data safely
31
31
  errorObject.data ||= error.data;
32
32
  errorObject.statusText ||= error.statusText || error.statusMessage;
@@ -1,4 +1,3 @@
1
- import { decodePath } from "ufo";
2
1
  import { useRuntimeConfig } from "nitropack/runtime";
3
2
  import { createHead } from "@unhead/vue/server";
4
3
  import { sharedPrerenderCache } from "../cache.mjs";
@@ -13,7 +12,7 @@ const PRERENDER_NO_SSR_ROUTES = new Set([
13
12
  ]);
14
13
  export function createSSRContext(event) {
15
14
  const ssrContext = {
16
- url: decodePath(event.path),
15
+ url: event.path,
17
16
  event,
18
17
  runtimeConfig: useRuntimeConfig(event),
19
18
  noSSR: !!NUXT_NO_SSR || event.context.nuxt?.noSSR || (import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(event.path) : false),
@@ -10,9 +10,7 @@ interface Renderer {
10
10
  renderScripts: () => string;
11
11
  }>;
12
12
  }
13
- // -- SSR Renderer --
14
13
  export declare const getSSRRenderer: unknown;
15
14
  export declare function getRenderer(ssrContext: NuxtSSRContext): Promise<Renderer>;
16
- // @ts-expect-error file will be produced after app build
17
15
  export declare const getSSRStyles: unknown;
18
16
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/nitro-server",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@nuxt/devalue": "^2.0.2",
22
- "@unhead/vue": "^2.1.2",
22
+ "@unhead/vue": "^2.1.3",
23
23
  "@vue/shared": "^3.5.27",
24
24
  "consola": "^3.4.2",
25
25
  "defu": "^6.1.4",
@@ -44,16 +44,16 @@
44
44
  "vue": "^3.5.27",
45
45
  "vue-bundle-renderer": "^2.2.0",
46
46
  "vue-devtools-stub": "^0.1.0",
47
- "@nuxt/kit": "4.3.0"
47
+ "@nuxt/kit": "4.3.1"
48
48
  },
49
49
  "peerDependencies": {
50
- "nuxt": "^4.3.0"
50
+ "nuxt": "^4.3.1"
51
51
  },
52
52
  "devDependencies": {
53
- "obuild": "0.4.14",
54
- "vitest": "3.2.4",
55
- "@nuxt/schema": "4.3.0",
56
- "nuxt": "4.3.0"
53
+ "obuild": "0.4.27",
54
+ "vitest": "4.0.18",
55
+ "@nuxt/schema": "4.3.1",
56
+ "nuxt": "4.3.1"
57
57
  },
58
58
  "engines": {
59
59
  "node": "^20.19.0 || >=22.12.0"