@rangojs/router 0.31.0 → 0.33.0

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 (192) hide show
  1. package/README.md +3 -2
  2. package/dist/bin/browser-7KIJ5HSV.js +15 -0
  3. package/dist/bin/chunk-3B7CKBRO.js +463 -0
  4. package/dist/bin/chunk-524VACCG.js +71 -0
  5. package/dist/bin/chunk-LD7UBHT4.js +196 -0
  6. package/dist/bin/chunk-TO6CRWLN.js +1429 -0
  7. package/dist/bin/chunk-TTXC2U3G.js +2477 -0
  8. package/dist/bin/client-urls-projection-DQLWPDAT.js +28 -0
  9. package/dist/bin/forward-user-plugins-URBZKJP4.js +62 -0
  10. package/dist/bin/rango.js +42 -10143
  11. package/dist/bin/runtime-EPUDEHO4.js +596 -0
  12. package/dist/bin/runtime-discovery-CZ2QHT4Q.js +352 -0
  13. package/dist/bin/state-ACD2MGKJ.js +16 -0
  14. package/dist/bin/temp-rsc-server-QRR6HD6T.js +3190 -0
  15. package/dist/types/bin/rango.d.ts +1 -0
  16. package/dist/types/browser/action-fence.d.ts +20 -0
  17. package/dist/types/browser/cookie-name.d.ts +51 -10
  18. package/dist/types/browser/history-state.d.ts +13 -2
  19. package/dist/types/browser/invalidate-client-cache.d.ts +8 -6
  20. package/dist/types/browser/navigation-bridge.d.ts +36 -1
  21. package/dist/types/browser/navigation-client.d.ts +19 -0
  22. package/dist/types/browser/navigation-store-handle.d.ts +37 -4
  23. package/dist/types/browser/navigation-store.d.ts +2 -2
  24. package/dist/types/browser/navigation-transaction.d.ts +0 -1
  25. package/dist/types/browser/partial-update.d.ts +13 -0
  26. package/dist/types/browser/prefetch/cache.d.ts +96 -8
  27. package/dist/types/browser/prefetch/fetch.d.ts +26 -2
  28. package/dist/types/browser/prefetch/queue.d.ts +3 -2
  29. package/dist/types/browser/rango-state.d.ts +34 -5
  30. package/dist/types/browser/react/Link.d.ts +19 -13
  31. package/dist/types/browser/react/location-state-shared.d.ts +2 -1
  32. package/dist/types/browser/types.d.ts +25 -0
  33. package/dist/types/build/generate-route-types.d.ts +1 -1
  34. package/dist/types/build/route-types/include-resolution.d.ts +9 -1
  35. package/dist/types/build/route-types/router-processing.d.ts +3 -1
  36. package/dist/types/cache/cache-key-utils.d.ts +12 -8
  37. package/dist/types/cache/cache-scope.d.ts +4 -2
  38. package/dist/types/cache/cf/cf-cache-types.d.ts +9 -5
  39. package/dist/types/cache/document-cache-policy.d.ts +9 -1
  40. package/dist/types/cache/memory-segment-store.d.ts +3 -2
  41. package/dist/types/cache/segment-codec.d.ts +2 -2
  42. package/dist/types/cache/shell-snapshot.d.ts +1 -1
  43. package/dist/types/cache/types.d.ts +12 -7
  44. package/dist/types/cache/vercel/vercel-cache-store.d.ts +2 -1
  45. package/dist/types/client-urls/types.d.ts +7 -5
  46. package/dist/types/prefetch-markers.d.ts +9 -0
  47. package/dist/types/prefetch-source-scope.d.ts +66 -0
  48. package/dist/types/route-definition/helpers-types.d.ts +8 -5
  49. package/dist/types/route-definition/redirect.d.ts +5 -0
  50. package/dist/types/router/intercept-resolution.d.ts +25 -11
  51. package/dist/types/router/match-context.d.ts +1 -0
  52. package/dist/types/router/match-handlers.d.ts +1 -1
  53. package/dist/types/router/middleware-types.d.ts +6 -0
  54. package/dist/types/router/prefetch-cache-ttl.d.ts +11 -3
  55. package/dist/types/router/router-context.d.ts +1 -1
  56. package/dist/types/router/router-options.d.ts +6 -3
  57. package/dist/types/router/segment-resolution/loader-cache.d.ts +8 -0
  58. package/dist/types/router/segment-resolution/prefetch-deferral.d.ts +23 -7
  59. package/dist/types/router/segment-resolution/revalidation.d.ts +19 -0
  60. package/dist/types/router/source-reads.d.ts +53 -0
  61. package/dist/types/router/types.d.ts +1 -1
  62. package/dist/types/rsc/helpers.d.ts +8 -3
  63. package/dist/types/rsc/prefetch-render-error.d.ts +7 -2
  64. package/dist/types/rsc/request-stages.d.ts +4 -0
  65. package/dist/types/rsc/shell-serve.d.ts +6 -1
  66. package/dist/types/server/context.d.ts +23 -6
  67. package/dist/types/server/cookie-store.d.ts +15 -1
  68. package/dist/types/server/document-location-state.d.ts +59 -0
  69. package/dist/types/server/handle-store.d.ts +2 -0
  70. package/dist/types/server/request-context.d.ts +65 -12
  71. package/dist/types/testing/e2e/server.d.ts +16 -1
  72. package/dist/types/testing/render-route.d.ts +83 -2
  73. package/dist/types/testing/serve-shell-request.d.ts +15 -3
  74. package/dist/types/types/handler-context.d.ts +21 -4
  75. package/dist/types/types/loader-types.d.ts +7 -4
  76. package/dist/types/types/segments.d.ts +18 -1
  77. package/dist/types/urls/path-helper-types.d.ts +7 -5
  78. package/dist/types/vite/temp-rsc-server.d.ts +2 -2
  79. package/dist/types/vite/utils/forward-user-plugins.d.ts +32 -2
  80. package/dist/vite/index.js +451 -191
  81. package/package.json +2 -2
  82. package/skills/app-structure/SKILL.md +74 -0
  83. package/skills/app-structure/e-commerce.md +10 -9
  84. package/skills/app-structure/large-app.md +15 -2
  85. package/skills/caching/SKILL.md +10 -5
  86. package/skills/client-urls/SKILL.md +18 -11
  87. package/skills/comparison/references/framework-comparison.md +16 -10
  88. package/skills/document-cache/SKILL.md +13 -0
  89. package/skills/hooks/navigation.md +8 -8
  90. package/skills/hooks/state.md +132 -12
  91. package/skills/intercept/SKILL.md +33 -11
  92. package/skills/layout/SKILL.md +11 -0
  93. package/skills/links/SKILL.md +101 -4
  94. package/skills/loader/SKILL.md +49 -22
  95. package/skills/migrate-nextjs/SKILL.md +8 -2
  96. package/skills/migrate-react-router/data-and-actions.md +5 -0
  97. package/skills/ppr/SKILL.md +38 -5
  98. package/skills/prerender/SKILL.md +4 -1
  99. package/skills/route/SKILL.md +6 -6
  100. package/skills/router-setup/SKILL.md +2 -1
  101. package/skills/server-actions/SKILL.md +49 -8
  102. package/skills/testing/client-components.md +73 -32
  103. package/skills/testing/serve-shell-request.md +45 -20
  104. package/skills/testing/server-actions.md +8 -0
  105. package/skills/ux-architecture/SKILL.md +67 -15
  106. package/src/bin/rango.ts +39 -13
  107. package/src/browser/action-fence.ts +72 -0
  108. package/src/browser/cookie-name.ts +82 -14
  109. package/src/browser/history-state.ts +24 -2
  110. package/src/browser/invalidate-client-cache.ts +9 -7
  111. package/src/browser/navigation-bridge.ts +164 -32
  112. package/src/browser/navigation-client.ts +95 -20
  113. package/src/browser/navigation-store-handle.ts +67 -5
  114. package/src/browser/navigation-store.ts +86 -17
  115. package/src/browser/navigation-transaction.ts +0 -6
  116. package/src/browser/partial-update.ts +31 -12
  117. package/src/browser/prefetch/cache.ts +188 -11
  118. package/src/browser/prefetch/fetch.ts +211 -51
  119. package/src/browser/prefetch/queue.ts +3 -2
  120. package/src/browser/rango-state.ts +50 -8
  121. package/src/browser/react/Link.tsx +24 -16
  122. package/src/browser/react/location-state-shared.ts +8 -1
  123. package/src/browser/react/use-navigation.ts +1 -1
  124. package/src/browser/rsc-router.tsx +13 -3
  125. package/src/browser/server-action-bridge.ts +3 -3
  126. package/src/browser/types.ts +25 -0
  127. package/src/build/generate-route-types.ts +1 -0
  128. package/src/build/route-types/include-resolution.ts +40 -3
  129. package/src/build/route-types/router-processing.ts +170 -25
  130. package/src/build/route-types/scan-filter.ts +1 -0
  131. package/src/build/runtime-discovery.ts +46 -8
  132. package/src/cache/cache-key-utils.ts +12 -8
  133. package/src/cache/cache-runtime.ts +5 -1
  134. package/src/cache/cache-scope.ts +28 -7
  135. package/src/cache/cf/cf-cache-types.ts +9 -5
  136. package/src/cache/document-cache-policy.ts +37 -1
  137. package/src/cache/document-cache.ts +12 -0
  138. package/src/cache/memory-segment-store.ts +3 -2
  139. package/src/cache/segment-codec.ts +2 -2
  140. package/src/cache/shell-snapshot.ts +1 -1
  141. package/src/cache/types.ts +12 -7
  142. package/src/cache/vercel/vercel-cache-store.ts +2 -1
  143. package/src/client-urls/types.ts +7 -5
  144. package/src/prefetch-markers.ts +10 -0
  145. package/src/prefetch-source-scope.ts +137 -0
  146. package/src/route-definition/helpers-types.ts +8 -5
  147. package/src/route-definition/redirect.ts +5 -0
  148. package/src/router/intercept-resolution.ts +94 -50
  149. package/src/router/loader-resolution.ts +8 -6
  150. package/src/router/match-api.ts +33 -29
  151. package/src/router/match-context.ts +5 -0
  152. package/src/router/match-handlers.ts +2 -1
  153. package/src/router/match-middleware/cache-lookup.ts +39 -14
  154. package/src/router/match-result.ts +45 -85
  155. package/src/router/middleware-types.ts +6 -0
  156. package/src/router/navigation-snapshot.ts +18 -3
  157. package/src/router/prefetch-cache-ttl.ts +15 -3
  158. package/src/router/revalidation.ts +63 -13
  159. package/src/router/router-context.ts +2 -1
  160. package/src/router/router-options.ts +6 -3
  161. package/src/router/segment-resolution/loader-cache.ts +21 -3
  162. package/src/router/segment-resolution/prefetch-deferral.ts +38 -31
  163. package/src/router/segment-resolution/revalidation.ts +40 -12
  164. package/src/router/source-reads.ts +122 -0
  165. package/src/router/types.ts +2 -1
  166. package/src/router.ts +11 -12
  167. package/src/rsc/helpers.ts +20 -6
  168. package/src/rsc/prefetch-render-error.ts +7 -2
  169. package/src/rsc/progressive-enhancement.ts +8 -2
  170. package/src/rsc/request-stages.ts +87 -1
  171. package/src/rsc/rsc-rendering.ts +78 -32
  172. package/src/rsc/server-action.ts +2 -1
  173. package/src/rsc/shell-capture.ts +4 -5
  174. package/src/rsc/shell-serve.ts +12 -1
  175. package/src/segment-system.tsx +1 -1
  176. package/src/server/context.ts +37 -6
  177. package/src/server/cookie-store.ts +22 -1
  178. package/src/server/document-location-state.ts +334 -0
  179. package/src/server/handle-store.ts +2 -0
  180. package/src/server/request-context.ts +137 -33
  181. package/src/testing/dispatch.ts +6 -0
  182. package/src/testing/e2e/fixture.ts +4 -12
  183. package/src/testing/e2e/server.ts +91 -4
  184. package/src/testing/render-route.tsx +309 -10
  185. package/src/testing/run-revalidate.ts +11 -1
  186. package/src/testing/serve-shell-request.ts +22 -3
  187. package/src/types/handler-context.ts +21 -4
  188. package/src/types/loader-types.ts +7 -4
  189. package/src/types/segments.ts +18 -1
  190. package/src/urls/path-helper-types.ts +7 -5
  191. package/src/vite/temp-rsc-server.ts +2 -2
  192. package/src/vite/utils/forward-user-plugins.ts +13 -5
