@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.120
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 -9
- package/dist/cjs/cli/routeSplitting.js +87 -0
- package/dist/cjs/cli/tanstackTypes.js +230 -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 +28 -6
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +219 -59
- 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 +28 -6
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +219 -59
- 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 +7 -1
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- package/dist/types/cli/tanstackTypes.d.ts +9 -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 +20 -20
- package/src/cli/index.ts +59 -2
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +347 -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 +315 -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 +415 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
|
|
1
|
+
import { createRootRoute, createRoute, notFound, redirect, rootRouteId } from "@tanstack/react-router";
|
|
2
|
+
import { createElement } from "react";
|
|
2
3
|
import { DefaultNotFound } from "./DefaultNotFound.mjs";
|
|
4
|
+
import { withModernRouteMatchContext } from "./outlet.mjs";
|
|
3
5
|
import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "./rsc/payloadRouter.mjs";
|
|
4
6
|
function createTanstackRoute(options) {
|
|
5
7
|
return createRoute(options);
|
|
@@ -7,6 +9,10 @@ function createTanstackRoute(options) {
|
|
|
7
9
|
function createTanstackRootRoute(options) {
|
|
8
10
|
return createRootRoute(options);
|
|
9
11
|
}
|
|
12
|
+
function wrapRouteComponentWithModernContext(route, component, routeId) {
|
|
13
|
+
const routeMatchId = routeId || route.id;
|
|
14
|
+
if (component && routeMatchId) route.options.component = withModernRouteMatchContext(component, routeMatchId);
|
|
15
|
+
}
|
|
10
16
|
function toTanstackPath(pathname) {
|
|
11
17
|
return pathname.split('/').map((segment)=>{
|
|
12
18
|
if (!segment) return segment;
|
|
@@ -54,6 +60,40 @@ function normalizeModernLoaderResponse(result) {
|
|
|
54
60
|
}
|
|
55
61
|
return normalizeModernLoaderResult(result);
|
|
56
62
|
}
|
|
63
|
+
function pickRouteModuleComponent(routeModule, seen = new Set()) {
|
|
64
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
65
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
66
|
+
if (seen.has(routeModule)) return;
|
|
67
|
+
seen.add(routeModule);
|
|
68
|
+
const module = routeModule;
|
|
69
|
+
for (const candidate of [
|
|
70
|
+
module.default,
|
|
71
|
+
module.Component
|
|
72
|
+
]){
|
|
73
|
+
const component = pickRouteModuleComponent(candidate, seen);
|
|
74
|
+
if (component) return component;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
78
|
+
if ("u" > typeof document) return fallbackComponent;
|
|
79
|
+
let resolvedComponent;
|
|
80
|
+
let pendingLoad;
|
|
81
|
+
const load = async ()=>{
|
|
82
|
+
if (resolvedComponent) return resolvedComponent;
|
|
83
|
+
const routeModule = await lazyImport();
|
|
84
|
+
const component = pickRouteModuleComponent(routeModule);
|
|
85
|
+
if (component) resolvedComponent = component;
|
|
86
|
+
return resolvedComponent;
|
|
87
|
+
};
|
|
88
|
+
const Component = (props)=>{
|
|
89
|
+
if (resolvedComponent) return createElement(resolvedComponent, props);
|
|
90
|
+
pendingLoad ||= load();
|
|
91
|
+
throw pendingLoad;
|
|
92
|
+
};
|
|
93
|
+
Component.load = load;
|
|
94
|
+
Component.preload = load;
|
|
95
|
+
return Component;
|
|
96
|
+
}
|
|
57
97
|
function isAbsoluteUrl(value) {
|
|
58
98
|
try {
|
|
59
99
|
new URL(value);
|
|
@@ -126,7 +166,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options
|
|
|
126
166
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
127
167
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
128
168
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
129
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
169
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
130
170
|
signal
|
|
131
171
|
}) : createModernRequest(href, signal);
|
|
132
172
|
const params = mapParamsForModernLoader({
|
|
@@ -191,7 +231,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
191
231
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
192
232
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
193
233
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
194
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
234
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
195
235
|
signal
|
|
196
236
|
}) : createModernRequest(href, signal);
|
|
197
237
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -228,10 +268,18 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
228
268
|
}
|
|
229
269
|
function toRouteComponent(routeObject) {
|
|
230
270
|
const route = routeObject;
|
|
271
|
+
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
272
|
+
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
273
|
+
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
231
274
|
if (route.Component) return route.Component;
|
|
232
275
|
const element = route.element;
|
|
233
276
|
if (element) return ()=>element;
|
|
234
277
|
}
|
|
278
|
+
function toModernRouteComponent(route) {
|
|
279
|
+
const component = route.component || void 0;
|
|
280
|
+
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
281
|
+
return component;
|
|
282
|
+
}
|
|
235
283
|
function toErrorComponent(routeObject) {
|
|
236
284
|
const route = routeObject;
|
|
237
285
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -269,12 +317,14 @@ function createRouteFromRouteObject(opts) {
|
|
|
269
317
|
const shouldRevalidate = modernRouteObject.shouldRevalidate;
|
|
270
318
|
const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
|
|
271
319
|
const stableFallbackId = routeObject.id || modernRouteObject.file || routeObject.path || 'pathless';
|
|
320
|
+
const component = toRouteComponent(routeObject);
|
|
272
321
|
const base = {
|
|
273
322
|
getParentRoute: ()=>parent,
|
|
274
|
-
component
|
|
323
|
+
component,
|
|
275
324
|
pendingComponent: toPendingComponent(routeObject),
|
|
276
325
|
errorComponent: toErrorComponent(routeObject),
|
|
277
|
-
|
|
326
|
+
validateSearch: modernRouteObject.validateSearch,
|
|
327
|
+
loaderDeps: modernRouteObject.loaderDeps,
|
|
278
328
|
staticData: createRouteStaticData({
|
|
279
329
|
modernRouteId: routeObject.id,
|
|
280
330
|
modernRouteAction: modernRouteObject.action,
|
|
@@ -293,6 +343,7 @@ function createRouteFromRouteObject(opts) {
|
|
|
293
343
|
if (isRouteObjectPathlessLayout(routeObject)) base.id = stableFallbackId;
|
|
294
344
|
else base.path = routeObject.index ? '/' : toTanstackPath(routeObject.path || '');
|
|
295
345
|
const route = createTanstackRoute(base);
|
|
346
|
+
wrapRouteComponentWithModernContext(route, component, routeObject.id);
|
|
296
347
|
const children = routeObject.children;
|
|
297
348
|
if (children && children.length > 0) {
|
|
298
349
|
const childRoutes = children.map((child)=>createRouteFromRouteObject({
|
|
@@ -312,7 +363,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
312
363
|
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
313
364
|
const pendingComponent = route.loading || route.pendingComponent;
|
|
314
365
|
const errorComponent = route.error || route.errorComponent;
|
|
315
|
-
const component = route
|
|
366
|
+
const component = toModernRouteComponent(route);
|
|
316
367
|
const modernLoader = route.loader;
|
|
317
368
|
const modernAction = route.action;
|
|
318
369
|
const modernShouldRevalidate = route.shouldRevalidate;
|
|
@@ -324,7 +375,8 @@ function createRouteFromModernRoute(opts) {
|
|
|
324
375
|
component: component || void 0,
|
|
325
376
|
pendingComponent: pendingComponent || void 0,
|
|
326
377
|
errorComponent: errorComponent || void 0,
|
|
327
|
-
|
|
378
|
+
validateSearch: route.validateSearch,
|
|
379
|
+
loaderDeps: route.loaderDeps,
|
|
328
380
|
staticData: createRouteStaticData({
|
|
329
381
|
modernRouteId: modernId,
|
|
330
382
|
modernRouteAction: modernAction,
|
|
@@ -346,6 +398,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
346
398
|
base.path = isIndexRoute ? '/' : toTanstackPath(rawPath || '');
|
|
347
399
|
}
|
|
348
400
|
const tanstackRoute = createTanstackRoute(base);
|
|
401
|
+
wrapRouteComponentWithModernContext(tanstackRoute, component, modernId);
|
|
349
402
|
const children = route.children;
|
|
350
403
|
if (children && children.length > 0) {
|
|
351
404
|
const childRoutes = children.map((child)=>createRouteFromModernRoute({
|
|
@@ -359,7 +412,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
359
412
|
}
|
|
360
413
|
function createRouteTreeFromModernRoutes(routes, options = {}) {
|
|
361
414
|
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
362
|
-
const rootComponent = rootModern
|
|
415
|
+
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
363
416
|
const pendingComponent = rootModern?.loading;
|
|
364
417
|
const errorComponent = rootModern?.error;
|
|
365
418
|
const rootLoader = rootModern?.loader;
|
|
@@ -372,7 +425,8 @@ function createRouteTreeFromModernRoutes(routes, options = {}) {
|
|
|
372
425
|
component: rootComponent || void 0,
|
|
373
426
|
pendingComponent: pendingComponent || void 0,
|
|
374
427
|
errorComponent: errorComponent || void 0,
|
|
375
|
-
|
|
428
|
+
validateSearch: rootModern?.validateSearch,
|
|
429
|
+
loaderDeps: rootModern?.loaderDeps,
|
|
376
430
|
notFoundComponent: DefaultNotFound,
|
|
377
431
|
staticData: createRouteStaticData({
|
|
378
432
|
modernRouteId: rootModernId,
|
|
@@ -390,6 +444,7 @@ function createRouteTreeFromModernRoutes(routes, options = {}) {
|
|
|
390
444
|
if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
|
|
391
445
|
if (rootModern?.inValidSSRRoute) rootRouteOptions.ssr = false;
|
|
392
446
|
const rootRoute = createTanstackRootRoute(rootRouteOptions);
|
|
447
|
+
if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
|
|
393
448
|
const topLevel = rootModern ? rootModern.children || [] : routes;
|
|
394
449
|
const childRoutes = topLevel.map((child)=>createRouteFromModernRoute({
|
|
395
450
|
options,
|
|
@@ -407,11 +462,13 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
|
|
|
407
462
|
const rootRevalidationState = {};
|
|
408
463
|
const rootShouldRevalidate = rootLikeRoute?.shouldRevalidate;
|
|
409
464
|
const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
|
|
465
|
+
const rootComponent = rootLikeRoute ? toRouteComponent(rootLikeRoute) : void 0;
|
|
410
466
|
const rootRouteOptions = {
|
|
411
|
-
component:
|
|
467
|
+
component: rootComponent,
|
|
412
468
|
pendingComponent: rootLikeRoute ? toPendingComponent(rootLikeRoute) : void 0,
|
|
413
469
|
errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
|
|
414
|
-
|
|
470
|
+
validateSearch: rootLikeRoute?.validateSearch,
|
|
471
|
+
loaderDeps: rootLikeRoute?.loaderDeps,
|
|
415
472
|
notFoundComponent: DefaultNotFound,
|
|
416
473
|
staticData: createRouteStaticData({
|
|
417
474
|
modernRouteId: rootLikeRoute?.id,
|
|
@@ -429,6 +486,7 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
|
|
|
429
486
|
if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
|
|
430
487
|
if (rootLikeRoute?.inValidSSRRoute) rootRouteOptions.ssr = false;
|
|
431
488
|
const rootRoute = createTanstackRootRoute(rootRouteOptions);
|
|
489
|
+
if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
|
|
432
490
|
const topLevel = rootLikeRoute ? [
|
|
433
491
|
...rootLikeRoute.children || [],
|
|
434
492
|
...routes.filter((route)=>route !== rootLikeRoute)
|
|
@@ -443,9 +501,11 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
|
|
|
443
501
|
}
|
|
444
502
|
function getModernRouteIdsFromMatches(router) {
|
|
445
503
|
const matches = router.state.matches || [];
|
|
504
|
+
const routesById = router.routesById;
|
|
446
505
|
const ids = matches.map((match)=>{
|
|
447
|
-
const
|
|
448
|
-
|
|
506
|
+
const normalizedMatch = match;
|
|
507
|
+
const routeId = 'string' == typeof normalizedMatch.routeId ? normalizedMatch.routeId : void 0;
|
|
508
|
+
return normalizedMatch.route?.options?.staticData?.modernRouteId ?? (routeId ? routesById?.[routeId]?.options?.staticData?.modernRouteId : void 0);
|
|
449
509
|
}).filter((id)=>'string' == typeof id);
|
|
450
510
|
return Array.from(new Set(ids));
|
|
451
511
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const modernTanstackRouterFastDefaults = {
|
|
2
|
+
defaultStructuralSharing: true
|
|
3
|
+
};
|
|
4
|
+
const getModernTanstackRouterFastDefaults = (config = {})=>({
|
|
5
|
+
defaultStructuralSharing: config.defaultStructuralSharing ?? modernTanstackRouterFastDefaults.defaultStructuralSharing
|
|
6
|
+
});
|
|
7
|
+
export { getModernTanstackRouterFastDefaults, modernTanstackRouterFastDefaults };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import node_path from "node:path";
|
|
3
3
|
import { NESTED_ROUTE_SPEC_FILE, filterRoutesForServer, fs } from "@modern-js/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { createTanstackRsbuildRouteSplittingProfile, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled } from "./routeSplitting.mjs";
|
|
5
|
+
import { collectCanonicalRoutesForEntry, generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled } from "./tanstackTypes.mjs";
|
|
5
6
|
import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
6
7
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
7
8
|
import { dirname as __rspack_dirname } from "node:path";
|
|
@@ -35,6 +36,14 @@ async function writeFileIfChanged(filePath, content) {
|
|
|
35
36
|
function createRegisterDtsContent(opts) {
|
|
36
37
|
const importStatements = opts.entries.map((entryName, index)=>`import type { router as router${index} } from './${entryName}/router.gen';`).join('\n');
|
|
37
38
|
const routerUnionType = opts.entries.map((_, index)=>`typeof router${index}`).join(' | ');
|
|
39
|
+
const canonicalEntries = Object.entries(opts.canonicalRoutes ?? {});
|
|
40
|
+
const canonicalRoutesAugmentation = canonicalEntries.length > 0 ? `
|
|
41
|
+
declare module '${opts.i18nRuntimeModule || '@modern-js/plugin-i18n/runtime'}' {
|
|
42
|
+
interface UltramodernCanonicalRoutes {
|
|
43
|
+
${canonicalEntries.map(([routePath, paramsType])=>` '${routePath}': ${paramsType};`).join('\n')}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
` : '';
|
|
38
47
|
return `// This file is auto-generated by Modern.js. Do not edit manually.
|
|
39
48
|
|
|
40
49
|
${importStatements}
|
|
@@ -44,15 +53,17 @@ declare module '${opts.runtimeModule}' {
|
|
|
44
53
|
router: ${routerUnionType};
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
|
-
`;
|
|
56
|
+
${canonicalRoutesAugmentation}`;
|
|
48
57
|
}
|
|
49
58
|
async function writeTanstackRegisterFile(opts) {
|
|
50
|
-
const { entries, generatedDirName = DEFAULT_GENERATED_DIR_NAME, runtimeModule = '@modern-js/plugin-tanstack/runtime', srcDirectory } = opts;
|
|
59
|
+
const { entries, generatedDirName = DEFAULT_GENERATED_DIR_NAME, runtimeModule = '@modern-js/plugin-tanstack/runtime', srcDirectory, canonicalRoutes, i18nRuntimeModule } = opts;
|
|
51
60
|
if (0 === entries.length) return;
|
|
52
61
|
const registerDtsPath = node_path.join(srcDirectory, generatedDirName, 'register.gen.d.ts');
|
|
53
62
|
await writeFileIfChanged(registerDtsPath, createRegisterDtsContent({
|
|
54
63
|
entries,
|
|
55
|
-
runtimeModule
|
|
64
|
+
runtimeModule,
|
|
65
|
+
canonicalRoutes,
|
|
66
|
+
i18nRuntimeModule
|
|
56
67
|
}));
|
|
57
68
|
}
|
|
58
69
|
async function writeTanstackRouterTypesForEntries(opts) {
|
|
@@ -73,15 +84,25 @@ async function writeTanstackRouterTypesForEntries(opts) {
|
|
|
73
84
|
if (mainEntryName && b === mainEntryName) return 1;
|
|
74
85
|
return a.localeCompare(b);
|
|
75
86
|
});
|
|
87
|
+
let canonicalRoutes = null;
|
|
88
|
+
for (const entryName of registerEntries){
|
|
89
|
+
const entryCanonicalRoutes = collectCanonicalRoutesForEntry(routesByEntry[entryName]);
|
|
90
|
+
if (entryCanonicalRoutes) canonicalRoutes = {
|
|
91
|
+
...entryCanonicalRoutes,
|
|
92
|
+
...canonicalRoutes ?? {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
76
95
|
await writeTanstackRegisterFile({
|
|
77
96
|
entries: registerEntries,
|
|
78
97
|
generatedDirName,
|
|
79
|
-
srcDirectory: appContext.srcDirectory
|
|
98
|
+
srcDirectory: appContext.srcDirectory,
|
|
99
|
+
canonicalRoutes
|
|
80
100
|
});
|
|
81
101
|
}
|
|
82
102
|
function tanstackRouterPlugin(options = {}) {
|
|
83
103
|
const routesDir = options.routesDir || DEFAULT_ROUTES_DIR;
|
|
84
104
|
const generatedDirName = options.generatedDirName || DEFAULT_GENERATED_DIR_NAME;
|
|
105
|
+
const routeSplittingProfile = createTanstackRsbuildRouteSplittingProfile(options);
|
|
85
106
|
return {
|
|
86
107
|
name: '@modern-js/plugin-tanstack',
|
|
87
108
|
required: [
|
|
@@ -117,6 +138,7 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
117
138
|
entry: entry || getRuntimeRouterCli().isRouteEntry(entryPath, routesDir)
|
|
118
139
|
}));
|
|
119
140
|
api.config(()=>({
|
|
141
|
+
...routeSplittingProfile.defaultConfig,
|
|
120
142
|
source: {
|
|
121
143
|
include: [
|
|
122
144
|
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
@@ -199,4 +221,4 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
199
221
|
}
|
|
200
222
|
const src_cli = tanstackRouterPlugin;
|
|
201
223
|
export default src_cli;
|
|
202
|
-
export { generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled, tanstackRouterPlugin, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
|
|
224
|
+
export { collectCanonicalRoutesForEntry, createTanstackRsbuildRouteSplittingProfile, generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled, tanstackRouterPlugin, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const TANSTACK_START_ROUTE_FACTORY_CALLS = [
|
|
3
|
+
'createFileRoute',
|
|
4
|
+
'createRootRoute',
|
|
5
|
+
'createRootRouteWithContext'
|
|
6
|
+
];
|
|
7
|
+
const TANSTACK_START_ROUTE_FACTORY_REGEX = /\b(createFileRoute|createRootRoute|createRootRouteWithContext)\s*(?:<|\()/;
|
|
8
|
+
function isTanstackStartRouteModuleSource(source) {
|
|
9
|
+
return TANSTACK_START_ROUTE_FACTORY_REGEX.test(source);
|
|
10
|
+
}
|
|
11
|
+
function resolveTanstackRouteCodeSplittingEnabled(option) {
|
|
12
|
+
if ('boolean' == typeof option) return option;
|
|
13
|
+
return option?.enabled ?? true;
|
|
14
|
+
}
|
|
15
|
+
function createTanstackRsbuildRouteSplittingProfile(opts) {
|
|
16
|
+
return {
|
|
17
|
+
defaultConfig: {
|
|
18
|
+
output: {
|
|
19
|
+
splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
modernRouteChunks: {
|
|
23
|
+
enabled: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting),
|
|
24
|
+
owner: 'modern'
|
|
25
|
+
},
|
|
26
|
+
builderChunkSplit: {
|
|
27
|
+
owner: 'modern-rsbuild',
|
|
28
|
+
preserved: true
|
|
29
|
+
},
|
|
30
|
+
tanstackStartRspackSplitter: {
|
|
31
|
+
compatible: false,
|
|
32
|
+
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.',
|
|
33
|
+
clientDeleteNodes: [
|
|
34
|
+
'ssr',
|
|
35
|
+
'server',
|
|
36
|
+
'headers'
|
|
37
|
+
],
|
|
38
|
+
routeFactoryCalls: [
|
|
39
|
+
...TANSTACK_START_ROUTE_FACTORY_CALLS
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export { createTanstackRsbuildRouteSplittingProfile, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled };
|