@tanstack/router-generator 1.120.4-alpha.19 → 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
@@ -1,12 +1,15 @@
1
1
  import path from "node:path";
2
2
  import * as fs from "node:fs";
3
3
  import * as fsp from "node:fs/promises";
4
- import { logging, multiSortBy, replaceBackslash, removeExt, writeIfDifferent, format, resetRegex, trimPathLeft, removeUnderscores, routePathToVariable } from "./utils.js";
4
+ import { logging, multiSortBy, replaceBackslash, removeExt, writeIfDifferent, format, determineInitialRoutePath, resetRegex, trimPathLeft, removeUnderscores, routePathToVariable, removeTrailingSlash } from "./utils.js";
5
5
  import { getRouteNodes as getRouteNodes$1 } from "./filesystem/physical/getRouteNodes.js";
6
6
  import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
7
7
  import { rootPathId } from "./filesystem/physical/rootPathId.js";
8
- import { getTargetTemplate, fillTemplate } from "./template.js";
9
- const rootRouteId = "__root__";
8
+ import { getTargetTemplate, fillTemplate, defaultAPIRouteTemplate } from "./template.js";
9
+ const CONSTANTS = {
10
+ // When changing this, you'll want to update the import in `start-api-routes/src/index.ts#defaultAPIFileRouteHandler`
11
+ APIRouteExportVariable: "APIRoute"
12
+ };
10
13
  let latestTask = 0;
11
14
  const routeGroupPatternRegex = /\(.+\)/g;
12
15
  const possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
@@ -35,6 +38,7 @@ async function generator(config, root) {
35
38
  };
36
39
  const start = Date.now();
37
40
  const TYPES_DISABLED = config.disableTypes;
41
+ const ENABLED_API_ROUTES_GENERATION = config.__enableAPIRoutesGeneration ?? false;
38
42
  let getRouteNodesResult;
39
43
  if (config.virtualRouteConfig) {
40
44
  getRouteNodesResult = await getRouteNodes(config, root);
@@ -70,6 +74,23 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
70
74
  ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ""));
71
75
  const routeTree = [];
72
76
  const routePiecesByPath = {};
