@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.
Files changed (94) hide show
  1. package/dist/cjs/cli/index.js +47 -27
  2. package/dist/cjs/cli/routeSplitting.js +0 -32
  3. package/dist/cjs/cli/tanstackTypes.js +34 -199
  4. package/dist/cjs/runtime/hooks.js +11 -14
  5. package/dist/cjs/runtime/index.js +107 -319
  6. package/dist/cjs/runtime/lifecycle.js +12 -86
  7. package/dist/cjs/runtime/loaderBridge.js +173 -0
  8. package/dist/cjs/runtime/plugin.js +6 -30
  9. package/dist/cjs/runtime/plugin.node.js +7 -29
  10. package/dist/cjs/runtime/pluginCore.js +55 -0
  11. package/dist/cjs/runtime/register.js +56 -0
  12. package/dist/cjs/runtime/routeTree.js +10 -207
  13. package/dist/cjs/runtime/{DefaultNotFound.js → router.js} +5 -15
  14. package/dist/cjs/runtime/rsc/payloadRouter.js +35 -1
  15. package/dist/cjs/runtime/state.js +45 -0
  16. package/dist/cjs/runtime/utils.js +0 -5
  17. package/dist/esm/cli/index.mjs +52 -26
  18. package/dist/esm/cli/routeSplitting.mjs +1 -30
  19. package/dist/esm/cli/tanstackTypes.mjs +32 -194
  20. package/dist/esm/runtime/hooks.mjs +1 -8
  21. package/dist/esm/runtime/index.mjs +4 -2
  22. package/dist/esm/runtime/lifecycle.mjs +1 -82
  23. package/dist/esm/runtime/loaderBridge.mjs +114 -0
  24. package/dist/esm/runtime/plugin.mjs +8 -32
  25. package/dist/esm/runtime/plugin.node.mjs +10 -32
  26. package/dist/esm/runtime/pluginCore.mjs +14 -0
  27. package/dist/esm/runtime/register.mjs +18 -0
  28. package/dist/esm/runtime/routeTree.mjs +4 -198
  29. package/dist/esm/runtime/router.mjs +2 -0
  30. package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
  31. package/dist/esm/runtime/state.mjs +7 -0
  32. package/dist/esm/runtime/utils.mjs +0 -5
  33. package/dist/esm-node/cli/index.mjs +52 -26
  34. package/dist/esm-node/cli/routeSplitting.mjs +1 -30
  35. package/dist/esm-node/cli/tanstackTypes.mjs +32 -194
  36. package/dist/esm-node/runtime/hooks.mjs +1 -8
  37. package/dist/esm-node/runtime/index.mjs +4 -2
  38. package/dist/esm-node/runtime/lifecycle.mjs +1 -82
  39. package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
  40. package/dist/esm-node/runtime/plugin.mjs +8 -32
  41. package/dist/esm-node/runtime/plugin.node.mjs +10 -32
  42. package/dist/esm-node/runtime/pluginCore.mjs +15 -0
  43. package/dist/esm-node/runtime/register.mjs +19 -0
  44. package/dist/esm-node/runtime/routeTree.mjs +4 -198
  45. package/dist/esm-node/runtime/router.mjs +3 -0
  46. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
  47. package/dist/esm-node/runtime/state.mjs +8 -0
  48. package/dist/esm-node/runtime/utils.mjs +0 -5
  49. package/dist/types/cli/index.d.ts +9 -2
  50. package/dist/types/cli/routeSplitting.d.ts +6 -15
  51. package/dist/types/cli/tanstackTypes.d.ts +13 -2
  52. package/dist/types/runtime/hooks.d.ts +8 -18
  53. package/dist/types/runtime/index.d.ts +6 -4
  54. package/dist/types/runtime/lifecycle.d.ts +7 -22
  55. package/dist/types/runtime/loaderBridge.d.ts +48 -0
  56. package/dist/types/runtime/plugin.d.ts +1 -14
  57. package/dist/types/runtime/plugin.node.d.ts +1 -14
  58. package/dist/types/runtime/pluginCore.d.ts +21 -0
  59. package/dist/types/runtime/register.d.ts +9 -0
  60. package/dist/types/runtime/routeTree.d.ts +0 -2
  61. package/dist/types/runtime/router.d.ts +14 -0
  62. package/dist/types/runtime/state.d.ts +16 -0
  63. package/dist/types/runtime/types.d.ts +7 -53
  64. package/package.json +30 -28
  65. package/rstest.config.mts +6 -0
  66. package/src/cli/index.ts +111 -29
  67. package/src/cli/routeSplitting.ts +6 -44
  68. package/src/cli/tanstackTypes.ts +78 -214
  69. package/src/runtime/hooks.ts +10 -27
  70. package/src/runtime/index.tsx +12 -107
  71. package/src/runtime/lifecycle.ts +16 -151
  72. package/src/runtime/loaderBridge.ts +257 -0
  73. package/src/runtime/plugin.node.tsx +14 -77
  74. package/src/runtime/plugin.tsx +12 -72
  75. package/src/runtime/pluginCore.ts +48 -0
  76. package/src/runtime/register.ts +58 -0
  77. package/src/runtime/routeTree.ts +8 -370
  78. package/src/runtime/router.ts +15 -0
  79. package/src/runtime/rsc/payloadRouter.ts +45 -2
  80. package/src/runtime/state.ts +29 -0
  81. package/src/runtime/types.ts +20 -67
  82. package/src/runtime/utils.tsx +3 -6
  83. package/tests/router/cli.test.ts +297 -31
  84. package/tests/router/hooks.test.ts +26 -0
  85. package/tests/router/loaderBridge.test.ts +211 -0
  86. package/tests/router/packageSurface.test.ts +24 -0
  87. package/tests/router/register.test.ts +46 -0
  88. package/tests/router/routeTree.test.ts +65 -180
  89. package/tests/router/rsc.test.tsx +70 -0
  90. package/tests/router/tanstackTypes.test.ts +164 -6
  91. package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
  92. package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
  93. package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
  94. package/src/runtime/DefaultNotFound.tsx +0 -15
