@bleedingdev/modern-js-plugin-tanstack 3.5.0-ultramodern.36 → 3.5.0-ultramodern.37
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/cjs/cli/tanstackTypes/shared.js +12 -19
- package/dist/cjs/cli/tanstackTypes/source.js +24 -19
- package/dist/cjs/runtime/blockingSubscribe.js +0 -7
- package/dist/cjs/runtime/clientHydration.js +2 -14
- package/dist/cjs/runtime/loaderBridge.js +3 -10
- package/dist/cjs/runtime/pluginShared.js +0 -3
- package/dist/cjs/runtime/register.js +1 -47
- package/dist/cjs/runtime/rsc/ReplayableStream.js +0 -4
- package/dist/cjs/runtime/rsc/payloadFetch.js +3 -16
- package/dist/cjs/runtime/rsc/payloadRoutes.js +2 -14
- package/dist/cjs/runtime/rsc/shared.js +2 -5
- package/dist/cjs/runtime/shared/isAbsoluteUrl.js +47 -0
- package/dist/esm/cli/index.mjs +4 -4
- package/dist/esm/cli/tanstackTypes/shared.mjs +12 -19
- package/dist/esm/cli/tanstackTypes/source.mjs +23 -18
- package/dist/esm/runtime/blockingSubscribe.mjs +1 -1
- package/dist/esm/runtime/clientHydration.mjs +1 -1
- package/dist/esm/runtime/loaderBridge.mjs +1 -8
- package/dist/esm/runtime/pluginShared.mjs +1 -1
- package/dist/esm/runtime/register.mjs +0 -14
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +1 -1
- package/dist/esm/runtime/rsc/payloadFetch.mjs +2 -9
- package/dist/esm/runtime/rsc/payloadRoutes.mjs +1 -1
- package/dist/esm/runtime/rsc/shared.mjs +1 -1
- package/dist/esm/runtime/shared/isAbsoluteUrl.mjs +9 -0
- package/dist/esm-node/cli/index.mjs +4 -4
- package/dist/esm-node/cli/tanstackTypes/shared.mjs +12 -19
- package/dist/esm-node/cli/tanstackTypes/source.mjs +23 -18
- package/dist/esm-node/runtime/blockingSubscribe.mjs +1 -1
- package/dist/esm-node/runtime/clientHydration.mjs +1 -1
- package/dist/esm-node/runtime/loaderBridge.mjs +1 -8
- package/dist/esm-node/runtime/pluginShared.mjs +1 -1
- package/dist/esm-node/runtime/register.mjs +0 -14
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +1 -1
- package/dist/esm-node/runtime/rsc/payloadFetch.mjs +2 -9
- package/dist/esm-node/runtime/rsc/payloadRoutes.mjs +1 -1
- package/dist/esm-node/runtime/rsc/shared.mjs +1 -1
- package/dist/esm-node/runtime/shared/isAbsoluteUrl.mjs +10 -0
- package/dist/types/cli/tanstackTypes/shared.d.ts +1 -1
- package/dist/types/cli/tanstackTypes/source.d.ts +3 -1
- package/dist/types/runtime/blockingSubscribe.d.ts +0 -2
- package/dist/types/runtime/clientHydration.d.ts +0 -9
- package/dist/types/runtime/formData.d.ts +2 -1
- package/dist/types/runtime/loaderBridge.d.ts +2 -1
- package/dist/types/runtime/pluginShared.d.ts +2 -3
- package/dist/types/runtime/register.d.ts +1 -9
- package/dist/types/runtime/routeTree/types.d.ts +2 -1
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +3 -2
- package/dist/types/runtime/rsc/SlotContext.d.ts +2 -1
- package/dist/types/runtime/rsc/payloadFetch.d.ts +2 -4
- package/dist/types/runtime/rsc/payloadRoutes.d.ts +3 -6
- package/dist/types/runtime/rsc/shared.d.ts +0 -1
- package/dist/types/runtime/shared/isAbsoluteUrl.d.ts +1 -0
- package/dist/types/runtime/ssrTypes.d.ts +3 -2
- package/dist/types/runtime/types.d.ts +2 -3
- package/package.json +15 -16
- package/src/cli/tanstackTypes/canonicalRoutes.ts +1 -1
- package/src/cli/tanstackTypes/shared.ts +24 -30
- package/src/cli/tanstackTypes/source.ts +31 -21
- package/src/runtime/blockingSubscribe.ts +2 -2
- package/src/runtime/clientHydration.ts +5 -10
- package/src/runtime/formData.ts +1 -1
- package/src/runtime/loaderBridge.ts +3 -9
- package/src/runtime/pluginShared.ts +3 -3
- package/src/runtime/register.ts +5 -37
- package/src/runtime/routeTree/types.ts +1 -1
- package/src/runtime/rsc/ReplayableStream.ts +2 -2
- package/src/runtime/rsc/SlotContext.tsx +1 -1
- package/src/runtime/rsc/payloadFetch.ts +5 -11
- package/src/runtime/rsc/payloadRoutes.ts +6 -6
- package/src/runtime/rsc/shared.ts +1 -1
- package/src/runtime/shared/isAbsoluteUrl.ts +8 -0
- package/src/runtime/ssrTypes.ts +2 -2
- package/src/runtime/submitAction.ts +17 -10
- package/src/runtime/types.ts +1 -8
- package/tests/router/register.test.ts +1 -39
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
1
2
|
import { makeLegalIdentifier } from "@modern-js/runtime/cli";
|
|
2
|
-
import path from "path";
|
|
3
3
|
import { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt, toTanstackPath } from "./shared.mjs";
|
|
4
4
|
async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
5
5
|
const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
|
|
6
|
-
const outDir =
|
|
7
|
-
const rootModern = routes.find((r)=>
|
|
8
|
-
|
|
6
|
+
const outDir = node_path.join(appContext.srcDirectory, generatedDirName, entryName);
|
|
7
|
+
const rootModern = routes.find((r)=>{
|
|
8
|
+
const extras = r;
|
|
9
|
+
return r && 'nested' === extras.type && extras.isRoot;
|
|
10
|
+
});
|
|
11
|
+
const rootExtras = rootModern;
|
|
12
|
+
const topLevel = rootModern ? rootExtras?.children || [] : routes;
|
|
9
13
|
const imports = [];
|
|
10
14
|
const statements = [];
|
|
11
15
|
const loaderImportMap = new Map();
|
|
@@ -24,7 +28,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
24
28
|
pendingImportName = (async ()=>{
|
|
25
29
|
const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
|
|
26
30
|
if (!resolvedNoExt) return null;
|
|
27
|
-
const relImport = normalizeRelativeImport(
|
|
31
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
28
32
|
const componentName = `component_${componentIndex++}`;
|
|
29
33
|
imports.push(`import ${componentName} from ${quote(relImport)};`);
|
|
30
34
|
return componentName;
|
|
@@ -38,8 +42,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
38
42
|
let absNoExt;
|
|
39
43
|
if (aliasedNoExtPath.startsWith(prefix)) {
|
|
40
44
|
const rel = aliasedNoExtPath.slice(prefix.length);
|
|
41
|
-
absNoExt =
|
|
42
|
-
} else absNoExt =
|
|
45
|
+
absNoExt = node_path.join(appContext.srcDirectory, rel);
|
|
46
|
+
} else absNoExt = node_path.isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : node_path.join(appContext.srcDirectory, aliasedNoExtPath);
|
|
43
47
|
return resolveFileNoExt(absNoExt);
|
|
44
48
|
};
|
|
45
49
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -51,7 +55,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
51
55
|
};
|
|
52
56
|
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
53
57
|
if (!resolvedNoExt) return null;
|
|
54
|
-
const relImport = normalizeRelativeImport(
|
|
58
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
55
59
|
const importName = `loader_${loaderIndex++}`;
|
|
56
60
|
const actionName = hasAction ? importName.replace(/^loader_/, 'action_') : null;
|
|
57
61
|
if (inline) {
|
|
@@ -73,7 +77,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
73
77
|
if (existing) return existing;
|
|
74
78
|
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
75
79
|
if (!resolvedNoExt) return null;
|
|
76
|
-
const relImport = normalizeRelativeImport(
|
|
80
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
77
81
|
const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
|
|
78
82
|
imports.push(`import { ${exportName} as ${importName} } from ${quote(relImport)};`);
|
|
79
83
|
searchContractImportMap.set(key, importName);
|
|
@@ -94,23 +98,24 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
94
98
|
const buildRoute = async (opts)=>{
|
|
95
99
|
const { parentVar, route } = opts;
|
|
96
100
|
const varName = createRouteVarName(route);
|
|
101
|
+
const routeExtras = route;
|
|
97
102
|
const loaderInfo = pickModernLoaderModule(route);
|
|
98
|
-
const routeAction =
|
|
103
|
+
const routeAction = routeExtras.action;
|
|
99
104
|
const loaderImports = loaderInfo ? await getImportNamesForLoader(loaderInfo.loaderPath, loaderInfo.inline, Boolean(loaderInfo.inline && routeAction === loaderInfo.loaderPath)) : null;
|
|
100
105
|
const loaderName = loaderImports?.loaderName || null;
|
|
101
106
|
const actionName = loaderImports?.actionName || null;
|
|
102
107
|
const searchContractInfo = pickRouteSearchContractModules(route);
|
|
103
108
|
const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
|
|
104
109
|
const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
|
|
105
|
-
const rawPath =
|
|
110
|
+
const rawPath = routeExtras.path;
|
|
106
111
|
const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
|
|
107
112
|
const routeOpts = [
|
|
108
113
|
`getParentRoute: () => ${parentVar},`
|
|
109
114
|
];
|
|
110
|
-
const componentName = await getImportNameForComponent(
|
|
115
|
+
const componentName = await getImportNameForComponent(routeExtras._component);
|
|
111
116
|
if (componentName) routeOpts.push(`component: ${componentName},`);
|
|
112
117
|
if (isPathlessLayout(route)) {
|
|
113
|
-
const id =
|
|
118
|
+
const id = routeExtras.id;
|
|
114
119
|
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
115
120
|
} else {
|
|
116
121
|
const p = isIndexRoute(route) ? '/' : toTanstackPath(rawPath || '');
|
|
@@ -120,12 +125,12 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
120
125
|
if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
|
|
121
126
|
if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
|
|
122
127
|
const staticDataSnippet = createRouteStaticDataSnippet({
|
|
123
|
-
modernRouteId:
|
|
128
|
+
modernRouteId: routeExtras.id,
|
|
124
129
|
loaderName,
|
|
125
130
|
actionName
|
|
126
131
|
});
|
|
127
132
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
128
|
-
const children =
|
|
133
|
+
const children = routeExtras.children;
|
|
129
134
|
const hasChildren = Boolean(children && children.length > 0);
|
|
130
135
|
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
131
136
|
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
@@ -140,7 +145,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
140
145
|
return varName;
|
|
141
146
|
};
|
|
142
147
|
const rootLoaderInfo = rootModern ? pickModernLoaderModule(rootModern) : null;
|
|
143
|
-
const rootAction =
|
|
148
|
+
const rootAction = rootExtras?.action;
|
|
144
149
|
const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
|
|
145
150
|
const rootLoaderName = rootLoaderImports?.loaderName || null;
|
|
146
151
|
const rootActionName = rootLoaderImports?.actionName || null;
|
|
@@ -153,7 +158,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
153
158
|
route
|
|
154
159
|
}));
|
|
155
160
|
const rootOpts = [];
|
|
156
|
-
const rootComponentName = await getImportNameForComponent(
|
|
161
|
+
const rootComponentName = await getImportNameForComponent(rootExtras?._component);
|
|
157
162
|
if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
|
|
158
163
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
159
164
|
if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
|
|
@@ -177,7 +182,7 @@ ${imports.join('\n')}
|
|
|
177
182
|
export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
|
|
178
183
|
${rootOpts.join('\n ')}
|
|
179
184
|
${createRouteStaticDataSnippet({
|
|
180
|
-
modernRouteId:
|
|
185
|
+
modernRouteId: rootExtras?.id,
|
|
181
186
|
loaderName: rootLoaderName,
|
|
182
187
|
actionName: rootActionName
|
|
183
188
|
}) || ''}
|
|
@@ -16,4 +16,4 @@ function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
|
|
|
16
16
|
};
|
|
17
17
|
target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
|
|
18
18
|
}
|
|
19
|
-
export {
|
|
19
|
+
export { wrapRouterSubscribeWithBlockState };
|
|
@@ -67,4 +67,4 @@ function ModernRouterClient({ router }) {
|
|
|
67
67
|
router
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
export { ModernRouterClient,
|
|
70
|
+
export { ModernRouterClient, getTanstackSsrHydrationPromise, hasTanstackSsrHydrationRecord, hydrateTanstackRouter };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notFound, redirect } from "@tanstack/react-router";
|
|
2
|
+
import { isAbsoluteUrl } from "./shared/isAbsoluteUrl.mjs";
|
|
2
3
|
function isResponse(value) {
|
|
3
4
|
const record = value;
|
|
4
5
|
return null != record && 'object' == typeof record && 'number' == typeof record.status && 'object' == typeof record.headers;
|
|
@@ -16,14 +17,6 @@ function isRedirectResponse(res) {
|
|
|
16
17
|
function isTanstackRedirect(value) {
|
|
17
18
|
return isResponse(value) && 'object' == typeof value.options;
|
|
18
19
|
}
|
|
19
|
-
function isAbsoluteUrl(value) {
|
|
20
|
-
try {
|
|
21
|
-
new URL(value);
|
|
22
|
-
return true;
|
|
23
|
-
} catch {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
20
|
function throwTanstackRedirect(location) {
|
|
28
21
|
const target = location || '/';
|
|
29
22
|
if (isAbsoluteUrl(target)) throw redirect({
|
|
@@ -37,4 +37,4 @@ function joinBasename(baseUrl, basename) {
|
|
|
37
37
|
if (!trimmedBasename) return trimmedBase || '/';
|
|
38
38
|
return `${trimmedBase}/${trimmedBasename}`.replace(/\/{2,}/g, '/');
|
|
39
39
|
}
|
|
40
|
-
export { createTanstackRouteObjects,
|
|
40
|
+
export { createTanstackRouteObjects, getMergedRouterConfig, getTanstackRouteConfig, joinBasename };
|
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import { registerRouterProvider } from "@modern-js/runtime/context";
|
|
2
|
-
import { Form, RouteActionResponseError, useFetcher } from "./dataMutation.mjs";
|
|
3
|
-
import { Outlet } from "./outlet.mjs";
|
|
4
2
|
import { tanstackRouterPlugin } from "./plugin.mjs";
|
|
5
|
-
import { Link, NavLink } from "./prefetchLink.mjs";
|
|
6
3
|
const tanstackRouterProviderFactory = (userConfig)=>tanstackRouterPlugin(userConfig);
|
|
7
4
|
registerRouterProvider('tanstack', tanstackRouterProviderFactory);
|
|
8
|
-
const COMPAT_BINDINGS_SLOT = Symbol.for('@modern-js/plugin-tanstack:runtime-compat-bindings');
|
|
9
|
-
const tanstackRouterCompatBindings = {
|
|
10
|
-
Form: Form,
|
|
11
|
-
Link: Link,
|
|
12
|
-
NavLink: NavLink,
|
|
13
|
-
Outlet: Outlet,
|
|
14
|
-
RouteActionResponseError: RouteActionResponseError,
|
|
15
|
-
useFetcher: useFetcher
|
|
16
|
-
};
|
|
17
|
-
globalThis[COMPAT_BINDINGS_SLOT] ??= tanstackRouterCompatBindings;
|
|
18
|
-
export { tanstackRouterCompatBindings };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notFound, redirect } from "@tanstack/react-router";
|
|
2
|
+
import { isAbsoluteUrl } from "../shared/isAbsoluteUrl.mjs";
|
|
2
3
|
import { reviveTanstackRscFlightValues } from "./flightSerialization.mjs";
|
|
3
4
|
const payloadFetchCache = new Map();
|
|
4
5
|
let payloadDecoder;
|
|
@@ -19,14 +20,6 @@ function createPayloadFetchKey(request) {
|
|
|
19
20
|
].sort(([left], [right])=>left.localeCompare(right))
|
|
20
21
|
]);
|
|
21
22
|
}
|
|
22
|
-
function isAbsoluteUrl(value) {
|
|
23
|
-
try {
|
|
24
|
-
new URL(value);
|
|
25
|
-
return true;
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
23
|
async function fetchTanstackRscPayload(request) {
|
|
31
24
|
const headers = new Headers(request.headers);
|
|
32
25
|
headers.set('x-rsc-tree', 'true');
|
|
@@ -59,4 +52,4 @@ function __setTanstackRscPayloadDecoderForTests(decoder) {
|
|
|
59
52
|
payloadDecoder = decoder;
|
|
60
53
|
payloadFetchCache.clear();
|
|
61
54
|
}
|
|
62
|
-
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey,
|
|
55
|
+
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey, fetchTanstackRscPayload, isAbsoluteUrl, payloadFetchCache };
|
|
@@ -47,4 +47,4 @@ function toPayloadRoute(match) {
|
|
|
47
47
|
pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
export { getRouteId,
|
|
50
|
+
export { getRouteId, toPayloadRoute, toPlainLocation };
|
|
@@ -18,4 +18,4 @@ function renderSelectedTree(src, { getTree = src[RSC_PROXY_GET_TREE], missingTre
|
|
|
18
18
|
if (!getTree) throw new Error(missingTreeError);
|
|
19
19
|
return selectTreePath(getTree(), src[RSC_PROXY_PATH] || []);
|
|
20
20
|
}
|
|
21
|
-
export { EmptyFallback, TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue, renderSelectedTree
|
|
21
|
+
export { EmptyFallback, TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue, renderSelectedTree };
|
|
@@ -7,10 +7,10 @@ import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
|
7
7
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
8
8
|
import { dirname as __rspack_dirname } from "node:path";
|
|
9
9
|
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
10
|
-
import * as
|
|
10
|
+
import * as __rspack_external__modern_js_runtime_cli_d0edd589 from "@modern-js/runtime/cli";
|
|
11
11
|
__webpack_require__.add({
|
|
12
|
-
"@modern-js/runtime/cli?
|
|
13
|
-
module.exports =
|
|
12
|
+
"@modern-js/runtime/cli?32f1" (module) {
|
|
13
|
+
module.exports = __rspack_external__modern_js_runtime_cli_d0edd589;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
const DEFAULT_ROUTES_DIR = 'routes';
|
|
@@ -19,7 +19,7 @@ const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
|
|
|
19
19
|
let runtimeRouterCli;
|
|
20
20
|
function getRuntimeRouterCli() {
|
|
21
21
|
if (runtimeRouterCli) return runtimeRouterCli;
|
|
22
|
-
const cli = __webpack_require__("@modern-js/runtime/cli?
|
|
22
|
+
const cli = __webpack_require__("@modern-js/runtime/cli?32f1");
|
|
23
23
|
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir && cli.getEntrypointRoutesOwner && cli.updateNestedRoutesSpec) {
|
|
24
24
|
runtimeRouterCli = cli;
|
|
25
25
|
return runtimeRouterCli;
|
|
@@ -11,18 +11,6 @@ const JS_OR_TS_EXTS = [
|
|
|
11
11
|
'.cjs',
|
|
12
12
|
'.cts'
|
|
13
13
|
];
|
|
14
|
-
function toTanstackPath(pathname) {
|
|
15
|
-
return pathname.split('/').map((segment)=>{
|
|
16
|
-
if (!segment) return segment;
|
|
17
|
-
if ('*' === segment) return '$';
|
|
18
|
-
if (segment.startsWith(':')) {
|
|
19
|
-
const name = segment.slice(1);
|
|
20
|
-
if (name.endsWith('?')) return `{-$${name.slice(0, -1)}}`;
|
|
21
|
-
return `$${name}`;
|
|
22
|
-
}
|
|
23
|
-
return segment;
|
|
24
|
-
}).join('/');
|
|
25
|
-
}
|
|
26
14
|
async function resolveFileNoExt(inputNoExtPath) {
|
|
27
15
|
const file = findExists(JS_OR_TS_EXTS.map((ext)=>`${inputNoExtPath}${ext}`));
|
|
28
16
|
return file ? getPathWithoutExt(file) : null;
|
|
@@ -36,27 +24,31 @@ function normalizeRelativeImport(p) {
|
|
|
36
24
|
return `./${normalized}`;
|
|
37
25
|
}
|
|
38
26
|
function pickModernLoaderModule(route) {
|
|
39
|
-
const
|
|
27
|
+
const extras = route;
|
|
28
|
+
const loaderPath = extras.data || extras.loader;
|
|
40
29
|
if (!loaderPath || 'string' != typeof loaderPath) return null;
|
|
41
|
-
const inline = Boolean(
|
|
30
|
+
const inline = Boolean(extras.data);
|
|
42
31
|
return {
|
|
43
32
|
loaderPath,
|
|
44
33
|
inline
|
|
45
34
|
};
|
|
46
35
|
}
|
|
47
36
|
function pickRouteSearchContractModules(route) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
37
|
+
const extras = route;
|
|
38
|
+
const validateSearchPath = extras.validateSearch;
|
|
39
|
+
const loaderDepsPath = extras.loaderDeps;
|
|
50
40
|
return {
|
|
51
41
|
validateSearchPath: 'string' == typeof validateSearchPath ? validateSearchPath : null,
|
|
52
42
|
loaderDepsPath: 'string' == typeof loaderDepsPath ? loaderDepsPath : null
|
|
53
43
|
};
|
|
54
44
|
}
|
|
55
45
|
function isPathlessLayout(route) {
|
|
56
|
-
|
|
46
|
+
const extras = route;
|
|
47
|
+
return 'nested' === extras.type && 'boolean' != typeof extras.index && void 0 === extras.path;
|
|
57
48
|
}
|
|
58
49
|
function isIndexRoute(route) {
|
|
59
|
-
|
|
50
|
+
const extras = route;
|
|
51
|
+
return 'nested' === extras.type && Boolean(extras.index);
|
|
60
52
|
}
|
|
61
53
|
function createRouteStaticDataSnippet(opts) {
|
|
62
54
|
const staticDataLines = [];
|
|
@@ -66,4 +58,5 @@ function createRouteStaticDataSnippet(opts) {
|
|
|
66
58
|
if (!staticDataLines.length) return null;
|
|
67
59
|
return `staticData: createRouteStaticData({\n ${staticDataLines.join('\n ')}\n }),`;
|
|
68
60
|
}
|
|
69
|
-
export {
|
|
61
|
+
export { toTanstackPath } from "../../runtime/routeTree/paths.mjs";
|
|
62
|
+
export { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt };
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
2
3
|
import { makeLegalIdentifier } from "@modern-js/runtime/cli";
|
|
3
|
-
import path from "path";
|
|
4
4
|
import { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt, toTanstackPath } from "./shared.mjs";
|
|
5
5
|
async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
6
6
|
const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
|
|
7
|
-
const outDir =
|
|
8
|
-
const rootModern = routes.find((r)=>
|
|
9
|
-
|
|
7
|
+
const outDir = node_path.join(appContext.srcDirectory, generatedDirName, entryName);
|
|
8
|
+
const rootModern = routes.find((r)=>{
|
|
9
|
+
const extras = r;
|
|
10
|
+
return r && 'nested' === extras.type && extras.isRoot;
|
|
11
|
+
});
|
|
12
|
+
const rootExtras = rootModern;
|
|
13
|
+
const topLevel = rootModern ? rootExtras?.children || [] : routes;
|
|
10
14
|
const imports = [];
|
|
11
15
|
const statements = [];
|
|
12
16
|
const loaderImportMap = new Map();
|
|
@@ -25,7 +29,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
25
29
|
pendingImportName = (async ()=>{
|
|
26
30
|
const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
|
|
27
31
|
if (!resolvedNoExt) return null;
|
|
28
|
-
const relImport = normalizeRelativeImport(
|
|
32
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
29
33
|
const componentName = `component_${componentIndex++}`;
|
|
30
34
|
imports.push(`import ${componentName} from ${quote(relImport)};`);
|
|
31
35
|
return componentName;
|
|
@@ -39,8 +43,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
39
43
|
let absNoExt;
|
|
40
44
|
if (aliasedNoExtPath.startsWith(prefix)) {
|
|
41
45
|
const rel = aliasedNoExtPath.slice(prefix.length);
|
|
42
|
-
absNoExt =
|
|
43
|
-
} else absNoExt =
|
|
46
|
+
absNoExt = node_path.join(appContext.srcDirectory, rel);
|
|
47
|
+
} else absNoExt = node_path.isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : node_path.join(appContext.srcDirectory, aliasedNoExtPath);
|
|
44
48
|
return resolveFileNoExt(absNoExt);
|
|
45
49
|
};
|
|
46
50
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -52,7 +56,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
52
56
|
};
|
|
53
57
|
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
54
58
|
if (!resolvedNoExt) return null;
|
|
55
|
-
const relImport = normalizeRelativeImport(
|
|
59
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
56
60
|
const importName = `loader_${loaderIndex++}`;
|
|
57
61
|
const actionName = hasAction ? importName.replace(/^loader_/, 'action_') : null;
|
|
58
62
|
if (inline) {
|
|
@@ -74,7 +78,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
74
78
|
if (existing) return existing;
|
|
75
79
|
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
76
80
|
if (!resolvedNoExt) return null;
|
|
77
|
-
const relImport = normalizeRelativeImport(
|
|
81
|
+
const relImport = normalizeRelativeImport(node_path.relative(outDir, resolvedNoExt));
|
|
78
82
|
const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
|
|
79
83
|
imports.push(`import { ${exportName} as ${importName} } from ${quote(relImport)};`);
|
|
80
84
|
searchContractImportMap.set(key, importName);
|
|
@@ -95,23 +99,24 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
95
99
|
const buildRoute = async (opts)=>{
|
|
96
100
|
const { parentVar, route } = opts;
|
|
97
101
|
const varName = createRouteVarName(route);
|
|
102
|
+
const routeExtras = route;
|
|
98
103
|
const loaderInfo = pickModernLoaderModule(route);
|
|
99
|
-
const routeAction =
|
|
104
|
+
const routeAction = routeExtras.action;
|
|
100
105
|
const loaderImports = loaderInfo ? await getImportNamesForLoader(loaderInfo.loaderPath, loaderInfo.inline, Boolean(loaderInfo.inline && routeAction === loaderInfo.loaderPath)) : null;
|
|
101
106
|
const loaderName = loaderImports?.loaderName || null;
|
|
102
107
|
const actionName = loaderImports?.actionName || null;
|
|
103
108
|
const searchContractInfo = pickRouteSearchContractModules(route);
|
|
104
109
|
const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
|
|
105
110
|
const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
|
|
106
|
-
const rawPath =
|
|
111
|
+
const rawPath = routeExtras.path;
|
|
107
112
|
const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
|
|
108
113
|
const routeOpts = [
|
|
109
114
|
`getParentRoute: () => ${parentVar},`
|
|
110
115
|
];
|
|
111
|
-
const componentName = await getImportNameForComponent(
|
|
116
|
+
const componentName = await getImportNameForComponent(routeExtras._component);
|
|
112
117
|
if (componentName) routeOpts.push(`component: ${componentName},`);
|
|
113
118
|
if (isPathlessLayout(route)) {
|
|
114
|
-
const id =
|
|
119
|
+
const id = routeExtras.id;
|
|
115
120
|
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
116
121
|
} else {
|
|
117
122
|
const p = isIndexRoute(route) ? '/' : toTanstackPath(rawPath || '');
|
|
@@ -121,12 +126,12 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
121
126
|
if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
|
|
122
127
|
if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
|
|
123
128
|
const staticDataSnippet = createRouteStaticDataSnippet({
|
|
124
|
-
modernRouteId:
|
|
129
|
+
modernRouteId: routeExtras.id,
|
|
125
130
|
loaderName,
|
|
126
131
|
actionName
|
|
127
132
|
});
|
|
128
133
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
129
|
-
const children =
|
|
134
|
+
const children = routeExtras.children;
|
|
130
135
|
const hasChildren = Boolean(children && children.length > 0);
|
|
131
136
|
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
132
137
|
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
@@ -141,7 +146,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
141
146
|
return varName;
|
|
142
147
|
};
|
|
143
148
|
const rootLoaderInfo = rootModern ? pickModernLoaderModule(rootModern) : null;
|
|
144
|
-
const rootAction =
|
|
149
|
+
const rootAction = rootExtras?.action;
|
|
145
150
|
const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
|
|
146
151
|
const rootLoaderName = rootLoaderImports?.loaderName || null;
|
|
147
152
|
const rootActionName = rootLoaderImports?.actionName || null;
|
|
@@ -154,7 +159,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
154
159
|
route
|
|
155
160
|
}));
|
|
156
161
|
const rootOpts = [];
|
|
157
|
-
const rootComponentName = await getImportNameForComponent(
|
|
162
|
+
const rootComponentName = await getImportNameForComponent(rootExtras?._component);
|
|
158
163
|
if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
|
|
159
164
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
160
165
|
if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
|
|
@@ -178,7 +183,7 @@ ${imports.join('\n')}
|
|
|
178
183
|
export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
|
|
179
184
|
${rootOpts.join('\n ')}
|
|
180
185
|
${createRouteStaticDataSnippet({
|
|
181
|
-
modernRouteId:
|
|
186
|
+
modernRouteId: rootExtras?.id,
|
|
182
187
|
loaderName: rootLoaderName,
|
|
183
188
|
actionName: rootActionName
|
|
184
189
|
}) || ''}
|
|
@@ -17,4 +17,4 @@ function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
|
|
|
17
17
|
};
|
|
18
18
|
target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
|
|
19
19
|
}
|
|
20
|
-
export {
|
|
20
|
+
export { wrapRouterSubscribeWithBlockState };
|
|
@@ -68,4 +68,4 @@ function ModernRouterClient({ router }) {
|
|
|
68
68
|
router
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
export { ModernRouterClient,
|
|
71
|
+
export { ModernRouterClient, getTanstackSsrHydrationPromise, hasTanstackSsrHydrationRecord, hydrateTanstackRouter };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { notFound, redirect } from "@tanstack/react-router";
|
|
3
|
+
import { isAbsoluteUrl } from "./shared/isAbsoluteUrl.mjs";
|
|
3
4
|
function isResponse(value) {
|
|
4
5
|
const record = value;
|
|
5
6
|
return null != record && 'object' == typeof record && 'number' == typeof record.status && 'object' == typeof record.headers;
|
|
@@ -17,14 +18,6 @@ function isRedirectResponse(res) {
|
|
|
17
18
|
function isTanstackRedirect(value) {
|
|
18
19
|
return isResponse(value) && 'object' == typeof value.options;
|
|
19
20
|
}
|
|
20
|
-
function isAbsoluteUrl(value) {
|
|
21
|
-
try {
|
|
22
|
-
new URL(value);
|
|
23
|
-
return true;
|
|
24
|
-
} catch {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
21
|
function throwTanstackRedirect(location) {
|
|
29
22
|
const target = location || '/';
|
|
30
23
|
if (isAbsoluteUrl(target)) throw redirect({
|
|
@@ -38,4 +38,4 @@ function joinBasename(baseUrl, basename) {
|
|
|
38
38
|
if (!trimmedBasename) return trimmedBase || '/';
|
|
39
39
|
return `${trimmedBase}/${trimmedBasename}`.replace(/\/{2,}/g, '/');
|
|
40
40
|
}
|
|
41
|
-
export { createTanstackRouteObjects,
|
|
41
|
+
export { createTanstackRouteObjects, getMergedRouterConfig, getTanstackRouteConfig, joinBasename };
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { registerRouterProvider } from "@modern-js/runtime/context";
|
|
3
|
-
import { Form, RouteActionResponseError, useFetcher } from "./dataMutation.mjs";
|
|
4
|
-
import { Outlet } from "./outlet.mjs";
|
|
5
3
|
import { tanstackRouterPlugin } from "./plugin.mjs";
|
|
6
|
-
import { Link, NavLink } from "./prefetchLink.mjs";
|
|
7
4
|
const tanstackRouterProviderFactory = (userConfig)=>tanstackRouterPlugin(userConfig);
|
|
8
5
|
registerRouterProvider('tanstack', tanstackRouterProviderFactory);
|
|
9
|
-
const COMPAT_BINDINGS_SLOT = Symbol.for('@modern-js/plugin-tanstack:runtime-compat-bindings');
|
|
10
|
-
const tanstackRouterCompatBindings = {
|
|
11
|
-
Form: Form,
|
|
12
|
-
Link: Link,
|
|
13
|
-
NavLink: NavLink,
|
|
14
|
-
Outlet: Outlet,
|
|
15
|
-
RouteActionResponseError: RouteActionResponseError,
|
|
16
|
-
useFetcher: useFetcher
|
|
17
|
-
};
|
|
18
|
-
globalThis[COMPAT_BINDINGS_SLOT] ??= tanstackRouterCompatBindings;
|
|
19
|
-
export { tanstackRouterCompatBindings };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { notFound, redirect } from "@tanstack/react-router";
|
|
3
|
+
import { isAbsoluteUrl } from "../shared/isAbsoluteUrl.mjs";
|
|
3
4
|
import { reviveTanstackRscFlightValues } from "./flightSerialization.mjs";
|
|
4
5
|
const payloadFetchCache = new Map();
|
|
5
6
|
let payloadDecoder;
|
|
@@ -20,14 +21,6 @@ function createPayloadFetchKey(request) {
|
|
|
20
21
|
].sort(([left], [right])=>left.localeCompare(right))
|
|
21
22
|
]);
|
|
22
23
|
}
|
|
23
|
-
function isAbsoluteUrl(value) {
|
|
24
|
-
try {
|
|
25
|
-
new URL(value);
|
|
26
|
-
return true;
|
|
27
|
-
} catch {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
24
|
async function fetchTanstackRscPayload(request) {
|
|
32
25
|
const headers = new Headers(request.headers);
|
|
33
26
|
headers.set('x-rsc-tree', 'true');
|
|
@@ -60,4 +53,4 @@ function __setTanstackRscPayloadDecoderForTests(decoder) {
|
|
|
60
53
|
payloadDecoder = decoder;
|
|
61
54
|
payloadFetchCache.clear();
|
|
62
55
|
}
|
|
63
|
-
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey,
|
|
56
|
+
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey, fetchTanstackRscPayload, isAbsoluteUrl, payloadFetchCache };
|
|
@@ -48,4 +48,4 @@ function toPayloadRoute(match) {
|
|
|
48
48
|
pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
export { getRouteId,
|
|
51
|
+
export { getRouteId, toPayloadRoute, toPlainLocation };
|
|
@@ -19,4 +19,4 @@ function renderSelectedTree(src, { getTree = src[RSC_PROXY_GET_TREE], missingTre
|
|
|
19
19
|
if (!getTree) throw new Error(missingTreeError);
|
|
20
20
|
return selectTreePath(getTree(), src[RSC_PROXY_PATH] || []);
|
|
21
21
|
}
|
|
22
|
-
export { EmptyFallback, TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue, renderSelectedTree
|
|
22
|
+
export { EmptyFallback, TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue, renderSelectedTree };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
2
|
-
export
|
|
2
|
+
export { toTanstackPath } from '../../runtime/routeTree/paths';
|
|
3
3
|
export declare function resolveFileNoExt(inputNoExtPath: string): Promise<string | null>;
|
|
4
4
|
export declare function quote(str: string): string;
|
|
5
5
|
export declare function normalizeRelativeImport(p: string): string;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AppToolsContext } from '@modern-js/app-tools';
|
|
2
2
|
import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
3
|
+
type RouteForCli = NestedRouteForCli | PageRoute;
|
|
3
4
|
export declare function generateTanstackRouterTypesSourceForEntry(opts: {
|
|
4
5
|
appContext: AppToolsContext;
|
|
5
6
|
entryName: string;
|
|
6
7
|
generatedDirName?: string;
|
|
7
|
-
routes:
|
|
8
|
+
routes: RouteForCli[];
|
|
8
9
|
}): Promise<{
|
|
9
10
|
routerGenTs: string;
|
|
10
11
|
}>;
|
|
12
|
+
export {};
|
|
@@ -2,16 +2,7 @@ import { type AnyRouter } from '@tanstack/react-router';
|
|
|
2
2
|
export type WindowWithTanstackSsr = Window & {
|
|
3
3
|
$_TSR?: unknown;
|
|
4
4
|
};
|
|
5
|
-
export type RouterHydrationRecord = {
|
|
6
|
-
error?: unknown;
|
|
7
|
-
promise: Promise<unknown>;
|
|
8
|
-
status: 'pending' | 'fulfilled' | 'rejected';
|
|
9
|
-
};
|
|
10
|
-
export declare const routerHydrationRecords: WeakMap<AnyRouter, RouterHydrationRecord>;
|
|
11
|
-
export declare function getCachedRouteModule(routeId: string): unknown;
|
|
12
|
-
export declare function preloadHydratedRouteComponents(router: AnyRouter): Promise<void>;
|
|
13
5
|
export declare function hydrateTanstackRouter(router: AnyRouter): Promise<unknown>;
|
|
14
|
-
export declare function getTanstackSsrHydrationRecord(router: AnyRouter): RouterHydrationRecord;
|
|
15
6
|
export declare function getTanstackSsrHydrationPromise(router: AnyRouter): Promise<unknown>;
|
|
16
7
|
export declare function hasTanstackSsrHydrationRecord(router: AnyRouter): boolean;
|
|
17
8
|
export declare function ModernRouterClient({ router }: {
|