@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.9 → 3.2.0-ultramodern.90
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/index.js +12 -0
- package/dist/cjs/cli/routeSplitting.js +83 -0
- package/dist/cjs/cli/tanstackTypes.js +146 -58
- package/dist/cjs/runtime/index.js +38 -6
- package/dist/cjs/runtime/plugin.js +6 -5
- package/dist/cjs/runtime/plugin.node.js +27 -10
- package/dist/cjs/runtime/plugin.worker.js +49 -0
- package/dist/cjs/runtime/routeTree.js +55 -4
- package/dist/cjs/runtime/types.js +27 -1
- package/dist/esm/cli/index.mjs +4 -1
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +146 -58
- package/dist/esm/runtime/index.mjs +2 -1
- package/dist/esm/runtime/plugin.mjs +10 -9
- package/dist/esm/runtime/plugin.node.mjs +28 -11
- package/dist/esm/runtime/plugin.worker.mjs +1 -0
- package/dist/esm/runtime/routeTree.mjs +55 -4
- package/dist/esm/runtime/types.mjs +7 -0
- package/dist/esm-node/cli/index.mjs +4 -1
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +146 -58
- package/dist/esm-node/runtime/index.mjs +2 -1
- package/dist/esm-node/runtime/plugin.mjs +10 -9
- package/dist/esm-node/runtime/plugin.node.mjs +28 -11
- package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
- package/dist/esm-node/runtime/routeTree.mjs +55 -4
- package/dist/esm-node/runtime/types.mjs +7 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/dist/types/runtime/plugin.node.d.ts +1 -1
- package/dist/types/runtime/plugin.worker.d.ts +1 -0
- package/dist/types/runtime/types.d.ts +7 -0
- package/package.json +14 -14
- package/src/cli/index.ts +17 -0
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +216 -67
- package/src/runtime/index.tsx +13 -1
- package/src/runtime/plugin.node.tsx +54 -7
- package/src/runtime/plugin.tsx +8 -5
- package/src/runtime/plugin.worker.tsx +4 -0
- package/src/runtime/routeTree.ts +125 -8
- package/src/runtime/types.ts +13 -0
- package/tests/router/cli.test.ts +239 -0
- package/tests/router/fastDefaults.test.ts +25 -0
- package/tests/router/routeTree.test.ts +193 -1
- package/tests/router/tanstackTypes.test.ts +184 -0
package/dist/cjs/cli/index.js
CHANGED
|
@@ -48,9 +48,12 @@ var __webpack_exports__ = {};
|
|
|
48
48
|
(()=>{
|
|
49
49
|
__webpack_require__.r(__webpack_exports__);
|
|
50
50
|
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
createTanstackRsbuildRouteSplittingProfile: ()=>external_routeSplitting_js_namespaceObject.createTanstackRsbuildRouteSplittingProfile,
|
|
51
52
|
default: ()=>src_cli,
|
|
52
53
|
generateTanstackRouterTypesSourceForEntry: ()=>external_tanstackTypes_js_namespaceObject.generateTanstackRouterTypesSourceForEntry,
|
|
53
54
|
isTanstackRouterFrameworkEnabled: ()=>external_tanstackTypes_js_namespaceObject.isTanstackRouterFrameworkEnabled,
|
|
55
|
+
isTanstackStartRouteModuleSource: ()=>external_routeSplitting_js_namespaceObject.isTanstackStartRouteModuleSource,
|
|
56
|
+
resolveTanstackRouteCodeSplittingEnabled: ()=>external_routeSplitting_js_namespaceObject.resolveTanstackRouteCodeSplittingEnabled,
|
|
54
57
|
tanstackRouterPlugin: ()=>tanstackRouterPlugin,
|
|
55
58
|
writeTanstackRegisterFile: ()=>writeTanstackRegisterFile,
|
|
56
59
|
writeTanstackRouterTypesForEntries: ()=>writeTanstackRouterTypesForEntries
|
|
@@ -58,6 +61,7 @@ var __webpack_exports__ = {};
|
|
|
58
61
|
const external_node_path_namespaceObject = require("node:path");
|
|
59
62
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
60
63
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
64
|
+
const external_routeSplitting_js_namespaceObject = require("./routeSplitting.js");
|
|
61
65
|
const external_tanstackTypes_js_namespaceObject = require("./tanstackTypes.js");
|
|
62
66
|
const DEFAULT_ROUTES_DIR = 'routes';
|
|
63
67
|
const DEFAULT_GENERATED_DIR_NAME = 'modern-tanstack';
|
|
@@ -129,6 +133,7 @@ declare module '${opts.runtimeModule}' {
|
|
|
129
133
|
function tanstackRouterPlugin(options = {}) {
|
|
130
134
|
const routesDir = options.routesDir || DEFAULT_ROUTES_DIR;
|
|
131
135
|
const generatedDirName = options.generatedDirName || DEFAULT_GENERATED_DIR_NAME;
|
|
136
|
+
const routeSplittingProfile = (0, external_routeSplitting_js_namespaceObject.createTanstackRsbuildRouteSplittingProfile)(options);
|
|
132
137
|
return {
|
|
133
138
|
name: '@modern-js/plugin-tanstack',
|
|
134
139
|
required: [
|
|
@@ -164,6 +169,7 @@ declare module '${opts.runtimeModule}' {
|
|
|
164
169
|
entry: entry || getRuntimeRouterCli().isRouteEntry(entryPath, routesDir)
|
|
165
170
|
}));
|
|
166
171
|
api.config(()=>({
|
|
172
|
+
...routeSplittingProfile.defaultConfig,
|
|
167
173
|
source: {
|
|
168
174
|
include: [
|
|
169
175
|
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
@@ -246,16 +252,22 @@ declare module '${opts.runtimeModule}' {
|
|
|
246
252
|
}
|
|
247
253
|
const src_cli = tanstackRouterPlugin;
|
|
248
254
|
})();
|
|
255
|
+
exports.createTanstackRsbuildRouteSplittingProfile = __webpack_exports__.createTanstackRsbuildRouteSplittingProfile;
|
|
249
256
|
exports["default"] = __webpack_exports__["default"];
|
|
250
257
|
exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
|
|
251
258
|
exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
|
|
259
|
+
exports.isTanstackStartRouteModuleSource = __webpack_exports__.isTanstackStartRouteModuleSource;
|
|
260
|
+
exports.resolveTanstackRouteCodeSplittingEnabled = __webpack_exports__.resolveTanstackRouteCodeSplittingEnabled;
|
|
252
261
|
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
253
262
|
exports.writeTanstackRegisterFile = __webpack_exports__.writeTanstackRegisterFile;
|
|
254
263
|
exports.writeTanstackRouterTypesForEntries = __webpack_exports__.writeTanstackRouterTypesForEntries;
|
|
255
264
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
265
|
+
"createTanstackRsbuildRouteSplittingProfile",
|
|
256
266
|
"default",
|
|
257
267
|
"generateTanstackRouterTypesSourceForEntry",
|
|
258
268
|
"isTanstackRouterFrameworkEnabled",
|
|
269
|
+
"isTanstackStartRouteModuleSource",
|
|
270
|
+
"resolveTanstackRouteCodeSplittingEnabled",
|
|
259
271
|
"tanstackRouterPlugin",
|
|
260
272
|
"writeTanstackRegisterFile",
|
|
261
273
|
"writeTanstackRouterTypesForEntries"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createTanstackRsbuildRouteSplittingProfile: ()=>createTanstackRsbuildRouteSplittingProfile,
|
|
28
|
+
isTanstackStartRouteModuleSource: ()=>isTanstackStartRouteModuleSource,
|
|
29
|
+
resolveTanstackRouteCodeSplittingEnabled: ()=>resolveTanstackRouteCodeSplittingEnabled
|
|
30
|
+
});
|
|
31
|
+
const TANSTACK_START_ROUTE_FACTORY_CALLS = [
|
|
32
|
+
'createFileRoute',
|
|
33
|
+
'createRootRoute',
|
|
34
|
+
'createRootRouteWithContext'
|
|
35
|
+
];
|
|
36
|
+
const TANSTACK_START_ROUTE_FACTORY_REGEX = /\b(createFileRoute|createRootRoute|createRootRouteWithContext)\s*(?:<|\()/;
|
|
37
|
+
function isTanstackStartRouteModuleSource(source) {
|
|
38
|
+
return TANSTACK_START_ROUTE_FACTORY_REGEX.test(source);
|
|
39
|
+
}
|
|
40
|
+
function resolveTanstackRouteCodeSplittingEnabled(option) {
|
|
41
|
+
if ('boolean' == typeof option) return option;
|
|
42
|
+
return option?.enabled ?? true;
|
|
43
|
+
}
|
|
44
|
+
function createTanstackRsbuildRouteSplittingProfile(opts) {
|
|
45
|
+
return {
|
|
46
|
+
defaultConfig: {
|
|
47
|
+
output: {
|
|
48
|
+
splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting)
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
modernRouteChunks: {
|
|
52
|
+
enabled: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting),
|
|
53
|
+
owner: 'modern'
|
|
54
|
+
},
|
|
55
|
+
builderChunkSplit: {
|
|
56
|
+
owner: 'modern-rsbuild',
|
|
57
|
+
preserved: true
|
|
58
|
+
},
|
|
59
|
+
tanstackStartRspackSplitter: {
|
|
60
|
+
compatible: false,
|
|
61
|
+
reason: 'TanStack Start Rsbuild route splitting is tied to TanStack file-route factory modules; Modern generates TanStack route trees from Modern route metadata and owns route chunking through output.splitRouteChunks.',
|
|
62
|
+
clientDeleteNodes: [
|
|
63
|
+
'ssr',
|
|
64
|
+
'server',
|
|
65
|
+
'headers'
|
|
66
|
+
],
|
|
67
|
+
routeFactoryCalls: [
|
|
68
|
+
...TANSTACK_START_ROUTE_FACTORY_CALLS
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.createTanstackRsbuildRouteSplittingProfile = __webpack_exports__.createTanstackRsbuildRouteSplittingProfile;
|
|
74
|
+
exports.isTanstackStartRouteModuleSource = __webpack_exports__.isTanstackStartRouteModuleSource;
|
|
75
|
+
exports.resolveTanstackRouteCodeSplittingEnabled = __webpack_exports__.resolveTanstackRouteCodeSplittingEnabled;
|
|
76
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
77
|
+
"createTanstackRsbuildRouteSplittingProfile",
|
|
78
|
+
"isTanstackStartRouteModuleSource",
|
|
79
|
+
"resolveTanstackRouteCodeSplittingEnabled"
|
|
80
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
81
|
+
Object.defineProperty(exports, '__esModule', {
|
|
82
|
+
value: true
|
|
83
|
+
});
|
|
@@ -94,6 +94,14 @@ function pickModernLoaderModule(route) {
|
|
|
94
94
|
inline
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
+
function pickRouteSearchContractModules(route) {
|
|
98
|
+
const validateSearchPath = route.validateSearch;
|
|
99
|
+
const loaderDepsPath = route.loaderDeps;
|
|
100
|
+
return {
|
|
101
|
+
validateSearchPath: 'string' == typeof validateSearchPath ? validateSearchPath : null,
|
|
102
|
+
loaderDepsPath: 'string' == typeof loaderDepsPath ? loaderDepsPath : null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
97
105
|
function isPathlessLayout(route) {
|
|
98
106
|
return 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
|
|
99
107
|
}
|
|
@@ -127,8 +135,21 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
127
135
|
const imports = [];
|
|
128
136
|
const statements = [];
|
|
129
137
|
const loaderImportMap = new Map();
|
|
138
|
+
const searchContractImportMap = new Map();
|
|
139
|
+
const usedRouteVarNames = new Set();
|
|
130
140
|
let loaderIndex = 0;
|
|
141
|
+
let validateSearchIndex = 0;
|
|
142
|
+
let loaderDepsIndex = 0;
|
|
131
143
|
let routeIndex = 0;
|
|
144
|
+
const resolveRouteModuleNoExt = async (aliasedNoExtPath)=>{
|
|
145
|
+
const prefix = `${appContext.internalSrcAlias}/`;
|
|
146
|
+
let absNoExt;
|
|
147
|
+
if (aliasedNoExtPath.startsWith(prefix)) {
|
|
148
|
+
const rel = aliasedNoExtPath.slice(prefix.length);
|
|
149
|
+
absNoExt = external_path_default().join(appContext.srcDirectory, rel);
|
|
150
|
+
} else absNoExt = external_path_default().isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : external_path_default().join(appContext.srcDirectory, aliasedNoExtPath);
|
|
151
|
+
return resolveFileNoExt(absNoExt);
|
|
152
|
+
};
|
|
132
153
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
133
154
|
const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
|
|
134
155
|
const existing = loaderImportMap.get(key);
|
|
@@ -136,13 +157,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
136
157
|
loaderName: existing,
|
|
137
158
|
actionName: hasAction ? existing.replace(/^loader_/, 'action_') : null
|
|
138
159
|
};
|
|
139
|
-
const
|
|
140
|
-
let absNoExt;
|
|
141
|
-
if (aliasedNoExtPath.startsWith(prefix)) {
|
|
142
|
-
const rel = aliasedNoExtPath.slice(prefix.length);
|
|
143
|
-
absNoExt = external_path_default().join(appContext.srcDirectory, rel);
|
|
144
|
-
} else absNoExt = external_path_default().isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : external_path_default().join(appContext.srcDirectory, aliasedNoExtPath);
|
|
145
|
-
const resolvedNoExt = await resolveFileNoExt(absNoExt);
|
|
160
|
+
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
146
161
|
if (!resolvedNoExt) return null;
|
|
147
162
|
const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
|
|
148
163
|
const importName = `loader_${loaderIndex++}`;
|
|
@@ -160,10 +175,29 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
160
175
|
actionName
|
|
161
176
|
};
|
|
162
177
|
};
|
|
178
|
+
const getImportNameForSearchContract = async (aliasedNoExtPath, exportName)=>{
|
|
179
|
+
const key = `${exportName}:${aliasedNoExtPath}`;
|
|
180
|
+
const existing = searchContractImportMap.get(key);
|
|
181
|
+
if (existing) return existing;
|
|
182
|
+
const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
|
|
183
|
+
if (!resolvedNoExt) return null;
|
|
184
|
+
const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
|
|
185
|
+
const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
|
|
186
|
+
imports.push(`import { ${exportName} as ${importName} } from ${quote(relImport)};`);
|
|
187
|
+
searchContractImportMap.set(key, importName);
|
|
188
|
+
return importName;
|
|
189
|
+
};
|
|
190
|
+
const reserveRouteVarName = (preferred)=>{
|
|
191
|
+
let candidate = preferred;
|
|
192
|
+
let suffix = 1;
|
|
193
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
194
|
+
usedRouteVarNames.add(candidate);
|
|
195
|
+
return candidate;
|
|
196
|
+
};
|
|
163
197
|
const createRouteVarName = (route)=>{
|
|
164
198
|
const id = route.id;
|
|
165
199
|
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
166
|
-
return `route_${base}
|
|
200
|
+
return reserveRouteVarName(`route_${base}`);
|
|
167
201
|
};
|
|
168
202
|
const buildRoute = async (opts)=>{
|
|
169
203
|
const { parentVar, route } = opts;
|
|
@@ -173,6 +207,9 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
173
207
|
const loaderImports = loaderInfo ? await getImportNamesForLoader(loaderInfo.loaderPath, loaderInfo.inline, Boolean(loaderInfo.inline && routeAction === loaderInfo.loaderPath)) : null;
|
|
174
208
|
const loaderName = loaderImports?.loaderName || null;
|
|
175
209
|
const actionName = loaderImports?.actionName || null;
|
|
210
|
+
const searchContractInfo = pickRouteSearchContractModules(route);
|
|
211
|
+
const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
|
|
212
|
+
const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
|
|
176
213
|
const rawPath = route.path;
|
|
177
214
|
const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
|
|
178
215
|
const routeOpts = [
|
|
@@ -186,20 +223,24 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
186
223
|
routeOpts.push(`path: ${quote(p)},`);
|
|
187
224
|
}
|
|
188
225
|
if (loaderName) routeOpts.push(`loader: modernLoaderToTanstack({ hasSplat: ${hasSplat} }, ${loaderName}),`);
|
|
226
|
+
if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
|
|
227
|
+
if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
|
|
189
228
|
const staticDataSnippet = createRouteStaticDataSnippet({
|
|
190
229
|
modernRouteId: route.id,
|
|
191
230
|
loaderName,
|
|
192
231
|
actionName
|
|
193
232
|
});
|
|
194
233
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
195
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
196
234
|
const children = route.children;
|
|
235
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
236
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
237
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
197
238
|
if (children && children.length > 0) {
|
|
198
239
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
199
|
-
parentVar:
|
|
240
|
+
parentVar: routeCtorVarName,
|
|
200
241
|
route: child
|
|
201
242
|
})));
|
|
202
|
-
statements.push(
|
|
243
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
203
244
|
}
|
|
204
245
|
return varName;
|
|
205
246
|
};
|
|
@@ -208,17 +249,23 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
208
249
|
const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
|
|
209
250
|
const rootLoaderName = rootLoaderImports?.loaderName || null;
|
|
210
251
|
const rootActionName = rootLoaderImports?.actionName || null;
|
|
252
|
+
const rootSearchContractInfo = rootModern ? pickRouteSearchContractModules(rootModern) : null;
|
|
253
|
+
const rootValidateSearchName = rootSearchContractInfo?.validateSearchPath ? await getImportNameForSearchContract(rootSearchContractInfo.validateSearchPath, 'validateSearch') : null;
|
|
254
|
+
const rootLoaderDepsName = rootSearchContractInfo?.loaderDepsPath ? await getImportNameForSearchContract(rootSearchContractInfo.loaderDepsPath, 'loaderDeps') : null;
|
|
211
255
|
const topLevelVars = await Promise.all(topLevel.map((route)=>buildRoute({
|
|
212
256
|
parentVar: 'rootRoute',
|
|
213
257
|
route
|
|
214
258
|
})));
|
|
215
259
|
const rootOpts = [];
|
|
216
260
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
261
|
+
if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
|
|
262
|
+
if (rootLoaderDepsName) rootOpts.push(`loaderDeps: ${rootLoaderDepsName},`);
|
|
217
263
|
const routerGenTs = `/* eslint-disable */
|
|
218
264
|
// This file is auto-generated by Modern.js. Do not edit manually.
|
|
219
265
|
|
|
220
266
|
import {
|
|
221
267
|
createMemoryHistory,
|
|
268
|
+
modernTanstackRouterFastDefaults,
|
|
222
269
|
createRootRouteWithContext,
|
|
223
270
|
createRoute,
|
|
224
271
|
createRouter,
|
|
@@ -246,7 +293,7 @@ function isRedirectResponse(res: Response) {
|
|
|
246
293
|
}
|
|
247
294
|
|
|
248
295
|
function throwTanstackRedirect(location: string) {
|
|
249
|
-
const target = location
|
|
296
|
+
const target = location.length > 0 ? location : '/';
|
|
250
297
|
try {
|
|
251
298
|
void new URL(target);
|
|
252
299
|
throw redirect({ href: target });
|
|
@@ -272,21 +319,87 @@ function createRouteStaticData(opts: {
|
|
|
272
319
|
modernRouteAction?: unknown;
|
|
273
320
|
modernRouteLoader?: unknown;
|
|
274
321
|
}) {
|
|
275
|
-
const staticData:
|
|
322
|
+
const staticData: {
|
|
323
|
+
modernRouteId?: string;
|
|
324
|
+
modernRouteAction?: unknown;
|
|
325
|
+
modernRouteLoader?: unknown;
|
|
326
|
+
} = {};
|
|
276
327
|
|
|
277
|
-
if (opts.modernRouteId) {
|
|
328
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
278
329
|
staticData.modernRouteId = opts.modernRouteId;
|
|
279
330
|
}
|
|
280
331
|
|
|
281
|
-
if (opts.modernRouteLoader) {
|
|
332
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
282
333
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
283
334
|
}
|
|
284
335
|
|
|
285
|
-
if (opts.modernRouteAction) {
|
|
336
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
286
337
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
287
338
|
}
|
|
288
339
|
|
|
289
|
-
return
|
|
340
|
+
return staticData;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
344
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
345
|
+
if (abortSignal instanceof AbortSignal) {
|
|
346
|
+
return abortSignal;
|
|
347
|
+
}
|
|
348
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
349
|
+
return ctx.signal;
|
|
350
|
+
}
|
|
351
|
+
return new AbortController().signal;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function getLoaderHref(ctx: any): string {
|
|
355
|
+
if (typeof ctx?.location === 'string') {
|
|
356
|
+
return ctx.location;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const publicHref = ctx?.location?.publicHref;
|
|
360
|
+
if (typeof publicHref === 'string') {
|
|
361
|
+
return publicHref;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const href = ctx?.location?.href;
|
|
365
|
+
if (typeof href === 'string') {
|
|
366
|
+
return href;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const urlHref = ctx?.location?.url?.href;
|
|
370
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
374
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
378
|
+
if (isResponse(result)) {
|
|
379
|
+
if (isRedirectResponse(result)) {
|
|
380
|
+
const location = result.headers.get('Location') ?? '/';
|
|
381
|
+
throwTanstackRedirect(location);
|
|
382
|
+
}
|
|
383
|
+
if (result.status === 404) {
|
|
384
|
+
throw notFound();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function handleModernLoaderError(err: unknown): never {
|
|
392
|
+
if (isResponse(err)) {
|
|
393
|
+
if (isRedirectResponse(err)) {
|
|
394
|
+
const location = err.headers.get('Location') ?? '/';
|
|
395
|
+
throwTanstackRedirect(location);
|
|
396
|
+
}
|
|
397
|
+
if (err.status === 404) {
|
|
398
|
+
throw notFound();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
throw err;
|
|
290
403
|
}
|
|
291
404
|
|
|
292
405
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
@@ -295,57 +408,31 @@ function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
|
295
408
|
) {
|
|
296
409
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
297
410
|
|
|
298
|
-
return
|
|
411
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
299
412
|
try {
|
|
300
|
-
const signal
|
|
301
|
-
ctx?.abortController?.signal ||
|
|
302
|
-
ctx?.signal ||
|
|
303
|
-
new AbortController().signal;
|
|
413
|
+
const signal = getLoaderSignal(ctx);
|
|
304
414
|
const baseRequest: Request | undefined =
|
|
305
415
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
306
416
|
|
|
307
|
-
const href =
|
|
308
|
-
typeof ctx?.location === 'string'
|
|
309
|
-
? ctx.location
|
|
310
|
-
: ctx?.location?.publicHref ||
|
|
311
|
-
ctx?.location?.href ||
|
|
312
|
-
ctx?.location?.url?.href ||
|
|
313
|
-
'';
|
|
417
|
+
const href = getLoaderHref(ctx);
|
|
314
418
|
|
|
315
|
-
const request = baseRequest
|
|
419
|
+
const request = baseRequest !== undefined
|
|
316
420
|
? new Request(baseRequest, { signal })
|
|
317
421
|
: new Request(href, { signal });
|
|
318
422
|
|
|
319
|
-
const params = mapParamsForModernLoader(ctx
|
|
423
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
320
424
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
throwTanstackRedirect(location);
|
|
331
|
-
}
|
|
332
|
-
if (result.status === 404) {
|
|
333
|
-
throw notFound();
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return result as LoaderResult;
|
|
425
|
+
return Promise.resolve(
|
|
426
|
+
(modernLoader as any)({
|
|
427
|
+
request,
|
|
428
|
+
params,
|
|
429
|
+
context: ctx?.context?.requestContext,
|
|
430
|
+
}),
|
|
431
|
+
)
|
|
432
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
433
|
+
.catch(handleModernLoaderError);
|
|
338
434
|
} catch (err) {
|
|
339
|
-
|
|
340
|
-
if (isRedirectResponse(err)) {
|
|
341
|
-
const location = err.headers.get('Location') || '/';
|
|
342
|
-
throwTanstackRedirect(location);
|
|
343
|
-
}
|
|
344
|
-
if (err.status === 404) {
|
|
345
|
-
throw notFound();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
throw err;
|
|
435
|
+
handleModernLoaderError(err);
|
|
349
436
|
}
|
|
350
437
|
};
|
|
351
438
|
}
|
|
@@ -366,6 +453,7 @@ ${statements.join('\n\n')}
|
|
|
366
453
|
export const routeTree = rootRoute.addChildren([${topLevelVars.join(', ')}]);
|
|
367
454
|
|
|
368
455
|
export const router = createRouter({
|
|
456
|
+
...modernTanstackRouterFastDefaults,
|
|
369
457
|
routeTree,
|
|
370
458
|
history: createMemoryHistory({
|
|
371
459
|
initialEntries: ['/'],
|
|
@@ -12,6 +12,9 @@ var __webpack_modules__ = {
|
|
|
12
12
|
"./rsc/client" (module) {
|
|
13
13
|
module.exports = require("./rsc/client.js");
|
|
14
14
|
},
|
|
15
|
+
"./types" (module) {
|
|
16
|
+
module.exports = require("./types.js");
|
|
17
|
+
},
|
|
15
18
|
"@tanstack/react-router" (module) {
|
|
16
19
|
module.exports = require("@tanstack/react-router");
|
|
17
20
|
}
|
|
@@ -64,50 +67,79 @@ var __webpack_exports__ = {};
|
|
|
64
67
|
Form: ()=>_dataMutation__rspack_import_1.Form,
|
|
65
68
|
Link: ()=>_prefetchLink__rspack_import_3.Link,
|
|
66
69
|
NavLink: ()=>_prefetchLink__rspack_import_3.NavLink,
|
|
70
|
+
Outlet: ()=>_tanstack_react_router__rspack_import_0.Outlet,
|
|
67
71
|
RouteActionResponseError: ()=>_dataMutation__rspack_import_1.RouteActionResponseError,
|
|
68
72
|
default: ()=>_plugin__rspack_import_2.tanstackRouterPlugin,
|
|
73
|
+
getModernTanstackRouterFastDefaults: ()=>_types__rspack_import_5.getModernTanstackRouterFastDefaults,
|
|
74
|
+
modernTanstackRouterFastDefaults: ()=>_types__rspack_import_5.modernTanstackRouterFastDefaults,
|
|
69
75
|
tanstackRouterPlugin: ()=>_plugin__rspack_import_2.tanstackRouterPlugin,
|
|
70
76
|
useFetcher: ()=>_dataMutation__rspack_import_1.useFetcher,
|
|
71
|
-
|
|
77
|
+
useLocation: ()=>_tanstack_react_router__rspack_import_0.useLocation,
|
|
78
|
+
useMatch: ()=>_tanstack_react_router__rspack_import_0.useMatch,
|
|
79
|
+
useMatches: ()=>_tanstack_react_router__rspack_import_0.useMatches,
|
|
80
|
+
useNavigate: ()=>_tanstack_react_router__rspack_import_0.useNavigate,
|
|
81
|
+
useRouter: ()=>_tanstack_react_router__rspack_import_0.useRouter
|
|
72
82
|
});
|
|
73
83
|
var _tanstack_react_router__rspack_import_0 = __webpack_require__("@tanstack/react-router");
|
|
74
84
|
var __rspack_reexport = {};
|
|
75
85
|
for(const __rspack_import_key in _tanstack_react_router__rspack_import_0)if ([
|
|
86
|
+
"useNavigate",
|
|
87
|
+
"useRouter",
|
|
88
|
+
"CompositeComponent",
|
|
89
|
+
"useFetcher",
|
|
90
|
+
"useMatches",
|
|
91
|
+
"Form",
|
|
92
|
+
"Link",
|
|
76
93
|
"default",
|
|
77
94
|
"NavLink",
|
|
95
|
+
"getModernTanstackRouterFastDefaults",
|
|
78
96
|
"useMatch",
|
|
79
97
|
"tanstackRouterPlugin",
|
|
80
|
-
"
|
|
81
|
-
"
|
|
98
|
+
"useLocation",
|
|
99
|
+
"modernTanstackRouterFastDefaults",
|
|
82
100
|
"RouteActionResponseError",
|
|
83
|
-
"
|
|
84
|
-
"Link"
|
|
101
|
+
"Outlet"
|
|
85
102
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_tanstack_react_router__rspack_import_0[__rspack_import_key];
|
|
86
103
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
87
104
|
var _dataMutation__rspack_import_1 = __webpack_require__("./dataMutation");
|
|
88
105
|
var _plugin__rspack_import_2 = __webpack_require__("./plugin");
|
|
89
106
|
var _prefetchLink__rspack_import_3 = __webpack_require__("./prefetchLink");
|
|
90
107
|
var _rsc_client__rspack_import_4 = __webpack_require__("./rsc/client");
|
|
108
|
+
var _types__rspack_import_5 = __webpack_require__("./types");
|
|
91
109
|
})();
|
|
92
110
|
exports.CompositeComponent = __webpack_exports__.CompositeComponent;
|
|
93
111
|
exports.Form = __webpack_exports__.Form;
|
|
94
112
|
exports.Link = __webpack_exports__.Link;
|
|
95
113
|
exports.NavLink = __webpack_exports__.NavLink;
|
|
114
|
+
exports.Outlet = __webpack_exports__.Outlet;
|
|
96
115
|
exports.RouteActionResponseError = __webpack_exports__.RouteActionResponseError;
|
|
97
116
|
exports["default"] = __webpack_exports__["default"];
|
|
117
|
+
exports.getModernTanstackRouterFastDefaults = __webpack_exports__.getModernTanstackRouterFastDefaults;
|
|
118
|
+
exports.modernTanstackRouterFastDefaults = __webpack_exports__.modernTanstackRouterFastDefaults;
|
|
98
119
|
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
99
120
|
exports.useFetcher = __webpack_exports__.useFetcher;
|
|
121
|
+
exports.useLocation = __webpack_exports__.useLocation;
|
|
100
122
|
exports.useMatch = __webpack_exports__.useMatch;
|
|
123
|
+
exports.useMatches = __webpack_exports__.useMatches;
|
|
124
|
+
exports.useNavigate = __webpack_exports__.useNavigate;
|
|
125
|
+
exports.useRouter = __webpack_exports__.useRouter;
|
|
101
126
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
102
127
|
"CompositeComponent",
|
|
103
128
|
"Form",
|
|
104
129
|
"Link",
|
|
105
130
|
"NavLink",
|
|
131
|
+
"Outlet",
|
|
106
132
|
"RouteActionResponseError",
|
|
107
133
|
"default",
|
|
134
|
+
"getModernTanstackRouterFastDefaults",
|
|
135
|
+
"modernTanstackRouterFastDefaults",
|
|
108
136
|
"tanstackRouterPlugin",
|
|
109
137
|
"useFetcher",
|
|
110
|
-
"
|
|
138
|
+
"useLocation",
|
|
139
|
+
"useMatch",
|
|
140
|
+
"useMatches",
|
|
141
|
+
"useNavigate",
|
|
142
|
+
"useRouter"
|
|
111
143
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
112
144
|
Object.defineProperty(exports, '__esModule', {
|
|
113
145
|
value: true
|
|
@@ -37,8 +37,10 @@ const external_react_namespaceObject = require("react");
|
|
|
37
37
|
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
38
38
|
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
39
39
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
40
|
+
const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
|
|
40
41
|
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
41
42
|
const client_js_namespaceObject = require("./rsc/client.js");
|
|
43
|
+
const external_types_js_namespaceObject = require("./types.js");
|
|
42
44
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
43
45
|
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-subscribe');
|
|
44
46
|
const BLOCKING_STATE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-state');
|
|
@@ -102,6 +104,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
context.router = {
|
|
107
|
+
Link: external_prefetchLink_js_namespaceObject.Link,
|
|
105
108
|
useMatches: react_router_namespaceObject.useMatches,
|
|
106
109
|
useLocation: react_router_namespaceObject.useLocation,
|
|
107
110
|
useNavigate: react_router_namespaceObject.useNavigate,
|
|
@@ -171,6 +174,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
171
174
|
const rewrite = (0, external_basepathRewrite_js_namespaceObject.createModernBasepathRewrite)(_basename);
|
|
172
175
|
const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (0, client_js_namespaceObject.getTanstackRscSerializationAdapters)() : void 0;
|
|
173
176
|
cachedRouter = (0, react_router_namespaceObject.createRouter)({
|
|
177
|
+
...(0, external_types_js_namespaceObject.getModernTanstackRouterFastDefaults)(mergedConfig),
|
|
174
178
|
routeTree,
|
|
175
179
|
basepath: '/',
|
|
176
180
|
rewrite,
|
|
@@ -214,11 +218,8 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
214
218
|
router,
|
|
215
219
|
runtimeContext: runtimeState
|
|
216
220
|
});
|
|
217
|
-
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
218
|
-
|
|
219
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
220
|
-
router: router
|
|
221
|
-
})
|
|
221
|
+
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
222
|
+
router: router
|
|
222
223
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
223
224
|
router: router
|
|
224
225
|
});
|