@tanstack/router-generator 1.166.9 → 1.166.10

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 (58) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/cjs/config.cjs +111 -147
  3. package/dist/cjs/config.cjs.map +1 -1
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +224 -303
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
  6. package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -4
  7. package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -1
  8. package/dist/cjs/filesystem/virtual/config.cjs +32 -30
  9. package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
  10. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +164 -209
  11. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
  12. package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +9 -8
  13. package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
  14. package/dist/cjs/generator.cjs +766 -1106
  15. package/dist/cjs/generator.cjs.map +1 -1
  16. package/dist/cjs/index.cjs +32 -34
  17. package/dist/cjs/logger.cjs +28 -34
  18. package/dist/cjs/logger.cjs.map +1 -1
  19. package/dist/cjs/template.cjs +144 -151
  20. package/dist/cjs/template.cjs.map +1 -1
  21. package/dist/cjs/transform/transform.cjs +287 -426
  22. package/dist/cjs/transform/transform.cjs.map +1 -1
  23. package/dist/cjs/transform/utils.cjs +31 -33
  24. package/dist/cjs/transform/utils.cjs.map +1 -1
  25. package/dist/cjs/utils.cjs +534 -544
  26. package/dist/cjs/utils.cjs.map +1 -1
  27. package/dist/cjs/validate-route-params.cjs +66 -51
  28. package/dist/cjs/validate-route-params.cjs.map +1 -1
  29. package/dist/esm/config.js +106 -147
  30. package/dist/esm/config.js.map +1 -1
  31. package/dist/esm/filesystem/physical/getRouteNodes.js +220 -286
  32. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
  33. package/dist/esm/filesystem/physical/rootPathId.js +6 -5
  34. package/dist/esm/filesystem/physical/rootPathId.js.map +1 -1
  35. package/dist/esm/filesystem/virtual/config.js +31 -30
  36. package/dist/esm/filesystem/virtual/config.js.map +1 -1
  37. package/dist/esm/filesystem/virtual/getRouteNodes.js +161 -208
  38. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
  39. package/dist/esm/filesystem/virtual/loadConfigFile.js +7 -7
  40. package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
  41. package/dist/esm/generator.js +756 -1083
  42. package/dist/esm/generator.js.map +1 -1
  43. package/dist/esm/index.js +4 -31
  44. package/dist/esm/logger.js +29 -35
  45. package/dist/esm/logger.js.map +1 -1
  46. package/dist/esm/template.js +144 -152
  47. package/dist/esm/template.js.map +1 -1
  48. package/dist/esm/transform/transform.js +285 -425
  49. package/dist/esm/transform/transform.js.map +1 -1
  50. package/dist/esm/transform/utils.js +31 -33
  51. package/dist/esm/transform/utils.js.map +1 -1
  52. package/dist/esm/utils.js +529 -564
  53. package/dist/esm/utils.js.map +1 -1
  54. package/dist/esm/validate-route-params.js +67 -52
  55. package/dist/esm/validate-route-params.js.map +1 -1
  56. package/package.json +5 -5
  57. package/dist/cjs/index.cjs.map +0 -1
  58. package/dist/esm/index.js.map +0 -1
