@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 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 (136) hide show
  1. package/dist/cjs/cli/index.js +89 -31
  2. package/dist/cjs/cli/routeSplitting.js +55 -0
  3. package/dist/cjs/cli/tanstackTypes.js +172 -170
  4. package/dist/cjs/cli.js +12 -8
  5. package/dist/cjs/runtime/basepathRewrite.js +12 -8
  6. package/dist/cjs/runtime/dataMutation.js +9 -5
  7. package/dist/cjs/runtime/hooks.js +20 -19
  8. package/dist/cjs/runtime/hydrationBoundary.js +48 -0
  9. package/dist/cjs/runtime/index.js +79 -35
  10. package/dist/cjs/runtime/lifecycle.js +21 -91
  11. package/dist/cjs/runtime/loaderBridge.js +173 -0
  12. package/dist/cjs/runtime/outlet.js +58 -0
  13. package/dist/cjs/runtime/plugin.js +195 -114
  14. package/dist/cjs/runtime/plugin.node.js +45 -45
  15. package/dist/cjs/runtime/plugin.worker.js +53 -0
  16. package/dist/cjs/runtime/pluginCore.js +55 -0
  17. package/dist/cjs/runtime/prefetchLink.js +10 -6
  18. package/dist/cjs/runtime/register.js +56 -0
  19. package/dist/cjs/runtime/routeTree.js +74 -207
  20. package/dist/cjs/runtime/router.js +41 -0
  21. package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
  22. package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
  23. package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
  24. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
  25. package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
  26. package/dist/cjs/runtime/rsc/client.js +9 -5
  27. package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
  28. package/dist/cjs/runtime/rsc/index.js +9 -5
  29. package/dist/cjs/runtime/rsc/payloadRouter.js +44 -6
  30. package/dist/cjs/runtime/rsc/server.js +9 -5
  31. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
  32. package/dist/cjs/runtime/rsc/symbols.js +20 -15
  33. package/dist/cjs/runtime/state.js +45 -0
  34. package/dist/cjs/runtime/types.js +31 -1
  35. package/dist/cjs/runtime/utils.js +9 -10
  36. package/dist/cjs/runtime.js +9 -5
  37. package/dist/esm/cli/index.mjs +75 -27
  38. package/dist/esm/cli/routeSplitting.mjs +14 -0
  39. package/dist/esm/cli/tanstackTypes.mjs +158 -160
  40. package/dist/esm/runtime/hooks.mjs +1 -8
  41. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  42. package/dist/esm/runtime/index.mjs +5 -2
  43. package/dist/esm/runtime/lifecycle.mjs +1 -82
  44. package/dist/esm/runtime/loaderBridge.mjs +114 -0
  45. package/dist/esm/runtime/outlet.mjs +17 -0
  46. package/dist/esm/runtime/plugin.mjs +191 -114
  47. package/dist/esm/runtime/plugin.node.mjs +40 -44
  48. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  49. package/dist/esm/runtime/pluginCore.mjs +14 -0
  50. package/dist/esm/runtime/prefetchLink.mjs +1 -1
  51. package/dist/esm/runtime/register.mjs +18 -0
  52. package/dist/esm/runtime/routeTree.mjs +59 -193
  53. package/dist/esm/runtime/router.mjs +2 -0
  54. package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
  55. package/dist/esm/runtime/state.mjs +7 -0
  56. package/dist/esm/runtime/types.mjs +7 -0
  57. package/dist/esm/runtime/utils.mjs +0 -5
  58. package/dist/esm-node/cli/index.mjs +75 -27
  59. package/dist/esm-node/cli/routeSplitting.mjs +15 -0
  60. package/dist/esm-node/cli/tanstackTypes.mjs +158 -160
  61. package/dist/esm-node/runtime/hooks.mjs +1 -8
  62. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  63. package/dist/esm-node/runtime/index.mjs +5 -2
  64. package/dist/esm-node/runtime/lifecycle.mjs +1 -82
  65. package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
  66. package/dist/esm-node/runtime/outlet.mjs +18 -0
  67. package/dist/esm-node/runtime/plugin.mjs +191 -114
  68. package/dist/esm-node/runtime/plugin.node.mjs +40 -44
  69. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  70. package/dist/esm-node/runtime/pluginCore.mjs +15 -0
  71. package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
  72. package/dist/esm-node/runtime/register.mjs +19 -0
  73. package/dist/esm-node/runtime/routeTree.mjs +59 -193
  74. package/dist/esm-node/runtime/router.mjs +3 -0
  75. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
  76. package/dist/esm-node/runtime/state.mjs +8 -0
  77. package/dist/esm-node/runtime/types.mjs +7 -0
  78. package/dist/esm-node/runtime/utils.mjs +0 -5
  79. package/dist/types/cli/index.d.ts +14 -1
  80. package/dist/types/cli/routeSplitting.d.ts +20 -0
  81. package/dist/types/cli/tanstackTypes.d.ts +21 -1
  82. package/dist/types/runtime/hooks.d.ts +8 -33
  83. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  84. package/dist/types/runtime/index.d.ts +8 -3
  85. package/dist/types/runtime/lifecycle.d.ts +7 -22
  86. package/dist/types/runtime/loaderBridge.d.ts +48 -0
  87. package/dist/types/runtime/outlet.d.ts +2 -0
  88. package/dist/types/runtime/plugin.d.ts +2 -15
  89. package/dist/types/runtime/plugin.node.d.ts +2 -15
  90. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  91. package/dist/types/runtime/pluginCore.d.ts +21 -0
  92. package/dist/types/runtime/register.d.ts +9 -0
  93. package/dist/types/runtime/routeTree.d.ts +0 -2
  94. package/dist/types/runtime/router.d.ts +14 -0
  95. package/dist/types/runtime/state.d.ts +16 -0
  96. package/dist/types/runtime/types.d.ts +14 -53
  97. package/package.json +42 -40
  98. package/rstest.config.mts +6 -0
  99. package/src/cli/index.ts +162 -23
  100. package/src/cli/routeSplitting.ts +43 -0
  101. package/src/cli/tanstackTypes.ts +331 -187
  102. package/src/runtime/hooks.ts +10 -27
  103. package/src/runtime/hydrationBoundary.tsx +12 -0
  104. package/src/runtime/index.tsx +17 -7
  105. package/src/runtime/lifecycle.ts +16 -151
  106. package/src/runtime/loaderBridge.ts +257 -0
  107. package/src/runtime/outlet.tsx +48 -0
  108. package/src/runtime/plugin.node.tsx +72 -85
  109. package/src/runtime/plugin.tsx +361 -206
  110. package/src/runtime/plugin.worker.tsx +4 -0
  111. package/src/runtime/pluginCore.ts +48 -0
  112. package/src/runtime/prefetchLink.tsx +1 -1
  113. package/src/runtime/register.ts +58 -0
  114. package/src/runtime/routeTree.ts +163 -354
  115. package/src/runtime/router.ts +15 -0
  116. package/src/runtime/rsc/payloadRouter.ts +45 -2
  117. package/src/runtime/ssr-shim.d.ts +1 -3
  118. package/src/runtime/state.ts +29 -0
  119. package/src/runtime/types.ts +32 -66
  120. package/src/runtime/utils.tsx +3 -6
  121. package/tests/router/cli.test.ts +586 -5
  122. package/tests/router/fastDefaults.test.ts +25 -0
  123. package/tests/router/hooks.test.ts +26 -0
  124. package/tests/router/hydrationBoundary.test.tsx +23 -0
  125. package/tests/router/loaderBridge.test.ts +211 -0
  126. package/tests/router/packageSurface.test.ts +24 -0
  127. package/tests/router/prefetchLink.test.tsx +43 -7
  128. package/tests/router/register.test.ts +46 -0
  129. package/tests/router/routeTree.test.ts +381 -81
  130. package/tests/router/rsc.test.tsx +70 -0
  131. package/tests/router/tanstackTypes.test.ts +573 -1
  132. package/dist/cjs/runtime/DefaultNotFound.js +0 -47
  133. package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
  134. package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
  135. package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
  136. package/src/runtime/DefaultNotFound.tsx +0 -15
