vinext 0.0.46 → 0.0.47

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 (171) hide show
  1. package/README.md +7 -5
  2. package/dist/build/prerender.d.ts +2 -1
  3. package/dist/build/prerender.js +70 -14
  4. package/dist/build/prerender.js.map +1 -1
  5. package/dist/build/report.d.ts +1 -1
  6. package/dist/build/route-classification-injector.d.ts +35 -0
  7. package/dist/build/route-classification-injector.js +61 -0
  8. package/dist/build/route-classification-injector.js.map +1 -0
  9. package/dist/build/route-classification-manifest.d.ts +1 -1
  10. package/dist/build/static-export.d.ts +1 -1
  11. package/dist/cli-args.d.ts +31 -0
  12. package/dist/cli-args.js +104 -0
  13. package/dist/cli-args.js.map +1 -0
  14. package/dist/cli.js +2 -19
  15. package/dist/cli.js.map +1 -1
  16. package/dist/cloudflare/kv-cache-handler.js +29 -9
  17. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  18. package/dist/config/next-config.d.ts +4 -2
  19. package/dist/config/next-config.js +3 -0
  20. package/dist/config/next-config.js.map +1 -1
  21. package/dist/entries/app-rsc-entry.d.ts +4 -3
  22. package/dist/entries/app-rsc-entry.js +373 -854
  23. package/dist/entries/app-rsc-entry.js.map +1 -1
  24. package/dist/entries/app-rsc-manifest.d.ts +1 -1
  25. package/dist/entries/app-rsc-manifest.js +2 -0
  26. package/dist/entries/app-rsc-manifest.js.map +1 -1
  27. package/dist/entries/pages-server-entry.js +5 -2
  28. package/dist/entries/pages-server-entry.js.map +1 -1
  29. package/dist/index.js +28 -51
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugins/fonts.js +54 -32
  32. package/dist/plugins/fonts.js.map +1 -1
  33. package/dist/plugins/rsc-client-shim-excludes.js +1 -0
  34. package/dist/plugins/rsc-client-shim-excludes.js.map +1 -1
  35. package/dist/routing/app-route-graph.d.ts +109 -0
  36. package/dist/routing/app-route-graph.js +819 -0
  37. package/dist/routing/app-route-graph.js.map +1 -0
  38. package/dist/routing/app-router.d.ts +2 -88
  39. package/dist/routing/app-router.js +6 -694
  40. package/dist/routing/app-router.js.map +1 -1
  41. package/dist/server/app-browser-entry.js +86 -252
  42. package/dist/server/app-browser-entry.js.map +1 -1
  43. package/dist/server/app-browser-error.d.ts +3 -4
  44. package/dist/server/app-browser-error.js +8 -4
  45. package/dist/server/app-browser-error.js.map +1 -1
  46. package/dist/server/app-browser-navigation-controller.d.ts +73 -0
  47. package/dist/server/app-browser-navigation-controller.js +282 -0
  48. package/dist/server/app-browser-navigation-controller.js.map +1 -0
  49. package/dist/server/app-browser-state.d.ts +1 -1
  50. package/dist/server/app-elements.js +1 -5
  51. package/dist/server/app-elements.js.map +1 -1
  52. package/dist/server/app-fallback-renderer.d.ts +57 -0
  53. package/dist/server/app-fallback-renderer.js +79 -0
  54. package/dist/server/app-fallback-renderer.js.map +1 -0
  55. package/dist/server/app-hook-warning-suppression.d.ts +7 -0
  56. package/dist/server/app-hook-warning-suppression.js +12 -0
  57. package/dist/server/app-hook-warning-suppression.js.map +1 -0
  58. package/dist/server/app-mounted-slots-header.d.ts +17 -0
  59. package/dist/server/app-mounted-slots-header.js +21 -0
  60. package/dist/server/app-mounted-slots-header.js.map +1 -0
  61. package/dist/server/app-page-boundary-render.d.ts +2 -2
  62. package/dist/server/app-page-boundary-render.js.map +1 -1
  63. package/dist/server/app-page-cache.d.ts +18 -4
  64. package/dist/server/app-page-cache.js +53 -10
  65. package/dist/server/app-page-cache.js.map +1 -1
  66. package/dist/server/app-page-dispatch.d.ts +7 -4
  67. package/dist/server/app-page-dispatch.js +24 -8
  68. package/dist/server/app-page-dispatch.js.map +1 -1
  69. package/dist/server/app-page-element-builder.d.ts +61 -0
  70. package/dist/server/app-page-element-builder.js +139 -0
  71. package/dist/server/app-page-element-builder.js.map +1 -0
  72. package/dist/server/app-page-params.d.ts +2 -1
  73. package/dist/server/app-page-params.js +3 -3
  74. package/dist/server/app-page-params.js.map +1 -1
  75. package/dist/server/app-page-render.d.ts +5 -1
  76. package/dist/server/app-page-render.js +80 -27
  77. package/dist/server/app-page-render.js.map +1 -1
  78. package/dist/server/app-page-request.d.ts +19 -4
  79. package/dist/server/app-page-request.js +51 -6
  80. package/dist/server/app-page-request.js.map +1 -1
  81. package/dist/server/app-page-response.d.ts +1 -0
  82. package/dist/server/app-page-response.js +3 -7
  83. package/dist/server/app-page-response.js.map +1 -1
  84. package/dist/server/app-page-route-wiring.d.ts +15 -2
  85. package/dist/server/app-page-route-wiring.js.map +1 -1
  86. package/dist/server/app-post-middleware-context.d.ts +16 -0
  87. package/dist/server/app-post-middleware-context.js +28 -0
  88. package/dist/server/app-post-middleware-context.js.map +1 -0
  89. package/dist/server/app-request-context.d.ts +22 -0
  90. package/dist/server/app-request-context.js +30 -0
  91. package/dist/server/app-request-context.js.map +1 -0
  92. package/dist/server/app-route-handler-cache.d.ts +1 -0
  93. package/dist/server/app-route-handler-cache.js +5 -1
  94. package/dist/server/app-route-handler-cache.js.map +1 -1
  95. package/dist/server/app-route-handler-dispatch.d.ts +1 -0
  96. package/dist/server/app-route-handler-dispatch.js +2 -0
  97. package/dist/server/app-route-handler-dispatch.js.map +1 -1
  98. package/dist/server/app-route-handler-execution.d.ts +2 -1
  99. package/dist/server/app-route-handler-execution.js +2 -2
  100. package/dist/server/app-route-handler-execution.js.map +1 -1
  101. package/dist/server/app-route-handler-response.d.ts +4 -2
  102. package/dist/server/app-route-handler-response.js +8 -7
  103. package/dist/server/app-route-handler-response.js.map +1 -1
  104. package/dist/server/app-rsc-error-handler.d.ts +21 -0
  105. package/dist/server/app-rsc-error-handler.js +30 -0
  106. package/dist/server/app-rsc-error-handler.js.map +1 -0
  107. package/dist/server/app-rsc-handler.d.ts +117 -0
  108. package/dist/server/app-rsc-handler.js +260 -0
  109. package/dist/server/app-rsc-handler.js.map +1 -0
  110. package/dist/server/app-rsc-request-normalization.d.ts +40 -0
  111. package/dist/server/app-rsc-request-normalization.js +63 -0
  112. package/dist/server/app-rsc-request-normalization.js.map +1 -0
  113. package/dist/server/app-rsc-response-finalizer.d.ts +30 -0
  114. package/dist/server/app-rsc-response-finalizer.js +38 -0
  115. package/dist/server/app-rsc-response-finalizer.js.map +1 -0
  116. package/dist/server/app-segment-config.d.ts +33 -0
  117. package/dist/server/app-segment-config.js +86 -0
  118. package/dist/server/app-segment-config.js.map +1 -0
  119. package/dist/server/app-server-action-execution.d.ts +2 -0
  120. package/dist/server/app-server-action-execution.js +2 -0
  121. package/dist/server/app-server-action-execution.js.map +1 -1
  122. package/dist/server/cache-control.d.ts +24 -0
  123. package/dist/server/cache-control.js +33 -0
  124. package/dist/server/cache-control.js.map +1 -0
  125. package/dist/server/dev-error-overlay-store.d.ts +23 -0
  126. package/dist/server/dev-error-overlay-store.js +67 -0
  127. package/dist/server/dev-error-overlay-store.js.map +1 -0
  128. package/dist/server/dev-error-overlay.d.ts +15 -0
  129. package/dist/server/dev-error-overlay.js +548 -0
  130. package/dist/server/dev-error-overlay.js.map +1 -0
  131. package/dist/server/instrumentation-runtime.d.ts +44 -0
  132. package/dist/server/instrumentation-runtime.js +29 -0
  133. package/dist/server/instrumentation-runtime.js.map +1 -0
  134. package/dist/server/isr-cache.d.ts +2 -7
  135. package/dist/server/isr-cache.js +7 -10
  136. package/dist/server/isr-cache.js.map +1 -1
  137. package/dist/server/pages-page-data.d.ts +2 -1
  138. package/dist/server/pages-page-data.js +6 -5
  139. package/dist/server/pages-page-data.js.map +1 -1
  140. package/dist/server/pages-page-response.d.ts +2 -1
  141. package/dist/server/pages-page-response.js +3 -2
  142. package/dist/server/pages-page-response.js.map +1 -1
  143. package/dist/server/rsc-stream-hints.d.ts +3 -1
  144. package/dist/server/rsc-stream-hints.js +4 -1
  145. package/dist/server/rsc-stream-hints.js.map +1 -1
  146. package/dist/server/seed-cache.js +19 -8
  147. package/dist/server/seed-cache.js.map +1 -1
  148. package/dist/shims/cache-runtime.js +28 -11
  149. package/dist/shims/cache-runtime.js.map +1 -1
  150. package/dist/shims/cache.d.ts +15 -3
  151. package/dist/shims/cache.js +42 -15
  152. package/dist/shims/cache.js.map +1 -1
  153. package/dist/shims/error-boundary.d.ts +17 -1
  154. package/dist/shims/error-boundary.js +31 -1
  155. package/dist/shims/error-boundary.js.map +1 -1
  156. package/dist/shims/fetch-cache.d.ts +4 -1
  157. package/dist/shims/fetch-cache.js +55 -13
  158. package/dist/shims/fetch-cache.js.map +1 -1
  159. package/dist/shims/image.js +93 -5
  160. package/dist/shims/image.js.map +1 -1
  161. package/dist/shims/request-state-types.d.ts +1 -1
  162. package/dist/shims/unified-request-context.d.ts +1 -1
  163. package/dist/shims/unified-request-context.js +1 -0
  164. package/dist/shims/unified-request-context.js.map +1 -1
  165. package/dist/shims/use-merged-ref.d.ts +7 -0
  166. package/dist/shims/use-merged-ref.js +40 -0
  167. package/dist/shims/use-merged-ref.js.map +1 -0
  168. package/dist/utils/cache-control-metadata.d.ts +6 -0
  169. package/dist/utils/cache-control-metadata.js +16 -0
  170. package/dist/utils/cache-control-metadata.js.map +1 -0
  171. package/package.json +1 -1
