@tanstack/router-generator 1.51.6 → 1.54.0

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 (53) hide show
  1. package/dist/cjs/config.cjs +38 -14
  2. package/dist/cjs/config.cjs.map +1 -1
  3. package/dist/cjs/config.d.cts +9 -0
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +125 -0
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -0
  6. package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +3 -0
  7. package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -0
  8. package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -0
  9. package/dist/cjs/filesystem/physical/rootPathId.d.cts +1 -0
  10. package/dist/cjs/filesystem/virtual/config.cjs +37 -0
  11. package/dist/cjs/filesystem/virtual/config.cjs.map +1 -0
  12. package/dist/cjs/filesystem/virtual/config.d.cts +3 -0
  13. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +119 -0
  14. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -0
  15. package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +5 -0
  16. package/dist/cjs/generator.cjs +48 -171
  17. package/dist/cjs/generator.cjs.map +1 -1
  18. package/dist/cjs/generator.d.cts +2 -27
  19. package/dist/cjs/types.d.cts +27 -0
  20. package/dist/cjs/utils.cjs +34 -0
  21. package/dist/cjs/utils.cjs.map +1 -1
  22. package/dist/cjs/utils.d.cts +8 -0
  23. package/dist/esm/config.d.ts +9 -0
  24. package/dist/esm/config.js +24 -0
  25. package/dist/esm/config.js.map +1 -1
  26. package/dist/esm/filesystem/physical/getRouteNodes.d.ts +3 -0
  27. package/dist/esm/filesystem/physical/getRouteNodes.js +108 -0
  28. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -0
  29. package/dist/esm/filesystem/physical/rootPathId.d.ts +1 -0
  30. package/dist/esm/filesystem/physical/rootPathId.js +5 -0
  31. package/dist/esm/filesystem/physical/rootPathId.js.map +1 -0
  32. package/dist/esm/filesystem/virtual/config.d.ts +3 -0
  33. package/dist/esm/filesystem/virtual/config.js +37 -0
  34. package/dist/esm/filesystem/virtual/config.js.map +1 -0
  35. package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +5 -0
  36. package/dist/esm/filesystem/virtual/getRouteNodes.js +119 -0
  37. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -0
  38. package/dist/esm/generator.d.ts +2 -27
  39. package/dist/esm/generator.js +34 -157
  40. package/dist/esm/generator.js.map +1 -1
  41. package/dist/esm/types.d.ts +27 -0
  42. package/dist/esm/utils.d.ts +8 -0
  43. package/dist/esm/utils.js +34 -0
  44. package/dist/esm/utils.js.map +1 -1
  45. package/package.json +3 -2
  46. package/src/config.ts +25 -0
  47. package/src/filesystem/physical/getRouteNodes.ts +151 -0
  48. package/src/filesystem/physical/rootPathId.ts +1 -0
  49. package/src/filesystem/virtual/config.ts +45 -0
  50. package/src/filesystem/virtual/getRouteNodes.ts +141 -0
  51. package/src/generator.ts +52 -236
  52. package/src/types.ts +28 -0
  53. package/src/utils.ts +43 -0
@@ -3,7 +3,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const path = require("node:path");
4
4
  const fs = require("node:fs");
5
5
  const zod = require("zod");
