@rangojs/router 0.0.0-experimental.d7eeaa75 → 0.0.0-experimental.d98a8e9d
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 +120 -25
- package/dist/bin/rango.js +147 -57
- package/dist/testing/vitest.js +82 -0
- package/dist/vite/index.js +2154 -861
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +57 -11
- package/skills/api-client/SKILL.md +211 -0
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +220 -30
- package/skills/caching/SKILL.md +116 -8
- 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 +247 -17
- package/skills/loader/SKILL.md +219 -9
- package/skills/middleware/SKILL.md +47 -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 +71 -6
- package/skills/prerender/SKILL.md +14 -33
- package/skills/rango/SKILL.md +243 -22
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +122 -47
- package/skills/route/SKILL.md +57 -4
- package/skills/router-setup/SKILL.md +3 -3
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/testing/SKILL.md +128 -0
- package/skills/testing/bindings.md +89 -0
- package/skills/testing/cache-prerender.md +98 -0
- package/skills/testing/client-components.md +121 -0
- package/skills/testing/e2e-parity.md +124 -0
- package/skills/testing/flight.md +89 -0
- package/skills/testing/handles.md +127 -0
- package/skills/testing/loader.md +108 -0
- package/skills/testing/middleware.md +97 -0
- package/skills/testing/render-handler.md +102 -0
- package/skills/testing/response-routes.md +94 -0
- package/skills/testing/reverse-and-types.md +83 -0
- package/skills/testing/server-actions.md +89 -0
- package/skills/testing/server-tree.md +128 -0
- package/skills/testing/setup.md +120 -0
- package/skills/typesafety/SKILL.md +319 -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 +116 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/event-controller.ts +86 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/navigation-bridge.ts +84 -11
- package/src/browser/navigation-client.ts +104 -68
- package/src/browser/navigation-store.ts +32 -9
- package/src/browser/navigation-transaction.ts +10 -28
- package/src/browser/partial-update.ts +64 -26
- package/src/browser/prefetch/cache.ts +183 -44
- package/src/browser/prefetch/fetch.ts +228 -37
- package/src/browser/prefetch/queue.ts +36 -5
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +30 -2
- package/src/browser/react/NavigationProvider.tsx +72 -31
- 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 +17 -9
- 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 +22 -2
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +32 -1
- package/src/browser/rsc-router.tsx +69 -22
- package/src/browser/scroll-restoration.ts +22 -14
- package/src/browser/segment-reconciler.ts +36 -14
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +23 -30
- package/src/browser/types.ts +21 -0
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +60 -35
- package/src/build/generate-route-types.ts +2 -0
- package/src/build/index.ts +8 -1
- package/src/build/prefix-tree-utils.ts +123 -0
- package/src/build/route-trie.ts +95 -25
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +1 -1
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +55 -14
- package/src/build/route-types/scan-filter.ts +1 -1
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-scope.ts +28 -42
- package/src/cache/cf/cf-cache-store.ts +54 -13
- package/src/client.rsc.tsx +3 -0
- package/src/client.tsx +96 -205
- package/src/context-var.ts +5 -5
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -4
- package/src/handle.ts +32 -14
- 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 -21
- package/src/index.rsc.ts +10 -6
- package/src/index.ts +54 -17
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +25 -7
- package/src/loader.ts +16 -9
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender.ts +27 -6
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -36
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +384 -257
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +100 -28
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-types.ts +26 -41
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +15 -2
- package/src/router/error-handling.ts +1 -1
- package/src/router/find-match.ts +54 -6
- package/src/router/handler-context.ts +21 -38
- package/src/router/intercept-resolution.ts +4 -18
- package/src/router/lazy-includes.ts +41 -22
- package/src/router/loader-resolution.ts +82 -36
- package/src/router/manifest.ts +41 -19
- package/src/router/match-api.ts +4 -3
- package/src/router/match-handlers.ts +63 -20
- package/src/router/match-middleware/cache-lookup.ts +44 -91
- package/src/router/match-middleware/cache-store.ts +3 -2
- package/src/router/match-result.ts +53 -32
- package/src/router/metrics.ts +1 -1
- package/src/router/middleware-types.ts +15 -26
- package/src/router/middleware.ts +99 -84
- package/src/router/pattern-matching.ts +116 -19
- package/src/router/prerender-match.ts +1 -1
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +4 -28
- package/src/router/revalidation.ts +58 -2
- package/src/router/router-interfaces.ts +45 -28
- package/src/router/router-options.ts +40 -1
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +27 -6
- package/src/router/segment-resolution/revalidation.ts +147 -106
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry.ts +99 -0
- package/src/router/trie-matching.ts +40 -16
- package/src/router/types.ts +8 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +52 -30
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +28 -69
- package/src/rsc/helpers.ts +91 -43
- package/src/rsc/index.ts +1 -1
- package/src/rsc/manifest-init.ts +28 -41
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/progressive-enhancement.ts +4 -0
- package/src/rsc/response-error.ts +79 -12
- package/src/rsc/response-route-handler.ts +57 -61
- package/src/rsc/rsc-rendering.ts +35 -51
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +17 -37
- package/src/rsc/ssr-setup.ts +16 -0
- package/src/rsc/types.ts +8 -2
- package/src/runtime-env.ts +18 -0
- 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 +132 -116
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +175 -53
- package/src/server/cookie-store.ts +28 -4
- package/src/server/request-context.ts +67 -51
- package/src/ssr/index.tsx +5 -1
- package/src/static-handler.ts +25 -3
- package/src/testing/cache-status.ts +166 -0
- package/src/testing/collect-handle.ts +63 -0
- package/src/testing/dispatch.ts +581 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +188 -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 +326 -0
- package/src/testing/e2e/server.ts +195 -0
- package/src/testing/flight-matchers.ts +110 -0
- package/src/testing/flight-normalize.ts +38 -0
- package/src/testing/flight-runtime.d.ts +57 -0
- package/src/testing/flight-tree.ts +682 -0
- package/src/testing/flight.entry.ts +51 -0
- package/src/testing/flight.ts +234 -0
- package/src/testing/generated-routes.ts +223 -0
- package/src/testing/index.ts +106 -0
- package/src/testing/internal/context.ts +304 -0
- package/src/testing/internal/flight-client-globals.ts +30 -0
- package/src/testing/internal/seed-vars.ts +42 -0
- package/src/testing/render-handler.ts +323 -0
- package/src/testing/render-route.tsx +590 -0
- package/src/testing/run-loader.ts +363 -0
- package/src/testing/run-middleware.ts +205 -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 +285 -0
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +68 -50
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +11 -9
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-entry.ts +11 -0
- package/src/types/segments.ts +35 -2
- package/src/urls/include-helper.ts +34 -67
- package/src/urls/index.ts +1 -5
- package/src/urls/path-helper-types.ts +41 -7
- package/src/urls/path-helper.ts +17 -52
- package/src/urls/pattern-types.ts +36 -19
- package/src/urls/response-types.ts +22 -29
- package/src/urls/type-extraction.ts +58 -139
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +413 -42
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +6 -6
- package/src/vite/discovery/discover-routers.ts +106 -75
- 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 +67 -26
- 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 +33 -0
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +2 -0
- package/src/vite/plugin-types.ts +67 -0
- 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 +54 -30
- package/src/vite/plugins/expose-id-utils.ts +12 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
- 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 +496 -486
- package/src/vite/plugins/performance-tracks.ts +29 -25
- 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 +59 -2
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +116 -29
- package/src/vite/router-discovery.ts +750 -100
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +1 -1
- 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 +8 -59
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +21 -6
- package/src/vite/utils/shared-utils.ts +107 -26
- package/src/browser/action-response-classifier.ts +0 -99
|
@@ -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
|
|
@@ -20,6 +20,13 @@ export interface PluginOptions {
|
|
|
20
20
|
buildEnv?: import("../plugin-types.js").BuildEnvOption;
|
|
21
21
|
/** Deployment preset (needed for buildEnv "auto" resolution). */
|
|
22
22
|
preset?: "node" | "cloudflare";
|
|
23
|
+
/**
|
|
24
|
+
* Shared context the built-in clientChunks strategy reads. Discovery populates
|
|
25
|
+
* it (registered fallback hashes + single-router name) before the client build
|
|
26
|
+
* invokes the strategy. Present only when the built-in strategy is active
|
|
27
|
+
* (`clientChunks: true`/default); undefined for `false` or a custom function.
|
|
28
|
+
*/
|
|
29
|
+
clientChunkCtx?: import("../utils/client-chunks.js").ClientChunkContext;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
export interface PrecomputedEntry {
|
|
@@ -45,6 +52,21 @@ export interface DiscoveryState {
|
|
|
45
52
|
projectRoot: string;
|
|
46
53
|
isBuildMode: boolean;
|
|
47
54
|
userResolveAlias: any;
|
|
55
|
+
/**
|
|
56
|
+
* Data-only slice of the user's resolved config (resolve.* incl. native
|
|
57
|
+
* tsconfigPaths, define, oxc) mirrored into the discovery temp server so it
|
|
58
|
+
* resolves and transforms modules the same way the real environment does.
|
|
59
|
+
* See `utils/forward-user-plugins.ts`.
|
|
60
|
+
*/
|
|
61
|
+
userRunnerConfig:
|
|
62
|
+
| import("../utils/forward-user-plugins.js").ForwardedRunnerConfig
|
|
63
|
+
| undefined;
|
|
64
|
+
/**
|
|
65
|
+
* User resolution plugins (resolveId/load), stripped to their resolution
|
|
66
|
+
* surface, forwarded into the discovery temp server. Lets third-party
|
|
67
|
+
* resolvers such as vite-tsconfig-paths participate in discovery.
|
|
68
|
+
*/
|
|
69
|
+
userResolvePlugins: import("vite").Plugin[];
|
|
48
70
|
scanFilter: ScanFilter | undefined;
|
|
49
71
|
cachedRouterFiles: string[] | undefined;
|
|
50
72
|
opts: PluginOptions | undefined;
|
|
@@ -76,6 +98,14 @@ export interface DiscoveryState {
|
|
|
76
98
|
resolvedBuildEnv?: Record<string, unknown>;
|
|
77
99
|
/** Cleanup function for build-time env resources (e.g., miniflare). */
|
|
78
100
|
buildEnvDispose?: (() => Promise<void> | void) | null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Set when the most recent HMR re-discovery threw. Cleared on the next
|
|
104
|
+
* successful discovery. Surfaced via debug logs so we can detect "manifest
|
|
105
|
+
* frozen at last-good after error → user fix in non-route file → no
|
|
106
|
+
* rediscovery trigger" scenarios.
|
|
107
|
+
*/
|
|
108
|
+
lastDiscoveryError?: { message: string; at: number } | null;
|
|
79
109
|
}
|
|
80
110
|
|
|
81
111
|
export function createDiscoveryState(
|
|
@@ -87,6 +117,8 @@ export function createDiscoveryState(
|
|
|
87
117
|
projectRoot: "",
|
|
88
118
|
isBuildMode: false,
|
|
89
119
|
userResolveAlias: undefined,
|
|
120
|
+
userRunnerConfig: undefined,
|
|
121
|
+
userResolvePlugins: [],
|
|
90
122
|
scanFilter: undefined,
|
|
91
123
|
cachedRouterFiles: undefined,
|
|
92
124
|
opts,
|
|
@@ -113,5 +145,6 @@ export function createDiscoveryState(
|
|
|
113
145
|
devServer: null,
|
|
114
146
|
selfWrittenGenFiles: new Map(),
|
|
115
147
|
SELF_WRITE_WINDOW_MS: 5_000,
|
|
148
|
+
lastDiscoveryError: null,
|
|
116
149
|
};
|
|
117
150
|
}
|
|
@@ -58,7 +58,7 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const lines = [
|
|
61
|
-
`import { setCachedManifest,
|
|
61
|
+
`import { setCachedManifest, setRouterManifest, registerRouterManifestLoader, clearAllRouterData } from "@rangojs/router/server";`,
|
|
62
62
|
...genFileImports,
|
|
63
63
|
// Clear stale per-router cached data (manifest, trie, precomputed entries)
|
|
64
64
|
// before re-populating. In Cloudflare dev mode, program reloads re-evaluate
|
|
@@ -101,28 +101,18 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
lines.push(
|
|
117
|
-
`setPrecomputedEntries(${jsonParseExpression(state.mergedPrecomputedEntries)});`,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
if (state.mergedRouteTrie) {
|
|
121
|
-
lines.push(
|
|
122
|
-
`setRouteTrie(${jsonParseExpression(state.mergedRouteTrie)});`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
104
|
+
// Per-router trie and precomputedEntries are NOT inlined eagerly.
|
|
105
|
+
// They live in the per-router lazy chunks (generatePerRouterModule) and
|
|
106
|
+
// are loaded via ensureRouterManifest(routerId), which is awaited before
|
|
107
|
+
// every request in router.fetch() and before findMatch is reached.
|
|
108
|
+
// Inlining the merged versions here would duplicate the per-router data
|
|
109
|
+
// (the merged trie/precomputedEntries equal the per-router data for
|
|
110
|
+
// single-router apps; for multi-router, the merged trie is dead code
|
|
111
|
+
// because find-match.ts only consumes per-router tries).
|
|
112
|
+
//
|
|
113
|
+
// In dev mode, the handler also falls back to Phase 2 regex matching
|
|
114
|
+
// against live router.urlpatterns, which is always correct after a
|
|
115
|
+
// program reload.
|
|
126
116
|
|
|
127
117
|
// Register lazy loaders for per-router manifest modules.
|
|
128
118
|
// Each import() uses a static string literal so Rollup creates separate chunks.
|
package/src/vite/index.ts
CHANGED
package/src/vite/plugin-types.ts
CHANGED
|
@@ -47,6 +47,64 @@ export type BuildEnvOption =
|
|
|
47
47
|
| Record<string, unknown>
|
|
48
48
|
| BuildEnvFactory;
|
|
49
49
|
|
|
50
|
+
// -- Client chunking --------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Metadata for one client ("use client") module, passed to a {@link ClientChunks}
|
|
54
|
+
* function. Mirrors the shape `@vitejs/plugin-rsc` passes to its own
|
|
55
|
+
* `clientChunks` option.
|
|
56
|
+
*/
|
|
57
|
+
export interface ClientChunkMeta {
|
|
58
|
+
/** Absolute module id of the "use client" file. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Normalized (posix) module id — convenient for path-based matching. */
|
|
61
|
+
normalizedId: string;
|
|
62
|
+
/**
|
|
63
|
+
* The RSC/server chunk that statically imports this client reference. This is
|
|
64
|
+
* the key used for the default grouping when no override is supplied: a single
|
|
65
|
+
* router that statically imports every route yields ONE `serverChunk`, hence
|
|
66
|
+
* one client chunk for all routes.
|
|
67
|
+
*/
|
|
68
|
+
serverChunk: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Controls how client ("use client") components are grouped into browser
|
|
73
|
+
* chunks, i.e. per-route / per-feature code splitting of the client bundle.
|
|
74
|
+
*
|
|
75
|
+
* Without splitting, a single router ships ONE client chunk containing every
|
|
76
|
+
* route's client components (and their CSS) — navigating to one route downloads
|
|
77
|
+
* every other route's client code. (Host sub-apps loaded via a dynamic `import()`
|
|
78
|
+
* are the exception: each forms its own chunk.) This option controls how that
|
|
79
|
+
* monolith is split.
|
|
80
|
+
*
|
|
81
|
+
* Behavior branches:
|
|
82
|
+
* - `true` / omitted (**default**, pre-1.0): Rango's built-in **directory
|
|
83
|
+
* strategy**. It splits app `"use client"` modules by **route id** — the segment
|
|
84
|
+
* after a route-root directory (`routes`, `app`, `pages`, `features`, `handlers`,
|
|
85
|
+
* …) — so `routes/dashboard/**` becomes `app-dashboard` at any nesting depth.
|
|
86
|
+
* Where it finds NO route structure (a flat `src/components/`, or host sub-apps
|
|
87
|
+
* already split by a dynamic `import()`), it inherits the default grouping
|
|
88
|
+
* unchanged — so the shared `src/components` chunk stays shared and host apps do
|
|
89
|
+
* not leak across each other. Shared runtime (React, the router, `node_modules`)
|
|
90
|
+
* is never split.
|
|
91
|
+
* - `false`: opt out — inherit `@vitejs/plugin-rsc`'s default grouping everywhere
|
|
92
|
+
* (one chunk per router / per host sub-app).
|
|
93
|
+
* - function: full override. Return a chunk group name, or `undefined` to fall
|
|
94
|
+
* back to the default grouping for that one module. Forwarded directly to
|
|
95
|
+
* `@vitejs/plugin-rsc`'s `clientChunks`.
|
|
96
|
+
*
|
|
97
|
+
* Every module maps to exactly one group, so there is no byte duplication: a
|
|
98
|
+
* component used by two routes lives in one group and is fetched whenever it
|
|
99
|
+
* renders. Put genuinely shared client components OUTSIDE route directories so
|
|
100
|
+
* they land in the shared group rather than one route's chunk.
|
|
101
|
+
*
|
|
102
|
+
* @default true
|
|
103
|
+
*/
|
|
104
|
+
export type ClientChunks =
|
|
105
|
+
| boolean
|
|
106
|
+
| ((meta: ClientChunkMeta) => string | undefined);
|
|
107
|
+
|
|
50
108
|
// -- Plugin options ---------------------------------------------------------
|
|
51
109
|
|
|
52
110
|
/**
|
|
@@ -59,6 +117,15 @@ interface RangoBaseOptions {
|
|
|
59
117
|
*/
|
|
60
118
|
banner?: boolean;
|
|
61
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Group client ("use client") components into browser chunks for per-route /
|
|
122
|
+
* per-feature code splitting. On by default (pre-1.0); pass `false` to opt out.
|
|
123
|
+
* See {@link ClientChunks}.
|
|
124
|
+
*
|
|
125
|
+
* @default true
|
|
126
|
+
*/
|
|
127
|
+
clientChunks?: ClientChunks;
|
|
128
|
+
|
|
62
129
|
/**
|
|
63
130
|
* Environment bindings available to Prerender and Static handlers at build
|
|
64
131
|
* time via `ctx.env`. Applies to both production build and dev on-demand
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import { createRangoDebugger, NS } from "../debug.js";
|
|
3
|
+
|
|
4
|
+
const debug = createRangoDebugger(NS.transform);
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Transform CJS vendor files from @vitejs/plugin-rsc to ESM for browser compatibility.
|
|
@@ -9,18 +12,16 @@ export function createCjsToEsmPlugin(): Plugin {
|
|
|
9
12
|
name: "@rangojs/router:cjs-to-esm",
|
|
10
13
|
enforce: "pre",
|
|
11
14
|
transform(code, id) {
|
|
12
|
-
const cleanId = id.split("?")[0];
|
|
15
|
+
const cleanId = id.split("?")[0].replaceAll("\\", "/");
|
|
13
16
|
|
|
14
17
|
// Transform the client.browser.js entry point to re-export from CJS
|
|
15
|
-
if (
|
|
16
|
-
cleanId.includes("vendor/react-server-dom/client.browser.js") ||
|
|
17
|
-
cleanId.includes("vendor\\react-server-dom\\client.browser.js")
|
|
18
|
-
) {
|
|
18
|
+
if (cleanId.includes("vendor/react-server-dom/client.browser.js")) {
|
|
19
19
|
const isProd = process.env.NODE_ENV === "production";
|
|
20
20
|
const cjsFile = isProd
|
|
21
21
|
? "./cjs/react-server-dom-webpack-client.browser.production.js"
|
|
22
22
|
: "./cjs/react-server-dom-webpack-client.browser.development.js";
|
|
23
23
|
|
|
24
|
+
debug?.("cjs-to-esm entry redirect %s", id);
|
|
24
25
|
return {
|
|
25
26
|
code: `export * from "${cjsFile}";`,
|
|
26
27
|
map: null,
|
|
@@ -29,8 +30,7 @@ export function createCjsToEsmPlugin(): Plugin {
|
|
|
29
30
|
|
|
30
31
|
// Transform the actual CJS files to ESM
|
|
31
32
|
if (
|
|
32
|
-
|
|
33
|
-
cleanId.includes("vendor\\react-server-dom\\cjs\\")) &&
|
|
33
|
+
cleanId.includes("vendor/react-server-dom/cjs/") &&
|
|
34
34
|
cleanId.includes("client.browser")
|
|
35
35
|
) {
|
|
36
36
|
let transformed = code;
|
|
@@ -81,6 +81,7 @@ export function createCjsToEsmPlugin(): Plugin {
|
|
|
81
81
|
// Reconstruct with license at the top
|
|
82
82
|
transformed = license + "\n" + transformed;
|
|
83
83
|
|
|
84
|
+
debug?.("cjs-to-esm body rewrite %s", id);
|
|
84
85
|
return {
|
|
85
86
|
code: transformed,
|
|
86
87
|
map: null,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { Plugin, ResolvedConfig } from "vite";
|
|
2
|
+
import { createRangoDebugger, NS } from "../debug.js";
|
|
3
|
+
|
|
4
|
+
const debug = createRangoDebugger(NS.transform);
|
|
2
5
|
|
|
3
6
|
const CLIENT_IN_SERVER_PROXY_PREFIX =
|
|
4
7
|
"virtual:vite-rsc/client-in-server-package-proxy/";
|
|
@@ -62,6 +65,7 @@ export function extractPackageName(absolutePath: string): string | null {
|
|
|
62
65
|
*/
|
|
63
66
|
export function clientRefDedup(): Plugin {
|
|
64
67
|
let clientExclude: string[] = [];
|
|
68
|
+
const dedupedPackages = new Set<string>();
|
|
65
69
|
|
|
66
70
|
return {
|
|
67
71
|
name: "@rangojs/router:client-ref-dedup",
|
|
@@ -76,6 +80,16 @@ export function clientRefDedup(): Plugin {
|
|
|
76
80
|
clientEnv?.optimizeDeps?.exclude ?? config.optimizeDeps?.exclude ?? [];
|
|
77
81
|
},
|
|
78
82
|
|
|
83
|
+
buildEnd() {
|
|
84
|
+
if (debug && dedupedPackages.size > 0) {
|
|
85
|
+
debug(
|
|
86
|
+
"client-ref-dedup: redirected %d package(s) (%s)",
|
|
87
|
+
dedupedPackages.size,
|
|
88
|
+
[...dedupedPackages].join(","),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
79
93
|
resolveId(source, importer, options) {
|
|
80
94
|
// Only intercept in the client environment
|
|
81
95
|
if (this.environment?.name !== "client") return;
|
|
@@ -95,6 +109,8 @@ export function clientRefDedup(): Plugin {
|
|
|
95
109
|
// Don't redirect packages that are excluded from optimization
|
|
96
110
|
if (clientExclude.includes(packageName)) return;
|
|
97
111
|
|
|
112
|
+
if (debug) dedupedPackages.add(packageName);
|
|
113
|
+
|
|
98
114
|
// Return a virtual module that re-exports via bare specifier
|
|
99
115
|
return `\0rango:dedup/${packageName}`;
|
|
100
116
|
},
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
+
import { createRangoDebugger, createCounter, NS } from "../debug.js";
|
|
5
|
+
|
|
6
|
+
const debug = createRangoDebugger(NS.transform);
|
|
4
7
|
|
|
5
8
|
// Dev-mode client-reference key prefixes emitted by @vitejs/plugin-rsc
|
|
6
9
|
const CLIENT_PKG_PROXY_PREFIX =
|
|
@@ -19,6 +22,17 @@ const FS_PREFIX = "/@fs/";
|
|
|
19
22
|
* Returns the input unchanged if it doesn't match a known dev-mode pattern
|
|
20
23
|
* (e.g., already a production hash).
|
|
21
24
|
*/
|
|
25
|
+
/**
|
|
26
|
+
* The production client-reference key hash: `sha256(relativeId).slice(0,12)`,
|
|
27
|
+
* matching @vitejs/plugin-rsc's `hashString`. Exported so the client-chunks
|
|
28
|
+
* strategy can hash a `clientChunks` callback's `meta.normalizedId` (already the
|
|
29
|
+
* project-root-relative id) and compare it against fallback hashes collected
|
|
30
|
+
* during discovery.
|
|
31
|
+
*/
|
|
32
|
+
export function hashRefKey(relativeId: string): string {
|
|
33
|
+
return createHash("sha256").update(relativeId).digest("hex").slice(0, 12);
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
export function computeProductionHash(
|
|
23
37
|
projectRoot: string,
|
|
24
38
|
refKey: string,
|
|
@@ -46,7 +60,7 @@ export function computeProductionHash(
|
|
|
46
60
|
return refKey;
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
return
|
|
63
|
+
return hashRefKey(toHash);
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
// Regex to match registerClientReference() calls as emitted by @vitejs/plugin-rsc.
|
|
@@ -89,6 +103,7 @@ export function transformClientRefs(
|
|
|
89
103
|
* regex replacement of Flight payloads.
|
|
90
104
|
*/
|
|
91
105
|
export function hashClientRefs(projectRoot: string): Plugin {
|
|
106
|
+
const counter = createCounter(debug, "hash-client-refs");
|
|
92
107
|
return {
|
|
93
108
|
name: "@rangojs/router:hash-client-refs",
|
|
94
109
|
// Run after the RSC plugin's transform (default enforce is normal)
|
|
@@ -96,10 +111,18 @@ export function hashClientRefs(projectRoot: string): Plugin {
|
|
|
96
111
|
applyToEnvironment(env) {
|
|
97
112
|
return env.name === "rsc";
|
|
98
113
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
buildEnd() {
|
|
115
|
+
counter?.flush();
|
|
116
|
+
},
|
|
117
|
+
transform(code, id) {
|
|
118
|
+
const start = counter ? performance.now() : 0;
|
|
119
|
+
try {
|
|
120
|
+
const result = transformClientRefs(code, projectRoot);
|
|
121
|
+
if (result === null) return;
|
|
122
|
+
return { code: result, map: null };
|
|
123
|
+
} finally {
|
|
124
|
+
counter?.record(id, performance.now() - start);
|
|
125
|
+
}
|
|
103
126
|
},
|
|
104
127
|
};
|
|
105
128
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface LoaderResolveContext {
|
|
2
|
+
parentURL?: string;
|
|
3
|
+
conditions?: readonly string[];
|
|
4
|
+
importAttributes?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface LoaderResolveResult {
|
|
8
|
+
shortCircuit?: boolean;
|
|
9
|
+
url: string;
|
|
10
|
+
format?: "module" | "commonjs" | "json" | "wasm" | null;
|
|
11
|
+
importAttributes?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type NextResolve = (
|
|
15
|
+
specifier: string,
|
|
16
|
+
context?: LoaderResolveContext,
|
|
17
|
+
) => Promise<LoaderResolveResult>;
|
|
18
|
+
|
|
19
|
+
export function resolve(
|
|
20
|
+
specifier: string,
|
|
21
|
+
context: LoaderResolveContext,
|
|
22
|
+
nextResolve: NextResolve,
|
|
23
|
+
): Promise<LoaderResolveResult>;
|