@tanstack/router-generator 1.120.4-alpha.4 → 1.120.4

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 (51) hide show
  1. package/dist/cjs/config.cjs +14 -14
  2. package/dist/cjs/config.cjs.map +1 -1
  3. package/dist/cjs/config.d.cts +31 -68
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +5 -1
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
  6. package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +2 -2
  7. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
  8. package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +2 -2
  9. package/dist/cjs/generator.cjs +172 -160
  10. package/dist/cjs/generator.cjs.map +1 -1
  11. package/dist/cjs/generator.d.cts +59 -0
  12. package/dist/cjs/index.cjs +2 -23
  13. package/dist/cjs/index.cjs.map +1 -1
  14. package/dist/cjs/index.d.cts +4 -8
  15. package/dist/cjs/template.cjs +12 -4
  16. package/dist/cjs/template.cjs.map +1 -1
  17. package/dist/cjs/template.d.cts +1 -0
  18. package/dist/cjs/types.d.cts +1 -1
  19. package/dist/cjs/utils.cjs +2 -61
  20. package/dist/cjs/utils.cjs.map +1 -1
  21. package/dist/cjs/utils.d.cts +2 -4
  22. package/dist/esm/config.d.ts +31 -68
  23. package/dist/esm/config.js +14 -14
  24. package/dist/esm/config.js.map +1 -1
  25. package/dist/esm/filesystem/physical/getRouteNodes.d.ts +2 -2
  26. package/dist/esm/filesystem/physical/getRouteNodes.js +6 -2
  27. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
  28. package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +2 -2
  29. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
  30. package/dist/esm/generator.d.ts +59 -0
  31. package/dist/esm/generator.js +175 -163
  32. package/dist/esm/generator.js.map +1 -1
  33. package/dist/esm/index.d.ts +4 -8
  34. package/dist/esm/index.js +4 -25
  35. package/dist/esm/index.js.map +1 -1
  36. package/dist/esm/template.d.ts +1 -0
  37. package/dist/esm/template.js +12 -4
  38. package/dist/esm/template.js.map +1 -1
  39. package/dist/esm/types.d.ts +1 -1
  40. package/dist/esm/utils.d.ts +2 -4
  41. package/dist/esm/utils.js +2 -61
  42. package/dist/esm/utils.js.map +1 -1
  43. package/package.json +3 -3
  44. package/src/config.ts +11 -14
  45. package/src/filesystem/physical/getRouteNodes.ts +14 -13
  46. package/src/filesystem/virtual/getRouteNodes.ts +3 -18
  47. package/src/generator.ts +221 -242
  48. package/src/index.ts +7 -32
  49. package/src/template.ts +15 -4
  50. package/src/types.ts +1 -0
  51. package/src/utils.ts +4 -85
@@ -26,7 +26,10 @@ function _interopNamespaceDefault(e) {
26
26
  }
27
27
  const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
28
28
  const fsp__namespace = /* @__PURE__ */ _interopNamespaceDefault(fsp);
29
- const rootRouteId = "__root__";
29
+ const CONSTANTS = {
30
+ // When changing this, you'll want to update the import in `start-api-routes/src/index.ts#defaultAPIFileRouteHandler`
31
+ APIRouteExportVariable: "APIRoute"
32
+ };
30
33
  let latestTask = 0;
31
34
  const routeGroupPatternRegex = /\(.+\)/g;
32
35
  const possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
@@ -55,6 +58,7 @@ async function generator(config, root) {
55
58
  };
56
59
  const start = Date.now();
57
60
  const TYPES_DISABLED = config.disableTypes;
61
+ const ENABLED_API_ROUTES_GENERATION = config.__enableAPIRoutesGeneration ?? false;
58
62
  let getRouteNodesResult;
59
63
  if (config.virtualRouteConfig) {
60
64
  getRouteNodesResult = await getRouteNodes.getRouteNodes(config, root);
@@ -90,6 +94,23 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
90
94
  ]).filter((d) => ![`/${rootPathId.rootPathId}`].includes(d.routePath || ""));