@@ -1,313 +1,234 @@
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 getRouteNodes$1 = require("../virtual/getRouteNodes.cjs");
7
- const loadConfigFile = require("../virtual/loadConfigFile.cjs");
8
- const logger = require("../../logger.cjs");
9
- const rootPathId = require("./rootPathId.cjs");
10
- function _interopNamespaceDefault(e) {
11
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
- if (e) {
13
- for (const k in e) {
14
- if (k !== "default") {
15
- const d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: () => e[k]
19
- });
20
- }
21
- }
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
- const fsp__namespace = /* @__PURE__ */ _interopNamespaceDefault(fsp);
27
- const disallowedRouteGroupConfiguration = /\(([^)]+)\).(ts|js|tsx|jsx|vue)/;
28
- const virtualConfigFileRegExp = /__virtual\.[mc]?[jt]s$/;
1
+ const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
2
+ const require_logger = require("../../logger.cjs");
3
+ require("./rootPathId.cjs");
4
+ const require_utils = require("../../utils.cjs");
5
+ const require_loadConfigFile = require("../virtual/loadConfigFile.cjs");
6
+ const require_getRouteNodes = require("../virtual/getRouteNodes.cjs");
7
+ let node_path = require("node:path");
8
+ node_path = require_runtime.__toESM(node_path);
9
+ let node_fs_promises = require("node:fs/promises");
10
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
11
+ //#region src/filesystem/physical/getRouteNodes.ts
12
+ var disallowedRouteGroupConfiguration = /\(([^)]+)\).(ts|js|tsx|jsx|vue)/;
13
+ var virtualConfigFileRegExp = /__virtual\.[mc]?[jt]s$/;
29
14
  function isVirtualConfigFile(fileName) {
30
- return virtualConfigFileRegExp.test(fileName);
15
+ return virtualConfigFileRegExp.test(fileName);
31
16
  }