6
+ const config = require("./filesystem/virtual/config.cjs");
6
7
  const configSchema = zod.z.object({
8
+ virtualRouteConfig: config.virtualRootRouteSchema.optional(),
7
9
  routeFilePrefix: zod.z.string().optional(),
8
10
  routeFileIgnorePrefix: zod.z.string().optional().default("-"),
9
11
  routeFileIgnorePattern: zod.z.string().optional(),
@@ -24,6 +26,8 @@ const configSchema = zod.z.object({
24
26
  ]),
25
27
  routeTreeFileFooter: zod.z.array(zod.z.string()).optional().default(["/* prettier-ignore-end */"]),
26
28
  autoCodeSplitting: zod.z.boolean().optional(),
29
+ indexToken: zod.z.string().optional().default("index"),
30
+ routeToken: zod.z.string().optional().default("route"),
27
31
  experimental: zod.z.object({
28
32
  // TODO: Remove this option in the next major release (v2).
29
33
  enableCodeSplitting: zod.z.boolean().optional()
@@ -35,45 +39,65 @@ function getConfig(inlineConfig = {}, configDirectory) {
35
39
  }
36
40
  const configFilePathJson = path.resolve(configDirectory, "tsr.config.json");
37
41
  const exists = fs.existsSync(configFilePathJson);
38
- let config;
42
+ let config2;
39
43
  if (exists) {
40
- config = configSchema.parse({
44
+ config2 = configSchema.parse({
41
45
  ...JSON.parse(fs.readFileSync(configFilePathJson, "utf-8")),
42
46
  ...inlineConfig
43
47
  });
44
48
  } else {
45
- config = configSchema.parse(inlineConfig);
49
+ config2 = configSchema.parse(inlineConfig);
46
50
  }
47
- if (config.disableTypes) {
48
- config.generatedRouteTree = config.generatedRouteTree.replace(
51
+ if (config2.disableTypes) {
52
+ config2.generatedRouteTree = config2.generatedRouteTree.replace(
49
53
  /\.(ts|tsx)$/,
50
54
  ".js"
51
55
  );
52
56
  }
53
57
  if (configDirectory) {
54
58
  if (path.isAbsolute(configDirectory)) {
55
- config.routesDirectory = path.resolve(
59
+ config2.routesDirectory = path.resolve(
56
60
  configDirectory,
57
- config.routesDirectory
61
+ config2.routesDirectory
58
62
  );
59
- config.generatedRouteTree = path.resolve(
63
+ config2.generatedRouteTree = path.resolve(
60
64
  configDirectory,
61
- config.generatedRouteTree
65
+ config2.generatedRouteTree
62
66
  );
63
67
  } else {
64
- config.routesDirectory = path.resolve(
68
+ config2.routesDirectory = path.resolve(
65
69
  process.cwd(),
66
70
  configDirectory,
67
- config.routesDirectory
71
+ config2.routesDirectory
68
72
  );
69
- config.generatedRouteTree = path.resolve(
73
+ config2.generatedRouteTree = path.resolve(
70
74
  process.cwd(),
71
75
  configDirectory,
72
- config.generatedRouteTree
76
+ config2.generatedRouteTree
73
77
  );
74
78
  }
75
79
  }
76
- return config;
80
+ validateConfig(config2);
81
+ return config2;
82
+ }
83
+ function validateConfig(config2) {
84
+ var _a;
85
+ if (typeof ((_a = config2.experimental) == null ? void 0 : _a.enableCodeSplitting) !== "undefined") {
86
+ const message = `
87
+ ------
88
+ ⚠️ ⚠️ ⚠️
89
+ ERROR: The "experimental.enableCodeSplitting" flag has been made stable and is now "autoCodeSplitting". Please update your configuration file to use "autoCodeSplitting" instead of "experimental.enableCodeSplitting".
90
+ ------
91
+ `;
92
+ console.error(message);
93
+ throw new Error(message);
94
+ }
95
+ if (config2.indexToken === config2.routeToken) {
96
+ throw new Error(
97
+ `The "indexToken" and "routeToken" options must be different.`
98
+ );
99
+ }
100
+ return config2;
77
101
  }
78
102
  exports.configSchema = configSchema;
79
103
  exports.getConfig = getConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs","sources":["../../src/config.ts"],"sourcesContent":["import path from 'node:path'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { z } from 'zod'\n\nexport const configSchema = z.object({\n routeFilePrefix: z.string().optional(),\n routeFileIgnorePrefix: z.string().optional().default('-'),\n routeFileIgnorePattern: z.string().optional(),\n routesDirectory: z.string().optional().default('./src/routes'),\n generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),\n quoteStyle: z.enum(['single', 'double']).optional().default('single'),\n semicolons: z.boolean().optional().default(false),\n disableTypes: z.boolean().optional().default(false),\n addExtensions: z.boolean().optional().default(false),\n disableLogging: z.boolean().optional().default(false),\n disableManifestGeneration: z.boolean().optional().default(false),\n apiBase: z.string().optional().default('/api'),\n routeTreeFileHeader: z\n .array(z.string())\n .optional()\n .default([\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n ]),\n routeTreeFileFooter: z\n .array(z.string())\n .optional()\n .default(['/* prettier-ignore-end */']),\n autoCodeSplitting: z.boolean().optional(),\n experimental: z\n .object({\n // TODO: Remove this option in the next major release (v2).\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nexport function getConfig(\n inlineConfig: Partial<Config> = {},\n configDirectory?: string,\n): Config {\n if (configDirectory === undefined) {\n configDirectory = process.cwd()\n }\n const configFilePathJson = path.resolve(configDirectory, 'tsr.config.json')\n const exists = existsSync(configFilePathJson)\n\n let config: Config\n\n if (exists) {\n config = configSchema.parse({\n ...JSON.parse(readFileSync(configFilePathJson, 'utf-8')),\n ...inlineConfig,\n })\n } else {\n config = configSchema.parse(inlineConfig)\n }\n\n // If typescript is disabled, make sure the generated route tree is a .js file\n if (config.disableTypes) {\n config.generatedRouteTree = config.generatedRouteTree.replace(\n /\\.(ts|tsx)$/,\n '.js',\n )\n }\n\n // if a configDirectory is used, paths should be relative to that directory\n if (configDirectory) {\n // if absolute configDirectory is provided, use it as the root\n if (path.isAbsolute(configDirectory)) {\n config.routesDirectory = path.resolve(\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n configDirectory,\n config.generatedRouteTree,\n )\n } else {\n config.routesDirectory = path.resolve(\n process.cwd(),\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n process.cwd(),\n configDirectory,\n config.generatedRouteTree,\n )\n }\n }\n\n return config\n}\n"],"names":["z","existsSync","readFileSync"],"mappings":";;;;;AAIa,MAAA,eAAeA,MAAE,OAAO;AAAA,EACnC,iBAAiBA,IAAA,EAAE,OAAO,EAAE,SAAS;AAAA,EACrC,uBAAuBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,GAAG;AAAA,EACxD,wBAAwBA,IAAA,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5C,iBAAiBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,cAAc;AAAA,EAC7D,oBAAoBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,wBAAwB;AAAA,EAC1E,YAAYA,IAAAA,EAAE,KAAK,CAAC,UAAU,QAAQ,CAAC,EAAE,SAAA,EAAW,QAAQ,QAAQ;AAAA,EACpE,YAAYA,IAAE,EAAA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cAAc;AAChB,WAAA,qBAAqB,OAAO,mBAAmB;AAAA,MACpD;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGA,MAAI,iBAAiB;AAEf,QAAA,KAAK,WAAW,eAAe,GAAG;AACpC,aAAO,kBAAkB,KAAK;AAAA,QAC5B;AAAA,QACA,OAAO;AAAA,MAAA;AAET,aAAO,qBAAqB,KAAK;AAAA,QAC/B;AAAA,QACA,OAAO;AAAA,MAAA;AAAA,IACT,OACK;AACL,aAAO,kBAAkB,KAAK;AAAA,QAC5B,QAAQ,IAAI;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MAAA;AAET,aAAO,qBAAqB,KAAK;AAAA,QAC/B,QAAQ,IAAI;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MAAA;AAAA,IAEX;AAAA,EACF;AAEO,SAAA;AACT;;;"}
1
+ {"version":3,"file":"config.cjs","sources":["../../src/config.ts"],"sourcesContent":["import path from 'node:path'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { z } from 'zod'\nimport { virtualRootRouteSchema } from './filesystem/virtual/config'\n\nexport const configSchema = z.object({\n virtualRouteConfig: virtualRootRouteSchema.optional(),\n routeFilePrefix: z.string().optional(),\n routeFileIgnorePrefix: z.string().optional().default('-'),\n routeFileIgnorePattern: z.string().optional(),\n routesDirectory: z.string().optional().default('./src/routes'),\n generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),\n quoteStyle: z.enum(['single', 'double']).optional().default('single'),\n semicolons: z.boolean().optional().default(false),\n disableTypes: z.boolean().optional().default(false),\n addExtensions: z.boolean().optional().default(false),\n disableLogging: z.boolean().optional().default(false),\n disableManifestGeneration: z.boolean().optional().default(false),\n apiBase: z.string().optional().default('/api'),\n routeTreeFileHeader: z\n .array(z.string())\n .optional()\n .default([\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n ]),\n routeTreeFileFooter: z\n .array(z.string())\n .optional()\n .default(['/* prettier-ignore-end */']),\n autoCodeSplitting: z.boolean().optional(),\n indexToken: z.string().optional().default('index'),\n routeToken: z.string().optional().default('route'),\n experimental: z\n .object({\n // TODO: Remove this option in the next major release (v2).\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nexport function getConfig(\n inlineConfig: Partial<Config> = {},\n configDirectory?: string,\n): Config {\n if (configDirectory === undefined) {\n configDirectory = process.cwd()\n }\n const configFilePathJson = path.resolve(configDirectory, 'tsr.config.json')\n const exists = existsSync(configFilePathJson)\n\n let config: Config\n\n if (exists) {\n config = configSchema.parse({\n ...JSON.parse(readFileSync(configFilePathJson, 'utf-8')),\n ...inlineConfig,\n })\n } else {\n config = configSchema.parse(inlineConfig)\n }\n\n // If typescript is disabled, make sure the generated route tree is a .js file\n if (config.disableTypes) {\n config.generatedRouteTree = config.generatedRouteTree.replace(\n /\\.(ts|tsx)$/,\n '.js',\n )\n }\n\n // if a configDirectory is used, paths should be relative to that directory\n if (configDirectory) {\n // if absolute configDirectory is provided, use it as the root\n if (path.isAbsolute(configDirectory)) {\n config.routesDirectory = path.resolve(\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n configDirectory,\n config.generatedRouteTree,\n )\n } else {\n config.routesDirectory = path.resolve(\n process.cwd(),\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n process.cwd(),\n configDirectory,\n config.generatedRouteTree,\n )\n }\n }\n\n validateConfig(config)\n return config\n}\n\nfunction validateConfig(config: Config) {\n if (typeof config.experimental?.enableCodeSplitting !== 'undefined') {\n const message = `\n------\n⚠️ ⚠️ ⚠️\nERROR: The \"experimental.enableCodeSplitting\" flag has been made stable and is now \"autoCodeSplitting\". Please update your configuration file to use \"autoCodeSplitting\" instead of \"experimental.enableCodeSplitting\".\n------\n`\n console.error(message)\n throw new Error(message)\n }\n\n if (config.indexToken === config.routeToken) {\n throw new Error(\n `The \"indexToken\" and \"routeToken\" options must be different.`,\n )\n }\n return config\n}\n"],"names":["z","virtualRootRouteSchema","existsSync","config","readFileSync"],"mappings":";;;;;;AAKa,MAAA,eAAeA,MAAE,OAAO;AAAA,EACnC,oBAAoBC,8BAAuB,SAAS;AAAA,EACpD,iBAAiBD,IAAA,EAAE,OAAO,EAAE,SAAS;AAAA,EACrC,uBAAuBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,GAAG;AAAA,EACxD,wBAAwBA,IAAA,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5C,iBAAiBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,cAAc;AAAA,EAC7D,oBAAoBA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,wBAAwB;AAAA,EAC1E,YAAYA,IAAAA,EAAE,KAAK,CAAC,UAAU,QAAQ,CAAC,EAAE,SAAA,EAAW,QAAQ,QAAQ;AAAA,EACpE,YAAYA,IAAE,EAAA,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EAChD,cAAcA,IAAE,EAAA,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EAClD,eAAeA,IAAE,EAAA,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EACnD,gBAAgBA,IAAE,EAAA,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EACpD,2BAA2BA,IAAE,EAAA,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EAC/D,SAASA,IAAE,EAAA,OAAA,EAAS,SAAS,EAAE,QAAQ,MAAM;AAAA,EAC7C,qBAAqBA,IAAAA,EAClB,MAAMA,IAAA,EAAE,QAAQ,EAChB,SAAS,EACT,QAAQ;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAAA,EACH,qBAAqBA,IAAA,EAClB,MAAMA,IAAAA,EAAE,OAAO,CAAC,EAChB,WACA,QAAQ,CAA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/B,QAAQ,IAAI;AAAA,QACZ;AAAA,QACAA,QAAO;AAAA,MAAA;AAAA,IAEX;AAAA,EACF;AAEA,iBAAeA,OAAM;AACd,SAAAA;AACT;AAEA,SAAS,eAAeA,SAAgB;;AACtC,MAAI,SAAO,KAAAA,QAAO,iBAAP,mBAAqB,yBAAwB,aAAa;AACnE,UAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAMhB,YAAQ,MAAM,OAAO;AACf,UAAA,IAAI,MAAM,OAAO;AAAA,EACzB;AAEI,MAAAA,QAAO,eAAeA,QAAO,YAAY;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACO,SAAAA;AACT;;;"}
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const configSchema: z.ZodObject<{
3
+ virtualRouteConfig: z.ZodOptional<z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>>;
3
4
  routeFilePrefix: z.ZodOptional<z.ZodString>;
4
5
  routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
5
6
  routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
@@ -15,6 +16,8 @@ export declare const configSchema: z.ZodObject<{
15
16
  routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
16
17
  routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
17
18
  autoCodeSplitting: z.ZodOptional<z.ZodBoolean>;
19
+ indexToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
20
+ routeToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
18
21
  experimental: z.ZodOptional<z.ZodObject<{
19
22
  enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
20
23
  }, "strip", z.ZodTypeAny, {
@@ -35,6 +38,9 @@ export declare const configSchema: z.ZodObject<{
35
38
  apiBase: string;
36
39
  routeTreeFileHeader: string[];
37
40
  routeTreeFileFooter: string[];
41
+ indexToken: string;
42
+ routeToken: string;
43
+ virtualRouteConfig?: import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
38
44
  routeFilePrefix?: string | undefined;
39
45
  routeFileIgnorePattern?: string | undefined;
40
46
  autoCodeSplitting?: boolean | undefined;
@@ -42,6 +48,7 @@ export declare const configSchema: z.ZodObject<{
42
48
  enableCodeSplitting?: boolean | undefined;
43
49
  } | undefined;
44
50
  }, {
51
+ virtualRouteConfig?: import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
45
52
  routeFilePrefix?: string | undefined;
46
53
  routeFileIgnorePrefix?: string | undefined;
47
54
  routeFileIgnorePattern?: string | undefined;
@@ -57,6 +64,8 @@ export declare const configSchema: z.ZodObject<{
57
64
  routeTreeFileHeader?: string[] | undefined;
58
65
  routeTreeFileFooter?: string[] | undefined;
59
66
  autoCodeSplitting?: boolean | undefined;
67
+ indexToken?: string | undefined;
68
+ routeToken?: string | undefined;
60
69
  experimental?: {
61
70
  enableCodeSplitting?: boolean | undefined;
62
71
  } | undefined;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
4
+ const fsp = require("node:fs/promises");
5
+ const utils = require("../../utils.cjs");
6
+ const rootPathId = require("./rootPathId.cjs");
7
+ function _interopNamespaceDefault(e) {
8
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
+ if (e) {
10
+ for (const k in e) {
11
+ if (k !== "default") {
12
+ const d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: () => e[k]
16
+ });
17
+ }
18
+ }
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+ const fsp__namespace = /* @__PURE__ */ _interopNamespaceDefault(fsp);
24
+ const disallowedRouteGroupConfiguration = /\(([^)]+)\).(ts|js|tsx|jsx)/;
25
+ async function getRouteNodes(config) {
26
+ const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } = config;
27
+ const logger = utils.logging({ disabled: config.disableLogging });
28
+ const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? "", "g");
29
+ const routeNodes = [];
30
+ async function recurse(dir) {
31
+ const fullDir = path.resolve(config.routesDirectory, dir);
32
+ let dirList = await fsp__namespace.readdir(fullDir, { withFileTypes: true });
33
+ dirList = dirList.filter((d) => {
34
+ if (d.name.startsWith(".") || routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix)) {
35
+ return false;
36
+ }
37
+ if (routeFilePrefix) {
38
+ return d.name.startsWith(routeFilePrefix);
39
+ }
40
+ if (routeFileIgnorePattern) {
41
+ return !d.name.match(routeFileIgnoreRegExp);
42
+ }
43
+ return true;
44
+ });
45
+ await Promise.all(
46
+ dirList.map(async (dirent) => {
47
+ const fullPath = path.join(fullDir, dirent.name);
48
+ const relativePath = path.join(dir, dirent.name);
49
+ if (dirent.isDirectory()) {
50
+ await recurse(relativePath);
51
+ } else if (fullPath.match(/\.(tsx|ts|jsx|js)$/)) {
52
+ const filePath = utils.replaceBackslash(path.join(dir, dirent.name));
53
+ const filePathNoExt = utils.removeExt(filePath);
54
+ let routePath = utils.determineInitialRoutePath(filePathNoExt);
55
+ if (routeFilePrefix) {
56
+ routePath = routePath.replaceAll(routeFilePrefix, "");
57
+ }
58
+ if (disallowedRouteGroupConfiguration.test(dirent.name)) {
59
+ const errorMessage = `A route configuration for a route group was found at \`${filePath}\`. This is not supported. Did you mean to use a layout/pathless route instead?`;
60
+ logger.error(`ERROR: ${errorMessage}`);
61
+ throw new Error(errorMessage);
62
+ }
63
+ const variableName = utils.routePathToVariable(routePath);
64
+ const isLazy = routePath.endsWith("/lazy");
65
+ if (isLazy) {
66
+ routePath = routePath.replace(/\/lazy$/, "");
67
+ }
68
+ const isRoute = routePath.endsWith(`/${config.routeToken}`);
69
+ const isComponent = routePath.endsWith("/component");
70
+ const isErrorComponent = routePath.endsWith("/errorComponent");
71
+ const isPendingComponent = routePath.endsWith("/pendingComponent");
72
+ const isLoader = routePath.endsWith("/loader");
73
+ const isAPIRoute = routePath.startsWith(
74
+ `${utils.removeTrailingSlash(config.apiBase)}/`
75
+ );
76
+ const segments = routePath.split("/");
77
+ const lastRouteSegment = segments[segments.length - 1];
78
+ const isLayout = lastRouteSegment !== config.indexToken && lastRouteSegment !== config.routeToken && (lastRouteSegment == null ? void 0 : lastRouteSegment.startsWith("_")) || false;
79
+ [
80
+ [isComponent, "component"],
81
+ [isErrorComponent, "errorComponent"],
82
+ [isPendingComponent, "pendingComponent"],
83
+ [isLoader, "loader"]
84
+ ].forEach(([isType, type]) => {
85
+ if (isType) {
86
+ logger.warn(
87
+ `WARNING: The \`.${type}.tsx\` suffix used for the ${filePath} file is deprecated. Use the new \`.lazy.tsx\` suffix instead.`
88
+ );
89
+ }
90
+ });
91
+ routePath = routePath.replace(
92
+ new RegExp(
93
+ `/(component|errorComponent|pendingComponent|loader|${config.routeToken}|lazy)$`
94
+ ),
95
+ ""
96
+ );
97
+ if (routePath === config.indexToken) {
98
+ routePath = "/";
99
+ }
100
+ routePath = routePath.replace(new RegExp(`/${config.indexToken}$`), "/") || "/";
101
+ routeNodes.push({
102
+ filePath,
103
+ fullPath,
104
+ routePath,
105
+ variableName,
106
+ isRoute,
107
+ isComponent,
108
+ isErrorComponent,
109
+ isPendingComponent,
110
+ isLoader,
111
+ isLazy,
112
+ isLayout,
113
+ isAPIRoute
114
+ });
115
+ }
116
+ })
117
+ );
118
+ return routeNodes;
119
+ }
120
+ await recurse("./");
121
+ const rootRouteNode = routeNodes.find((d) => d.routePath === `/${rootPathId.rootPathId}`);
122
+ return { rootRouteNode, routeNodes };
123
+ }
124
+ exports.getRouteNodes = getRouteNodes;
125
+ //# sourceMappingURL=getRouteNodes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRouteNodes.cjs","sources":["../../../../src/filesystem/physical/getRouteNodes.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport {\n determineInitialRoutePath,\n logging,\n removeExt,\n removeTrailingSlash,\n replaceBackslash,\n routePathToVariable,\n} from '../../utils'\nimport { rootPathId } from './rootPathId'\nimport type { GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\n\nconst disallowedRouteGroupConfiguration = /\\(([^)]+)\\).(ts|js|tsx|jsx)/\n\nexport async function getRouteNodes(\n config: Config,\n): Promise<GetRouteNodesResult> {\n const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } =\n config\n const logger = logging({ disabled: config.disableLogging })\n const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? '', 'g')\n\n const routeNodes: Array<RouteNode> = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n if (routeFileIgnorePattern) {\n return !d.name.match(routeFileIgnoreRegExp)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath = determineInitialRoutePath(filePathNoExt)\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n }\n\n if (disallowedRouteGroupConfiguration.test(dirent.name)) {\n const errorMessage = `A route configuration for a route group was found at \\`${filePath}\\`. This is not supported. Did you mean to use a layout/pathless route instead?`\n logger.error(`ERROR: ${errorMessage}`)\n throw new Error(errorMessage)\n }\n\n const variableName = routePathToVariable(routePath)\n\n const isLazy = routePath.endsWith('/lazy')\n\n if (isLazy) {\n routePath = routePath.replace(/\\/lazy$/, '')\n }\n\n const isRoute = routePath.endsWith(`/${config.routeToken}`)\n const isComponent = routePath.endsWith('/component')\n const isErrorComponent = routePath.endsWith('/errorComponent')\n const isPendingComponent = routePath.endsWith('/pendingComponent')\n const isLoader = routePath.endsWith('/loader')\n const isAPIRoute = routePath.startsWith(\n `${removeTrailingSlash(config.apiBase)}/`,\n )\n\n const segments = routePath.split('/')\n const lastRouteSegment = segments[segments.length - 1]\n const isLayout =\n (lastRouteSegment !== config.indexToken &&\n lastRouteSegment !== config.routeToken &&\n lastRouteSegment?.startsWith('_')) ||\n false\n\n ;(\n [\n [isComponent, 'component'],\n [isErrorComponent, 'errorComponent'],\n [isPendingComponent, 'pendingComponent'],\n [isLoader, 'loader'],\n ] as const\n ).forEach(([isType, type]) => {\n if (isType) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n\n routePath = routePath.replace(\n new RegExp(\n `/(component|errorComponent|pendingComponent|loader|${config.routeToken}|lazy)$`,\n ),\n '',\n )\n\n if (routePath === config.indexToken) {\n routePath = '/'\n }\n\n routePath =\n routePath.replace(new RegExp(`/${config.indexToken}$`), '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\n isLazy,\n isLayout,\n isAPIRoute,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n const rootRouteNode = routeNodes.find((d) => d.routePath === `/${rootPathId}`)\n return { rootRouteNode, routeNodes }\n}\n"],"names":["logging","fsp","replaceBackslash","removeExt","determineInitialRoutePath","routePathToVariable","removeTrailingSlash","rootPathId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U,QAAQ,IAAI,OAAO,IAAI,OAAO,UAAU,GAAG,GAAG,GAAG,KAAK;AAElE,qBAAW,KAAK;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA,CACD;AAAA,QACH;AAAA,MAAA,CACD;AAAA,IAAA;AAGI,WAAA;AAAA,EACT;AAEA,QAAM,QAAQ,IAAI;AAEZ,QAAA,gBAAgB,WAAW,KAAK,CAAC,MAAM,EAAE,cAAc,IAAIC,WAAU,UAAA,EAAE;AACtE,SAAA,EAAE,eAAe;AAC1B;;"}
@@ -0,0 +1,3 @@
1
+ import { GetRouteNodesResult } from '../../types';
2
+ import { Config } from '../../config';
3
+ export declare function getRouteNodes(config: Config): Promise<GetRouteNodesResult>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const rootPathId = "__root";
4
+ exports.rootPathId = rootPathId;
5
+ //# sourceMappingURL=rootPathId.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rootPathId.cjs","sources":["../../../../src/filesystem/physical/rootPathId.ts"],"sourcesContent":["export const rootPathId = '__root'\n"],"names":[],"mappings":";;AAAO,MAAM,aAAa;;"}
@@ -0,0 +1 @@
1
+ export declare const rootPathId = "__root";
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const zod = require("zod");
4
+ const indexRouteSchema = zod.z.object({
5
+ type: zod.z.literal("index"),
6
+ file: zod.z.string()
7
+ });
8
+ const layoutRouteSchema = zod.z.object({
9
+ type: zod.z.literal("layout"),
10
+ id: zod.z.string(),
11
+ file: zod.z.string(),
12
+ children: zod.z.array(zod.z.lazy(() => virtualRouteNodeSchema)).optional()
13
+ });
14
+ const routeSchema = zod.z.object({
15
+ type: zod.z.literal("route"),
16
+ file: zod.z.string(),
17
+ path: zod.z.string(),
18
+ children: zod.z.array(zod.z.lazy(() => virtualRouteNodeSchema)).optional()
19
+ });
20
+ const physicalSubTreeSchema = zod.z.object({
21
+ type: zod.z.literal("physical"),
22
+ directory: zod.z.string(),
23
+ pathPrefix: zod.z.string()
24
+ });
25
+ const virtualRouteNodeSchema = zod.z.union([
26
+ indexRouteSchema,
27
+ layoutRouteSchema,
28
+ routeSchema,
29
+ physicalSubTreeSchema
30
+ ]);
31
+ const virtualRootRouteSchema = zod.z.object({
32
+ type: zod.z.literal("root"),
33
+ file: zod.z.string(),
34
+ children: zod.z.array(virtualRouteNodeSchema).optional()
35
+ });
36
+ exports.virtualRootRouteSchema = virtualRootRouteSchema;
37
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs","sources":["../../../../src/filesystem/virtual/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport type {\n LayoutRoute,\n PhysicalSubtree,\n Route,\n VirtualRootRoute,\n} from '@tanstack/virtual-file-routes'\n\nconst indexRouteSchema = z.object({\n type: z.literal('index'),\n file: z.string(),\n})\n\nconst layoutRouteSchema: z.ZodType<LayoutRoute> = z.object({\n type: z.literal('layout'),\n id: z.string(),\n file: z.string(),\n children: z.array(z.lazy(() => virtualRouteNodeSchema)).optional(),\n})\n\nconst routeSchema: z.ZodType<Route> = z.object({\n type: z.literal('route'),\n file: z.string(),\n path: z.string(),\n children: z.array(z.lazy(() => virtualRouteNodeSchema)).optional(),\n})\n\nconst physicalSubTreeSchema: z.ZodType<PhysicalSubtree> = z.object({\n type: z.literal('physical'),\n directory: z.string(),\n pathPrefix: z.string(),\n})\n\nconst virtualRouteNodeSchema = z.union([\n indexRouteSchema,\n layoutRouteSchema,\n routeSchema,\n physicalSubTreeSchema,\n])\n\nexport const virtualRootRouteSchema: z.ZodType<VirtualRootRoute> = z.object({\n type: z.literal('root'),\n file: z.string(),\n children: z.array(virtualRouteNodeSchema).optional(),\n})\n"],"names":["z"],"mappings":";;;AAQA,MAAM,mBAAmBA,MAAE,OAAO;AAAA,EAChC,MAAMA,IAAAA,EAAE,QAAQ,OAAO;AAAA,EACvB,MAAMA,MAAE,OAAO;AACjB,CAAC;AAED,MAAM,oBAA4CA,MAAE,OAAO;AAAA,EACzD,MAAMA,IAAAA,EAAE,QAAQ,QAAQ;AAAA,EACxB,IAAIA,MAAE,OAAO;AAAA,EACb,MAAMA,MAAE,OAAO;AAAA,EACf,UAAUA,IAAAA,EAAE,MAAMA,IAAA,EAAE,KAAK,MAAM,sBAAsB,CAAC,EAAE,SAAS;AACnE,CAAC;AAED,MAAM,cAAgCA,MAAE,OAAO;AAAA,EAC7C,MAAMA,IAAAA,EAAE,QAAQ,OAAO;AAAA,EACvB,MAAMA,MAAE,OAAO;AAAA,EACf,MAAMA,MAAE,OAAO;AAAA,EACf,UAAUA,IAAAA,EAAE,MAAMA,IAAA,EAAE,KAAK,MAAM,sBAAsB,CAAC,EAAE,SAAS;AACnE,CAAC;AAED,MAAM,wBAAoDA,MAAE,OAAO;AAAA,EACjE,MAAMA,IAAAA,EAAE,QAAQ,UAAU;AAAA,EAC1B,WAAWA,MAAE,OAAO;AAAA,EACpB,YAAYA,MAAE,OAAO;AACvB,CAAC;AAED,MAAM,yBAAyBA,MAAE,MAAM;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEY,MAAA,yBAAsDA,MAAE,OAAO;AAAA,EAC1E,MAAMA,IAAAA,EAAE,QAAQ,MAAM;AAAA,EACtB,MAAMA,MAAE,OAAO;AAAA,EACf,UAAUA,IAAAA,EAAE,MAAM,sBAAsB,EAAE,SAAS;AACrD,CAAC;;"}
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+ import { VirtualRootRoute } from '@tanstack/virtual-file-routes';
3
+ export declare const virtualRootRouteSchema: z.ZodType<VirtualRootRoute>;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
4
+ const utils = require("../../utils.cjs");
5
+ const getRouteNodes$1 = require("../physical/getRouteNodes.cjs");
6
+ function ensureLeadingUnderScore(id) {
7
+ if (id.startsWith("_")) {
8
+ return id;
9
+ }
10
+ return `_${id}`;
11
+ }
12
+ function flattenTree(node) {
13
+ const result = [node];
14
+ if (node.children) {
15
+ for (const child of node.children) {
16
+ result.push(...flattenTree(child));
17
+ }
18
+ }
19
+ delete node.children;
20
+ return result;
21
+ }
22
+ async function getRouteNodes(tsrConfig) {
23
+ const fullDir = path.resolve(tsrConfig.routesDirectory);
24
+ if (tsrConfig.virtualRouteConfig === void 0) {
25
+ throw new Error(`virtualRouteConfig is undefined`);
26
+ }
27
+ const children = await getRouteNodesRecursive(
28
+ tsrConfig,
29
+ fullDir,
30
+ tsrConfig.virtualRouteConfig.children
31
+ );
32
+ const allNodes = flattenTree({
33
+ children,
34
+ filePath: tsrConfig.virtualRouteConfig.file,
35
+ fullPath: path.join(fullDir, tsrConfig.virtualRouteConfig.file),
36
+ variableName: "rootRoute",
37
+ routePath: "/",
38
+ isRoot: true
39
+ });
40
+ const rootRouteNode = allNodes[0];
41
+ const routeNodes = allNodes.slice(1);
42
+ return { rootRouteNode, routeNodes };
43
+ }
44
+ async function getRouteNodesRecursive(tsrConfig, fullDir, nodes, parent) {
45
+ if (nodes === void 0) {
46
+ return [];
47
+ }
48
+ const children = await Promise.all(
49
+ nodes.map(async (node) => {
50
+ if (node.type === "physical") {
51
+ const { routeNodes } = await getRouteNodes$1.getRouteNodes({
52
+ ...tsrConfig,
53
+ routesDirectory: path.resolve(fullDir, node.directory)
54
+ });
55
+ routeNodes.forEach((subtreeNode) => {
56
+ subtreeNode.variableName = utils.routePathToVariable(
57
+ `${node.pathPrefix}/${utils.removeExt(subtreeNode.filePath)}`
58
+ );
59
+ subtreeNode.routePath = `${(parent == null ? void 0 : parent.routePath) ?? ""}${node.pathPrefix}${subtreeNode.routePath}`;
60
+ subtreeNode.filePath = `${node.directory}/${subtreeNode.filePath}`;
61
+ });
62
+ return routeNodes;
63
+ }
64
+ const filePath = node.file;
65
+ const variableName = utils.routePathToVariable(utils.removeExt(filePath));
66
+ const fullPath = path.join(fullDir, filePath);
67
+ const parentRoutePath = utils.removeTrailingSlash((parent == null ? void 0 : parent.routePath) ?? "/");
68
+ const isLayout = node.type === "layout";
69
+ switch (node.type) {
70
+ case "index": {
71
+ const routePath = `${parentRoutePath}/`;
72
+ return {
73
+ filePath,
74
+ fullPath,
75
+ variableName,
76
+ routePath,
77
+ isLayout
78
+ };
79
+ }
80
+ case "route":
81
+ case "layout": {
82
+ let lastSegment;
83
+ if (node.type === "layout") {
84
+ if (node.id !== void 0) {
85
+ node.id = ensureLeadingUnderScore(node.id);
86
+ } else {
87
+ node.id = "_layout";
88
+ }
89
+ lastSegment = node.id;
90
+ } else {
91
+ lastSegment = node.path;
92
+ }
93
+ const routePath = `${parentRoutePath}/${utils.removeLeadingSlash(lastSegment)}`;
94
+ const routeNode = {
95
+ fullPath,
96
+ isLayout,
97
+ filePath,
98
+ variableName,
99
+ routePath
100
+ };
101
+ if (node.children !== void 0) {
102
+ const children2 = await getRouteNodesRecursive(
103
+ tsrConfig,
104
+ fullDir,
105
+ node.children,
106
+ routeNode
107
+ );
108
+ routeNode.children = children2;
109
+ }
110
+ return routeNode;
111
+ }
112
+ }
113
+ })
114
+ );
115
+ return children.flat();
116
+ }
117
+ exports.getRouteNodes = getRouteNodes;
118
+ exports.getRouteNodesRecursive = getRouteNodesRecursive;
119
+ //# sourceMappingURL=getRouteNodes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRouteNodes.cjs","sources":["../../../../src/filesystem/virtual/getRouteNodes.ts"],"sourcesContent":["import { join, resolve } from 'node:path'\nimport {\n removeExt,\n removeLeadingSlash,\n removeTrailingSlash,\n routePathToVariable,\n} from '../../utils'\nimport { getRouteNodes as getRouteNodesPhysical } from '../physical/getRouteNodes'\nimport type { VirtualRouteNode } from '@tanstack/virtual-file-routes'\nimport type { GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\n\nfunction ensureLeadingUnderScore(id: string) {\n if (id.startsWith('_')) {\n return id\n }\n return `_${id}`\n}\n\nfunction flattenTree(node: RouteNode): Array<RouteNode> {\n const result = [node]\n\n if (node.children) {\n for (const child of node.children) {\n result.push(...flattenTree(child))\n }\n }\n delete node.children\n\n return result\n}\n\nexport async function getRouteNodes(\n tsrConfig: Config,\n): Promise<GetRouteNodesResult> {\n const fullDir = resolve(tsrConfig.routesDirectory)\n if (tsrConfig.virtualRouteConfig === undefined) {\n throw new Error(`virtualRouteConfig is undefined`)\n }\n const children = await getRouteNodesRecursive(\n tsrConfig,\n fullDir,\n tsrConfig.virtualRouteConfig.children,\n )\n const allNodes = flattenTree({\n children,\n filePath: tsrConfig.virtualRouteConfig.file,\n fullPath: join(fullDir, tsrConfig.virtualRouteConfig.file),\n variableName: 'rootRoute',\n routePath: '/',\n isRoot: true,\n })\n\n const rootRouteNode = allNodes[0]\n const routeNodes = allNodes.slice(1)\n\n return { rootRouteNode, routeNodes }\n}\n\nexport async function getRouteNodesRecursive(\n tsrConfig: Config,\n fullDir: string,\n nodes?: Array<VirtualRouteNode>,\n parent?: RouteNode,\n): Promise<Array<RouteNode>> {\n if (nodes === undefined) {\n return []\n }\n const children = await Promise.all(\n nodes.map(async (node) => {\n if (node.type === 'physical') {\n const { routeNodes } = await getRouteNodesPhysical({\n ...tsrConfig,\n routesDirectory: resolve(fullDir, node.directory),\n })\n routeNodes.forEach((subtreeNode) => {\n subtreeNode.variableName = routePathToVariable(\n `${node.pathPrefix}/${removeExt(subtreeNode.filePath)}`,\n )\n subtreeNode.routePath = `${parent?.routePath ?? ''}${node.pathPrefix}${subtreeNode.routePath}`\n subtreeNode.filePath = `${node.directory}/${subtreeNode.filePath}`\n })\n return routeNodes\n }\n\n const filePath = node.file\n const variableName = routePathToVariable(removeExt(filePath))\n const fullPath = join(fullDir, filePath)\n const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/')\n const isLayout = node.type === 'layout'\n switch (node.type) {\n case 'index': {\n const routePath = `${parentRoutePath}/`\n return {\n filePath,\n fullPath,\n variableName,\n routePath,\n isLayout,\n } satisfies RouteNode\n }\n\n case 'route':\n case 'layout': {\n let lastSegment: string\n if (node.type === 'layout') {\n if (node.id !== undefined) {\n node.id = ensureLeadingUnderScore(node.id)\n } else {\n node.id = '_layout'\n }\n lastSegment = node.id\n } else {\n lastSegment = node.path\n }\n const routePath = `${parentRoutePath}/${removeLeadingSlash(lastSegment)}`\n\n const routeNode: RouteNode = {\n fullPath,\n isLayout,\n filePath,\n variableName,\n routePath,\n }\n\n if (node.children !== undefined) {\n const children = await getRouteNodesRecursive(\n tsrConfig,\n fullDir,\n node.children,\n routeNode,\n )\n routeNode.children = children\n }\n return routeNode\n }\n }\n }),\n )\n return children.flat()\n}\n"],"names":["resolve","join","getRouteNodesPhysical","routePathToVariable","removeExt","removeTrailingSlash","removeLeadingSlash","children"],"mappings":";;;;;AAYA,SAAS,wBAAwB,IAAY;AACvC,MAAA,GAAG,WAAW,GAAG,GAAG;AACf,WAAA;AAAA,EACT;AACA,SAAO,IAAI,EAAE;AACf;AAEA,SAAS,YAAY,MAAmC;AAChD,QAAA,SAAS,CAAC,IAAI;AAEpB,MAAI,KAAK,UAAU;AACN,eAAA,SAAS,KAAK,UAAU;AACjC,aAAO,KAAK,GAAG,YAAY,KAAK,CAAC;AAAA,IACnC;AAAA,EACF;AACA,SAAO,KAAK;AAEL,SAAA;AACT;AAEA,eAAsB,cACpB,WAC8B;AACxB,QAAA,UAAUA,KAAAA,QAAQ,UAAU,eAAe;AAC7C,MAAA,UAAU,uBAAuB,QAAW;AACxC,UAAA,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,QAAM,WAAW,MAAM;AAAA,IACrB;AAAA,IACA;AAAA,IACA,UAAU,mBAAmB;AAAA,EAAA;AAE/B,QA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AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,QAEA,KAAK;AAAA,QACL,KAAK,UAAU;AACT,cAAA;AACA,cAAA,KAAK,SAAS,UAAU;AACtB,gBAAA,KAAK,OAAO,QAAW;AACpB,mBAAA,KAAK,wBAAwB,KAAK,EAAE;AAAA,YAAA,OACpC;AACL,mBAAK,KAAK;AAAA,YACZ;AACA,0BAAc,KAAK;AAAA,UAAA,OACd;AACL,0BAAc,KAAK;AAAA,UACrB;AACA,gBAAM,YAAY,GAAG,eAAe,IAAIC,yBAAmB,WAAW,CAAC;AAEvE,gBAAM,YAAuB;AAAA,YAC3B;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAGE,cAAA,KAAK,aAAa,QAAW;AAC/B,kBAAMC,YAAW,MAAM;AAAA,cACrB;AAAA,cACA;AAAA,cACA,KAAK;AAAA,cACL;AAAA,YAAA;AAEF,sBAAU,WAAWA;AAAAA,UACvB;AACO,iBAAA;AAAA,QACT;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EAAA;AAEH,SAAO,SAAS;AAClB;;;"}
@@ -0,0 +1,5 @@
1
+ import { VirtualRouteNode } from '@tanstack/virtual-file-routes';
2
+ import { GetRouteNodesResult, RouteNode } from '../../types';
3
+ import { Config } from '../../config';
4
+ export declare function getRouteNodes(tsrConfig: Config): Promise<GetRouteNodesResult>;
5
+ export declare function getRouteNodesRecursive(tsrConfig: Config, fullDir: string, nodes?: Array<VirtualRouteNode>, parent?: RouteNode): Promise<Array<RouteNode>>;