@rangojs/router 0.0.0-experimental.124 → 0.0.0-experimental.126
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 +6 -4
- package/dist/bin/rango.js +3 -4
- package/dist/vite/index.js +315 -68
- package/package.json +19 -18
- package/skills/breadcrumbs/SKILL.md +60 -0
- package/skills/hooks/SKILL.md +2 -2
- package/skills/route/SKILL.md +6 -0
- package/skills/server-actions/SKILL.md +25 -1
- package/skills/testing/SKILL.md +17 -17
- package/skills/testing/cache-prerender.md +29 -3
- package/skills/testing/flight.md +13 -10
- package/skills/testing/render-handler.md +3 -0
- package/skills/testing/server-tree.md +1 -1
- package/skills/testing/setup.md +1 -1
- package/src/__internal.ts +0 -65
- package/src/browser/action-coordinator.ts +1 -1
- package/src/browser/action-fence.ts +10 -0
- package/src/browser/event-controller.ts +1 -83
- package/src/browser/navigation-store-handle.ts +3 -4
- package/src/browser/navigation-store.ts +0 -39
- package/src/browser/navigation-transaction.ts +0 -32
- package/src/browser/partial-update.ts +23 -84
- package/src/browser/prefetch/cache.ts +6 -45
- package/src/browser/prefetch/queue.ts +6 -3
- package/src/browser/rango-state.ts +2 -23
- package/src/browser/react/Link.tsx +0 -2
- package/src/browser/react/NavigationProvider.tsx +2 -1
- package/src/browser/react/ScrollRestoration.tsx +10 -6
- package/src/browser/react/filter-segment-order.ts +0 -2
- package/src/browser/react/index.ts +0 -45
- package/src/browser/react/location-state-shared.ts +0 -13
- package/src/browser/react/location-state.ts +0 -1
- package/src/browser/react/use-action.ts +6 -15
- package/src/browser/react/use-handle.ts +0 -5
- package/src/browser/react/use-link-status.ts +0 -4
- package/src/browser/react/use-navigation.ts +0 -3
- package/src/browser/react/use-params.ts +0 -2
- package/src/browser/react/use-router.ts +2 -1
- package/src/browser/react/use-search-params.ts +0 -5
- package/src/browser/react/use-segments.ts +0 -13
- package/src/browser/rsc-router.tsx +10 -3
- package/src/browser/server-action-bridge.ts +51 -3
- package/src/browser/types.ts +23 -5
- package/src/browser/validate-redirect-origin.ts +43 -16
- package/src/build/index.ts +8 -9
- package/src/build/route-trie.ts +46 -11
- package/src/build/route-types/param-extraction.ts +6 -3
- package/src/build/route-types/router-processing.ts +0 -8
- package/src/cache/cache-policy.ts +0 -54
- package/src/cache/cache-runtime.ts +48 -24
- package/src/cache/cache-scope.ts +0 -27
- package/src/cache/cache-tag.ts +0 -37
- package/src/cache/cf/cf-cache-store.ts +72 -45
- package/src/cache/cf/index.ts +0 -24
- package/src/cache/document-cache.ts +10 -36
- package/src/cache/handle-snapshot.ts +0 -40
- package/src/cache/index.ts +0 -27
- package/src/cache/memory-segment-store.ts +0 -52
- package/src/cache/profile-registry.ts +6 -30
- package/src/cache/read-through-swr.ts +41 -11
- package/src/cache/segment-codec.ts +0 -16
- package/src/cache/types.ts +0 -98
- package/src/client.rsc.tsx +4 -22
- package/src/client.tsx +19 -32
- package/src/context-var.ts +12 -0
- package/src/defer.ts +196 -0
- package/src/deps/ssr.ts +0 -1
- package/src/handle.ts +2 -12
- package/src/handles/MetaTags.tsx +0 -14
- package/src/handles/breadcrumbs.ts +16 -5
- package/src/handles/meta.ts +0 -39
- package/src/host/cookie-handler.ts +0 -36
- package/src/host/errors.ts +0 -24
- package/src/host/index.ts +6 -0
- package/src/host/pattern-matcher.ts +7 -50
- package/src/host/router.ts +1 -65
- package/src/host/testing.ts +0 -16
- package/src/host/types.ts +6 -2
- package/src/href-client.ts +0 -4
- package/src/index.rsc.ts +27 -2
- package/src/index.ts +7 -0
- package/src/internal-debug.ts +2 -4
- package/src/loader.rsc.ts +4 -15
- package/src/loader.ts +3 -9
- package/src/network-error-thrower.tsx +1 -6
- package/src/outlet-provider.tsx +1 -5
- package/src/prerender/param-hash.ts +10 -11
- package/src/prerender/store.ts +23 -30
- package/src/prerender.ts +34 -0
- package/src/redirect-origin.ts +100 -0
- package/src/root-error-boundary.tsx +1 -19
- package/src/route-content-wrapper.tsx +1 -44
- package/src/route-definition/dsl-helpers.ts +7 -19
- package/src/route-definition/helpers-types.ts +3 -3
- package/src/route-definition/redirect.ts +43 -9
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/route-map-builder.ts +0 -16
- package/src/router/content-negotiation.ts +0 -13
- package/src/router/error-handling.ts +12 -16
- package/src/router/find-match.ts +4 -31
- package/src/router/intercept-resolution.ts +10 -1
- package/src/router/lazy-includes.ts +1 -57
- package/src/router/loader-resolution.ts +25 -23
- package/src/router/logging.ts +0 -6
- package/src/router/manifest.ts +1 -25
- package/src/router/match-api.ts +0 -20
- package/src/router/match-context.ts +0 -22
- package/src/router/match-handlers.ts +0 -43
- package/src/router/match-middleware/background-revalidation.ts +0 -7
- package/src/router/match-middleware/cache-lookup.ts +96 -179
- package/src/router/match-middleware/cache-store.ts +0 -31
- package/src/router/match-middleware/intercept-resolution.ts +0 -22
- package/src/router/match-middleware/segment-resolution.ts +0 -22
- package/src/router/match-pipelines.ts +1 -42
- package/src/router/match-result.ts +1 -52
- package/src/router/metrics.ts +0 -34
- package/src/router/middleware-types.ts +0 -116
- package/src/router/middleware.ts +77 -60
- package/src/router/navigation-snapshot.ts +0 -51
- package/src/router/params-util.ts +23 -0
- package/src/router/pattern-matching.ts +5 -56
- package/src/router/prerender-match.ts +56 -51
- package/src/router/request-classification.ts +1 -38
- package/src/router/revalidation.ts +14 -62
- package/src/router/route-snapshot.ts +0 -1
- package/src/router/router-context.ts +0 -27
- package/src/router/router-interfaces.ts +10 -0
- package/src/router/segment-resolution/fresh.ts +25 -57
- package/src/router/segment-resolution/helpers.ts +34 -0
- package/src/router/segment-resolution/loader-cache.ts +35 -23
- package/src/router/segment-resolution/revalidation.ts +188 -283
- package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
- package/src/router/segment-resolution.ts +4 -1
- package/src/router/segment-wrappers.ts +0 -3
- package/src/router/telemetry-otel.ts +0 -20
- package/src/router/telemetry.ts +0 -22
- package/src/router/timeout.ts +0 -20
- package/src/router/trie-matching.ts +66 -45
- package/src/router/types.ts +1 -63
- package/src/router/url-params.ts +0 -5
- package/src/router.ts +8 -11
- package/src/rsc/handler-context.ts +1 -0
- package/src/rsc/handler.ts +20 -4
- package/src/rsc/helpers.ts +71 -3
- package/src/rsc/json-route-result.ts +38 -0
- package/src/rsc/origin-guard.ts +9 -15
- package/src/rsc/progressive-enhancement.ts +10 -1
- package/src/rsc/redirect-guard.ts +99 -0
- package/src/rsc/response-route-handler.ts +23 -18
- package/src/rsc/rsc-rendering.ts +2 -7
- package/src/rsc/runtime-warnings.ts +14 -0
- package/src/rsc/server-action.ts +34 -29
- package/src/rsc/types.ts +6 -3
- package/src/search-params.ts +0 -16
- package/src/segment-loader-promise.ts +14 -2
- package/src/segment-system.tsx +79 -88
- package/src/server/handle-store.ts +7 -24
- package/src/server/loader-registry.ts +5 -24
- package/src/server/request-context.ts +29 -92
- package/src/ssr/index.tsx +14 -14
- package/src/static-handler.ts +2 -27
- package/src/testing/cache-status.ts +44 -48
- package/src/testing/collect-handle.ts +1 -24
- package/src/testing/dispatch.ts +43 -6
- package/src/testing/e2e/index.ts +1 -22
- package/src/testing/e2e/matchers.ts +0 -16
- package/src/testing/flight-matchers.ts +0 -13
- package/src/testing/flight-normalize.ts +3 -30
- package/src/testing/flight.ts +46 -48
- package/src/testing/generated-routes.ts +1 -41
- package/src/testing/index.ts +1 -21
- package/src/testing/internal/context.ts +3 -45
- package/src/testing/internal/seed-vars.ts +0 -26
- package/src/testing/render-handler.ts +31 -61
- package/src/testing/render-route.tsx +75 -103
- package/src/testing/run-loader.ts +0 -96
- package/src/testing/run-middleware.ts +0 -26
- package/src/theme/ThemeProvider.tsx +0 -52
- package/src/theme/ThemeScript.tsx +0 -6
- package/src/theme/constants.ts +0 -12
- package/src/theme/index.ts +0 -7
- package/src/theme/theme-context.ts +1 -5
- package/src/theme/theme-script.ts +0 -14
- package/src/theme/use-theme.ts +0 -3
- package/src/types/boundaries.ts +0 -35
- package/src/types/error-types.ts +25 -89
- package/src/types/global-namespace.ts +4 -14
- package/src/types/handler-context.ts +28 -9
- package/src/types/index.ts +0 -10
- package/src/types/request-scope.ts +0 -19
- package/src/types/route-config.ts +6 -50
- package/src/types/route-entry.ts +0 -6
- package/src/types/segments.ts +0 -13
- package/src/urls/include-helper.ts +0 -4
- package/src/urls/index.ts +0 -6
- package/src/urls/path-helper-types.ts +2 -2
- package/src/urls/path-helper.ts +0 -54
- package/src/urls/urls-function.ts +0 -13
- package/src/use-loader.tsx +0 -186
- package/src/vite/discovery/bundle-postprocess.ts +2 -1
- package/src/vite/discovery/discover-routers.ts +28 -18
- package/src/vite/discovery/prerender-collection.ts +2 -4
- package/src/vite/discovery/state.ts +5 -0
- package/src/vite/discovery/virtual-module-codegen.ts +1 -11
- package/src/vite/plugin-types.ts +35 -9
- package/src/vite/plugins/cjs-to-esm.ts +0 -11
- package/src/vite/plugins/client-ref-dedup.ts +0 -11
- package/src/vite/plugins/client-ref-hashing.ts +0 -10
- package/src/vite/plugins/cloudflare-protocol-stub.ts +0 -20
- package/src/vite/plugins/expose-action-id.ts +2 -73
- package/src/vite/plugins/expose-id-utils.ts +0 -55
- package/src/vite/plugins/expose-ids/export-analysis.ts +0 -38
- package/src/vite/plugins/expose-ids/handler-transform.ts +0 -15
- package/src/vite/plugins/expose-ids/loader-transform.ts +0 -15
- package/src/vite/plugins/expose-ids/router-transform.ts +0 -13
- package/src/vite/plugins/expose-internal-ids.ts +10 -0
- package/src/vite/plugins/performance-tracks.ts +0 -3
- package/src/vite/plugins/refresh-cmd.ts +1 -1
- package/src/vite/plugins/use-cache-transform.ts +21 -46
- package/src/vite/plugins/version-injector.ts +0 -20
- package/src/vite/plugins/version-plugin.ts +1 -49
- package/src/vite/plugins/virtual-entries.ts +0 -15
- package/src/vite/rango.ts +2 -108
- package/src/vite/router-discovery.ts +9 -1
- package/src/vite/utils/ast-handler-extract.ts +0 -16
- package/src/vite/utils/bundle-analysis.ts +6 -13
- package/src/vite/utils/client-chunks.ts +0 -6
- package/src/vite/utils/forward-user-plugins.ts +0 -22
- package/src/vite/utils/manifest-utils.ts +0 -4
- package/src/vite/utils/package-resolution.ts +1 -73
- package/src/vite/utils/prerender-utils.ts +0 -35
- package/src/vite/utils/shared-utils.ts +3 -35
- package/src/browser/shallow.ts +0 -40
- package/src/handles/index.ts +0 -7
- package/src/router/middleware-cookies.ts +0 -55
|
@@ -14,7 +14,6 @@ export function createCjsToEsmPlugin(): Plugin {
|
|
|
14
14
|
transform(code, id) {
|
|
15
15
|
const cleanId = id.split("?")[0].replaceAll("\\", "/");
|
|
16
16
|
|
|
17
|
-
// Transform the client.browser.js entry point to re-export from CJS
|
|
18
17
|
if (cleanId.includes("vendor/react-server-dom/client.browser.js")) {
|
|
19
18
|
const isProd = process.env.NODE_ENV === "production";
|
|
20
19
|
const cjsFile = isProd
|
|
@@ -28,57 +27,47 @@ export function createCjsToEsmPlugin(): Plugin {
|
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
// Transform the actual CJS files to ESM
|
|
32
30
|
if (
|
|
33
31
|
cleanId.includes("vendor/react-server-dom/cjs/") &&
|
|
34
32
|
cleanId.includes("client.browser")
|
|
35
33
|
) {
|
|
36
34
|
let transformed = code;
|
|
37
35
|
|
|
38
|
-
// Extract the license comment to preserve it
|
|
39
36
|
const licenseMatch = transformed.match(/^\/\*\*[\s\S]*?\*\//);
|
|
40
37
|
const license = licenseMatch ? licenseMatch[0] : "";
|
|
41
38
|
if (license) {
|
|
42
39
|
transformed = transformed.slice(license.length);
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
// Remove "use strict" (both dev and prod have this)
|
|
46
42
|
transformed = transformed.replace(/^\s*["']use strict["'];\s*/, "");
|
|
47
43
|
|
|
48
|
-
// Remove the conditional IIFE wrapper (development only)
|
|
49
44
|
transformed = transformed.replace(
|
|
50
45
|
/^\s*["']production["']\s*!==\s*process\.env\.NODE_ENV\s*&&\s*\(function\s*\(\)\s*\{/,
|
|
51
46
|
"",
|
|
52
47
|
);
|
|
53
48
|
|
|
54
|
-
// Remove the closing of the conditional IIFE at the end (development only)
|
|
55
49
|
transformed = transformed.replace(/\}\)\(\);?\s*$/, "");
|
|
56
50
|
|
|
57
|
-
// Replace require('react') and require('react-dom') with imports (development)
|
|
58
51
|
transformed = transformed.replace(
|
|
59
52
|
/var\s+React\s*=\s*require\s*\(\s*["']react["']\s*\)\s*,[\s\n]+ReactDOM\s*=\s*require\s*\(\s*["']react-dom["']\s*\)\s*,/g,
|
|
60
53
|
'import React from "react";\nimport ReactDOM from "react-dom";\nvar ',
|
|
61
54
|
);
|
|
62
55
|
|
|
63
|
-
// Replace require('react-dom') only (production - doesn't import React)
|
|
64
56
|
transformed = transformed.replace(
|
|
65
57
|
/var\s+ReactDOM\s*=\s*require\s*\(\s*["']react-dom["']\s*\)\s*,/g,
|
|
66
58
|
'import ReactDOM from "react-dom";\nvar ',
|
|
67
59
|
);
|
|
68
60
|
|
|
69
|
-
// Transform exports.xyz = function() to export function xyz()
|
|
70
61
|
transformed = transformed.replace(
|
|
71
62
|
/exports\.(\w+)\s*=\s*function\s*\(/g,
|
|
72
63
|
"export function $1(",
|
|
73
64
|
);
|
|
74
65
|
|
|
75
|
-
// Transform exports.xyz = value to export const xyz = value
|
|
76
66
|
transformed = transformed.replace(
|
|
77
67
|
/exports\.(\w+)\s*=/g,
|
|
78
68
|
"export const $1 =",
|
|
79
69
|
);
|
|
80
70
|
|
|
81
|
-
// Reconstruct with license at the top
|
|
82
71
|
transformed = license + "\n" + transformed;
|
|
83
72
|
|
|
84
73
|
debug?.("cjs-to-esm body rewrite %s", id);
|
|
@@ -73,8 +73,6 @@ export function clientRefDedup(): Plugin {
|
|
|
73
73
|
apply: "serve",
|
|
74
74
|
|
|
75
75
|
configResolved(config: ResolvedConfig) {
|
|
76
|
-
// Respect user's optimizeDeps.exclude — if a package is explicitly
|
|
77
|
-
// excluded from pre-bundling, we shouldn't redirect it there.
|
|
78
76
|
const clientEnv = config.environments?.["client"];
|
|
79
77
|
clientExclude =
|
|
80
78
|
clientEnv?.optimizeDeps?.exclude ?? config.optimizeDeps?.exclude ?? [];
|
|
@@ -91,27 +89,19 @@ export function clientRefDedup(): Plugin {
|
|
|
91
89
|
},
|
|
92
90
|
|
|
93
91
|
resolveId(source, importer, options) {
|
|
94
|
-
// Only intercept in the client environment
|
|
95
92
|
if (this.environment?.name !== "client") return;
|
|
96
93
|
|
|
97
|
-
// Only handle imports from client-in-server-package-proxy virtual modules
|
|
98
94
|
if (!importer?.includes(CLIENT_IN_SERVER_PROXY_PREFIX)) return;
|
|
99
95
|
|
|
100
|
-
// Only handle absolute node_modules paths
|
|
101
96
|
if (!source.includes("/node_modules/")) return;
|
|
102
97
|
|
|
103
|
-
// Must have an importer
|
|
104
|
-
if (!importer) return;
|
|
105
|
-
|
|
106
98
|
const packageName = extractPackageName(source);
|
|
107
99
|
if (!packageName) return;
|
|
108
100
|
|
|
109
|
-
// Don't redirect packages that are excluded from optimization
|
|
110
101
|
if (clientExclude.includes(packageName)) return;
|
|
111
102
|
|
|
112
103
|
if (debug) dedupedPackages.add(packageName);
|
|
113
104
|
|
|
114
|
-
// Return a virtual module that re-exports via bare specifier
|
|
115
105
|
return `\0rango:dedup/${packageName}`;
|
|
116
106
|
},
|
|
117
107
|
|
|
@@ -120,7 +110,6 @@ export function clientRefDedup(): Plugin {
|
|
|
120
110
|
|
|
121
111
|
const packageName = id.slice("\0rango:dedup/".length);
|
|
122
112
|
|
|
123
|
-
// Re-export via bare specifier so Vite routes through pre-bundling
|
|
124
113
|
return [
|
|
125
114
|
`export * from ${JSON.stringify(packageName)};`,
|
|
126
115
|
`import * as __all__ from ${JSON.stringify(packageName)};`,
|
|
@@ -5,7 +5,6 @@ import { createRangoDebugger, createCounter, NS } from "../debug.js";
|
|
|
5
5
|
|
|
6
6
|
const debug = createRangoDebugger(NS.transform);
|
|
7
7
|
|
|
8
|
-
// Dev-mode client-reference key prefixes emitted by @vitejs/plugin-rsc
|
|
9
8
|
const CLIENT_PKG_PROXY_PREFIX =
|
|
10
9
|
"/@id/__x00__virtual:vite-rsc/client-package-proxy/";
|
|
11
10
|
const CLIENT_IN_SERVER_PKG_PROXY_PREFIX =
|
|
@@ -40,32 +39,24 @@ export function computeProductionHash(
|
|
|
40
39
|
let toHash: string;
|
|
41
40
|
|
|
42
41
|
if (refKey.startsWith(CLIENT_PKG_PROXY_PREFIX)) {
|
|
43
|
-
// /@id/__x00__virtual:vite-rsc/client-package-proxy/<pkg> -> hash("<pkg>")
|
|
44
42
|
toHash = refKey.slice(CLIENT_PKG_PROXY_PREFIX.length);
|
|
45
43
|
} else if (refKey.startsWith(CLIENT_IN_SERVER_PKG_PROXY_PREFIX)) {
|
|
46
|
-
// /@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/<encodedAbsPath>
|
|
47
44
|
const absPath = decodeURIComponent(
|
|
48
45
|
refKey.slice(CLIENT_IN_SERVER_PKG_PROXY_PREFIX.length),
|
|
49
46
|
);
|
|
50
47
|
toHash = relative(projectRoot, absPath).replaceAll("\\", "/");
|
|
51
48
|
} else if (refKey.startsWith(FS_PREFIX)) {
|
|
52
|
-
// /@fs/abs/path.tsx -> hash(relative(root, "/abs/path.tsx"))
|
|
53
49
|
const absPath = refKey.slice(FS_PREFIX.length - 1); // keep leading /
|
|
54
50
|
toHash = relative(projectRoot, absPath).replaceAll("\\", "/");
|
|
55
51
|
} else if (refKey.startsWith("/")) {
|
|
56
|
-
// /src/Button.tsx -> hash("src/Button.tsx")
|
|
57
52
|
toHash = refKey.slice(1);
|
|
58
53
|
} else {
|
|
59
|
-
// Already hashed or unknown format — return unchanged
|
|
60
54
|
return refKey;
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
return hashRefKey(toHash);
|
|
64
58
|
}
|
|
65
59
|
|
|
66
|
-
// Regex to match registerClientReference() calls as emitted by @vitejs/plugin-rsc.
|
|
67
|
-
// Captures the reference key (second argument) from the call.
|
|
68
|
-
// Handles two proxy forms: parenthesized expression `(expr)` and arrow-throw `() => { ... }`.
|
|
69
60
|
const REGISTER_CLIENT_REF_RE =
|
|
70
61
|
/registerClientReference\(\s*(?:(?:\([^)]*\))|(?:\(\)[\s\S]*?\}))\s*,\s*"([^"]+)"\s*,\s*"[^"]+"\s*\)/g;
|
|
71
62
|
|
|
@@ -106,7 +97,6 @@ export function hashClientRefs(projectRoot: string): Plugin {
|
|
|
106
97
|
const counter = createCounter(debug, "hash-client-refs");
|
|
107
98
|
return {
|
|
108
99
|
name: "@rangojs/router:hash-client-refs",
|
|
109
|
-
// Run after the RSC plugin's transform (default enforce is normal)
|
|
110
100
|
enforce: "post",
|
|
111
101
|
applyToEnvironment(env) {
|
|
112
102
|
return env.name === "rsc";
|
|
@@ -32,14 +32,6 @@ const IMPORT_NODE_TYPES = new Set([
|
|
|
32
32
|
"ExportAllDeclaration",
|
|
33
33
|
]);
|
|
34
34
|
|
|
35
|
-
// Keep in sync with `STUBS` in cloudflare-protocol-loader-hook.mjs —
|
|
36
|
-
// both paths (Vite transform and Node loader) need to hand out the same
|
|
37
|
-
// classes. Unknown `cloudflare:*` modules fall back to an empty default
|
|
38
|
-
// export so third-party packages (e.g. the Cloudflare Agents SDK) can
|
|
39
|
-
// pull them into the graph without crashing discovery. Discovery only
|
|
40
|
-
// evaluates module top-level code — no handlers run — so missing named
|
|
41
|
-
// exports only fail if something does `class X extends Missing {}` at
|
|
42
|
-
// module scope, which is rare outside the already-stubbed classes.
|
|
43
35
|
const STUBS: Record<string, string> = {
|
|
44
36
|
"cloudflare:workers": `
|
|
45
37
|
export class DurableObject { constructor(_ctx, _env) {} }
|
|
@@ -65,15 +57,6 @@ export default {};
|
|
|
65
57
|
`,
|
|
66
58
|
};
|
|
67
59
|
|
|
68
|
-
// Policy: unknown `cloudflare:*` specifiers resolve permissively (empty
|
|
69
|
-
// default export) rather than throwing. We prioritize dependency-graph
|
|
70
|
-
// resilience over strict validation of user imports because third-party
|
|
71
|
-
// packages can pull `cloudflare:*` modules we haven't curated, and
|
|
72
|
-
// discovery should not fail just because those modules appear in the graph.
|
|
73
|
-
// Tradeoff: unsupported user-authored `cloudflare:*` imports may fail later
|
|
74
|
-
// with a generic JS/module error instead of a tailored rango-branded hint.
|
|
75
|
-
// The test below pins this behavior so dependency compatibility is not
|
|
76
|
-
// regressed accidentally.
|
|
77
60
|
const FALLBACK_STUB = `export default {};\n`;
|
|
78
61
|
|
|
79
62
|
interface AstNode {
|
|
@@ -163,9 +146,6 @@ export function createCloudflareProtocolStubPlugin(): Plugin {
|
|
|
163
146
|
|
|
164
147
|
if (hits.length === 0) return null;
|
|
165
148
|
|
|
166
|
-
// Rewrite from last to first so earlier offsets stay valid. `start`/
|
|
167
|
-
// `end` span the full literal including quotes, so we re-emit the
|
|
168
|
-
// same quote character around the new specifier.
|
|
169
149
|
hits.sort((a, b) => b.start - a.start);
|
|
170
150
|
let out = code;
|
|
171
151
|
for (const hit of hits) {
|
|
@@ -7,9 +7,6 @@ import { createRangoDebugger, createCounter, NS } from "../debug.js";
|
|
|
7
7
|
|
|
8
8
|
const debug = createRangoDebugger(NS.transform);
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Type for the RSC plugin's manager API
|
|
12
|
-
*/
|
|
13
10
|
interface RscPluginManager {
|
|
14
11
|
serverReferenceMetaMap: Record<
|
|
15
12
|
string,
|
|
@@ -26,14 +23,9 @@ interface RscPluginApi {
|
|
|
26
23
|
manager: RscPluginManager;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
/**
|
|
30
|
-
* Get the RSC plugin's API from Vite config
|
|
31
|
-
*/
|
|
32
26
|
function getRscPluginApi(config: ResolvedConfig): RscPluginApi | undefined {
|
|
33
|
-
// Try by name first
|
|
34
27
|
let plugin = config.plugins.find((p) => p.name === "rsc:minimal");
|
|
35
28
|
|
|
36
|
-
// Fallback: find by API structure if name lookup fails
|
|
37
29
|
if (!plugin) {
|
|
38
30
|
plugin = config.plugins.find(
|
|
39
31
|
(p) =>
|
|
@@ -62,13 +54,11 @@ function getRscPluginApi(config: ResolvedConfig): RscPluginApi | undefined {
|
|
|
62
54
|
function isUseServerModule(filePath: string): boolean {
|
|
63
55
|
try {
|
|
64
56
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
65
|
-
// Remove leading comments and whitespace to find the first meaningful content
|
|
66
57
|
const trimmed = content
|
|
67
|
-
.replace(/^\s*\/\/[^\n]*\n/gm, "")
|
|
68
|
-
.replace(/^\s*\/\*[\s\S]*?\*\/\s*/gm, "")
|
|
58
|
+
.replace(/^\s*\/\/[^\n]*\n/gm, "")
|
|
59
|
+
.replace(/^\s*\/\*[\s\S]*?\*\/\s*/gm, "")
|
|
69
60
|
.trimStart();
|
|
70
61
|
|
|
71
|
-
// Check if the file starts with "use server" directive
|
|
72
62
|
return (
|
|
73
63
|
trimmed.startsWith('"use server"') || trimmed.startsWith("'use server'")
|
|
74
64
|
);
|
|
@@ -77,18 +67,6 @@ function isUseServerModule(filePath: string): boolean {
|
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
69
|
|
|
80
|
-
/**
|
|
81
|
-
* Transform code to expose action IDs on createServerReference calls.
|
|
82
|
-
* Wraps each call with an IIFE that attaches $id to the returned function.
|
|
83
|
-
*
|
|
84
|
-
* @param code - The source code to transform
|
|
85
|
-
* @param sourceId - The source file identifier (for sourcemap)
|
|
86
|
-
* @param hashToFileMap - Optional mapping from hash to file path (for server bundles)
|
|
87
|
-
*/
|
|
88
|
-
/**
|
|
89
|
-
* Apply createServerReference wrapping to a MagicString instance.
|
|
90
|
-
* Returns true if any changes were made.
|
|
91
|
-
*/
|
|
92
70
|
function applyServerReferenceWrapping(
|
|
93
71
|
code: string,
|
|
94
72
|
s: MagicString,
|
|
@@ -98,11 +76,6 @@ function applyServerReferenceWrapping(
|
|
|
98
76
|
return false;
|
|
99
77
|
}
|
|
100
78
|
|
|
101
|
-
// Match: createServerReference("hash#actionName", ...) or $$ReactClient.createServerReference(...)
|
|
102
|
-
// The RSC plugin uses $$ReactClient namespace in transformed code.
|
|
103
|
-
// Note: [^)]* cannot handle nested parens in trailing args. This is safe in practice
|
|
104
|
-
// because the RSC plugin always generates simple variable references (e.g., callServer)
|
|
105
|
-
// as the second argument, never nested function calls.
|
|
106
79
|
const pattern =
|
|
107
80
|
/((?:\$\$\w+\.)?createServerReference)\(("[^"]+#[^"]+")([^)]*)\)/g;
|
|
108
81
|
|
|
@@ -115,23 +88,19 @@ function applyServerReferenceWrapping(
|
|
|
115
88
|
const start = match.index;
|
|
116
89
|
const end = start + fullMatch.length;
|
|
117
90
|
|
|
118
|
-
// Parse the ID to potentially replace hash with file path
|
|
119
91
|
let finalIdArg = idArg;
|
|
120
92
|
if (hashToFileMap) {
|
|
121
|
-
// idArg is like '"hash#actionName"', extract the parts
|
|
122
93
|
const idValue = idArg.slice(1, -1); // Remove quotes
|
|
123
94
|
const hashMatch = idValue.match(/^([^#]+)#(.+)$/);
|
|
124
95
|
if (hashMatch) {
|
|
125
96
|
const [, hash, actionName] = hashMatch;
|
|
126
97
|
const filePath = hashToFileMap.get(hash);
|
|
127
98
|
if (filePath) {
|
|
128
|
-
// Replace hash with file path for server-side
|
|
129
99
|
finalIdArg = `"${filePath}#${actionName}"`;
|
|
130
100
|
}
|
|
131
101
|
}
|
|
132
102
|
}
|
|
133
103
|
|
|
134
|
-
// Wrap the createServerReference call to attach $$id to the returned function
|
|
135
104
|
const replacement = `(function(fn) { fn.$$id = ${finalIdArg}; return fn; })(${fnCall}(${idArg}${rest}))`;
|
|
136
105
|
s.overwrite(start, end, replacement);
|
|
137
106
|
}
|
|
@@ -155,29 +124,6 @@ function transformServerReferences(
|
|
|
155
124
|
};
|
|
156
125
|
}
|
|
157
126
|
|
|
158
|
-
/**
|
|
159
|
-
* Transform registerServerReference calls in server bundles to use file paths instead of hashes.
|
|
160
|
-
* Pattern: registerServerReference(fn, "hash", "exportName")
|
|
161
|
-
* React's registerServerReference sets $$id = hash + "#" + exportName
|
|
162
|
-
* By replacing the hash with file path, $$id will contain the file path for revalidation matching.
|
|
163
|
-
*
|
|
164
|
-
* Only actions from module-level "use server" files are transformed.
|
|
165
|
-
* Inline actions (defined in RSC components with "use server" inside a function) are NOT in
|
|
166
|
-
* hashToFileMap and keep their hashed IDs. This is intentional for client security:
|
|
167
|
-
* - Module-level "use server" files: shared action modules, file path helps revalidation
|
|
168
|
-
* - Inline actions: one-off actions in RSC, hash ID prevents file path exposure to client
|
|
169
|
-
*
|
|
170
|
-
* @param code - The source code to transform
|
|
171
|
-
* @param sourceId - The source file identifier (for sourcemap)
|
|
172
|
-
* @param hashToFileMap - Mapping from hash to file path (only module-level "use server" files)
|
|
173
|
-
*/
|
|
174
|
-
/**
|
|
175
|
-
* Apply registerServerReference wrapping to a MagicString instance.
|
|
176
|
-
* Returns true if any changes were made.
|
|
177
|
-
*
|
|
178
|
-
* Only actions from module-level "use server" files are transformed.
|
|
179
|
-
* Inline actions keep their hashed IDs for client security.
|
|
180
|
-
*/
|
|
181
127
|
function applyRegisterReferenceWrapping(
|
|
182
128
|
code: string,
|
|
183
129
|
s: MagicString,
|
|
@@ -187,8 +133,6 @@ function applyRegisterReferenceWrapping(
|
|
|
187
133
|
return false;
|
|
188
134
|
}
|
|
189
135
|
|
|
190
|
-
// Match: registerServerReference(fn, "hash", "exportName")
|
|
191
|
-
// The hash is the second argument, exportName is the third
|
|
192
136
|
const pattern =
|
|
193
137
|
/registerServerReference\(([^,]+),\s*"([^"]+)",\s*"([^"]+)"\)/g;
|
|
194
138
|
|
|
@@ -200,15 +144,9 @@ function applyRegisterReferenceWrapping(
|
|
|
200
144
|
const start = match.index;
|
|
201
145
|
const end = start + fullMatch.length;
|
|
202
146
|
|
|
203
|
-
// Look up the file path for this hash
|
|
204
147
|
const filePath = hashToFileMap.get(hash);
|
|
205
148
|
if (filePath) {
|
|
206
149
|
hasChanges = true;
|
|
207
|
-
// WRAP the call to add $id property with file path
|
|
208
|
-
// Keep the original hash for React's action registry (so loadServerAction works)
|
|
209
|
-
// Add $id (single dollar) with file path for revalidation matching
|
|
210
|
-
// Note: We use $id instead of $$id because React's registerServerReference
|
|
211
|
-
// sets $$id as a non-writable property
|
|
212
150
|
const filePathId = `${filePath}#${exportName}`;
|
|
213
151
|
const replacement = `(function(fn) { fn.$id = "${filePathId}"; return fn; })(registerServerReference(${fnArg}, "${hash}", "${exportName}"))`;
|
|
214
152
|
s.overwrite(start, end, replacement);
|
|
@@ -336,27 +274,19 @@ export function exposeActionId(): Plugin {
|
|
|
336
274
|
|
|
337
275
|
const start = counterTransform ? performance.now() : 0;
|
|
338
276
|
try {
|
|
339
|
-
// Dev mode: no hash-to-file mapping needed (IDs are already file paths)
|
|
340
277
|
return transformServerReferences(code, id);
|
|
341
278
|
} finally {
|
|
342
279
|
counterTransform?.record(id, performance.now() - start);
|
|
343
280
|
}
|
|
344
281
|
},
|
|
345
282
|
|
|
346
|
-
// Build mode: renderChunk runs after all transforms and bundling complete
|
|
347
283
|
renderChunk(code, chunk) {
|
|
348
284
|
const start = counterRender ? performance.now() : 0;
|
|
349
285
|
try {
|
|
350
|
-
// Only RSC bundle should get file paths for revalidation matching
|
|
351
|
-
// SSR bundle must NOT use file paths because client components run there
|
|
352
|
-
// and need to match the client bundle during hydration (otherwise: error #418)
|
|
353
286
|
const isRscEnv = this.environment?.name === "rsc";
|
|
354
287
|
|
|
355
|
-
// Only use file path mapping for RSC environment
|
|
356
288
|
const effectiveMap = isRscEnv ? hashToFileMap : undefined;
|
|
357
289
|
|
|
358
|
-
// For RSC bundles, both createServerReference and registerServerReference
|
|
359
|
-
// may need transforming. Use a single MagicString for correct sourcemaps.
|
|
360
290
|
if (isRscEnv && hashToFileMap) {
|
|
361
291
|
const s = new MagicString(code);
|
|
362
292
|
const changed1 = applyServerReferenceWrapping(code, s, effectiveMap);
|
|
@@ -377,7 +307,6 @@ export function exposeActionId(): Plugin {
|
|
|
377
307
|
return null;
|
|
378
308
|
}
|
|
379
309
|
|
|
380
|
-
// Non-RSC environments: only transform createServerReference calls
|
|
381
310
|
return transformServerReferences(code, chunk.fileName, effectiveMap);
|
|
382
311
|
} finally {
|
|
383
312
|
counterRender?.record(chunk.fileName, performance.now() - start);
|
|
@@ -8,21 +8,12 @@ export function normalizePath(p: string): string {
|
|
|
8
8
|
return p.split(path.sep).join("/");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Generate a short hash for an ID.
|
|
13
|
-
* Uses first 8 chars of SHA-256 hash for uniqueness while keeping IDs short.
|
|
14
|
-
* Appends export name for easier debugging in production: "abc123#ExportName"
|
|
15
|
-
*/
|
|
16
11
|
export function hashId(filePath: string, exportName: string): string {
|
|
17
12
|
const input = `${filePath}#${exportName}`;
|
|
18
13
|
const hash = crypto.createHash("sha256").update(input).digest("hex");
|
|
19
14
|
return `${hash.slice(0, 8)}#${exportName}`;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
|
-
/**
|
|
23
|
-
* Build a stable ID for an export binding. Uses hashed IDs in production
|
|
24
|
-
* builds (short + opaque) and readable path#name IDs in dev.
|
|
25
|
-
*/
|
|
26
17
|
export function makeStubId(
|
|
27
18
|
filePath: string,
|
|
28
19
|
exportName: string,
|
|
@@ -31,17 +22,6 @@ export function makeStubId(
|
|
|
31
22
|
return isBuild ? hashId(filePath, exportName) : `${filePath}#${exportName}`;
|
|
32
23
|
}
|
|
33
24
|
|
|
34
|
-
/**
|
|
35
|
-
* Generate an 8-char hex hash for an inline handler call site.
|
|
36
|
-
*
|
|
37
|
-
* Keyed on the source-order INDEX of the call (the Nth inline `fnName(...)` in
|
|
38
|
-
* the file), NOT its line number. Line numbers shift between the prerender
|
|
39
|
-
* build context and the production build context (preceding transforms differ,
|
|
40
|
-
* e.g. plugin-react boilerplate), which would desync the prerender manifest key
|
|
41
|
-
* from the runtime handler id and break prerender/static freezing. The
|
|
42
|
-
* source-order index is invariant to line shifts; `fnName` keeps Static and
|
|
43
|
-
* Prerender inline ids from colliding at the same index.
|
|
44
|
-
*/
|
|
45
25
|
export function hashInlineId(
|
|
46
26
|
filePath: string,
|
|
47
27
|
fnName: string,
|
|
@@ -61,11 +41,6 @@ export interface DetectedImports {
|
|
|
61
41
|
any: boolean;
|
|
62
42
|
}
|
|
63
43
|
|
|
64
|
-
/**
|
|
65
|
-
* Build a map from local binding name to exported names by walking
|
|
66
|
-
* ExportNamedDeclaration nodes. Handles `export const X`, `export { X }`,
|
|
67
|
-
* and `export { X as Y }`. Skips re-exports (`export { X } from "..."`).
|
|
68
|
-
*/
|
|
69
44
|
export function buildExportMap(program: any): Map<string, string[]> {
|
|
70
45
|
const exportMap = new Map<string, string[]>();
|
|
71
46
|
|
|
@@ -105,10 +80,6 @@ export function buildExportMap(program: any): Map<string, string[]> {
|
|
|
105
80
|
return exportMap;
|
|
106
81
|
}
|
|
107
82
|
|
|
108
|
-
/**
|
|
109
|
-
* Single-pass detection of all create* imports from @rangojs/router.
|
|
110
|
-
* Returns which create functions are imported so we can skip unnecessary transforms.
|
|
111
|
-
*/
|
|
112
83
|
export function detectImports(code: string): DetectedImports {
|
|
113
84
|
// Extract all import declarations from @rangojs/router in one scan
|
|
114
85
|
const importPattern =
|
|
@@ -135,10 +106,6 @@ export function detectImports(code: string): DetectedImports {
|
|
|
135
106
|
if (/\bcreateRouter\b/.test(imports)) result.router = true;
|
|
136
107
|
}
|
|
137
108
|
|
|
138
|
-
// createRouter has a stricter check: only from "@rangojs/router" (not sub-paths).
|
|
139
|
-
// NOTE: This is intentional — detectImports is used as a fast pre-filter in
|
|
140
|
-
// exposeInternalIds (which does NOT handle router transforms). The separate
|
|
141
|
-
// exposeRouterId plugin handles createRouter and DOES accept the /server subpath.
|
|
142
109
|
if (result.router) {
|
|
143
110
|
result.router =
|
|
144
111
|
/import\s*\{[^}]*\bcreateRouter\b[^}]*\}\s*from\s*["']@rangojs\/router["']/.test(
|
|
@@ -157,11 +124,6 @@ export function detectImports(code: string): DetectedImports {
|
|
|
157
124
|
return result;
|
|
158
125
|
}
|
|
159
126
|
|
|
160
|
-
/**
|
|
161
|
-
* Skip past a string literal, template literal, or comment starting at pos.
|
|
162
|
-
* Returns the index after the closing delimiter, or pos if not at a
|
|
163
|
-
* string/comment start. Handles escape sequences and nested ${} in templates.
|
|
164
|
-
*/
|
|
165
127
|
export function skipStringOrComment(code: string, pos: number): number {
|
|
166
128
|
const ch = code[pos];
|
|
167
129
|
|
|
@@ -219,11 +181,6 @@ export function skipStringOrComment(code: string, pos: number): number {
|
|
|
219
181
|
return pos;
|
|
220
182
|
}
|
|
221
183
|
|
|
222
|
-
/**
|
|
223
|
-
* Find the matching closing paren starting after an already-opened paren.
|
|
224
|
-
* Skips strings, template literals, and comments so parens inside them
|
|
225
|
-
* don't affect depth tracking. Returns the index after the closing paren.
|
|
226
|
-
*/
|
|
227
184
|
export function findMatchingParen(code: string, startPos: number): number {
|
|
228
185
|
let depth = 1;
|
|
229
186
|
let i = startPos;
|
|
@@ -240,10 +197,6 @@ export function findMatchingParen(code: string, startPos: number): number {
|
|
|
240
197
|
return i;
|
|
241
198
|
}
|
|
242
199
|
|
|
243
|
-
/**
|
|
244
|
-
* Count the number of top-level arguments in a function call.
|
|
245
|
-
* Skips nested parens, brackets, braces, strings, and comments.
|
|
246
|
-
*/
|
|
247
200
|
export function countArgs(
|
|
248
201
|
code: string,
|
|
249
202
|
startPos: number,
|
|
@@ -279,10 +232,6 @@ export function countArgs(
|
|
|
279
232
|
return hasContent ? argCount + 1 : 0;
|
|
280
233
|
}
|
|
281
234
|
|
|
282
|
-
/**
|
|
283
|
-
* Find the end of a statement: skip whitespace and optional semicolon after
|
|
284
|
-
* a closing paren position.
|
|
285
|
-
*/
|
|
286
235
|
export function findStatementEnd(code: string, pos: number): number {
|
|
287
236
|
let i = pos;
|
|
288
237
|
while (i < code.length && /\s/.test(code[i])) {
|
|
@@ -294,10 +243,6 @@ export function findStatementEnd(code: string, pos: number): number {
|
|
|
294
243
|
return i;
|
|
295
244
|
}
|
|
296
245
|
|
|
297
|
-
/**
|
|
298
|
-
* Escape special regex characters in a string so it can be safely
|
|
299
|
-
* interpolated into a RegExp pattern.
|
|
300
|
-
*/
|
|
301
246
|
export function escapeRegExp(input: string): string {
|
|
302
247
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
303
248
|
}
|
|
@@ -9,12 +9,6 @@ import {
|
|
|
9
9
|
import { codeMatchIndices } from "../../../build/route-types/source-scan.js";
|
|
10
10
|
import type { CreateExportBinding } from "./types.js";
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Check whether every non-type export in `code` is accounted for by the given
|
|
14
|
-
* bindings. Returns false if any export exists that is not one of the known
|
|
15
|
-
* create* call locals/exports, allowing callers to bail out for mixed-export
|
|
16
|
-
* files.
|
|
17
|
-
*/
|
|
18
12
|
export function isExportOnlyFile(
|
|
19
13
|
code: string,
|
|
20
14
|
bindings: CreateExportBinding[],
|
|
@@ -28,10 +22,8 @@ export function isExportOnlyFile(
|
|
|
28
22
|
for (const e of b.exportNames) knownExports.add(e);
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
// Bail on star re-exports (unknown exports)
|
|
32
25
|
if (/export\s*\*/.test(code)) return false;
|
|
33
26
|
|
|
34
|
-
// Check `export const/let/var/function/class/default X` declarations
|
|
35
27
|
const declExportPattern =
|
|
36
28
|
/export\s+(const|let|var|function|class|default)\s+(\w+)/g;
|
|
37
29
|
let match: RegExpExecArray | null;
|
|
@@ -39,8 +31,6 @@ export function isExportOnlyFile(
|
|
|
39
31
|
if (!knownExports.has(match[2])) return false;
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
// Check `export { X }` and `export { X as Y }` specifiers: the local name
|
|
43
|
-
// must reference a known create* binding.
|
|
44
34
|
const specExportPattern = /export\s*\{([^}]+)\}/g;
|
|
45
35
|
while ((match = specExportPattern.exec(code)) !== null) {
|
|
46
36
|
const specifiers = match[1]
|
|
@@ -67,9 +57,6 @@ function createCallPattern(fnNames: string[]): RegExp {
|
|
|
67
57
|
);
|
|
68
58
|
}
|
|
69
59
|
|
|
70
|
-
// Counts real create*() call sites, ignoring occurrences inside comments and
|
|
71
|
-
// string literals. Used by the unsupported-shape warning heuristic and the
|
|
72
|
-
// inline-extraction pre-check.
|
|
73
60
|
export function countCreateCallsForNames(
|
|
74
61
|
code: string,
|
|
75
62
|
fnNames: string[],
|
|
@@ -77,7 +64,6 @@ export function countCreateCallsForNames(
|
|
|
77
64
|
return codeMatchIndices(code, createCallPattern(fnNames)).length;
|
|
78
65
|
}
|
|
79
66
|
|
|
80
|
-
/** Convert a 0-based byte offset to a 1-based { line, column }. */
|
|
81
67
|
export function offsetToLineColumn(
|
|
82
68
|
code: string,
|
|
83
69
|
index: number,
|
|
@@ -94,14 +80,6 @@ export function offsetToLineColumn(
|
|
|
94
80
|
return { line, column: index - lineStart + 1 };
|
|
95
81
|
}
|
|
96
82
|
|
|
97
|
-
/**
|
|
98
|
-
* Locate every real create*() call site (comment/string-free) that is NOT one
|
|
99
|
-
* of the supported, id-injectable export bindings, returning each as a 1-based
|
|
100
|
-
* { line, column }. The empty result means every call is in a supported shape.
|
|
101
|
-
* Both binding-collection paths anchor `callExprStart` at the start of the
|
|
102
|
-
* create* identifier — exactly where this pattern matches — so the set
|
|
103
|
-
* difference is exact.
|
|
104
|
-
*/
|
|
105
83
|
export function findUnsupportedCreateCallSites(
|
|
106
84
|
code: string,
|
|
107
85
|
fnNames: string[],
|
|
@@ -158,16 +136,6 @@ export function getCalledIdentifierFromCall(callExpr: any): string | null {
|
|
|
158
136
|
return null;
|
|
159
137
|
}
|
|
160
138
|
|
|
161
|
-
/**
|
|
162
|
-
* plugin-react's dev Fast Refresh wraps exports whose function body uses
|
|
163
|
-
* hook-like calls in a signature-registration call. A loader/handle that calls
|
|
164
|
-
* `ctx.use(...)` trips this heuristic, so `export const X = createLoader(...)`
|
|
165
|
-
* becomes `export const X = _s(createLoader(...), "<sig>", true)` — the create*
|
|
166
|
-
* call is the first argument of an unrelated wrapper call. Unwrap a single such
|
|
167
|
-
* layer so ID injection still targets the inner create* call. The `$$id`
|
|
168
|
-
* assignment is appended after the whole statement (against the export local),
|
|
169
|
-
* which is unaffected by the wrapper since `_s(x)` returns `x`.
|
|
170
|
-
*/
|
|
171
139
|
function unwrapSignatureWrappedCall(init: any, fnNameSet: Set<string>): any {
|
|
172
140
|
if (init?.type !== "CallExpression") return init;
|
|
173
141
|
const directId = getCalledIdentifierFromCall(init);
|
|
@@ -331,10 +299,6 @@ export function collectCreateExportBindings(
|
|
|
331
299
|
}
|
|
332
300
|
}
|
|
333
301
|
|
|
334
|
-
// When the JS parser misidentifies TypeScript generics (e.g.,
|
|
335
|
-
// createLocationState<{ text: string }>({...})) as binary expressions,
|
|
336
|
-
// the AST path finds 0 bindings even though calls exist. Fall back to
|
|
337
|
-
// regex-based detection which handles generics via <[^>]*> matching.
|
|
338
302
|
if (bindings.length === 0) {
|
|
339
303
|
return collectCreateExportBindingsFallback(code, fnNames);
|
|
340
304
|
}
|
|
@@ -349,8 +313,6 @@ export function buildUnsupportedShapeWarning(
|
|
|
349
313
|
): string {
|
|
350
314
|
const lines = [`[rango] Unsupported ${fnName} shape in "${filePath}".`];
|
|
351
315
|
|
|
352
|
-
// Point at the exact call(s) so the location is clickable in the terminal/IDE
|
|
353
|
-
// (file:line:column) instead of leaving the user to scan the whole file.
|
|
354
316
|
if (sites.length === 1) {
|
|
355
317
|
const s = sites[0];
|
|
356
318
|
lines.push(
|
|
@@ -69,10 +69,6 @@ export function transformLocationState(
|
|
|
69
69
|
return hasChanges;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/**
|
|
73
|
-
* Replace the entire file with lightweight stubs when ALL non-type exports are
|
|
74
|
-
* handler calls of the given type. Returns null for files with mixed exports.
|
|
75
|
-
*/
|
|
76
72
|
export function generateWholeFileStubs(
|
|
77
73
|
cfg: HandlerTransformConfig,
|
|
78
74
|
bindings: CreateExportBinding[],
|
|
@@ -91,10 +87,6 @@ export function generateWholeFileStubs(
|
|
|
91
87
|
return { code: stubs.join("\n") + "\n", map: null };
|
|
92
88
|
}
|
|
93
89
|
|
|
94
|
-
/**
|
|
95
|
-
* Replace handler call expressions with lightweight stub objects on the shared
|
|
96
|
-
* unified-pipeline MagicString so all transforms share one sourcemap.
|
|
97
|
-
*/
|
|
98
90
|
export function stubHandlerExprs(
|
|
99
91
|
cfg: HandlerTransformConfig,
|
|
100
92
|
bindings: CreateExportBinding[],
|
|
@@ -117,9 +109,6 @@ export function stubHandlerExprs(
|
|
|
117
109
|
return hasChanges;
|
|
118
110
|
}
|
|
119
111
|
|
|
120
|
-
/**
|
|
121
|
-
* Inject $$id into export const handler calls in RSC environments.
|
|
122
|
-
*/
|
|
123
112
|
export function transformHandlerIds(
|
|
124
113
|
cfg: HandlerTransformConfig,
|
|
125
114
|
bindings: CreateExportBinding[],
|
|
@@ -133,10 +122,6 @@ export function transformHandlerIds(
|
|
|
133
122
|
|
|
134
123
|
const handlerId = makeStubId(filePath, exportName, isBuild);
|
|
135
124
|
|
|
136
|
-
// Injection strategy matches the runtime overload signatures:
|
|
137
|
-
// 0 args -> inject undefined, "id"
|
|
138
|
-
// 1 arg (handler) -> inject , undefined, "id"
|
|
139
|
-
// 2+ args -> inject , "id"
|
|
140
125
|
let paramInjection: string;
|
|
141
126
|
if (binding.argCount === 0) {
|
|
142
127
|
paramInjection = `undefined, "${handlerId}"`;
|