@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.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +111 -147
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +224 -303
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -4
- package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/config.cjs +32 -30
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +164 -209
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +9 -8
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
- package/dist/cjs/generator.cjs +766 -1106
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/index.cjs +32 -34
- package/dist/cjs/logger.cjs +28 -34
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/template.cjs +144 -151
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/transform/transform.cjs +287 -426
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/utils.cjs +31 -33
- package/dist/cjs/transform/utils.cjs.map +1 -1
- package/dist/cjs/utils.cjs +534 -544
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/validate-route-params.cjs +66 -51
- package/dist/cjs/validate-route-params.cjs.map +1 -1
- package/dist/esm/config.js +106 -147
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.js +220 -286
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/physical/rootPathId.js +6 -5
- package/dist/esm/filesystem/physical/rootPathId.js.map +1 -1
- package/dist/esm/filesystem/virtual/config.js +31 -30
- package/dist/esm/filesystem/virtual/config.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.js +161 -208
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/loadConfigFile.js +7 -7
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
- package/dist/esm/generator.js +756 -1083
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.js +4 -31
- package/dist/esm/logger.js +29 -35
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/template.js +144 -152
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/transform/transform.js +285 -425
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/utils.js +31 -33
- package/dist/esm/transform/utils.js.map +1 -1
- package/dist/esm/utils.js +529 -564
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/validate-route-params.js +67 -52
- package/dist/esm/validate-route-params.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/index.cjs.map +0 -1
- 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
12
|
+
return virtualConfigFileRegExp.test(fileName);
|
|
12
13
|
}
|
|
13
14
|
async function getRouteNodes(config, root, tokenRegexes) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
//# sourceMappingURL=getRouteNodes.js.map
|
|
227
|
+
//#endregion
|
|
228
|
+
export { getRouteNodes, isVirtualConfigFile };
|
|
229
|
+
|
|
230
|
+
//# sourceMappingURL=getRouteNodes.js.map
|