@rangojs/router 0.20.0 → 0.22.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.
- package/dist/bin/rango.js +39 -15
- package/dist/types/browser/event-controller.d.ts +49 -0
- package/dist/types/browser/history-state.d.ts +16 -4
- package/dist/types/browser/navigation-store.d.ts +9 -0
- package/dist/types/browser/navigation-transaction.d.ts +7 -0
- package/dist/types/browser/partial-update.d.ts +2 -1
- package/dist/types/browser/prefetch/default-strategy.d.ts +16 -20
- package/dist/types/browser/rango-state.d.ts +3 -1
- package/dist/types/browser/react/NavigationProvider.d.ts +14 -1
- package/dist/types/browser/react/context.d.ts +25 -0
- package/dist/types/browser/react/location-state-shared.d.ts +84 -10
- package/dist/types/browser/react/location-state.d.ts +7 -2
- package/dist/types/browser/rsc-router.d.ts +13 -2
- package/dist/types/browser/types.d.ts +10 -0
- package/dist/types/build/generate-manifest.d.ts +2 -0
- package/dist/types/cache/background-task.d.ts +22 -0
- package/dist/types/cache/cache-key-utils.d.ts +50 -5
- package/dist/types/cache/cache-policy.d.ts +17 -0
- package/dist/types/cache/cache-scope.d.ts +5 -6
- package/dist/types/cache/cf/cf-cache-store.d.ts +34 -7
- package/dist/types/cache/cf/cf-cache-types.d.ts +12 -4
- package/dist/types/cache/document-cache.d.ts +8 -5
- package/dist/types/cache/handle-snapshot.d.ts +59 -50
- package/dist/types/cache/index.d.ts +3 -1
- package/dist/types/cache/invalidation-order.d.ts +14 -0
- package/dist/types/cache/memory-segment-store.d.ts +33 -1
- package/dist/types/cache/shell-snapshot.d.ts +29 -4
- package/dist/types/cache/store-scope.d.ts +22 -0
- package/dist/types/cache/tag-invalidation.d.ts +7 -6
- package/dist/types/cache/types.d.ts +84 -24
- package/dist/types/cache/vercel/vercel-cache-store.d.ts +35 -17
- package/dist/types/client-urls/navigation.d.ts +7 -1
- package/dist/types/client-urls/optimistic-location.d.ts +10 -4
- package/dist/types/errors.d.ts +6 -0
- package/dist/types/handles/deferred-resolution.d.ts +18 -1
- package/dist/types/internal-suspense-audit.d.ts +1 -0
- package/dist/types/loader-store.d.ts +4 -8
- package/dist/types/outlet-provider.d.ts +2 -1
- package/dist/types/prerender/build-shell-capture.d.ts +8 -6
- package/dist/types/prerender/cloudflare.d.ts +49 -0
- package/dist/types/prerender/create-prerender-trigger.d.ts +121 -0
- package/dist/types/prerender/index.d.ts +12 -0
- package/dist/types/prerender/memory-prerender-store.d.ts +29 -0
- package/dist/types/prerender/on-demand.d.ts +272 -0
- package/dist/types/prerender/producer-guard.d.ts +33 -0
- package/dist/types/prerender/shell-manifest-key.d.ts +1 -18
- package/dist/types/prerender/warm-request.d.ts +65 -0
- package/dist/types/prerender/warm.d.ts +65 -0
- package/dist/types/prerender/writable-store.d.ts +170 -0
- package/dist/types/prerender.d.ts +27 -0
- package/dist/types/reverse.d.ts +1 -1
- package/dist/types/route-content-wrapper.d.ts +3 -1
- package/dist/types/router/error-handling.d.ts +2 -0
- package/dist/types/router/handler-context.d.ts +1 -1
- package/dist/types/router/match-middleware/cache-lookup.d.ts +15 -1
- package/dist/types/router/navigation-snapshot.d.ts +8 -1
- package/dist/types/router/pattern-matching.d.ts +2 -0
- package/dist/types/router/prefetch-default.d.ts +4 -4
- package/dist/types/router/prerender-match.d.ts +23 -1
- package/dist/types/router/route-trie-builder.d.ts +8 -1
- package/dist/types/router/router-context.d.ts +1 -0
- package/dist/types/router/router-interfaces.d.ts +32 -1
- package/dist/types/router/router-options.d.ts +39 -5
- package/dist/types/router/segment-resolution/fresh.d.ts +7 -0
- package/dist/types/router/segment-resolution/loader-cache.d.ts +23 -10
- package/dist/types/router/segment-resolution/revalidation.d.ts +5 -1
- package/dist/types/router/segment-resolution/streamed-handler-boundary.d.ts +43 -0
- package/dist/types/router/trie-matching.d.ts +2 -0
- package/dist/types/router-versions.d.ts +39 -0
- package/dist/types/rsc/handler-context.d.ts +5 -0
- package/dist/types/rsc/shell-build-manifest.d.ts +9 -6
- package/dist/types/rsc/shell-capture-constants.d.ts +20 -5
- package/dist/types/rsc/shell-capture.d.ts +14 -1
- package/dist/types/rsc/shell-serve.d.ts +2 -2
- package/dist/types/rsc/ssr-module-loader.d.ts +15 -0
- package/dist/types/rsc/types.d.ts +12 -6
- package/dist/types/segment-boundary-content.d.ts +17 -0
- package/dist/types/segment-loader-promise.d.ts +2 -6
- package/dist/types/server/build-version-table.d.ts +53 -0
- package/dist/types/server/context.d.ts +12 -4
- package/dist/types/server/handle-store.d.ts +89 -46
- package/dist/types/server/request-context.d.ts +84 -9
- package/dist/types/suspense-audit-react.d.ts +26 -0
- package/dist/types/suspense-audit.d.ts +157 -0
- package/dist/types/testing/action-form.d.ts +34 -0
- package/dist/types/testing/build-versions.d.ts +32 -0
- package/dist/types/testing/dom.entry.d.ts +1 -1
- package/dist/types/testing/flight.entry.d.ts +3 -1
- package/dist/types/testing/index.d.ts +6 -0
- package/dist/types/testing/internal/seed-vars.d.ts +7 -2
- package/dist/types/testing/internal/server-modules.d.ts +8 -0
- package/dist/types/testing/location-state-key.d.ts +5 -1
- package/dist/types/testing/render-route.d.ts +77 -6
- package/dist/types/testing/serve-shell-request.d.ts +55 -4
- package/dist/types/testing/shell-status.d.ts +14 -6
- package/dist/types/testing/vitest-stubs/plugin-rsc.d.ts +9 -6
- package/dist/types/testing/vitest-stubs/version.d.ts +1 -0
- package/dist/types/thenable-status.d.ts +6 -0
- package/dist/types/types/handler-context.d.ts +15 -5
- package/dist/types/types/route-entry.d.ts +5 -0
- package/dist/types/urls/path-helper.d.ts +18 -0
- package/dist/types/vite/discovery/build-versions.d.ts +393 -0
- package/dist/types/vite/discovery/installed-packages.d.ts +26 -0
- package/dist/types/vite/discovery/router-versions-phase.d.ts +52 -0
- package/dist/types/vite/discovery/shell-prerender-phase.d.ts +7 -17
- package/dist/types/vite/discovery/state.d.ts +25 -0
- package/dist/types/vite/encryption-key.d.ts +18 -0
- package/dist/types/vite/inject-client-debug.d.ts +6 -25
- package/dist/types/vite/plugin-types.d.ts +27 -0
- package/dist/types/vite/plugins/{version-injector.d.ts → entry-bootstrap-injector.d.ts} +4 -6
- package/dist/types/vite/plugins/expose-ids/export-analysis.d.ts +1 -0
- package/dist/types/vite/plugins/expose-ids/router-transform.d.ts +14 -0
- package/dist/types/vite/plugins/stable-rsc-output.d.ts +51 -0
- package/dist/types/vite/plugins/version-plugin.d.ts +9 -11
- package/dist/types/vite/plugins/virtual-entries.d.ts +18 -1
- package/dist/types/vite/router-discovery.d.ts +6 -0
- package/dist/types/vite/utils/bundle-analysis.d.ts +6 -2
- package/dist/types/vite/utils/client-chunks.d.ts +2 -0
- package/dist/types/vite/utils/compare-strings.d.ts +7 -0
- package/dist/types/vite/utils/package-resolution.d.ts +8 -0
- package/dist/types/vite/utils/prerender-utils.d.ts +2 -0
- package/dist/vite/index.js +1707 -931
- package/package.json +12 -3
- package/skills/cache-guide/SKILL.md +102 -37
- package/skills/caching/SKILL.md +56 -9
- package/skills/catalog.json +1 -1
- package/skills/client-urls/SKILL.md +16 -0
- package/skills/cloudflare/SKILL.md +133 -1
- package/skills/comparison/references/framework-comparison.md +17 -13
- package/skills/deployment-caching/SKILL.md +33 -12
- package/skills/document-cache/SKILL.md +16 -14
- package/skills/hooks/SKILL.md +25 -0
- package/skills/hooks/handle-and-actions.md +5 -0
- package/skills/hooks/navigation.md +38 -0
- package/skills/hooks/state.md +213 -11
- package/skills/hooks/urls.md +40 -1
- package/skills/host-router/SKILL.md +31 -0
- package/skills/intercept/SKILL.md +6 -0
- package/skills/loader/SKILL.md +25 -5
- package/skills/middleware/SKILL.md +2 -0
- package/skills/migrate-nextjs/SKILL.md +82 -9
- package/skills/ppr/SKILL.md +150 -48
- package/skills/prerender/SKILL.md +651 -10
- package/skills/rango/SKILL.md +9 -7
- package/skills/response-routes/SKILL.md +5 -5
- package/skills/route/SKILL.md +29 -0
- package/skills/router-setup/SKILL.md +15 -1
- package/skills/testing/SKILL.md +32 -27
- package/skills/testing/cache-prerender.md +18 -17
- package/skills/testing/client-components.md +193 -8
- package/skills/testing/handles.md +2 -0
- package/skills/testing/loader.md +1 -1
- package/skills/testing/middleware.md +1 -1
- package/skills/testing/render-handler.md +18 -18
- package/skills/testing/serve-shell-request.md +167 -22
- package/skills/testing/server-actions.md +17 -17
- package/skills/testing/server-tree.md +1 -1
- package/skills/typesafety/generated-files-and-cli.md +1 -1
- package/skills/use-cache/SKILL.md +25 -10
- package/skills/vercel/SKILL.md +5 -3
- package/skills/view-transitions/SKILL.md +9 -4
- package/src/bin/rango.ts +1 -1
- package/src/browser/event-controller.ts +119 -2
- package/src/browser/history-state.ts +39 -17
- package/src/browser/link-interceptor.ts +2 -2
- package/src/browser/navigation-bridge.ts +104 -41
- package/src/browser/navigation-store.ts +26 -0
- package/src/browser/navigation-transaction.ts +24 -12
- package/src/browser/network-error-handler.ts +2 -0
- package/src/browser/partial-update.ts +58 -14
- package/src/browser/prefetch/default-strategy.ts +22 -42
- package/src/browser/rango-state.ts +3 -1
- package/src/browser/react/Link.tsx +37 -43
- package/src/browser/react/NavigationProvider.tsx +85 -1
- package/src/browser/react/context.ts +30 -0
- package/src/browser/react/location-state-shared.ts +200 -34
- package/src/browser/react/location-state.ts +28 -77
- package/src/browser/react/use-action.ts +4 -1
- package/src/browser/react/use-handle.ts +3 -0
- package/src/browser/react/use-link-status.ts +4 -3
- package/src/browser/react/use-navigation.ts +4 -1
- package/src/browser/react/use-params.ts +4 -1
- package/src/browser/react/use-pathname.ts +4 -1
- package/src/browser/react/use-search-params.ts +5 -3
- package/src/browser/react/use-segments.ts +36 -54
- package/src/browser/rsc-router.tsx +93 -31
- package/src/browser/segment-reconciler.ts +3 -3
- package/src/browser/server-action-bridge.ts +43 -7
- package/src/browser/types.ts +11 -0
- package/src/build/generate-manifest.ts +17 -0
- package/src/build/merge-full-manifests.ts +5 -0
- package/src/build/route-trie.ts +1 -0
- package/src/cache/background-task.ts +61 -0
- package/src/cache/cache-key-utils.ts +91 -12
- package/src/cache/cache-policy.ts +11 -2
- package/src/cache/cache-runtime.ts +23 -23
- package/src/cache/cache-scope.ts +48 -36
- package/src/cache/cf/cf-cache-store.ts +91 -66
- package/src/cache/cf/cf-cache-types.ts +12 -4
- package/src/cache/document-cache.ts +35 -14
- package/src/cache/handle-snapshot.ts +118 -86
- package/src/cache/index.ts +5 -0
- package/src/cache/invalidation-order.ts +53 -0
- package/src/cache/memory-segment-store.ts +52 -1
- package/src/cache/shell-snapshot.ts +52 -5
- package/src/cache/store-scope.ts +36 -0
- package/src/cache/tag-invalidation.ts +7 -5
- package/src/cache/types.ts +90 -24
- package/src/cache/vercel/vercel-cache-store.ts +68 -26
- package/src/client-urls/client-root.tsx +1 -0
- package/src/client-urls/navigation.ts +10 -0
- package/src/client-urls/optimistic-location.ts +10 -4
- package/src/client.tsx +40 -3
- package/src/errors.ts +13 -6
- package/src/handles/deferred-resolution.ts +36 -0
- package/src/internal-suspense-audit.ts +12 -0
- package/src/loader-store.ts +4 -9
- package/src/outlet-provider.tsx +25 -1
- package/src/prerender/build-shell-capture.ts +11 -9
- package/src/prerender/cloudflare.ts +130 -0
- package/src/prerender/create-prerender-trigger.ts +780 -0
- package/src/prerender/index.ts +39 -0
- package/src/prerender/memory-prerender-store.ts +115 -0
- package/src/prerender/on-demand.ts +339 -0
- package/src/prerender/producer-guard.ts +66 -0
- package/src/prerender/shell-manifest-key.ts +12 -17
- package/src/prerender/warm-request.ts +154 -0
- package/src/prerender/warm.ts +193 -0
- package/src/prerender/writable-store.ts +278 -0
- package/src/prerender.ts +29 -0
- package/src/reverse.ts +1 -1
- package/src/route-content-wrapper.tsx +107 -13
- package/src/router/error-handling.ts +12 -12
- package/src/router/find-match.ts +1 -0
- package/src/router/handler-context.ts +2 -0
- package/src/router/intercept-resolution.ts +15 -8
- package/src/router/loader-resolution.ts +2 -10
- package/src/router/manifest.ts +2 -0
- package/src/router/match-middleware/background-revalidation.ts +2 -0
- package/src/router/match-middleware/cache-lookup.ts +239 -54
- package/src/router/navigation-snapshot.ts +25 -6
- package/src/router/pattern-matching.ts +14 -0
- package/src/router/prefetch-default.ts +4 -4
- package/src/router/prerender-match.ts +460 -352
- package/src/router/request-classification.ts +15 -12
- package/src/router/route-trie-builder.ts +9 -0
- package/src/router/router-context.ts +1 -0
- package/src/router/router-interfaces.ts +35 -1
- package/src/router/router-options.ts +45 -5
- package/src/router/segment-resolution/fresh.ts +20 -19
- package/src/router/segment-resolution/loader-cache.ts +110 -77
- package/src/router/segment-resolution/revalidation.ts +34 -24
- package/src/router/segment-resolution/streamed-handler-boundary.ts +133 -0
- package/src/router/trie-matching.ts +3 -0
- package/src/router-versions.ts +60 -0
- package/src/router.ts +107 -1
- package/src/rsc/full-payload.ts +6 -2
- package/src/rsc/handler-context.ts +5 -0
- package/src/rsc/handler.ts +64 -7
- package/src/rsc/progressive-enhancement.ts +5 -1
- package/src/rsc/response-cache-serve.ts +10 -4
- package/src/rsc/rsc-rendering.ts +65 -12
- package/src/rsc/shell-build-manifest.ts +17 -12
- package/src/rsc/shell-capture-constants.ts +39 -7
- package/src/rsc/shell-capture.ts +144 -45
- package/src/rsc/shell-serve.ts +12 -6
- package/src/rsc/ssr-module-loader.ts +26 -0
- package/src/rsc/types.ts +12 -6
- package/src/segment-boundary-content.ts +25 -0
- package/src/segment-loader-promise.ts +28 -38
- package/src/segment-system.tsx +117 -57
- package/src/server/build-version-table.ts +130 -0
- package/src/server/context.ts +40 -17
- package/src/server/cookie-store.ts +5 -0
- package/src/server/handle-store.ts +357 -127
- package/src/server/request-context.ts +149 -12
- package/src/ssr/ssr-root.tsx +32 -13
- package/src/suspense-audit-react.tsx +98 -0
- package/src/suspense-audit.ts +1030 -0
- package/src/testing/action-form.ts +66 -0
- package/src/testing/build-versions.ts +64 -0
- package/src/testing/dispatch.ts +6 -0
- package/src/testing/dom.entry.ts +1 -0
- package/src/testing/flight-runtime.d.ts +27 -0
- package/src/testing/flight.entry.ts +4 -0
- package/src/testing/index.ts +22 -0
- package/src/testing/internal/context.ts +2 -1
- package/src/testing/internal/seed-vars.ts +14 -2
- package/src/testing/internal/server-modules.ts +32 -0
- package/src/testing/location-state-key.ts +18 -8
- package/src/testing/render-handler.ts +2 -1
- package/src/testing/render-route.tsx +293 -46
- package/src/testing/serve-shell-request.ts +262 -37
- package/src/testing/shell-status.ts +17 -6
- package/src/testing/vitest-stubs/plugin-rsc.ts +37 -11
- package/src/testing/vitest-stubs/version.ts +4 -1
- package/src/thenable-status.ts +10 -0
- package/src/types/handler-context.ts +15 -5
- package/src/types/route-entry.ts +6 -0
- package/src/urls/path-helper.ts +69 -9
- package/src/use-loader.tsx +57 -30
- package/src/vite/discovery/build-versions.ts +1281 -0
- package/src/vite/discovery/bundle-postprocess.ts +4 -0
- package/src/vite/discovery/discover-routers.ts +15 -0
- package/src/vite/discovery/installed-packages.ts +159 -0
- package/src/vite/discovery/prerender-collection.ts +38 -1
- package/src/vite/discovery/router-versions-phase.ts +336 -0
- package/src/vite/discovery/shell-prerender-phase.ts +33 -43
- package/src/vite/discovery/state.ts +36 -1
- package/src/vite/discovery/virtual-module-codegen.ts +7 -2
- package/src/vite/encryption-key.ts +101 -9
- package/src/vite/inject-client-debug.ts +42 -20
- package/src/vite/plugin-types.ts +28 -0
- package/src/vite/plugins/{version-injector.ts → entry-bootstrap-injector.ts} +7 -22
- package/src/vite/plugins/expose-ids/export-analysis.ts +1 -1
- package/src/vite/plugins/expose-ids/router-transform.ts +36 -15
- package/src/vite/plugins/expose-internal-ids.ts +12 -3
- package/src/vite/plugins/stable-rsc-output.ts +147 -0
- package/src/vite/plugins/version-plugin.ts +19 -24
- package/src/vite/plugins/version.d.ts +17 -2
- package/src/vite/plugins/virtual-entries.ts +39 -6
- package/src/vite/rango.ts +28 -3
- package/src/vite/router-discovery.ts +96 -13
- package/src/vite/utils/bundle-analysis.ts +39 -7
- package/src/vite/utils/client-chunks.ts +5 -1
- package/src/vite/utils/compare-strings.ts +9 -0
- package/src/vite/utils/package-resolution.ts +9 -0
- package/src/vite/utils/prerender-utils.ts +4 -1
- package/src/vite/utils/shared-utils.ts +1 -1
- package/dist/types/segment-content-promise.d.ts +0 -13
- package/src/segment-content-promise.ts +0 -67
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-router cache versions, computed from the built server output.
|
|
3
|
+
*
|
|
4
|
+
* Every cache key and stored PPR shell is tied to a version. A router's
|
|
5
|
+
* versions are hashes of the code that router can run, so the same code gives
|
|
6
|
+
* the same versions and a new deployment finds the entries the previous one
|
|
7
|
+
* wrote. Design and measurements: docs/design/per-app-cache-version.md.
|
|
8
|
+
*
|
|
9
|
+
* Two steps, both pure over data the build hooks record:
|
|
10
|
+
*
|
|
11
|
+
* 1. Membership ({@link resolveRouterMembers}): which server modules can a
|
|
12
|
+
* router run. Walked on the MODULE graph, not the chunk graph, because the
|
|
13
|
+
* build has registries that name every app's code (plugin-rsc's
|
|
14
|
+
* server-reference map, the loader manifest, the routes manifest). A walk
|
|
15
|
+
* that followed them would put every router's code in every router's set.
|
|
16
|
+
* 2. Hashing ({@link computeRouterVersions}): the bytes on disk of the chunks
|
|
17
|
+
* holding those modules, read AFTER postprocessBundle rewrote them, with
|
|
18
|
+
* everything taken out that says where or how the build ran instead of what
|
|
19
|
+
* it built ({@link digestBundle}).
|
|
20
|
+
*
|
|
21
|
+
* One rule covers what the build cannot determine (a file it lists and cannot
|
|
22
|
+
* read, an import it cannot resolve): the build fails, or the version changes
|
|
23
|
+
* on every build. A version never silently stays the same.
|
|
24
|
+
*/
|
|
25
|
+
import { type RouterVersionsTable } from "../../router-versions.js";
|
|
26
|
+
/** Import edges of one module, as the bundler resolved them. */
|
|
27
|
+
export interface BuildModuleEdges {
|
|
28
|
+
readonly imports: readonly string[];
|
|
29
|
+
readonly dynamicImports: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* The module encrypts inline-action bound arguments, so what it renders can
|
|
32
|
+
* only be decrypted with the build's encryption key.
|
|
33
|
+
*/
|
|
34
|
+
readonly encryptsBoundArgs?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface BuildChunk {
|
|
37
|
+
readonly fileName: string;
|
|
38
|
+
/** The chunk's name without its content hash. */
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly moduleIds: readonly string[];
|
|
41
|
+
/** Specifiers the chunk imports that the bundle does not contain. */
|
|
42
|
+
readonly externalImports?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export interface BuildAsset {
|
|
45
|
+
readonly fileName: string;
|
|
46
|
+
/** The asset's name without its content hash. */
|
|
47
|
+
readonly name: string;
|
|
48
|
+
}
|
|
49
|
+
/** The files one environment's bundle emits. */
|
|
50
|
+
export interface BundleFiles {
|
|
51
|
+
readonly chunks: readonly BuildChunk[];
|
|
52
|
+
readonly assets: readonly BuildAsset[];
|
|
53
|
+
}
|
|
54
|
+
/** The RSC environment's bundle, from its real (not scan) build pass. */
|
|
55
|
+
export interface ServerBuildGraph extends BundleFiles {
|
|
56
|
+
readonly modules: ReadonlyMap<string, BuildModuleEdges>;
|
|
57
|
+
}
|
|
58
|
+
/** The client environment's module graph and emitted file names. */
|
|
59
|
+
export interface ClientBuildGraph {
|
|
60
|
+
readonly modules: ReadonlyMap<string, BuildModuleEdges>;
|
|
61
|
+
readonly fileNames: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
/** One discovered router: its runtime id and the module that creates it. */
|
|
64
|
+
export interface RouterSource {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
/** Absolute path of the file calling createRouter(), when known. */
|
|
67
|
+
readonly moduleId: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* One piece of data the build produced that a router's output depends on and
|
|
71
|
+
* that none of the router's chunks holds. Named by the digest of its bytes.
|
|
72
|
+
*
|
|
73
|
+
* The kinds feed different versions, by where the data can end up at run
|
|
74
|
+
* time:
|
|
75
|
+
*
|
|
76
|
+
* - A Static payload is a segment of an ordinary route, so a `cache()` entry
|
|
77
|
+
* of that route stores it. It is part of the DATA version.
|
|
78
|
+
* - A clientUrls() projection is what the server materializes a client-defined
|
|
79
|
+
* route group from: its loaders, loading states, transitions and route ids.
|
|
80
|
+
* It ships in the routes registry (virtual-module-codegen.ts), which a
|
|
81
|
+
* lazily mounted app's chunks do not include. DATA version.
|
|
82
|
+
* - A server component's stylesheet URLs are read at run time from plugin-rsc's
|
|
83
|
+
* assets manifest and rendered as `<link>`s into the router's Flight, so
|
|
84
|
+
* they are in cached payloads while no server chunk holds them. DATA version.
|
|
85
|
+
* - A Prerender payload is served from the build's own store and never
|
|
86
|
+
* written to the segment cache (withCacheLookup returns before the cache
|
|
87
|
+
* scope, match-middleware/cache-lookup.ts). Only stored HTML holds it: a PPR
|
|
88
|
+
* shell or a document-cache response of the route. It is part of the
|
|
89
|
+
* DOCUMENT version only.
|
|
90
|
+
*/
|
|
91
|
+
export interface BuildDataRecord {
|
|
92
|
+
readonly kind: "prerender" | "static" | "client-urls" | "server-css";
|
|
93
|
+
/**
|
|
94
|
+
* Prerender manifest key, Static handler id, clientUrls() module, or the
|
|
95
|
+
* module a `serverResources` entry is keyed by.
|
|
96
|
+
*/
|
|
97
|
+
readonly key: string;
|
|
98
|
+
/** sha256 of the payload, the projection, or the entry. */
|
|
99
|
+
readonly digest: string;
|
|
100
|
+
/** Router that rendered it (prerender). */
|
|
101
|
+
readonly routerId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Module the data belongs to (static: the handler's; client-urls: the
|
|
104
|
+
* clientUrls() module; server-css: the module that renders the links).
|
|
105
|
+
* Owned by {@link ownersOf}.
|
|
106
|
+
*/
|
|
107
|
+
readonly moduleId?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface RouterMembers {
|
|
110
|
+
/** Server modules the router can run. */
|
|
111
|
+
readonly modules: ReadonlySet<string>;
|
|
112
|
+
/** Chunk files holding any of them, plus the router's route manifest. */
|
|
113
|
+
readonly chunkFiles: ReadonlySet<string>;
|
|
114
|
+
}
|
|
115
|
+
/** The slice of a plugin context the graph recorders read. */
|
|
116
|
+
interface ModuleGraphContext {
|
|
117
|
+
getModuleIds(): Iterable<string>;
|
|
118
|
+
getModuleInfo(id: string): {
|
|
119
|
+
importedIds?: readonly string[];
|
|
120
|
+
dynamicallyImportedIds?: readonly string[];
|
|
121
|
+
code?: string | null;
|
|
122
|
+
} | null;
|
|
123
|
+
}
|
|
124
|
+
/** The slice of an output bundle the graph recorders read. */
|
|
125
|
+
type OutputBundleLike = Record<string, {
|
|
126
|
+
type: string;
|
|
127
|
+
fileName: string;
|
|
128
|
+
name?: string;
|
|
129
|
+
names?: readonly string[];
|
|
130
|
+
moduleIds?: readonly string[];
|
|
131
|
+
imports?: readonly string[];
|
|
132
|
+
dynamicImports?: readonly string[];
|
|
133
|
+
}>;
|
|
134
|
+
/** The chunks and assets of a bundle. Call from generateBundle. */
|
|
135
|
+
export declare function recordBundleFiles(bundle: OutputBundleLike): BundleFiles;
|
|
136
|
+
/** Call from the RSC environment's generateBundle. */
|
|
137
|
+
export declare function recordServerGraph(context: ModuleGraphContext, bundle: OutputBundleLike): ServerBuildGraph;
|
|
138
|
+
/** Call from the client environment's generateBundle. */
|
|
139
|
+
export declare function recordClientGraph(context: ModuleGraphContext, bundle: OutputBundleLike): ClientBuildGraph;
|
|
140
|
+
/** plugin-rsc's build-time map of every server reference in the app. */
|
|
141
|
+
export declare const SERVER_REFERENCES_MODULE_ID = "\0virtual:vite-rsc/server-references";
|
|
142
|
+
/**
|
|
143
|
+
* plugin-rsc writes the key to this file next to the RSC entry and has chunks
|
|
144
|
+
* import it at run time (its `rsc:encryption-key` renderChunk), so the key is
|
|
145
|
+
* in no chunk and in no bundle graph. The file exists only when a rendered
|
|
146
|
+
* chunk reads the key.
|
|
147
|
+
*/
|
|
148
|
+
export declare const ENCRYPTION_KEY_FILE = "__vite_rsc_encryption_key.js";
|
|
149
|
+
/**
|
|
150
|
+
* Work out, per router, the server modules it can run and the chunk files
|
|
151
|
+
* holding them.
|
|
152
|
+
*
|
|
153
|
+
* The walk starts at the module calling createRouter() AND at every module
|
|
154
|
+
* that statically imports it, directly or through other static imports. What
|
|
155
|
+
* runs with a router is not only what its own module imports: the modules
|
|
156
|
+
* importing it attach middleware and handlers (`router.use(...)` in an app
|
|
157
|
+
* module) and wrap its fetch (the mounted handler). The climb stops at a
|
|
158
|
+
* dynamic import, which is how a host mounts an app it does not run with; so
|
|
159
|
+
* routers that one module imports statically share that module's code, and
|
|
160
|
+
* only lazily mounted apps are independent of each other.
|
|
161
|
+
*
|
|
162
|
+
* A router whose module the build cannot find is left out of the result; the
|
|
163
|
+
* runtime then serves it with the whole-build versions
|
|
164
|
+
* ({@link DEFAULT_ROUTER_VERSIONS_KEY}).
|
|
165
|
+
*
|
|
166
|
+
* Membership is per module, the hash is per chunk file. A chunk that holds one
|
|
167
|
+
* reached module is hashed whole, so a router's version also covers whatever
|
|
168
|
+
* the bundler placed next to its code: the conservative direction.
|
|
169
|
+
*/
|
|
170
|
+
export declare function resolveRouterMembers(server: ServerBuildGraph, client: ClientBuildGraph | undefined, routers: readonly RouterSource[]): Map<string, RouterMembers>;
|
|
171
|
+
export declare function sha256(value: string | Uint8Array): string;
|
|
172
|
+
/**
|
|
173
|
+
* A module id without the build machine's checkout directory: root-relative
|
|
174
|
+
* inside the project, and from the outermost node_modules for an installed
|
|
175
|
+
* package. The outermost, not the innermost: two installed versions of one
|
|
176
|
+
* package differ only in the directories between (`.pnpm/foo@1…/node_modules/foo`,
|
|
177
|
+
* a nested `a/node_modules/foo`), and must not get the same id. A pnpm store
|
|
178
|
+
* directory is reduced to `name@version` ({@link PNPM_PEER_SUFFIX}).
|
|
179
|
+
*
|
|
180
|
+
* A virtual id can carry a file path in its query. plugin-rsc's server CSS
|
|
181
|
+
* module is `virtual:vite-rsc/css?type=rsc&id=<URI-encoded absolute importer>`,
|
|
182
|
+
* so those values are made portable too.
|
|
183
|
+
*/
|
|
184
|
+
export declare function portableModuleId(id: string, projectRoot: string): string;
|
|
185
|
+
/** A sourcemap describes a file; it is not code the server runs. */
|
|
186
|
+
export declare function isSourceMap(fileName: string): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Drop the body of the server-reference map from a chunk's source.
|
|
189
|
+
*
|
|
190
|
+
* The map lists every `"use server"` module of the build with its export
|
|
191
|
+
* names, and it sits in a chunk every router runs (plugin-rsc's server
|
|
192
|
+
* runtime imports it). Hashed as is, the map would put every app's action
|
|
193
|
+
* list into every app's version. Its text is derived: each module it names is
|
|
194
|
+
* hashed by the routers that reach it (resolveRouterMembers), so nothing the
|
|
195
|
+
* map says is lost by skipping it.
|
|
196
|
+
*
|
|
197
|
+
* Works on the region comments, so a minified server build (which has none)
|
|
198
|
+
* keeps the map in every router's hash: more clearing, never less.
|
|
199
|
+
*/
|
|
200
|
+
export declare function stripServerReferenceMap(source: string): string;
|
|
201
|
+
/**
|
|
202
|
+
* Take the module paths out of a chunk's region comments.
|
|
203
|
+
*
|
|
204
|
+
* The bundler prints one before each module's code, and the path says where
|
|
205
|
+
* the build ran, not what it built: it is relative to the directory `vite
|
|
206
|
+
* build` was started from (`vite build apps/web` from a repository root
|
|
207
|
+
* prints other paths than `vite build` in the app), it holds the pnpm store
|
|
208
|
+
* directory with its peer suffix, and a virtual id is printed verbatim,
|
|
209
|
+
* absolute paths in its query included. The code under the comment is hashed
|
|
210
|
+
* either way.
|
|
211
|
+
*/
|
|
212
|
+
export declare function stripRegionPaths(source: string): string;
|
|
213
|
+
/** One thing a version is a hash of: its name and the digest of its bytes. */
|
|
214
|
+
export type VersionInput = readonly [name: string, digest: string];
|
|
215
|
+
/** One bundle file, digested once for every router. */
|
|
216
|
+
export interface DigestedFile {
|
|
217
|
+
readonly fileName: string;
|
|
218
|
+
/**
|
|
219
|
+
* What the file is, independent of its content: the un-hashed name plus, for
|
|
220
|
+
* a chunk, a digest of the module ids inside it. Stands in for the file's
|
|
221
|
+
* hashed name wherever a router that owns the file refers to it.
|
|
222
|
+
*/
|
|
223
|
+
readonly identity: string;
|
|
224
|
+
/**
|
|
225
|
+
* Digest of the file's bytes with every reference to a bundle file replaced
|
|
226
|
+
* by one token ({@link FILE_REFERENCE}), so a content hash in a file name
|
|
227
|
+
* never reaches it.
|
|
228
|
+
*/
|
|
229
|
+
readonly base: string;
|
|
230
|
+
/** The files those references named, in order of appearance. */
|
|
231
|
+
readonly references: readonly string[];
|
|
232
|
+
/** Specifiers the file imports that the bundle does not contain. */
|
|
233
|
+
readonly externalImports: readonly string[];
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Digest every file of a bundle, as it is on disk.
|
|
237
|
+
*
|
|
238
|
+
* Three things are taken out of a chunk's text first, each because it says
|
|
239
|
+
* where or how the build ran: the server-reference map's body
|
|
240
|
+
* ({@link stripServerReferenceMap}), the paths in region comments
|
|
241
|
+
* ({@link stripRegionPaths}), and the hashed names of bundle files. A name
|
|
242
|
+
* carries the content hash of its file, and every chunk importing the file
|
|
243
|
+
* has the name in its bytes, so one router's change would otherwise move the
|
|
244
|
+
* digest of every chunk naming its chunk. Only names with a content hash are
|
|
245
|
+
* replaced; a fixed name such as the entry's "index.js" is the same in every
|
|
246
|
+
* build. An asset is data (a route manifest staged as a text module can be
|
|
247
|
+
* megabytes): hashed as bytes, never scanned.
|
|
248
|
+
*
|
|
249
|
+
* Throws when the bundle lists a file that is not on disk: its bytes would
|
|
250
|
+
* silently drop out of every version.
|
|
251
|
+
*/
|
|
252
|
+
export declare function digestBundle(bundle: BundleFiles, projectRoot: string, read: (fileName: string) => Uint8Array | undefined, label: string): DigestedFile[];
|
|
253
|
+
/** How the build reads what the bundles leave external. */
|
|
254
|
+
export interface ExternalResolver {
|
|
255
|
+
/**
|
|
256
|
+
* What is installed for a package: `name@version` of the package and of
|
|
257
|
+
* everything it depends on (installed-packages.ts). The chunk only says
|
|
258
|
+
* `from "pkg"`, whichever version that is. `undefined` when the package
|
|
259
|
+
* cannot be found.
|
|
260
|
+
*/
|
|
261
|
+
readonly describePackage: (name: string) => string | undefined;
|
|
262
|
+
/** The bytes of a file at an absolute path; `undefined` when it is absent. */
|
|
263
|
+
readonly readFile: (path: string) => Uint8Array | undefined;
|
|
264
|
+
/** Unique to this build: the digest of an input that cannot be determined. */
|
|
265
|
+
readonly buildId: string;
|
|
266
|
+
}
|
|
267
|
+
export type ExternalImport = {
|
|
268
|
+
readonly kind: "provided";
|
|
269
|
+
} | {
|
|
270
|
+
readonly kind: "package";
|
|
271
|
+
readonly name: string;
|
|
272
|
+
} | {
|
|
273
|
+
readonly kind: "file";
|
|
274
|
+
} | {
|
|
275
|
+
readonly kind: "unknown";
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* What an import a bundle leaves external is. THE rule for all of them, and
|
|
279
|
+
* the only place it is decided:
|
|
280
|
+
*
|
|
281
|
+
* - `provided`: the version does not cover it. A runtime builtin (`node:fs`,
|
|
282
|
+
* bare `fs`, `cloudflare:workers`, `bun:sqlite`), a `data:` URL (its content
|
|
283
|
+
* is the specifier, which is in the chunk), or a marker of another plugin
|
|
284
|
+
* whose file is a bundle output the hash already covers.
|
|
285
|
+
* - `package`: an installed package. The version covers what is installed.
|
|
286
|
+
* - `file`: a relative or absolute path. The version covers the file's bytes.
|
|
287
|
+
* - `unknown`: anything else (`https:`, `npm:`, a name npm would reject).
|
|
288
|
+
*
|
|
289
|
+
* A package that is not installed, a path that does not resolve and every
|
|
290
|
+
* `unknown` import get a value unique to the build, and the build names them:
|
|
291
|
+
* the routers importing them get a new version on every build. Nothing the
|
|
292
|
+
* build cannot read is left out of a version.
|
|
293
|
+
*/
|
|
294
|
+
export declare function classifyExternal(specifier: string): ExternalImport;
|
|
295
|
+
export interface ComputeRouterVersionsInput {
|
|
296
|
+
readonly projectRoot: string;
|
|
297
|
+
readonly server: ServerBuildGraph;
|
|
298
|
+
readonly client: ClientBuildGraph;
|
|
299
|
+
/** The SSR environment's bundle, with the files plugin-rsc writes next to it. */
|
|
300
|
+
readonly ssr: BundleFiles;
|
|
301
|
+
readonly routers: readonly RouterSource[];
|
|
302
|
+
readonly buildData: readonly BuildDataRecord[];
|
|
303
|
+
/** Read a file of the RSC output directory; undefined when it is absent. */
|
|
304
|
+
readonly readServerFile: (fileName: string) => Uint8Array | undefined;
|
|
305
|
+
/** Read a file of the SSR output directory; undefined when it is absent. */
|
|
306
|
+
readonly readSsrFile: (fileName: string) => Uint8Array | undefined;
|
|
307
|
+
/** Vite's `base`, a prefix of every asset URL in stored HTML. */
|
|
308
|
+
readonly base: string;
|
|
309
|
+
/**
|
|
310
|
+
* plugin-rsc's `serverResources` from the built assets manifest: the
|
|
311
|
+
* root-relative id of a server module that imports CSS, to the text of its
|
|
312
|
+
* entry (the stylesheet URLs).
|
|
313
|
+
*/
|
|
314
|
+
readonly serverResources?: ReadonlyMap<string, string>;
|
|
315
|
+
readonly externals: ExternalResolver;
|
|
316
|
+
}
|
|
317
|
+
export interface RouterVersionDetail {
|
|
318
|
+
readonly routerId: string;
|
|
319
|
+
readonly data: string;
|
|
320
|
+
readonly document: string;
|
|
321
|
+
/**
|
|
322
|
+
* Everything the data version is a hash of, in hashed order: `file
|
|
323
|
+
* <identity>` for a server file, `static <id>` for a Static payload,
|
|
324
|
+
* `client-urls <module>` for a clientUrls() projection, `server-css
|
|
325
|
+
* <module>` for a server component's stylesheets, `external <import>` for
|
|
326
|
+
* what the bundle left external, `encryption-key` for the key. Two builds'
|
|
327
|
+
* lists differ exactly where the version's inputs differ.
|
|
328
|
+
*/
|
|
329
|
+
readonly dataInputs: readonly VersionInput[];
|
|
330
|
+
/**
|
|
331
|
+
* What the document version adds to the data version: `ssr-and-client` (the
|
|
332
|
+
* SSR output and the client asset names) and `prerender <key>` for a
|
|
333
|
+
* Prerender payload.
|
|
334
|
+
*/
|
|
335
|
+
readonly documentInputs: readonly VersionInput[];
|
|
336
|
+
/** The key is part of the router's data version. */
|
|
337
|
+
readonly usesEncryptionKey: boolean;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* What stored HTML depends on besides a router's server code, one set for the
|
|
341
|
+
* build (the SSR output is not split by router). Hashed as the
|
|
342
|
+
* `ssr-and-client` input of every document version.
|
|
343
|
+
*/
|
|
344
|
+
export interface SsrAndClientInputs {
|
|
345
|
+
/** Vite's `base`, a prefix of every asset URL in stored HTML. */
|
|
346
|
+
readonly base: string;
|
|
347
|
+
/**
|
|
348
|
+
* The SSR output, file by file ({@link digestBundle}). It renders the HTML,
|
|
349
|
+
* and its own code can change without the client's.
|
|
350
|
+
*/
|
|
351
|
+
readonly ssr: readonly VersionInput[];
|
|
352
|
+
/** What the SSR output leaves external ({@link classifyExternal}). */
|
|
353
|
+
readonly externals: readonly VersionInput[];
|
|
354
|
+
/**
|
|
355
|
+
* The client asset names. A prelude and an open tab both hold them, and the
|
|
356
|
+
* names carry the bundler's content hashes.
|
|
357
|
+
*/
|
|
358
|
+
readonly client: readonly string[];
|
|
359
|
+
}
|
|
360
|
+
export interface ComputedRouterVersions {
|
|
361
|
+
readonly table: RouterVersionsTable;
|
|
362
|
+
/** One entry per attributed router, then the whole-build entry. */
|
|
363
|
+
readonly details: readonly RouterVersionDetail[];
|
|
364
|
+
/** What every document version covers besides its router's data version. */
|
|
365
|
+
readonly ssrAndClient: SsrAndClientInputs;
|
|
366
|
+
/** Server files no attributed router owns, by identity. */
|
|
367
|
+
readonly unownedFiles: readonly string[];
|
|
368
|
+
/** Imports the build could not determine ({@link classifyExternal}). */
|
|
369
|
+
readonly undetermined: readonly string[];
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Compute every router's data and document version, and the whole-build pair.
|
|
373
|
+
*
|
|
374
|
+
* A router's data version covers: its chunk files, the bundle assets those
|
|
375
|
+
* files name (a route manifest staged as a text module), what those files
|
|
376
|
+
* leave external, and the inputs it owns that no chunk holds
|
|
377
|
+
* ({@link ownersOf}). Its document version is the data version plus the SSR
|
|
378
|
+
* output, the client asset names, `base` and its Prerender payloads.
|
|
379
|
+
*/
|
|
380
|
+
export declare function computeRouterVersions(input: ComputeRouterVersionsInput): ComputedRouterVersions;
|
|
381
|
+
/**
|
|
382
|
+
* The chunk files of a bundle that hold the `@rangojs/router:version` module,
|
|
383
|
+
* where the placeholder has to be replaced. Recorded for every environment:
|
|
384
|
+
* the module is emitted wherever something imports it (a second worker that
|
|
385
|
+
* uses a cache store), and an unreplaced placeholder throws on load.
|
|
386
|
+
*/
|
|
387
|
+
export declare function recordVersionModuleFiles(bundle: OutputBundleLike): string[];
|
|
388
|
+
/**
|
|
389
|
+
* Replace the version module's placeholder with the table. Returns undefined
|
|
390
|
+
* when `source` does not hold the placeholder.
|
|
391
|
+
*/
|
|
392
|
+
export declare function fillRouterVersions(source: string, table: RouterVersionsTable): string | undefined;
|
|
393
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What is installed for a package a server build leaves external.
|
|
3
|
+
*
|
|
4
|
+
* The node preset bundles only packages that need the React server condition
|
|
5
|
+
* (plugin-rsc's `noExternal`); every other dependency stays an import the
|
|
6
|
+
* deployed process resolves from node_modules. The built chunk then says
|
|
7
|
+
* `from "pkg"` whichever version is installed, so a lockfile bump changes what
|
|
8
|
+
* the server renders and nothing the cache versions hash
|
|
9
|
+
* (discovery/build-versions.ts). This module supplies the missing input: the
|
|
10
|
+
* `name@version` of the package and of everything it depends on, as installed
|
|
11
|
+
* next to the project at build time.
|
|
12
|
+
*
|
|
13
|
+
* A registry package's code is fixed by its version. A linked package (a
|
|
14
|
+
* workspace package, resolved to a directory outside node_modules) is not.
|
|
15
|
+
* Vite bundles those unless the config lists one in `resolve.external`; then
|
|
16
|
+
* it comes through here and its files are digested instead.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Returns a function describing an installed package by name: the sorted
|
|
20
|
+
* `name@version` lines of the package and its transitive dependencies
|
|
21
|
+
* (dependencies, optionalDependencies and peerDependencies, each resolved from
|
|
22
|
+
* the package that declares it), with a digest of its files for a linked
|
|
23
|
+
* one, or `undefined` when the package is not installed. Results are kept per
|
|
24
|
+
* name for the life of the returned function.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createInstalledPackageDescriber(projectRoot: string): (name: string) => string | undefined;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-build cache version phase.
|
|
3
|
+
*
|
|
4
|
+
* Runs from the buildApp post hook, after every environment bundle is written
|
|
5
|
+
* and postprocessBundle has rewritten the RSC chunks, and before the shell
|
|
6
|
+
* capture phase, which stamps its entries with the document versions computed
|
|
7
|
+
* here. Reads the bytes that ship, computes each router's versions
|
|
8
|
+
* (build-versions.ts) and writes the table into the built
|
|
9
|
+
* `@rangojs/router:version` module in place of its placeholder.
|
|
10
|
+
*/
|
|
11
|
+
import { type RouterVersionsTable } from "../../router-versions.js";
|
|
12
|
+
import type { DiscoveryState } from "./state.js";
|
|
13
|
+
/** Minimal builder surface the post-build phases read. */
|
|
14
|
+
export interface BuilderLike {
|
|
15
|
+
config?: {
|
|
16
|
+
base?: string;
|
|
17
|
+
};
|
|
18
|
+
environments?: Record<string, {
|
|
19
|
+
config?: {
|
|
20
|
+
build?: {
|
|
21
|
+
outDir?: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
} | undefined>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* An environment's output directory, or Vite's default layout without one.
|
|
28
|
+
* Resolved against the root: a relative `build.outDir` is relative to it, not
|
|
29
|
+
* to the directory `vite build <root>` was run from.
|
|
30
|
+
*/
|
|
31
|
+
export declare function environmentOutDir(builder: BuilderLike | undefined, projectRoot: string, environment: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Where the build leaves what each version was computed from. Outside the
|
|
34
|
+
* output directories, so it never ships.
|
|
35
|
+
*/
|
|
36
|
+
export declare const VERSIONS_REPORT_FILE: string;
|
|
37
|
+
/**
|
|
38
|
+
* The `serverResources` map of plugin-rsc's assets manifest
|
|
39
|
+
* (`export default { ..., serverResources: { "<module>": { js, css } } }`):
|
|
40
|
+
* each server module that imports CSS, to the source text of its entry. Text,
|
|
41
|
+
* not a parsed value: with `renderBuiltUrl` an entry holds runtime expressions.
|
|
42
|
+
* Throws when the manifest is not that shape, so a plugin-rsc that moves it
|
|
43
|
+
* fails the build instead of dropping stylesheets from the versions.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readServerResources(manifest: string): Map<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Compute the versions, write them into the built version module and return
|
|
48
|
+
* the table (`undefined` outside a build). Fails the build when an input was
|
|
49
|
+
* not recorded or cannot be read: a version computed without it would stay
|
|
50
|
+
* the same when it changes.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runRouterVersionsPhase(s: DiscoveryState, builder: BuilderLike | undefined): RouterVersionsTable | undefined;
|
|
@@ -18,23 +18,13 @@
|
|
|
18
18
|
* or never consulted the prerender store is SKIPPED loudly — the route keeps
|
|
19
19
|
* producer A (runtime capture) semantics, never a wrong-lane bake.
|
|
20
20
|
*/
|
|
21
|
+
import { type RouterVersionsTable } from "../../router-versions.js";
|
|
22
|
+
import { type BuilderLike } from "./router-versions-phase.js";
|
|
21
23
|
import type { DiscoveryState } from "./state.js";
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
* @param versionsTable The versions the shipped build serves with
|
|
26
|
+
* (router-versions-phase.ts), `undefined` outside a build. Never the temp
|
|
27
|
+
* server's own version-plugin stamp, which is a dev Date.now() and would
|
|
28
|
+
* fail the serve-side isValidShellHit gate forever.
|
|
25
29
|
*/
|
|
26
|
-
|
|
27
|
-
config?: {
|
|
28
|
-
base?: string;
|
|
29
|
-
plugins?: readonly unknown[];
|
|
30
|
-
};
|
|
31
|
-
environments?: Record<string, {
|
|
32
|
-
config?: {
|
|
33
|
-
build?: {
|
|
34
|
-
outDir?: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
} | undefined>;
|
|
38
|
-
}
|
|
39
|
-
export declare function runShellPrerenderPhase(s: DiscoveryState, builder: BuilderLike | undefined): Promise<void>;
|
|
40
|
-
export {};
|
|
30
|
+
export declare function runShellPrerenderPhase(s: DiscoveryState, builder: BuilderLike | undefined, versionsTable: RouterVersionsTable | undefined): Promise<void>;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { ScanFilter } from "../../build/generate-route-types.js";
|
|
9
9
|
import type { ClientUrlProjection } from "../../client-urls/server-projection.js";
|
|
10
10
|
export declare const VIRTUAL_ROUTES_MANIFEST_ID = "virtual:rsc-router/routes-manifest";
|
|
11
|
+
export declare const VIRTUAL_LOADER_MANIFEST_ID = "virtual:rsc-router/loader-manifest";
|
|
11
12
|
export interface PluginOptions {
|
|
12
13
|
enableBuildPrerender?: boolean;
|
|
13
14
|
staticRouteTypesGeneration?: boolean;
|
|
@@ -62,6 +63,7 @@ export interface ChunkInfo {
|
|
|
62
63
|
name: string;
|
|
63
64
|
handlerId: string;
|
|
64
65
|
passthrough: boolean;
|
|
66
|
+
onDemand: boolean;
|
|
65
67
|
}>;
|
|
66
68
|
}
|
|
67
69
|
export interface PerRouterManifestEntry {
|
|
@@ -143,8 +145,31 @@ export interface DiscoveryState {
|
|
|
143
145
|
* buildEnd (aborted build).
|
|
144
146
|
*/
|
|
145
147
|
shellPhaseTempServer: import("vite").ViteDevServer | null;
|
|
148
|
+
/**
|
|
149
|
+
* Inputs of the per-router cache versions (build-versions.ts), recorded by
|
|
150
|
+
* generateBundle. plugin-rsc builds the RSC and SSR environments twice (a
|
|
151
|
+
* scan pass, then the real pass); each pass overwrites its slot, so the
|
|
152
|
+
* buildApp post hook reads the real pass.
|
|
153
|
+
*/
|
|
154
|
+
serverBuildGraph: import("./build-versions.js").ServerBuildGraph | null;
|
|
155
|
+
clientBuildGraph: import("./build-versions.js").ClientBuildGraph | null;
|
|
156
|
+
ssrBundle: import("./build-versions.js").BundleFiles | null;
|
|
157
|
+
/** Per environment, the chunk files holding the version module. */
|
|
158
|
+
versionModuleFiles: Map<string, string[]>;
|
|
159
|
+
/** Prerender and Static payloads the build rendered, by content digest. */
|
|
160
|
+
buildData: import("./build-versions.js").BuildDataRecord[];
|
|
146
161
|
handlerChunkInfoMap: Map<string, ChunkInfo>;
|
|
147
162
|
staticHandlerChunkInfoMap: Map<string, ChunkInfo>;
|
|
163
|
+
/**
|
|
164
|
+
* handlerId ($$id) -> route name for every route the evaluated source marks
|
|
165
|
+
* onDemand. Written during discovery (buildStart), consumed by the
|
|
166
|
+
* generateBundle chunk scan (extractHandlerExportsFromChunk) as the
|
|
167
|
+
* authoritative onDemand set driving producer retention — the same source
|
|
168
|
+
* that sets the runtime od trie flag, so any truthy onDemand spelling
|
|
169
|
+
* (literal, spread, imported const) both marks the route and retains its
|
|
170
|
+
* producer.
|
|
171
|
+
*/
|
|
172
|
+
onDemandHandlerIds: Map<string, string>;
|
|
148
173
|
rscEntryFileName: string | null;
|
|
149
174
|
resolvedPrerenderModules: Map<string, string[]> | undefined;
|
|
150
175
|
resolvedStaticModules: Map<string, string[]> | undefined;
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws unless `value` is the base64 form of an AES key (16, 24 or 32 bytes).
|
|
3
|
+
* `source` names where the value came from, for the message.
|
|
4
|
+
*/
|
|
5
|
+
export declare function assertValidEncryptionKey(value: unknown, source: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the build's encryption key from rango({ encryptionKey }) or the
|
|
8
|
+
* RANGO_ENCRYPTION_KEY fallback, validating whichever is set. Called by
|
|
9
|
+
* rango() at config time, before any plugin-rsc instance reads the key, so an
|
|
10
|
+
* invalid key fails the config load instead of the first encrypted action.
|
|
11
|
+
* A key generated earlier in the process is kept when neither source is set:
|
|
12
|
+
* the discovery temp server must encrypt with the main build's key.
|
|
13
|
+
*/
|
|
14
|
+
export declare function configureEncryptionKey(option: string | undefined): void;
|
|
1
15
|
export declare function buildEncryptionKey(): string;
|
|
16
|
+
/** False when this build generated its own key (it differs on every build). */
|
|
17
|
+
export declare function isEncryptionKeyStable(): boolean;
|
|
2
18
|
export declare function defineEncryptionKeyExpr(): string;
|
|
19
|
+
/** @internal Test seam: forget the process-wide key. */
|
|
20
|
+
export declare function resetEncryptionKeyForTests(): void;
|
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
import type { Connect } from "vite";
|
|
2
|
-
/**
|
|
3
|
-
* Bake the resolved INTERNAL_RANGO_DEBUG value into the router's `internal-debug`
|
|
4
|
-
* module so the flag reaches the CLIENT debug logs by just setting the env var.
|
|
5
|
-
*
|
|
6
|
-
* internal-debug.ts normally reads the flag via `typeof __RANGO_DEBUG__`, a Vite
|
|
7
|
-
* define. That delivery is unreliable on the client: in dev Vite ships the define
|
|
8
|
-
* only as an injected global whose presence varies across consumer setups, so the
|
|
9
|
-
* module can fall through to `process.env` (undefined in the browser) and the FE
|
|
10
|
-
* debug flag silently stays false while the server logs work. A Vite `transform`
|
|
11
|
-
* runs on the module regardless of how (or whether) the define is delivered, in
|
|
12
|
-
* both dev and build and for every environment, so the discovery plugin uses this
|
|
13
|
-
* to replace the module with the resolved literal.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Scope to the router's own internal-debug module: the published package
|
|
17
|
-
* (`/@rangojs/router/`, incl. pnpm's nested layout) or the monorepo workspace
|
|
18
|
-
* (`/packages/rangojs-router/`). The package-anchored path avoids matching a
|
|
19
|
-
* consumer file that merely sits under a directory named `rangojs-router`.
|
|
20
|
-
* Accepts module ids and dev-server URLs (`/@fs/...internal-debug.ts?v=abc`).
|
|
21
|
-
*/
|
|
2
|
+
/** A router flag module: internal-debug.ts or internal-suspense-audit.ts. */
|
|
22
3
|
export declare function isRouterInternalDebugId(id: string): boolean;
|
|
23
4
|
/**
|
|
24
|
-
* Transform: replace
|
|
25
|
-
* Returns null for any
|
|
5
|
+
* Transform: replace a router flag module with the resolved literal.
|
|
6
|
+
* Returns null for any other module.
|
|
26
7
|
*/
|
|
27
8
|
export declare function injectClientDebugFlag(id: string): {
|
|
28
9
|
code: string;
|
|
@@ -44,9 +25,9 @@ export declare function injectClientDebugFlag(id: string): {
|
|
|
44
25
|
* immune -- workspace source is outside node_modules and served no-cache --
|
|
45
26
|
* which is why this bit only npm consumers.
|
|
46
27
|
*
|
|
47
|
-
*
|
|
48
|
-
* are byte-identical across flag states), so forcing revalidation for
|
|
49
|
-
*
|
|
28
|
+
* The two flag modules are the only flag-varying modules in the graph (their
|
|
29
|
+
* importers are byte-identical across flag states), so forcing revalidation for
|
|
30
|
+
* them is sufficient and costs a conditional request each per session. The
|
|
50
31
|
* middleware is unconditional (not gated on the flag) so an already-poisoned
|
|
51
32
|
* cache heals in both directions. Alternatives that do not work: a plugin
|
|
52
33
|
* `resolveId` appending a flag query never fires in Vite 8 dev for
|
|
@@ -213,6 +213,33 @@ interface RangoBaseOptions {
|
|
|
213
213
|
prerender?: {
|
|
214
214
|
onError?: "fail" | "warn";
|
|
215
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* The key inline server actions encrypt their bound arguments with:
|
|
218
|
+
* base64-encoded 32 bytes (`openssl rand -base64 32`). Pass it from the
|
|
219
|
+
* environment, never as a literal in the config file:
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* rango({ encryptionKey: process.env.RANGO_ENCRYPTION_KEY })
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* Why set it: the key is part of the cache version of every router whose
|
|
226
|
+
* server code encrypts with it, because a payload cached under one key
|
|
227
|
+
* carries arguments another key cannot decrypt. Without a stable key rango
|
|
228
|
+
* generates one per build, so those routers get a new version, and a cleared
|
|
229
|
+
* cache, on every deploy. With a stable key their cache survives a deploy
|
|
230
|
+
* that does not change their server code. It also lets a build decrypt
|
|
231
|
+
* arguments an earlier build encrypted (a cached or prerendered payload, an
|
|
232
|
+
* open tab).
|
|
233
|
+
*
|
|
234
|
+
* Validated when `rango()` is called: a value that is not base64 or does not
|
|
235
|
+
* decode to an AES key size (16, 24 or 32 bytes) throws. `undefined` (the
|
|
236
|
+
* variable is unset) falls back to the `RANGO_ENCRYPTION_KEY` environment
|
|
237
|
+
* variable, then to a generated key. Rotating the key clears the cache of
|
|
238
|
+
* the routers that use it.
|
|
239
|
+
*
|
|
240
|
+
* @default process.env.RANGO_ENCRYPTION_KEY, else a key generated per build
|
|
241
|
+
*/
|
|
242
|
+
encryptionKey?: string;
|
|
216
243
|
}
|
|
217
244
|
/**
|
|
218
245
|
* Options for Node.js deployment (default)
|