77
+ const onlyAPIRouteNodes = preRouteNodes.filter((d) => {
78
+ if (!ENABLED_API_ROUTES_GENERATION) {
79
+ return false;
80
+ }
81
+ if (d._fsRouteType !== "api") {
82
+ return false;
83
+ }
84
+ return true;
85
+ });
86
+ const onlyGeneratorRouteNodes = preRouteNodes.filter((d) => {
87
+ if (ENABLED_API_ROUTES_GENERATION) {
88
+ if (d._fsRouteType === "api") {
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ });
73
94
  const routeNodes = [];
74
95
  const handleRootNode = async (node) => {
75
96
  if (!node) {
@@ -134,7 +155,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
134
155
  (((_c = config.customScaffolding) == null ? void 0 : _c.lazyRouteTemplate) || ((_d = config.customScaffolding) == null ? void 0 : _d.routeTemplate)) ?? tLazyRouteTemplate.template(),
135
156
  {
136
157
  tsrImports: tLazyRouteTemplate.imports.tsrImports(),
137
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
158
+ tsrPath: escapedRoutePath,
138
159
  tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
139
160
  tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
140
161
  }
@@ -155,66 +176,16 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
155
176
  ((_e = config.customScaffolding) == null ? void 0 : _e.routeTemplate) ?? tRouteTemplate.template(),
156
177
  {
157
178
  tsrImports: tRouteTemplate.imports.tsrImports(),
158
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
179
+ tsrPath: escapedRoutePath,
159
180
  tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
160
181
  tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
161
182
  }
162
183
  );
163
184
  }
164
- } else if (config.verboseFileRoutes === false) {
165
- if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
166
- return;
167
- }
168
- replaced = routeCode.replace(
169
- /(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
170
- (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
171
- ).replace(
172
- new RegExp(
173
- `(import\\s*\\{)(.*)(create(Lazy)?FileRoute)(.*)(\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
174
- "gs"
175
- ),
176
- (_, p1, p2, ___, ____, p5, p6) => {
177
- const beforeCreateFileRoute = () => {
178
- if (!p2) return "";
179
- let trimmed = p2.trim();
180
- if (trimmed.endsWith(",")) {
181
- trimmed = trimmed.slice(0, -1);
182
- }
183
- return trimmed;
184
- };
185
- const afterCreateFileRoute = () => {
186
- if (!p5) return "";
187
- let trimmed = p5.trim();
188
- if (trimmed.startsWith(",")) {
189
- trimmed = trimmed.slice(1);
190
- }
191
- return trimmed;
192
- };
193
- const newImport = () => {
194
- const before = beforeCreateFileRoute();
195
- const after = afterCreateFileRoute();
196
- if (!before) return after;
197
- if (!after) return before;
198
- return `${before},${after}`;
199
- };
200
- const middle = newImport();
201
- if (middle === "") return "";
202
- return `${p1} ${newImport()} ${p6}`;
203
- }
204
- ).replace(
205
- /create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
206
- (_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}`
207
- );
208
185
  } else {
209
- if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
210
- return;
211
- }
212
186
  replaced = routeCode.replace(
213
187
  /(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
214
188
  (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
215
- ).replace(
216
- /((FileRoute)(\s*)(\({))/g,
217
- (_, __, p2, p3, p4) => `${p2}('${escapedRoutePath}')${p3}${p4}`
218
189
  ).replace(
219
190
  new RegExp(
220
191
  `(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
@@ -225,16 +196,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
225
196
  /create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
226
197
  (_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}${p2}${escapedRoutePath}${p4}`
227
198
  );
228
- const regex = new RegExp(
229
- `(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
230
- "gm"
231
- );
232
- if (!replaced.match(regex)) {
233
- replaced = [
234
- `import { ${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"} } from '@tanstack/${ROUTE_TEMPLATE.subPkg}'`,
235
- ...replaced.split("\n")
236
- ].join("\n");
237
- }
238
199
  }
239
200
  await writeIfDifferent(node.fullPath, routeCode, replaced, {
240
201
  beforeWrite: () => {
@@ -307,15 +268,68 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
307
268
  }
308
269
  routeNodes.push(node);
309
270
  };
310
- for (const node of preRouteNodes) {
271
+ for (const node of onlyGeneratorRouteNodes) {
311
272
  await handleNode(node);
312
273
  }
313
274
  checkRouteFullPathUniqueness(
314
275
  preRouteNodes.filter(
315
- (d) => d.children === void 0 && "lazy" !== d._fsRouteType
276
+ (d) => d.children === void 0 && ["api", "lazy"].every(
277
+ (type) => type !== d._fsRouteType
278
+ )
316
279
  ),
317
280
  config
318
281
  );
282
+ const startAPIRouteNodes = checkStartAPIRoutes(
283
+ onlyAPIRouteNodes,
284
+ config
285
+ );
286
+ const handleAPINode = async (node) => {
287
+ var _a, _b;
288
+ const routeCode = fs.readFileSync(node.fullPath, "utf-8");
289
+ const escapedRoutePath = ((_a = node.routePath) == null ? void 0 : _a.replaceAll("$", "$$")) ?? "";
290
+ if (!routeCode) {
291
+ const replaced = await fillTemplate(
292
+ config,
293
+ ((_b = config.customScaffolding) == null ? void 0 : _b.apiTemplate) ?? defaultAPIRouteTemplate,
294
+ {
295
+ tsrImports: "import { createAPIFileRoute } from '@tanstack/react-start/api';",
296
+ tsrPath: escapedRoutePath,
297
+ tsrExportStart: `export const ${CONSTANTS.APIRouteExportVariable} = createAPIFileRoute('${escapedRoutePath}')(`,
298
+ tsrExportEnd: ");"
299
+ }
300
+ );
301
+ await writeIfDifferent(
302
+ node.fullPath,
303
+ "",
304
+ // Empty string because the file doesn't exist yet
305
+ replaced,
306
+ {
307
+ beforeWrite: () => {
308
+ logger.log(`🟡 Creating ${node.fullPath}`);
309
+ }
310
+ }
311
+ );
312
+ } else {
313
+ await writeIfDifferent(
314
+ node.fullPath,
315
+ routeCode,
316
+ routeCode.replace(
317
+ /(createAPIFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
318
+ (_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
319
+ ),
320
+ {
321
+ beforeWrite: () => {
322
+ logger.log(`🟡 Updating ${node.fullPath}`);
323
+ }
324
+ }
325
+ );
326
+ }
327
+ };
328
+ if (ENABLED_API_ROUTES_GENERATION) {
329
+ for (const node of startAPIRouteNodes) {
330
+ await handleAPINode(node);
331
+ }
332
+ }
319
333
  function buildRouteTreeConfig(nodes, depth = 1) {
320
334
  const children = nodes.map((node) => {
321
335
  var _a, _b;
@@ -362,21 +376,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
362
376
  },
363
377
  (d) => d
364
378
  ]);
365
- const typeImports = Object.entries({
366
- // Used for augmentation of regular routes
367
- CreateFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
368
- (d) => isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
369
- ),
370
- // Used for augmentation of lazy (`.lazy`) routes
371
- CreateLazyFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
372
- (node) => {
373
- var _a;
374
- return ((_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.lazy) && isRouteNodeValidForAugmentation(node);
375
- }
376
- ),
377
- // Used in the process of augmenting the routes
378
- FileRoutesByPath: config.verboseFileRoutes === false && sortedRouteNodes.some((d) => isRouteNodeValidForAugmentation(d))
379
- }).filter((d) => d[1]).map((d) => d[0]).sort((a, b) => a.localeCompare(b));
380
379
  const imports = Object.entries({
381
380
  createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),
382
381
  lazyFn: sortedRouteNodes.some(
@@ -409,20 +408,18 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
409
408
  `// This file was automatically generated by TanStack Router.
410
409
  // You should NOT make any changes in this file as it will be overwritten.
411
410
  // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
412
- [
413
- imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : "",
414
- !TYPES_DISABLED && typeImports.length ? `import type { ${typeImports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : ""
415
- ].filter(Boolean).join("\n"),
411
+ imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'
412
+ ` : "",
416
413
  "// Import Routes",
417
414
  [
418
415
  `import { Route as rootRoute } from './${getImportPath(rootRouteNode)}'`,
419
416
  ...sortedRouteNodes.filter((d) => !d.isVirtual).map((node) => {
420
- return `import { Route as ${node.variableName}RouteImport } from './${getImportPath(node)}'`;
417
+ return `import { Route as ${node.variableName}Import } from './${getImportPath(node)}'`;
421
418
  })
422
419
  ].join("\n"),
423
420
  virtualRouteNodes.length ? "// Create Virtual Routes" : "",
424
421
  virtualRouteNodes.map((node) => {
425
- return `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`;
422
+ return `const ${node.variableName}Import = createFileRoute('${node.routePath}')()`;
426
423
  }).join("\n"),
427
424
  "// Create/Update Routes",
428
425
  sortedRouteNodes.map((node) => {
@@ -433,54 +430,52 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
433
430
  const pendingComponentNode = (_d = routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
434
431
  const lazyComponentNode = (_e = routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
435
432
  return [
436
- [
437
- `const ${node.variableName}Route = ${node.variableName}RouteImport.update({
433
+ `const ${node.variableName}Route = ${node.variableName}Import.update({
438
434
  ${[
439
- `id: '${node.path}'`,
440
- !node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
441
- `getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
442
- ].filter(Boolean).join(",")}
435
+ `id: '${node.path}'`,
436
+ !node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
437
+ `getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
438
+ ].filter(Boolean).join(",")}
443
439
  }${TYPES_DISABLED ? "" : "as any"})`,
444
- loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
445
- removeExt(
446
- path.relative(
447
- path.dirname(config.generatedRouteTree),
448
- path.resolve(config.routesDirectory, loaderNode.filePath)
449
- ),
450
- config.addExtensions
451
- )
452
- )}'), 'loader') })` : "",
453
- componentNode || errorComponentNode || pendingComponentNode ? `.update({
440
+ loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
441
+ removeExt(
442
+ path.relative(
443
+ path.dirname(config.generatedRouteTree),
444
+ path.resolve(config.routesDirectory, loaderNode.filePath)
445
+ ),
446
+ config.addExtensions
447
+ )
448
+ )}'), 'loader') })` : "",
449
+ componentNode || errorComponentNode || pendingComponentNode ? `.update({
454
450
  ${[
455
- ["component", componentNode],
456
- ["errorComponent", errorComponentNode],
457
- ["pendingComponent", pendingComponentNode]
458
- ].filter((d) => d[1]).map((d) => {
459
- return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
460
- removeExt(
461
- path.relative(
462
- path.dirname(config.generatedRouteTree),
463
- path.resolve(config.routesDirectory, d[1].filePath)
464
- ),
465
- config.addExtensions
466
- )
467
- )}'), '${d[0]}')`;
468
- }).join("\n,")}
469
- })` : "",
470
- lazyComponentNode ? `.lazy(() => import('./${replaceBackslash(
451
+ ["component", componentNode],
452
+ ["errorComponent", errorComponentNode],
453
+ ["pendingComponent", pendingComponentNode]
454
+ ].filter((d) => d[1]).map((d) => {
455
+ return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
471
456
  removeExt(
472
457
  path.relative(
473
458
  path.dirname(config.generatedRouteTree),
474
- path.resolve(
475
- config.routesDirectory,
476
- lazyComponentNode.filePath
477
- )
459
+ path.resolve(config.routesDirectory, d[1].filePath)
478
460
  ),
479
461
  config.addExtensions
480
462
  )
481
- )}').then((d) => d.Route))` : ""
482
- ].join("")
483
- ].join("\n\n");
463
+ )}'), '${d[0]}')`;
464
+ }).join("\n,")}
465
+ })` : "",
466
+ lazyComponentNode ? `.lazy(() => import('./${replaceBackslash(
467
+ removeExt(
468
+ path.relative(
469
+ path.dirname(config.generatedRouteTree),
470
+ path.resolve(
471
+ config.routesDirectory,
472
+ lazyComponentNode.filePath
473
+ )
474
+ ),
475
+ config.addExtensions
476
+ )
477
+ )}').then((d) => d.Route))` : ""
478
+ ].join("");
484
479
  }).join("\n\n"),