@@ -1,9 +1,7 @@
1
- import { compareRoutes, decodeRouteSegment, normalizePathnameForRouteMatch } from "./utils.js";
2
- import { createValidFileMatcher, scanWithExtensions } from "./file-matcher.js";
3
- import { validateRoutePatterns } from "./route-validation.js";
1
+ import { normalizePathnameForRouteMatch } from "./utils.js";
2
+ import { createValidFileMatcher } from "./file-matcher.js";
4
3
  import { buildRouteTrie, trieMatch } from "./route-trie.js";
5
- import fs from "node:fs";
6
- import path from "node:path";
4
+ import { buildAppRouteGraph, computeRootParamNames } from "./app-route-graph.js";
7
5
  //#region src/routing/app-router.ts
8
6
  /**
9
7
  * App Router file-system routing.
@@ -28,13 +26,6 @@ function invalidateAppRouteCache() {
28
26
  cachedAppDir = null;
29
27
  cachedPageExtensionsKey = null;
30
28
  }
31
- function hasParallelSlotDirectory(dir) {
32
- try {
33
- return fs.readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isDirectory() && entry.name.startsWith("@"));
34
- } catch {
35
- return false;
36
- }
37
- }
38
29
  /**
39
30
  * Scan the app/ directory and return a list of routes.
40
31
  */
