@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.120 → 3.2.0-ultramodern.121
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 +47 -27
- package/dist/cjs/cli/routeSplitting.js +0 -32
- package/dist/cjs/cli/tanstackTypes.js +34 -199
- package/dist/cjs/runtime/hooks.js +11 -14
- package/dist/cjs/runtime/index.js +107 -319
- package/dist/cjs/runtime/lifecycle.js +12 -86
- package/dist/cjs/runtime/loaderBridge.js +173 -0
- package/dist/cjs/runtime/plugin.js +6 -30
- package/dist/cjs/runtime/plugin.node.js +7 -29
- package/dist/cjs/runtime/pluginCore.js +55 -0
- package/dist/cjs/runtime/register.js +56 -0
- package/dist/cjs/runtime/routeTree.js +10 -207
- package/dist/cjs/runtime/{DefaultNotFound.js → router.js} +5 -15
- package/dist/cjs/runtime/rsc/payloadRouter.js +35 -1
- package/dist/cjs/runtime/state.js +45 -0
- package/dist/cjs/runtime/utils.js +0 -5
- package/dist/esm/cli/index.mjs +52 -26
- package/dist/esm/cli/routeSplitting.mjs +1 -30
- package/dist/esm/cli/tanstackTypes.mjs +32 -194
- package/dist/esm/runtime/hooks.mjs +1 -8
- package/dist/esm/runtime/index.mjs +4 -2
- package/dist/esm/runtime/lifecycle.mjs +1 -82
- package/dist/esm/runtime/loaderBridge.mjs +114 -0
- package/dist/esm/runtime/plugin.mjs +8 -32
- package/dist/esm/runtime/plugin.node.mjs +10 -32
- package/dist/esm/runtime/pluginCore.mjs +14 -0
- package/dist/esm/runtime/register.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +4 -198
- package/dist/esm/runtime/router.mjs +2 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
- package/dist/esm/runtime/state.mjs +7 -0
- package/dist/esm/runtime/utils.mjs +0 -5
- package/dist/esm-node/cli/index.mjs +52 -26
- package/dist/esm-node/cli/routeSplitting.mjs +1 -30
- package/dist/esm-node/cli/tanstackTypes.mjs +32 -194
- package/dist/esm-node/runtime/hooks.mjs +1 -8
- package/dist/esm-node/runtime/index.mjs +4 -2
- package/dist/esm-node/runtime/lifecycle.mjs +1 -82
- package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
- package/dist/esm-node/runtime/plugin.mjs +8 -32
- package/dist/esm-node/runtime/plugin.node.mjs +10 -32
- package/dist/esm-node/runtime/pluginCore.mjs +15 -0
- package/dist/esm-node/runtime/register.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +4 -198
- package/dist/esm-node/runtime/router.mjs +3 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
- package/dist/esm-node/runtime/state.mjs +8 -0
- package/dist/esm-node/runtime/utils.mjs +0 -5
- package/dist/types/cli/index.d.ts +9 -2
- package/dist/types/cli/routeSplitting.d.ts +6 -15
- package/dist/types/cli/tanstackTypes.d.ts +13 -2
- package/dist/types/runtime/hooks.d.ts +8 -18
- package/dist/types/runtime/index.d.ts +6 -4
- package/dist/types/runtime/lifecycle.d.ts +7 -22
- package/dist/types/runtime/loaderBridge.d.ts +48 -0
- package/dist/types/runtime/plugin.d.ts +1 -14
- package/dist/types/runtime/plugin.node.d.ts +1 -14
- package/dist/types/runtime/pluginCore.d.ts +21 -0
- package/dist/types/runtime/register.d.ts +9 -0
- package/dist/types/runtime/routeTree.d.ts +0 -2
- package/dist/types/runtime/router.d.ts +14 -0
- package/dist/types/runtime/state.d.ts +16 -0
- package/dist/types/runtime/types.d.ts +7 -53
- package/package.json +30 -28
- package/rstest.config.mts +6 -0
- package/src/cli/index.ts +111 -29
- package/src/cli/routeSplitting.ts +6 -44
- package/src/cli/tanstackTypes.ts +78 -214
- package/src/runtime/hooks.ts +10 -27
- package/src/runtime/index.tsx +12 -107
- package/src/runtime/lifecycle.ts +16 -151
- package/src/runtime/loaderBridge.ts +257 -0
- package/src/runtime/plugin.node.tsx +14 -77
- package/src/runtime/plugin.tsx +12 -72
- package/src/runtime/pluginCore.ts +48 -0
- package/src/runtime/register.ts +58 -0
- package/src/runtime/routeTree.ts +8 -370
- package/src/runtime/router.ts +15 -0
- package/src/runtime/rsc/payloadRouter.ts +45 -2
- package/src/runtime/state.ts +29 -0
- package/src/runtime/types.ts +20 -67
- package/src/runtime/utils.tsx +3 -6
- package/tests/router/cli.test.ts +297 -31
- package/tests/router/hooks.test.ts +26 -0
- package/tests/router/loaderBridge.test.ts +211 -0
- package/tests/router/packageSurface.test.ts +24 -0
- package/tests/router/register.test.ts +46 -0
- package/tests/router/routeTree.test.ts +65 -180
- package/tests/router/rsc.test.tsx +70 -0
- package/tests/router/tanstackTypes.test.ts +164 -6
- package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
- package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
- package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
- package/src/runtime/DefaultNotFound.tsx +0 -15
package/dist/cjs/cli/index.js
CHANGED
|
@@ -56,8 +56,6 @@ var __webpack_exports__ = {};
|
|
|
56
56
|
createTanstackRsbuildRouteSplittingProfile: ()=>external_routeSplitting_js_namespaceObject.createTanstackRsbuildRouteSplittingProfile,
|
|
57
57
|
default: ()=>src_cli,
|
|
58
58
|
generateTanstackRouterTypesSourceForEntry: ()=>external_tanstackTypes_js_namespaceObject.generateTanstackRouterTypesSourceForEntry,
|
|
59
|
-
isTanstackRouterFrameworkEnabled: ()=>external_tanstackTypes_js_namespaceObject.isTanstackRouterFrameworkEnabled,
|
|
60
|
-
isTanstackStartRouteModuleSource: ()=>external_routeSplitting_js_namespaceObject.isTanstackStartRouteModuleSource,
|
|
61
59
|
resolveTanstackRouteCodeSplittingEnabled: ()=>external_routeSplitting_js_namespaceObject.resolveTanstackRouteCodeSplittingEnabled,
|
|
62
60
|
tanstackRouterPlugin: ()=>tanstackRouterPlugin,
|
|
63
61
|
writeTanstackRegisterFile: ()=>writeTanstackRegisterFile,
|
|
@@ -75,7 +73,7 @@ var __webpack_exports__ = {};
|
|
|
75
73
|
function getRuntimeRouterCli() {
|
|
76
74
|
if (runtimeRouterCli) return runtimeRouterCli;
|
|
77
75
|
const cli = __webpack_require__("@modern-js/runtime/cli");
|
|
78
|
-
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir) {
|
|
76
|
+
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir && cli.getEntrypointRoutesOwner) {
|
|
79
77
|
runtimeRouterCli = cli;
|
|
80
78
|
return runtimeRouterCli;
|
|
81
79
|
}
|
|
@@ -122,7 +120,7 @@ ${canonicalRoutesAugmentation}`;
|
|
|
122
120
|
}));
|
|
123
121
|
}
|
|
124
122
|
async function writeTanstackRouterTypesForEntries(opts) {
|
|
125
|
-
const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry } = opts;
|
|
123
|
+
const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry, i18nPluginInstalled = false } = opts;
|
|
126
124
|
const entryNames = Object.keys(routesByEntry);
|
|
127
125
|
await Promise.all(entryNames.map(async (entryName)=>{
|
|
128
126
|
const { routerGenTs } = await (0, external_tanstackTypes_js_namespaceObject.generateTanstackRouterTypesSourceForEntry)({
|
|
@@ -140,8 +138,10 @@ ${canonicalRoutesAugmentation}`;
|
|
|
140
138
|
return a.localeCompare(b);
|
|
141
139
|
});
|
|
142
140
|
let canonicalRoutes = null;
|
|
143
|
-
for (const entryName of registerEntries){
|
|
144
|
-
const entryCanonicalRoutes = (0, external_tanstackTypes_js_namespaceObject.collectCanonicalRoutesForEntry)(routesByEntry[entryName]
|
|
141
|
+
if (i18nPluginInstalled) for (const entryName of registerEntries){
|
|
142
|
+
const entryCanonicalRoutes = (0, external_tanstackTypes_js_namespaceObject.collectCanonicalRoutesForEntry)(routesByEntry[entryName], {
|
|
143
|
+
localeParamHeuristic: true
|
|
144
|
+
});
|
|
145
145
|
if (entryCanonicalRoutes) canonicalRoutes = {
|
|
146
146
|
...entryCanonicalRoutes,
|
|
147
147
|
...canonicalRoutes ?? {}
|
|
@@ -169,16 +169,42 @@ ${canonicalRoutesAugmentation}`;
|
|
|
169
169
|
const { getEntrypointRoutesDir } = getRuntimeRouterCli();
|
|
170
170
|
return getEntrypointRoutesDir(entrypoint) === routesDir;
|
|
171
171
|
};
|
|
172
|
+
const isForeignRouteEntrypoint = (entrypoint)=>{
|
|
173
|
+
const { getEntrypointRoutesDir, getEntrypointRoutesOwner } = getRuntimeRouterCli();
|
|
174
|
+
if (getEntrypointRoutesOwner(entrypoint)) return true;
|
|
175
|
+
if (entrypoint.pageRoutesEntry) return true;
|
|
176
|
+
return null !== getEntrypointRoutesDir(entrypoint);
|
|
177
|
+
};
|
|
178
|
+
const isI18nPluginInstalled = ()=>{
|
|
179
|
+
const { plugins } = api.getAppContext();
|
|
180
|
+
return Boolean(plugins?.some((plugin)=>plugin?.name === '@modern-js/plugin-i18n'));
|
|
181
|
+
};
|
|
172
182
|
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
173
|
-
|
|
183
|
+
const { metaName, serverRoutes } = api.getAppContext();
|
|
184
|
+
const serverBase = serverRoutes.filter((route)=>route.entryName === entrypoint.entryName).map((route)=>route.urlPath).sort((a, b)=>a.length - b.length > 0 ? -1 : 1);
|
|
185
|
+
if (isTanstackEntrypoint(entrypoint)) {
|
|
186
|
+
plugins.push({
|
|
187
|
+
name: 'tanstackRouter',
|
|
188
|
+
path: `@${metaName}/plugin-tanstack/runtime`,
|
|
189
|
+
config: {
|
|
190
|
+
serverBase
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
entrypoint,
|
|
195
|
+
plugins
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (isForeignRouteEntrypoint(entrypoint)) return {
|
|
174
199
|
entrypoint,
|
|
175
200
|
plugins
|
|
176
201
|
};
|
|
177
|
-
const {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
202
|
+
const routerWrapperPath = `@${metaName}/plugin-tanstack/runtime/router`;
|
|
203
|
+
const existingRouterPlugin = plugins.find((plugin)=>'router' === plugin.name);
|
|
204
|
+
if (existingRouterPlugin) existingRouterPlugin.path = routerWrapperPath;
|
|
205
|
+
else plugins.push({
|
|
206
|
+
name: 'router',
|
|
207
|
+
path: routerWrapperPath,
|
|
182
208
|
config: {
|
|
183
209
|
serverBase
|
|
184
210
|
}
|
|
@@ -197,7 +223,9 @@ ${canonicalRoutesAugmentation}`;
|
|
|
197
223
|
source: {
|
|
198
224
|
include: [
|
|
199
225
|
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
200
|
-
|
|
226
|
+
/[\\/]node_modules[\\/]@tanstack[\\/]router-core[\\/]/,
|
|
227
|
+
/[\\/]node_modules[\\/]@tanstack[\\/]react-store[\\/]/,
|
|
228
|
+
external_node_path_default().resolve(__dirname, '..', '..')
|
|
201
229
|
]
|
|
202
230
|
}
|
|
203
231
|
}));
|
|
@@ -214,15 +242,13 @@ ${canonicalRoutesAugmentation}`;
|
|
|
214
242
|
if (0 === tanstackEntrypoints.length) return;
|
|
215
243
|
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
216
244
|
const routesByEntry = await handleGeneratorEntryCode(api, tanstackEntrypoints, {
|
|
217
|
-
entrypointsKey: ENTRYPOINTS_KEY
|
|
218
|
-
generateCodeOptions: {
|
|
219
|
-
enableTanstackTypes: false
|
|
220
|
-
}
|
|
245
|
+
entrypointsKey: ENTRYPOINTS_KEY
|
|
221
246
|
});
|
|
222
247
|
await writeTanstackRouterTypesForEntries({
|
|
223
248
|
appContext: api.getAppContext(),
|
|
224
249
|
generatedDirName,
|
|
225
|
-
routesByEntry
|
|
250
|
+
routesByEntry,
|
|
251
|
+
i18nPluginInstalled: isI18nPluginInstalled()
|
|
226
252
|
});
|
|
227
253
|
});
|
|
228
254
|
api.onFileChanged(async (event)=>{
|
|
@@ -236,15 +262,13 @@ ${canonicalRoutesAugmentation}`;
|
|
|
236
262
|
regenerate: async ({ api, entrypoints })=>{
|
|
237
263
|
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
238
264
|
const routesByEntry = await handleGeneratorEntryCode(api, entrypoints, {
|
|
239
|
-
entrypointsKey: ENTRYPOINTS_KEY
|
|
240
|
-
generateCodeOptions: {
|
|
241
|
-
enableTanstackTypes: false
|
|
242
|
-
}
|
|
265
|
+
entrypointsKey: ENTRYPOINTS_KEY
|
|
243
266
|
});
|
|
244
267
|
await writeTanstackRouterTypesForEntries({
|
|
245
268
|
appContext: api.getAppContext(),
|
|
246
269
|
generatedDirName,
|
|
247
|
-
routesByEntry
|
|
270
|
+
routesByEntry,
|
|
271
|
+
i18nPluginInstalled: isI18nPluginInstalled()
|
|
248
272
|
});
|
|
249
273
|
}
|
|
250
274
|
});
|
|
@@ -280,8 +304,6 @@ exports.collectCanonicalRoutesForEntry = __webpack_exports__.collectCanonicalRou
|
|
|
280
304
|
exports.createTanstackRsbuildRouteSplittingProfile = __webpack_exports__.createTanstackRsbuildRouteSplittingProfile;
|
|
281
305
|
exports["default"] = __webpack_exports__["default"];
|
|
282
306
|
exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
|
|
283
|
-
exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
|
|
284
|
-
exports.isTanstackStartRouteModuleSource = __webpack_exports__.isTanstackStartRouteModuleSource;
|
|
285
307
|
exports.resolveTanstackRouteCodeSplittingEnabled = __webpack_exports__.resolveTanstackRouteCodeSplittingEnabled;
|
|
286
308
|
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
287
309
|
exports.writeTanstackRegisterFile = __webpack_exports__.writeTanstackRegisterFile;
|
|
@@ -291,8 +313,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
291
313
|
"createTanstackRsbuildRouteSplittingProfile",
|
|
292
314
|
"default",
|
|
293
315
|
"generateTanstackRouterTypesSourceForEntry",
|
|
294
|
-
"isTanstackRouterFrameworkEnabled",
|
|
295
|
-
"isTanstackStartRouteModuleSource",
|
|
296
316
|
"resolveTanstackRouteCodeSplittingEnabled",
|
|
297
317
|
"tanstackRouterPlugin",
|
|
298
318
|
"writeTanstackRegisterFile",
|
|
@@ -27,15 +27,6 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
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
30
|
function resolveTanstackRouteCodeSplittingEnabled(option) {
|
|
40
31
|
if ('boolean' == typeof option) return option;
|
|
41
32
|
return option?.enabled ?? true;
|
|
@@ -46,40 +37,17 @@ function createTanstackRsbuildRouteSplittingProfile(opts) {
|
|
|
46
37
|
output: {
|
|
47
38
|
splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting)
|
|
48
39
|
}
|
|
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
40
|
}
|
|
70
41
|
};
|
|
71
42
|
}
|
|
72
43
|
__webpack_require__.d(__webpack_exports__, {
|
|
73
44
|
createTanstackRsbuildRouteSplittingProfile: ()=>createTanstackRsbuildRouteSplittingProfile,
|
|
74
|
-
isTanstackStartRouteModuleSource: ()=>isTanstackStartRouteModuleSource,
|
|
75
45
|
resolveTanstackRouteCodeSplittingEnabled: ()=>resolveTanstackRouteCodeSplittingEnabled
|
|
76
46
|
});
|
|
77
47
|
exports.createTanstackRsbuildRouteSplittingProfile = __webpack_exports__.createTanstackRsbuildRouteSplittingProfile;
|
|
78
|
-
exports.isTanstackStartRouteModuleSource = __webpack_exports__.isTanstackStartRouteModuleSource;
|
|
79
48
|
exports.resolveTanstackRouteCodeSplittingEnabled = __webpack_exports__.resolveTanstackRouteCodeSplittingEnabled;
|
|
80
49
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
81
50
|
"createTanstackRsbuildRouteSplittingProfile",
|
|
82
|
-
"isTanstackStartRouteModuleSource",
|
|
83
51
|
"resolveTanstackRouteCodeSplittingEnabled"
|
|
84
52
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
53
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -38,24 +38,12 @@ var __webpack_exports__ = {};
|
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
collectCanonicalRoutesForEntry: ()=>collectCanonicalRoutesForEntry,
|
|
41
|
-
generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry
|
|
42
|
-
isTanstackRouterFrameworkEnabled: ()=>isTanstackRouterFrameworkEnabled
|
|
41
|
+
generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry
|
|
43
42
|
});
|
|
43
|
+
const cli_namespaceObject = require("@modern-js/runtime/cli");
|
|
44
44
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
45
|
const external_path_namespaceObject = require("path");
|
|
46
46
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
-
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';
|
|
48
|
-
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';
|
|
49
|
-
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
50
|
-
function makeLegalIdentifier(str) {
|
|
51
|
-
const identifier = str.replace(/-(\w)/g, (_, letter)=>letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
52
|
-
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) return `_${identifier}`;
|
|
53
|
-
return identifier || '_';
|
|
54
|
-
}
|
|
55
|
-
function getPathWithoutExt(filename) {
|
|
56
|
-
const extname = external_path_default().extname(filename);
|
|
57
|
-
return extname ? filename.slice(0, -extname.length) : filename;
|
|
58
|
-
}
|
|
59
47
|
const JS_OR_TS_EXTS = [
|
|
60
48
|
'.js',
|
|
61
49
|
'.jsx',
|
|
@@ -80,7 +68,7 @@ function toTanstackPath(pathname) {
|
|
|
80
68
|
}
|
|
81
69
|
async function resolveFileNoExt(inputNoExtPath) {
|
|
82
70
|
const file = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${inputNoExtPath}${ext}`));
|
|
83
|
-
return file ? getPathWithoutExt(file) : null;
|
|
71
|
+
return file ? (0, cli_namespaceObject.getPathWithoutExt)(file) : null;
|
|
84
72
|
}
|
|
85
73
|
function quote(str) {
|
|
86
74
|
return JSON.stringify(str);
|
|
@@ -152,7 +140,8 @@ function paramsTypeForCanonicalPath(canonicalPath) {
|
|
|
152
140
|
}
|
|
153
141
|
return fields.length > 0 ? `{ ${fields.join('; ')} }` : 'Record<string, never>';
|
|
154
142
|
}
|
|
155
|
-
function collectCanonicalRoutesForEntry(routes) {
|
|
143
|
+
function collectCanonicalRoutesForEntry(routes, options = {}) {
|
|
144
|
+
const { localeParamHeuristic = true } = options;
|
|
156
145
|
const canonicalParams = new Map();
|
|
157
146
|
let hasI18nSurface = false;
|
|
158
147
|
const normalizeJoined = (joined)=>{
|
|
@@ -172,7 +161,7 @@ function collectCanonicalRoutesForEntry(routes) {
|
|
|
172
161
|
currentPath = normalizeJoined(route.modernCanonicalPath);
|
|
173
162
|
} else if ('string' == typeof route.path && route.path.length > 0) {
|
|
174
163
|
const segments = route.path.replace(/\[(.+?)\]/g, ':$1').split('/').filter(Boolean);
|
|
175
|
-
if ('' === parentPath && LOCALE_PARAM_SEGMENTS.has(segments[0])) {
|
|
164
|
+
if (localeParamHeuristic && '' === parentPath && LOCALE_PARAM_SEGMENTS.has(segments[0])) {
|
|
176
165
|
hasI18nSurface = true;
|
|
177
166
|
segments.shift();
|
|
178
167
|
}
|
|
@@ -193,17 +182,6 @@ function collectCanonicalRoutesForEntry(routes) {
|
|
|
193
182
|
...canonicalParams.entries()
|
|
194
183
|
].sort(([a], [b])=>a.localeCompare(b)));
|
|
195
184
|
}
|
|
196
|
-
async function isTanstackRouterFrameworkEnabled(appContext) {
|
|
197
|
-
const runtimeConfigBase = external_path_default().join(appContext.srcDirectory, appContext.runtimeConfigFile);
|
|
198
|
-
const runtimeConfigFile = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${runtimeConfigBase}${ext}`));
|
|
199
|
-
if (!runtimeConfigFile) return false;
|
|
200
|
-
try {
|
|
201
|
-
const content = await utils_namespaceObject.fs.readFile(runtimeConfigFile, 'utf-8');
|
|
202
|
-
return /framework\s*:\s*['"]tanstack['"]/.test(content);
|
|
203
|
-
} catch {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
185
|
async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
208
186
|
const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
|
|
209
187
|
const outDir = external_path_default().join(appContext.srcDirectory, generatedDirName, entryName);
|
|
@@ -212,12 +190,30 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
212
190
|
const imports = [];
|
|
213
191
|
const statements = [];
|
|
214
192
|
const loaderImportMap = new Map();
|
|
193
|
+
const componentImportMap = new Map();
|
|
215
194
|
const searchContractImportMap = new Map();
|
|
216
195
|
const usedRouteVarNames = new Set();
|
|
217
196
|
let loaderIndex = 0;
|
|
197
|
+
let componentIndex = 0;
|
|
218
198
|
let validateSearchIndex = 0;
|
|
219
199
|
let loaderDepsIndex = 0;
|
|
220
200
|
let routeIndex = 0;
|
|
201
|
+
const getImportNameForComponent = (componentPath)=>{
|
|
202
|
+
if ('string' != typeof componentPath || 0 === componentPath.length) return Promise.resolve(null);
|
|
203
|
+
let pendingImportName = componentImportMap.get(componentPath);
|
|
204
|
+
if (!pendingImportName) {
|
|
205
|
+
pendingImportName = (async ()=>{
|
|
206
|
+
const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
|
|
207
|
+
if (!resolvedNoExt) return null;
|
|
208
|
+
const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
|
|
209
|
+
const componentName = `component_${componentIndex++}`;
|
|
210
|
+
imports.push(`import ${componentName} from ${quote(relImport)};`);
|
|
211
|
+
return componentName;
|
|
212
|
+
})();
|
|
213
|
+
componentImportMap.set(componentPath, pendingImportName);
|
|
214
|
+
}
|
|
215
|
+
return pendingImportName;
|
|
216
|
+
};
|
|
221
217
|
const resolveRouteModuleNoExt = async (aliasedNoExtPath)=>{
|
|
222
218
|
const prefix = `${appContext.internalSrcAlias}/`;
|
|
223
219
|
let absNoExt;
|
|
@@ -273,7 +269,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
273
269
|
};
|
|
274
270
|
const createRouteVarName = (route)=>{
|
|
275
271
|
const id = route.id;
|
|
276
|
-
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
272
|
+
const base = id ? (0, cli_namespaceObject.makeLegalIdentifier)(id) : `r_${routeIndex++}`;
|
|
277
273
|
return reserveRouteVarName(`route_${base}`);
|
|
278
274
|
};
|
|
279
275
|
const buildRoute = async (opts)=>{
|
|
@@ -292,6 +288,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
292
288
|
const routeOpts = [
|
|
293
289
|
`getParentRoute: () => ${parentVar},`
|
|
294
290
|
];
|
|
291
|
+
const componentName = await getImportNameForComponent(route._component);
|
|
292
|
+
if (componentName) routeOpts.push(`component: ${componentName},`);
|
|
295
293
|
if (isPathlessLayout(route)) {
|
|
296
294
|
const id = route.id;
|
|
297
295
|
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
@@ -334,6 +332,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
334
332
|
route
|
|
335
333
|
})));
|
|
336
334
|
const rootOpts = [];
|
|
335
|
+
const rootComponentName = await getImportNameForComponent(rootModern?._component);
|
|
336
|
+
if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
|
|
337
337
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
338
338
|
if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
|
|
339
339
|
if (rootLoaderDepsName) rootOpts.push(`loaderDeps: ${rootLoaderDepsName},`);
|
|
@@ -342,178 +342,15 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
342
342
|
|
|
343
343
|
import {
|
|
344
344
|
createMemoryHistory,
|
|
345
|
-
modernTanstackRouterFastDefaults,
|
|
346
345
|
createRootRouteWithContext,
|
|
347
346
|
createRoute,
|
|
348
347
|
createRouter,
|
|
349
|
-
|
|
350
|
-
|
|
348
|
+
createRouteStaticData,
|
|
349
|
+
type ModernRouterContext,
|
|
350
|
+
modernLoaderToTanstack,
|
|
351
|
+
modernTanstackRouterFastDefaults,
|
|
351
352
|
} from '@modern-js/plugin-tanstack/runtime';
|
|
352
353
|
|
|
353
|
-
type ModernRouterContext = {
|
|
354
|
-
request?: Request;
|
|
355
|
-
requestContext?: unknown;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
function isResponse(value: unknown): value is Response {
|
|
359
|
-
return (
|
|
360
|
-
value != null &&
|
|
361
|
-
typeof value === 'object' &&
|
|
362
|
-
typeof (value as any).status === 'number' &&
|
|
363
|
-
typeof (value as any).headers === 'object'
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
|
|
368
|
-
function isRedirectResponse(res: Response) {
|
|
369
|
-
return redirectStatusCodes.has(res.status);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function throwTanstackRedirect(location: string) {
|
|
373
|
-
const target = location.length > 0 ? location : '/';
|
|
374
|
-
try {
|
|
375
|
-
void new URL(target);
|
|
376
|
-
throw redirect({ href: target });
|
|
377
|
-
} catch {
|
|
378
|
-
throw redirect({ to: target });
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function mapParamsForModernLoader(params: Record<string, string>, hasSplat: boolean) {
|
|
383
|
-
if (!hasSplat) {
|
|
384
|
-
return params;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const { _splat, ...rest } = params as any;
|
|
388
|
-
if (typeof _splat !== 'undefined') {
|
|
389
|
-
return { ...rest, '*': _splat };
|
|
390
|
-
}
|
|
391
|
-
return rest;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function createRouteStaticData(opts: {
|
|
395
|
-
modernRouteId?: string;
|
|
396
|
-
modernRouteAction?: unknown;
|
|
397
|
-
modernRouteLoader?: unknown;
|
|
398
|
-
}) {
|
|
399
|
-
const staticData: {
|
|
400
|
-
modernRouteId?: string;
|
|
401
|
-
modernRouteAction?: unknown;
|
|
402
|
-
modernRouteLoader?: unknown;
|
|
403
|
-
} = {};
|
|
404
|
-
|
|
405
|
-
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
406
|
-
staticData.modernRouteId = opts.modernRouteId;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
410
|
-
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
414
|
-
staticData.modernRouteAction = opts.modernRouteAction;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return staticData;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function getLoaderSignal(ctx: any): AbortSignal {
|
|
421
|
-
const abortSignal = ctx?.abortController?.signal;
|
|
422
|
-
if (abortSignal instanceof AbortSignal) {
|
|
423
|
-
return abortSignal;
|
|
424
|
-
}
|
|
425
|
-
if (ctx?.signal instanceof AbortSignal) {
|
|
426
|
-
return ctx.signal;
|
|
427
|
-
}
|
|
428
|
-
return new AbortController().signal;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function getLoaderHref(ctx: any): string {
|
|
432
|
-
if (typeof ctx?.location === 'string') {
|
|
433
|
-
return ctx.location;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
const publicHref = ctx?.location?.publicHref;
|
|
437
|
-
if (typeof publicHref === 'string') {
|
|
438
|
-
return publicHref;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const href = ctx?.location?.href;
|
|
442
|
-
if (typeof href === 'string') {
|
|
443
|
-
return href;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
const urlHref = ctx?.location?.url?.href;
|
|
447
|
-
return typeof urlHref === 'string' ? urlHref : '';
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function getLoaderParams(ctx: any): Record<string, string> {
|
|
451
|
-
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
455
|
-
if (isResponse(result)) {
|
|
456
|
-
if (isRedirectResponse(result)) {
|
|
457
|
-
const location = result.headers.get('Location') ?? '/';
|
|
458
|
-
throwTanstackRedirect(location);
|
|
459
|
-
}
|
|
460
|
-
if (result.status === 404) {
|
|
461
|
-
throw notFound();
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return result;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function handleModernLoaderError(err: unknown): never {
|
|
469
|
-
if (isResponse(err)) {
|
|
470
|
-
if (isRedirectResponse(err)) {
|
|
471
|
-
const location = err.headers.get('Location') ?? '/';
|
|
472
|
-
throwTanstackRedirect(location);
|
|
473
|
-
}
|
|
474
|
-
if (err.status === 404) {
|
|
475
|
-
throw notFound();
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
throw err;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
483
|
-
opts: { hasSplat: boolean },
|
|
484
|
-
modernLoader: TLoader,
|
|
485
|
-
) {
|
|
486
|
-
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
487
|
-
|
|
488
|
-
return (ctx: any): Promise<LoaderResult> => {
|
|
489
|
-
try {
|
|
490
|
-
const signal = getLoaderSignal(ctx);
|
|
491
|
-
const baseRequest: Request | undefined =
|
|
492
|
-
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
493
|
-
|
|
494
|
-
const href = getLoaderHref(ctx);
|
|
495
|
-
|
|
496
|
-
const request = baseRequest !== undefined
|
|
497
|
-
? new Request(baseRequest, { signal })
|
|
498
|
-
: new Request(href, { signal });
|
|
499
|
-
|
|
500
|
-
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
501
|
-
|
|
502
|
-
return Promise.resolve(
|
|
503
|
-
(modernLoader as any)({
|
|
504
|
-
request,
|
|
505
|
-
params,
|
|
506
|
-
context: ctx?.context?.requestContext,
|
|
507
|
-
}),
|
|
508
|
-
)
|
|
509
|
-
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
510
|
-
.catch(handleModernLoaderError);
|
|
511
|
-
} catch (err) {
|
|
512
|
-
handleModernLoaderError(err);
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
|
|
517
354
|
${imports.join('\n')}
|
|
518
355
|
|
|
519
356
|
export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
|
|
@@ -544,11 +381,9 @@ export const router = createRouter({
|
|
|
544
381
|
}
|
|
545
382
|
exports.collectCanonicalRoutesForEntry = __webpack_exports__.collectCanonicalRoutesForEntry;
|
|
546
383
|
exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
|
|
547
|
-
exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
|
|
548
384
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
549
385
|
"collectCanonicalRoutesForEntry",
|
|
550
|
-
"generateTanstackRouterTypesSourceForEntry"
|
|
551
|
-
"isTanstackRouterFrameworkEnabled"
|
|
386
|
+
"generateTanstackRouterTypesSourceForEntry"
|
|
552
387
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
553
388
|
Object.defineProperty(exports, '__esModule', {
|
|
554
389
|
value: true
|
|
@@ -28,33 +28,30 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
modifyRoutes: ()=>modifyRoutes,
|
|
32
|
-
onAfterCreateRouter: ()=>onAfterCreateRouter,
|
|
33
|
-
onAfterHydrateRouter: ()=>onAfterHydrateRouter,
|
|
34
|
-
onBeforeCreateRouter: ()=>onBeforeCreateRouter,
|
|
35
|
-
onBeforeCreateRoutes: ()=>onBeforeCreateRoutes,
|
|
36
|
-
onBeforeHydrateRouter: ()=>onBeforeHydrateRouter
|
|
31
|
+
modifyRoutes: ()=>context_namespaceObject.modifyRoutes,
|
|
32
|
+
onAfterCreateRouter: ()=>context_namespaceObject.onAfterCreateRouter,
|
|
33
|
+
onAfterHydrateRouter: ()=>context_namespaceObject.onAfterHydrateRouter,
|
|
34
|
+
onBeforeCreateRouter: ()=>context_namespaceObject.onBeforeCreateRouter,
|
|
35
|
+
onBeforeCreateRoutes: ()=>context_namespaceObject.onBeforeCreateRoutes,
|
|
36
|
+
onBeforeHydrateRouter: ()=>context_namespaceObject.onBeforeHydrateRouter,
|
|
37
|
+
routerProviderRegistryHooks: ()=>context_namespaceObject.routerProviderRegistryHooks
|
|
37
38
|
});
|
|
38
|
-
const
|
|
39
|
-
const modifyRoutes = (0, plugin_namespaceObject.createSyncHook)();
|
|
40
|
-
const onBeforeCreateRoutes = (0, plugin_namespaceObject.createSyncHook)();
|
|
41
|
-
const onBeforeCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
42
|
-
const onAfterCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
43
|
-
const onBeforeHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
44
|
-
const onAfterHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
39
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
45
40
|
exports.modifyRoutes = __webpack_exports__.modifyRoutes;
|
|
46
41
|
exports.onAfterCreateRouter = __webpack_exports__.onAfterCreateRouter;
|
|
47
42
|
exports.onAfterHydrateRouter = __webpack_exports__.onAfterHydrateRouter;
|
|
48
43
|
exports.onBeforeCreateRouter = __webpack_exports__.onBeforeCreateRouter;
|
|
49
44
|
exports.onBeforeCreateRoutes = __webpack_exports__.onBeforeCreateRoutes;
|
|
50
45
|
exports.onBeforeHydrateRouter = __webpack_exports__.onBeforeHydrateRouter;
|
|
46
|
+
exports.routerProviderRegistryHooks = __webpack_exports__.routerProviderRegistryHooks;
|
|
51
47
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
52
48
|
"modifyRoutes",
|
|
53
49
|
"onAfterCreateRouter",
|
|
54
50
|
"onAfterHydrateRouter",
|
|
55
51
|
"onBeforeCreateRouter",
|
|
56
52
|
"onBeforeCreateRoutes",
|
|
57
|
-
"onBeforeHydrateRouter"
|
|
53
|
+
"onBeforeHydrateRouter",
|
|
54
|
+
"routerProviderRegistryHooks"
|
|
58
55
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
56
|
Object.defineProperty(exports, '__esModule', {
|
|
60
57
|
value: true
|