91
95
  const routeTree = [];
92
96
  const routePiecesByPath = {};
97
+ const onlyAPIRouteNodes = preRouteNodes.filter((d) => {
98
+ if (!ENABLED_API_ROUTES_GENERATION) {
99
+ return false;
100
+ }
101
+ if (d._fsRouteType !== "api") {
102
+ return false;
103
+ }
104
+ return true;
105
+ });
106
+ const onlyGeneratorRouteNodes = preRouteNodes.filter((d) => {
107
+ if (ENABLED_API_ROUTES_GENERATION) {
108
+ if (d._fsRouteType === "api") {
109
+ return false;
110
+ }
111
+ }
112
+ return true;
113
+ });
93
114
  const routeNodes = [];
94
115
  const handleRootNode = async (node) => {
95
116
  if (!node) {
@@ -154,7 +175,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
154
175
  (((_c = config.customScaffolding) == null ? void 0 : _c.lazyRouteTemplate) || ((_d = config.customScaffolding) == null ? void 0 : _d.routeTemplate)) ?? tLazyRouteTemplate.template(),
155
176
  {
156
177
  tsrImports: tLazyRouteTemplate.imports.tsrImports(),
157
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
178
+ tsrPath: escapedRoutePath,
158
179
  tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
159
180
  tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
160
181
  }
@@ -175,66 +196,16 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
175
196
  ((_e = config.customScaffolding) == null ? void 0 : _e.routeTemplate) ?? tRouteTemplate.template(),
176
197
  {
177
198
  tsrImports: tRouteTemplate.imports.tsrImports(),
178
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
199
+ tsrPath: escapedRoutePath,
179
200
  tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
180
201
  tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
181
202
  }
182
203
  );
183
204
  }
