@tanstack/router-generator 1.120.3 → 1.120.4-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 +157 -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 +61 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +4 -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 +160 -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 +4 -2
- package/dist/esm/utils.js +61 -2
- 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 +233 -222
- package/src/index.ts +32 -7
- package/src/template.ts +4 -15
- package/src/types.ts +0 -1
- package/src/utils.ts +85 -4
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,63 @@ 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 {
|
|
186
209
|
replaced = routeCode.replace(
|
|
187
210
|
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
188
211
|
(_, p1, __, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
212
|
+
).replace(
|
|
213
|
+
/((FileRoute)(\s*)(\({))/g,
|
|
214
|
+
(_, __, p2, p3, p4) => `${p2}('${escapedRoutePath}')${p3}${p4}`
|
|
189
215
|
).replace(
|
|
190
216
|
new RegExp(
|
|
191
217
|
`(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
|
|
@@ -196,6 +222,16 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
196
222
|
/create(Lazy)?FileRoute(\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
197
223
|
(_, __, p2, ___, p4) => `${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}${p2}${escapedRoutePath}${p4}`
|
|
198
224
|
);
|
|
225
|
+
const regex = new RegExp(
|
|
226
|
+
`(import\\s*\\{.*)(create(Lazy)?FileRoute)(.*\\}\\s*from\\s*['"]@tanstack\\/${ROUTE_TEMPLATE.subPkg}['"])`,
|
|
227
|
+
"gm"
|
|
228
|
+
);
|
|
229
|
+
if (!replaced.match(regex)) {
|
|
230
|
+
replaced = [
|
|
231
|
+
`import { ${node._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"} } from '@tanstack/${ROUTE_TEMPLATE.subPkg}'`,
|
|
232
|
+
...replaced.split("\n")
|
|
233
|
+
].join("\n");
|
|
234
|
+
}
|
|
199
235
|
}
|
|
200
236
|
await writeIfDifferent(node.fullPath, routeCode, replaced, {
|
|
201
237
|
beforeWrite: () => {
|
|
@@ -268,68 +304,15 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
268
304
|
}
|
|
269
305
|
routeNodes.push(node);
|
|
270
306
|
};
|
|
271
|
-
for (const node of
|
|
307
|
+
for (const node of preRouteNodes) {
|
|
272
308
|
await handleNode(node);
|
|
273
309
|
}
|
|
274
310
|
checkRouteFullPathUniqueness(
|
|
275
311
|
preRouteNodes.filter(
|
|
276
|
-
(d) => d.children === void 0 &&
|
|
277
|
-
(type) => type !== d._fsRouteType
|
|
278
|
-
)
|
|
312
|
+
(d) => d.children === void 0 && "lazy" !== d._fsRouteType
|
|
279
313
|
),
|
|
280
314
|
config
|
|
281
315
|
);
|
|
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
316
|
function buildRouteTreeConfig(nodes, depth = 1) {
|
|
334
317
|
const children = nodes.map((node) => {
|
|
335
318
|
var _a, _b;
|
|
@@ -376,6 +359,21 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
376
359
|
},
|
|
377
360
|
(d) => d
|
|
378
361
|
]);
|
|
362
|
+
const typeImports = Object.entries({
|
|
363
|
+
// Used for augmentation of regular routes
|
|
364
|
+
CreateFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
|
|
365
|
+
(d) => isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
|
|
366
|
+
),
|
|
367
|
+
// Used for augmentation of lazy (`.lazy`) routes
|
|
368
|
+
CreateLazyFileRoute: config.verboseFileRoutes === false && sortedRouteNodes.some(
|
|
369
|
+
(node) => {
|
|
370
|
+
var _a;
|
|
371
|
+
return ((_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.lazy) && isRouteNodeValidForAugmentation(node);
|
|
372
|
+
}
|
|
373
|
+
),
|
|
374
|
+
// Used in the process of augmenting the routes
|
|
375
|
+
FileRoutesByPath: config.verboseFileRoutes === false && sortedRouteNodes.some((d) => isRouteNodeValidForAugmentation(d))
|
|
376
|
+
}).filter((d) => d[1]).map((d) => d[0]).sort((a, b) => a.localeCompare(b));
|
|
379
377
|
const imports = Object.entries({
|
|
380
378
|
createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),
|
|
381
379
|
lazyFn: sortedRouteNodes.some(
|
|
@@ -408,18 +406,20 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
408
406
|
`// This file was automatically generated by TanStack Router.
|
|
409
407
|
// You should NOT make any changes in this file as it will be overwritten.
|
|
410
408
|
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
|
|
411
|
-
|
|
412
|
-
` : "",
|
|
409
|
+
[
|
|
410
|
+
imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : "",
|
|
411
|
+
!TYPES_DISABLED && typeImports.length ? `import type { ${typeImports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'` : ""
|
|
412
|
+
].filter(Boolean).join("\n"),
|
|
413
413
|
"// Import Routes",
|
|
414
414
|
[
|
|
415
415
|
`import { Route as rootRoute } from './${getImportPath(rootRouteNode)}'`,
|
|
416
416
|
...sortedRouteNodes.filter((d) => !d.isVirtual).map((node) => {
|
|
417
|
-
return `import { Route as ${node.variableName}
|
|
417
|
+
return `import { Route as ${node.variableName}RouteImport } from './${getImportPath(node)}'`;
|
|
418
418
|
})
|
|
419
419
|
].join("\n"),
|
|
420
420
|
virtualRouteNodes.length ? "// Create Virtual Routes" : "",
|
|
421
421
|
virtualRouteNodes.map((node) => {
|
|
422
|
-
return `const ${node.variableName}
|
|
422
|
+
return `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`;
|
|
423
423
|
}).join("\n"),
|
|
424
424
|
"// Create/Update Routes",
|
|
425
425
|
sortedRouteNodes.map((node) => {
|
|
@@ -430,52 +430,54 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
430
430
|
const pendingComponentNode = (_d = routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
|
|
431
431
|
const lazyComponentNode = (_e = routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
|
|
432
432
|
return [
|
|
433
|
-
|
|
433
|
+
[
|
|
434
|
+
`const ${node.variableName}Route = ${node.variableName}RouteImport.update({
|
|
434
435
|
${[
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
436
|
+
`id: '${node.path}'`,
|
|
437
|
+
!node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
|
|
438
|
+
`getParentRoute: () => ${((_f = node.parent) == null ? void 0 : _f.variableName) ?? "root"}Route`
|
|
439
|
+
].filter(Boolean).join(",")}
|
|
439
440
|
}${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(
|
|
441
|
+
loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
|
|
456
442
|
removeExt(
|
|
457
443
|
path.relative(
|
|
458
444
|
path.dirname(config.generatedRouteTree),
|
|
459
|
-
path.resolve(config.routesDirectory,
|
|
445
|
+
path.resolve(config.routesDirectory, loaderNode.filePath)
|
|
460
446
|
),
|
|
461
447
|
config.addExtensions
|
|
462
448
|
)
|
|
463
|
-
)}'), '
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
449
|
+
)}'), 'loader') })` : "",
|
|
450
|
+
componentNode || errorComponentNode || pendingComponentNode ? `.update({
|
|
451
|
+
${[
|
|
452
|
+
["component", componentNode],
|
|
453
|
+
["errorComponent", errorComponentNode],
|
|
454
|
+
["pendingComponent", pendingComponentNode]
|
|
455
|
+
].filter((d) => d[1]).map((d) => {
|
|
456
|
+
return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
|
|
457
|
+
removeExt(
|
|
458
|
+
path.relative(
|
|
459
|
+
path.dirname(config.generatedRouteTree),
|
|
460
|
+
path.resolve(config.routesDirectory, d[1].filePath)
|
|
461
|
+
),
|
|
462
|
+
config.addExtensions
|
|
473
463
|
)
|
|
474
|
-
),
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
464
|
+
)}'), '${d[0]}')`;
|
|
465
|
+
}).join("\n,")}
|
|
466
|
+
})` : "",
|
|
467
|
+
lazyComponentNode ? `.lazy(() => import('./${replaceBackslash(
|
|
468
|
+
removeExt(
|
|
469
|
+
path.relative(
|
|
470
|
+
path.dirname(config.generatedRouteTree),
|
|
471
|
+
path.resolve(
|
|
472
|
+
config.routesDirectory,
|
|
473
|
+
lazyComponentNode.filePath
|
|
474
|
+
)
|
|
475
|
+
),
|
|
476
|
+
config.addExtensions
|
|
477
|
+
)
|
|
478
|
+
)}').then((d) => d.Route))` : ""
|
|
479
|
+
].join("")
|
|
480
|
+
].join("\n\n");
|
|
479
481
|
}).join("\n\n"),
|
|
480
482
|
...TYPES_DISABLED ? [] : [
|
|
481
483
|
"// Populate the FileRoutesByPath interface",
|
|
@@ -488,13 +490,36 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
488
490
|
id: '${filePathId}'
|
|
489
491
|
path: '${inferPath(routeNode)}'
|
|
490
492
|
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}
|
|
493
|
+
preLoaderRoute: typeof ${routeNode.variableName}RouteImport
|
|
494
|
+
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
495
|
}`;
|
|
494
496
|
}).join("\n")}
|
|
495
497
|
}
|
|
496
498
|
}`
|
|
497
499
|
],
|
|
500
|
+
...TYPES_DISABLED ? [] : config.verboseFileRoutes !== false ? [] : [
|
|
501
|
+
`// Add type-safety to the createFileRoute function across the route tree`,
|
|
502
|
+
routeNodes.map((routeNode) => {
|
|
503
|
+
var _a;
|
|
504
|
+
function getModuleDeclaration(routeNode2) {
|
|
505
|
+
if (!isRouteNodeValidForAugmentation(routeNode2)) {
|
|
506
|
+
return "";
|
|
507
|
+
}
|
|
508
|
+
return `declare module './${getImportPath(routeNode2)}' {
|
|
509
|
+
const ${routeNode2._fsRouteType === "lazy" ? "createLazyFileRoute" : "createFileRoute"}: ${routeNode2._fsRouteType === "lazy" ? `CreateLazyFileRoute<FileRoutesByPath['${routeNode2.routePath}']['preLoaderRoute']>}` : `CreateFileRoute<
|
|
510
|
+
'${routeNode2.routePath}',
|
|
511
|
+
FileRoutesByPath['${routeNode2.routePath}']['parentRoute'],
|
|
512
|
+
FileRoutesByPath['${routeNode2.routePath}']['id'],
|
|
513
|
+
FileRoutesByPath['${routeNode2.routePath}']['path'],
|
|
514
|
+
FileRoutesByPath['${routeNode2.routePath}']['fullPath']
|
|
515
|
+
>
|
|
516
|
+
}`}`;
|
|
517
|
+
}
|
|
518
|
+
return getModuleDeclaration(routeNode) + getModuleDeclaration(
|
|
519
|
+
(_a = routePiecesByPath[routeNode.routePath]) == null ? void 0 : _a.lazy
|
|
520
|
+
);
|
|
521
|
+
}).join("\n")
|
|
522
|
+
],
|
|
498
523
|
"// Create and export the route tree",
|
|
499
524
|
routeConfigChildrenText,
|
|
500
525
|
...TYPES_DISABLED ? [] : [
|
|
@@ -511,7 +536,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
511
536
|
})}
|
|
512
537
|
}`,
|
|
513
538
|
`export interface FileRoutesById {
|
|
514
|
-
'
|
|
539
|
+
'${rootRouteId}': typeof rootRoute,
|
|
515
540
|
${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {
|
|
516
541
|
return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
517
542
|
})}
|
|
@@ -521,7 +546,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
521
546
|
fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
|
|
522
547
|
fileRoutesByTo: FileRoutesByTo
|
|
523
548
|
to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
|
|
524
|
-
id: ${[`'
|
|
549
|
+
id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
|
|
525
550
|
fileRoutesById: FileRoutesById
|
|
526
551
|
}`,
|
|
527
552
|
`export interface RootRouteChildren {
|
|
@@ -536,7 +561,7 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
536
561
|
].filter(Boolean).join("\n\n");
|
|
537
562
|
const createRouteManifest = () => {
|
|
538
563
|
const routesManifest = {
|
|
539
|
-
|
|
564
|
+
[rootRouteId]: {
|
|
540
565
|
filePath: rootRouteNode.filePath,
|
|
541
566
|
children: routeTree.map((d) => d.routePath)
|
|
542
567
|
},
|
|
@@ -603,6 +628,12 @@ Add the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes
|
|
|
603
628
|
function removeGroups(s) {
|
|
604
629
|
return s.replace(possiblyNestedRouteGroupPatternRegex, "");
|
|
605
630
|
}
|
|
631
|
+
function isRouteNodeValidForAugmentation(routeNode) {
|
|
632
|
+
if (!routeNode || routeNode.isVirtual) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
606
637
|
function determineNodePath(node) {
|
|
607
638
|
var _a;
|
|
608
639
|
return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath ?? "", "")) || "/" : node.routePath;
|
|
@@ -703,60 +734,14 @@ function checkRouteFullPathUniqueness(_routes, config) {
|
|
|
703
734
|
const conflictingFiles = checkUnique(routes, "inferredFullPath");
|
|
704
735
|
if (conflictingFiles !== void 0) {
|
|
705
736
|
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.
|
|
737
|
+
Please ensure each Route has a unique full path.
|
|
725
738
|
Conflicting files:
|
|
726
739
|
${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
|
|
727
740
|
`;
|
|
728
741
|
throw new Error(errorMessage);
|
|
729
742
|
}
|
|
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
743
|
}
|
|
747
744
|
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
|
|
745
|
+
generator
|
|
761
746
|
};
|
|
762
747
|
//# sourceMappingURL=generator.js.map
|