@nuxt/nitro-server-nightly 4.3.0-29435909.323f27bc → 4.3.0-29436247.ecea7a86

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.
Files changed (2) hide show
  1. package/dist/index.mjs +56 -47
  2. package/package.json +7 -6
package/dist/index.mjs CHANGED
@@ -4,10 +4,12 @@ import { cpus } from 'node:os';
4
4
  import process from 'node:process';
5
5
  import { readFile, mkdir, writeFile } from 'node:fs/promises';
6
6
  import { randomUUID } from 'node:crypto';
7
+ import { findAllRoutes, createRouter, addRoute } from 'rou3';
8
+ import { compileRouterToString } from 'rou3/compiler';
7
9
  import { dirname, relative, resolve, join, isAbsolute } from 'pathe';
8
10
  import { readPackageJSON } from 'pkg-types';
9
- import { toRouteMatcher, createRouter, exportMatcher } from 'radix3';
10
11
  import { withTrailingSlash, joinURL } from 'ufo';
12
+ import { hash } from 'ohash';
11
13
  import { createNitro, scanHandlers, writeTypes, copyPublicAssets, prepare, build, prerender, createDevServer } from 'nitropack';
12
14
  import { getLayerDirectories, getDirectory, resolveNuxtModule, addTemplate, resolveAlias, addPlugin, resolveIgnorePatterns, createIsIgnored, addVitePlugin, logger, findPath } from '@nuxt/kit';
13
15
  import escapeRE from 'escape-string-regexp';
@@ -17,7 +19,7 @@ import { isWindows } from 'std-env';
17
19
  import { ImpoundPlugin } from 'impound';
18
20
  import { resolveModulePath } from 'exsolve';
19
21
 
20
- const version = "4.3.0-29435909.323f27bc";
22
+ const version = "4.3.0-29436247.ecea7a86";
21
23
  const nitroBuilder = {
22
24
  version: version};
23
25
 
@@ -445,6 +447,56 @@ async function bundle(nuxt) {
445
447
  ...resolveIgnorePatterns(nitroConfig.srcDir),
446
448
  `!${join(nuxt.options.buildDir, "dist/client", nuxt.options.app.buildAssetsDir, "**/*")}`
447
449
  );