184
- } else if (config.verboseFileRoutes === false) {
185
- if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
186
- return;
187
- }
188
- replaced = routeCode.replace(
189
- /(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
190
- (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
191
- ).replace(
192
- new RegExp(
193
- `(import\\s*\\{)(.*)(create(Lazy)?FileRoute)(.*)(\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
194
- "gs"
195
- ),
196
- (_, p1, p2, ___, ____, p5, p6) => {
197
- const beforeCreateFileRoute = () => {
198
- if (!p2) return "";
199
- let trimmed = p2.trim();
200
- if (trimmed.endsWith(",")) {
201
- trimmed = trimmed.slice(0, -1);
202
- }
203
- return trimmed;
204
- };
205
- const afterCreateFileRoute = () => {
206
- if (!p5) return "";
207
- let trimmed = p5.trim();
208
- if (trimmed.startsWith(",")) {
209
- trimmed = trimmed.slice(1);
210
- }
211
- return trimmed;
212
- };
213
- const newImport = () => {
214
- const before = beforeCreateFileRoute();
215
- const after = afterCreateFileRoute();
216
- if (!before) return after;
217
- if (!after) return before;
218
- return `${before},${after}`;
219
- };
220
- const middle = newImport();
221
- if (middle === "") return "";
222
- return `${p1} ${newImport()} ${p6}`;
223
- }
224
- ).replace(
225
- /create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
226
- (_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}`
227
- );
228
205
  } else {
229
- if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
230
- return;
231
- }
232
206
  replaced = routeCode.replace(
233
207
  /(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
234
208
  (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
235
- ).replace(
236
- /((FileRoute)(\s*)(\({))/g,
237
- (_, __, p2, p3, p4) => `${p2}('${escapedRoutePath}')${p3}${p4}`
238
209
  ).replace(
239
210
  new RegExp(
240
211
  `(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
@@ -245,16 +216,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
245
216
  /create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
246
217
  (_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}${p2}${escapedRoutePath}${p4}`
247
218
  );
248
- const regex = new RegExp(
249
- `(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
250
- "gm"
251
- );
252
- if (!replaced.match(regex)) {
253
- replaced = [
254
- `import { ${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"} } from '@tanstack/${ROUTE_TEMPLATE.subPkg}'`,
255
- ...replaced.split("\n")
256
- ].join("\n");
257
- }
258
219
  }
259
220
  await utils.writeIfDifferent(node.fullPath, routeCode, replaced, {
260
221
  beforeWrite: () => {
@@ -327,15 +288,68 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
327
288
  }
328
289
  routeNodes.push(node);
329
290
  };
330
- for (const node of preRouteNodes) {
291
+ for (const node of onlyGeneratorRouteNodes) {
331
292
  await handleNode(node);
332
293
  }
333
294
  checkRouteFullPathUniqueness(
334
295
  preRouteNodes.filter(
335
- (d) => d.children === void 0 && "lazy" !== d._fsRouteType
296
+ (d) => d.children === void 0 && ["api", "lazy"].every(
297
+ (type) => type !== d._fsRouteType
298
+ )
336
299
  ),
337
300
  config
338
301
  );
302
+ const startAPIRouteNodes = checkStartAPIRoutes(
303
+ onlyAPIRouteNodes,
304
+ config
305
+ );
306
+ const handleAPINode = async (node) => {
307
+ var _a, _b;
308
+ const routeCode = fs__namespace.readFileSync(node.fullPath, "utf-8");
309
+ const escapedRoutePath = ((_a = node.routePath) == null ? void 0 : _a.replaceAll("$", "$$")) ?? "";
310
+ if (!routeCode) {
311
+ const replaced = await template.fillTemplate(
312
+ config,
313
+ ((_b = config.customScaffolding) == null ? void 0 : _b.apiTemplate) ?? template.defaultAPIRouteTemplate,
314
+ {
315
+ tsrImports: "import { createAPIFileRoute } from '@tanstack/react-start/api';",
316
+ tsrPath: escapedRoutePath,
317
+ tsrExportStart: `export const ${CONSTANTS.APIRouteExportVariable} = createAPIFileRoute('${escapedRoutePath}')(`,
318
+ tsrExportEnd: ");"
319
+ }
320
+ );
321
+ await utils.writeIfDifferent(
322
+ node.fullPath,
323
+ "",
324
+ // Empty string because the file doesn't exist yet
325
+ replaced,
326
+ {
327
+ beforeWrite: () => {
328
+ logger.log(`🟡 Creating ${node.fullPath}`);
329
+ }
330
+ }
331
+ );
332
+ } else {
333
+ await utils.writeIfDifferent(
334
+ node.fullPath,
335
+ routeCode,
336
+ routeCode.replace(
337
+ /(createAPIFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
338
+ (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
339
+ ),
340
+ {
341
+ beforeWrite: () => {
342
+ logger.log(`🟡 Updating ${node.fullPath}`);
343
+ }
344
+ }
345
+ );
346
+ }
347
+ };
348
+ if (ENABLED_API_ROUTES_GENERATION) {
349
+ for (const node of startAPIRouteNodes) {
350
+ await handleAPINode(node);
351
+ }
352
+ }
339
353
  function buildRouteTreeConfig(nodes, depth = 1) {
340
354
  const children = nodes.map((node) => {
341
355
  var _a, _b;
@@ -382,21 +396,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
382
396
  },
383
397
  (d) => d
384
398
  ]);
385
- const typeImports = Object.entries({
386
- // Used for augmentation of regular routes
387
- CreateFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
388
- (d) => isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
389
- ),
390
- // Used for augmentation of lazy (`.lazy`) routes
391
- CreateLazyFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
392
- (node) => {
393
- var _a;
394
- return ((_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.lazy) && isRouteNodeValidForAugmentation(node);
395
- }
396
- ),
397
- // Used in the process of augmenting the routes
398
- FileRoutesByPath: config.verboseFileRoutes === false && sortedRouteNodes.some((d) => isRouteNodeValidForAugmentation(d))
399
- }).filter((d) => d[1]).map((d) => d[0]).sort((a, b) => a.localeCompare(b));
400
399
  const imports = Object.entries({
401
400
  createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),
402
401
  lazyFn: sortedRouteNodes.some(
@@ -429,20 +428,18 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
429
428
  `// This file was automatically generated by TanStack Router.
430
429
  // You should NOT make any changes in this file as it will be overwritten.
431
430
  // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
432
- [
433
- imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : "",
434
- !TYPES_DISABLED && typeImports.length ? `import type { ${typeImports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : ""
435
- ].filter(Boolean).join("\n"),
431
+ imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'
432
+ ` : "",
436
433
  "// Import Routes",
437
434
  [
438
435
  `import { Route as rootRoute } from './${getImportPath(rootRouteNode)}'`,
439
436
  ...sortedRouteNodes.filter((d) => !d.isVirtual).map((node) => {
440
- return `import { Route as ${node.variableName}RouteImport } from './${getImportPath(node)}'`;
437
+ return `import { Route as ${node.variableName}Import } from './${getImportPath(node)}'`;
441
438
  })
442
439
  ].join("\n"),
443
440
  virtualRouteNodes.length ? "// Create Virtual Routes" : "",
444
441
  virtualRouteNodes.map((node) => {
445
- return `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`;
442
+ return `const ${node.variableName}Import = createFileRoute('${node.routePath}')()`;
446
443
  }).join("\n"),
447
444
  "// Create/Update Routes",
448
445
  sortedRouteNodes.map((node) => {
@@ -453,54 +450,52 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
453
450
  const pendingComponentNode = (_d = routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
454
451
  const lazyComponentNode = (_e = routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
455
452
  return [
456
- [
457
- `const ${node.variableName}Route = ${node.variableName}RouteImport.update({
453
+ `const ${node.variableName}Route = ${node.variableName}Import.update({
458
454
  ${[
459
- `id: '${node.path}'`,
460
- !node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
461
- `getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
462
- ].filter(Boolean).join(",")}
455
+ `id: '${node.path}'`,
456
+ !node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
457
+ `getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
458
+ ].filter(Boolean).join(",")}
463
459
  }${TYPES_DISABLED ? "" : "as any"})`,
464
- loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${utils.replaceBackslash(
465
- utils.removeExt(
466
- path.relative(
467
- path.dirname(config.generatedRouteTree),
468
- path.resolve(config.routesDirectory, loaderNode.filePath)
469
- ),
470
- config.addExtensions
471
- )
472
- )}'), 'loader') })` : "",
473
- componentNode || errorComponentNode || pendingComponentNode ? `.update({
460
+ loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${utils.replaceBackslash(
461
+ utils.removeExt(
462
+ path.relative(
463
+ path.dirname(config.generatedRouteTree),
464
+ path.resolve(config.routesDirectory, loaderNode.filePath)
465
+ ),
466
+ config.addExtensions
467
+ )
468
+ )}'), 'loader') })` : "",
469
+ componentNode || errorComponentNode || pendingComponentNode ? `.update({
474
470
  ${[
475
- ["component", componentNode],
476
- ["errorComponent", errorComponentNode],
477
- ["pendingComponent", pendingComponentNode]
478
- ].filter((d) => d[1]).map((d) => {
479
- return `${d[0]}: lazyRouteComponent(() => import('./${utils.replaceBackslash(
480
- utils.removeExt(
481
- path.relative(
482
- path.dirname(config.generatedRouteTree),
483
- path.resolve(config.routesDirectory, d[1].filePath)
484
- ),
485
- config.addExtensions
486
- )
487
- )}'), '${d[0]}')`;
488
- }).join("\n,")}
489
- })` : "",
490
- lazyComponentNode ? `.lazy(() => import('./${utils.replaceBackslash(
471
+ ["component", componentNode],
472
+ ["errorComponent", errorComponentNode],
473
+ ["pendingComponent", pendingComponentNode]
474
+ ].filter((d) => d[1]).map((d) => {
475
+ return `${d[0]}: lazyRouteComponent(() => import('./${utils.replaceBackslash(
491
476
  utils.removeExt(
492
477
  path.relative(
493
478
  path.dirname(config.generatedRouteTree),
494
- path.resolve(
495
- config.routesDirectory,
496
- lazyComponentNode.filePath
497
- )
479
+ path.resolve(config.routesDirectory, d[1].filePath)
498
480
  ),
499
481
  config.addExtensions
500
482
  )
501
- )}').then((d) => d.Route))` : ""
502
- ].join("")
503
- ].join("\n\n");
483
+ )}'), '${d[0]}')`;
484
+ }).join("\n,")}
485
+ })` : "",
486
+ lazyComponentNode ? `.lazy(() => import('./${utils.replaceBackslash(
487
+ utils.removeExt(
488
+ path.relative(
489
+ path.dirname(config.generatedRouteTree),
490
+ path.resolve(
491
+ config.routesDirectory,
492
+ lazyComponentNode.filePath
493
+ )
494
+ ),
495
+ config.addExtensions
496
+ )
497
+ )}').then((d) => d.Route))` : ""
498
+ ].join("");
504
499
  }).join("\n\n"),