@@ -0,0 +1,14 @@
1
+ import { getGlobalLayoutApp, getGlobalRoutes } from "@modern-js/runtime/context";
2
+ import { merge } from "@modern-js/runtime-utils/merge";
3
+ function getMergedRouterConfig(api, userConfig) {
4
+ const pluginConfig = api.getRuntimeConfig();
5
+ return merge(pluginConfig.router || {}, userConfig);
6
+ }
7
+ function getFinalRouteConfig(mergedConfig) {
8
+ return {
9
+ routes: getGlobalRoutes(),
10
+ globalApp: getGlobalLayoutApp(),
11
+ ...mergedConfig.routesConfig
12
+ };
13
+ }
14
+ export { getFinalRouteConfig, getMergedRouterConfig };
@@ -0,0 +1,18 @@
1
+ import { registerRouterProvider } from "@modern-js/runtime/context";
2
+ import { Form, RouteActionResponseError, useFetcher } from "./dataMutation.mjs";
3
+ import { Outlet } from "./outlet.mjs";
4
+ import { tanstackRouterPlugin } from "./plugin.mjs";
5
+ import { Link, NavLink } from "./prefetchLink.mjs";
6
+ const tanstackRouterProviderFactory = (userConfig)=>tanstackRouterPlugin(userConfig);
7
+ registerRouterProvider('tanstack', tanstackRouterProviderFactory);
8
+ const COMPAT_BINDINGS_SLOT = Symbol.for('@modern-js/plugin-tanstack:runtime-compat-bindings');
9
+ const tanstackRouterCompatBindings = {
10
+ Form: Form,
11
+ Link: Link,
12
+ NavLink: NavLink,
13
+ Outlet: Outlet,
14
+ RouteActionResponseError: RouteActionResponseError,
15
+ useFetcher: useFetcher
16
+ };
17
+ globalThis[COMPAT_BINDINGS_SLOT] ??= tanstackRouterCompatBindings;
18
+ export { tanstackRouterCompatBindings };
@@ -1,6 +1,7 @@
1
- import { createRootRoute, createRoute, notFound, redirect, rootRouteId } from "@tanstack/react-router";
1
+ import { DefaultNotFound } from "@modern-js/runtime/context";
2
+ import { createRootRoute, createRoute, notFound, rootRouteId } from "@tanstack/react-router";
2
3
  import { createElement } from "react";
