@tanstack/router-generator 1.166.9 → 1.166.11

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