505
500
  ...TYPES_DISABLED ? [] : [
506
501
  "// Populate the FileRoutesByPath interface",
@@ -513,36 +508,13 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
513
508
  id: '${filePathId}'
514
509
  path: '${inferPath(routeNode)}'
515
510
  fullPath: '${inferFullPath(routeNode)}'
516
- preLoaderRoute: typeof ${routeNode.variableName}RouteImport
517
- parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${routeNode.parent.variableName}RouteImport` : "rootRoute"}
511
+ preLoaderRoute: typeof ${routeNode.variableName}Import
512
+ parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${routeNode.parent.variableName}Import` : "rootRoute"}
518
513
  }`;
519
514
  }).join("\n")}
520
515
  }
521
516
  }`
522
517
  ],
523
- ...TYPES_DISABLED ? [] : config.verboseFileRoutes !== false ? [] : [
524
- `// Add type-safety to the createFileRoute function across the route tree`,
525
- routeNodes.map((routeNode) => {
526
- var _a;
527
- function getModuleDeclaration(routeNode2) {
528
- if (!isRouteNodeValidForAugmentation(routeNode2)) {
529
- return "";
530
- }
531
- return `declare module './${getImportPath(routeNode2)}' {
532
- const ${routeNode2._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}: ${routeNode2._fsRouteType === "lazy" ? `CreateLazyFileRoute<FileRoutesByPath['${routeNode2.routePath}']['preLoaderRoute']>}` : `CreateFileRoute<
533
- '${routeNode2.routePath}',
534
- FileRoutesByPath['${routeNode2.routePath}']['parentRoute'],
535
- FileRoutesByPath['${routeNode2.routePath}']['id'],
536
- FileRoutesByPath['${routeNode2.routePath}']['path'],
537
- FileRoutesByPath['${routeNode2.routePath}']['fullPath']
538
- >
539
- }`}`;
540
- }
541
- return getModuleDeclaration(routeNode) + getModuleDeclaration(
542
- (_a = routePiecesByPath[routeNode.routePath]) == null ? void 0 : _a.lazy
543
- );
544
- }).join("\n")
545
- ],
546
518
  "// Create and export the route tree",