3
- import { DefaultNotFound } from "./DefaultNotFound.mjs";
4
+ import { isRedirectResponse, isResponse, isTanstackRedirect, throwTanstackRedirect } from "./loaderBridge.mjs";
4
5
  import { withModernRouteMatchContext } from "./outlet.mjs";
5
6
  import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "./rsc/payloadRouter.mjs";
6
7
  function createTanstackRoute(options) {
@@ -25,23 +26,6 @@ function toTanstackPath(pathname) {
25
26
  return segment;
26
27
  }).join('/');
27
28
  }
28
- function isResponse(value) {
29
- const record = value;
30
- return null != record && 'object' == typeof record && 'number' == typeof record.status && 'object' == typeof record.headers;
31
- }
32
- function isTanstackRedirect(value) {
33
- return isResponse(value) && 'object' == typeof value.options;
34
- }
35
- const redirectStatusCodes = new Set([
36
- 301,
37
- 302,
38
- 303,
39
- 307,
40
- 308
41
- ]);
42
- function isRedirectResponse(res) {
43
- return redirectStatusCodes.has(res.status);
44
- }
45
29
  function isModernDeferredData(value) {
46
30
  if (!value || 'object' != typeof value) return false;
47
31
  const deferred = value;
@@ -94,34 +78,6 @@ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
94
78
  Component.preload = load;
95
79
  return Component;
96
80
  }