485
480
  ...TYPES_DISABLED ? [] : [
486
481
  "// Populate the FileRoutesByPath interface",
@@ -493,36 +488,13 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
493
488
  id: '${filePathId}'
494
489
  path: '${inferPath(routeNode)}'
495
490
  fullPath: '${inferFullPath(routeNode)}'
496
- preLoaderRoute: typeof ${routeNode.variableName}RouteImport
497
- 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"}
491
+ preLoaderRoute: typeof ${routeNode.variableName}Import
492
+ 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"}
498
493
  }`;
499
494
  }).join("\n")}
500
495
  }
501
496
  }`
502
497
  ],
503
- ...TYPES_DISABLED ? [] : config.verboseFileRoutes !== false ? [] : [
504
- `// Add type-safety to the createFileRoute function across the route tree`,
505
- routeNodes.map((routeNode) => {
506
- var _a;
507
- function getModuleDeclaration(routeNode2) {
508
- if (!isRouteNodeValidForAugmentation(routeNode2)) {
509
- return "";
510
- }
511
- return `declare module './${getImportPath(routeNode2)}' {
512
- const ${routeNode2._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}: ${routeNode2._fsRouteType === "lazy" ? `CreateLazyFileRoute<FileRoutesByPath['${routeNode2.routePath}']['preLoaderRoute']>}` : `CreateFileRoute<
513
- '${routeNode2.routePath}',
514
- FileRoutesByPath['${routeNode2.routePath}']['parentRoute'],
515
- FileRoutesByPath['${routeNode2.routePath}']['id'],
516
- FileRoutesByPath['${routeNode2.routePath}']['path'],
517
- FileRoutesByPath['${routeNode2.routePath}']['fullPath']
518
- >
519
- }`}`;
520
- }
521
- return getModuleDeclaration(routeNode) + getModuleDeclaration(
522
- (_a = routePiecesByPath[routeNode.routePath]) == null ? void 0 : _a.lazy
523
- );
524
- }).join("\n")
525
- ],
526
498
  "// Create and export the route tree",
