@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.
- 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,313 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
15
|
+
return virtualConfigFileRegExp.test(fileName);
|
|
31
16
|
}
|
|
32
17
|
async function getRouteNodes(config, root, tokenRegexes) {
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
230
|
+
//#endregion
|
|
311
231
|
exports.getRouteNodes = getRouteNodes;
|
|
312
232
|
exports.isVirtualConfigFile = isVirtualConfigFile;
|
|
313
|
-
|
|
233
|
+
|
|
234
|
+
//# sourceMappingURL=getRouteNodes.cjs.map
|