@tanstack/router-generator 1.120.5 → 1.121.0-alpha.1
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/config.cjs +14 -14
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +68 -31
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +1 -5
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +2 -2
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +2 -2
- package/dist/cjs/generator.cjs +160 -172
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +0 -59
- package/dist/cjs/index.cjs +23 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +8 -4
- package/dist/cjs/template.cjs +4 -12
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/template.d.cts +0 -1
- package/dist/cjs/types.d.cts +1 -1
- package/dist/cjs/utils.cjs +64 -5
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +11 -2
- package/dist/esm/config.d.ts +68 -31
- package/dist/esm/config.js +14 -14
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.d.ts +2 -2
- package/dist/esm/filesystem/physical/getRouteNodes.js +2 -6
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +2 -2
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/generator.d.ts +0 -59
- package/dist/esm/generator.js +163 -175
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.d.ts +8 -4
- package/dist/esm/index.js +25 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/template.d.ts +0 -1
- package/dist/esm/template.js +4 -12
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/utils.d.ts +11 -2
- package/dist/esm/utils.js +63 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/config.ts +14 -11
- package/src/filesystem/physical/getRouteNodes.ts +13 -14
- package/src/filesystem/virtual/getRouteNodes.ts +18 -3
- package/src/generator.ts +242 -221
- package/src/index.ts +32 -7
- package/src/template.ts +4 -15
- package/src/types.ts +0 -1
- package/src/utils.ts +102 -6
package/dist/esm/generator.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as fsp from "node:fs/promises";
|
|
4
|
-
import { logging, multiSortBy, replaceBackslash, removeExt, writeIfDifferent, format,
|
|
4
|
+
import { logging, multiSortBy, replaceBackslash, removeExt, writeIfDifferent, format, resetRegex, trimPathLeft, removeUnderscores, routePathToVariable } from "./utils.js";
|
|
5
5
|
import { getRouteNodes as getRouteNodes$1 } from "./filesystem/physical/getRouteNodes.js";
|
|
6
6
|
import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
|
|
7
7
|
import { rootPathId } from "./filesystem/physical/rootPathId.js";
|
|
8
|
-
import { getTargetTemplate, fillTemplate
|
|
9
|
-
const
|
|
10
|
-
// When changing this, you'll want to update the import in `start-api-routes/src/index.ts#defaultAPIFileRouteHandler`
|
|
11
|
-
APIRouteExportVariable: "APIRoute"
|
|
12
|
-
};
|
|
8
|
+
import { getTargetTemplate, fillTemplate } from "./template.js";
|
|
9
|
+
const rootRouteId = "__root__";
|
|
13
10
|
let latestTask = 0;
|
|
14
11
|
const routeGroupPatternRegex = /\(.+\)/g;
|
|
15
12
|
const possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
|
|
@@ -38,7 +35,6 @@ async function generator(config, root) {
|
|
|
38
35
|
};
|
|
39
36
|
const start = Date.now();
|
|
40
37
|
const TYPES_DISABLED = config.disableTypes;
|
|
41
|
-
const ENABLED_API_ROUTES_GENERATION = config.__enableAPIRoutesGeneration ?? false;
|
|
42
38
|
let getRouteNodesResult;
|
|
43
39
|
if (config.virtualRouteConfig) {
|
|
44
40
|
getRouteNodesResult = await getRouteNodes(config, root);
|
|
@@ -74,23 +70,6 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
74
70
|
]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ""));
|
|
75
71
|
const routeTree = [];
|
|
76
72
|
const routePiecesByPath = {};
|
|
77
|
-
const onlyAPIRouteNodes = preRouteNodes.filter((d) => {
|
|
78
|
-
if (!ENABLED_API_ROUTES_GENERATION) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
if (d._fsRouteType !== "api") {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
});
|
|
86
|
-
const onlyGeneratorRouteNodes = preRouteNodes.filter((d) => {
|
|
87
|
-
if (ENABLED_API_ROUTES_GENERATION) {
|
|
88
|
-
if (d._fsRouteType === "api") {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
});
|
|
94
73
|
const routeNodes = [];
|
|
95
74
|
const handleRootNode = async (node) => {
|
|
96
75
|
if (!node) {
|
|
@@ -155,7 +134,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
155
134
|
(((_c = config.customScaffolding) == null ? void 0 : _c.lazyRouteTemplate) || ((_d = config.customScaffolding) == null ? void 0 : _d.routeTemplate)) ?? tLazyRouteTemplate.template(),
|
|
156
135
|
{
|
|
157
136
|
tsrImports: tLazyRouteTemplate.imports.tsrImports(),
|
|
158
|
-
tsrPath: escapedRoutePath,
|
|
137
|
+
tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
|
|
159
138
|
tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
|
|
160
139
|
tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
|
|
161
140
|
}
|
|
@@ -176,16 +155,66 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
176
155
|
((_e = config.customScaffolding) == null ? void 0 : _e.routeTemplate) ?? tRouteTemplate.template(),
|
|
177
156
|
{
|
|
178
157
|
tsrImports: tRouteTemplate.imports.tsrImports(),
|
|
179
|
-
tsrPath: escapedRoutePath,
|
|
158
|
+
tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
|
|
180
159
|
tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
|
|
181
160
|
tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
|
|
182
161
|
}
|
|
183
162
|
);
|
|
184
163
|
}
|
|
164
|
+
} else if (config.verboseFileRoutes === false) {
|
|
165
|
+
if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
replaced = routeCode.replace(
|
|
169
|
+
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
170
|
+
(_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
171
|
+
).replace(
|
|
172
|
+
new RegExp(
|
|
173
|
+
`(import\\s*\\{)(.*)(create(Lazy)?FileRoute)(.*)(\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
|
|
174
|
+
"gs"
|
|
175
|
+
),
|
|
176
|
+
(_, p1, p2, ___, ____, p5, p6) => {
|
|
177
|
+
const beforeCreateFileRoute = () => {
|
|
178
|
+
if (!p2) return "";
|
|
179
|
+
let trimmed = p2.trim();
|
|
180
|
+
if (trimmed.endsWith(",")) {
|
|
181
|
+
trimmed = trimmed.slice(0, -1);
|
|
182
|
+
}
|
|
183
|
+
return trimmed;
|
|
184
|
+
};
|
|
185
|
+
const afterCreateFileRoute = () => {
|
|
186
|
+
if (!p5) return "";
|
|
187
|
+
let trimmed = p5.trim();
|
|
188
|
+
if (trimmed.startsWith(",")) {
|
|
189
|
+
trimmed = trimmed.slice(1);
|
|
190
|
+
}
|
|
191
|
+
return trimmed;
|
|
192
|
+
};
|
|
193
|
+
const newImport = () => {
|
|
194
|
+
const before = beforeCreateFileRoute();
|
|
195
|
+
const after = afterCreateFileRoute();
|
|
196
|
+
if (!before) return after;
|
|
197
|
+
if (!after) return before;
|
|
198
|
+
return `${before},${after}`;
|
|
199
|
+
};
|
|
200
|
+
const middle = newImport();
|
|
201
|
+
if (middle === "") return "";
|
|
202
|
+
return `${p1} ${newImport()} ${p6}`;
|
|
203
|
+
}
|
|
204
|
+
).replace(
|
|
205
|
+
/create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
206
|
+
(_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}`
|
|
207
|
+
);
|
|
185
208
|
} else {
|
|
209
|
+
if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const Route"))) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
186
212
|
replaced = routeCode.replace(
|
|
187
213
|
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
188
214
|
(_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
215
|
+
).replace(
|
|
216
|
+
/((FileRoute)(\s*)(\({))/g,
|
|
217
|
+
(_, __, p2, p3, p4) => `${p2}('${escapedRoutePath}')${p3}${p4}`
|
|
189
218
|
).replace(
|
|
190
219
|
new RegExp(
|
|
191
220
|
`(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
|
|
@@ -196,6 +225,16 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
196
225
|
/create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
197
226
|
(_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}${p2}${escapedRoutePath}${p4}`
|
|
198
227
|
);
|
|
228
|
+
const regex = new RegExp(
|
|
229
|
+
`(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
|
|
230
|
+
"gm"
|
|
231
|
+
);
|
|
232
|
+
if (!replaced.match(regex)) {
|
|
233
|
+
replaced = [
|
|
234
|
+
`import { ${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"} } from '@tanstack/${ROUTE_TEMPLATE.subPkg}'`,
|
|
235
|
+
...replaced.split("\n")
|
|
236
|
+
].join("\n");
|
|
237
|
+
}
|
|
199
238
|
}
|
|
200
239
|
await writeIfDifferent(node.fullPath, routeCode, replaced, {
|
|
201
240
|
beforeWrite: () => {
|
|
@@ -268,68 +307,15 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
268
307
|
}
|
|
269
308
|
routeNodes.push(node);
|
|
270
309
|
};
|
|
271
|
-
for (const node of
|
|
310
|
+
for (const node of preRouteNodes) {
|
|
272
311
|
await handleNode(node);
|
|
273
312
|
}
|
|
274
313
|
checkRouteFullPathUniqueness(
|
|
275
314
|
preRouteNodes.filter(
|
|
276
|
-
(d) => d.children === void 0 &&
|
|
277
|
-
(type) => type !== d._fsRouteType
|
|
278
|
-
)
|
|
315
|
+
(d) => d.children === void 0 && "lazy" !== d._fsRouteType
|
|
279
316
|
),
|
|
280
317
|
config
|
|
281
318
|
);
|
|
282
|
-
const startAPIRouteNodes = checkStartAPIRoutes(
|
|
283
|
-
onlyAPIRouteNodes,
|
|
284
|
-
config
|
|
285
|
-
);
|
|
286
|
-
const handleAPINode = async (node) => {
|
|
287
|
-
var _a, _b;
|
|
288
|
-
const routeCode = fs.readFileSync(node.fullPath, "utf-8");
|
|
289
|
-
const escapedRoutePath = ((_a = node.routePath) == null ? void 0 : _a.replaceAll("$", "$$")) ?? "";
|
|
290
|
-
if (!routeCode) {
|
|
291
|
-
const replaced = await fillTemplate(
|
|
292
|
-
config,
|
|
293
|
-
((_b = config.customScaffolding) == null ? void 0 : _b.apiTemplate) ?? defaultAPIRouteTemplate,
|
|
294
|
-
{
|
|
295
|
-
tsrImports: "import { createAPIFileRoute } from '@tanstack/react-start/api';",
|
|
296
|
-
tsrPath: escapedRoutePath,
|
|
297
|
-
tsrExportStart: `export const ${CONSTANTS.APIRouteExportVariable} = createAPIFileRoute('${escapedRoutePath}')(`,
|
|
298
|
-
tsrExportEnd: ");"
|
|
299
|
-
}
|
|
300
|
-
);
|
|
301
|
-
await writeIfDifferent(
|
|
302
|
-
node.fullPath,
|
|
303
|
-
"",
|
|
304
|
-
// Empty string because the file doesn't exist yet
|
|
305
|
-
replaced,
|
|
306
|
-
{
|
|
307
|
-
beforeWrite: () => {
|
|
308
|
-
logger.log(`🟡 Creating ${node.fullPath}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
} else {
|
|
313
|
-
await writeIfDifferent(
|
|
314
|
-
node.fullPath,
|
|
315
|
-
routeCode,
|
|
316
|
-
routeCode.replace(
|
|
317
|
-
/(createAPIFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
318
|
-
(_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
319
|
-
),
|
|
320
|
-
{
|
|
321
|
-
beforeWrite: () => {
|
|
322
|
-
logger.log(`🟡 Updating ${node.fullPath}`);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
if (ENABLED_API_ROUTES_GENERATION) {
|
|
329
|
-
for (const node of startAPIRouteNodes) {
|
|
330
|
-
await handleAPINode(node);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
319
|
function buildRouteTreeConfig(nodes, depth = 1) {
|
|
334
320
|
const children = nodes.map((node) => {
|
|
335
321
|
var _a, _b;
|
|
@@ -376,6 +362,21 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
376
362
|
},
|
|
377
363
|
(d) => d
|
|
378
364
|
]);
|
|
365
|
+
const typeImports = Object.entries({
|
|
366
|
+
// Used for augmentation of regular routes
|
|
367
|
+
CreateFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
|
|
368
|
+
(d) => isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
|
|
369
|
+
),
|
|
370
|
+
// Used for augmentation of lazy (`.lazy`) routes
|
|
371
|
+
CreateLazyFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
|
|
372
|
+
(node) => {
|
|
373
|
+
var _a;
|
|
374
|
+
return ((_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.lazy) && isRouteNodeValidForAugmentation(node);
|
|
375
|
+
}
|
|
376
|
+
),
|
|
377
|
+
// Used in the process of augmenting the routes
|
|
378
|
+
FileRoutesByPath: config.verboseFileRoutes === false && sortedRouteNodes.some((d) => isRouteNodeValidForAugmentation(d))
|
|
379
|
+
}).filter((d) => d[1]).map((d) => d[0]).sort((a, b) => a.localeCompare(b));
|
|
379
380
|
const imports = Object.entries({
|
|
380
381
|
createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),
|
|
381
382
|
lazyFn: sortedRouteNodes.some(
|
|
@@ -408,18 +409,20 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
408
409
|
`// This file was automatically generated by TanStack Router.
|
|
409
410
|
// You should NOT make any changes in this file as it will be overwritten.
|
|
410
411
|
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
|
|
411
|
-
|
|
412
|
-
` : "",
|
|
412
|
+
[
|
|
413
|
+
imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : "",
|
|
414
|
+
!TYPES_DISABLED && typeImports.length ? `import type { ${typeImports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : ""
|
|
415
|
+
].filter(Boolean).join("\n"),
|
|
413
416
|
"// Import Routes",
|
|
414
417
|
[
|
|
415
418
|
`import { Route as rootRoute } from './${getImportPath(rootRouteNode)}'`,
|
|
416
419
|
...sortedRouteNodes.filter((d) => !d.isVirtual).map((node) => {
|
|
417
|
-
return `import { Route as ${node.variableName}
|
|
420
|
+
return `import { Route as ${node.variableName}RouteImport } from './${getImportPath(node)}'`;
|
|
418
421
|
})
|
|
419
422
|
].join("\n"),
|
|
420
423
|
virtualRouteNodes.length ? "// Create Virtual Routes" : "",
|
|
421
424
|
virtualRouteNodes.map((node) => {
|
|
422
|
-
return `const ${node.variableName}
|
|
425
|
+
return `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`;
|
|
423
426
|
}).join("\n"),
|
|
424
427
|
"// Create/Update Routes",
|
|
425
428
|
sortedRouteNodes.map((node) => {
|
|
@@ -430,52 +433,54 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
430
433
|
const pendingComponentNode = (_d = routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
|
|
431
434
|
const lazyComponentNode = (_e = routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
|
|
432
435
|
return [
|
|
433
|
-
|
|
436
|
+
[
|
|
437
|
+
`const ${node.variableName}Route = ${node.variableName}RouteImport.update({
|
|
434
438
|
${[
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
+
`id: '${node.path}'`,
|
|
440
|
+
!node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
|
|
441
|
+
`getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
|
|
442
|
+
].filter(Boolean).join(",")}
|
|
439
443
|
}${TYPES_DISABLED ? "" : "as any"})`,
|
|
440
|
-
|
|
441
|
-
removeExt(
|
|
442
|
-
path.relative(
|
|
443
|
-
path.dirname(config.generatedRouteTree),
|
|
444
|
-
path.resolve(config.routesDirectory, loaderNode.filePath)
|
|
445
|
-
),
|
|
446
|
-
config.addExtensions
|
|
447
|
-
)
|
|
448
|
-
)}'), 'loader') })` : "",
|
|
449
|
-
componentNode || errorComponentNode || pendingComponentNode ? `.update({
|
|
450
|
-
${[
|
|
451
|
-
["component", componentNode],
|
|
452
|
-
["errorComponent", errorComponentNode],
|
|
453
|
-
["pendingComponent", pendingComponentNode]
|
|
454
|
-
].filter((d) => d[1]).map((d) => {
|
|
455
|
-
return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
|
|
444
|
+
loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
|
|
456
445
|
removeExt(
|
|
457
446
|
path.relative(
|
|
458
447
|
path.dirname(config.generatedRouteTree),
|
|
459
|
-
path.resolve(config.routesDirectory,
|
|
448
|
+
path.resolve(config.routesDirectory, loaderNode.filePath)
|
|
460
449
|
),
|
|
461
450
|
config.addExtensions
|
|
462
451
|
)
|
|
463
|
-
)}'), '
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
452
|
+
)}'), 'loader') })` : "",
|
|
453
|
+
componentNode || errorComponentNode || pendingComponentNode ? `.update({
|
|
454
|
+
${[
|
|
455
|
+
["component", componentNode],
|
|
456
|
+
["errorComponent", errorComponentNode],
|
|
457
|
+
["pendingComponent", pendingComponentNode]
|
|
458
|
+
].filter((d) => d[1]).map((d) => {
|
|
459
|
+
return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
|
|
460
|
+
removeExt(
|
|
461
|
+
path.relative(
|
|
462
|
+
path.dirname(config.generatedRouteTree),
|
|
463
|
+
path.resolve(config.routesDirectory, d[1].filePath)
|
|
464
|
+
),
|
|
465
|
+
config.addExtensions
|
|
473
466
|
)
|
|
474
|
-
),
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
467
|
+
)}'), '${d[0]}')`;
|
|
468
|
+
}).join("\n,")}
|
|
469
|
+
})` : "",
|
|
470
|
+
lazyComponentNode ? `.lazy(() => import('./${replaceBackslash(
|
|
471
|
+
removeExt(
|
|
472
|
+
path.relative(
|
|
473
|
+
path.dirname(config.generatedRouteTree),
|
|
474
|
+
path.resolve(
|
|
475
|
+
config.routesDirectory,
|
|
476
|
+
lazyComponentNode.filePath
|
|
477
|
+
)
|
|
478
|
+
),
|
|
479
|
+
config.addExtensions
|
|
480
|
+
)
|
|
481
|
+
)}').then((d) => d.Route))` : ""
|
|
482
|
+
].join("")
|
|
483
|
+
].join("\n\n");
|
|
479
484
|
}).join("\n\n"),
|
|
480
485
|
...TYPES_DISABLED ? [] : [
|
|
481
486
|
"// Populate the FileRoutesByPath interface",
|
|
@@ -488,13 +493,36 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
488
493
|
id: '${filePathId}'
|
|
489
494
|
path: '${inferPath(routeNode)}'
|
|
490
495
|
fullPath: '${inferFullPath(routeNode)}'
|
|
491
|
-
preLoaderRoute: typeof ${routeNode.variableName}
|
|
492
|
-
parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${routeNode.parent.variableName}
|
|
496
|
+
preLoaderRoute: typeof ${routeNode.variableName}RouteImport
|
|
497
|
+
parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${routeNode.parent.variableName}RouteImport` : "rootRoute"}
|
|
493
498
|
}`;
|
|
494
499
|
}).join("\n")}
|
|
495
500
|
}
|
|
496
501
|
}`
|
|
497
502
|
],
|
|
503
|
+
...TYPES_DISABLED ? [] : config.verboseFileRoutes !== false ? [] : [
|
|
504
|
+
`// Add type-safety to the createFileRoute function across the route tree`,
|
|
505
|
+
routeNodes.map((routeNode) => {
|
|
506
|
+
var _a;
|
|
507
|
+
function getModuleDeclaration(routeNode2) {
|
|
508
|
+
if (!isRouteNodeValidForAugmentation(routeNode2)) {
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
return `declare module './${getImportPath(routeNode2)}' {
|
|
512
|
+
const ${routeNode2._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}: ${routeNode2._fsRouteType === "lazy" ? `CreateLazyFileRoute<FileRoutesByPath['${routeNode2.routePath}']['preLoaderRoute']>}` : `CreateFileRoute<
|
|
513
|
+
'${routeNode2.routePath}',
|
|
514
|
+
FileRoutesByPath['${routeNode2.routePath}']['parentRoute'],
|
|
515
|
+
FileRoutesByPath['${routeNode2.routePath}']['id'],
|
|
516
|
+
FileRoutesByPath['${routeNode2.routePath}']['path'],
|
|
517
|
+
FileRoutesByPath['${routeNode2.routePath}']['fullPath']
|
|
518
|
+
>
|
|
519
|
+
}`}`;
|
|
520
|
+
}
|
|
521
|
+
return getModuleDeclaration(routeNode) + getModuleDeclaration(
|
|
522
|
+
(_a = routePiecesByPath[routeNode.routePath]) == null ? void 0 : _a.lazy
|
|
523
|
+
);
|
|
524
|
+
}).join("\n")
|
|
525
|
+
],
|
|
498
526
|
"// Create and export the route tree",
|
|
499
527
|
routeConfigChildrenText,
|
|
500
528
|
...TYPES_DISABLED ? [] : [
|
|
@@ -511,7 +539,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
511
539
|
})}
|
|
512
540
|
}`,
|
|
513
541
|
`export interface FileRoutesById {
|
|
514
|
-
'
|
|
542
|
+
'${rootRouteId}': typeof rootRoute,
|
|
515
543
|
${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {
|
|
516
544
|
return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
517
545
|
})}
|
|
@@ -521,7 +549,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
521
549
|
fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
|
|
522
550
|
fileRoutesByTo: FileRoutesByTo
|
|
523
551
|
to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
|
|
524
|
-
id: ${[`'
|
|
552
|
+
id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
|
|
525
553
|
fileRoutesById: FileRoutesById
|
|
526
554
|
}`,
|
|
527
555
|
`export interface RootRouteChildren {
|
|
@@ -536,7 +564,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
536
564
|
].filter(Boolean).join("\n\n");
|
|
537
565
|
const createRouteManifest = () => {
|
|
538
566
|
const routesManifest = {
|
|
539
|
-
|
|
567
|
+
[rootRouteId]: {
|
|
540
568
|
filePath: rootRouteNode.filePath,
|
|
541
569
|
children: routeTree.map((d) => d.routePath)
|
|
542
570
|
},
|
|
@@ -603,6 +631,12 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
603
631
|
function removeGroups(s) {
|
|
604
632
|
return s.replace(possiblyNestedRouteGroupPatternRegex, "");
|
|
605
633
|
}
|
|
634
|
+
function isRouteNodeValidForAugmentation(routeNode) {
|
|
635
|
+
if (!routeNode || routeNode.isVirtual) {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
606
640
|
function determineNodePath(node) {
|
|
607
641
|
var _a;
|
|
608
642
|
return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath ?? "", "")) || "/" : node.routePath;
|
|
@@ -703,60 +737,14 @@ function checkRouteFullPathUniqueness(_routes, config) {
|
|
|
703
737
|
const conflictingFiles = checkUnique(routes, "inferredFullPath");
|
|
704
738
|
if (conflictingFiles !== void 0) {
|
|
705
739
|
const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p.inferredFullPath}"`).join(", ")}.
|
|
706
|
-
Please ensure each
|
|
707
|
-
Conflicting files:
|
|
708
|
-
${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
|
|
709
|
-
`;
|
|
710
|
-
throw new Error(errorMessage);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
function checkStartAPIRoutes(_routes, config) {
|
|
714
|
-
if (_routes.length === 0) {
|
|
715
|
-
return [];
|
|
716
|
-
}
|
|
717
|
-
const routes = _routes.map((d) => {
|
|
718
|
-
const routePath = removeTrailingSlash(d.routePath ?? "");
|
|
719
|
-
return { ...d, routePath };
|
|
720
|
-
});
|
|
721
|
-
const conflictingFiles = checkUnique(routes, "routePath");
|
|
722
|
-
if (conflictingFiles !== void 0) {
|
|
723
|
-
const errorMessage = `Conflicting configuration paths were found for the following API route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p}"`).join(", ")}.
|
|
724
|
-
Please ensure each API route has a unique route path.
|
|
740
|
+
Please ensure each Route has a unique full path.
|
|
725
741
|
Conflicting files:
|
|
726
742
|
${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
|
|
727
743
|
`;
|
|
728
744
|
throw new Error(errorMessage);
|
|
729
745
|
}
|
|
730
|
-
return routes;
|
|
731
|
-
}
|
|
732
|
-
function startAPIRouteSegmentsFromTSRFilePath(src, config) {
|
|
733
|
-
const routePath = determineInitialRoutePath(src);
|
|
734
|
-
const parts = routePath.replaceAll(".", "/").split("/").filter((p) => !!p && p !== config.indexToken);
|
|
735
|
-
const segments = parts.map((part) => {
|
|
736
|
-
if (part.startsWith("$")) {
|
|
737
|
-
if (part === "$") {
|
|
738
|
-
return { value: part, type: "splat" };
|
|
739
|
-
}
|
|
740
|
-
part.replaceAll("$", "");
|
|
741
|
-
return { value: part, type: "param" };
|
|
742
|
-
}
|
|
743
|
-
return { value: part, type: "path" };
|
|
744
|
-
});
|
|
745
|
-
return segments;
|
|
746
746
|
}
|
|
747
747
|
export {
|
|
748
|
-
|
|
749
|
-
createRouteNodesByFullPath,
|
|
750
|
-
createRouteNodesById,
|
|
751
|
-
createRouteNodesByTo,
|
|
752
|
-
dedupeBranchesAndIndexRoutes,
|
|
753
|
-
generator,
|
|
754
|
-
getResolvedRouteNodeVariableName,
|
|
755
|
-
hasParentRoute,
|
|
756
|
-
inferFullPath,
|
|
757
|
-
inferPath,
|
|
758
|
-
inferTo,
|
|
759
|
-
removeLastSegmentFromPath,
|
|
760
|
-
startAPIRouteSegmentsFromTSRFilePath
|
|
748
|
+
generator
|
|
761
749
|
};
|
|
762
750
|
//# sourceMappingURL=generator.js.map
|