32
17
  async function getRouteNodes(config, root, tokenRegexes) {
33
- const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } = config;
34
- const logger$1 = logger.logging({ disabled: config.disableLogging });
35
- const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? "", "g");
36
- const routeNodes = [];
37
- const allPhysicalDirectories = [];
38
- async function recurse(dir) {
39
- const fullDir = path.resolve(config.routesDirectory, dir);
40
- let dirList = await fsp__namespace.readdir(fullDir, { withFileTypes: true });
41
- dirList = dirList.filter((d) => {
42
- if (d.name.startsWith(".") || routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix)) {
43
- return false;
44
- }
45
- if (routeFilePrefix) {
46
- if (routeFileIgnorePattern) {
47
- return d.name.startsWith(routeFilePrefix) && !d.name.match(routeFileIgnoreRegExp);
48
- }
49
- return d.name.startsWith(routeFilePrefix);
50
- }
51
- if (routeFileIgnorePattern) {
52
- return !d.name.match(routeFileIgnoreRegExp);
53
- }
54
- return true;
55
- });
56
- const virtualConfigFile = dirList.find((dirent) => {
57
- return dirent.isFile() && isVirtualConfigFile(dirent.name);
58
- });
59
- if (virtualConfigFile !== void 0) {
60
- const virtualRouteConfigExport = await loadConfigFile.loadConfigFile(
61
- path.resolve(fullDir, virtualConfigFile.name)
62
- );
63
- let virtualRouteSubtreeConfig;
64
- if (typeof virtualRouteConfigExport.default === "function") {
65
- virtualRouteSubtreeConfig = await virtualRouteConfigExport.default();
66
- } else {
67
- virtualRouteSubtreeConfig = virtualRouteConfigExport.default;
68
- }
69
- const dummyRoot = {
70
- type: "root",
71
- file: "",
72
- children: virtualRouteSubtreeConfig
73
- };
74
- const { routeNodes: virtualRouteNodes, physicalDirectories } = await getRouteNodes$1.getRouteNodes(
75
- {
76
- ...config,
77
- routesDirectory: fullDir,
78
- virtualRouteConfig: dummyRoot
79
- },
80
- root,
81
- tokenRegexes
82
- );
83
- allPhysicalDirectories.push(...physicalDirectories);
84
- virtualRouteNodes.forEach((node) => {
85
- const filePath = utils.replaceBackslash(path.join(dir, node.filePath));
86
- const routePath = `/${dir}${node.routePath}`;
87
- node.variableName = utils.routePathToVariable(
88
- `${dir}/${utils.removeExt(node.filePath)}`
89
- );
90
- node.routePath = routePath;
91
- if (node.originalRoutePath) {
92
- node.originalRoutePath = `/${dir}${node.originalRoutePath}`;
93
- }
94
- node.filePath = filePath;
95
- delete node._virtualParentRoutePath;
96
- });
97
- routeNodes.push(...virtualRouteNodes);
98
- return;
99
- }
100
- await Promise.all(
101
- dirList.map(async (dirent) => {
102
- const fullPath = utils.replaceBackslash(path.join(fullDir, dirent.name));
103
- const relativePath = path.posix.join(dir, dirent.name);
104
- if (dirent.isDirectory()) {
105
- await recurse(relativePath);
106
- } else if (fullPath.match(/\.(tsx|ts|jsx|js|vue)$/)) {
107
- const filePath = utils.replaceBackslash(path.join(dir, dirent.name));
108
- const filePathNoExt = utils.removeExt(filePath);
109
- const {
110
- routePath: initialRoutePath,
111
- originalRoutePath: initialOriginalRoutePath
112
- } = utils.determineInitialRoutePath(filePathNoExt);
113
- let routePath = initialRoutePath;
114
- let originalRoutePath = initialOriginalRoutePath;
115
- if (routeFilePrefix) {
116
- routePath = routePath.replaceAll(routeFilePrefix, "");
117
- originalRoutePath = originalRoutePath.replaceAll(
118
- routeFilePrefix,
119
- ""
120
- );
121
- }
122
- if (disallowedRouteGroupConfiguration.test(dirent.name)) {
123
- 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?`;
124
- logger$1.error(`ERROR: ${errorMessage}`);
125
- throw new Error(errorMessage);
126
- }
127
- const meta = getRouteMeta(routePath, originalRoutePath, tokenRegexes);
128
- const variableName = meta.variableName;
129
- let routeType = meta.fsRouteType;
130
- if (routeType === "lazy") {
131
- routePath = routePath.replace(/\/lazy$/, "");
132
- originalRoutePath = originalRoutePath.replace(/\/lazy$/, "");
133
- }
134
- if (isValidPathlessLayoutRoute(
135
- routePath,
136
- originalRoutePath,
137
- routeType,
138
- tokenRegexes
139
- )) {
140
- routeType = "pathless_layout";
141
- }
142
- const isVueFile = filePath.endsWith(".vue");
143
- if (!isVueFile) {
144
- [
145
- ["component", "component"],
146
- ["errorComponent", "errorComponent"],
147
- ["notFoundComponent", "notFoundComponent"],
148
- ["pendingComponent", "pendingComponent"],
149
- ["loader", "loader"]
150
- ].forEach(([matcher, type]) => {
151
- if (routeType === matcher) {
152
- logger$1.warn(
153
- `WARNING: The \`.${type}.tsx\` suffix used for the ${filePath} file is deprecated. Use the new \`.lazy.tsx\` suffix instead.`
154
- );
155
- }
156
- });
157
- }
158
- const originalSegments = originalRoutePath.split("/").filter(Boolean);
159
- const lastOriginalSegmentForSuffix = originalSegments[originalSegments.length - 1] || "";
160
- const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
161
- const specialSuffixes = [
162
- "component",
163
- "errorComponent",
164
- "notFoundComponent",
165
- "pendingComponent",
166
- "loader",
167
- "lazy"
168
- ];
169
- const routePathSegments = routePath.split("/").filter(Boolean);
170
- const lastRouteSegment = routePathSegments[routePathSegments.length - 1] || "";
171
- const suffixToStrip = specialSuffixes.find((suffix) => {
172
- const endsWithSuffix = routePath.endsWith(`/${suffix}`);
173
- const isEscaped = lastOriginalSegmentForSuffix.startsWith("[") && lastOriginalSegmentForSuffix.endsWith("]") && utils.unwrapBracketWrappedSegment(lastOriginalSegmentForSuffix) === suffix;
174
- return endsWithSuffix && !isEscaped;
175
- });
176
- const routeTokenCandidate = utils.unwrapBracketWrappedSegment(
177
- lastOriginalSegmentForSuffix
178
- );
179
- const isRouteTokenEscaped = lastOriginalSegmentForSuffix !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
180
- const shouldStripRouteToken = routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped;
181
- if (suffixToStrip || shouldStripRouteToken) {
182
- const stripSegment = suffixToStrip ?? lastRouteSegment;
183
- routePath = routePath.replace(new RegExp(`/${stripSegment}$`), "");
184
- originalRoutePath = originalRoutePath.replace(
185
- new RegExp(`/${stripSegment}$`),
186
- ""
187
- );
188
- }
189
- const lastOriginalSegment = originalRoutePath.split("/").filter(Boolean).pop() || "";
190
- const indexTokenCandidate = utils.unwrapBracketWrappedSegment(lastOriginalSegment);
191
- const isIndexEscaped = lastOriginalSegment !== indexTokenCandidate && indexTokenSegmentRegex.test(indexTokenCandidate);
192
- if (!isIndexEscaped) {
193
- const updatedRouteSegments = routePath.split("/").filter(Boolean);
194
- const updatedLastRouteSegment = updatedRouteSegments[updatedRouteSegments.length - 1] || "";
195
- if (indexTokenSegmentRegex.test(updatedLastRouteSegment)) {
196
- if (routePathSegments.length === 1) {
197
- routePath = "/";
198
- }
199
- if (lastOriginalSegment === updatedLastRouteSegment) {
200
- originalRoutePath = "/";
201
- }
202
- const isLayoutRoute = routeType === "layout";
203
- routePath = routePath.replace(
204
- new RegExp(`/${updatedLastRouteSegment}$`),
205
- "/"
206
- ) || (isLayoutRoute ? "" : "/");
207
- originalRoutePath = originalRoutePath.replace(
208
- new RegExp(`/${indexTokenCandidate}$`),
209
- "/"
210
- ) || (isLayoutRoute ? "" : "/");
211
- }
212
- }
213
- routeNodes.push({
214
- filePath,
215
- fullPath,
216
- routePath,
217
- variableName,
218
- _fsRouteType: routeType,
219
- originalRoutePath
220
- });
221
- }
222
- })
223
- );
224
- return routeNodes;
225
- }
226
- await recurse("./");
227
- const rootRouteNode = routeNodes.find(
228
- (d) => d.routePath === `/${rootPathId.rootPathId}` && ![
229
- "component",
230
- "errorComponent",
231
- "notFoundComponent",
232
- "pendingComponent",
233
- "loader",
234
- "lazy"
235
- ].includes(d._fsRouteType)
236
- ) ?? routeNodes.find((d) => d.routePath === `/${rootPathId.rootPathId}`);
237
- if (rootRouteNode) {
238
- rootRouteNode._fsRouteType = "__root";
239
- rootRouteNode.variableName = "root";
240
- }
241
- return {
242
- rootRouteNode,
243
- routeNodes,
244
- physicalDirectories: allPhysicalDirectories
245
- };
18
+ const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } = config;
19
+ const logger = require_logger.logging({ disabled: config.disableLogging });
20
+ const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? "", "g");
21
+ const routeNodes = [];
22
+ const allPhysicalDirectories = [];
23
+ async function recurse(dir) {
24
+ const fullDir = node_path.default.resolve(config.routesDirectory, dir);
25
+ let dirList = await node_fs_promises.readdir(fullDir, { withFileTypes: true });
26
+ dirList = dirList.filter((d) => {
27
+ if (d.name.startsWith(".") || routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix)) return false;
28
+ if (routeFilePrefix) {
29
+ if (routeFileIgnorePattern) return d.name.startsWith(routeFilePrefix) && !d.name.match(routeFileIgnoreRegExp);
30
+ return d.name.startsWith(routeFilePrefix);
31
+ }
32
+ if (routeFileIgnorePattern) return !d.name.match(routeFileIgnoreRegExp);
33
+ return true;
34
+ });
35
+ const virtualConfigFile = dirList.find((dirent) => {
36
+ return dirent.isFile() && isVirtualConfigFile(dirent.name);
37
+ });
38
+ if (virtualConfigFile !== void 0) {
39
+ const virtualRouteConfigExport = await require_loadConfigFile.loadConfigFile(node_path.default.resolve(fullDir, virtualConfigFile.name));
40
+ let virtualRouteSubtreeConfig;
41
+ if (typeof virtualRouteConfigExport.default === "function") virtualRouteSubtreeConfig = await virtualRouteConfigExport.default();
42
+ else virtualRouteSubtreeConfig = virtualRouteConfigExport.default;
43
+ const dummyRoot = {
44
+ type: "root",
45
+ file: "",
46
+ children: virtualRouteSubtreeConfig
47
+ };
48
+ const { routeNodes: virtualRouteNodes, physicalDirectories } = await require_getRouteNodes.getRouteNodes({
49
+ ...config,
50
+ routesDirectory: fullDir,
51
+ virtualRouteConfig: dummyRoot
52
+ }, root, tokenRegexes);
53
+ allPhysicalDirectories.push(...physicalDirectories);
54
+ virtualRouteNodes.forEach((node) => {
55
+ const filePath = require_utils.replaceBackslash(node_path.default.join(dir, node.filePath));
56
+ const routePath = `/${dir}${node.routePath}`;
57
+ node.variableName = require_utils.routePathToVariable(`${dir}/${require_utils.removeExt(node.filePath)}`);
58
+ node.routePath = routePath;
59
+ if (node.originalRoutePath) node.originalRoutePath = `/${dir}${node.originalRoutePath}`;
60
+ node.filePath = filePath;
61
+ delete node._virtualParentRoutePath;
62
+ });
63
+ routeNodes.push(...virtualRouteNodes);
64
+ return;
65
+ }
66
+ await Promise.all(dirList.map(async (dirent) => {
67
+ const fullPath = require_utils.replaceBackslash(node_path.default.join(fullDir, dirent.name));
68
+ const relativePath = node_path.default.posix.join(dir, dirent.name);
69
+ if (dirent.isDirectory()) await recurse(relativePath);
70
+ else if (fullPath.match(/\.(tsx|ts|jsx|js|vue)$/)) {
71
+ const filePath = require_utils.replaceBackslash(node_path.default.join(dir, dirent.name));
72
+ const { routePath: initialRoutePath, originalRoutePath: initialOriginalRoutePath } = require_utils.determineInitialRoutePath(require_utils.removeExt(filePath));
73
+ let routePath = initialRoutePath;
74
+ let originalRoutePath = initialOriginalRoutePath;
75
+ if (routeFilePrefix) {
76
+ routePath = routePath.replaceAll(routeFilePrefix, "");
77
+ originalRoutePath = originalRoutePath.replaceAll(routeFilePrefix, "");
78
+ }
79
+ if (disallowedRouteGroupConfiguration.test(dirent.name)) {
80
+ 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?`;
81
+ logger.error(`ERROR: ${errorMessage}`);
82
+ throw new Error(errorMessage);
83
+ }
84
+ const meta = getRouteMeta(routePath, originalRoutePath, tokenRegexes);
85
+ const variableName = meta.variableName;
86
+ let routeType = meta.fsRouteType;
87
+ if (routeType === "lazy") {
88
+ routePath = routePath.replace(/\/lazy$/, "");
89
+ originalRoutePath = originalRoutePath.replace(/\/lazy$/, "");
90
+ }
91
+ if (isValidPathlessLayoutRoute(routePath, originalRoutePath, routeType, tokenRegexes)) routeType = "pathless_layout";
92
+ if (!filePath.endsWith(".vue")) [
93
+ ["component", "component"],
94
+ ["errorComponent", "errorComponent"],
95
+ ["notFoundComponent", "notFoundComponent"],
96
+ ["pendingComponent", "pendingComponent"],
97
+ ["loader", "loader"]
98
+ ].forEach(([matcher, type]) => {
99
+ if (routeType === matcher) logger.warn(`WARNING: The \`.${type}.tsx\` suffix used for the ${filePath} file is deprecated. Use the new \`.lazy.tsx\` suffix instead.`);
100
+ });
101
+ const originalSegments = originalRoutePath.split("/").filter(Boolean);
102
+ const lastOriginalSegmentForSuffix = originalSegments[originalSegments.length - 1] || "";
103
+ const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
104
+ const specialSuffixes = [
105
+ "component",
106
+ "errorComponent",
107
+ "notFoundComponent",
108
+ "pendingComponent",
109
+ "loader",
110
+ "lazy"
111
+ ];
112
+ const routePathSegments = routePath.split("/").filter(Boolean);
113
+ const lastRouteSegment = routePathSegments[routePathSegments.length - 1] || "";
114
+ const suffixToStrip = specialSuffixes.find((suffix) => {
115
+ const endsWithSuffix = routePath.endsWith(`/${suffix}`);
116
+ const isEscaped = lastOriginalSegmentForSuffix.startsWith("[") && lastOriginalSegmentForSuffix.endsWith("]") && require_utils.unwrapBracketWrappedSegment(lastOriginalSegmentForSuffix) === suffix;
117
+ return endsWithSuffix && !isEscaped;
118
+ });
119
+ const routeTokenCandidate = require_utils.unwrapBracketWrappedSegment(lastOriginalSegmentForSuffix);
120
+ const isRouteTokenEscaped = lastOriginalSegmentForSuffix !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
121
+ const shouldStripRouteToken = routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped;
122
+ if (suffixToStrip || shouldStripRouteToken) {
123
+ const stripSegment = suffixToStrip ?? lastRouteSegment;
124
+ routePath = routePath.replace(new RegExp(`/${stripSegment}$`), "");
125
+ originalRoutePath = originalRoutePath.replace(new RegExp(`/${stripSegment}$`), "");
126
+ }
127
+ const lastOriginalSegment = originalRoutePath.split("/").filter(Boolean).pop() || "";
128
+ const indexTokenCandidate = require_utils.unwrapBracketWrappedSegment(lastOriginalSegment);
129
+ if (!(lastOriginalSegment !== indexTokenCandidate && indexTokenSegmentRegex.test(indexTokenCandidate))) {
130
+ const updatedRouteSegments = routePath.split("/").filter(Boolean);
131
+ const updatedLastRouteSegment = updatedRouteSegments[updatedRouteSegments.length - 1] || "";
132
+ if (indexTokenSegmentRegex.test(updatedLastRouteSegment)) {
133
+ if (routePathSegments.length === 1) routePath = "/";
134
+ if (lastOriginalSegment === updatedLastRouteSegment) originalRoutePath = "/";
135
+ const isLayoutRoute = routeType === "layout";
136
+ routePath = routePath.replace(new RegExp(`/${updatedLastRouteSegment}$`), "/") || (isLayoutRoute ? "" : "/");
137
+ originalRoutePath = originalRoutePath.replace(new RegExp(`/${indexTokenCandidate}$`), "/") || (isLayoutRoute ? "" : "/");
138
+ }
139
+ }
140
+ routeNodes.push({
141
+ filePath,
142
+ fullPath,
143
+ routePath,
144
+ variableName,
145
+ _fsRouteType: routeType,
146
+ originalRoutePath
147
+ });
148
+ }
149
+ }));
150
+ return routeNodes;
151
+ }
152
+ await recurse("./");
153
+ const rootRouteNode = routeNodes.find((d) => d.routePath === `/__root` && ![
154
+ "component",
155
+ "errorComponent",
156
+ "notFoundComponent",
157
+ "pendingComponent",
158
+ "loader",
159
+ "lazy"
160
+ ].includes(d._fsRouteType)) ?? routeNodes.find((d) => d.routePath === `/__root`);
161
+ if (rootRouteNode) {
162
+ rootRouteNode._fsRouteType = "__root";
163
+ rootRouteNode.variableName = "root";
164
+ }
165
+ return {
166
+ rootRouteNode,
167
+ routeNodes,
168
+ physicalDirectories: allPhysicalDirectories
169
+ };
246
170
  }