547
519
  routeConfigChildrenText,
548
520
  ...TYPES_DISABLED ? [] : [
@@ -559,7 +531,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
559
531
  })}
560
532
  }`,
561
533
  `export interface FileRoutesById {
562
- '${rootRouteId}': typeof rootRoute,
534
+ '__root__': typeof rootRoute,
563
535
  ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {
564
536
  return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
565
537
  })}
@@ -569,7 +541,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
569
541
  fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
570
542
  fileRoutesByTo: FileRoutesByTo
571
543
  to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
572
- id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
544
+ id: ${[`'__root__'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
573
545
  fileRoutesById: FileRoutesById
574
546
  }`,
575
547
  `export interface RootRouteChildren {
@@ -584,7 +556,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
584
556
  ].filter(Boolean).join("\n\n");
585
557
  const createRouteManifest = () => {
586
558
  const routesManifest = {
587
- [rootRouteId]: {
559
+ __root__: {
588
560
  filePath: rootRouteNode.filePath,
589
561
  children: routeTree.map((d) => d.routePath)
590
562
  },
@@ -651,12 +623,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId.rootPathId}.${config.di
651
623
  function removeGroups(s) {
652
624
  return s.replace(possiblyNestedRouteGroupPatternRegex, "");
653
625
  }
654
- function isRouteNodeValidForAugmentation(routeNode) {
655
- if (!routeNode || routeNode.isVirtual) {
656
- return false;
657
- }
658
- return true;
659
- }
660
626
  function determineNodePath(node) {
661
627
  var _a;
662
628
  return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath ?? "", "")) || "/" : node.routePath;
@@ -757,12 +723,58 @@ function checkRouteFullPathUniqueness(_routes, config) {
757
723
  const conflictingFiles = checkUnique(routes, "inferredFullPath");
758
724
  if (conflictingFiles !== void 0) {
759
725
  const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p.inferredFullPath}"`).join(", ")}.