527
499
  routeConfigChildrenText,
528
500
  ...TYPES_DISABLED ? [] : [
@@ -539,7 +511,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
539
511
  })}
540
512
  }`,
541
513
  `export interface FileRoutesById {
542
- '${rootRouteId}': typeof rootRoute,
514
+ '__root__': typeof rootRoute,
543
515
  ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {
544
516
  return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
545
517
  })}
@@ -549,7 +521,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
549
521
  fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
550
522
  fileRoutesByTo: FileRoutesByTo
551
523
  to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
552
- id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
524
+ id: ${[`'__root__'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
553
525
  fileRoutesById: FileRoutesById
554
526
  }`,
555
527
  `export interface RootRouteChildren {
@@ -564,7 +536,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
564
536
  ].filter(Boolean).join("\n\n");
565
537
  const createRouteManifest = () => {
566
538
  const routesManifest = {
567
- [rootRouteId]: {
539
+ __root__: {
568
540
  filePath: rootRouteNode.filePath,
569
541
  children: routeTree.map((d) => d.routePath)
570
542
  },
@@ -631,12 +603,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
631
603
  function removeGroups(s) {
632
604
  return s.replace(possiblyNestedRouteGroupPatternRegex, "");
633
605
  }
634
- function isRouteNodeValidForAugmentation(routeNode) {
635
- if (!routeNode || routeNode.isVirtual) {
636
- return false;
637
- }
638
- return true;
639
- }
640
606
  function determineNodePath(node) {
641
607
  var _a;
642
608
  return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath ?? "", "")) || "/" : node.routePath;
@@ -737,14 +703,60 @@ function checkRouteFullPathUniqueness(_routes, config) {
737
703
  const conflictingFiles = checkUnique(routes, "inferredFullPath");
738
704
  if (conflictingFiles !== void 0) {
739
705
  const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p.inferredFullPath}"`).join(", ")}.
