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