@@ -0,0 +1,196 @@
1
+ // src/route-name.ts
2
+ var AUTO_GENERATED_ROUTE_PREFIX = "$path_";
3
+ var INTERNAL_INCLUDE_SCOPE_PREFIX = "$prefix_";
4
+ function isAutoGeneratedRouteName(name) {
5
+ return name.split(".").some((segment) => {
6
+ return segment.startsWith(AUTO_GENERATED_ROUTE_PREFIX) || segment.startsWith(INTERNAL_INCLUDE_SCOPE_PREFIX);
7
+ });
8
+ }
9
+
10
+ // src/build/route-types/scan-filter.ts
11
+ import { isAbsolute, join, relative } from "node:path";
12
+ import { readdirSync } from "node:fs";
13
+ import picomatch from "picomatch";
14
+ function isUniversallySkippedScanDir(name) {
15
+ return name === "node_modules" || name === "dist" || name === "coverage" || name.startsWith(".");
16
+ }
17
+ function isSkippedSourceScanDir(name) {
18
+ return isUniversallySkippedScanDir(name) || name === "build";
19
+ }
20
+ function findTsFiles(dir, filter) {
21
+ const results = [];
22
+ let entries;
23
+ try {
24
+ entries = readdirSync(dir, { withFileTypes: true });
25
+ } catch (err) {
26
+ console.warn(
27
+ `[rango] Failed to scan directory ${dir}: ${err.message}`
28
+ );
29
+ return results;
30
+ }
31
+ for (const entry of entries) {
32
+ const fullPath = join(dir, entry.name);
33
+ if (entry.isDirectory()) {
34
+ if (isSkippedSourceScanDir(entry.name)) continue;
35
+ results.push(...findTsFiles(fullPath, filter));
36
+ } else if ((entry.name.endsWith(".ts") || entry.name.endsWith(".tsx") || entry.name.endsWith(".js") || entry.name.endsWith(".jsx")) && !entry.name.includes(".gen.")) {
37
+ if (filter && !filter(fullPath)) continue;
38
+ results.push(fullPath);
39
+ }
40
+ }
41
+ return results;
42
+ }
43
+
44
+ // src/build/route-types/source-scan.ts
45
+ function isLineTerminator(ch) {
46
+ const c = ch.charCodeAt(0);
47
+ return c === 10 || c === 13 || c === 8232 || c === 8233;
48
+ }
49
+ var REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
50
+ "return",
51
+ "typeof",
52
+ "instanceof",
53
+ "in",
54
+ "of",
55
+ "new",
56
+ "delete",
57
+ "void",
58
+ "do",
59
+ "else",
60
+ "yield",
61
+ "await",
62
+ "case",
63
+ "throw"
64
+ ]);
65
+ function isRegexPositionAt(code, slashPos, prevChar) {
66
+ if (prevChar === void 0) return true;
67
+ if (prevChar === ")" || prevChar === "]" || prevChar === "}") return false;
68
+ if (!/[\w$]/.test(prevChar)) return true;
69
+ let k = slashPos - 1;
70
+ while (k >= 0 && /\s/.test(code[k])) k--;
71
+ const wordEnd = k + 1;
72
+ while (k >= 0 && /[\w$]/.test(code[k])) k--;
73
+ return REGEX_PRECEDING_KEYWORDS.has(code.slice(k + 1, wordEnd));
74
+ }
75
+ function makeCodeClassifier(code) {
76
+ const n = code.length;
77
+ let i = 0;
78
+ let skipStart = -1;
79
+ let skipEnd = -1;
80
+ let lastSig;
81
+ return (q) => {
82
+ if (q >= skipStart && q < skipEnd) return false;
83
+ while (i < n && i <= q) {
84
+ const c = code[i];
85
+ const d = i + 1 < n ? code[i + 1] : "";
86
+ let end = -1;
87
+ let transparent = false;
88
+ if (c === "/" && d === "/") {
89
+ let j = i + 2;
90
+ while (j < n && !isLineTerminator(code[j])) j++;
91
+ end = j;
92
+ transparent = true;
93
+ } else if (c === "/" && d === "*") {
94
+ let j = i + 2;
95
+ while (j < n && !(code[j] === "*" && code[j + 1] === "/")) j++;
96
+ end = Math.min(n, j + 2);
97
+ transparent = true;
98
+ } else if (c === '"' || c === "'" || c === "`") {
99
+ let j = i + 1;
100
+ while (j < n) {
101
+ if (code[j] === "\\") {
102
+ j += 2;
103
+ continue;
104
+ }
105
+ if (code[j] === c) {
106
+ j++;
107
+ break;
108
+ }
109
+ j++;
110
+ }
111
+ end = j;
112
+ } else if (c === "/" && d !== "/" && d !== "*" && isRegexPositionAt(code, i, lastSig)) {
113
+ let j = i + 1;
114
+ let inClass = false;
115
+ let closed = false;
116
+ while (j < n && !isLineTerminator(code[j])) {
117
+ const r = code[j];
118
+ if (r === "\\") {
119
+ j += 2;
120
+ continue;
121
+ }
122
+ if (r === "[") inClass = true;
123
+ else if (r === "]") inClass = false;
124
+ else if (r === "/" && !inClass) {
125
+ j++;
126
+ closed = true;
127
+ break;
128
+ }
129
+ j++;
130
+ }
131
+ if (closed) {
132
+ while (j < n && /[a-z]/.test(code[j])) j++;
133
+ end = j;
134
+ }
135
+ }
136
+ if (end >= 0) {
137
+ if (q < end) {
138
+ skipStart = i;
139
+ skipEnd = end;
140
+ return false;
141
+ }
142
+ i = end;
143
+ if (!transparent) lastSig = "x";
144
+ } else {
145
+ if (!/\s/.test(c)) lastSig = c;
146
+ i++;
147
+ }
148
+ }
149
+ return true;
150
+ };
151
+ }
152
+ function firstCodeMatchIndex(code, pattern) {
153
+ const inCode = makeCodeClassifier(code);
154
+ pattern.lastIndex = 0;
155
+ let m;
156
+ while ((m = pattern.exec(code)) !== null) {
157
+ if (inCode(m.index)) return m.index;
158
+ if (pattern.lastIndex <= m.index) pattern.lastIndex = m.index + 1;
159
+ }
160
+ return -1;
161
+ }
162
+ function codeMatchIndices(code, pattern) {
163
+ const inCode = makeCodeClassifier(code);
164
+ const indices = [];
165
+ pattern.lastIndex = 0;
166
+ let m;
167
+ while ((m = pattern.exec(code)) !== null) {
168
+ if (inCode(m.index)) indices.push(m.index);
169
+ if (pattern.lastIndex <= m.index) pattern.lastIndex = m.index + 1;
170
+ }
171
+ return indices;
172
+ }
173
+
174
+ // src/router/basename.ts
175
+ function normalizeBasename(basename) {
176
+ if (!basename) return void 0;
177
+ const trimmed = basename.replace(/^\/+|\/+$/g, "");
178
+ return trimmed ? "/" + trimmed : void 0;
179
+ }
180
+ function prefixBasename(path, basename) {
181
+ if (!basename || !path.startsWith("/") || path === basename || path.startsWith(basename + "/") || path.startsWith(basename + "?") || path.startsWith(basename + "#")) {
182
+ return path;
183
+ }
184
+ return path === "/" ? basename : basename + path;
185
+ }
186
+
187
+ export {
188
+ isAutoGeneratedRouteName,
189
+ isUniversallySkippedScanDir,
190
+ isSkippedSourceScanDir,
191
+ findTsFiles,
192
+ firstCodeMatchIndex,
193
+ codeMatchIndices,
194
+ normalizeBasename,
195
+ prefixBasename
196
+ };