@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.0
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/LICENSE +21 -0
- package/dist/cjs/cli/index.js +268 -0
- package/dist/cjs/cli/tanstackTypes.js +388 -0
- package/dist/cjs/cli.js +65 -0
- package/dist/cjs/runtime/DefaultNotFound.js +47 -0
- package/dist/cjs/runtime/basepathRewrite.js +62 -0
- package/dist/cjs/runtime/dataMutation.js +345 -0
- package/dist/cjs/runtime/hooks.js +57 -0
- package/dist/cjs/runtime/index.js +114 -0
- package/dist/cjs/runtime/lifecycle.js +125 -0
- package/dist/cjs/runtime/plugin.js +250 -0
- package/dist/cjs/runtime/plugin.node.js +304 -0
- package/dist/cjs/runtime/prefetchLink.js +55 -0
- package/dist/cjs/runtime/routeTree.js +492 -0
- package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
- package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
- package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
- package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
- package/dist/cjs/runtime/rsc/client.js +93 -0
- package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
- package/dist/cjs/runtime/rsc/index.js +42 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
- package/dist/cjs/runtime/rsc/server.js +246 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
- package/dist/cjs/runtime/rsc/symbols.js +72 -0
- package/dist/cjs/runtime/types.js +18 -0
- package/dist/cjs/runtime/utils.js +142 -0
- package/dist/cjs/runtime.js +58 -0
- package/dist/esm/cli/index.mjs +201 -0
- package/dist/esm/cli/tanstackTypes.mjs +341 -0
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
- package/dist/esm/runtime/basepathRewrite.mjs +28 -0
- package/dist/esm/runtime/dataMutation.mjs +305 -0
- package/dist/esm/runtime/hooks.mjs +8 -0
- package/dist/esm/runtime/index.mjs +6 -0
- package/dist/esm/runtime/lifecycle.mjs +82 -0
- package/dist/esm/runtime/plugin.mjs +214 -0
- package/dist/esm/runtime/plugin.node.mjs +268 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +452 -0
- package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
- package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
- package/dist/esm/runtime/rsc/client.mjs +53 -0
- package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
- package/dist/esm/runtime/rsc/index.mjs +1 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
- package/dist/esm/runtime/rsc/server.mjs +200 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
- package/dist/esm/runtime/rsc/symbols.mjs +17 -0
- package/dist/esm/runtime/types.mjs +0 -0
- package/dist/esm/runtime/utils.mjs +89 -0
- package/dist/esm/runtime.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +205 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
- package/dist/esm-node/cli.mjs +3 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
- package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
- package/dist/esm-node/runtime/dataMutation.mjs +306 -0
- package/dist/esm-node/runtime/hooks.mjs +9 -0
- package/dist/esm-node/runtime/index.mjs +7 -0
- package/dist/esm-node/runtime/lifecycle.mjs +83 -0
- package/dist/esm-node/runtime/plugin.mjs +215 -0
- package/dist/esm-node/runtime/plugin.node.mjs +269 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +453 -0
- package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
- package/dist/esm-node/runtime/rsc/client.mjs +54 -0
- package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
- package/dist/esm-node/runtime/rsc/index.mjs +2 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
- package/dist/esm-node/runtime/rsc/server.mjs +201 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
- package/dist/esm-node/runtime/types.mjs +1 -0
- package/dist/esm-node/runtime/utils.mjs +90 -0
- package/dist/esm-node/runtime.mjs +2 -0
- package/dist/types/cli/index.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +11 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types/runtime/dataMutation.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/lifecycle.d.ts +22 -0
- package/dist/types/runtime/plugin.d.ts +17 -0
- package/dist/types/runtime/plugin.node.d.ts +17 -0
- package/dist/types/runtime/prefetchLink.d.ts +11 -0
- package/dist/types/runtime/routeTree.d.ts +11 -0
- package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types/runtime/rsc/client.d.ts +11 -0
- package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/runtime/rsc/index.d.ts +2 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types/runtime/rsc/server.d.ts +14 -0
- package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types/runtime/types.d.ts +68 -0
- package/dist/types/runtime/utils.d.ts +36 -0
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types-direct/cli/index.d.ts +20 -0
- package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
- package/dist/types-direct/cli.d.ts +2 -0
- package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
- package/dist/types-direct/runtime/hooks.d.ts +18 -0
- package/dist/types-direct/runtime/index.d.ts +9 -0
- package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
- package/dist/types-direct/runtime/plugin.d.ts +17 -0
- package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
- package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
- package/dist/types-direct/runtime/routeTree.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
- package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types-direct/runtime/types.d.ts +68 -0
- package/dist/types-direct/runtime/utils.d.ts +36 -0
- package/dist/types-direct/runtime.d.ts +1 -0
- package/package.json +126 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +43 -0
- package/src/cli/index.ts +388 -0
- package/src/cli/tanstackTypes.ts +503 -0
- package/src/cli.ts +2 -0
- package/src/runtime/DefaultNotFound.tsx +15 -0
- package/src/runtime/basepathRewrite.ts +59 -0
- package/src/runtime/dataMutation.tsx +517 -0
- package/src/runtime/hooks.ts +34 -0
- package/src/runtime/index.tsx +30 -0
- package/src/runtime/lifecycle.ts +150 -0
- package/src/runtime/plugin.node.tsx +534 -0
- package/src/runtime/plugin.tsx +395 -0
- package/src/runtime/prefetchLink.tsx +87 -0
- package/src/runtime/routeTree.ts +942 -0
- package/src/runtime/rsc/ClientSlot.tsx +25 -0
- package/src/runtime/rsc/CompositeComponent.tsx +65 -0
- package/src/runtime/rsc/ReplayableStream.ts +155 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
- package/src/runtime/rsc/SlotContext.tsx +31 -0
- package/src/runtime/rsc/client.tsx +90 -0
- package/src/runtime/rsc/createRscProxy.tsx +189 -0
- package/src/runtime/rsc/index.ts +10 -0
- package/src/runtime/rsc/payloadRouter.ts +318 -0
- package/src/runtime/rsc/server.tsx +303 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
- package/src/runtime/rsc/symbols.ts +106 -0
- package/src/runtime/ssr-shim.d.ts +12 -0
- package/src/runtime/types.ts +83 -0
- package/src/runtime/utils.tsx +161 -0
- package/src/runtime.ts +1 -0
- package/tests/router/cli.test.ts +386 -0
- package/tests/router/dataMutation.test.tsx +396 -0
- package/tests/router/prefetchLink.test.tsx +43 -0
- package/tests/router/routeTree.test.ts +502 -0
- package/tests/router/rsc.test.tsx +256 -0
- package/tests/router/tanstackTypes.test.ts +62 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsgo.json +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@modern-js/runtime/cli" (module) {
|
|
4
|
+
module.exports = require("@modern-js/runtime/cli");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
default: ()=>src_cli,
|
|
52
|
+
generateTanstackRouterTypesSourceForEntry: ()=>external_tanstackTypes_js_namespaceObject.generateTanstackRouterTypesSourceForEntry,
|
|
53
|
+
isTanstackRouterFrameworkEnabled: ()=>external_tanstackTypes_js_namespaceObject.isTanstackRouterFrameworkEnabled,
|
|
54
|
+
tanstackRouterPlugin: ()=>tanstackRouterPlugin,
|
|
55
|
+
writeTanstackRegisterFile: ()=>writeTanstackRegisterFile,
|
|
56
|
+
writeTanstackRouterTypesForEntries: ()=>writeTanstackRouterTypesForEntries
|
|
57
|
+
});
|
|
58
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
59
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
60
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
61
|
+
const external_tanstackTypes_js_namespaceObject = require("./tanstackTypes.js");
|
|
62
|
+
const DEFAULT_ROUTES_DIR = 'routes';
|
|
63
|
+
const DEFAULT_GENERATED_DIR_NAME = 'modern-tanstack';
|
|
64
|
+
const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
|
|
65
|
+
let runtimeRouterCli;
|
|
66
|
+
function getRuntimeRouterCli() {
|
|
67
|
+
if (runtimeRouterCli) return runtimeRouterCli;
|
|
68
|
+
const cli = __webpack_require__("@modern-js/runtime/cli");
|
|
69
|
+
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir) {
|
|
70
|
+
runtimeRouterCli = cli;
|
|
71
|
+
return runtimeRouterCli;
|
|
72
|
+
}
|
|
73
|
+
throw new Error('@modern-js/plugin-tanstack requires @modern-js/runtime/cli router helper exports.');
|
|
74
|
+
}
|
|
75
|
+
async function writeFileIfChanged(filePath, content) {
|
|
76
|
+
try {
|
|
77
|
+
const previous = await utils_namespaceObject.fs.pathExists(filePath) ? await utils_namespaceObject.fs.readFile(filePath, 'utf-8') : null;
|
|
78
|
+
if (previous === content) return;
|
|
79
|
+
} catch {}
|
|
80
|
+
await utils_namespaceObject.fs.outputFile(filePath, content, 'utf-8');
|
|
81
|
+
}
|
|
82
|
+
function createRegisterDtsContent(opts) {
|
|
83
|
+
const importStatements = opts.entries.map((entryName, index)=>`import type { router as router${index} } from './${entryName}/router.gen';`).join('\n');
|
|
84
|
+
const routerUnionType = opts.entries.map((_, index)=>`typeof router${index}`).join(' | ');
|
|
85
|
+
return `// This file is auto-generated by Modern.js. Do not edit manually.
|
|
86
|
+
|
|
87
|
+
${importStatements}
|
|
88
|
+
|
|
89
|
+
declare module '${opts.runtimeModule}' {
|
|
90
|
+
interface Register {
|
|
91
|
+
router: ${routerUnionType};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
async function writeTanstackRegisterFile(opts) {
|
|
97
|
+
const { entries, generatedDirName = DEFAULT_GENERATED_DIR_NAME, runtimeModule = '@modern-js/plugin-tanstack/runtime', srcDirectory } = opts;
|
|
98
|
+
if (0 === entries.length) return;
|
|
99
|
+
const registerDtsPath = external_node_path_default().join(srcDirectory, generatedDirName, 'register.gen.d.ts');
|
|
100
|
+
await writeFileIfChanged(registerDtsPath, createRegisterDtsContent({
|
|
101
|
+
entries,
|
|
102
|
+
runtimeModule
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
async function writeTanstackRouterTypesForEntries(opts) {
|
|
106
|
+
const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry } = opts;
|
|
107
|
+
const entryNames = Object.keys(routesByEntry);
|
|
108
|
+
await Promise.all(entryNames.map(async (entryName)=>{
|
|
109
|
+
const { routerGenTs } = await (0, external_tanstackTypes_js_namespaceObject.generateTanstackRouterTypesSourceForEntry)({
|
|
110
|
+
appContext,
|
|
111
|
+
entryName,
|
|
112
|
+
generatedDirName,
|
|
113
|
+
routes: routesByEntry[entryName]
|
|
114
|
+
});
|
|
115
|
+
await writeFileIfChanged(external_node_path_default().join(appContext.srcDirectory, generatedDirName, entryName, 'router.gen.ts'), routerGenTs);
|
|
116
|
+
}));
|
|
117
|
+
const mainEntryName = appContext.entrypoints?.find((entrypoint)=>entrypoint.isMainEntry)?.entryName;
|
|
118
|
+
const registerEntries = entryNames.sort((a, b)=>{
|
|
119
|
+
if (mainEntryName && a === mainEntryName) return -1;
|
|
120
|
+
if (mainEntryName && b === mainEntryName) return 1;
|
|
121
|
+
return a.localeCompare(b);
|
|
122
|
+
});
|
|
123
|
+
await writeTanstackRegisterFile({
|
|
124
|
+
entries: registerEntries,
|
|
125
|
+
generatedDirName,
|
|
126
|
+
srcDirectory: appContext.srcDirectory
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function tanstackRouterPlugin(options = {}) {
|
|
130
|
+
const routesDir = options.routesDir || DEFAULT_ROUTES_DIR;
|
|
131
|
+
const generatedDirName = options.generatedDirName || DEFAULT_GENERATED_DIR_NAME;
|
|
132
|
+
return {
|
|
133
|
+
name: '@modern-js/plugin-tanstack',
|
|
134
|
+
required: [
|
|
135
|
+
'@modern-js/runtime'
|
|
136
|
+
],
|
|
137
|
+
setup: (api)=>{
|
|
138
|
+
const nestedRoutesForServer = {};
|
|
139
|
+
const isTanstackEntrypoint = (entrypoint)=>{
|
|
140
|
+
const { getEntrypointRoutesDir } = getRuntimeRouterCli();
|
|
141
|
+
return getEntrypointRoutesDir(entrypoint) === routesDir;
|
|
142
|
+
};
|
|
143
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
144
|
+
if (!isTanstackEntrypoint(entrypoint)) return {
|
|
145
|
+
entrypoint,
|
|
146
|
+
plugins
|
|
147
|
+
};
|
|
148
|
+
const { metaName, serverRoutes } = api.getAppContext();
|
|
149
|
+
const serverBase = serverRoutes.filter((route)=>route.entryName === entrypoint.entryName).map((route)=>route.urlPath).sort((a, b)=>a.length - b.length > 0 ? -1 : 1);
|
|
150
|
+
plugins.push({
|
|
151
|
+
name: 'tanstackRouter',
|
|
152
|
+
path: `@${metaName}/plugin-tanstack/runtime`,
|
|
153
|
+
config: {
|
|
154
|
+
serverBase
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
entrypoint,
|
|
159
|
+
plugins
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
api.checkEntryPoint(({ path: entryPath, entry })=>{
|
|
163
|
+
const { isRouteEntry } = getRuntimeRouterCli();
|
|
164
|
+
return {
|
|
165
|
+
path: entryPath,
|
|
166
|
+
entry: entry || isRouteEntry(entryPath, routesDir)
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
api.config(()=>({
|
|
170
|
+
source: {
|
|
171
|
+
include: [
|
|
172
|
+
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
173
|
+
external_node_path_default().resolve(__dirname, '../runtime').replace('cjs', 'esm')
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
api.modifyEntrypoints(async ({ entrypoints })=>{
|
|
178
|
+
const { handleModifyEntrypoints } = getRuntimeRouterCli();
|
|
179
|
+
return {
|
|
180
|
+
entrypoints: await handleModifyEntrypoints(entrypoints, routesDir, {
|
|
181
|
+
routesOwner: ENTRYPOINTS_KEY
|
|
182
|
+
})
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
api.generateEntryCode(async ({ entrypoints })=>{
|
|
186
|
+
const tanstackEntrypoints = entrypoints.filter(isTanstackEntrypoint);
|
|
187
|
+
if (0 === tanstackEntrypoints.length) return;
|
|
188
|
+
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
189
|
+
const routesByEntry = await handleGeneratorEntryCode(api, tanstackEntrypoints, {
|
|
190
|
+
entrypointsKey: ENTRYPOINTS_KEY,
|
|
191
|
+
generateCodeOptions: {
|
|
192
|
+
enableTanstackTypes: false
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
await writeTanstackRouterTypesForEntries({
|
|
196
|
+
appContext: api.getAppContext(),
|
|
197
|
+
generatedDirName,
|
|
198
|
+
routesByEntry
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
api.onFileChanged(async (event)=>{
|
|
202
|
+
const { handleFileChange } = getRuntimeRouterCli();
|
|
203
|
+
await handleFileChange(api, event, {
|
|
204
|
+
entrypointsKey: ENTRYPOINTS_KEY,
|
|
205
|
+
includeEntry: (entrypoint)=>{
|
|
206
|
+
const { getEntrypointRoutesDir } = getRuntimeRouterCli();
|
|
207
|
+
return getEntrypointRoutesDir(entrypoint) === routesDir;
|
|
208
|
+
},
|
|
209
|
+
regenerate: async ({ api, entrypoints })=>{
|
|
210
|
+
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
211
|
+
const routesByEntry = await handleGeneratorEntryCode(api, entrypoints, {
|
|
212
|
+
entrypointsKey: ENTRYPOINTS_KEY,
|
|
213
|
+
generateCodeOptions: {
|
|
214
|
+
enableTanstackTypes: false
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
await writeTanstackRouterTypesForEntries({
|
|
218
|
+
appContext: api.getAppContext(),
|
|
219
|
+
generatedDirName,
|
|
220
|
+
routesByEntry
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
api.modifyFileSystemRoutes(async ({ entrypoint, routes })=>{
|
|
226
|
+
if (isTanstackEntrypoint(entrypoint)) nestedRoutesForServer[entrypoint.entryName] = (0, utils_namespaceObject.filterRoutesForServer)(routes);
|
|
227
|
+
return {
|
|
228
|
+
entrypoint,
|
|
229
|
+
routes
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
api.onBeforeGenerateRoutes(async ({ entrypoint, code })=>{
|
|
233
|
+
if (isTanstackEntrypoint(entrypoint)) {
|
|
234
|
+
const { distDirectory } = api.getAppContext();
|
|
235
|
+
const nestedRoutesSpecPath = external_node_path_default().resolve(distDirectory, utils_namespaceObject.NESTED_ROUTE_SPEC_FILE);
|
|
236
|
+
const existingNestedRoutes = await utils_namespaceObject.fs.pathExists(nestedRoutesSpecPath) ? await utils_namespaceObject.fs.readJSON(nestedRoutesSpecPath) : {};
|
|
237
|
+
await utils_namespaceObject.fs.outputJSON(nestedRoutesSpecPath, {
|
|
238
|
+
...existingNestedRoutes,
|
|
239
|
+
...nestedRoutesForServer
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
entrypoint,
|
|
244
|
+
code
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const src_cli = tanstackRouterPlugin;
|
|
251
|
+
})();
|
|
252
|
+
exports["default"] = __webpack_exports__["default"];
|
|
253
|
+
exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
|
|
254
|
+
exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
|
|
255
|
+
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
256
|
+
exports.writeTanstackRegisterFile = __webpack_exports__.writeTanstackRegisterFile;
|
|
257
|
+
exports.writeTanstackRouterTypesForEntries = __webpack_exports__.writeTanstackRouterTypesForEntries;
|
|
258
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
259
|
+
"default",
|
|
260
|
+
"generateTanstackRouterTypesSourceForEntry",
|
|
261
|
+
"isTanstackRouterFrameworkEnabled",
|
|
262
|
+
"tanstackRouterPlugin",
|
|
263
|
+
"writeTanstackRegisterFile",
|
|
264
|
+
"writeTanstackRouterTypesForEntries"
|
|
265
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
266
|
+
Object.defineProperty(exports, '__esModule', {
|
|
267
|
+
value: true
|
|
268
|
+
});
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry,
|
|
37
|
+
isTanstackRouterFrameworkEnabled: ()=>isTanstackRouterFrameworkEnabled
|
|
38
|
+
});
|
|
39
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
40
|
+
const external_path_namespaceObject = require("path");
|
|
41
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
42
|
+
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
|
|
43
|
+
const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
|
|
44
|
+
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
45
|
+
function makeLegalIdentifier(str) {
|
|
46
|
+
const identifier = str.replace(/-(\w)/g, (_, letter)=>letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
47
|
+
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) return `_${identifier}`;
|
|
48
|
+
return identifier || '_';
|
|
49
|
+
}
|
|
50
|
+
function getPathWithoutExt(filename) {
|
|
51
|
+
const extname = external_path_default().extname(filename);
|
|
52
|
+
return extname ? filename.slice(0, -extname.length) : filename;
|
|
53
|
+
}
|
|
54
|
+
const JS_OR_TS_EXTS = [
|
|
55
|
+
'.js',
|
|
56
|
+
'.jsx',
|
|
57
|
+
'.ts',
|
|
58
|
+
'.tsx',
|
|
59
|
+
'.mjs',
|
|
60
|
+
'.mts',
|
|
61
|
+
'.cjs',
|
|
62
|
+
'.cts'
|
|
63
|
+
];
|
|
64
|
+
function toTanstackPath(pathname) {
|
|
65
|
+
return pathname.split('/').map((segment)=>{
|
|
66
|
+
if (!segment) return segment;
|
|
67
|
+
if ('*' === segment) return '$';
|
|
68
|
+
if (segment.startsWith(':')) {
|
|
69
|
+
const name = segment.slice(1);
|
|
70
|
+
if (name.endsWith('?')) return `{-$${name.slice(0, -1)}}`;
|
|
71
|
+
return `$${name}`;
|
|
72
|
+
}
|
|
73
|
+
return segment;
|
|
74
|
+
}).join('/');
|
|
75
|
+
}
|
|
76
|
+
async function resolveFileNoExt(inputNoExtPath) {
|
|
77
|
+
const file = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${inputNoExtPath}${ext}`));
|
|
78
|
+
return file ? getPathWithoutExt(file) : null;
|
|
79
|
+
}
|
|
80
|
+
function quote(str) {
|
|
81
|
+
return JSON.stringify(str);
|
|
82
|
+
}
|
|
83
|
+
function normalizeRelativeImport(p) {
|
|
84
|
+
const normalized = (0, utils_namespaceObject.formatImportPath)((0, utils_namespaceObject.slash)(p));
|
|
85
|
+
if (normalized.startsWith('.')) return normalized;
|
|
86
|
+
return `./${normalized}`;
|
|
87
|
+
}
|
|
88
|
+
function pickModernLoaderModule(route) {
|
|
89
|
+
const loaderPath = route.data || route.loader;
|
|
90
|
+
if (!loaderPath || 'string' != typeof loaderPath) return null;
|
|
91
|
+
const inline = Boolean(route.data);
|
|
92
|
+
return {
|
|
93
|
+
loaderPath,
|
|
94
|
+
inline
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function isPathlessLayout(route) {
|
|
98
|
+
return 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
|
|
99
|
+
}
|
|
100
|
+
function isIndexRoute(route) {
|
|
101
|
+
return 'nested' === route.type && Boolean(route.index);
|
|
102
|
+
}
|
|
103
|
+
function createRouteStaticDataSnippet(opts) {
|
|
104
|
+
const staticDataLines = [];
|
|
105
|
+
if (opts.modernRouteId) staticDataLines.push(`modernRouteId: ${quote(opts.modernRouteId)},`);
|
|
106
|
+
if (opts.loaderName) staticDataLines.push(`modernRouteLoader: ${opts.loaderName},`);
|
|
107
|
+
if (opts.actionName) staticDataLines.push(`modernRouteAction: ${opts.actionName},`);
|
|
108
|
+
if (!staticDataLines.length) return null;
|
|
109
|
+
return `staticData: createRouteStaticData({\n ${staticDataLines.join('\n ')}\n }),`;
|
|
110
|
+
}
|
|
111
|
+
async function isTanstackRouterFrameworkEnabled(appContext) {
|
|
112
|
+
const runtimeConfigBase = external_path_default().join(appContext.srcDirectory, appContext.runtimeConfigFile);
|
|
113
|
+
const runtimeConfigFile = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${runtimeConfigBase}${ext}`));
|
|
114
|
+
if (!runtimeConfigFile) return false;
|
|
115
|
+
try {
|
|
116
|
+
const content = await utils_namespaceObject.fs.readFile(runtimeConfigFile, 'utf-8');
|
|
117
|
+
return /framework\s*:\s*['"]tanstack['"]/.test(content);
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
123
|
+
const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
|
|
124
|
+
const outDir = external_path_default().join(appContext.srcDirectory, generatedDirName, entryName);
|
|
125
|
+
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
126
|
+
const topLevel = rootModern ? rootModern.children || [] : routes;
|
|
127
|
+
const imports = [];
|
|
128
|
+
const statements = [];
|
|
129
|
+
const loaderImportMap = new Map();
|
|
130
|
+
let loaderIndex = 0;
|
|
131
|
+
let routeIndex = 0;
|
|
132
|
+
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
133
|
+
const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
|
|
134
|
+
const existing = loaderImportMap.get(key);
|
|
135
|
+
if (existing) return {
|
|
136
|
+
loaderName: existing,
|
|
137
|
+
actionName: hasAction ? existing.replace(/^loader_/, 'action_') : null
|
|
138
|
+
};
|
|
139
|
+
const prefix = `${appContext.internalSrcAlias}/`;
|
|
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);
|
|
146
|
+
if (!resolvedNoExt) return null;
|
|
147
|
+
const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
|
|
148
|
+
const importName = `loader_${loaderIndex++}`;
|
|
149
|
+
const actionName = hasAction ? importName.replace(/^loader_/, 'action_') : null;
|
|
150
|
+
if (inline) {
|
|
151
|
+
const specifiers = [
|
|
152
|
+
`loader as ${importName}`
|
|
153
|
+
];
|
|
154
|
+
if (actionName) specifiers.push(`action as ${actionName}`);
|
|
155
|
+
imports.push(`import { ${specifiers.join(', ')} } from ${quote(relImport)};`);
|
|
156
|
+
} else imports.push(`import ${importName} from ${quote(relImport)};`);
|
|
157
|
+
loaderImportMap.set(key, importName);
|
|
158
|
+
return {
|
|
159
|
+
loaderName: importName,
|
|
160
|
+
actionName
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
const createRouteVarName = (route)=>{
|
|
164
|
+
const id = route.id;
|
|
165
|
+
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
166
|
+
return `route_${base}`;
|
|
167
|
+
};
|
|
168
|
+
const buildRoute = async (opts)=>{
|
|
169
|
+
const { parentVar, route } = opts;
|
|
170
|
+
const varName = createRouteVarName(route);
|
|
171
|
+
const loaderInfo = pickModernLoaderModule(route);
|
|
172
|
+
const routeAction = route.action;
|
|
173
|
+
const loaderImports = loaderInfo ? await getImportNamesForLoader(loaderInfo.loaderPath, loaderInfo.inline, Boolean(loaderInfo.inline && routeAction === loaderInfo.loaderPath)) : null;
|
|
174
|
+
const loaderName = loaderImports?.loaderName || null;
|
|
175
|
+
const actionName = loaderImports?.actionName || null;
|
|
176
|
+
const rawPath = route.path;
|
|
177
|
+
const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
|
|
178
|
+
const routeOpts = [
|
|
179
|
+
`getParentRoute: () => ${parentVar},`
|
|
180
|
+
];
|
|
181
|
+
if (isPathlessLayout(route)) {
|
|
182
|
+
const id = route.id;
|
|
183
|
+
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
184
|
+
} else {
|
|
185
|
+
const p = isIndexRoute(route) ? '/' : toTanstackPath(rawPath || '');
|
|
186
|
+
routeOpts.push(`path: ${quote(p)},`);
|
|
187
|
+
}
|
|
188
|
+
if (loaderName) routeOpts.push(`loader: modernLoaderToTanstack({ hasSplat: ${hasSplat} }, ${loaderName}),`);
|
|
189
|
+
const staticDataSnippet = createRouteStaticDataSnippet({
|
|
190
|
+
modernRouteId: route.id,
|
|
191
|
+
loaderName,
|
|
192
|
+
actionName
|
|
193
|
+
});
|
|
194
|
+
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
195
|
+
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
196
|
+
const children = route.children;
|
|
197
|
+
if (children && children.length > 0) {
|
|
198
|
+
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
199
|
+
parentVar: varName,
|
|
200
|
+
route: child
|
|
201
|
+
})));
|
|
202
|
+
statements.push(`${varName}.addChildren([${childVars.join(', ')}]);`);
|
|
203
|
+
}
|
|
204
|
+
return varName;
|
|
205
|
+
};
|
|
206
|
+
const rootLoaderInfo = rootModern ? pickModernLoaderModule(rootModern) : null;
|
|
207
|
+
const rootAction = rootModern?.action;
|
|
208
|
+
const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
|
|
209
|
+
const rootLoaderName = rootLoaderImports?.loaderName || null;
|
|
210
|
+
const rootActionName = rootLoaderImports?.actionName || null;
|
|
211
|
+
const topLevelVars = await Promise.all(topLevel.map((route)=>buildRoute({
|
|
212
|
+
parentVar: 'rootRoute',
|
|
213
|
+
route
|
|
214
|
+
})));
|
|
215
|
+
const rootOpts = [];
|
|
216
|
+
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
217
|
+
const routerGenTs = `/* eslint-disable */
|
|
218
|
+
// This file is auto-generated by Modern.js. Do not edit manually.
|
|
219
|
+
|
|
220
|
+
import {
|
|
221
|
+
createMemoryHistory,
|
|
222
|
+
createRootRouteWithContext,
|
|
223
|
+
createRoute,
|
|
224
|
+
createRouter,
|
|
225
|
+
notFound,
|
|
226
|
+
redirect,
|
|
227
|
+
} from '@modern-js/plugin-tanstack/runtime';
|
|
228
|
+
|
|
229
|
+
type ModernRouterContext = {
|
|
230
|
+
request?: Request;
|
|
231
|
+
requestContext?: unknown;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
function isResponse(value: unknown): value is Response {
|
|
235
|
+
return (
|
|
236
|
+
value != null &&
|
|
237
|
+
typeof value === 'object' &&
|
|
238
|
+
typeof (value as any).status === 'number' &&
|
|
239
|
+
typeof (value as any).headers === 'object'
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
|
|
244
|
+
function isRedirectResponse(res: Response) {
|
|
245
|
+
return redirectStatusCodes.has(res.status);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function throwTanstackRedirect(location: string) {
|
|
249
|
+
const target = location || '/';
|
|
250
|
+
try {
|
|
251
|
+
void new URL(target);
|
|
252
|
+
throw redirect({ href: target });
|
|
253
|
+
} catch {
|
|
254
|
+
throw redirect({ to: target });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function mapParamsForModernLoader(params: Record<string, string>, hasSplat: boolean) {
|
|
259
|
+
if (!hasSplat) {
|
|
260
|
+
return params;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const { _splat, ...rest } = params as any;
|
|
264
|
+
if (typeof _splat !== 'undefined') {
|
|
265
|
+
return { ...rest, '*': _splat };
|
|
266
|
+
}
|
|
267
|
+
return rest;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function createRouteStaticData(opts: {
|
|
271
|
+
modernRouteId?: string;
|
|
272
|
+
modernRouteAction?: unknown;
|
|
273
|
+
modernRouteLoader?: unknown;
|
|
274
|
+
}) {
|
|
275
|
+
const staticData: Record<string, unknown> = {};
|
|
276
|
+
|
|
277
|
+
if (opts.modernRouteId) {
|
|
278
|
+
staticData.modernRouteId = opts.modernRouteId;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (opts.modernRouteLoader) {
|
|
282
|
+
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (opts.modernRouteAction) {
|
|
286
|
+
staticData.modernRouteAction = opts.modernRouteAction;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return Object.keys(staticData).length > 0 ? staticData : undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
293
|
+
opts: { hasSplat: boolean },
|
|
294
|
+
modernLoader: TLoader,
|
|
295
|
+
) {
|
|
296
|
+
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
297
|
+
|
|
298
|
+
return async (ctx: any): Promise<LoaderResult> => {
|
|
299
|
+
try {
|
|
300
|
+
const signal: AbortSignal =
|
|
301
|
+
ctx?.abortController?.signal ||
|
|
302
|
+
ctx?.signal ||
|
|
303
|
+
new AbortController().signal;
|
|
304
|
+
const baseRequest: Request | undefined =
|
|
305
|
+
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
306
|
+
|
|
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
|
+
'';
|
|
314
|
+
|
|
315
|
+
const request = baseRequest
|
|
316
|
+
? new Request(baseRequest, { signal })
|
|
317
|
+
: new Request(href, { signal });
|
|
318
|
+
|
|
319
|
+
const params = mapParamsForModernLoader(ctx?.params || {}, opts.hasSplat);
|
|
320
|
+
|
|
321
|
+
const result = await (modernLoader as any)({
|
|
322
|
+
request,
|
|
323
|
+
params,
|
|
324
|
+
context: ctx?.context?.requestContext,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (isResponse(result)) {
|
|
328
|
+
if (isRedirectResponse(result)) {
|
|
329
|
+
const location = result.headers.get('Location') || '/';
|
|
330
|
+
throwTanstackRedirect(location);
|
|
331
|
+
}
|
|
332
|
+
if (result.status === 404) {
|
|
333
|
+
throw notFound();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return result as LoaderResult;
|
|
338
|
+
} catch (err) {
|
|
339
|
+
if (isResponse(err)) {
|
|
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;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
${imports.join('\n')}
|
|
354
|
+
|
|
355
|
+
export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
|
|
356
|
+
${rootOpts.join('\n ')}
|
|
357
|
+
${createRouteStaticDataSnippet({
|
|
358
|
+
modernRouteId: rootModern?.id,
|
|
359
|
+
loaderName: rootLoaderName,
|
|
360
|
+
actionName: rootActionName
|
|
361
|
+
}) || ''}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
${statements.join('\n\n')}
|
|
365
|
+
|
|
366
|
+
export const routeTree = rootRoute.addChildren([${topLevelVars.join(', ')}]);
|
|
367
|
+
|
|
368
|
+
export const router = createRouter({
|
|
369
|
+
routeTree,
|
|
370
|
+
history: createMemoryHistory({
|
|
371
|
+
initialEntries: ['/'],
|
|
372
|
+
}),
|
|
373
|
+
context: {} as ModernRouterContext,
|
|
374
|
+
});
|
|
375
|
+
`;
|
|
376
|
+
return {
|
|
377
|
+
routerGenTs
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
|
|
381
|
+
exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
|
|
382
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
383
|
+
"generateTanstackRouterTypesSourceForEntry",
|
|
384
|
+
"isTanstackRouterFrameworkEnabled"
|
|
385
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
386
|
+
Object.defineProperty(exports, '__esModule', {
|
|
387
|
+
value: true
|
|
388
|
+
});
|