@@ -1,7 +1,14 @@
1
+ import { execFile } from 'node:child_process';
1
2
  import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
2
3
  import { tmpdir } from 'node:os';
3
4
  import path from 'node:path';
4
- import { generateTanstackRouterTypesSourceForEntry } from '../../src/cli/tanstackTypes';
5
+ import { promisify } from 'node:util';
6
+ import {
7
+ collectCanonicalRoutesForEntry,
8
+ generateTanstackRouterTypesSourceForEntry,
9
+ } from '../../src/cli/tanstackTypes';
10
+
11
+ const execFileAsync = promisify(execFile);
5
12
 
6
13
  describe('tanstack router type generation', () => {
7
14
  let tempDir: string | undefined;
@@ -58,5 +65,570 @@ describe('tanstack router type generation', () => {
58
65
  expect(routerGenTs).toContain(
59
66
  "} from '@modern-js/plugin-tanstack/runtime';",
60
67
  );
68
+ expect(routerGenTs).toContain('modernTanstackRouterFastDefaults,');
69
+ expect(routerGenTs).toContain('...modernTanstackRouterFastDefaults,');
70
+
71
+ // The loader-bridge helpers are imported from the package runtime instead
72
+ // of being inlined into every generated file (bugfixes ship via package
73
+ // update, and the broken inline absolute-redirect handler is gone).
74
+ expect(routerGenTs).toContain('createRouteStaticData,');
75
+ expect(routerGenTs).toContain('modernLoaderToTanstack,');
76
+ expect(routerGenTs).toContain('type ModernRouterContext,');
77
+ expect(routerGenTs).not.toContain('function modernLoaderToTanstack');
78
+ expect(routerGenTs).not.toContain('function createRouteStaticData');
79
+ expect(routerGenTs).not.toContain('function throwTanstackRedirect');
80
+ });
81
+
82
+ test('emits resolvable relative component imports for routes carrying _component', async () => {
83
+ tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-types-'));
84
+ const srcDirectory = path.join(tempDir, 'src');
85
+ for (const componentFile of [
86
+ 'routes/layout.tsx',
87
+ 'routes/page.tsx',
88
+ 'routes/about/page.tsx',
89
+ ]) {
90
+ const componentPath = path.join(srcDirectory, componentFile);
91
+ await mkdir(path.dirname(componentPath), { recursive: true });
92
+ await writeFile(componentPath, 'export default () => null;');
93
+ }
94
+
95
+ const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
96
+ appContext: {
97
+ srcDirectory,
98
+ internalSrcAlias: '@/_',
99
+ } as any,
100
+ entryName: 'index',
101
+ routes: [
102
+ {
103
+ type: 'nested',
104
+ id: 'layout',
105
+ isRoot: true,
106
+ _component: '@/_/routes/layout',
107
+ children: [
108
+ {
109
+ type: 'nested',
110
+ id: 'page',
111
+ index: true,
112
+ _component: '@/_/routes/page',
113
+ },
114
+ {
115
+ type: 'nested',
116
+ id: 'about/page',
117
+ path: 'about',
118
+ _component: '@/_/routes/about/page',
119
+ },
120
+ {
121
+ // Shares the page component module: the import must be reused.
122
+ type: 'nested',
123
+ id: 'about-alias/page',
124
+ path: 'about-alias',
125
+ _component: '@/_/routes/about/page',
126
+ },
127
+ {
128
+ // No _component: no component option may be emitted.
129
+ type: 'nested',
130
+ id: 'data-only/page',
131
+ path: 'data-only',
132
+ },
133
+ ],
134
+ },
135
+ ] as any,
136
+ });
137
+
138
+ // Children are emitted first, the root route component import last.
139
+ // Imports are relative (resolved like loader modules) — the raw
140
+ // `@/_` internal alias is not mapped by app tsconfigs.
141
+ expect(routerGenTs).toContain(
142
+ 'import component_0 from "../../routes/page";',
143
+ );
144
+ expect(routerGenTs).toContain(
145
+ 'import component_1 from "../../routes/about/page";',
146
+ );
147
+ expect(routerGenTs).toContain(
148
+ 'import component_2 from "../../routes/layout";',
149
+ );
150
+ expect(routerGenTs).not.toContain('@/_/routes');
151
+ // The shared module is imported exactly once.
152
+ expect(routerGenTs).not.toContain('component_3');
153
+ expect(
154
+ routerGenTs.match(/from "\.\.\/\.\.\/routes\/about\/page";/g),
155
+ ).toHaveLength(1);
156
+
157
+ expect(routerGenTs).toContain('component: component_0,');
158
+ // The shared component import is referenced by both aliased routes.
159
+ expect(routerGenTs.match(/component: component_1,/g)).toHaveLength(2);
160
+ // The root route gets its component option.
161
+ expect(routerGenTs).toContain('component: component_2,');
162
+
163
+ const dataOnlyRoute = routerGenTs
164
+ .split('const ')
165
+ .find(block => block.includes('path: "data-only",'));
166
+ expect(dataOnlyRoute).toBeDefined();
167
+ expect(dataOnlyRoute).not.toContain('component:');
168
+ });
169
+
170
+ test('typechecks generated TanStack search contracts', async () => {
171
+ tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-types-'));
172
+ const srcDirectory = path.join(tempDir, 'src');
173
+ const routeDir = path.join(srcDirectory, 'routes');
174
+ const generatedDir = path.join(srcDirectory, 'modern-tanstack', 'index');
175
+ await mkdir(routeDir, { recursive: true });
176
+ await mkdir(generatedDir, { recursive: true });
177
+ await writeFile(
178
+ path.join(routeDir, 'search.contract.ts'),
179
+ [
180
+ 'export const validateSearch = (search: { q?: string }) => ({ q: search.q ?? "" });',
181
+ 'export const loaderDeps = ({ search }: { search: { q: string } }) => ({ q: search.q });',
182
+ ].join('\n'),
183
+ );
184
+
185
+ const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
186
+ appContext: {
187
+ srcDirectory,
188
+ internalSrcAlias: '@/_',
189
+ } as any,
190
+ entryName: 'index',
191
+ routes: [
192
+ {
193
+ type: 'nested',
194
+ id: 'layout',
195
+ isRoot: true,
196
+ validateSearch: '@/_/routes/search.contract',
197
+ loaderDeps: '@/_/routes/search.contract',
198
+ children: [
199
+ {
200
+ type: 'nested',
201
+ id: 'search/page',
202
+ path: 'search',
203
+ validateSearch: '@/_/routes/search.contract',
204
+ loaderDeps: '@/_/routes/search.contract',
205
+ },
206
+ ],
207
+ },
208
+ ] as any,
209
+ });
210
+
211
+ await writeFile(path.join(generatedDir, 'router.gen.ts'), routerGenTs);
212
+ await writeFile(
213
+ path.join(srcDirectory, 'runtime-shim.d.ts'),
214
+ [
215
+ "declare module '@modern-js/plugin-tanstack/runtime' {",
216
+ ' type RouteOptions = {',
217
+ ' getParentRoute?: () => unknown;',
218
+ ' id?: string;',
219
+ ' loader?: unknown;',
220
+ ' loaderDeps?: unknown;',
221
+ ' path?: string;',
222
+ ' staticData?: unknown;',
223
+ ' validateSearch?: unknown;',
224
+ ' };',
225
+ ' type Route<TOptions extends RouteOptions> = {',
226
+ ' options: TOptions;',
227
+ ' addChildren<TChildren extends readonly unknown[]>(children: TChildren): Route<TOptions> & { children: TChildren };',
228
+ ' };',
229
+ ' export type ModernRouterContext = {',
230
+ ' request?: Request;',
231
+ ' requestContext?: unknown;',
232
+ ' };',
233
+ ' export function createMemoryHistory(options: unknown): unknown;',
234
+ ' export const modernTanstackRouterFastDefaults: Record<string, unknown>;',
235
+ ' export function createRootRouteWithContext<TContext>(): <TOptions extends RouteOptions>(options: TOptions) => Route<TOptions>;',
236
+ ' export function createRoute<TOptions extends RouteOptions>(options: TOptions): Route<TOptions>;',
237
+ ' export function createRouter<TOptions extends Record<string, unknown>>(options: TOptions): TOptions;',
238
+ ' export function createRouteStaticData(opts: { modernRouteId?: string; modernRouteAction?: unknown; modernRouteLoader?: unknown }): Record<string, unknown>;',
239
+ ' export function modernLoaderToTanstack<TLoader extends (args: never) => unknown>(opts: { hasSplat: boolean }, modernLoader: TLoader): (ctx: unknown) => Promise<Awaited<ReturnType<TLoader>>>;',
240
+ '}',
241
+ ].join('\n'),
242
+ );
243
+ await writeFile(
244
+ path.join(srcDirectory, 'assert-search-contracts.ts'),
245
+ [
246
+ "import { rootRoute, routeTree } from './modern-tanstack/index/router.gen';",
247
+ "import { loaderDeps, validateSearch } from './routes/search.contract';",
248
+ '',
249
+ 'const rootValidateSearch: typeof validateSearch = rootRoute.options.validateSearch;',
250
+ 'const rootLoaderDeps: typeof loaderDeps = rootRoute.options.loaderDeps;',
251
+ 'const childValidateSearch: typeof validateSearch = routeTree.children[0].options.validateSearch;',
252
+ 'const childLoaderDeps: typeof loaderDeps = routeTree.children[0].options.loaderDeps;',
253
+ '',
254
+ "rootValidateSearch({ q: 'root' });",
255
+ "rootLoaderDeps({ search: { q: 'root' } });",
256
+ "childValidateSearch({ q: 'child' });",
257
+ "childLoaderDeps({ search: { q: 'child' } });",
258
+ ].join('\n'),
259
+ );
260
+ await writeFile(
261
+ path.join(tempDir, 'tsconfig.json'),
262
+ JSON.stringify(
263
+ {
264
+ compilerOptions: {
265
+ lib: ['ESNext', 'DOM'],
266
+ module: 'Preserve',
267
+ moduleResolution: 'Bundler',
268
+ noEmit: true,
269
+ skipLibCheck: true,
270
+ strict: true,
271
+ target: 'ESNext',
272
+ types: [],
273
+ },
274
+ include: ['src/**/*.ts', 'src/**/*.d.ts'],
275
+ },
276
+ null,
277
+ 2,
278
+ ),
279
+ );
280
+
281
+ await expect(
282
+ execFileAsync('tsgo', ['--noEmit', '-p', 'tsconfig.json'], {
283
+ cwd: tempDir,
284
+ }),
285
+ ).resolves.toBeDefined();
286
+ });
287
+
288
+ test('preserves typed child trees for localized nested route aliases', async () => {
289
+ tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-types-'));
290
+ const srcDirectory = path.join(tempDir, 'src');
291
+
292
+ const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
293
+ appContext: {
294
+ srcDirectory,
295
+ internalSrcAlias: '@/_',
296
+ } as any,
297
+ entryName: 'index',
298
+ routes: [
299
+ {
300
+ type: 'nested',
301
+ id: 'layout',
302
+ isRoot: true,
303
+ children: [
304
+ {
305
+ type: 'nested',
306
+ id: '(lang)/layout',
307
+ path: ':lang',
308
+ children: [
309
+ {
310
+ type: 'nested',
311
+ id: '(lang)/products/(slug)/page',
312
+ path: 'products/:slug',
313
+ },
314
+ {
315
+ type: 'nested',
316
+ id: '(lang)/products/(slug)/page__localised_produkty_slug',
317
+ path: 'produkty/:slug',
318
+ },
319
+ {
320
+ type: 'nested',
321
+ id: '(lang)/optional/(slug$)/page__localised_volitelne_slug',
322
+ path: 'volitelne/:slug?',
323
+ },
324
+ ],
325
+ },
326
+ ],
327
+ },
328
+ ] as any,
329
+ });
330
+
331
+ expect(routerGenTs).toContain(
332
+ 'const route__lang__layout__base = createRoute({',
333
+ );
334
+ expect(routerGenTs).toContain(
335
+ 'getParentRoute: () => route__lang__layout__base,',
336
+ );
337
+ expect(routerGenTs).toContain('path: "produkty/$slug",');
338
+ expect(routerGenTs).toContain('path: "volitelne/{-$slug}",');
339
+ expect(routerGenTs).toContain(
340
+ 'const route__lang__layout = route__lang__layout__base.addChildren([route__lang__products__slug__page, route__lang__products__slug__page__localised_produkty_slug, route__lang__optional__slug$__page__localised_volitelne_slug]);',
341
+ );
342
+ expect(routerGenTs).toContain(
343
+ 'export const routeTree = rootRoute.addChildren([route__lang__layout]);',
344
+ );
345
+ expect(routerGenTs).not.toContain('route__lang__layout.addChildren([');
346
+ });
347
+ });
348
+
349
+ describe('collectCanonicalRoutesForEntry', () => {
350
+ test('returns null for a route tree with no locale param and no canonical metadata', () => {
351
+ const result = collectCanonicalRoutesForEntry([
352
+ {
353
+ type: 'nested',
354
+ id: 'layout',
355
+ isRoot: true,
356
+ children: [
357
+ {
358
+ type: 'nested',
359
+ id: 'about/page',
360
+ path: 'about',
361
+ },
362
+ {
363
+ type: 'nested',
364
+ id: 'contact/page',
365
+ path: 'contact',
366
+ },
367
+ ],
368
+ },
369
+ ] as any);
370
+
371
+ expect(result).toBeNull();
372
+ });
373
+
374
+ test('ignores a leading :lang param when the locale-param heuristic is disabled (no plugin-i18n)', () => {
375
+ const routes = [
376
+ {
377
+ type: 'nested',
378
+ id: 'layout',
379
+ isRoot: true,
380
+ children: [
381
+ {
382
+ type: 'nested',
383
+ id: '(lang)/layout',
384
+ path: ':lang',
385
+ children: [
386
+ {
387
+ type: 'nested',
388
+ id: '(lang)/about/page',
389
+ path: 'about',
390
+ },
391
+ ],
392
+ },
393
+ ],
394
+ },
395
+ ] as any;
396
+
397
+ // Without plugin-i18n, a hand-rolled `/:lang/` param must NOT trigger the
398
+ // i18n surface (the emitted module augmentation would break typechecking).
399
+ expect(
400
+ collectCanonicalRoutesForEntry(routes, { localeParamHeuristic: false }),
401
+ ).toBeNull();
402
+ // With plugin-i18n installed the heuristic strips the locale prefix.
403
+ expect(
404
+ collectCanonicalRoutesForEntry(routes, { localeParamHeuristic: true }),
405
+ ).toEqual({
406
+ '/about': 'Record<string, never>',
407
+ });
408
+ });
409
+
410
+ test('still honors modernCanonicalPath metadata when the heuristic is disabled', () => {
411
+ const result = collectCanonicalRoutesForEntry(
412
+ [
413
+ {
414
+ type: 'nested',
415
+ id: 'layout',
416
+ isRoot: true,
417
+ children: [
418
+ {
419
+ type: 'nested',
420
+ id: '(lang)/products/(slug)/page',
421
+ path: 'products/:slug',
422
+ modernCanonicalPath: '/products/:slug',
423
+ },
424
+ ],
425
+ },
426
+ ] as any,
427
+ { localeParamHeuristic: false },
428
+ );
429
+
430
+ expect(result).not.toBeNull();
431
+ expect(result!['/products/$slug']).toBe('{ "slug": string }');
432
+ });
433
+
434
+ test('strips leading :lang param and maps index under :lang to "/"', () => {
435
+ const result = collectCanonicalRoutesForEntry([
436
+ {
437
+ type: 'nested',
438
+ id: 'layout',
439
+ isRoot: true,
440
+ children: [
441
+ {
442
+ type: 'nested',
443
+ id: '(lang)/layout',
444
+ path: ':lang',
445
+ children: [
446
+ {
447
+ type: 'nested',
448
+ id: '(lang)/page',
449
+ index: true,
450
+ },
451
+ {
452
+ type: 'nested',
453
+ id: '(lang)/about/page',
454
+ path: 'about',
455
+ },
456
+ ],
457
+ },
458
+ ],
459
+ },
460
+ ] as any);
461
+
462
+ expect(result).not.toBeNull();
463
+ expect(result!['/']).toBe('Record<string, never>');
464
+ expect(result!['/about']).toBe('Record<string, never>');
465
+ });
466
+
467
+ test('converts :slug to $slug with required params type', () => {
468
+ const result = collectCanonicalRoutesForEntry([
469
+ {
470
+ type: 'nested',
471
+ id: 'layout',
472
+ isRoot: true,
473
+ children: [
474
+ {
475
+ type: 'nested',
476
+ id: '(lang)/layout',
477
+ path: ':lang',
478
+ children: [
479
+ {
480
+ type: 'nested',
481
+ id: '(lang)/products/(slug)/page',
482
+ path: 'products/:slug',
483
+ },
484
+ ],
485
+ },
486
+ ],
487
+ },
488
+ ] as any);
489
+
490
+ expect(result).not.toBeNull();
491
+ expect(result!['/products/$slug']).toBe('{ "slug": string }');
492
+ });
493
+
494
+ test('converts :slug? to optional {-$slug} with optional params type', () => {
495
+ const result = collectCanonicalRoutesForEntry([
496
+ {
497
+ type: 'nested',
498
+ id: 'layout',
499
+ isRoot: true,
500
+ children: [
501
+ {
502
+ type: 'nested',
503
+ id: '(lang)/layout',
504
+ path: ':lang',
505
+ children: [
506
+ {
507
+ type: 'nested',
508
+ id: '(lang)/optional/(slug$)/page',
509
+ path: 'optional/:slug?',
510
+ },
511
+ ],
512
+ },
513
+ ],
514
+ },
515
+ ] as any);
516
+
517
+ expect(result).not.toBeNull();
518
+ expect(result!['/optional/{-$slug}']).toBe('{ "slug"?: string }');
519
+ });
520
+
521
+ test('converts * splat to $ with optional _splat param', () => {
522
+ const result = collectCanonicalRoutesForEntry([
523
+ {
524
+ type: 'nested',
525
+ id: 'layout',
526
+ isRoot: true,
527
+ children: [
528
+ {
529
+ type: 'nested',
530
+ id: '(lang)/layout',
531
+ path: ':lang',
532
+ children: [
533
+ {
534
+ type: 'nested',
535
+ id: '(lang)/files/page',
536
+ path: 'files/*',
537
+ },
538
+ ],
539
+ },
540
+ ],
541
+ },
542
+ ] as any);
543
+
544
+ expect(result).not.toBeNull();
545
+ expect(result!['/files/$']).toBe("{ '_splat'?: string }");
546
+ });
547
+
548
+ test('collapses localized variants with shared modernCanonicalPath to one canonical key', () => {
549
+ // This reuses the same fixture shape as the 'preserves typed child trees'
550
+ // test but adds modernCanonicalPath fields as plugin-i18n now emits.
551
+ const result = collectCanonicalRoutesForEntry([
552
+ {
553
+ type: 'nested',
554
+ id: 'layout',
555
+ isRoot: true,
556
+ children: [
557
+ {
558
+ type: 'nested',
559
+ id: '(lang)/layout',
560
+ path: ':lang',
561
+ children: [
562
+ {
563
+ type: 'nested',
564
+ id: '(lang)/products/(slug)/page',
565
+ path: 'products/:slug',
566
+ modernCanonicalPath: '/products/:slug',
567
+ },
568
+ {
569
+ type: 'nested',
570
+ id: '(lang)/products/(slug)/page__localised_produkty_slug',
571
+ path: 'produkty/:slug',
572
+ modernCanonicalPath: '/products/:slug',
573
+ },
574
+ {
575
+ type: 'nested',
576
+ id: '(lang)/optional/(slug$)/page__localised_volitelne_slug',
577
+ path: 'volitelne/:slug?',
578
+ modernCanonicalPath: '/optional/:slug?',
579
+ },
580
+ ],
581
+ },
582
+ ],
583
+ },
584
+ ] as any);
585
+
586
+ expect(result).not.toBeNull();
587
+ // Two physical variants share the same canonical path — only one entry.
588
+ const keys = Object.keys(result!);
589
+ // /products/$slug and /optional/{-$slug} — exactly 2 keys with params
590
+ expect(keys.filter(k => k.startsWith('/products'))).toHaveLength(1);
591
+ expect(result!['/products/$slug']).toBe('{ "slug": string }');
592
+ expect(result!['/optional/{-$slug}']).toBe('{ "slug"?: string }');
593
+ // The Czech localized path must not appear as a separate key.
594
+ expect('/produkty/$slug' in result!).toBe(false);
595
+ });
596
+
597
+ test('output is sorted alphabetically by canonical key', () => {
598
+ const result = collectCanonicalRoutesForEntry([
599
+ {
600
+ type: 'nested',
601
+ id: 'layout',
602
+ isRoot: true,
603
+ children: [
604
+ {
605
+ type: 'nested',
606
+ id: '(lang)/layout',
607
+ path: ':lang',
608
+ children: [
609
+ {
610
+ type: 'nested',
611
+ id: '(lang)/products/(slug)/page',
612
+ path: 'products/:slug',
613
+ },
614
+ {
615
+ type: 'nested',
616
+ id: '(lang)/about/page',
617
+ path: 'about',
618
+ },
619
+ {
620
+ type: 'nested',
621
+ id: '(lang)/page',
622
+ index: true,
623
+ },
624
+ ],
625
+ },
626
+ ],
627
+ },
628
+ ] as any);
629
+
630
+ expect(result).not.toBeNull();
631
+ const keys = Object.keys(result!);
632
+ expect(keys).toEqual([...keys].sort((a, b) => a.localeCompare(b)));
61
633
  });
62
634
  });
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- DefaultNotFound: ()=>DefaultNotFound
28
- });
29
- const jsx_runtime_namespaceObject = require("react/jsx-runtime");
30
- require("react");
31
- const DefaultNotFound = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
32
- style: {
33
- margin: '150px auto',
34
- textAlign: 'center',
35
- display: 'flex',
36
- alignItems: 'center',
37
- justifyContent: 'center'
38
- },
39
- children: "404"
40
- });
41
- exports.DefaultNotFound = __webpack_exports__.DefaultNotFound;
42
- for(var __rspack_i in __webpack_exports__)if (-1 === [
43
- "DefaultNotFound"
44
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
45
- Object.defineProperty(exports, '__esModule', {
46
- value: true
47
- });
@@ -1,13 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import "react";
3
- const DefaultNotFound = ()=>/*#__PURE__*/ jsx("div", {
4
- style: {
5
- margin: '150px auto',
6
- textAlign: 'center',
7
- display: 'flex',
8
- alignItems: 'center',
9
- justifyContent: 'center'
10
- },
11
- children: "404"
12
- });
13
- export { DefaultNotFound };
@@ -1,14 +0,0 @@
1
- import "node:module";
2
- import { jsx } from "react/jsx-runtime";
3
- import "react";
4
- const DefaultNotFound = ()=>/*#__PURE__*/ jsx("div", {
5
- style: {
6
- margin: '150px auto',
7
- textAlign: 'center',
8
- display: 'flex',
9
- alignItems: 'center',
10
- justifyContent: 'center'
11
- },
12
- children: "404"
13
- });
14
- export { DefaultNotFound };
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const DefaultNotFound: () => React.JSX.Element;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
-
3
- export const DefaultNotFound = () => (
4
- <div
5
- style={{
6
- margin: '150px auto',
7
- textAlign: 'center',
8
- display: 'flex',
9
- alignItems: 'center',
10
- justifyContent: 'center',
11
- }}
12
- >
13
- 404
14
- </div>
15
- );