@rangojs/router 0.0.0-experimental.107 → 0.0.0-experimental.109
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/README.md +4 -4
- package/dist/bin/rango.js +16 -16
- package/dist/vite/index.js +146 -150
- package/package.json +6 -6
- package/skills/hooks/SKILL.md +2 -0
- package/skills/links/SKILL.md +13 -1
- package/skills/loader/SKILL.md +1 -1
- package/skills/middleware/SKILL.md +3 -3
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/prerender/SKILL.md +13 -13
- package/skills/rango/SKILL.md +9 -0
- package/skills/response-routes/SKILL.md +58 -9
- package/skills/router-setup/SKILL.md +3 -3
- package/skills/typesafety/SKILL.md +273 -31
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +117 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/react/location-state-shared.ts +3 -3
- package/src/browser/react/use-handle.ts +17 -9
- package/src/browser/rsc-router.tsx +14 -14
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/build/generate-manifest.ts +3 -3
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +1 -1
- package/src/build/route-types/per-module-writer.ts +3 -3
- package/src/build/route-types/router-processing.ts +4 -4
- package/src/build/route-types/scan-filter.ts +1 -1
- package/src/client.tsx +4 -7
- package/src/errors.ts +1 -1
- package/src/handle.ts +2 -2
- package/src/href-client.ts +136 -19
- package/src/index.rsc.ts +4 -4
- package/src/index.ts +2 -2
- package/src/loader.rsc.ts +1 -1
- package/src/loader.ts +1 -1
- package/src/prerender.ts +4 -4
- package/src/route-definition/dsl-helpers.ts +2 -2
- package/src/route-definition/helpers-types.ts +2 -2
- package/src/router/error-handling.ts +1 -1
- package/src/router/lazy-includes.ts +2 -2
- package/src/router/metrics.ts +1 -1
- package/src/router/middleware-types.ts +1 -1
- package/src/router/prerender-match.ts +1 -1
- package/src/router/router-interfaces.ts +34 -28
- package/src/router/router-options.ts +1 -1
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +2 -2
- package/src/router/segment-resolution/revalidation.ts +2 -2
- package/src/router.ts +13 -16
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/index.ts +1 -1
- package/src/rsc/types.ts +2 -2
- package/src/search-params.ts +4 -4
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +16 -16
- package/src/static-handler.ts +1 -1
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +3 -3
- package/src/urls/path-helper-types.ts +2 -2
- package/src/urls/pattern-types.ts +34 -0
- package/src/urls/type-extraction.ts +6 -1
- package/src/use-loader.tsx +6 -4
- package/src/vite/discovery/bundle-postprocess.ts +6 -6
- package/src/vite/discovery/discover-routers.ts +3 -3
- package/src/vite/discovery/discovery-errors.ts +1 -1
- package/src/vite/discovery/prerender-collection.ts +19 -25
- package/src/vite/discovery/route-types-writer.ts +3 -3
- package/src/vite/discovery/state.ts +4 -4
- package/src/vite/plugins/cloudflare-protocol-stub.ts +1 -1
- package/src/vite/plugins/expose-action-id.ts +2 -2
- package/src/vite/plugins/expose-id-utils.ts +12 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +33 -9
- package/src/vite/plugins/expose-internal-ids.ts +1 -1
- package/src/vite/plugins/performance-tracks.ts +12 -16
- package/src/vite/plugins/use-cache-transform.ts +1 -1
- package/src/vite/plugins/version-plugin.ts +2 -2
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +11 -11
- package/src/vite/router-discovery.ts +26 -29
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/forward-user-plugins.ts +46 -17
- package/src/vite/utils/shared-utils.ts +26 -22
package/README.md
CHANGED
|
@@ -993,16 +993,16 @@ Auto-detects file type:
|
|
|
993
993
|
|
|
994
994
|
## Type Safety
|
|
995
995
|
|
|
996
|
-
The Vite plugin automatically generates a `router.named-routes.gen.ts` file that globally registers route names, patterns, and search schemas via `
|
|
996
|
+
The Vite plugin automatically generates a `router.named-routes.gen.ts` file that globally registers route names, patterns, and search schemas via `Rango.GeneratedRouteMap`. This powers server-side named-route typing such as `Handler<"name">`, `ctx.reverse()`, `getRequestContext().reverse()`, and `RouteParams<"name">` without any manual route registration. The gen file is updated on dev server startup, HMR, and production builds.
|
|
997
997
|
|
|
998
|
-
Use the generated map by default. Augment `
|
|
998
|
+
Use the generated map by default. Augment `Rango.RegisteredRoutes` only when you need the richer `typeof router.routeMap` shape globally, especially for response-aware and path-based utilities.
|
|
999
999
|
|
|
1000
1000
|
```typescript
|
|
1001
1001
|
// router.tsx
|
|
1002
1002
|
const router = createRouter<AppBindings>({}).routes(urlpatterns);
|
|
1003
1003
|
|
|
1004
1004
|
declare global {
|
|
1005
|
-
namespace
|
|
1005
|
+
namespace Rango {
|
|
1006
1006
|
interface Env extends AppEnv {}
|
|
1007
1007
|
interface Vars extends AppVars {}
|
|
1008
1008
|
interface RegisteredRoutes extends typeof router.routeMap {}
|
|
@@ -1014,7 +1014,7 @@ Quick rule of thumb:
|
|
|
1014
1014
|
|
|
1015
1015
|
- `GeneratedRouteMap` (auto-generated) — use for server-side named-route typing: `Handler<"name">`, `ctx.reverse()`, `Prerender<"name">`
|
|
1016
1016
|
- `typeof router.routeMap` — use when you need route entries with response metadata
|
|
1017
|
-
- `RegisteredRoutes` (manual augmentation) — use to expose `typeof router.routeMap` globally for `href()`, `
|
|
1017
|
+
- `RegisteredRoutes` (manual augmentation) — use to expose `typeof router.routeMap` globally for `href()`, `Rango.Path`, `Rango.PathResponse`, and other path/response-aware utilities
|
|
1018
1018
|
|
|
1019
1019
|
For extracted reusable loaders or middleware, prefer global dotted names on
|
|
1020
1020
|
`ctx.reverse()` by default. If you want type-safe local names for a specific
|
package/dist/bin/rango.js
CHANGED
|
@@ -139,7 +139,7 @@ function generatePerModuleTypesSource(routes) {
|
|
|
139
139
|
const valid = routes.filter(({ name }) => {
|
|
140
140
|
if (!name || /["'\\`\n\r]/.test(name)) {
|
|
141
141
|
console.warn(
|
|
142
|
-
`[
|
|
142
|
+
`[rango] Skipping route with invalid name: ${JSON.stringify(name)}`
|
|
143
143
|
);
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
@@ -149,7 +149,7 @@ function generatePerModuleTypesSource(routes) {
|
|
|
149
149
|
for (const { name, pattern, params, search } of valid) {
|
|
150
150
|
if (deduped.has(name)) {
|
|
151
151
|
console.warn(
|
|
152
|
-
`[
|
|
152
|
+
`[rango] Duplicate route name "${name}" \u2014 keeping first definition`
|
|
153
153
|
);
|
|
154
154
|
continue;
|
|
155
155
|
}
|
|
@@ -186,7 +186,7 @@ ${objectBody}
|
|
|
186
186
|
} as const;
|
|
187
187
|
|
|
188
188
|
declare global {
|
|
189
|
-
namespace
|
|
189
|
+
namespace Rango {
|
|
190
190
|
interface GeneratedRouteMap extends Readonly<typeof NamedRoutes> {}
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -211,7 +211,7 @@ function findTsFiles(dir, filter) {
|
|
|
211
211
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
212
212
|
} catch (err) {
|
|
213
213
|
console.warn(
|
|
214
|
-
`[
|
|
214
|
+
`[rango] Failed to scan directory ${dir}: ${err.message}`
|
|
215
215
|
);
|
|
216
216
|
return results;
|
|
217
217
|
}
|
|
@@ -456,7 +456,7 @@ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagno
|
|
|
456
456
|
const realPath = resolve(filePath);
|
|
457
457
|
const key = variableName ? `${realPath}:${variableName}` : realPath;
|
|
458
458
|
if (visited.has(key)) {
|
|
459
|
-
console.warn(`[
|
|
459
|
+
console.warn(`[rango] Circular include detected, skipping: ${key}`);
|
|
460
460
|
return { routes: {}, searchSchemas: {} };
|
|
461
461
|
}
|
|
462
462
|
visited.add(key);
|
|
@@ -548,7 +548,7 @@ function writePerModuleRouteTypesForFile(filePath) {
|
|
|
548
548
|
if (varNames.length > 0 && !existsSync2(genPath)) {
|
|
549
549
|
writeFileSync(genPath, generatePerModuleTypesSource([]));
|
|
550
550
|
console.log(
|
|
551
|
-
`[
|
|
551
|
+
`[rango] Generated route types (placeholder) -> ${genPath}`
|
|
552
552
|
);
|
|
553
553
|
}
|
|
554
554
|
return;
|
|
@@ -557,11 +557,11 @@ function writePerModuleRouteTypesForFile(filePath) {
|
|
|
557
557
|
const existing = existsSync2(genPath) ? readFileSync2(genPath, "utf-8") : null;
|
|
558
558
|
if (existing !== genSource) {
|
|
559
559
|
writeFileSync(genPath, genSource);
|
|
560
|
-
console.log(`[
|
|
560
|
+
console.log(`[rango] Generated route types -> ${genPath}`);
|
|
561
561
|
}
|
|
562
562
|
} catch (err) {
|
|
563
563
|
console.warn(
|
|
564
|
-
`[
|
|
564
|
+
`[rango] Failed to generate route types for ${filePath}: ${err.message}`
|
|
565
565
|
);
|
|
566
566
|
}
|
|
567
567
|
}
|
|
@@ -612,7 +612,7 @@ function findRouterFilesRecursive(dir, filter, results) {
|
|
|
612
612
|
entries = readdirSync2(dir, { withFileTypes: true });
|
|
613
613
|
} catch (err) {
|
|
614
614
|
console.warn(
|
|
615
|
-
`[
|
|
615
|
+
`[rango] Failed to scan directory ${dir}: ${err.message}`
|
|
616
616
|
);
|
|
617
617
|
return;
|
|
618
618
|
}
|
|
@@ -668,7 +668,7 @@ function findNestedRouterConflict(routerFiles) {
|
|
|
668
668
|
}
|
|
669
669
|
return null;
|
|
670
670
|
}
|
|
671
|
-
function formatNestedRouterConflictError(conflict, prefix = "[
|
|
671
|
+
function formatNestedRouterConflictError(conflict, prefix = "[rango]") {
|
|
672
672
|
return `${prefix} Nested router roots are not supported.
|
|
673
673
|
Router root: ${conflict.ancestor}
|
|
674
674
|
Nested router: ${conflict.nested}
|
|
@@ -897,7 +897,7 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
|
|
|
897
897
|
if (existsSync3(oldCombinedPath)) {
|
|
898
898
|
unlinkSync(oldCombinedPath);
|
|
899
899
|
console.log(
|
|
900
|
-
`[
|
|
900
|
+
`[rango] Removed stale combined route types: ${oldCombinedPath}`
|
|
901
901
|
);
|
|
902
902
|
}
|
|
903
903
|
} catch {
|
|
@@ -952,7 +952,7 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
|
|
|
952
952
|
}
|
|
953
953
|
writeFileSync2(outPath, source);
|
|
954
954
|
console.log(
|
|
955
|
-
`[
|
|
955
|
+
`[rango] Generated route types (${Object.keys(result.routes).length} routes) -> ${outPath}`
|
|
956
956
|
);
|
|
957
957
|
}
|
|
958
958
|
}
|
|
@@ -1003,7 +1003,7 @@ import {
|
|
|
1003
1003
|
import { createElement, StrictMode } from "react";
|
|
1004
1004
|
import { hydrateRoot } from "react-dom/client";
|
|
1005
1005
|
import { rscStream } from "@rangojs/router/internal/deps/html-stream-client";
|
|
1006
|
-
import { initBrowserApp,
|
|
1006
|
+
import { initBrowserApp, Rango } from "@rangojs/router/browser";
|
|
1007
1007
|
|
|
1008
1008
|
async function initializeApp() {
|
|
1009
1009
|
const deps = {
|
|
@@ -1018,7 +1018,7 @@ async function initializeApp() {
|
|
|
1018
1018
|
|
|
1019
1019
|
hydrateRoot(
|
|
1020
1020
|
document,
|
|
1021
|
-
createElement(StrictMode, null, createElement(
|
|
1021
|
+
createElement(StrictMode, null, createElement(Rango))
|
|
1022
1022
|
);
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
@@ -1063,7 +1063,7 @@ function normalizeModuleId(id) {
|
|
|
1063
1063
|
function getClientModuleSignature(source) {
|
|
1064
1064
|
let program;
|
|
1065
1065
|
try {
|
|
1066
|
-
program = parseAst(source, {
|
|
1066
|
+
program = parseAst(source, { lang: "tsx" });
|
|
1067
1067
|
} catch {
|
|
1068
1068
|
return void 0;
|
|
1069
1069
|
}
|
|
@@ -1151,7 +1151,7 @@ function createVersionPlugin() {
|
|
|
1151
1151
|
let versionCounter = 0;
|
|
1152
1152
|
const bumpVersion = (reason) => {
|
|
1153
1153
|
currentVersion = Date.now().toString(16) + String(++versionCounter);
|
|
1154
|
-
console.log(`[
|
|
1154
|
+
console.log(`[rango] ${reason}, version updated: ${currentVersion}`);
|
|
1155
1155
|
const rscEnv = server?.environments?.rsc;
|
|
1156
1156
|
const versionMod = rscEnv?.moduleGraph?.getModuleById(
|
|
1157
1157
|
"\0" + VIRTUAL_IDS.version
|