740
- Please ensure each Route has a unique full path.
706
+ Please ensure each route has a unique full path.
707
+ Conflicting files:
708
+ ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
709
+ `;
710
+ throw new Error(errorMessage);
711
+ }
712
+ }
713
+ function checkStartAPIRoutes(_routes, config) {
714
+ if (_routes.length === 0) {
715
+ return [];
716
+ }
717
+ const routes = _routes.map((d) => {
718
+ const routePath = removeTrailingSlash(d.routePath ?? "");
719
+ return { ...d, routePath };
720
+ });
721
+ const conflictingFiles = checkUnique(routes, "routePath");
722
+ if (conflictingFiles !== void 0) {
723
+ const errorMessage = `Conflicting configuration paths were found for the following API route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p}"`).join(", ")}.
724
+ Please ensure each API route has a unique route path.
741
725
  Conflicting files:
742
726
  ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
743
727
  `;
744
728
  throw new Error(errorMessage);
745
729
  }
730
+ return routes;
731
+ }
732
+ function startAPIRouteSegmentsFromTSRFilePath(src, config) {
733
+ const routePath = determineInitialRoutePath(src);
734
+ const parts = routePath.replaceAll(".", "/").split("/").filter((p) => !!p && p !== config.indexToken);
735
+ const segments = parts.map((part) => {
736
+ if (part.startsWith("$")) {
737
+ if (part === "$") {
738
+ return { value: part, type: "splat" };
739
+ }
740
+ part.replaceAll("$", "");
741
+ return { value: part, type: "param" };
742
+ }
743
+ return { value: part, type: "path" };
744
+ });
745
+ return segments;
746
746
  }
747
747
  export {
748
- generator
748
+ CONSTANTS,
749
+ createRouteNodesByFullPath,
750
+ createRouteNodesById,
751
+ createRouteNodesByTo,
752
+ dedupeBranchesAndIndexRoutes,
753
+ generator,
754
+ getResolvedRouteNodeVariableName,
755
+ hasParentRoute,
756
+ inferFullPath,
757
+ inferPath,
758
+ inferTo,
759
+ removeLastSegmentFromPath,
760
+ startAPIRouteSegmentsFromTSRFilePath
749
761
  };
750
762
  //# sourceMappingURL=generator.js.map