171
+ /**
172
+ * Determines the metadata for a given route path based on the provided configuration.
173
+ *
174
+ * @param routePath - The determined initial routePath (with brackets removed).
175
+ * @param originalRoutePath - The original route path (may contain brackets for escaped content).
176
+ * @param tokenRegexes - Pre-compiled token regexes for matching.
177
+ * @returns An object containing the type of the route and the variable name derived from the route path.
178
+ */
247
179
  function getRouteMeta(routePath, originalRoutePath, tokenRegexes) {
248
- let fsRouteType = "static";
249
- const originalSegments = originalRoutePath.split("/").filter(Boolean);
250
- const lastOriginalSegment = originalSegments[originalSegments.length - 1] || "";
251
- const { routeTokenSegmentRegex } = tokenRegexes;
252
- const isSuffixEscaped = (suffix) => {
253
- return lastOriginalSegment.startsWith("[") && lastOriginalSegment.endsWith("]") && utils.unwrapBracketWrappedSegment(lastOriginalSegment) === suffix;
254
- };
255
- const routeSegments = routePath.split("/").filter(Boolean);
256
- const lastRouteSegment = routeSegments[routeSegments.length - 1] || "";
257
- const routeTokenCandidate = utils.unwrapBracketWrappedSegment(lastOriginalSegment);
258
- const isRouteTokenEscaped = lastOriginalSegment !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
259
- if (routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped) {
260
- fsRouteType = "layout";
261
- } else if (routePath.endsWith("/lazy") && !isSuffixEscaped("lazy")) {
262
- fsRouteType = "lazy";
263
- } else if (routePath.endsWith("/loader") && !isSuffixEscaped("loader")) {
264
- fsRouteType = "loader";
265
- } else if (routePath.endsWith("/component") && !isSuffixEscaped("component")) {
266
- fsRouteType = "component";
267
- } else if (routePath.endsWith("/pendingComponent") && !isSuffixEscaped("pendingComponent")) {
268
- fsRouteType = "pendingComponent";
269
- } else if (routePath.endsWith("/errorComponent") && !isSuffixEscaped("errorComponent")) {
270
- fsRouteType = "errorComponent";
271
- } else if (routePath.endsWith("/notFoundComponent") && !isSuffixEscaped("notFoundComponent")) {
272
- fsRouteType = "notFoundComponent";
273
- }
274
- const hasFullyEscapedSegment = originalSegments.some(
275
- (seg) => seg.startsWith("[") && seg.endsWith("]") && !seg.slice(1, -1).includes("[") && !seg.slice(1, -1).includes("]")
276
- );
277
- const variableName = utils.routePathToVariable(
278
- hasFullyEscapedSegment ? originalRoutePath : routePath
279
- );
280
- return { fsRouteType, variableName };
180
+ let fsRouteType = "static";
181
+ const originalSegments = originalRoutePath.split("/").filter(Boolean);
182
+ const lastOriginalSegment = originalSegments[originalSegments.length - 1] || "";
183
+ const { routeTokenSegmentRegex } = tokenRegexes;
184
+ const isSuffixEscaped = (suffix) => {
185
+ return lastOriginalSegment.startsWith("[") && lastOriginalSegment.endsWith("]") && require_utils.unwrapBracketWrappedSegment(lastOriginalSegment) === suffix;
186
+ };
187
+ const routeSegments = routePath.split("/").filter(Boolean);
188
+ const lastRouteSegment = routeSegments[routeSegments.length - 1] || "";
189
+ const routeTokenCandidate = require_utils.unwrapBracketWrappedSegment(lastOriginalSegment);
190
+ const isRouteTokenEscaped = lastOriginalSegment !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
191
+ if (routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped) fsRouteType = "layout";
192
+ else if (routePath.endsWith("/lazy") && !isSuffixEscaped("lazy")) fsRouteType = "lazy";
193
+ else if (routePath.endsWith("/loader") && !isSuffixEscaped("loader")) fsRouteType = "loader";
194
+ else if (routePath.endsWith("/component") && !isSuffixEscaped("component")) fsRouteType = "component";
195
+ else if (routePath.endsWith("/pendingComponent") && !isSuffixEscaped("pendingComponent")) fsRouteType = "pendingComponent";
196
+ else if (routePath.endsWith("/errorComponent") && !isSuffixEscaped("errorComponent")) fsRouteType = "errorComponent";
197
+ else if (routePath.endsWith("/notFoundComponent") && !isSuffixEscaped("notFoundComponent")) fsRouteType = "notFoundComponent";
198
+ const variableName = require_utils.routePathToVariable(originalSegments.some((seg) => seg.startsWith("[") && seg.endsWith("]") && !seg.slice(1, -1).includes("[") && !seg.slice(1, -1).includes("]")) ? originalRoutePath : routePath);
199
+ return {
200
+ fsRouteType,
201
+ variableName
202
+ };
281
203
  }
