@rangojs/router 0.0.0-experimental.b9cb8739 → 0.0.0-experimental.bd6e11bc
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 +196 -43
- package/dist/bin/rango.js +277 -99
- package/dist/testing/vitest.js +48 -0
- package/dist/vite/index.js +2779 -1064
- package/dist/vite/index.js.bak +5448 -0
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +57 -11
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +243 -21
- package/skills/caching/SKILL.md +155 -6
- package/skills/composability/SKILL.md +27 -2
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +364 -0
- package/skills/hooks/SKILL.md +229 -20
- package/skills/host-router/SKILL.md +45 -20
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +46 -4
- package/skills/layout/SKILL.md +28 -7
- package/skills/links/SKILL.md +249 -17
- package/skills/loader/SKILL.md +273 -53
- package/skills/middleware/SKILL.md +49 -12
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/observability/SKILL.md +137 -0
- package/skills/parallel/SKILL.md +197 -6
- package/skills/prerender/SKILL.md +123 -100
- package/skills/rango/SKILL.md +242 -22
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +66 -9
- package/skills/route/SKILL.md +88 -4
- package/skills/router-setup/SKILL.md +90 -5
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/testing/SKILL.md +716 -0
- package/skills/typesafety/SKILL.md +329 -27
- package/skills/use-cache/SKILL.md +34 -5
- package/skills/view-transitions/SKILL.md +294 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +117 -0
- package/src/__internal.ts +1 -1
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +91 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/navigation-bridge.ts +102 -16
- package/src/browser/navigation-client.ts +164 -59
- package/src/browser/navigation-store.ts +75 -17
- package/src/browser/navigation-transaction.ts +21 -37
- package/src/browser/partial-update.ts +139 -38
- package/src/browser/prefetch/cache.ts +175 -15
- package/src/browser/prefetch/fetch.ts +180 -33
- package/src/browser/prefetch/queue.ts +123 -20
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +81 -9
- package/src/browser/react/NavigationProvider.tsx +110 -33
- package/src/browser/react/context.ts +7 -2
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/index.ts +3 -0
- package/src/browser/react/location-state-shared.ts +175 -4
- package/src/browser/react/location-state.ts +39 -13
- package/src/browser/react/use-handle.ts +23 -64
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +20 -8
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +43 -10
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +25 -0
- package/src/browser/rsc-router.tsx +191 -74
- package/src/browser/scroll-restoration.ts +41 -14
- package/src/browser/segment-reconciler.ts +36 -9
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +31 -36
- package/src/browser/types.ts +57 -5
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +65 -40
- package/src/build/generate-route-types.ts +5 -0
- package/src/build/index.ts +2 -0
- package/src/build/route-trie.ts +52 -25
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +9 -2
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +278 -88
- package/src/build/route-types/scan-filter.ts +9 -2
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-runtime.ts +15 -11
- package/src/cache/cache-scope.ts +76 -49
- package/src/cache/cf/cf-cache-store.ts +501 -18
- 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/client.rsc.tsx +3 -0
- package/src/client.tsx +94 -238
- package/src/context-var.ts +72 -2
- package/src/debug.ts +2 -2
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -1
- package/src/handle.ts +65 -12
- package/src/host/index.ts +2 -2
- package/src/host/router.ts +129 -57
- package/src/host/types.ts +31 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +140 -20
- package/src/index.rsc.ts +12 -5
- package/src/index.ts +61 -11
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +2 -5
- package/src/loader.ts +3 -10
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender/store.ts +5 -4
- package/src/prerender.ts +141 -80
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -15
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +435 -260
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +110 -34
- package/src/route-definition/index.ts +3 -0
- package/src/route-definition/redirect.ts +11 -3
- package/src/route-definition/resolve-handler-use.ts +155 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-map-builder.ts +7 -1
- package/src/route-types.ts +37 -41
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +113 -1
- package/src/router/error-handling.ts +1 -1
- package/src/router/find-match.ts +4 -2
- package/src/router/handler-context.ts +77 -38
- package/src/router/intercept-resolution.ts +15 -22
- package/src/router/lazy-includes.ts +12 -9
- package/src/router/loader-resolution.ts +174 -22
- package/src/router/logging.ts +5 -2
- package/src/router/manifest.ts +31 -16
- package/src/router/match-api.ts +128 -192
- package/src/router/match-handlers.ts +63 -20
- package/src/router/match-middleware/background-revalidation.ts +30 -2
- package/src/router/match-middleware/cache-lookup.ts +136 -106
- package/src/router/match-middleware/cache-store.ts +54 -10
- package/src/router/match-middleware/intercept-resolution.ts +9 -7
- package/src/router/match-middleware/segment-resolution.ts +61 -5
- package/src/router/match-result.ts +125 -10
- package/src/router/metrics.ts +7 -2
- package/src/router/middleware-types.ts +21 -34
- package/src/router/middleware.ts +103 -90
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +101 -17
- package/src/router/prerender-match.ts +110 -10
- package/src/router/preview-match.ts +32 -102
- package/src/router/request-classification.ts +286 -0
- package/src/router/revalidation.ts +58 -2
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +6 -1
- package/src/router/router-interfaces.ts +77 -28
- package/src/router/router-options.ts +76 -11
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +223 -24
- 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 +466 -285
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/segment-wrappers.ts +2 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry.ts +99 -0
- package/src/router/trie-matching.ts +18 -13
- package/src/router/types.ts +9 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +91 -23
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +440 -381
- package/src/rsc/helpers.ts +91 -43
- package/src/rsc/index.ts +1 -1
- package/src/rsc/loader-fetch.ts +23 -3
- package/src/rsc/manifest-init.ts +5 -1
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/progressive-enhancement.ts +18 -2
- package/src/rsc/response-route-handler.ts +46 -53
- package/src/rsc/rsc-rendering.ts +41 -48
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +25 -37
- package/src/rsc/ssr-setup.ts +18 -2
- package/src/rsc/types.ts +17 -3
- package/src/search-params.ts +4 -4
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +219 -67
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +277 -61
- package/src/server/cookie-store.ts +28 -4
- package/src/server/handle-store.ts +19 -0
- package/src/server/loader-registry.ts +9 -8
- package/src/server/request-context.ts +204 -60
- package/src/ssr/index.tsx +9 -1
- package/src/static-handler.ts +19 -7
- package/src/testing/cache-status.ts +166 -0
- package/src/testing/collect-handle.ts +63 -0
- package/src/testing/dispatch.ts +440 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +154 -0
- package/src/testing/e2e/index.ts +149 -0
- package/src/testing/e2e/matchers.ts +51 -0
- package/src/testing/e2e/page-helpers.ts +272 -0
- package/src/testing/e2e/parity.ts +306 -0
- package/src/testing/e2e/server.ts +183 -0
- package/src/testing/flight-matchers.ts +104 -0
- package/src/testing/flight-runtime.d.ts +21 -0
- package/src/testing/flight.entry.ts +22 -0
- package/src/testing/flight.ts +182 -0
- package/src/testing/generated-routes.ts +223 -0
- package/src/testing/index.ts +106 -0
- package/src/testing/internal/context.ts +255 -0
- package/src/testing/render-route.tsx +565 -0
- package/src/testing/run-loader.ts +296 -0
- package/src/testing/run-middleware.ts +179 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
- package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
- package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
- package/src/testing/vitest-stubs/version.ts +5 -0
- package/src/testing/vitest.ts +183 -0
- package/src/types/cache-types.ts +4 -4
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +194 -72
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +41 -15
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-entry.ts +19 -1
- package/src/types/segments.ts +37 -1
- package/src/urls/include-helper.ts +34 -67
- package/src/urls/index.ts +0 -3
- package/src/urls/path-helper-types.ts +50 -9
- package/src/urls/path-helper.ts +63 -63
- package/src/urls/pattern-types.ts +48 -19
- package/src/urls/response-types.ts +25 -22
- package/src/urls/type-extraction.ts +26 -116
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +487 -44
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +34 -37
- package/src/vite/discovery/discover-routers.ts +105 -51
- package/src/vite/discovery/discovery-errors.ts +194 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +188 -93
- package/src/vite/discovery/route-types-writer.ts +40 -84
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +46 -6
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +6 -0
- package/src/vite/plugin-types.ts +111 -72
- package/src/vite/plugins/cjs-to-esm.ts +8 -7
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +28 -5
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/expose-action-id.ts +55 -33
- package/src/vite/plugins/expose-id-utils.ts +24 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +12 -35
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +544 -317
- package/src/vite/plugins/performance-tracks.ts +92 -0
- package/src/vite/plugins/refresh-cmd.ts +88 -26
- package/src/vite/plugins/use-cache-transform.ts +65 -50
- package/src/vite/plugins/version-injector.ts +39 -23
- package/src/vite/plugins/version-plugin.ts +72 -3
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +265 -226
- package/src/vite/router-discovery.ts +920 -137
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +4 -4
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/client-chunks.ts +190 -0
- package/src/vite/utils/forward-user-plugins.ts +193 -0
- package/src/vite/utils/manifest-utils.ts +21 -5
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +38 -5
- package/src/vite/utils/shared-utils.ts +109 -27
- package/src/browser/action-response-classifier.ts +0 -99
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
stageBuildAssetModule,
|
|
17
17
|
} from "../utils/prerender-utils.js";
|
|
18
18
|
import type { DiscoveryState } from "./state.js";
|
|
19
|
+
import { createRangoDebugger, NS } from "../debug.js";
|
|
20
|
+
|
|
21
|
+
const debug = createRangoDebugger(NS.prerender);
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Expand prerender routes into concrete URLs and render them via the
|
|
@@ -30,6 +33,12 @@ export async function expandPrerenderRoutes(
|
|
|
30
33
|
): Promise<void> {
|
|
31
34
|
if (!state.opts?.enableBuildPrerender || !state.isBuildMode) return;
|
|
32
35
|
|
|
36
|
+
const overallStart = debug ? performance.now() : 0;
|
|
37
|
+
debug?.(
|
|
38
|
+
"expandPrerenderRoutes: start (%d router manifest(s))",
|
|
39
|
+
allManifests.length,
|
|
40
|
+
);
|
|
41
|
+
|
|
33
42
|
type PrerenderEntry = {
|
|
34
43
|
urlPath: string;
|
|
35
44
|
routeName: string;
|
|
@@ -51,103 +60,172 @@ export async function expandPrerenderRoutes(
|
|
|
51
60
|
return substituteRouteParams(pattern, params);
|
|
52
61
|
};
|
|
53
62
|
|
|
63
|
+
let resolvedRoutes = 0;
|
|
64
|
+
let totalDynamic = 0;
|
|
65
|
+
|
|
66
|
+
// Count dynamic routes upfront for progress reporting
|
|
54
67
|
for (const { manifest } of allManifests) {
|
|
55
68
|
if (!manifest.prerenderRoutes) continue;
|
|
56
|
-
const defs = manifest._prerenderDefs || {};
|
|
57
69
|
for (const routeName of manifest.prerenderRoutes) {
|
|
58
70
|
const pattern = manifest.routeManifest[routeName];
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
if (pattern && (pattern.includes(":") || pattern.includes("*"))) {
|
|
72
|
+
totalDynamic++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Periodic progress log so long getParams() calls don't look stalled
|
|
78
|
+
const paramsStart = performance.now();
|
|
79
|
+
const progressInterval =
|
|
80
|
+
totalDynamic > 0
|
|
81
|
+
? setInterval(() => {
|
|
82
|
+
const elapsed = ((performance.now() - paramsStart) / 1000).toFixed(1);
|
|
83
|
+
console.log(
|
|
84
|
+
`[rango] Resolving prerender params... ${resolvedRoutes}/${totalDynamic} routes (${elapsed}s)`,
|
|
85
|
+
);
|
|
86
|
+
}, 5000)
|
|
87
|
+
: undefined;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
for (const { manifest } of allManifests) {
|
|
91
|
+
if (!manifest.prerenderRoutes) continue;
|
|
92
|
+
const defs = manifest._prerenderDefs || {};
|
|
93
|
+
const passthroughSet = new Set(manifest.passthroughRoutes || []);
|
|
94
|
+
for (const routeName of manifest.prerenderRoutes) {
|
|
95
|
+
const pattern = manifest.routeManifest[routeName];
|
|
96
|
+
if (!pattern) continue;
|
|
97
|
+
const def = defs[routeName];
|
|
98
|
+
const isPassthroughRoute = passthroughSet.has(routeName);
|
|
99
|
+
const hasDynamic = pattern.includes(":") || pattern.includes("*");
|
|
100
|
+
if (!hasDynamic) {
|
|
101
|
+
// Static route: use pattern directly (strip trailing slash for URL)
|
|
102
|
+
entries.push({
|
|
103
|
+
urlPath: pattern.replace(/\/$/, "") || "/",
|
|
104
|
+
routeName,
|
|
105
|
+
concurrency: 1,
|
|
106
|
+
isPassthroughRoute,
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
// Dynamic route: call getParams() to enumerate param combinations
|
|
110
|
+
if (def?.getParams) {
|
|
111
|
+
const getParamsStart = debug ? performance.now() : 0;
|
|
112
|
+
try {
|
|
113
|
+
const buildVars: Record<string, any> = {};
|
|
114
|
+
const buildEnv = state.resolvedBuildEnv;
|
|
115
|
+
const getParamsCtx = {
|
|
116
|
+
build: true as const,
|
|
117
|
+
dev: !state.isBuildMode,
|
|
118
|
+
set: ((keyOrVar: any, value: any) => {
|
|
119
|
+
contextSet(buildVars, keyOrVar, value);
|
|
120
|
+
}) as any,
|
|
121
|
+
reverse: getParamsReverse,
|
|
122
|
+
get env() {
|
|
123
|
+
if (buildEnv !== undefined) return buildEnv;
|
|
124
|
+
throw new Error(
|
|
125
|
+
"[rango] ctx.env is not available during build-time getParams(). " +
|
|
126
|
+
"Configure buildEnv in your rango() plugin options to enable build-time env access.",
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const paramsList = await def.getParams(getParamsCtx);
|
|
131
|
+
debug?.(
|
|
132
|
+
"getParams %s -> %d params (%sms)",
|
|
133
|
+
routeName,
|
|
134
|
+
paramsList.length,
|
|
135
|
+
(performance.now() - getParamsStart).toFixed(1),
|
|
93
136
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
137
|
+
const concurrency = def.options?.concurrency ?? 1;
|
|
138
|
+
const hasBuildVars =
|
|
139
|
+
Object.keys(buildVars).length > 0 ||
|
|
140
|
+
Object.getOwnPropertySymbols(buildVars).length > 0;
|
|
141
|
+
for (const params of paramsList) {
|
|
142
|
+
let url = substituteRouteParams(
|
|
143
|
+
pattern,
|
|
144
|
+
params as Record<string, string>,
|
|
145
|
+
encodePathParam,
|
|
146
|
+
);
|
|
147
|
+
// Anonymous wildcard fallback: use conventional keys if provided
|
|
148
|
+
if (url.includes("*")) {
|
|
149
|
+
const wildcardValue =
|
|
150
|
+
(params as Record<string, string>)["*"] ??
|
|
151
|
+
(params as Record<string, string>).splat;
|
|
152
|
+
if (wildcardValue !== undefined) {
|
|
153
|
+
url = url.replace(
|
|
154
|
+
/\*[^/]*$/,
|
|
155
|
+
encodePathParam(wildcardValue),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
101
158
|
}
|
|
159
|
+
entries.push({
|
|
160
|
+
urlPath: url.replace(/\/$/, "") || "/",
|
|
161
|
+
routeName,
|
|
162
|
+
concurrency,
|
|
163
|
+
...(hasBuildVars ? { buildVars } : {}),
|
|
164
|
+
isPassthroughRoute,
|
|
165
|
+
});
|
|
102
166
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
167
|
+
resolvedRoutes++;
|
|
168
|
+
} catch (err: any) {
|
|
169
|
+
resolvedRoutes++;
|
|
170
|
+
// Skip in getParams() skips the entire route
|
|
171
|
+
if (err.name === "Skip") {
|
|
172
|
+
console.log(
|
|
173
|
+
`[rango] SKIP route "${routeName}" - ${err.message}`,
|
|
174
|
+
);
|
|
175
|
+
notifyOnError(
|
|
176
|
+
registry,
|
|
177
|
+
err,
|
|
178
|
+
"prerender",
|
|
179
|
+
routeName,
|
|
180
|
+
undefined,
|
|
181
|
+
true,
|
|
182
|
+
);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
// Regular error: fail the build
|
|
186
|
+
console.error(
|
|
187
|
+
`[rango] Failed to get params for prerender route "${routeName}": ${err.message}`,
|
|
124
188
|
);
|
|
125
|
-
|
|
189
|
+
notifyOnError(registry, err, "prerender", routeName);
|
|
190
|
+
throw err;
|
|
126
191
|
}
|
|
127
|
-
|
|
128
|
-
console.
|
|
129
|
-
`[
|
|
192
|
+
} else {
|
|
193
|
+
console.warn(
|
|
194
|
+
`[rango] Dynamic prerender route "${routeName}" has no getParams(), skipping`,
|
|
130
195
|
);
|
|
131
|
-
notifyOnError(registry, err, "prerender", routeName);
|
|
132
|
-
throw err;
|
|
133
196
|
}
|
|
134
|
-
} else {
|
|
135
|
-
console.warn(
|
|
136
|
-
`[rsc-router] Dynamic prerender route "${routeName}" has no getParams(), skipping`,
|
|
137
|
-
);
|
|
138
197
|
}
|
|
139
198
|
}
|
|
140
199
|
}
|
|
200
|
+
} finally {
|
|
201
|
+
if (progressInterval) {
|
|
202
|
+
clearInterval(progressInterval);
|
|
203
|
+
const elapsed = ((performance.now() - paramsStart) / 1000).toFixed(1);
|
|
204
|
+
console.log(
|
|
205
|
+
`[rango] Resolved prerender params: ${resolvedRoutes}/${totalDynamic} routes (${elapsed}s)`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
141
208
|
}
|
|
142
209
|
|
|
143
|
-
if (entries.length === 0)
|
|
210
|
+
if (entries.length === 0) {
|
|
211
|
+
debug?.(
|
|
212
|
+
"no prerender entries (done in %sms)",
|
|
213
|
+
(performance.now() - overallStart).toFixed(1),
|
|
214
|
+
);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
144
217
|
|
|
145
218
|
// Determine the max concurrency for the log header
|
|
146
219
|
const maxConcurrency = Math.max(...entries.map((e) => e.concurrency));
|
|
147
220
|
const concurrencyNote =
|
|
148
221
|
maxConcurrency > 1 ? ` (concurrency: ${maxConcurrency})` : "";
|
|
149
222
|
console.log(
|
|
150
|
-
`[
|
|
223
|
+
`[rango] Pre-rendering ${entries.length} URL(s)${concurrencyNote}...`,
|
|
224
|
+
);
|
|
225
|
+
debug?.(
|
|
226
|
+
"prerender loop: %d entries, max concurrency %d",
|
|
227
|
+
entries.length,
|
|
228
|
+
maxConcurrency,
|
|
151
229
|
);
|
|
152
230
|
|
|
153
231
|
const { hashParams } = await rscEnv.runner.import("@rangojs/router/build");
|
|
@@ -175,6 +253,7 @@ export async function expandPrerenderRoutes(
|
|
|
175
253
|
{},
|
|
176
254
|
entry.buildVars,
|
|
177
255
|
entry.isPassthroughRoute,
|
|
256
|
+
state.resolvedBuildEnv,
|
|
178
257
|
);
|
|
179
258
|
if (!result) continue;
|
|
180
259
|
|
|
@@ -182,7 +261,7 @@ export async function expandPrerenderRoutes(
|
|
|
182
261
|
if (result.passthrough) {
|
|
183
262
|
const elapsed = (performance.now() - startUrl).toFixed(0);
|
|
184
263
|
console.log(
|
|
185
|
-
`[
|
|
264
|
+
`[rango] PASS ${entry.urlPath.padEnd(40)} (${elapsed}ms) - live fallback`,
|
|
186
265
|
);
|
|
187
266
|
doneCount++;
|
|
188
267
|
break;
|
|
@@ -216,7 +295,7 @@ export async function expandPrerenderRoutes(
|
|
|
216
295
|
}
|
|
217
296
|
const elapsed = (performance.now() - startUrl).toFixed(0);
|
|
218
297
|
console.log(
|
|
219
|
-
`[
|
|
298
|
+
`[rango] OK ${entry.urlPath.padEnd(40)} (${elapsed}ms)`,
|
|
220
299
|
);
|
|
221
300
|
doneCount++;
|
|
222
301
|
break;
|
|
@@ -224,7 +303,7 @@ export async function expandPrerenderRoutes(
|
|
|
224
303
|
if (err.name === "Skip") {
|
|
225
304
|
const elapsed = (performance.now() - startUrl).toFixed(0);
|
|
226
305
|
console.log(
|
|
227
|
-
`[
|
|
306
|
+
`[rango] SKIP ${entry.urlPath.padEnd(40)} (${elapsed}ms) - ${err.message}`,
|
|
228
307
|
);
|
|
229
308
|
skipCount++;
|
|
230
309
|
notifyOnError(
|
|
@@ -240,7 +319,7 @@ export async function expandPrerenderRoutes(
|
|
|
240
319
|
// Regular error: log, notify, and fail the build
|
|
241
320
|
const elapsed = (performance.now() - startUrl).toFixed(0);
|
|
242
321
|
console.error(
|
|
243
|
-
`[
|
|
322
|
+
`[rango] FAIL ${entry.urlPath.padEnd(40)} (${elapsed}ms) - ${err.message}`,
|
|
244
323
|
);
|
|
245
324
|
notifyOnError(
|
|
246
325
|
registry,
|
|
@@ -263,7 +342,14 @@ export async function expandPrerenderRoutes(
|
|
|
263
342
|
const parts = [`${doneCount} done`];
|
|
264
343
|
if (skipCount > 0) parts.push(`${skipCount} skipped`);
|
|
265
344
|
console.log(
|
|
266
|
-
`[
|
|
345
|
+
`[rango] Pre-render complete: ${parts.join(", ")} (${totalElapsed}ms total)`,
|
|
346
|
+
);
|
|
347
|
+
debug?.(
|
|
348
|
+
"expandPrerenderRoutes done: %d done, %d skipped, %sms (overall %sms)",
|
|
349
|
+
doneCount,
|
|
350
|
+
skipCount,
|
|
351
|
+
totalElapsed,
|
|
352
|
+
(performance.now() - overallStart).toFixed(1),
|
|
267
353
|
);
|
|
268
354
|
}
|
|
269
355
|
|
|
@@ -285,6 +371,12 @@ export async function renderStaticHandlers(
|
|
|
285
371
|
)
|
|
286
372
|
return;
|
|
287
373
|
|
|
374
|
+
const overallStart = debug ? performance.now() : 0;
|
|
375
|
+
debug?.(
|
|
376
|
+
"renderStaticHandlers: start (%d static module(s))",
|
|
377
|
+
state.resolvedStaticModules.size,
|
|
378
|
+
);
|
|
379
|
+
|
|
288
380
|
const manifestEntries: Record<string, string> = {};
|
|
289
381
|
let staticDone = 0;
|
|
290
382
|
let staticSkip = 0;
|
|
@@ -295,9 +387,7 @@ export async function renderStaticHandlers(
|
|
|
295
387
|
totalStaticCount += exportNames.length;
|
|
296
388
|
}
|
|
297
389
|
const startStatic = performance.now();
|
|
298
|
-
console.log(
|
|
299
|
-
`[rsc-router] Rendering ${totalStaticCount} static handler(s)...`,
|
|
300
|
-
);
|
|
390
|
+
console.log(`[rango] Rendering ${totalStaticCount} static handler(s)...`);
|
|
301
391
|
|
|
302
392
|
for (const [moduleId, exportNames] of state.resolvedStaticModules) {
|
|
303
393
|
let mod: any;
|
|
@@ -305,7 +395,7 @@ export async function renderStaticHandlers(
|
|
|
305
395
|
mod = await rscEnv!.runner.import(moduleId);
|
|
306
396
|
} catch (err: any) {
|
|
307
397
|
console.error(
|
|
308
|
-
`[
|
|
398
|
+
`[rango] Failed to import static module ${moduleId}: ${err.message}`,
|
|
309
399
|
);
|
|
310
400
|
notifyOnError(registry, err, "static");
|
|
311
401
|
throw err;
|
|
@@ -326,6 +416,8 @@ export async function renderStaticHandlers(
|
|
|
326
416
|
def.handler,
|
|
327
417
|
def.$$id,
|
|
328
418
|
(def as any).$$routePrefix,
|
|
419
|
+
state.resolvedBuildEnv,
|
|
420
|
+
!state.isBuildMode,
|
|
329
421
|
);
|
|
330
422
|
if (result) {
|
|
331
423
|
const hasHandles = Object.keys(result.handles).length > 0;
|
|
@@ -338,9 +430,7 @@ export async function renderStaticHandlers(
|
|
|
338
430
|
exportValue,
|
|
339
431
|
);
|
|
340
432
|
const elapsed = (performance.now() - startHandler).toFixed(0);
|
|
341
|
-
console.log(
|
|
342
|
-
`[rsc-router] OK ${name.padEnd(40)} (${elapsed}ms)`,
|
|
343
|
-
);
|
|
433
|
+
console.log(`[rango] OK ${name.padEnd(40)} (${elapsed}ms)`);
|
|
344
434
|
staticDone++;
|
|
345
435
|
handled = true;
|
|
346
436
|
break;
|
|
@@ -349,7 +439,7 @@ export async function renderStaticHandlers(
|
|
|
349
439
|
if (err.name === "Skip") {
|
|
350
440
|
const elapsed = (performance.now() - startHandler).toFixed(0);
|
|
351
441
|
console.log(
|
|
352
|
-
`[
|
|
442
|
+
`[rango] SKIP ${name.padEnd(40)} (${elapsed}ms) - ${err.message}`,
|
|
353
443
|
);
|
|
354
444
|
staticSkip++;
|
|
355
445
|
notifyOnError(registry, err, "static", undefined, undefined, true);
|
|
@@ -359,16 +449,14 @@ export async function renderStaticHandlers(
|
|
|
359
449
|
// Regular error: log, notify, and fail the build
|
|
360
450
|
const elapsed = (performance.now() - startHandler).toFixed(0);
|
|
361
451
|
console.error(
|
|
362
|
-
`[
|
|
452
|
+
`[rango] FAIL ${name.padEnd(40)} (${elapsed}ms) - ${err.message}`,
|
|
363
453
|
);
|
|
364
454
|
notifyOnError(registry, err, "static");
|
|
365
455
|
throw err;
|
|
366
456
|
}
|
|
367
457
|
}
|
|
368
458
|
if (!handled) {
|
|
369
|
-
console.warn(
|
|
370
|
-
`[rsc-router] No router could render static handler "${name}"`,
|
|
371
|
-
);
|
|
459
|
+
console.warn(`[rango] No router could render static handler "${name}"`);
|
|
372
460
|
}
|
|
373
461
|
}
|
|
374
462
|
}
|
|
@@ -380,6 +468,13 @@ export async function renderStaticHandlers(
|
|
|
380
468
|
const staticParts = [`${staticDone} done`];
|
|
381
469
|
if (staticSkip > 0) staticParts.push(`${staticSkip} skipped`);
|
|
382
470
|
console.log(
|
|
383
|
-
`[
|
|
471
|
+
`[rango] Static render complete: ${staticParts.join(", ")} (${totalStaticElapsed}ms total)`,
|
|
472
|
+
);
|
|
473
|
+
debug?.(
|
|
474
|
+
"renderStaticHandlers done: %d done, %d skipped, %sms (overall %sms)",
|
|
475
|
+
staticDone,
|
|
476
|
+
staticSkip,
|
|
477
|
+
totalStaticElapsed,
|
|
478
|
+
(performance.now() - overallStart).toFixed(1),
|
|
384
479
|
);
|
|
385
480
|
}
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* from discovered router manifests and static source parsing.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { dirname,
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
9
|
import { readFileSync, writeFileSync, existsSync, unlinkSync } from "node:fs";
|
|
10
10
|
import {
|
|
11
11
|
generateRouteTypesSource,
|
|
12
12
|
writeCombinedRouteTypes,
|
|
13
13
|
findRouterFiles,
|
|
14
14
|
buildCombinedRouteMapForRouterFile,
|
|
15
|
+
genFileTsPath,
|
|
16
|
+
resolveSearchSchemas,
|
|
15
17
|
} from "../../build/generate-route-types.js";
|
|
16
18
|
import type { DiscoveryState } from "./state.js";
|
|
17
19
|
import { markSelfGenWrite } from "./self-gen-tracking.js";
|
|
@@ -35,6 +37,22 @@ function filterUserNamedRoutes(
|
|
|
35
37
|
return filtered;
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
// Write a gen file only when content changed, marking the write as
|
|
41
|
+
// self-generated BEFORE writeFileSync so the watcher distinguishes it from a
|
|
42
|
+
// manual edit (the HMR self-gen-loop guard).
|
|
43
|
+
function writeGenFileIfChanged(
|
|
44
|
+
state: DiscoveryState,
|
|
45
|
+
outPath: string,
|
|
46
|
+
source: string,
|
|
47
|
+
opts?: { log?: boolean },
|
|
48
|
+
): void {
|
|
49
|
+
const existing = existsSync(outPath) ? readFileSync(outPath, "utf-8") : null;
|
|
50
|
+
if (existing === source) return;
|
|
51
|
+
markSelfGenWrite(state, outPath, source);
|
|
52
|
+
writeFileSync(outPath, source);
|
|
53
|
+
if (opts?.log) console.log(`[rango] Generated route types -> ${outPath}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
/**
|
|
39
57
|
* Write combined route types for all router files.
|
|
40
58
|
* Only writes when content has changed to avoid triggering HMR loops.
|
|
@@ -48,45 +66,16 @@ export function writeCombinedRouteTypesWithTracking(
|
|
|
48
66
|
findRouterFiles(state.projectRoot, state.scanFilter);
|
|
49
67
|
state.cachedRouterFiles = routerFiles;
|
|
50
68
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
preContent.set(outPath, readFileSync(outPath, "utf-8"));
|
|
62
|
-
} catch {
|
|
63
|
-
// File doesn't exist yet — any write is a real change.
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
writeCombinedRouteTypes(state.projectRoot, routerFiles, opts);
|
|
68
|
-
|
|
69
|
-
// Mark only files that were actually written so the watcher can
|
|
70
|
-
// distinguish self-triggered change events from manual edits.
|
|
71
|
-
// Marking unchanged files creates stale entries that interfere with
|
|
72
|
-
// multi-server setups (e.g. shared webServer + isolated HMR server).
|
|
73
|
-
for (const routerFilePath of routerFiles) {
|
|
74
|
-
const routerDir = dirname(routerFilePath);
|
|
75
|
-
const routerBasename = basename(routerFilePath).replace(
|
|
76
|
-
/\.(tsx?|jsx?)$/,
|
|
77
|
-
"",
|
|
78
|
-
);
|
|
79
|
-
const outPath = join(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
80
|
-
if (!existsSync(outPath)) continue;
|
|
81
|
-
try {
|
|
82
|
-
const content = readFileSync(outPath, "utf-8");
|
|
83
|
-
if (content !== preContent.get(outPath)) {
|
|
84
|
-
markSelfGenWrite(state, outPath, content);
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// Ignore transient fs errors while files are being rewritten.
|
|
88
|
-
}
|
|
89
|
-
}
|
|
69
|
+
// Mark each gen file as self-generated BEFORE it is written, via the onWrite
|
|
70
|
+
// callback fired at every writeFileSync site, so the watcher distinguishes
|
|
71
|
+
// self-triggered change events from manual edits. The callback fires only
|
|
72
|
+
// for files actually written, so unchanged files are never marked (stale
|
|
73
|
+
// entries interfere with multi-server setups such as a shared webServer plus
|
|
74
|
+
// an isolated HMR server).
|
|
75
|
+
writeCombinedRouteTypes(state.projectRoot, routerFiles, {
|
|
76
|
+
...opts,
|
|
77
|
+
onWrite: (outPath, content) => markSelfGenWrite(state, outPath, content),
|
|
78
|
+
});
|
|
90
79
|
}
|
|
91
80
|
|
|
92
81
|
/**
|
|
@@ -104,7 +93,7 @@ export function writeRouteTypesFiles(state: DiscoveryState): void {
|
|
|
104
93
|
if (existsSync(oldCombinedPath)) {
|
|
105
94
|
unlinkSync(oldCombinedPath);
|
|
106
95
|
console.log(
|
|
107
|
-
`[
|
|
96
|
+
`[rango] Removed stale combined route types: ${oldCombinedPath}`,
|
|
108
97
|
);
|
|
109
98
|
}
|
|
110
99
|
} catch {}
|
|
@@ -122,40 +111,22 @@ export function writeRouteTypesFiles(state: DiscoveryState): void {
|
|
|
122
111
|
// the wrong location, causing non-deterministic type resolution.
|
|
123
112
|
if (sourceFile.includes("node_modules")) {
|
|
124
113
|
throw new Error(
|
|
125
|
-
`[
|
|
114
|
+
`[rango] Router "${id}" has sourceFile inside node_modules: ${sourceFile}\n` +
|
|
126
115
|
`This means createRouter() stack trace parsing matched a Vite internal frame.\n` +
|
|
127
116
|
`Set an explicit \`id\` on createRouter() or check the call site.`,
|
|
128
117
|
);
|
|
129
118
|
}
|
|
130
119
|
|
|
131
|
-
const
|
|
132
|
-
const routerBasename = basename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
|
|
133
|
-
const outPath = join(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
120
|
+
const outPath = genFileTsPath(sourceFile);
|
|
134
121
|
|
|
135
122
|
// Filter out auto-generated route names (e.g. "$path____debug_reverse-test")
|
|
136
123
|
// to match the static parser's output and prevent HMR oscillation.
|
|
137
124
|
const userRoutes = filterUserNamedRoutes(routeManifest);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
(!effectiveSearchSchemas ||
|
|
144
|
-
Object.keys(effectiveSearchSchemas).length === 0) &&
|
|
145
|
-
sourceFile
|
|
146
|
-
) {
|
|
147
|
-
const staticParsed = buildCombinedRouteMapForRouterFile(sourceFile);
|
|
148
|
-
if (Object.keys(staticParsed.searchSchemas).length > 0) {
|
|
149
|
-
const filtered: Record<string, Record<string, string>> = {};
|
|
150
|
-
for (const name of Object.keys(userRoutes)) {
|
|
151
|
-
const schema = staticParsed.searchSchemas[name];
|
|
152
|
-
if (schema) filtered[name] = schema;
|
|
153
|
-
}
|
|
154
|
-
if (Object.keys(filtered).length > 0) {
|
|
155
|
-
effectiveSearchSchemas = filtered;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
125
|
+
const effectiveSearchSchemas = resolveSearchSchemas(
|
|
126
|
+
Object.keys(userRoutes),
|
|
127
|
+
routeSearchSchemas,
|
|
128
|
+
sourceFile,
|
|
129
|
+
);
|
|
159
130
|
|
|
160
131
|
const source = generateRouteTypesSource(
|
|
161
132
|
userRoutes,
|
|
@@ -163,14 +134,7 @@ export function writeRouteTypesFiles(state: DiscoveryState): void {
|
|
|
163
134
|
? effectiveSearchSchemas
|
|
164
135
|
: undefined,
|
|
165
136
|
);
|
|
166
|
-
|
|
167
|
-
? readFileSync(outPath, "utf-8")
|
|
168
|
-
: null;
|
|
169
|
-
if (existing !== source) {
|
|
170
|
-
markSelfGenWrite(state, outPath, source);
|
|
171
|
-
writeFileSync(outPath, source);
|
|
172
|
-
console.log(`[rsc-router] Generated route types -> ${outPath}`);
|
|
173
|
-
}
|
|
137
|
+
writeGenFileIfChanged(state, outPath, source, { log: true });
|
|
174
138
|
}
|
|
175
139
|
}
|
|
176
140
|
|
|
@@ -236,22 +200,14 @@ export function supplementGenFilesWithRuntimeRoutes(
|
|
|
236
200
|
}
|
|
237
201
|
}
|
|
238
202
|
|
|
239
|
-
const
|
|
240
|
-
const routerBasename = basename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
|
|
241
|
-
const outPath = join(routerDir, `${routerBasename}.named-routes.gen.ts`);
|
|
203
|
+
const outPath = genFileTsPath(sourceFile);
|
|
242
204
|
const source = generateRouteTypesSource(
|
|
243
205
|
mergedRoutes,
|
|
244
206
|
Object.keys(mergedSearchSchemas).length > 0
|
|
245
207
|
? mergedSearchSchemas
|
|
246
208
|
: undefined,
|
|
247
209
|
);
|
|
248
|
-
|
|
249
|
-
? readFileSync(outPath, "utf-8")
|
|
250
|
-
: null;
|
|
251
|
-
if (existing !== source) {
|
|
252
|
-
markSelfGenWrite(state, outPath, source);
|
|
253
|
-
writeFileSync(outPath, source);
|
|
254
|
-
}
|
|
210
|
+
writeGenFileIfChanged(state, outPath, source);
|
|
255
211
|
}
|
|
256
212
|
// No manual manifest update needed: the virtual module imports the gen
|
|
257
213
|
// file, so Vite's HMR automatically re-evaluates it with fresh data.
|
|
@@ -22,6 +22,32 @@ export function markSelfGenWrite(
|
|
|
22
22
|
export function consumeSelfGenWrite(
|
|
23
23
|
state: DiscoveryState,
|
|
24
24
|
filePath: string,
|
|
25
|
+
): boolean {
|
|
26
|
+
return checkSelfGenWrite(state, filePath, true);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Non-consuming variant. Used by the `handleHotUpdate` plugin hook to
|
|
31
|
+
* suppress vite's HMR cascade for our own gen-file writes WITHOUT
|
|
32
|
+
* consuming the entry — `consumeSelfGenWrite` (called later from the
|
|
33
|
+
* chokidar `change` handler in `handleRouteFileChange`) still needs to
|
|
34
|
+
* see and consume the same entry to short-circuit our regen path.
|
|
35
|
+
*
|
|
36
|
+
* Both hooks fire for the same file change event:
|
|
37
|
+
* - `handleHotUpdate` runs first (vite's HMR pipeline).
|
|
38
|
+
* - chokidar `change` callback runs after (filesystem watcher).
|
|
39
|
+
*/
|
|
40
|
+
export function peekSelfGenWrite(
|
|
41
|
+
state: DiscoveryState,
|
|
42
|
+
filePath: string,
|
|
43
|
+
): boolean {
|
|
44
|
+
return checkSelfGenWrite(state, filePath, false);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function checkSelfGenWrite(
|
|
48
|
+
state: DiscoveryState,
|
|
49
|
+
filePath: string,
|
|
50
|
+
consume: boolean,
|
|
25
51
|
): boolean {
|
|
26
52
|
const info = state.selfWrittenGenFiles.get(filePath);
|
|
27
53
|
if (!info) return false;
|
|
@@ -33,7 +59,7 @@ export function consumeSelfGenWrite(
|
|
|
33
59
|
const current = readFileSync(filePath, "utf-8");
|
|
34
60
|
const currentHash = createHash("sha256").update(current).digest("hex");
|
|
35
61
|
if (currentHash === info.hash) {
|
|
36
|
-
state.selfWrittenGenFiles.delete(filePath);
|
|
62
|
+
if (consume) state.selfWrittenGenFiles.delete(filePath);
|
|
37
63
|
return true;
|
|
38
64
|
}
|
|
39
65
|
// Hash mismatch: file was changed externally. Keep the entry so a
|