97
- function isAbsoluteUrl(value) {
98
- try {
99
- new URL(value);
100
- return true;
101
- } catch {
102
- return false;
103
- }
104
- }
105
- function throwTanstackRedirect(location) {
106
- const target = location || '/';
107
- if (isAbsoluteUrl(target)) throw redirect({
108
- href: target
109
- });
110
- throw redirect({
111
- to: target
112
- });
113
- }
114
- function mapParamsForModernLoader({ modernRoute, params }) {
115
- if ('nested' === modernRoute.type && modernRoute.path?.includes('*')) {
116
- const { _splat, ...rest } = params;
117
- if (void 0 !== _splat) return {
118
- ...rest,
119
- '*': _splat
120
- };
121
- return rest;
122
- }
123
- return params;
124
- }
125
81
  function createModernRequest(input, signal) {
126
82
  return new Request(input, {
127
83
  signal
@@ -155,52 +111,6 @@ function createModernShouldReload(shouldRevalidate, state) {
155
111
  return 'boolean' == typeof result ? result : void 0;
156
112
  };
157
113
  }
158
- function wrapModernLoader(modernRoute, modernLoader, revalidationState, options = {}) {
159
- const route = modernRoute;
160
- return async (ctx)=>{
161
- try {
162
- if (revalidationState) rememberRouteLocation(revalidationState, ctx);
163
- if ('function' == typeof route.lazyImport) try {
164
- await route.lazyImport();
165
- } catch {}
166
- const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
167
- const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
168
- const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
169
- const request = void 0 !== baseRequest ? new Request(baseRequest, {
170
- signal
171
- }) : createModernRequest(href, signal);
172
- const params = mapParamsForModernLoader({
173
- modernRoute,
174
- params: ctx.params || {}
175
- });
176
- const loadModernData = async ()=>{
177
- const result = modernLoader ? await modernLoader({
178
- request,
179
- params,
180
- context: ctx?.context?.requestContext
181
- }) : null;
182
- return normalizeModernLoaderResponse(result);
183
- };
184
- if (options.rscPayloadRouter && isTanstackRscPayloadNavigationEnabled()) return loadTanstackRscRouteData({
185
- hasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
186
- loadClientData: loadModernData,
187
- request,
188
- routeId: ctx.route?.id
189
- });
190
- return loadModernData();
191
- } catch (err) {
192
- if (isResponse(err)) {
193
- if (isTanstackRedirect(err)) throw err;
194
- if (isRedirectResponse(err)) {
195
- const location = err.headers.get('Location') || '/';
196
- throwTanstackRedirect(location);
197
- }
198
- if (404 === err.status) throw notFound();
199
- }
200
- throw err;
201
- }
202
- };
203
- }
204
114
  function isRouteObjectPathlessLayout(route) {
205
115
  return !route.path && !route.index;
206
116
  }
@@ -275,11 +185,6 @@ function toRouteComponent(routeObject) {
275
185
  const element = route.element;
276
186
  if (element) return ()=>element;
277
187
  }
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
- }
283
188
  function toErrorComponent(routeObject) {
284
189
  const route = routeObject;
285
190
  if (route.ErrorBoundary) return route.ErrorBoundary;
@@ -355,105 +260,6 @@ function createRouteFromRouteObject(opts) {
355
260
  }
356
261
  return route;
357
262
  }
358
- function createRouteFromModernRoute(opts) {
359
- const { options = {}, parent, modernRoute } = opts;
360
- const route = modernRoute;
361
- const revalidationState = {};
362
- const modernId = route.id;
363
- const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
364
- const pendingComponent = route.loading || route.pendingComponent;
365
- const errorComponent = route.error || route.errorComponent;
366
- const component = toModernRouteComponent(route);
367
- const modernLoader = route.loader;
368
- const modernAction = route.action;
369
- const modernShouldRevalidate = route.shouldRevalidate;
370
- const shouldReload = createModernShouldReload(modernShouldRevalidate, revalidationState);
371
- const isPathlessLayout = 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
372
- const isIndexRoute = 'nested' === route.type && Boolean(route.index);
373
- const base = {
374
- getParentRoute: ()=>parent,
375
- component: component || void 0,
376
- pendingComponent: pendingComponent || void 0,
377
- errorComponent: errorComponent || void 0,
378
- validateSearch: route.validateSearch,
379
- loaderDeps: route.loaderDeps,
380
- staticData: createRouteStaticData({
381
- modernRouteId: modernId,
382
- modernRouteAction: modernAction,
383
- modernRouteHandle: mergeModernRouteHandle(route),
384
- modernRouteHasAction: route.hasAction || Boolean(modernAction),
385
- modernRouteHasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
386
- modernRouteHasLoader: route.hasLoader || 'function' == typeof modernLoader,
387
- modernRouteIsClientComponent: route.isClientComponent,
388
- modernRouteLoader: modernLoader,
389
- modernRouteShouldRevalidate: modernShouldRevalidate
390
- }),
391
- loader: wrapModernLoader(modernRoute, modernLoader, revalidationState, options)
392
- };
393
- if (route.inValidSSRRoute) base.ssr = false;
394
- if (shouldReload) base.shouldReload = shouldReload;
395
- if (isPathlessLayout) base.id = stableFallbackId || 'pathless';
396
- else {
397
- const rawPath = route.path;
398
- base.path = isIndexRoute ? '/' : toTanstackPath(rawPath || '');
399
- }
400
- const tanstackRoute = createTanstackRoute(base);
401
- wrapRouteComponentWithModernContext(tanstackRoute, component, modernId);
402
- const children = route.children;
403
- if (children && children.length > 0) {
404
- const childRoutes = children.map((child)=>createRouteFromModernRoute({
405
- options,
406
- parent: tanstackRoute,
407
- modernRoute: child
408
- }));
409
- tanstackRoute.addChildren(childRoutes);
410
- }
411
- return tanstackRoute;
412
- }
413
- function createRouteTreeFromModernRoutes(routes, options = {}) {
414
- const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
415
- const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
416
- const pendingComponent = rootModern?.loading;
417
- const errorComponent = rootModern?.error;
418
- const rootLoader = rootModern?.loader;
419
- const rootAction = rootModern?.action;
420
- const rootModernId = rootModern?.id;
421
- const rootShouldRevalidate = rootModern?.shouldRevalidate;
422
- const rootRevalidationState = {};
423
- const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
424
- const rootRouteOptions = {
425
- component: rootComponent || void 0,
426
- pendingComponent: pendingComponent || void 0,
427
- errorComponent: errorComponent || void 0,
428
- validateSearch: rootModern?.validateSearch,
429
- loaderDeps: rootModern?.loaderDeps,
430
- notFoundComponent: DefaultNotFound,
431
- staticData: createRouteStaticData({
432
- modernRouteId: rootModernId,
433
- modernRouteAction: rootAction,
434
- modernRouteHandle: rootModern ? mergeModernRouteHandle(rootModern) : void 0,
435
- modernRouteHasAction: rootModern?.hasAction || Boolean(rootAction),
436
- modernRouteHasClientLoader: rootModern?.hasClientLoader || void 0 !== rootModern?.clientData,
437
- modernRouteHasLoader: rootModern?.hasLoader || 'function' == typeof rootLoader,
438
- modernRouteIsClientComponent: rootModern?.isClientComponent,
439
- modernRouteLoader: rootLoader,
440
- modernRouteShouldRevalidate: rootShouldRevalidate
441
- }),
442
- loader: rootModern ? wrapModernLoader(rootModern, rootLoader, rootRevalidationState, options) : void 0
443
- };
444
- if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
445
- if (rootModern?.inValidSSRRoute) rootRouteOptions.ssr = false;
446
- const rootRoute = createTanstackRootRoute(rootRouteOptions);
447
- if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
448
- const topLevel = rootModern ? rootModern.children || [] : routes;
449
- const childRoutes = topLevel.map((child)=>createRouteFromModernRoute({
450
- options,
451
- parent: rootRoute,
452
- modernRoute: child
453
- }));
454
- rootRoute.addChildren(childRoutes);
455
- return rootRoute;
456
- }
457
263
  function getRootLikeRouteObject(routes) {
458
264
  return routes.find((route)=>'/' === route.path && !route.index);
459
265
  }
@@ -509,4 +315,4 @@ function getModernRouteIdsFromMatches(router) {
509
315
  }).filter((id)=>'string' == typeof id);