204
+ /**
205
+ * Used to validate if a route is a pathless layout route
206
+ * @param normalizedRoutePath Normalized route path, i.e `/foo/_layout/route.tsx` and `/foo._layout.route.tsx` to `/foo/_layout/route`
207
+ * @param originalRoutePath Original route path with brackets for escaped content
208
+ * @param routeType The route type determined from file extension
209
+ * @param tokenRegexes Pre-compiled token regexes for matching
210
+ * @returns Boolean indicating if the route is a pathless layout route
211
+ */
282
212
  function isValidPathlessLayoutRoute(normalizedRoutePath, originalRoutePath, routeType, tokenRegexes) {
283
- if (routeType === "lazy") {
284
- return false;
285
- }
286
- const segments = normalizedRoutePath.split("/").filter(Boolean);
287
- const originalSegments = originalRoutePath.split("/").filter(Boolean);
288
- if (segments.length === 0) {
289
- return false;
290
- }
291
- const lastRouteSegment = segments[segments.length - 1];
292
- const lastOriginalSegment = originalSegments[originalSegments.length - 1] || "";
293
- const secondToLastRouteSegment = segments[segments.length - 2];
294
- const secondToLastOriginalSegment = originalSegments[originalSegments.length - 2];
295
- if (lastRouteSegment === rootPathId.rootPathId) {
296
- return false;
297
- }
298
- const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
299
- if (routeTokenSegmentRegex.test(lastRouteSegment) && typeof secondToLastRouteSegment === "string" && typeof secondToLastOriginalSegment === "string") {
300
- if (utils.hasEscapedLeadingUnderscore(secondToLastOriginalSegment)) {
301
- return false;
302
- }
303
- return secondToLastRouteSegment.startsWith("_");
304
- }
305
- if (utils.hasEscapedLeadingUnderscore(lastOriginalSegment)) {
306
- return false;
307
- }
308
- return !indexTokenSegmentRegex.test(lastRouteSegment) && !routeTokenSegmentRegex.test(lastRouteSegment) && lastRouteSegment.startsWith("_");
213
+ if (routeType === "lazy") return false;
214
+ const segments = normalizedRoutePath.split("/").filter(Boolean);
215
+ const originalSegments = originalRoutePath.split("/").filter(Boolean);
216
+ if (segments.length === 0) return false;
217
+ const lastRouteSegment = segments[segments.length - 1];
218
+ const lastOriginalSegment = originalSegments[originalSegments.length - 1] || "";
219
+ const secondToLastRouteSegment = segments[segments.length - 2];
220
+ const secondToLastOriginalSegment = originalSegments[originalSegments.length - 2];
221
+ if (lastRouteSegment === "__root") return false;
222
+ const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
223
+ if (routeTokenSegmentRegex.test(lastRouteSegment) && typeof secondToLastRouteSegment === "string" && typeof secondToLastOriginalSegment === "string") {
224
+ if (require_utils.hasEscapedLeadingUnderscore(secondToLastOriginalSegment)) return false;
225
+ return secondToLastRouteSegment.startsWith("_");
226
+ }
227
+ if (require_utils.hasEscapedLeadingUnderscore(lastOriginalSegment)) return false;
228
+ return !indexTokenSegmentRegex.test(lastRouteSegment) && !routeTokenSegmentRegex.test(lastRouteSegment) && lastRouteSegment.startsWith("_");
309
229
  }
310
- exports.getRouteMeta = getRouteMeta;
230
+ //#endregion
311
231
  exports.getRouteNodes = getRouteNodes;
312
232
  exports.isVirtualConfigFile = isVirtualConfigFile;
313
- //# sourceMappingURL=getRouteNodes.cjs.map
233
+
234
+ //# sourceMappingURL=getRouteNodes.cjs.map