760
- Please ensure each Route has a unique full path.
726
+ Please ensure each route has a unique full path.
727
+ Conflicting files:
728
+ ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
729
+ `;
730
+ throw new Error(errorMessage);
731
+ }
732
+ }
733
+ function checkStartAPIRoutes(_routes, config) {
734
+ if (_routes.length === 0) {
735
+ return [];
736
+ }
737
+ const routes = _routes.map((d) => {
738
+ const routePath = utils.removeTrailingSlash(d.routePath ?? "");
739
+ return { ...d, routePath };
740
+ });
741
+ const conflictingFiles = checkUnique(routes, "routePath");
742
+ if (conflictingFiles !== void 0) {
743
+ const errorMessage = `Conflicting configuration paths were found for the following API route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p}"`).join(", ")}.
744
+ Please ensure each API route has a unique route path.
761
745
  Conflicting files:
762
746
  ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
763
747
  `;
764
748
  throw new Error(errorMessage);
765
749
  }
750
+ return routes;
751
+ }
752
+ function startAPIRouteSegmentsFromTSRFilePath(src, config) {
753
+ const routePath = utils.determineInitialRoutePath(src);
754
+ const parts = routePath.replaceAll(".", "/").split("/").filter((p) => !!p && p !== config.indexToken);
755
+ const segments = parts.map((part) => {
756
+ if (part.startsWith("$")) {
757
+ if (part === "$") {
758
+ return { value: part, type: "splat" };
759
+ }
760
+ part.replaceAll("$", "");
761
+ return { value: part, type: "param" };
762
+ }
763
+ return { value: part, type: "path" };
764
+ });
765
+ return segments;
766
766
  }
767
+ exports.CONSTANTS = CONSTANTS;
768
+ exports.createRouteNodesByFullPath = createRouteNodesByFullPath;
769
+ exports.createRouteNodesById = createRouteNodesById;
770
+ exports.createRouteNodesByTo = createRouteNodesByTo;
771
+ exports.dedupeBranchesAndIndexRoutes = dedupeBranchesAndIndexRoutes;
767
772
  exports.generator = generator;
773
+ exports.getResolvedRouteNodeVariableName = getResolvedRouteNodeVariableName;
774
+ exports.hasParentRoute = hasParentRoute;
775
+ exports.inferFullPath = inferFullPath;
776
+ exports.inferPath = inferPath;
777
+ exports.inferTo = inferTo;
778
+ exports.removeLastSegmentFromPath = removeLastSegmentFromPath;
779
+ exports.startAPIRouteSegmentsFromTSRFilePath = startAPIRouteSegmentsFromTSRFilePath;
768
780
  //# sourceMappingURL=generator.cjs.map