510
316
  return Array.from(new Set(ids));
511
317
  }
512
- export { createRouteTreeFromModernRoutes, createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches };
318
+ export { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches };
@@ -0,0 +1,2 @@
1
+ import "./register.mjs";
2
+ export { routerPlugin } from "@modern-js/runtime/router/internal";
@@ -1,3 +1,4 @@
1
+ import { isRouteErrorResponse } from "@modern-js/runtime-utils/router";
1
2
  import { notFound, redirect } from "@tanstack/react-router";
2
3
  const payloadFetchCache = new Map();
3
4
  let payloadDecoder;
@@ -37,6 +38,39 @@ function toPayloadRoute(match) {
37
38
  pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
38
39
  };
39
40
  }
41
+ function shouldRedactServerError(status = 500) {
42
+ return status >= 500 && 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
43
+ }
44
+ function serializePayloadError(error) {
45
+ if (isRouteErrorResponse(error)) {
46
+ if (shouldRedactServerError(error.status)) return {
47
+ status: error.status,
48
+ statusText: 'Internal Server Error',
49
+ data: 'Unexpected Server Error',
50
+ __type: 'RouteErrorResponse'
51
+ };
52
+ return {
53
+ ...error,
54
+ __type: 'RouteErrorResponse'
55
+ };
56
+ }
57
+ if (error instanceof Error) {
58
+ if (shouldRedactServerError()) return {
59
+ message: 'Unexpected Server Error',
60
+ stack: void 0,
61
+ __type: 'Error'
62
+ };
63
+ return {
64
+ message: error.message,
65
+ stack: error.stack,
66
+ __type: 'Error',
67
+ ...'Error' !== error.name ? {
68
+ __subType: error.name
69
+ } : {}
70
+ };
71
+ }
72
+ return error;
73
+ }
40
74
  function createTanstackRscServerPayload(router, options = {}) {
41
75
  const matches = Array.isArray(router.state?.matches) ? router.state.matches : [];
42
76
  const routes = [];
@@ -47,7 +81,7 @@ function createTanstackRscServerPayload(router, options = {}) {
47
81
  if (payloadRoute) {
48
82
  routes.push(payloadRoute);
49
83
  if ('loaderData' in match && void 0 !== match.loaderData && !(options.omitClientLoaderData && payloadRoute.hasClientLoader)) loaderData[payloadRoute.id] = match.loaderData;
50
- if (void 0 !== match.error) errors[payloadRoute.id] = match.error;
84
+ if (void 0 !== match.error) errors[payloadRoute.id] = serializePayloadError(match.error);
51
85
  }
52
86
  }
53
87
  return {
@@ -0,0 +1,7 @@
1
+ import { getRouterRuntimeState } from "@modern-js/runtime/context";
2
+ function getTanstackRouterState(context) {
3
+ const state = getRouterRuntimeState(context);
4
+ if (void 0 === state || 'tanstack' !== state.framework) return;
5
+ return state;
6
+ }
7
+ export { getTanstackRouterState };
@@ -1,6 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import react from "react";
3
- import { DefaultNotFound } from "./DefaultNotFound.mjs";
4
3
  function getRouteObjects(routes, { globalApp, ssrMode, props }) {
5
4
  const createLayoutElement = (Component)=>{
6
5
  const GlobalLayout = globalApp;
@@ -57,10 +56,6 @@ function getRouteObjects(routes, { globalApp, ssrMode, props }) {
57
56
  };
58
57
  routeObjects.push(routeObject);
59
58
  }
60
- routeObjects.push({
61
- path: '*',
62
- element: /*#__PURE__*/ jsx(DefaultNotFound, {})
63
- });
64
59
  return routeObjects;
65
60
  }
66
61
  function createRouteObjectsFromConfig({ routesConfig, props, ssrMode }) {
@@ -1,14 +1,14 @@
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 { createTanstackRsbuildRouteSplittingProfile, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled } from "./routeSplitting.mjs";
5
- import { collectCanonicalRoutesForEntry, generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled } from "./tanstackTypes.mjs";
4
+ import { createTanstackRsbuildRouteSplittingProfile, resolveTanstackRouteCodeSplittingEnabled } from "./routeSplitting.mjs";
5
+ import { collectCanonicalRoutesForEntry, generateTanstackRouterTypesSourceForEntry } from "./tanstackTypes.mjs";
6
6
  import { __webpack_require__ } from "../rslib-runtime.mjs";
7
7
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
8
8
  import { dirname as __rspack_dirname } from "node:path";
9
9
  import * as __rspack_external__modern_js_runtime_cli_401ee077 from "@modern-js/runtime/cli";
10
10
  __webpack_require__.add({
11
- "@modern-js/runtime/cli" (module) {
11
+ "@modern-js/runtime/cli?9b14" (module) {
12
12
  module.exports = __rspack_external__modern_js_runtime_cli_401ee077;
13
13
  }
14
14
  });
@@ -19,8 +19,8 @@ const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
19
19
  let runtimeRouterCli;
20
20
  function getRuntimeRouterCli() {
21
21
  if (runtimeRouterCli) return runtimeRouterCli;
22
- const cli = __webpack_require__("@modern-js/runtime/cli");
23
- if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir) {
22
+ const cli = __webpack_require__("@modern-js/runtime/cli?9b14");
23
+ if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir && cli.getEntrypointRoutesOwner) {
24
24
  runtimeRouterCli = cli;
25
25
  return runtimeRouterCli;
26
26
  }
@@ -67,7 +67,7 @@ async function writeTanstackRegisterFile(opts) {
67
67
  }));
68
68
  }
69
69
  async function writeTanstackRouterTypesForEntries(opts) {
70
- const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry } = opts;
70
+ const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry, i18nPluginInstalled = false } = opts;
71
71
  const entryNames = Object.keys(routesByEntry);