@@ -42,686 +33,11 @@ async function appRouter(appDir, pageExtensions, matcher) {
42
33
  matcher ??= createValidFileMatcher(pageExtensions);
43
34
  const pageExtensionsKey = JSON.stringify(matcher.extensions);
44
35
  if (cachedRoutes && cachedAppDir === appDir && cachedPageExtensionsKey === pageExtensionsKey) return cachedRoutes;
45
- const routes = [];
46
- const excludeDir = (name) => name.startsWith("@") || name.startsWith("_");
47
- for await (const file of scanWithExtensions("**/page", appDir, matcher.extensions, excludeDir)) {
48
- const route = fileToAppRoute(file, appDir, "page", matcher);
49
- if (route) routes.push(route);
50
- }
51
- for await (const file of scanWithExtensions("**/route", appDir, matcher.extensions, excludeDir)) {
52
- const route = fileToAppRoute(file, appDir, "route", matcher);
53
- if (route) routes.push(route);
54
- }
55
- const routePatterns = new Set(routes.map((route) => route.pattern));
56
- for await (const file of scanWithExtensions("**/layout", appDir, matcher.extensions, excludeDir)) {
57
- const dir = path.dirname(file);
58
- const routeDir = dir === "." ? appDir : path.join(appDir, dir);
59
- if (!hasParallelSlotDirectory(routeDir)) continue;
60
- if (discoverParallelSlots(routeDir, appDir, matcher).length === 0) continue;
61
- const route = directoryToAppRoute(dir, appDir, matcher, null, null);
62
- if (!route || routePatterns.has(route.pattern)) continue;
63
- routes.push(route);
64
- routePatterns.add(route.pattern);
65
- }
66
- const slotSubRoutes = discoverSlotSubRoutes(routes, appDir, matcher);
67
- routes.push(...slotSubRoutes);
68
- validatePageRouteConflicts(routes, appDir);
69
- validateRoutePatterns(routes.map((route) => route.pattern));
70
- validateRoutePatterns([...new Set(routes.flatMap((route) => route.parallelSlots.flatMap((slot) => slot.interceptingRoutes.map((intercept) => intercept.targetPattern))))]);
71
- routes.sort(compareRoutes);
72
- cachedRoutes = routes;
36
+ const graph = await buildAppRouteGraph(appDir, matcher);
37
+ cachedRoutes = graph.routes;
73
38
  cachedAppDir = appDir;
74
39
  cachedPageExtensionsKey = pageExtensionsKey;
75
- return routes;
76
- }
77
- function validatePageRouteConflicts(routes, appDir) {
78
- const byPattern = /* @__PURE__ */ new Map();
79
- for (const route of routes) {
80
- const entry = byPattern.get(route.pattern);
81
- if (!entry) {
82
- byPattern.set(route.pattern, {
83
- pagePath: route.pagePath,
84
- routePath: route.routePath
85
- });
86
- continue;
87
- }
88
- if (!entry.pagePath && route.pagePath) entry.pagePath = route.pagePath;
89
- if (!entry.routePath && route.routePath) entry.routePath = route.routePath;
90
- }
91
- for (const [pattern, entry] of byPattern) {
92
- if (!entry.pagePath || !entry.routePath) continue;
93
- throw new Error(`Conflicting route and page at ${pattern}: route at ${formatAppFilePath(entry.routePath, appDir)} and page at ${formatAppFilePath(entry.pagePath, appDir)}`);
94
- }
95
- }
96
- function formatAppFilePath(filePath, appDir) {
97
- const relativePath = path.relative(appDir, filePath).replace(/\\/g, "/");
98
- const parsedPath = path.parse(relativePath);
99
- const withoutExtension = path.join(parsedPath.dir, parsedPath.name).replace(/\\/g, "/");
100
- return withoutExtension.startsWith("/") ? withoutExtension : `/${withoutExtension}`;
101
- }
102
- /**
103
- * Discover sub-routes created by nested pages within parallel slots.
104
- *
105
- * In Next.js, pages nested inside @slot directories create additional URL routes.
106
- * For example, given:
107
- * app/parallel-routes/@audience/demographics/page.tsx
108
- * This creates a route at /parallel-routes/demographics where:
109
- * - children slot → parent's default.tsx
110
- * - @audience slot → @audience/demographics/page.tsx (matched)
111
- * - other slots → their default.tsx (fallback)
112
- */
113
- function discoverSlotSubRoutes(routes, _appDir, matcher) {
114
- const syntheticRoutes = [];
115
- const routesByPattern = new Map(routes.map((r) => [r.pattern, r]));
116
- const applySlotSubPages = (route, slotPages, rawSegments) => {
117
- route.parallelSlots = route.parallelSlots.map((slot) => {
118
- const subPage = slotPages.get(slot.key);
119
- if (subPage !== void 0) return {
120
- ...slot,
121
- pagePath: subPage,
122
- routeSegments: rawSegments
123
- };
124
- return slot;
125
- });
126
- };
127
- for (const parentRoute of routes) {
128
- if (parentRoute.parallelSlots.length === 0) continue;
129
- if (!parentRoute.pagePath) continue;
130
- const parentPageDir = path.dirname(parentRoute.pagePath);
131
- const subPathMap = /* @__PURE__ */ new Map();
132
- for (const slot of parentRoute.parallelSlots) {
133
- if (path.dirname(slot.ownerDir) !== parentPageDir) continue;
134
- const slotDir = slot.ownerDir;
135
- if (!fs.existsSync(slotDir)) continue;
136
- const subPages = findSlotSubPages(slotDir, matcher);
137
- for (const { relativePath, pagePath } of subPages) {
138
- const subSegments = relativePath.split(path.sep);
139
- const convertedSubRoute = convertSegmentsToRouteParts(subSegments);
140
- if (!convertedSubRoute) continue;
141
- const { urlSegments } = convertedSubRoute;
142
- const normalizedSubPath = urlSegments.join("/");
143
- let subPathEntry = subPathMap.get(normalizedSubPath);
144
- if (!subPathEntry) {
145
- subPathEntry = {
146
- rawSegments: subSegments,
147
- converted: convertedSubRoute,
148
- slotPages: /* @__PURE__ */ new Map()
149
- };
150
- subPathMap.set(normalizedSubPath, subPathEntry);
151
- }
152
- if (subPathEntry.slotPages.get(slot.key)) {
153
- const pattern = joinRoutePattern(parentRoute.pattern, normalizedSubPath);
154
- throw new Error(`You cannot have two routes that resolve to the same path ("${pattern}").`);
155
- }
156
- subPathEntry.slotPages.set(slot.key, pagePath);
157
- }
158
- }
159
- if (subPathMap.size === 0) continue;
160
- const childrenDefault = findFile(parentPageDir, "default", matcher);
161
- if (!childrenDefault) continue;
162
- for (const { rawSegments, converted: convertedSubRoute, slotPages } of subPathMap.values()) {
163
- const { urlSegments: urlParts, params: subParams, isDynamic: subIsDynamic } = convertedSubRoute;
164
- const subUrlPath = urlParts.join("/");
165
- const pattern = joinRoutePattern(parentRoute.pattern, subUrlPath);
166
- const existingRoute = routesByPattern.get(pattern);
167
- if (existingRoute) {
168
- if (existingRoute.routePath && !existingRoute.pagePath) throw new Error(`You cannot have two routes that resolve to the same path ("${pattern}").`);
169
- applySlotSubPages(existingRoute, slotPages, rawSegments);
170
- continue;
171
- }
172
- const subSlots = parentRoute.parallelSlots.map((slot) => {
173
- const subPage = slotPages.get(slot.key);
174
- return {
175
- ...slot,
176
- pagePath: subPage || null,
177
- routeSegments: subPage ? rawSegments : null
178
- };
179
- });
180
- const newRoute = {
181
- pattern,
182
- pagePath: childrenDefault,
183
- routePath: null,
184
- layouts: parentRoute.layouts,
185
- templates: parentRoute.templates,
186
- parallelSlots: subSlots,
187
- loadingPath: parentRoute.loadingPath,
188
- errorPath: parentRoute.errorPath,
189
- layoutErrorPaths: parentRoute.layoutErrorPaths,
190
- notFoundPath: parentRoute.notFoundPath,
191
- notFoundPaths: parentRoute.notFoundPaths,
192
- forbiddenPaths: parentRoute.forbiddenPaths,
193
- forbiddenPath: parentRoute.forbiddenPath,
194
- unauthorizedPath: parentRoute.unauthorizedPath,
195
- unauthorizedPaths: parentRoute.unauthorizedPaths,
196
- routeSegments: [...parentRoute.routeSegments, ...rawSegments],
197
- templateTreePositions: parentRoute.templateTreePositions,
198
- layoutTreePositions: parentRoute.layoutTreePositions,
199
- isDynamic: parentRoute.isDynamic || subIsDynamic,
200
- params: [...parentRoute.params, ...subParams],
201
- rootParamNames: parentRoute.rootParamNames,
202
- patternParts: [...parentRoute.patternParts, ...urlParts]
203
- };
204
- syntheticRoutes.push(newRoute);
205
- routesByPattern.set(pattern, newRoute);
206
- }
207
- }
208
- return syntheticRoutes;
209
- }
210
- /**
211
- * Find all page files in subdirectories of a parallel slot directory.
212
- * Returns relative paths (from the slot dir) and absolute page paths.
213
- * Skips the root page.tsx (already handled as the slot's main page)
214
- * and intercepting route directories.
215
- */
216
- function findSlotSubPages(slotDir, matcher) {
217
- const results = [];
218
- function scan(dir) {
219
- if (!fs.existsSync(dir)) return;
220
- const entries = fs.readdirSync(dir, { withFileTypes: true });
221
- for (const entry of entries) {
222
- if (!entry.isDirectory()) continue;
223
- if (matchInterceptConvention(entry.name)) continue;
224
- if (entry.name.startsWith("_")) continue;
225
- const subDir = path.join(dir, entry.name);
226
- const page = findFile(subDir, "page", matcher);
227
- if (page) {
228
- const relativePath = path.relative(slotDir, subDir);
229
- results.push({
230
- relativePath,
231
- pagePath: page
232
- });
233
- }
234
- scan(subDir);
235
- }
236
- }
237
- scan(slotDir);
238
- return results;
239
- }
240
- /**
241
- * Convert a file path relative to app/ into an AppRoute.
242
- */
243
- function fileToAppRoute(file, appDir, type, matcher) {
244
- return directoryToAppRoute(path.dirname(file), appDir, matcher, type === "page" ? path.join(appDir, file) : null, type === "route" ? path.join(appDir, file) : null);
245
- }
246
- function directoryToAppRoute(dir, appDir, matcher, pagePath, routePath) {
247
- const segments = dir === "." ? [] : dir.split(path.sep);
248
- const params = [];
249
- let isDynamic = false;
250
- const convertedRoute = convertSegmentsToRouteParts(segments);
251
- if (!convertedRoute) return null;
252
- const { urlSegments, params: routeParams, isDynamic: routeIsDynamic } = convertedRoute;
253
- params.push(...routeParams);
254
- isDynamic = routeIsDynamic;
255
- const pattern = "/" + urlSegments.join("/");
256
- const layouts = discoverLayouts(segments, appDir, matcher);
257
- const templates = discoverTemplates(segments, appDir, matcher);
258
- const templateTreePositions = computeLayoutTreePositions(appDir, templates);
259
- const layoutTreePositions = computeLayoutTreePositions(appDir, layouts);
260
- const layoutErrorPaths = discoverLayoutAlignedErrors(segments, appDir, matcher);
261
- const routeDir = dir === "." ? appDir : path.join(appDir, dir);
262
- const loadingPath = findFile(routeDir, "loading", matcher);
263
- const errorPath = findFile(routeDir, "error", matcher);
264
- const notFoundPath = discoverBoundaryFile(segments, appDir, "not-found", matcher);
265
- const forbiddenPath = discoverBoundaryFile(segments, appDir, "forbidden", matcher);
266
- const unauthorizedPath = discoverBoundaryFile(segments, appDir, "unauthorized", matcher);
267
- const notFoundPaths = discoverBoundaryFilePerLayout(layouts, "not-found", matcher);
268
- const forbiddenPaths = discoverBoundaryFilePerLayout(layouts, "forbidden", matcher);
269
- const unauthorizedPaths = discoverBoundaryFilePerLayout(layouts, "unauthorized", matcher);
270
- const parallelSlots = discoverInheritedParallelSlots(segments, appDir, routeDir, matcher);
271
- return {
272
- pattern: pattern === "/" ? "/" : pattern,
273
- pagePath,
274
- routePath,
275
- layouts,
276
- templates,
277
- parallelSlots,
278
- loadingPath,
279
- errorPath,
280
- layoutErrorPaths,
281
- notFoundPath,
282
- notFoundPaths,
283
- forbiddenPaths,
284
- forbiddenPath,
285
- unauthorizedPath,
286
- unauthorizedPaths,
287
- routeSegments: segments,
288
- templateTreePositions,
289
- layoutTreePositions,
290
- isDynamic,
291
- params,
292
- rootParamNames: computeRootParamNames(segments, layoutTreePositions),
293
- patternParts: urlSegments
294
- };
295
- }
296
- function dynamicParamNameFromSegment(segment) {
297
- if (segment.startsWith("[[...") && segment.endsWith("]]")) return segment.slice(5, -2);
298
- if (segment.startsWith("[...") && segment.endsWith("]")) return segment.slice(4, -1);
299
- if (segment.startsWith("[") && segment.endsWith("]")) return segment.slice(1, -1);
300
- return null;
301
- }
302
- function computeRootParamNames(routeSegments, layoutTreePositions) {
303
- const rootLayoutPosition = layoutTreePositions[0];
304
- if (rootLayoutPosition == null || rootLayoutPosition <= 0) return [];
305
- const names = [];
306
- for (const segment of routeSegments.slice(0, rootLayoutPosition)) {
307
- const name = dynamicParamNameFromSegment(segment);
308
- if (name && !names.includes(name)) names.push(name);
309
- }
310
- return names;
311
- }
312
- /**
313
- * Compute the tree position (directory depth from app root) for each layout.
314
- * Root layout = 0, a layout at app/blog/ = 1, app/blog/(group)/ = 2.
315
- * Counts ALL directory levels including route groups and parallel slots.
316
- */
317
- function computeLayoutTreePositions(appDir, layouts) {
318
- return layouts.map((layoutPath) => {
319
- const layoutDir = path.dirname(layoutPath);
320
- if (layoutDir === appDir) return 0;
321
- return path.relative(appDir, layoutDir).split(path.sep).length;
322
- });
323
- }
324
- /**
325
- * Discover all layout files from root to the given directory.
326
- * Each level of the directory tree may have a layout.tsx.
327
- */
328
- function discoverLayouts(segments, appDir, matcher) {
329
- const layouts = [];
330
- const rootLayout = findFile(appDir, "layout", matcher);
331
- if (rootLayout) layouts.push(rootLayout);
332
- let currentDir = appDir;
333
- for (const segment of segments) {
334
- currentDir = path.join(currentDir, segment);
335
- const layout = findFile(currentDir, "layout", matcher);
336
- if (layout) layouts.push(layout);
337
- }
338
- return layouts;
339
- }
340
- /**
341
- * Discover all template files from root to the given directory.
342
- * Each level of the directory tree may have a template.tsx.
343
- * Templates are like layouts but re-mount on navigation.
344
- */
345
- function discoverTemplates(segments, appDir, matcher) {
346
- const templates = [];
347
- const rootTemplate = findFile(appDir, "template", matcher);
348
- if (rootTemplate) templates.push(rootTemplate);
349
- let currentDir = appDir;
350
- for (const segment of segments) {
351
- currentDir = path.join(currentDir, segment);
352
- const template = findFile(currentDir, "template", matcher);
353
- if (template) templates.push(template);
354
- }
355
- return templates;
356
- }
357
- /**
358
- * Discover error.tsx files aligned with the layouts array.
359
- * Walks the same directory levels as discoverLayouts and, for each level
360
- * that contributes a layout entry, checks whether error.tsx also exists.
361
- * Returns an array of the same length as discoverLayouts() would return,
362
- * with the error path (or null) at each corresponding layout level.
363
- *
364
- * This enables interleaving ErrorBoundary components with layouts in the
365
- * rendering tree, matching Next.js behavior where each segment independently
366
- * wraps its children with an error boundary.
367
- */
368
- function discoverLayoutAlignedErrors(segments, appDir, matcher) {
369
- const errors = [];
370
- if (findFile(appDir, "layout", matcher)) errors.push(findFile(appDir, "error", matcher));
371
- let currentDir = appDir;
372
- for (const segment of segments) {
373
- currentDir = path.join(currentDir, segment);
374
- if (findFile(currentDir, "layout", matcher)) errors.push(findFile(currentDir, "error", matcher));
375
- }
376
- return errors;
377
- }
378
- /**
379
- * Discover the nearest boundary file (not-found, forbidden, unauthorized)
380
- * by walking from the route's directory up to the app root.
381
- * Returns the first (closest) file found, or null.
382
- */
383
- function discoverBoundaryFile(segments, appDir, fileName, matcher) {
384
- const dirs = [];
385
- let dir = appDir;
386
- dirs.push(dir);
387
- for (const segment of segments) {
388
- dir = path.join(dir, segment);
389
- dirs.push(dir);
390
- }
391
- for (let i = dirs.length - 1; i >= 0; i--) {
392
- const f = findFile(dirs[i], fileName, matcher);
393
- if (f) return f;
394
- }
395
- return null;
396
- }
397
- /**
398
- * Discover boundary files (not-found, forbidden, unauthorized) at each layout directory.
399
- * Returns an array aligned with the layouts array, where each entry is the boundary
400
- * file at that layout's directory, or null if none exists there.
401
- *
402
- * This is used for per-layout error boundaries. In Next.js, each layout level
403
- * has its own boundary that wraps the layout's children. When notFound() is thrown
404
- * from a layout, it propagates up to the parent layout's boundary.
405
- */
406
- function discoverBoundaryFilePerLayout(layouts, fileName, matcher) {
407
- return layouts.map((layoutPath) => {
408
- return findFile(path.dirname(layoutPath), fileName, matcher);
409
- });
410
- }
411
- /**
412
- * Discover parallel slots inherited from ancestor directories.
413
- *
414
- * In Next.js, parallel slots belong to the layout that defines them. When a
415
- * child route is rendered, its parent layout's slots must still be present.
416
- * If the child doesn't have matching content in a slot, the slot's default.tsx
417
- * is rendered instead.
418
- *
419
- * Walk from appDir through each segment to the route's directory. At each level
420
- * that has @slot dirs, collect them. Slots at the route's own directory level
421
- * use page.tsx; slots at ancestor levels use default.tsx only.
422
- */
423
- function discoverInheritedParallelSlots(segments, appDir, routeDir, matcher) {
424
- const slotMap = /* @__PURE__ */ new Map();
425
- let currentDir = appDir;
426
- const dirsToCheck = [];
427
- let layoutIdx = findFile(appDir, "layout", matcher) ? 0 : -1;
428
- dirsToCheck.push({
429
- dir: appDir,
430
- layoutIdx
431
- });
432
- for (const segment of segments) {
433
- currentDir = path.join(currentDir, segment);
434
- if (findFile(currentDir, "layout", matcher)) layoutIdx++;
435
- dirsToCheck.push({
436
- dir: currentDir,
437
- layoutIdx
438
- });
439
- }
440
- const routeHasLayout = layoutIdx >= 0;
441
- for (const { dir, layoutIdx: lvlLayoutIdx } of dirsToCheck) {
442
- if (lvlLayoutIdx < 0 && routeHasLayout) continue;
443
- const isOwnDir = dir === routeDir;
444
- const slotLayoutIdx = Math.max(lvlLayoutIdx, 0);
445
- const slotsAtLevel = discoverParallelSlots(dir, appDir, matcher);
446
- for (const slot of slotsAtLevel) if (isOwnDir) {
447
- slot.layoutIndex = slotLayoutIdx;
448
- slotMap.set(slot.key, slot);
449
- } else {
450
- const inheritedSlot = {
451
- ...slot,
452
- pagePath: null,
453
- layoutIndex: slotLayoutIdx,
454
- routeSegments: null
455
- };
456
- slotMap.set(slot.key, inheritedSlot);
457
- }
458
- }
459
- return Array.from(slotMap.values());
460
- }
461
- /**
462
- * Discover parallel route slots (@team, @analytics, etc.) in a directory.
463
- * Returns a ParallelSlot for each @-prefixed subdirectory that has a page or default component.
464
- */
465
- function discoverParallelSlots(dir, appDir, matcher) {
466
- if (!fs.existsSync(dir)) return [];
467
- const entries = fs.readdirSync(dir, { withFileTypes: true });
468
- const slots = [];
469
- for (const entry of entries) {
470
- if (!entry.isDirectory() || !entry.name.startsWith("@")) continue;
471
- const slotName = entry.name.slice(1);
472
- const slotDir = path.join(dir, entry.name);
473
- const pagePath = findFile(slotDir, "page", matcher);
474
- const defaultPath = findFile(slotDir, "default", matcher);
475
- const interceptingRoutes = discoverInterceptingRoutes(slotDir, dir, appDir, matcher);
476
- if (!pagePath && !defaultPath && interceptingRoutes.length === 0) continue;
477
- slots.push({
478
- key: `${slotName}@${path.relative(appDir, slotDir).replace(/\\/g, "/")}`,
479
- name: slotName,
480
- ownerDir: slotDir,
481
- pagePath,
482
- defaultPath,
483
- layoutPath: findFile(slotDir, "layout", matcher),
484
- loadingPath: findFile(slotDir, "loading", matcher),
485
- errorPath: findFile(slotDir, "error", matcher),
486
- interceptingRoutes,
487
- layoutIndex: -1,
488
- routeSegments: pagePath ? [] : null
489
- });
490
- }
491
- return slots;
492
- }
493
- /**
494
- * The interception convention prefix patterns.
495
- * (.) — same level, (..) — one level up, (..)(..)" — two levels up, (...) — root
496
- */
497
- const INTERCEPT_PATTERNS = [
498
- {
499
- prefix: "(...)",
500
- convention: "..."
501
- },
502
- {
503
- prefix: "(..)(..)",
504
- convention: "../.."
505
- },
506
- {
507
- prefix: "(..)",
508
- convention: ".."
509
- },
510
- {
511
- prefix: "(.)",
512
- convention: "."
513
- }
514
- ];
515
- /**
516
- * Discover intercepting routes inside a parallel slot directory.
517
- *
518
- * Intercepting routes use conventions like (.)photo, (..)feed, (...), etc.
519
- * They intercept navigation to another route and render within the slot instead.
520
- *
521
- * @param slotDir - The parallel slot directory (e.g. app/feed/@modal)
522
- * @param routeDir - The directory of the route that owns this slot (e.g. app/feed)
523
- * @param appDir - The root app directory
524
- */
525
- function discoverInterceptingRoutes(slotDir, routeDir, appDir, matcher) {
526
- if (!fs.existsSync(slotDir)) return [];
527
- const results = [];
528
- scanForInterceptingPages(slotDir, routeDir, appDir, results, matcher);
529
- return results;
530
- }
531
- /**
532
- * Recursively scan a directory tree for page.tsx files that are inside
533
- * intercepting route directories.
534
- */
535
- function scanForInterceptingPages(currentDir, routeDir, appDir, results, matcher) {
536
- if (!fs.existsSync(currentDir)) return;
537
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
538
- for (const entry of entries) {
539
- if (!entry.isDirectory()) continue;
540
- if (entry.name.startsWith("_")) continue;
541
- const interceptMatch = matchInterceptConvention(entry.name);
542
- if (interceptMatch) {
543
- const restOfName = entry.name.slice(interceptMatch.prefix.length);
544
- const interceptDir = path.join(currentDir, entry.name);
545
- collectInterceptingPages(interceptDir, interceptDir, interceptMatch.convention, restOfName, routeDir, appDir, results, matcher);
546
- } else scanForInterceptingPages(path.join(currentDir, entry.name), routeDir, appDir, results, matcher);
547
- }
548
- }
549
- /**
550
- * Match a directory name against interception convention prefixes.
551
- */
552
- function matchInterceptConvention(name) {
553
- for (const pattern of INTERCEPT_PATTERNS) if (name.startsWith(pattern.prefix)) return pattern;
554
- return null;
555
- }
556
- /**
557
- * Collect page.tsx files inside an intercepting route directory tree
558
- * and compute their target URL patterns.
559
- */
560
- function collectInterceptingPages(currentDir, interceptRoot, convention, interceptSegment, routeDir, appDir, results, matcher, parentLayoutPaths = []) {
561
- const currentLayoutPath = findFile(currentDir, "layout", matcher);
562
- const layoutPaths = currentLayoutPath ? [...parentLayoutPaths, currentLayoutPath] : parentLayoutPaths;
563
- const page = findFile(currentDir, "page", matcher);
564
- if (page) {
565
- const targetPattern = computeInterceptTarget(convention, interceptSegment, currentDir, interceptRoot, routeDir, appDir);
566
- if (targetPattern) results.push({
567
- convention,
568
- layoutPaths: [...layoutPaths],
569
- targetPattern: targetPattern.pattern,
570
- pagePath: page,
571
- params: targetPattern.params
572
- });
573
- }
574
- if (!fs.existsSync(currentDir)) return;
575
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
576
- for (const entry of entries) {
577
- if (!entry.isDirectory()) continue;
578
- if (entry.name.startsWith("_")) continue;
579
- collectInterceptingPages(path.join(currentDir, entry.name), interceptRoot, convention, interceptSegment, routeDir, appDir, results, matcher, layoutPaths);
580
- }
581
- }
582
- /**
583
- * Check whether a path segment is invisible in the URL (route groups, parallel slots, ".").
584
- *
585
- * Used by computeInterceptTarget, convertSegmentsToRouteParts, and
586
- * hasRemainingVisibleSegments — keep this the single source of truth.
587
- */
588
- function isInvisibleSegment(segment) {
589
- if (segment === ".") return true;
590
- if (segment.startsWith("(") && segment.endsWith(")")) return true;
591
- if (segment.startsWith("@")) return true;
592
- return false;
593
- }
594
- /**
595
- * Compute the target URL pattern for an intercepting route.
596
- *
597
- * Interception conventions (..), (..)(..)" climb by *visible route segments*
598
- * (not filesystem directories). Route groups like (marketing) and parallel
599
- * slots like @modal are invisible and must be skipped when counting levels.
600
- *
601
- * - (.) same level: resolve relative to routeDir
602
- * - (..) one level up: climb 1 visible segment
603
- * - (..)(..) two levels up: climb 2 visible segments
604
- * - (...) root: resolve from appDir
605
- */
606
- function computeInterceptTarget(convention, interceptSegment, currentDir, interceptRoot, routeDir, appDir) {
607
- const routeSegments = path.relative(appDir, routeDir).split(path.sep).filter(Boolean);
608
- let baseParts;
609
- switch (convention) {
610
- case ".":
611
- baseParts = routeSegments;
612
- break;
613
- case "..":
614
- case "../..": {
615
- const levelsToClimb = convention === ".." ? 1 : 2;
616
- let climbed = 0;
617
- let cutIndex = routeSegments.length;
618
- while (cutIndex > 0 && climbed < levelsToClimb) {
619
- cutIndex--;
620
- if (!isInvisibleSegment(routeSegments[cutIndex])) climbed++;
621
- }
622
- if (climbed < levelsToClimb) {
623
- const interceptionRoute = formatInterceptionRoutePath(routeSegments, convention, interceptSegment, path.relative(interceptRoot, currentDir).split(path.sep).filter(Boolean));
624
- if (convention === "..") throw new Error(`Invalid interception route: ${interceptionRoute}. Cannot use (..) marker at the root level, use (.) instead.`);
625
- throw new Error(`Invalid interception route: ${interceptionRoute}. Cannot use (..)(..) marker at the root level or one level up.`);
626
- }
627
- baseParts = routeSegments.slice(0, cutIndex);
628
- break;
629
- }
630
- case "...":
631
- baseParts = [];
632
- break;
633
- default: return null;
634
- }
635
- const nestedParts = path.relative(interceptRoot, currentDir).split(path.sep).filter(Boolean);
636
- const convertedTarget = convertSegmentsToRouteParts([
637
- ...baseParts,
638
- interceptSegment,
639
- ...nestedParts
640
- ]);
641
- if (!convertedTarget) return null;
642
- const { urlSegments, params } = convertedTarget;
643
- const pattern = "/" + urlSegments.join("/");
644
- return {
645
- pattern: pattern === "/" ? "/" : pattern,
646
- params
647
- };
648
- }
649
- function formatInterceptionRoutePath(routeSegments, convention, interceptSegment, nestedParts) {
650
- const marker = markerForInterceptionConvention(convention);
651
- const convertedRoute = convertSegmentsToRouteParts(routeSegments);
652
- const routePath = [
653
- ...convertedRoute ? convertedRoute.urlSegments : routeSegments.filter((segment) => !isInvisibleSegment(segment)),
654
- `${marker}${interceptSegment}`,
655
- ...nestedParts
656
- ].filter(Boolean).join("/");
657
- return routePath ? `/${routePath}` : "/";
658
- }
659
- function markerForInterceptionConvention(convention) {
660
- switch (convention) {
661
- case ".": return "(.)";
662
- case "..": return "(..)";
663
- case "../..": return "(..)(..)";
664
- case "...": return "(...)";
665
- default: return "";
666
- }
667
- }
668
- /**
669
- * Find a file by name (without extension) in a directory.
670
- * Checks configured pageExtensions.
671
- */
672
- function findFile(dir, name, matcher) {
673
- for (const ext of matcher.dottedExtensions) {
674
- const filePath = path.join(dir, name + ext);
675
- if (fs.existsSync(filePath)) return filePath;
676
- }
677
- return null;
678
- }
679
- /**
680
- * Convert filesystem path segments to URL route parts, skipping invisible segments
681
- * (route groups, @slots, ".") and converting dynamic segment syntax to Express-style
682
- * patterns (e.g. "[id]" → ":id", "[...slug]" → ":slug+").
683
- */
684
- function convertSegmentsToRouteParts(segments) {
685
- const urlSegments = [];
686
- const params = [];
687
- let isDynamic = false;
688
- for (let i = 0; i < segments.length; i++) {
689
- const segment = segments[i];
690
- if (isInvisibleSegment(segment)) continue;
691
- const catchAllMatch = segment.match(/^\[\.\.\.([\w-]+)\]$/);
692
- if (catchAllMatch) {
693
- if (hasRemainingVisibleSegments(segments, i + 1)) return null;
694
- isDynamic = true;
695
- params.push(catchAllMatch[1]);
696
- urlSegments.push(`:${catchAllMatch[1]}+`);
697
- continue;
698
- }
699
- const optionalCatchAllMatch = segment.match(/^\[\[\.\.\.([\w-]+)\]\]$/);
700
- if (optionalCatchAllMatch) {
701
- if (hasRemainingVisibleSegments(segments, i + 1)) return null;
702
- isDynamic = true;
703
- params.push(optionalCatchAllMatch[1]);
704
- urlSegments.push(`:${optionalCatchAllMatch[1]}*`);
705
- continue;
706
- }
707
- const dynamicMatch = segment.match(/^\[([\w-]+)\]$/);
708
- if (dynamicMatch) {
709
- isDynamic = true;
710
- params.push(dynamicMatch[1]);
711
- urlSegments.push(`:${dynamicMatch[1]}`);
712
- continue;
713
- }
714
- urlSegments.push(decodeRouteSegment(segment));
715
- }
716
- return {
717
- urlSegments,
718
- params,
719
- isDynamic
720
- };
721
- }
722
- function hasRemainingVisibleSegments(segments, startIndex) {
723
- for (let i = startIndex; i < segments.length; i++) if (!isInvisibleSegment(segments[i])) return true;
724
- return false;
40
+ return graph.routes;
725
41
  }
726
42
  const appTrieCache = /* @__PURE__ */ new WeakMap();
727
43
  function getOrBuildAppTrie(routes) {
@@ -732,10 +48,6 @@ function getOrBuildAppTrie(routes) {
732
48
  }
733
49
  return trie;
734
50
  }
735
- function joinRoutePattern(basePattern, subPath) {
736
- if (!subPath) return basePattern;
737
- return basePattern === "/" ? `/${subPath}` : `${basePattern}/${subPath}`;
738
- }
739
51
  /**
740
52
  * Match a URL against App Router routes.
741
53
  */