450
+ const validManifestKeys = ["prerender", "redirect", "appMiddleware"];
451
+ function getRouteRulesRouter() {
452
+ const routeRulesRouter = createRouter();
453
+ if (nuxt._nitro) {
454
+ for (const [route, rules] of Object.entries(nuxt._nitro.options.routeRules)) {
455
+ if (route === "/__nuxt_error") {
456
+ continue;
457
+ }
458
+ if (validManifestKeys.every((key) => !(key in rules))) {
459
+ continue;
460
+ }
461
+ addRoute(routeRulesRouter, void 0, route, rules);
462
+ }
463
+ }
464
+ return routeRulesRouter;
465
+ }
466
+ const cachedMatchers = {};
467
+ addTemplate({
468
+ filename: "route-rules.mjs",
469
+ getContents() {
470
+ const key = hash(nuxt._nitro?.options.routeRules || {});
471
+ if (cachedMatchers[key]) {
472
+ return cachedMatchers[key];
473
+ }
474
+ return cachedMatchers[key] = `export default ${compileRouterToString(getRouteRulesRouter(), "", {
475
+ matchAll: true,
476
+ serialize(routeRules) {
477
+ return `{${Object.entries(routeRules).filter(([name, value]) => value !== void 0 && validManifestKeys.includes(name)).map(([name, value]) => {
478
+ if (name === "redirect") {
479
+ const redirectOptions = value;
480
+ value = typeof redirectOptions === "string" ? redirectOptions : redirectOptions.to;
481
+ }
482
+ if (name === "appMiddleware") {
483
+ const appMiddlewareOptions = value;
484
+ if (typeof appMiddlewareOptions === "string") {
485
+ value = { [appMiddlewareOptions]: true };
486
+ } else if (Array.isArray(appMiddlewareOptions)) {
487
+ const normalizedRules = {};
488
+ for (const middleware of appMiddlewareOptions) {
489
+ normalizedRules[middleware] = true;
490
+ }
491
+ value = normalizedRules;
492
+ }
493
+ }
494
+ return `${name}: ${JSON.stringify(value)}`;
495
+ }).join(",")}}`;
496
+ }
497
+ })}`;
498
+ }
499
+ });
448
500
  if (nuxt.options.experimental.appManifest) {
449
501
  const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId;
450
502
  const buildTimestamp = Date.now();
@@ -477,59 +529,17 @@ async function bundle(nuxt) {
477
529
  nuxt.hook("nitro:config", (config) => {
478
530
  config.alias ||= {};
479
531
  config.alias["#app-manifest"] = join(tempDir, `meta/${buildId}.json`);
480
- const rules = config.routeRules;
481
- for (const rule in rules) {
482
- if (!rules[rule].appMiddleware) {
483
- continue;
484
- }
485
- const value = rules[rule].appMiddleware;
486
- if (typeof value === "string") {
487
- rules[rule].appMiddleware = { [value]: true };
488
- } else if (Array.isArray(value)) {
489
- const normalizedRules = {};
490
- for (const middleware of value) {
491
- normalizedRules[middleware] = true;
492
- }
493
- rules[rule].appMiddleware = normalizedRules;
494
- }
495
- }
496
532
  });
497
533
  nuxt.hook("nitro:init", (nitro2) => {
498
534
  nitro2.hooks.hook("rollup:before", async (nitro3) => {
499
- const routeRules = {};
500
- const _routeRules = nitro3.options.routeRules;
501
- const validManifestKeys = /* @__PURE__ */ new Set(["prerender", "redirect", "appMiddleware"]);
502
- for (const key in _routeRules) {
503
- if (key === "/__nuxt_error") {
504
- continue;
505
- }
506
- let hasRules = false;
507
- const filteredRules = {};
508
- for (const routeKey in _routeRules[key]) {
509
- const value = _routeRules[key][routeKey];
510
- if (value && validManifestKeys.has(routeKey)) {
511
- if (routeKey === "redirect") {
512
- filteredRules[routeKey] = typeof value === "string" ? value : value.to;
513
- } else {
514
- filteredRules[routeKey] = value;
515
- }
516
- hasRules = true;
517
- }
518
- }
519
- if (hasRules) {
520
- routeRules[key] = filteredRules;
521
- }
522
- }
523
535
  const prerenderedRoutes = /* @__PURE__ */ new Set();
524
- const routeRulesMatcher = toRouteMatcher(
525
- createRouter({ routes: routeRules })
526
- );
536
+ const routeRulesMatcher = getRouteRulesRouter();
527
537
  if (nitro3._prerenderedRoutes?.length) {
528
538
  const payloadSuffix = nuxt.options.experimental.renderJsonPayloads ? "/_payload.json" : "/_payload.js";
529
539
  for (const route of nitro3._prerenderedRoutes) {
530
540
  if (!route.error && route.route.endsWith(payloadSuffix)) {
531
541
  const url = route.route.slice(0, -payloadSuffix.length) || "/";
532
- const rules = defu({}, ...routeRulesMatcher.matchAll(url).reverse());
542
+ const rules = defu({}, ...findAllRoutes(routeRulesMatcher, void 0, url).reverse());
533
543
  if (!rules.prerender) {
534
544
  prerenderedRoutes.add(url);
535
545
  }
@@ -539,7 +549,6 @@ async function bundle(nuxt) {
539
549
  const manifest = {
540
550
  id: buildId,
541
551
  timestamp: buildTimestamp,
542
- matcher: exportMatcher(routeRulesMatcher),
543
552
  prerendered: nuxt.options.dev ? [] : [...prerenderedRoutes]
544
553
  };
545
554
  await promises.mkdir(join(tempDir, "meta"), { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/nitro-server-nightly",
3
- "version": "4.3.0-29435909.323f27bc",
3
+ "version": "4.3.0-29436247.ecea7a86",
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
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-29435909.323f27bc",
22
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-29436247.ecea7a86",
23
23
  "@unhead/vue": "^2.0.19",
24
24
  "@vue/shared": "^3.5.25",
25
25
  "consola": "^3.4.2",
@@ -34,9 +34,10 @@
34
34
  "klona": "^2.0.6",
35
35
  "mocked-exports": "^0.1.1",
36
36
  "nitropack": "^2.12.9",
37
+ "ohash": "^2.0.11",
37
38
  "pathe": "^2.0.3",
38
39
  "pkg-types": "^2.3.0",
39
- "radix3": "^1.1.2",
40
+ "rou3": "^0.7.12",
40
41
  "std-env": "^3.10.0",
41
42
  "ufo": "^1.6.1",
42
43
  "unctx": "^2.4.1",
@@ -46,11 +47,11 @@
46
47
  "vue-devtools-stub": "^0.1.0"
47
48
  },
48
49
  "peerDependencies": {
49
- "nuxt": "npm:nuxt-nightly@4.3.0-29435909.323f27bc"
50
+ "nuxt": "npm:nuxt-nightly@4.3.0-29436247.ecea7a86"
50
51
  },
51
52
  "devDependencies": {
52
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-29435909.323f27bc",
53
- "nuxt": "npm:nuxt-nightly@4.3.0-29435909.323f27bc",
53
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-29436247.ecea7a86",
54
+ "nuxt": "npm:nuxt-nightly@4.3.0-29436247.ecea7a86",
54
55
  "unbuild": "3.6.1",
55
56
  "vitest": "3.2.4"
56
57
  },