@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
|
@@ -28,13 +28,13 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
createRouteTreeFromModernRoutes: ()=>createRouteTreeFromModernRoutes,
|
|
32
31
|
createRouteTreeFromRouteObjects: ()=>createRouteTreeFromRouteObjects,
|
|
33
32
|
getModernRouteIdsFromMatches: ()=>getModernRouteIdsFromMatches
|
|
34
33
|
});
|
|
34
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
35
35
|
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
36
36
|
const external_react_namespaceObject = require("react");
|
|
37
|
-
const
|
|
37
|
+
const external_loaderBridge_js_namespaceObject = require("./loaderBridge.js");
|
|
38
38
|
const external_outlet_js_namespaceObject = require("./outlet.js");
|
|
39
39
|
const payloadRouter_js_namespaceObject = require("./rsc/payloadRouter.js");
|
|
40
40
|
function createTanstackRoute(options) {
|
|
@@ -59,23 +59,6 @@ function toTanstackPath(pathname) {
|
|
|
59
59
|
return segment;
|
|
60
60
|
}).join('/');
|
|
61
61
|
}
|
|
62
|
-
function isResponse(value) {
|
|
63
|
-
const record = value;
|
|
64
|
-
return null != record && 'object' == typeof record && 'number' == typeof record.status && 'object' == typeof record.headers;
|
|
65
|
-
}
|
|
66
|
-
function isTanstackRedirect(value) {
|
|
67
|
-
return isResponse(value) && 'object' == typeof value.options;
|
|
68
|
-
}
|
|
69
|
-
const redirectStatusCodes = new Set([
|
|
70
|
-
301,
|
|
71
|
-
302,
|
|
72
|
-
303,
|
|
73
|
-
307,
|
|
74
|
-
308
|
|
75
|
-
]);
|
|
76
|
-
function isRedirectResponse(res) {
|
|
77
|
-
return redirectStatusCodes.has(res.status);
|
|
78
|
-
}
|
|
79
62
|
function isModernDeferredData(value) {
|
|
80
63
|
if (!value || 'object' != typeof value) return false;
|
|
81
64
|
const deferred = value;
|
|
@@ -85,10 +68,10 @@ function normalizeModernLoaderResult(result) {
|
|
|
85
68
|
return isModernDeferredData(result) ? result.data : result;
|
|
86
69
|
}
|
|
87
70
|
function normalizeModernLoaderResponse(result) {
|
|
88
|
-
if (isResponse(result)) {
|
|
89
|
-
if (isRedirectResponse(result)) {
|
|
71
|
+
if ((0, external_loaderBridge_js_namespaceObject.isResponse)(result)) {
|
|
72
|
+
if ((0, external_loaderBridge_js_namespaceObject.isRedirectResponse)(result)) {
|
|
90
73
|
const location = result.headers.get('Location') || '/';
|
|
91
|
-
throwTanstackRedirect(location);
|
|
74
|
+
(0, external_loaderBridge_js_namespaceObject.throwTanstackRedirect)(location);
|
|
92
75
|
}
|
|
93
76
|
if (404 === result.status) throw (0, react_router_namespaceObject.notFound)();
|
|
94
77
|
}
|
|
@@ -128,34 +111,6 @@ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
|
128
111
|
Component.preload = load;
|
|
129
112
|
return Component;
|
|
130
113
|
}
|
|
131
|
-
function isAbsoluteUrl(value) {
|
|
132
|
-
try {
|
|
133
|
-
new URL(value);
|
|
134
|
-
return true;
|
|
135
|
-
} catch {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function throwTanstackRedirect(location) {
|
|
140
|
-
const target = location || '/';
|
|
141
|
-
if (isAbsoluteUrl(target)) throw (0, react_router_namespaceObject.redirect)({
|
|
142
|
-
href: target
|
|
143
|
-
});
|
|
144
|
-
throw (0, react_router_namespaceObject.redirect)({
|
|
145
|
-
to: target
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function mapParamsForModernLoader({ modernRoute, params }) {
|
|
149
|
-
if ('nested' === modernRoute.type && modernRoute.path?.includes('*')) {
|
|
150
|
-
const { _splat, ...rest } = params;
|
|
151
|
-
if (void 0 !== _splat) return {
|
|
152
|
-
...rest,
|
|
153
|
-
'*': _splat
|
|
154
|
-
};
|
|
155
|
-
return rest;
|
|
156
|
-
}
|
|
157
|
-
return params;
|
|
158
|
-
}
|
|
159
114
|
function createModernRequest(input, signal) {
|
|
160
115
|
return new Request(input, {
|
|
161
116
|
signal
|
|
@@ -189,52 +144,6 @@ function createModernShouldReload(shouldRevalidate, state) {
|
|
|
189
144
|
return 'boolean' == typeof result ? result : void 0;
|
|
190
145
|
};
|
|
191
146
|
}
|
|
192
|
-
function wrapModernLoader(modernRoute, modernLoader, revalidationState, options = {}) {
|
|
193
|
-
const route = modernRoute;
|
|
194
|
-
return async (ctx)=>{
|
|
195
|
-
try {
|
|
196
|
-
if (revalidationState) rememberRouteLocation(revalidationState, ctx);
|
|
197
|
-
if ('function' == typeof route.lazyImport) try {
|
|
198
|
-
await route.lazyImport();
|
|
199
|
-
} catch {}
|
|
200
|
-
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
201
|
-
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
202
|
-
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
203
|
-
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
204
|
-
signal
|
|
205
|
-
}) : createModernRequest(href, signal);
|
|
206
|
-
const params = mapParamsForModernLoader({
|
|
207
|
-
modernRoute,
|
|
208
|
-
params: ctx.params || {}
|
|
209
|
-
});
|
|
210
|
-
const loadModernData = async ()=>{
|
|
211
|
-
const result = modernLoader ? await modernLoader({
|
|
212
|
-
request,
|
|
213
|
-
params,
|
|
214
|
-
context: ctx?.context?.requestContext
|
|
215
|
-
}) : null;
|
|
216
|
-
return normalizeModernLoaderResponse(result);
|
|
217
|
-
};
|
|
218
|
-
if (options.rscPayloadRouter && (0, payloadRouter_js_namespaceObject.isTanstackRscPayloadNavigationEnabled)()) return (0, payloadRouter_js_namespaceObject.loadTanstackRscRouteData)({
|
|
219
|
-
hasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
|
|
220
|
-
loadClientData: loadModernData,
|
|
221
|
-
request,
|
|
222
|
-
routeId: ctx.route?.id
|
|
223
|
-
});
|
|
224
|
-
return loadModernData();
|
|
225
|
-
} catch (err) {
|
|
226
|
-
if (isResponse(err)) {
|
|
227
|
-
if (isTanstackRedirect(err)) throw err;
|
|
228
|
-
if (isRedirectResponse(err)) {
|
|
229
|
-
const location = err.headers.get('Location') || '/';
|
|
230
|
-
throwTanstackRedirect(location);
|
|
231
|
-
}
|
|
232
|
-
if (404 === err.status) throw (0, react_router_namespaceObject.notFound)();
|
|
233
|
-
}
|
|
234
|
-
throw err;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
147
|
function isRouteObjectPathlessLayout(route) {
|
|
239
148
|
return !route.path && !route.index;
|
|
240
149
|
}
|
|
@@ -288,11 +197,11 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
288
197
|
});
|
|
289
198
|
return loadModernData();
|
|
290
199
|
} catch (err) {
|
|
291
|
-
if (isResponse(err)) {
|
|
292
|
-
if (isTanstackRedirect(err)) throw err;
|
|
293
|
-
if (isRedirectResponse(err)) {
|
|
200
|
+
if ((0, external_loaderBridge_js_namespaceObject.isResponse)(err)) {
|
|
201
|
+
if ((0, external_loaderBridge_js_namespaceObject.isTanstackRedirect)(err)) throw err;
|
|
202
|
+
if ((0, external_loaderBridge_js_namespaceObject.isRedirectResponse)(err)) {
|
|
294
203
|
const location = err.headers.get('Location') || '/';
|
|
295
|
-
throwTanstackRedirect(location);
|
|
204
|
+
(0, external_loaderBridge_js_namespaceObject.throwTanstackRedirect)(location);
|
|
296
205
|
}
|
|
297
206
|
if (404 === err.status) throw (0, react_router_namespaceObject.notFound)();
|
|
298
207
|
}
|
|
@@ -309,11 +218,6 @@ function toRouteComponent(routeObject) {
|
|
|
309
218
|
const element = route.element;
|
|
310
219
|
if (element) return ()=>element;
|
|
311
220
|
}
|
|
312
|
-
function toModernRouteComponent(route) {
|
|
313
|
-
const component = route.component || void 0;
|
|
314
|
-
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
315
|
-
return component;
|
|
316
|
-
}
|
|
317
221
|
function toErrorComponent(routeObject) {
|
|
318
222
|
const route = routeObject;
|
|
319
223
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -389,105 +293,6 @@ function createRouteFromRouteObject(opts) {
|
|
|
389
293
|
}
|
|
390
294
|
return route;
|
|
391
295
|
}
|
|
392
|
-
function createRouteFromModernRoute(opts) {
|
|
393
|
-
const { options = {}, parent, modernRoute } = opts;
|
|
394
|
-
const route = modernRoute;
|
|
395
|
-
const revalidationState = {};
|
|
396
|
-
const modernId = route.id;
|
|
397
|
-
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
398
|
-
const pendingComponent = route.loading || route.pendingComponent;
|
|
399
|
-
const errorComponent = route.error || route.errorComponent;
|
|
400
|
-
const component = toModernRouteComponent(route);
|
|
401
|
-
const modernLoader = route.loader;
|
|
402
|
-
const modernAction = route.action;
|
|
403
|
-
const modernShouldRevalidate = route.shouldRevalidate;
|
|
404
|
-
const shouldReload = createModernShouldReload(modernShouldRevalidate, revalidationState);
|
|
405
|
-
const isPathlessLayout = 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
|
|
406
|
-
const isIndexRoute = 'nested' === route.type && Boolean(route.index);
|
|
407
|
-
const base = {
|
|
408
|
-
getParentRoute: ()=>parent,
|
|
409
|
-
component: component || void 0,
|
|
410
|
-
pendingComponent: pendingComponent || void 0,
|
|
411
|
-
errorComponent: errorComponent || void 0,
|
|
412
|
-
validateSearch: route.validateSearch,
|
|
413
|
-
loaderDeps: route.loaderDeps,
|
|
414
|
-
staticData: createRouteStaticData({
|
|
415
|
-
modernRouteId: modernId,
|
|
416
|
-
modernRouteAction: modernAction,
|
|
417
|
-
modernRouteHandle: mergeModernRouteHandle(route),
|
|
418
|
-
modernRouteHasAction: route.hasAction || Boolean(modernAction),
|
|
419
|
-
modernRouteHasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
|
|
420
|
-
modernRouteHasLoader: route.hasLoader || 'function' == typeof modernLoader,
|
|
421
|
-
modernRouteIsClientComponent: route.isClientComponent,
|
|
422
|
-
modernRouteLoader: modernLoader,
|
|
423
|
-
modernRouteShouldRevalidate: modernShouldRevalidate
|
|
424
|
-
}),
|
|
425
|
-
loader: wrapModernLoader(modernRoute, modernLoader, revalidationState, options)
|
|
426
|
-
};
|
|
427
|
-
if (route.inValidSSRRoute) base.ssr = false;
|
|
428
|
-
if (shouldReload) base.shouldReload = shouldReload;
|
|
429
|
-
if (isPathlessLayout) base.id = stableFallbackId || 'pathless';
|
|
430
|
-
else {
|
|
431
|
-
const rawPath = route.path;
|
|
432
|
-
base.path = isIndexRoute ? '/' : toTanstackPath(rawPath || '');
|
|
433
|
-
}
|
|
434
|
-
const tanstackRoute = createTanstackRoute(base);
|
|
435
|
-
wrapRouteComponentWithModernContext(tanstackRoute, component, modernId);
|
|
436
|
-
const children = route.children;
|
|
437
|
-
if (children && children.length > 0) {
|
|
438
|
-
const childRoutes = children.map((child)=>createRouteFromModernRoute({
|
|
439
|
-
options,
|
|
440
|
-
parent: tanstackRoute,
|
|
441
|
-
modernRoute: child
|
|
442
|
-
}));
|
|
443
|
-
tanstackRoute.addChildren(childRoutes);
|
|
444
|
-
}
|
|
445
|
-
return tanstackRoute;
|
|
446
|
-
}
|
|
447
|
-
function createRouteTreeFromModernRoutes(routes, options = {}) {
|
|
448
|
-
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
449
|
-
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
450
|
-
const pendingComponent = rootModern?.loading;
|
|
451
|
-
const errorComponent = rootModern?.error;
|
|
452
|
-
const rootLoader = rootModern?.loader;
|
|
453
|
-
const rootAction = rootModern?.action;
|
|
454
|
-
const rootModernId = rootModern?.id;
|
|
455
|
-
const rootShouldRevalidate = rootModern?.shouldRevalidate;
|
|
456
|
-
const rootRevalidationState = {};
|
|
457
|
-
const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
|
|
458
|
-
const rootRouteOptions = {
|
|
459
|
-
component: rootComponent || void 0,
|
|
460
|
-
pendingComponent: pendingComponent || void 0,
|
|
461
|
-
errorComponent: errorComponent || void 0,
|
|
462
|
-
validateSearch: rootModern?.validateSearch,
|
|
463
|
-
loaderDeps: rootModern?.loaderDeps,
|
|
464
|
-
notFoundComponent: external_DefaultNotFound_js_namespaceObject.DefaultNotFound,
|
|
465
|
-
staticData: createRouteStaticData({
|
|
466
|
-
modernRouteId: rootModernId,
|
|
467
|
-
modernRouteAction: rootAction,
|
|
468
|
-
modernRouteHandle: rootModern ? mergeModernRouteHandle(rootModern) : void 0,
|
|
469
|
-
modernRouteHasAction: rootModern?.hasAction || Boolean(rootAction),
|
|
470
|
-
modernRouteHasClientLoader: rootModern?.hasClientLoader || void 0 !== rootModern?.clientData,
|
|
471
|
-
modernRouteHasLoader: rootModern?.hasLoader || 'function' == typeof rootLoader,
|
|
472
|
-
modernRouteIsClientComponent: rootModern?.isClientComponent,
|
|
473
|
-
modernRouteLoader: rootLoader,
|
|
474
|
-
modernRouteShouldRevalidate: rootShouldRevalidate
|
|
475
|
-
}),
|
|
476
|
-
loader: rootModern ? wrapModernLoader(rootModern, rootLoader, rootRevalidationState, options) : void 0
|
|
477
|
-
};
|
|
478
|
-
if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
|
|
479
|
-
if (rootModern?.inValidSSRRoute) rootRouteOptions.ssr = false;
|
|
480
|
-
const rootRoute = createTanstackRootRoute(rootRouteOptions);
|
|
481
|
-
if (rootComponent) rootRoute.options.component = (0, external_outlet_js_namespaceObject.withModernRouteMatchContext)(rootComponent, react_router_namespaceObject.rootRouteId);
|
|
482
|
-
const topLevel = rootModern ? rootModern.children || [] : routes;
|
|
483
|
-
const childRoutes = topLevel.map((child)=>createRouteFromModernRoute({
|
|
484
|
-
options,
|
|
485
|
-
parent: rootRoute,
|
|
486
|
-
modernRoute: child
|
|
487
|
-
}));
|
|
488
|
-
rootRoute.addChildren(childRoutes);
|
|
489
|
-
return rootRoute;
|
|
490
|
-
}
|
|
491
296
|
function getRootLikeRouteObject(routes) {
|
|
492
297
|
return routes.find((route)=>'/' === route.path && !route.index);
|
|
493
298
|
}
|
|
@@ -503,7 +308,7 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
|
|
|
503
308
|
errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
|
|
504
309
|
validateSearch: rootLikeRoute?.validateSearch,
|
|
505
310
|
loaderDeps: rootLikeRoute?.loaderDeps,
|
|
506
|
-
notFoundComponent:
|
|
311
|
+
notFoundComponent: context_namespaceObject.DefaultNotFound,
|
|
507
312
|
staticData: createRouteStaticData({
|
|
508
313
|
modernRouteId: rootLikeRoute?.id,
|
|
509
314
|
modernRouteAction: rootLikeRoute?.action,
|
|
@@ -543,11 +348,9 @@ function getModernRouteIdsFromMatches(router) {
|
|
|
543
348
|
}).filter((id)=>'string' == typeof id);
|
|
544
349
|
return Array.from(new Set(ids));
|
|
545
350
|
}
|
|
546
|
-
exports.createRouteTreeFromModernRoutes = __webpack_exports__.createRouteTreeFromModernRoutes;
|
|
547
351
|
exports.createRouteTreeFromRouteObjects = __webpack_exports__.createRouteTreeFromRouteObjects;
|
|
548
352
|
exports.getModernRouteIdsFromMatches = __webpack_exports__.getModernRouteIdsFromMatches;
|
|
549
353
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
550
|
-
"createRouteTreeFromModernRoutes",
|
|
551
354
|
"createRouteTreeFromRouteObjects",
|
|
552
355
|
"getModernRouteIdsFromMatches"
|
|
553
356
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -28,23 +28,13 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
|
|
31
|
+
routerPlugin: ()=>internal_namespaceObject.routerPlugin
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
require("
|
|
35
|
-
|
|
36
|
-
style: {
|
|
37
|
-
margin: '150px auto',
|
|
38
|
-
textAlign: 'center',
|
|
39
|
-
display: 'flex',
|
|
40
|
-
alignItems: 'center',
|
|
41
|
-
justifyContent: 'center'
|
|
42
|
-
},
|
|
43
|
-
children: "404"
|
|
44
|
-
});
|
|
45
|
-
exports.DefaultNotFound = __webpack_exports__.DefaultNotFound;
|
|
33
|
+
require("./register.js");
|
|
34
|
+
const internal_namespaceObject = require("@modern-js/runtime/router/internal");
|
|
35
|
+
exports.routerPlugin = __webpack_exports__.routerPlugin;
|
|
46
36
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
-
"
|
|
37
|
+
"routerPlugin"
|
|
48
38
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
49
39
|
Object.defineProperty(exports, '__esModule', {
|
|
50
40
|
value: true
|
|
@@ -35,6 +35,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
35
35
|
loadTanstackRscPayload: ()=>loadTanstackRscPayload,
|
|
36
36
|
loadTanstackRscRouteData: ()=>loadTanstackRscRouteData
|
|
37
37
|
});
|
|
38
|
+
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
38
39
|
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
39
40
|
const payloadFetchCache = new Map();
|
|
40
41
|
let payloadDecoder;
|
|
@@ -74,6 +75,39 @@ function toPayloadRoute(match) {
|
|
|
74
75
|
pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
|
|
75
76
|
};
|
|
76
77
|
}
|
|
78
|
+
function shouldRedactServerError(status = 500) {
|
|
79
|
+
return status >= 500 && 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
|
|
80
|
+
}
|
|
81
|
+
function serializePayloadError(error) {
|
|
82
|
+
if ((0, router_namespaceObject.isRouteErrorResponse)(error)) {
|
|
83
|
+
if (shouldRedactServerError(error.status)) return {
|
|
84
|
+
status: error.status,
|
|
85
|
+
statusText: 'Internal Server Error',
|
|
86
|
+
data: 'Unexpected Server Error',
|
|
87
|
+
__type: 'RouteErrorResponse'
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
...error,
|
|
91
|
+
__type: 'RouteErrorResponse'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (error instanceof Error) {
|
|
95
|
+
if (shouldRedactServerError()) return {
|
|
96
|
+
message: 'Unexpected Server Error',
|
|
97
|
+
stack: void 0,
|
|
98
|
+
__type: 'Error'
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
message: error.message,
|
|
102
|
+
stack: error.stack,
|
|
103
|
+
__type: 'Error',
|
|
104
|
+
...'Error' !== error.name ? {
|
|
105
|
+
__subType: error.name
|
|
106
|
+
} : {}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return error;
|
|
110
|
+
}
|
|
77
111
|
function createTanstackRscServerPayload(router, options = {}) {
|
|
78
112
|
const matches = Array.isArray(router.state?.matches) ? router.state.matches : [];
|
|
79
113
|
const routes = [];
|
|
@@ -84,7 +118,7 @@ function createTanstackRscServerPayload(router, options = {}) {
|
|
|
84
118
|
if (payloadRoute) {
|
|
85
119
|
routes.push(payloadRoute);
|
|
86
120
|
if ('loaderData' in match && void 0 !== match.loaderData && !(options.omitClientLoaderData && payloadRoute.hasClientLoader)) loaderData[payloadRoute.id] = match.loaderData;
|
|
87
|
-
if (void 0 !== match.error) errors[payloadRoute.id] = match.error;
|
|
121
|
+
if (void 0 !== match.error) errors[payloadRoute.id] = serializePayloadError(match.error);
|
|
88
122
|
}
|
|
89
123
|
}
|
|
90
124
|
return {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
getTanstackRouterState: ()=>getTanstackRouterState
|
|
32
|
+
});
|
|
33
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
34
|
+
function getTanstackRouterState(context) {
|
|
35
|
+
const state = (0, context_namespaceObject.getRouterRuntimeState)(context);
|
|
36
|
+
if (void 0 === state || 'tanstack' !== state.framework) return;
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
exports.getTanstackRouterState = __webpack_exports__.getTanstackRouterState;
|
|
40
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
41
|
+
"getTanstackRouterState"
|
|
42
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
43
|
+
Object.defineProperty(exports, '__esModule', {
|
|
44
|
+
value: true
|
|
45
|
+
});
|
|
@@ -45,7 +45,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
45
45
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
46
46
|
const external_react_namespaceObject = require("react");
|
|
47
47
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
48
|
-
const external_DefaultNotFound_js_namespaceObject = require("./DefaultNotFound.js");
|
|
49
48
|
function getRouteObjects(routes, { globalApp, ssrMode, props }) {
|
|
50
49
|
const createLayoutElement = (Component)=>{
|
|
51
50
|
const GlobalLayout = globalApp;
|
|
@@ -102,10 +101,6 @@ function getRouteObjects(routes, { globalApp, ssrMode, props }) {
|
|
|
102
101
|
};
|
|
103
102
|
routeObjects.push(routeObject);
|
|
104
103
|
}
|
|
105
|
-
routeObjects.push({
|
|
106
|
-
path: '*',
|
|
107
|
-
element: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_DefaultNotFound_js_namespaceObject.DefaultNotFound, {})
|
|
108
|
-
});
|
|
109
104
|
return routeObjects;
|
|
110
105
|
}
|
|
111
106
|
function createRouteObjectsFromConfig({ routesConfig, props, ssrMode }) {
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
2
|
import { NESTED_ROUTE_SPEC_FILE, filterRoutesForServer, fs } from "@modern-js/utils";
|
|
3
|
-
import { createTanstackRsbuildRouteSplittingProfile,
|
|
4
|
-
import { collectCanonicalRoutesForEntry, generateTanstackRouterTypesSourceForEntry
|
|
3
|
+
import { createTanstackRsbuildRouteSplittingProfile, resolveTanstackRouteCodeSplittingEnabled } from "./routeSplitting.mjs";
|
|
4
|
+
import { collectCanonicalRoutesForEntry, generateTanstackRouterTypesSourceForEntry } from "./tanstackTypes.mjs";
|
|
5
5
|
import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
6
6
|
import * as __rspack_external__modern_js_runtime_cli_401ee077 from "@modern-js/runtime/cli";
|
|
7
7
|
__webpack_require__.add({
|
|
8
|
-
"@modern-js/runtime/cli" (module) {
|
|
8
|
+
"@modern-js/runtime/cli?9b14" (module) {
|
|
9
9
|
module.exports = __rspack_external__modern_js_runtime_cli_401ee077;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
@@ -15,8 +15,8 @@ const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
|
|
|
15
15
|
let runtimeRouterCli;
|
|
16
16
|
function getRuntimeRouterCli() {
|
|
17
17
|
if (runtimeRouterCli) return runtimeRouterCli;
|
|
18
|
-
const cli = __webpack_require__("@modern-js/runtime/cli");
|
|
19
|
-
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir) {
|
|
18
|
+
const cli = __webpack_require__("@modern-js/runtime/cli?9b14");
|
|
19
|
+
if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir && cli.getEntrypointRoutesOwner) {
|
|
20
20
|
runtimeRouterCli = cli;
|
|
21
21
|
return runtimeRouterCli;
|
|
22
22
|
}
|
|
@@ -63,7 +63,7 @@ async function writeTanstackRegisterFile(opts) {
|
|
|
63
63
|
}));
|
|
64
64
|
}
|
|
65
65
|
async function writeTanstackRouterTypesForEntries(opts) {
|
|
66
|
-
const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry } = opts;
|
|
66
|
+
const { appContext, generatedDirName = DEFAULT_GENERATED_DIR_NAME, routesByEntry, i18nPluginInstalled = false } = opts;
|
|
67
67
|
const entryNames = Object.keys(routesByEntry);
|
|
68
68
|
await Promise.all(entryNames.map(async (entryName)=>{
|
|
69
69
|
const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
|
|
@@ -81,8 +81,10 @@ async function writeTanstackRouterTypesForEntries(opts) {
|
|
|
81
81
|
return a.localeCompare(b);
|
|
82
82
|
});
|
|
83
83
|
let canonicalRoutes = null;
|
|
84
|
-
for (const entryName of registerEntries){
|
|
85
|
-
const entryCanonicalRoutes = collectCanonicalRoutesForEntry(routesByEntry[entryName]
|
|
84
|
+
if (i18nPluginInstalled) for (const entryName of registerEntries){
|
|
85
|
+
const entryCanonicalRoutes = collectCanonicalRoutesForEntry(routesByEntry[entryName], {
|
|
86
|
+
localeParamHeuristic: true
|
|
87
|
+
});
|
|
86
88
|
if (entryCanonicalRoutes) canonicalRoutes = {
|
|
87
89
|
...entryCanonicalRoutes,
|
|
88
90
|
...canonicalRoutes ?? {}
|
|
@@ -110,16 +112,42 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
110
112
|
const { getEntrypointRoutesDir } = getRuntimeRouterCli();
|
|
111
113
|
return getEntrypointRoutesDir(entrypoint) === routesDir;
|
|
112
114
|
};
|
|
115
|
+
const isForeignRouteEntrypoint = (entrypoint)=>{
|
|
116
|
+
const { getEntrypointRoutesDir, getEntrypointRoutesOwner } = getRuntimeRouterCli();
|
|
117
|
+
if (getEntrypointRoutesOwner(entrypoint)) return true;
|
|
118
|
+
if (entrypoint.pageRoutesEntry) return true;
|
|
119
|
+
return null !== getEntrypointRoutesDir(entrypoint);
|
|
120
|
+
};
|
|
121
|
+
const isI18nPluginInstalled = ()=>{
|
|
122
|
+
const { plugins } = api.getAppContext();
|
|
123
|
+
return Boolean(plugins?.some((plugin)=>plugin?.name === '@modern-js/plugin-i18n'));
|
|
124
|
+
};
|
|
113
125
|
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
114
|
-
|
|
126
|
+
const { metaName, serverRoutes } = api.getAppContext();
|
|
127
|
+
const serverBase = serverRoutes.filter((route)=>route.entryName === entrypoint.entryName).map((route)=>route.urlPath).sort((a, b)=>a.length - b.length > 0 ? -1 : 1);
|
|
128
|
+
if (isTanstackEntrypoint(entrypoint)) {
|
|
129
|
+
plugins.push({
|
|
130
|
+
name: 'tanstackRouter',
|
|
131
|
+
path: `@${metaName}/plugin-tanstack/runtime`,
|
|
132
|
+
config: {
|
|
133
|
+
serverBase
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
entrypoint,
|
|
138
|
+
plugins
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (isForeignRouteEntrypoint(entrypoint)) return {
|
|
115
142
|
entrypoint,
|
|
116
143
|
plugins
|
|
117
144
|
};
|
|
118
|
-
const {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
145
|
+
const routerWrapperPath = `@${metaName}/plugin-tanstack/runtime/router`;
|
|
146
|
+
const existingRouterPlugin = plugins.find((plugin)=>'router' === plugin.name);
|
|
147
|
+
if (existingRouterPlugin) existingRouterPlugin.path = routerWrapperPath;
|
|
148
|
+
else plugins.push({
|
|
149
|
+
name: 'router',
|
|
150
|
+
path: routerWrapperPath,
|
|
123
151
|
config: {
|
|
124
152
|
serverBase
|
|
125
153
|
}
|
|
@@ -138,7 +166,9 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
138
166
|
source: {
|
|
139
167
|
include: [
|
|
140
168
|
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
141
|
-
|
|
169
|
+
/[\\/]node_modules[\\/]@tanstack[\\/]router-core[\\/]/,
|
|
170
|
+
/[\\/]node_modules[\\/]@tanstack[\\/]react-store[\\/]/,
|
|
171
|
+
node_path.resolve(__dirname, '..', '..')
|
|
142
172
|
]
|
|
143
173
|
}
|
|
144
174
|
}));
|
|
@@ -155,15 +185,13 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
155
185
|
if (0 === tanstackEntrypoints.length) return;
|
|
156
186
|
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
157
187
|
const routesByEntry = await handleGeneratorEntryCode(api, tanstackEntrypoints, {
|
|
158
|
-
entrypointsKey: ENTRYPOINTS_KEY
|
|
159
|
-
generateCodeOptions: {
|
|
160
|
-
enableTanstackTypes: false
|
|
161
|
-
}
|
|
188
|
+
entrypointsKey: ENTRYPOINTS_KEY
|
|
162
189
|
});
|
|
163
190
|
await writeTanstackRouterTypesForEntries({
|
|
164
191
|
appContext: api.getAppContext(),
|
|
165
192
|
generatedDirName,
|
|
166
|
-
routesByEntry
|
|
193
|
+
routesByEntry,
|
|
194
|
+
i18nPluginInstalled: isI18nPluginInstalled()
|
|
167
195
|
});
|
|
168
196
|
});
|
|
169
197
|
api.onFileChanged(async (event)=>{
|
|
@@ -177,15 +205,13 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
177
205
|
regenerate: async ({ api, entrypoints })=>{
|
|
178
206
|
const { handleGeneratorEntryCode } = getRuntimeRouterCli();
|
|
179
207
|
const routesByEntry = await handleGeneratorEntryCode(api, entrypoints, {
|
|
180
|
-
entrypointsKey: ENTRYPOINTS_KEY
|
|
181
|
-
generateCodeOptions: {
|
|
182
|
-
enableTanstackTypes: false
|
|
183
|
-
}
|
|
208
|
+
entrypointsKey: ENTRYPOINTS_KEY
|
|
184
209
|
});
|
|
185
210
|
await writeTanstackRouterTypesForEntries({
|
|
186
211
|
appContext: api.getAppContext(),
|
|
187
212
|
generatedDirName,
|
|
188
|
-
routesByEntry
|
|
213
|
+
routesByEntry,
|
|
214
|
+
i18nPluginInstalled: isI18nPluginInstalled()
|
|
189
215
|
});
|
|
190
216
|
}
|
|
191
217
|
});
|
|
@@ -217,4 +243,4 @@ function tanstackRouterPlugin(options = {}) {
|
|
|
217
243
|
}
|
|
218
244
|
const src_cli = tanstackRouterPlugin;
|
|
219
245
|
export default src_cli;
|
|
220
|
-
export { collectCanonicalRoutesForEntry, createTanstackRsbuildRouteSplittingProfile, generateTanstackRouterTypesSourceForEntry,
|
|
246
|
+
export { collectCanonicalRoutesForEntry, createTanstackRsbuildRouteSplittingProfile, generateTanstackRouterTypesSourceForEntry, resolveTanstackRouteCodeSplittingEnabled, tanstackRouterPlugin, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
const TANSTACK_START_ROUTE_FACTORY_CALLS = [
|
|
2
|
-
'createFileRoute',
|
|
3
|
-
'createRootRoute',
|
|
4
|
-
'createRootRouteWithContext'
|
|
5
|
-
];
|
|
6
|
-
const TANSTACK_START_ROUTE_FACTORY_REGEX = /\b(createFileRoute|createRootRoute|createRootRouteWithContext)\s*(?:<|\()/;
|
|
7
|
-
function isTanstackStartRouteModuleSource(source) {
|
|
8
|
-
return TANSTACK_START_ROUTE_FACTORY_REGEX.test(source);
|
|
9
|
-
}
|
|
10
1
|
function resolveTanstackRouteCodeSplittingEnabled(option) {
|
|
11
2
|
if ('boolean' == typeof option) return option;
|
|
12
3
|
return option?.enabled ?? true;
|
|
@@ -17,27 +8,7 @@ function createTanstackRsbuildRouteSplittingProfile(opts) {
|
|
|
17
8
|
output: {
|
|
18
9
|
splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting)
|
|
19
10
|
}
|
|
20
|
-
},
|
|
21
|
-
modernRouteChunks: {
|
|
22
|
-
enabled: resolveTanstackRouteCodeSplittingEnabled(opts.routeCodeSplitting),
|
|
23
|
-
owner: 'modern'
|
|
24
|
-
},
|
|
25
|
-
builderChunkSplit: {
|
|
26
|
-
owner: 'modern-rsbuild',
|
|
27
|
-
preserved: true
|
|
28
|
-
},
|
|
29
|
-
tanstackStartRspackSplitter: {
|
|
30
|
-
compatible: false,
|
|
31
|
-
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.',
|
|
32
|
-
clientDeleteNodes: [
|
|
33
|
-
'ssr',
|
|
34
|
-
'server',
|
|
35
|
-
'headers'
|
|
36
|
-
],
|
|
37
|
-
routeFactoryCalls: [
|
|
38
|
-
...TANSTACK_START_ROUTE_FACTORY_CALLS
|
|
39
|
-
]
|
|
40
11
|
}
|
|
41
12
|
};
|
|
42
13
|
}
|
|
43
|
-
export { createTanstackRsbuildRouteSplittingProfile,
|
|
14
|
+
export { createTanstackRsbuildRouteSplittingProfile, resolveTanstackRouteCodeSplittingEnabled };
|