72
72
  await Promise.all(entryNames.map(async (entryName)=>{
73
73
  const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
@@ -85,8 +85,10 @@ async function writeTanstackRouterTypesForEntries(opts) {
85
85
  return a.localeCompare(b);
86
86
  });
87
87
  let canonicalRoutes = null;
88
- for (const entryName of registerEntries){
89
- const entryCanonicalRoutes = collectCanonicalRoutesForEntry(routesByEntry[entryName]);
88
+ if (i18nPluginInstalled) for (const entryName of registerEntries){
89
+ const entryCanonicalRoutes = collectCanonicalRoutesForEntry(routesByEntry[entryName], {
90
+ localeParamHeuristic: true
91
+ });
90
92
  if (entryCanonicalRoutes) canonicalRoutes = {
91
93
  ...entryCanonicalRoutes,
92
94
  ...canonicalRoutes ?? {}
@@ -114,16 +116,42 @@ function tanstackRouterPlugin(options = {}) {
114
116
  const { getEntrypointRoutesDir } = getRuntimeRouterCli();
115
117
  return getEntrypointRoutesDir(entrypoint) === routesDir;
116
118
  };
119
+ const isForeignRouteEntrypoint = (entrypoint)=>{
120
+ const { getEntrypointRoutesDir, getEntrypointRoutesOwner } = getRuntimeRouterCli();
121
+ if (getEntrypointRoutesOwner(entrypoint)) return true;
122
+ if (entrypoint.pageRoutesEntry) return true;
123
+ return null !== getEntrypointRoutesDir(entrypoint);
124
+ };
125
+ const isI18nPluginInstalled = ()=>{
126
+ const { plugins } = api.getAppContext();
127
+ return Boolean(plugins?.some((plugin)=>plugin?.name === '@modern-js/plugin-i18n'));
128
+ };
117
129
  api._internalRuntimePlugins(({ entrypoint, plugins })=>{
118
- if (!isTanstackEntrypoint(entrypoint)) return {
130
+ const { metaName, serverRoutes } = api.getAppContext();
131
+ const serverBase = serverRoutes.filter((route)=>route.entryName === entrypoint.entryName).map((route)=>route.urlPath).sort((a, b)=>a.length - b.length > 0 ? -1 : 1);
132
+ if (isTanstackEntrypoint(entrypoint)) {
133
+ plugins.push({
134
+ name: 'tanstackRouter',
135
+ path: `@${metaName}/plugin-tanstack/runtime`,
136
+ config: {
137
+ serverBase
138
+ }
139
+ });
140
+ return {
141
+ entrypoint,
142
+ plugins
143
+ };
144
+ }
145
+ if (isForeignRouteEntrypoint(entrypoint)) return {
119
146
  entrypoint,
120
147
  plugins
121
148
  };
122
- const { metaName, serverRoutes } = api.getAppContext();
123
- const serverBase = serverRoutes.filter((route)=>route.entryName === entrypoint.entryName).map((route)=>route.urlPath).sort((a, b)=>a.length - b.length > 0 ? -1 : 1);
124
- plugins.push({
125
- name: 'tanstackRouter',
126
- path: `@${metaName}/plugin-tanstack/runtime`,
149
+ const routerWrapperPath = `@${metaName}/plugin-tanstack/runtime/router`;
150
+ const existingRouterPlugin = plugins.find((plugin)=>'router' === plugin.name);
151
+ if (existingRouterPlugin) existingRouterPlugin.path = routerWrapperPath;
152
+ else plugins.push({
153
+ name: 'router',
154
+ path: routerWrapperPath,
127
155
  config: {
128
156
  serverBase
129
157
  }
@@ -142,7 +170,9 @@ function tanstackRouterPlugin(options = {}) {
142
170
  source: {
143
171
  include: [
144
172
  /[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
145
- node_path.resolve(cli_dirname, '../runtime').replace('cjs', 'esm')
173
+ /[\\/]node_modules[\\/]@tanstack[\\/]router-core[\\/]/,
174
+ /[\\/]node_modules[\\/]@tanstack[\\/]react-store[\\/]/,
175
+ node_path.resolve(cli_dirname, '..', '..')
146
176
  ]
147
177
  }
148
178
  }));
@@ -159,15 +189,13 @@ function tanstackRouterPlugin(options = {}) {
159
189
  if (0 === tanstackEntrypoints.length) return;
160
190
  const { handleGeneratorEntryCode } = getRuntimeRouterCli();
161
191
  const routesByEntry = await handleGeneratorEntryCode(api, tanstackEntrypoints, {
162
- entrypointsKey: ENTRYPOINTS_KEY,
163
- generateCodeOptions: {
164
- enableTanstackTypes: false
165
- }
192
+ entrypointsKey: ENTRYPOINTS_KEY
166
193
  });
167
194
  await writeTanstackRouterTypesForEntries({
168
195
  appContext: api.getAppContext(),
169
196
  generatedDirName,
170
- routesByEntry
197
+ routesByEntry,
198
+ i18nPluginInstalled: isI18nPluginInstalled()
171
199
  });
172
200
  });
173
201
  api.onFileChanged(async (event)=>{
@@ -181,15 +209,13 @@ function tanstackRouterPlugin(options = {}) {
181
209
  regenerate: async ({ api, entrypoints })=>{
182
210
  const { handleGeneratorEntryCode } = getRuntimeRouterCli();
183
211
  const routesByEntry = await handleGeneratorEntryCode(api, entrypoints, {
184
- entrypointsKey: ENTRYPOINTS_KEY,
185
- generateCodeOptions: {
186
- enableTanstackTypes: false
187
- }
212
+ entrypointsKey: ENTRYPOINTS_KEY
188
213
  });
189
214
  await writeTanstackRouterTypesForEntries({
190
215
  appContext: api.getAppContext(),
191
216
  generatedDirName,
192
- routesByEntry
217
+ routesByEntry,
218
+ i18nPluginInstalled: isI18nPluginInstalled()
193
219
  });
194
220
  }
195
221
  });
@@ -221,4 +247,4 @@ function tanstackRouterPlugin(options = {}) {
221
247
  }
222
248
  const src_cli = tanstackRouterPlugin;
223
249
  export default src_cli;
224
- export { collectCanonicalRoutesForEntry, createTanstackRsbuildRouteSplittingProfile, generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled, tanstackRouterPlugin, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
250
+ export { collectCanonicalRoutesForEntry, createTanstackRsbuildRouteSplittingProfile, generateTanstackRouterTypesSourceForEntry, resolveTanstackRouteCodeSplittingEnabled, tanstackRouterPlugin, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
@@ -1,13 +1,4 @@
1
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
2
  function resolveTanstackRouteCodeSplittingEnabled(option) {
12
3
  if ('boolean' == typeof option) return option;
13
4
  return option?.enabled ?? true;
@@ -18,27 +9,7 @@ function createTanstackRsbuildRouteSplittingProfile(opts) {
18
9
  output: {
19
10
  splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting)
20
11
  }
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
12
  }
42
13
  };
43
14
  }
44
- export { createTanstackRsbuildRouteSplittingProfile, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled };
15
+ export { createTanstackRsbuildRouteSplittingProfile, resolveTanstackRouteCodeSplittingEnabled };