@rangojs/router 0.0.0-experimental.39 → 0.0.0-experimental.3b1deca8
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/bin/rango.js +8 -3
- package/dist/vite/index.js +292 -204
- package/package.json +1 -1
- package/skills/cache-guide/SKILL.md +32 -0
- package/skills/caching/SKILL.md +45 -4
- package/skills/loader/SKILL.md +53 -43
- package/skills/parallel/SKILL.md +126 -0
- package/skills/route/SKILL.md +31 -0
- package/skills/router-setup/SKILL.md +52 -2
- package/skills/typesafety/SKILL.md +10 -0
- package/src/browser/debug-channel.ts +93 -0
- package/src/browser/event-controller.ts +5 -0
- package/src/browser/navigation-bridge.ts +1 -5
- package/src/browser/navigation-client.ts +84 -27
- package/src/browser/navigation-transaction.ts +11 -9
- package/src/browser/partial-update.ts +50 -9
- package/src/browser/prefetch/cache.ts +57 -5
- package/src/browser/prefetch/fetch.ts +30 -21
- package/src/browser/prefetch/queue.ts +92 -20
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/react/Link.tsx +9 -1
- package/src/browser/react/NavigationProvider.tsx +32 -3
- package/src/browser/rsc-router.tsx +109 -57
- package/src/browser/scroll-restoration.ts +31 -34
- package/src/browser/segment-reconciler.ts +6 -1
- package/src/browser/server-action-bridge.ts +12 -0
- package/src/browser/types.ts +17 -1
- package/src/build/route-types/router-processing.ts +12 -2
- package/src/cache/cache-runtime.ts +15 -11
- package/src/cache/cache-scope.ts +48 -7
- package/src/cache/cf/cf-cache-store.ts +453 -11
- package/src/cache/cf/index.ts +5 -1
- package/src/cache/document-cache.ts +17 -7
- package/src/cache/index.ts +1 -0
- package/src/cache/taint.ts +55 -0
- package/src/context-var.ts +72 -2
- package/src/debug.ts +2 -2
- package/src/deps/browser.ts +1 -0
- package/src/route-definition/dsl-helpers.ts +32 -7
- package/src/route-definition/helpers-types.ts +6 -5
- package/src/route-definition/redirect.ts +2 -2
- package/src/route-map-builder.ts +7 -1
- package/src/router/find-match.ts +4 -2
- package/src/router/handler-context.ts +31 -8
- package/src/router/intercept-resolution.ts +2 -0
- package/src/router/lazy-includes.ts +4 -1
- package/src/router/loader-resolution.ts +7 -1
- package/src/router/logging.ts +5 -2
- package/src/router/manifest.ts +9 -3
- package/src/router/match-middleware/background-revalidation.ts +30 -2
- package/src/router/match-middleware/cache-lookup.ts +66 -9
- package/src/router/match-middleware/cache-store.ts +53 -10
- package/src/router/match-middleware/intercept-resolution.ts +9 -7
- package/src/router/match-middleware/segment-resolution.ts +8 -5
- package/src/router/match-result.ts +22 -6
- package/src/router/metrics.ts +6 -1
- package/src/router/middleware-types.ts +6 -2
- package/src/router/middleware.ts +4 -3
- package/src/router/router-context.ts +6 -1
- package/src/router/segment-resolution/fresh.ts +130 -17
- package/src/router/segment-resolution/helpers.ts +29 -24
- package/src/router/segment-resolution/loader-cache.ts +1 -0
- package/src/router/segment-resolution/revalidation.ts +352 -290
- package/src/router/segment-wrappers.ts +2 -0
- package/src/router/types.ts +1 -0
- package/src/router.ts +6 -1
- package/src/rsc/handler.ts +28 -2
- package/src/rsc/loader-fetch.ts +7 -2
- package/src/rsc/progressive-enhancement.ts +4 -1
- package/src/rsc/rsc-rendering.ts +4 -1
- package/src/rsc/server-action.ts +2 -0
- package/src/rsc/types.ts +7 -1
- package/src/segment-system.tsx +140 -4
- package/src/server/context.ts +102 -13
- package/src/server/request-context.ts +59 -12
- package/src/ssr/index.tsx +1 -0
- package/src/types/handler-context.ts +120 -22
- package/src/types/loader-types.ts +4 -4
- package/src/types/route-entry.ts +7 -0
- package/src/types/segments.ts +2 -0
- package/src/urls/path-helper.ts +1 -1
- package/src/vite/discovery/state.ts +0 -2
- package/src/vite/plugin-types.ts +0 -83
- package/src/vite/plugins/expose-action-id.ts +1 -3
- package/src/vite/plugins/performance-tracks.ts +235 -0
- package/src/vite/plugins/version-plugin.ts +13 -1
- package/src/vite/rango.ts +148 -209
- package/src/vite/router-discovery.ts +0 -8
- package/src/vite/utils/banner.ts +3 -3
package/dist/vite/index.js
CHANGED
|
@@ -9,18 +9,18 @@ import fs from "node:fs";
|
|
|
9
9
|
|
|
10
10
|
// src/vite/plugins/expose-id-utils.ts
|
|
11
11
|
import path from "node:path";
|
|
12
|
-
import
|
|
12
|
+
import crypto2 from "node:crypto";
|
|
13
13
|
function normalizePath(p) {
|
|
14
14
|
return p.split(path.sep).join("/");
|
|
15
15
|
}
|
|
16
16
|
function hashId(filePath, exportName) {
|
|
17
17
|
const input = `${filePath}#${exportName}`;
|
|
18
|
-
const hash =
|
|
18
|
+
const hash = crypto2.createHash("sha256").update(input).digest("hex");
|
|
19
19
|
return `${hash.slice(0, 8)}#${exportName}`;
|
|
20
20
|
}
|
|
21
21
|
function hashInlineId(filePath, lineNumber, index) {
|
|
22
22
|
const input = index !== void 0 && index > 0 ? `${filePath}:${lineNumber}:${index}` : `${filePath}:${lineNumber}`;
|
|
23
|
-
return
|
|
23
|
+
return crypto2.createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
24
24
|
}
|
|
25
25
|
function buildExportMap(program) {
|
|
26
26
|
const exportMap = /* @__PURE__ */ new Map();
|
|
@@ -292,7 +292,7 @@ function exposeActionId() {
|
|
|
292
292
|
}
|
|
293
293
|
if (!rscPluginApi) {
|
|
294
294
|
throw new Error(
|
|
295
|
-
"[rsc-router] Could not find @vitejs/plugin-rsc. @rangojs/router requires the Vite RSC plugin
|
|
295
|
+
"[rsc-router] Could not find @vitejs/plugin-rsc. @rangojs/router requires the Vite RSC plugin, which is included automatically by rango()."
|
|
296
296
|
);
|
|
297
297
|
}
|
|
298
298
|
if (!isBuild) return;
|
|
@@ -1745,7 +1745,7 @@ import { resolve } from "node:path";
|
|
|
1745
1745
|
// package.json
|
|
1746
1746
|
var package_default = {
|
|
1747
1747
|
name: "@rangojs/router",
|
|
1748
|
-
version: "0.0.0-experimental.
|
|
1748
|
+
version: "0.0.0-experimental.3b1deca8",
|
|
1749
1749
|
description: "Django-inspired RSC router with composable URL patterns",
|
|
1750
1750
|
keywords: [
|
|
1751
1751
|
"react",
|
|
@@ -2095,31 +2095,7 @@ declare global {
|
|
|
2095
2095
|
}
|
|
2096
2096
|
|
|
2097
2097
|
// src/build/route-types/scan-filter.ts
|
|
2098
|
-
import { join, relative } from "node:path";
|
|
2099
2098
|
import picomatch from "picomatch";
|
|
2100
|
-
var DEFAULT_EXCLUDE_PATTERNS = [
|
|
2101
|
-
"**/__tests__/**",
|
|
2102
|
-
"**/__mocks__/**",
|
|
2103
|
-
"**/dist/**",
|
|
2104
|
-
"**/coverage/**",
|
|
2105
|
-
"**/*.test.{ts,tsx,js,jsx}",
|
|
2106
|
-
"**/*.spec.{ts,tsx,js,jsx}"
|
|
2107
|
-
];
|
|
2108
|
-
function createScanFilter(root, opts) {
|
|
2109
|
-
const { include, exclude } = opts;
|
|
2110
|
-
const hasInclude = include && include.length > 0;
|
|
2111
|
-
const hasCustomExclude = exclude !== void 0;
|
|
2112
|
-
if (!hasInclude && !hasCustomExclude) return void 0;
|
|
2113
|
-
const effectiveExclude = exclude ?? DEFAULT_EXCLUDE_PATTERNS;
|
|
2114
|
-
const includeMatcher = hasInclude ? picomatch(include) : null;
|
|
2115
|
-
const excludeMatcher = effectiveExclude.length > 0 ? picomatch(effectiveExclude) : null;
|
|
2116
|
-
return (absolutePath) => {
|
|
2117
|
-
const rel = relative(root, absolutePath);
|
|
2118
|
-
if (excludeMatcher && excludeMatcher(rel)) return false;
|
|
2119
|
-
if (includeMatcher) return includeMatcher(rel);
|
|
2120
|
-
return true;
|
|
2121
|
-
};
|
|
2122
|
-
}
|
|
2123
2099
|
|
|
2124
2100
|
// src/build/route-types/per-module-writer.ts
|
|
2125
2101
|
import ts4 from "typescript";
|
|
@@ -2386,7 +2362,7 @@ import {
|
|
|
2386
2362
|
readdirSync
|
|
2387
2363
|
} from "node:fs";
|
|
2388
2364
|
import {
|
|
2389
|
-
join
|
|
2365
|
+
join,
|
|
2390
2366
|
dirname as dirname2,
|
|
2391
2367
|
resolve as resolve3,
|
|
2392
2368
|
sep,
|
|
@@ -2406,7 +2382,7 @@ function countPublicRouteEntries(source) {
|
|
|
2406
2382
|
}
|
|
2407
2383
|
var ROUTER_CALL_PATTERN = /\bcreateRouter\s*[<(]/;
|
|
2408
2384
|
function isRoutableSourceFile(name) {
|
|
2409
|
-
return (name.endsWith(".ts") || name.endsWith(".tsx") || name.endsWith(".js") || name.endsWith(".jsx")) && !name.includes(".gen.");
|
|
2385
|
+
return (name.endsWith(".ts") || name.endsWith(".tsx") || name.endsWith(".js") || name.endsWith(".jsx")) && !name.includes(".gen.") && !name.includes(".test.") && !name.includes(".spec.");
|
|
2410
2386
|
}
|
|
2411
2387
|
function findRouterFilesRecursive(dir, filter, results) {
|
|
2412
2388
|
let entries;
|
|
@@ -2421,9 +2397,10 @@ function findRouterFilesRecursive(dir, filter, results) {
|
|
|
2421
2397
|
const childDirs = [];
|
|
2422
2398
|
const routerFilesInDir = [];
|
|
2423
2399
|
for (const entry of entries) {
|
|
2424
|
-
const fullPath =
|
|
2400
|
+
const fullPath = join(dir, entry.name);
|
|
2425
2401
|
if (entry.isDirectory()) {
|
|
2426
|
-
if (entry.name === "node_modules" || entry.name.startsWith("."))
|
|
2402
|
+
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === "coverage" || entry.name === "__tests__" || entry.name === "__mocks__" || entry.name.startsWith("."))
|
|
2403
|
+
continue;
|
|
2427
2404
|
childDirs.push(fullPath);
|
|
2428
2405
|
continue;
|
|
2429
2406
|
}
|
|
@@ -2547,7 +2524,7 @@ function findRouterFiles(root, filter) {
|
|
|
2547
2524
|
}
|
|
2548
2525
|
function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
|
|
2549
2526
|
try {
|
|
2550
|
-
const oldCombinedPath =
|
|
2527
|
+
const oldCombinedPath = join(root, "src", "named-routes.gen.ts");
|
|
2551
2528
|
if (existsSync3(oldCombinedPath)) {
|
|
2552
2529
|
unlinkSync(oldCombinedPath);
|
|
2553
2530
|
console.log(
|
|
@@ -2587,7 +2564,7 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
|
|
|
2587
2564
|
/\.(tsx?|jsx?)$/,
|
|
2588
2565
|
""
|
|
2589
2566
|
);
|
|
2590
|
-
const outPath =
|
|
2567
|
+
const outPath = join(
|
|
2591
2568
|
dirname2(routerFilePath),
|
|
2592
2569
|
`${routerBasename}.named-routes.gen.ts`
|
|
2593
2570
|
);
|
|
@@ -2717,8 +2694,9 @@ function createVersionPlugin() {
|
|
|
2717
2694
|
let isDev = false;
|
|
2718
2695
|
let server = null;
|
|
2719
2696
|
const clientModuleSignatures = /* @__PURE__ */ new Map();
|
|
2697
|
+
let versionCounter = 0;
|
|
2720
2698
|
const bumpVersion = (reason) => {
|
|
2721
|
-
currentVersion = Date.now().toString(16);
|
|
2699
|
+
currentVersion = Date.now().toString(16) + String(++versionCounter);
|
|
2722
2700
|
console.log(`[rsc-router] ${reason}, version updated: ${currentVersion}`);
|
|
2723
2701
|
const rscEnv = server?.environments?.rsc;
|
|
2724
2702
|
const versionMod = rscEnv?.moduleGraph?.getModuleById(
|
|
@@ -2774,6 +2752,9 @@ function createVersionPlugin() {
|
|
|
2774
2752
|
if (!isDev) return;
|
|
2775
2753
|
const isRscModule = this.environment?.name === "rsc";
|
|
2776
2754
|
if (!isRscModule) return;
|
|
2755
|
+
if (ctx.modules.length === 1 && ctx.modules[0].id === "\0" + VIRTUAL_IDS.version) {
|
|
2756
|
+
return;
|
|
2757
|
+
}
|
|
2777
2758
|
if (isCodeModule(ctx.file)) {
|
|
2778
2759
|
const filePath = normalizeModuleId(ctx.file);
|
|
2779
2760
|
const previousSignature = clientModuleSignatures.get(filePath);
|
|
@@ -2903,11 +2884,11 @@ ${dim} \u2571${reset} ${bold}\u2554\u2550\u2557${reset}${dim} * \u2
|
|
|
2903
2884
|
${dim} ${reset}${bold}\u2551 \u2551${reset} ${bold}\u2554\u2550\u2557${reset}${dim} * \u2727. \u2571${reset}
|
|
2904
2885
|
${dim} ${reset}${bold}\u2554\u2557 \u2551 \u2551 \u2551 \u2551${reset}${dim} * \u2571${reset}
|
|
2905
2886
|
${dim} ${reset}${bold}\u2551\u2551 \u2551 \u2551 \u2551 \u2551 \u2566\u2550\u2557\u2554\u2550\u2557\u2554\u2557\u2554\u2554\u2550\u2557\u2554\u2550\u2557${reset}${dim} \u2727 \u2726${reset}
|
|
2906
|
-
${dim}
|
|
2887
|
+
${dim} ${reset}${bold}\u2551\u2551 \u2551 \u2560\u2550\u255D \u2551 \u2560\u2566\u255D\u2560\u2550\u2563\u2551\u2551\u2551\u2551 \u2566\u2551 \u2551${reset}${dim} * \u2727${reset}
|
|
2907
2888
|
${dim} ${reset}${bold}\u2551\u255A\u2550\u255D \u2554\u2550\u2550\u2550\u255D \u2569\u255A\u2550\u2569 \u2569\u255D\u255A\u255D\u255A\u2550\u255D\u255A\u2550\u255D${reset}${dim} \u2726 . *${reset}
|
|
2908
2889
|
${dim} ${reset}${bold}\u255A\u2550\u2550\u2557 \u2551${reset}${dim} * RSC Wrangler \u2727 \u2726${reset}
|
|
2909
|
-
${dim} * ${reset}${bold}\u2551 \
|
|
2910
|
-
${bold}\u2550\u2550\u2550\
|
|
2890
|
+
${dim} * ${reset}${bold}\u2551 \u2551${reset}${dim} * \u2727. \u2571${reset}
|
|
2891
|
+
${dim} ${reset}${bold}\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550${reset}${dim} \u2726 *${reset}
|
|
2911
2892
|
|
|
2912
2893
|
v${version} \xB7 ${preset} \xB7 ${mode}
|
|
2913
2894
|
`;
|
|
@@ -3052,7 +3033,7 @@ function createVirtualStubPlugin() {
|
|
|
3052
3033
|
}
|
|
3053
3034
|
|
|
3054
3035
|
// src/vite/plugins/client-ref-hashing.ts
|
|
3055
|
-
import { relative
|
|
3036
|
+
import { relative } from "node:path";
|
|
3056
3037
|
import { createHash as createHash2 } from "node:crypto";
|
|
3057
3038
|
var CLIENT_PKG_PROXY_PREFIX = "/@id/__x00__virtual:vite-rsc/client-package-proxy/";
|
|
3058
3039
|
var CLIENT_IN_SERVER_PKG_PROXY_PREFIX = "/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/";
|
|
@@ -3065,10 +3046,10 @@ function computeProductionHash(projectRoot, refKey) {
|
|
|
3065
3046
|
const absPath = decodeURIComponent(
|
|
3066
3047
|
refKey.slice(CLIENT_IN_SERVER_PKG_PROXY_PREFIX.length)
|
|
3067
3048
|
);
|
|
3068
|
-
toHash =
|
|
3049
|
+
toHash = relative(projectRoot, absPath).replaceAll("\\", "/");
|
|
3069
3050
|
} else if (refKey.startsWith(FS_PREFIX)) {
|
|
3070
3051
|
const absPath = refKey.slice(FS_PREFIX.length - 1);
|
|
3071
|
-
toHash =
|
|
3052
|
+
toHash = relative(projectRoot, absPath).replaceAll("\\", "/");
|
|
3072
3053
|
} else if (refKey.startsWith("/")) {
|
|
3073
3054
|
toHash = refKey.slice(1);
|
|
3074
3055
|
} else {
|
|
@@ -3293,8 +3274,17 @@ function jsonParseExpression(value) {
|
|
|
3293
3274
|
}
|
|
3294
3275
|
|
|
3295
3276
|
// src/context-var.ts
|
|
3277
|
+
var NON_CACHEABLE_KEYS = /* @__PURE__ */ Symbol.for(
|
|
3278
|
+
"rango:non-cacheable-keys"
|
|
3279
|
+
);
|
|
3280
|
+
function getNonCacheableKeys(variables) {
|
|
3281
|
+
if (!variables[NON_CACHEABLE_KEYS]) {
|
|
3282
|
+
variables[NON_CACHEABLE_KEYS] = /* @__PURE__ */ new Set();
|
|
3283
|
+
}
|
|
3284
|
+
return variables[NON_CACHEABLE_KEYS];
|
|
3285
|
+
}
|
|
3296
3286
|
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
3297
|
-
function contextSet(variables, keyOrVar, value) {
|
|
3287
|
+
function contextSet(variables, keyOrVar, value, options) {
|
|
3298
3288
|
if (typeof keyOrVar === "string") {
|
|
3299
3289
|
if (FORBIDDEN_KEYS.has(keyOrVar)) {
|
|
3300
3290
|
throw new Error(
|
|
@@ -3302,8 +3292,14 @@ function contextSet(variables, keyOrVar, value) {
|
|
|
3302
3292
|
);
|
|
3303
3293
|
}
|
|
3304
3294
|
variables[keyOrVar] = value;
|
|
3295
|
+
if (options?.cache === false) {
|
|
3296
|
+
getNonCacheableKeys(variables).add(keyOrVar);
|
|
3297
|
+
}
|
|
3305
3298
|
} else {
|
|
3306
3299
|
variables[keyOrVar.key] = value;
|
|
3300
|
+
if (options?.cache === false) {
|
|
3301
|
+
getNonCacheableKeys(variables).add(keyOrVar.key);
|
|
3302
|
+
}
|
|
3307
3303
|
}
|
|
3308
3304
|
}
|
|
3309
3305
|
|
|
@@ -3937,7 +3933,7 @@ async function discoverRouters(state, rscEnv) {
|
|
|
3937
3933
|
}
|
|
3938
3934
|
|
|
3939
3935
|
// src/vite/discovery/route-types-writer.ts
|
|
3940
|
-
import { dirname as dirname3, basename, join as
|
|
3936
|
+
import { dirname as dirname3, basename, join as join2, resolve as resolve6 } from "node:path";
|
|
3941
3937
|
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync5, unlinkSync as unlinkSync2 } from "node:fs";
|
|
3942
3938
|
function filterUserNamedRoutes(manifest) {
|
|
3943
3939
|
const filtered = {};
|
|
@@ -3958,7 +3954,7 @@ function writeCombinedRouteTypesWithTracking(state, opts) {
|
|
|
3958
3954
|
/\.(tsx?|jsx?)$/,
|
|
3959
3955
|
""
|
|
3960
3956
|
);
|
|
3961
|
-
const outPath =
|
|
3957
|
+
const outPath = join2(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
3962
3958
|
try {
|
|
3963
3959
|
preContent.set(outPath, readFileSync4(outPath, "utf-8"));
|
|
3964
3960
|
} catch {
|
|
@@ -3971,7 +3967,7 @@ function writeCombinedRouteTypesWithTracking(state, opts) {
|
|
|
3971
3967
|
/\.(tsx?|jsx?)$/,
|
|
3972
3968
|
""
|
|
3973
3969
|
);
|
|
3974
|
-
const outPath =
|
|
3970
|
+
const outPath = join2(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
3975
3971
|
if (!existsSync5(outPath)) continue;
|
|
3976
3972
|
try {
|
|
3977
3973
|
const content = readFileSync4(outPath, "utf-8");
|
|
@@ -3988,7 +3984,7 @@ function writeRouteTypesFiles(state) {
|
|
|
3988
3984
|
const entryDir = dirname3(
|
|
3989
3985
|
resolve6(state.projectRoot, state.resolvedEntryPath)
|
|
3990
3986
|
);
|
|
3991
|
-
const oldCombinedPath =
|
|
3987
|
+
const oldCombinedPath = join2(entryDir, "named-routes.gen.ts");
|
|
3992
3988
|
if (existsSync5(oldCombinedPath)) {
|
|
3993
3989
|
unlinkSync2(oldCombinedPath);
|
|
3994
3990
|
console.log(
|
|
@@ -4013,7 +4009,7 @@ Set an explicit \`id\` on createRouter() or check the call site.`
|
|
|
4013
4009
|
}
|
|
4014
4010
|
const routerDir = dirname3(sourceFile);
|
|
4015
4011
|
const routerBasename = basename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
|
|
4016
|
-
const outPath =
|
|
4012
|
+
const outPath = join2(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
4017
4013
|
const userRoutes = filterUserNamedRoutes(routeManifest);
|
|
4018
4014
|
let effectiveSearchSchemas = routeSearchSchemas;
|
|
4019
4015
|
if ((!effectiveSearchSchemas || Object.keys(effectiveSearchSchemas).length === 0) && sourceFile) {
|
|
@@ -4078,7 +4074,7 @@ function supplementGenFilesWithRuntimeRoutes(state) {
|
|
|
4078
4074
|
}
|
|
4079
4075
|
const routerDir = dirname3(sourceFile);
|
|
4080
4076
|
const routerBasename = basename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
|
|
4081
|
-
const outPath =
|
|
4077
|
+
const outPath = join2(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
4082
4078
|
const source = generateRouteTypesSource(
|
|
4083
4079
|
mergedRoutes,
|
|
4084
4080
|
Object.keys(mergedSearchSchemas).length > 0 ? mergedSearchSchemas : void 0
|
|
@@ -4092,7 +4088,7 @@ function supplementGenFilesWithRuntimeRoutes(state) {
|
|
|
4092
4088
|
}
|
|
4093
4089
|
|
|
4094
4090
|
// src/vite/discovery/virtual-module-codegen.ts
|
|
4095
|
-
import { dirname as dirname4, basename as basename2, join as
|
|
4091
|
+
import { dirname as dirname4, basename as basename2, join as join3 } from "node:path";
|
|
4096
4092
|
function generateRoutesManifestModule(state) {
|
|
4097
4093
|
const hasManifest = state.mergedRouteManifest && Object.keys(state.mergedRouteManifest).length > 0;
|
|
4098
4094
|
if (hasManifest) {
|
|
@@ -4107,7 +4103,7 @@ function generateRoutesManifestModule(state) {
|
|
|
4107
4103
|
/\.(tsx?|jsx?)$/,
|
|
4108
4104
|
""
|
|
4109
4105
|
);
|
|
4110
|
-
const genPath =
|
|
4106
|
+
const genPath = join3(
|
|
4111
4107
|
routerDir,
|
|
4112
4108
|
`${routerBasename}.named-routes.gen.js`
|
|
4113
4109
|
).replaceAll("\\", "/");
|
|
@@ -4204,7 +4200,7 @@ function generatePerRouterModule(state, routerId) {
|
|
|
4204
4200
|
/\.(tsx?|jsx?)$/,
|
|
4205
4201
|
""
|
|
4206
4202
|
);
|
|
4207
|
-
const genPath =
|
|
4203
|
+
const genPath = join3(
|
|
4208
4204
|
routerDir,
|
|
4209
4205
|
`${routerBasename}.named-routes.gen.js`
|
|
4210
4206
|
).replaceAll("\\", "/");
|
|
@@ -4445,12 +4441,6 @@ function createRouterDiscoveryPlugin(entryPath, opts) {
|
|
|
4445
4441
|
s.resolvedEntryPath = entries[0];
|
|
4446
4442
|
}
|
|
4447
4443
|
}
|
|
4448
|
-
if (opts?.include || opts?.exclude) {
|
|
4449
|
-
s.scanFilter = createScanFilter(s.projectRoot, {
|
|
4450
|
-
include: opts.include,
|
|
4451
|
-
exclude: opts.exclude
|
|
4452
|
-
});
|
|
4453
|
-
}
|
|
4454
4444
|
if (opts?.staticRouteTypesGeneration !== false) {
|
|
4455
4445
|
s.cachedRouterFiles = findRouterFiles(s.projectRoot, s.scanFilter);
|
|
4456
4446
|
writeCombinedRouteTypesWithTracking(s, { preserveIfLarger: true });
|
|
@@ -4871,6 +4861,139 @@ ${details}`
|
|
|
4871
4861
|
};
|
|
4872
4862
|
}
|
|
4873
4863
|
|
|
4864
|
+
// src/vite/plugins/performance-tracks.ts
|
|
4865
|
+
import { Module } from "node:module";
|
|
4866
|
+
var DEBUG_ID_HEADER = "X-RSC-Debug-Id";
|
|
4867
|
+
var DEBUG_S2C_EVENT = "rango:perf-s2c";
|
|
4868
|
+
var DEBUG_C2S_EVENT = "rango:perf-c2s";
|
|
4869
|
+
var GLOBAL_KEY = "__RANGO_DEBUG_CHANNELS__";
|
|
4870
|
+
function getRegistry() {
|
|
4871
|
+
return Module[GLOBAL_KEY] ??= {
|
|
4872
|
+
channels: /* @__PURE__ */ new Map(),
|
|
4873
|
+
sessions: /* @__PURE__ */ new Map()
|
|
4874
|
+
};
|
|
4875
|
+
}
|
|
4876
|
+
var bytesToBase64 = (bytes) => Buffer.from(bytes).toString("base64");
|
|
4877
|
+
var base64ToBytes = (base64) => new Uint8Array(Buffer.from(base64, "base64"));
|
|
4878
|
+
function performanceTracksPlugin() {
|
|
4879
|
+
return {
|
|
4880
|
+
name: "@rangojs/router:performance-tracks",
|
|
4881
|
+
apply: "serve",
|
|
4882
|
+
enforce: "pre",
|
|
4883
|
+
configureServer(server) {
|
|
4884
|
+
const hot = server.environments.client.hot;
|
|
4885
|
+
const registry = getRegistry();
|
|
4886
|
+
const sessions = registry.sessions;
|
|
4887
|
+
const sendChunk = (debugId, chunk) => {
|
|
4888
|
+
hot.send(DEBUG_S2C_EVENT, {
|
|
4889
|
+
i: debugId,
|
|
4890
|
+
b: bytesToBase64(chunk)
|
|
4891
|
+
});
|
|
4892
|
+
};
|
|
4893
|
+
const cleanupIfEnded = (debugId, session) => {
|
|
4894
|
+
if (session.pendingChunks || !session.ended) return;
|
|
4895
|
+
sessions.delete(debugId);
|
|
4896
|
+
hot.send(DEBUG_S2C_EVENT, {
|
|
4897
|
+
i: debugId,
|
|
4898
|
+
d: true
|
|
4899
|
+
});
|
|
4900
|
+
};
|
|
4901
|
+
const registerDebugChannel = (debugId) => {
|
|
4902
|
+
let session = sessions.get(debugId);
|
|
4903
|
+
if (!session) {
|
|
4904
|
+
session = { pendingChunks: [], ended: false };
|
|
4905
|
+
sessions.set(debugId, session);
|
|
4906
|
+
}
|
|
4907
|
+
const readable = new ReadableStream({
|
|
4908
|
+
start(controller) {
|
|
4909
|
+
session.cmdController = controller;
|
|
4910
|
+
},
|
|
4911
|
+
cancel() {
|
|
4912
|
+
delete session.cmdController;
|
|
4913
|
+
}
|
|
4914
|
+
});
|
|
4915
|
+
const writable = new WritableStream({
|
|
4916
|
+
write(chunk) {
|
|
4917
|
+
if (session.pendingChunks) {
|
|
4918
|
+
session.pendingChunks.push(chunk);
|
|
4919
|
+
} else {
|
|
4920
|
+
sendChunk(debugId, chunk);
|
|
4921
|
+
}
|
|
4922
|
+
},
|
|
4923
|
+
close() {
|
|
4924
|
+
session.ended = true;
|
|
4925
|
+
cleanupIfEnded(debugId, session);
|
|
4926
|
+
},
|
|
4927
|
+
abort() {
|
|
4928
|
+
session.ended = true;
|
|
4929
|
+
cleanupIfEnded(debugId, session);
|
|
4930
|
+
}
|
|
4931
|
+
});
|
|
4932
|
+
registry.channels.set(debugId, { readable, writable });
|
|
4933
|
+
};
|
|
4934
|
+
hot.on(DEBUG_C2S_EVENT, (raw) => {
|
|
4935
|
+
const payload = raw;
|
|
4936
|
+
const session = sessions.get(payload.i);
|
|
4937
|
+
if (payload.d) {
|
|
4938
|
+
if (session?.cmdController) {
|
|
4939
|
+
try {
|
|
4940
|
+
session.cmdController.close();
|
|
4941
|
+
} catch {
|
|
4942
|
+
}
|
|
4943
|
+
delete session.cmdController;
|
|
4944
|
+
}
|
|
4945
|
+
return;
|
|
4946
|
+
}
|
|
4947
|
+
if (payload.b) {
|
|
4948
|
+
if (session?.cmdController) {
|
|
4949
|
+
try {
|
|
4950
|
+
session.cmdController.enqueue(base64ToBytes(payload.b));
|
|
4951
|
+
} catch {
|
|
4952
|
+
delete session.cmdController;
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
return;
|
|
4956
|
+
}
|
|
4957
|
+
if (session) {
|
|
4958
|
+
if (session.pendingChunks) {
|
|
4959
|
+
for (const chunk of session.pendingChunks) {
|
|
4960
|
+
sendChunk(payload.i, chunk);
|
|
4961
|
+
}
|
|
4962
|
+
delete session.pendingChunks;
|
|
4963
|
+
}
|
|
4964
|
+
cleanupIfEnded(payload.i, session);
|
|
4965
|
+
} else {
|
|
4966
|
+
sessions.set(payload.i, { ended: false });
|
|
4967
|
+
}
|
|
4968
|
+
});
|
|
4969
|
+
server.middlewares.use((req, _res, next) => {
|
|
4970
|
+
const existingId = req.headers[DEBUG_ID_HEADER.toLowerCase()];
|
|
4971
|
+
const isHtml = req.headers.accept?.includes("text/html");
|
|
4972
|
+
if (!existingId && !isHtml) {
|
|
4973
|
+
next();
|
|
4974
|
+
return;
|
|
4975
|
+
}
|
|
4976
|
+
const debugId = existingId || crypto.randomUUID();
|
|
4977
|
+
if (!existingId) {
|
|
4978
|
+
const lowerName = DEBUG_ID_HEADER.toLowerCase();
|
|
4979
|
+
req.headers[lowerName] = debugId;
|
|
4980
|
+
if (req.rawHeaders) {
|
|
4981
|
+
req.rawHeaders.push(DEBUG_ID_HEADER, debugId);
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
registerDebugChannel(debugId);
|
|
4985
|
+
console.log(
|
|
4986
|
+
"[perf-tracks] middleware: created channel for",
|
|
4987
|
+
debugId,
|
|
4988
|
+
"from",
|
|
4989
|
+
existingId ? "client header" : "SSR inject"
|
|
4990
|
+
);
|
|
4991
|
+
next();
|
|
4992
|
+
});
|
|
4993
|
+
}
|
|
4994
|
+
};
|
|
4995
|
+
}
|
|
4996
|
+
|
|
4874
4997
|
// src/vite/rango.ts
|
|
4875
4998
|
async function rango(options) {
|
|
4876
4999
|
const resolvedOptions = options ?? { preset: "node" };
|
|
@@ -4879,7 +5002,6 @@ async function rango(options) {
|
|
|
4879
5002
|
const plugins = [];
|
|
4880
5003
|
const rangoAliases = getPackageAliases();
|
|
4881
5004
|
const excludeDeps = getExcludeDeps();
|
|
4882
|
-
let rscEntryPath = null;
|
|
4883
5005
|
const routerRef = { path: void 0 };
|
|
4884
5006
|
const prerenderEnabled = true;
|
|
4885
5007
|
if (preset === "cloudflare") {
|
|
@@ -4983,153 +5105,121 @@ async function rango(options) {
|
|
|
4983
5105
|
);
|
|
4984
5106
|
plugins.push(clientRefDedup());
|
|
4985
5107
|
} else {
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
const
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
routerRef.path = (abs.startsWith(root) ? "./" + abs.slice(root.length + 1) : abs).replaceAll("\\", "/");
|
|
5002
|
-
} else if (candidates.length > 1) {
|
|
5003
|
-
const list = candidates.map(
|
|
5004
|
-
(f) => " - " + (f.startsWith(root) ? f.slice(root.length + 1) : f)
|
|
5005
|
-
).join("\n");
|
|
5006
|
-
throw new Error(
|
|
5007
|
-
`[rsc-router] Multiple routers found. Specify \`router\` to choose one:
|
|
5008
|
-
${list}`
|
|
5009
|
-
);
|
|
5010
|
-
}
|
|
5108
|
+
plugins.push({
|
|
5109
|
+
name: "@rangojs/router:auto-discover",
|
|
5110
|
+
config(userConfig) {
|
|
5111
|
+
if (routerRef.path) return;
|
|
5112
|
+
const root = userConfig.root ? resolve9(process.cwd(), userConfig.root) : process.cwd();
|
|
5113
|
+
const candidates = findRouterFiles(root);
|
|
5114
|
+
if (candidates.length === 1) {
|
|
5115
|
+
const abs = candidates[0];
|
|
5116
|
+
routerRef.path = (abs.startsWith(root) ? "./" + abs.slice(root.length + 1) : abs).replaceAll("\\", "/");
|
|
5117
|
+
} else if (candidates.length > 1) {
|
|
5118
|
+
const list = candidates.map(
|
|
5119
|
+
(f) => " - " + (f.startsWith(root) ? f.slice(root.length + 1) : f)
|
|
5120
|
+
).join("\n");
|
|
5121
|
+
throw new Error(`[rsc-router] Multiple routers found:
|
|
5122
|
+
${list}`);
|
|
5011
5123
|
}
|
|
5012
|
-
}
|
|
5013
|
-
}
|
|
5014
|
-
const
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
resolve: {
|
|
5043
|
-
alias: rangoAliases
|
|
5044
|
-
},
|
|
5045
|
-
environments: {
|
|
5046
|
-
client: {
|
|
5047
|
-
build: {
|
|
5048
|
-
rollupOptions: {
|
|
5049
|
-
output: {
|
|
5050
|
-
manualChunks: getManualChunks
|
|
5051
|
-
}
|
|
5052
|
-
}
|
|
5053
|
-
},
|
|
5054
|
-
// Always exclude rsc-router modules, conditionally add virtual entry
|
|
5055
|
-
optimizeDeps: {
|
|
5056
|
-
// Pre-bundle React and rsc-html-stream to prevent late discovery
|
|
5057
|
-
// triggering ERR_OUTDATED_OPTIMIZED_DEP on cold starts
|
|
5058
|
-
include: [
|
|
5059
|
-
"react",
|
|
5060
|
-
"react-dom",
|
|
5061
|
-
"react/jsx-runtime",
|
|
5062
|
-
"react/jsx-dev-runtime",
|
|
5063
|
-
"rsc-html-stream/client"
|
|
5064
|
-
],
|
|
5065
|
-
exclude: excludeDeps,
|
|
5066
|
-
esbuildOptions: sharedEsbuildOptions,
|
|
5067
|
-
...useVirtualClient && {
|
|
5068
|
-
// Tell Vite to scan the virtual entry for dependencies
|
|
5069
|
-
entries: [VIRTUAL_IDS.browser]
|
|
5070
|
-
}
|
|
5071
|
-
}
|
|
5072
|
-
},
|
|
5073
|
-
...useVirtualSSR && {
|
|
5074
|
-
ssr: {
|
|
5075
|
-
optimizeDeps: {
|
|
5076
|
-
entries: [VIRTUAL_IDS.ssr],
|
|
5077
|
-
// Pre-bundle all SSR deps to prevent late discovery triggering ERR_OUTDATED_OPTIMIZED_DEP
|
|
5078
|
-
include: [
|
|
5079
|
-
"react",
|
|
5080
|
-
"react-dom",
|
|
5081
|
-
"react-dom/server.edge",
|
|
5082
|
-
"react-dom/static.edge",
|
|
5083
|
-
"react/jsx-runtime",
|
|
5084
|
-
"react/jsx-dev-runtime",
|
|
5085
|
-
"@vitejs/plugin-rsc/vendor/react-server-dom/client.edge"
|
|
5086
|
-
],
|
|
5087
|
-
exclude: excludeDeps,
|
|
5088
|
-
esbuildOptions: sharedEsbuildOptions
|
|
5124
|
+
}
|
|
5125
|
+
});
|
|
5126
|
+
const finalEntries = {
|
|
5127
|
+
client: VIRTUAL_IDS.browser,
|
|
5128
|
+
ssr: VIRTUAL_IDS.ssr,
|
|
5129
|
+
rsc: VIRTUAL_IDS.rsc
|
|
5130
|
+
};
|
|
5131
|
+
const { default: rsc } = await import("@vitejs/plugin-rsc");
|
|
5132
|
+
let hasWarnedDuplicate = false;
|
|
5133
|
+
plugins.push({
|
|
5134
|
+
name: "@rangojs/router:rsc-integration",
|
|
5135
|
+
enforce: "pre",
|
|
5136
|
+
config() {
|
|
5137
|
+
return {
|
|
5138
|
+
optimizeDeps: {
|
|
5139
|
+
exclude: excludeDeps,
|
|
5140
|
+
esbuildOptions: sharedEsbuildOptions
|
|
5141
|
+
},
|
|
5142
|
+
build: {
|
|
5143
|
+
rollupOptions: { onwarn }
|
|
5144
|
+
},
|
|
5145
|
+
resolve: {
|
|
5146
|
+
alias: rangoAliases
|
|
5147
|
+
},
|
|
5148
|
+
environments: {
|
|
5149
|
+
client: {
|
|
5150
|
+
build: {
|
|
5151
|
+
rollupOptions: {
|
|
5152
|
+
output: {
|
|
5153
|
+
manualChunks: getManualChunks
|
|
5089
5154
|
}
|
|
5090
5155
|
}
|
|
5091
5156
|
},
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5157
|
+
optimizeDeps: {
|
|
5158
|
+
include: [
|
|
5159
|
+
"react",
|
|
5160
|
+
"react-dom",
|
|
5161
|
+
"react/jsx-runtime",
|
|
5162
|
+
"react/jsx-dev-runtime",
|
|
5163
|
+
"rsc-html-stream/client"
|
|
5164
|
+
],
|
|
5165
|
+
exclude: excludeDeps,
|
|
5166
|
+
esbuildOptions: sharedEsbuildOptions,
|
|
5167
|
+
entries: [VIRTUAL_IDS.browser]
|
|
5168
|
+
}
|
|
5169
|
+
},
|
|
5170
|
+
ssr: {
|
|
5171
|
+
optimizeDeps: {
|
|
5172
|
+
entries: [VIRTUAL_IDS.ssr],
|
|
5173
|
+
include: [
|
|
5174
|
+
"react",
|
|
5175
|
+
"react-dom",
|
|
5176
|
+
"react-dom/server.edge",
|
|
5177
|
+
"react-dom/static.edge",
|
|
5178
|
+
"react/jsx-runtime",
|
|
5179
|
+
"react/jsx-dev-runtime",
|
|
5180
|
+
"@vitejs/plugin-rsc/vendor/react-server-dom/client.edge"
|
|
5181
|
+
],
|
|
5182
|
+
exclude: excludeDeps,
|
|
5183
|
+
esbuildOptions: sharedEsbuildOptions
|
|
5184
|
+
}
|
|
5185
|
+
},
|
|
5186
|
+
rsc: {
|
|
5187
|
+
optimizeDeps: {
|
|
5188
|
+
entries: [VIRTUAL_IDS.rsc],
|
|
5189
|
+
include: [
|
|
5190
|
+
"react",
|
|
5191
|
+
"react/jsx-runtime",
|
|
5192
|
+
"react/jsx-dev-runtime",
|
|
5193
|
+
"@vitejs/plugin-rsc/vendor/react-server-dom/server.edge"
|
|
5194
|
+
],
|
|
5195
|
+
esbuildOptions: sharedEsbuildOptions
|
|
5106
5196
|
}
|
|
5107
5197
|
}
|
|
5108
|
-
};
|
|
5109
|
-
},
|
|
5110
|
-
configResolved(config) {
|
|
5111
|
-
if (showBanner) {
|
|
5112
|
-
const mode = config.command === "serve" ? process.argv.includes("preview") ? "preview" : "dev" : "build";
|
|
5113
|
-
printBanner(mode, "node", rangoVersion);
|
|
5114
|
-
}
|
|
5115
|
-
const rscMinimalCount = config.plugins.filter(
|
|
5116
|
-
(p) => p.name === "rsc:minimal"
|
|
5117
|
-
).length;
|
|
5118
|
-
if (rscMinimalCount > 1 && !hasWarnedDuplicate) {
|
|
5119
|
-
hasWarnedDuplicate = true;
|
|
5120
|
-
console.warn(
|
|
5121
|
-
"[rsc-router] Duplicate @vitejs/plugin-rsc detected. Remove rsc() from your config or use rango({ rsc: false }) for manual configuration."
|
|
5122
|
-
);
|
|
5123
5198
|
}
|
|
5199
|
+
};
|
|
5200
|
+
},
|
|
5201
|
+
configResolved(config) {
|
|
5202
|
+
if (showBanner) {
|
|
5203
|
+
const mode = config.command === "serve" ? process.argv.includes("preview") ? "preview" : "dev" : "build";
|
|
5204
|
+
printBanner(mode, "node", rangoVersion);
|
|
5124
5205
|
}
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5206
|
+
const rscMinimalCount = config.plugins.filter(
|
|
5207
|
+
(p) => p.name === "rsc:minimal"
|
|
5208
|
+
).length;
|
|
5209
|
+
if (rscMinimalCount > 1 && !hasWarnedDuplicate) {
|
|
5210
|
+
hasWarnedDuplicate = true;
|
|
5211
|
+
console.warn(
|
|
5212
|
+
"[rsc-router] Duplicate @vitejs/plugin-rsc detected. Remove rsc() from your vite config \u2014 rango() includes it automatically."
|
|
5213
|
+
);
|
|
5214
|
+
}
|
|
5215
|
+
}
|
|
5216
|
+
});
|
|
5217
|
+
plugins.push(createVirtualEntriesPlugin(finalEntries, routerRef));
|
|
5218
|
+
plugins.push(
|
|
5219
|
+
rsc({
|
|
5220
|
+
entries: finalEntries
|
|
5221
|
+
})
|
|
5222
|
+
);
|
|
5133
5223
|
plugins.push(clientRefDedup());
|
|
5134
5224
|
}
|
|
5135
5225
|
plugins.push({
|
|
@@ -5157,20 +5247,18 @@ ${list}`
|
|
|
5157
5247
|
plugins.push(createVersionPlugin());
|
|
5158
5248
|
const discoveryEntryPath = preset !== "cloudflare" ? routerRef.path : void 0;
|
|
5159
5249
|
const discoveryRouterRef = preset !== "cloudflare" ? routerRef : void 0;
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
plugins.push(createVersionInjectorPlugin(injectorEntryPath));
|
|
5250
|
+
if (preset === "cloudflare") {
|
|
5251
|
+
plugins.push(createVersionInjectorPlugin(void 0));
|
|
5163
5252
|
}
|
|
5164
5253
|
plugins.push(createCjsToEsmPlugin());
|
|
5165
5254
|
plugins.push(
|
|
5166
5255
|
createRouterDiscoveryPlugin(discoveryEntryPath, {
|
|
5167
5256
|
routerPathRef: discoveryRouterRef,
|
|
5168
5257
|
enableBuildPrerender: prerenderEnabled,
|
|
5169
|
-
staticRouteTypesGeneration: resolvedOptions.staticRouteTypesGeneration
|
|
5170
|
-
include: resolvedOptions.include,
|
|
5171
|
-
exclude: resolvedOptions.exclude
|
|
5258
|
+
staticRouteTypesGeneration: resolvedOptions.staticRouteTypesGeneration
|
|
5172
5259
|
})
|
|
5173
5260
|
);
|
|
5261
|
+
plugins.push(performanceTracksPlugin());
|
|
5174
5262
|
return plugins;
|
|
5175
5263
|
}
|
|
5176
5264
|
|