@tanstack/router-generator 1.19.2 → 1.19.3
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/generator.cjs +59 -22
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +1 -1
- package/dist/esm/generator.d.ts +1 -1
- package/dist/esm/generator.js +59 -22
- package/dist/esm/generator.js.map +1 -1
- package/package.json +1 -1
- package/src/generator.ts +79 -24
package/dist/cjs/generator.cjs
CHANGED
|
@@ -168,11 +168,12 @@ async function generator(config) {
|
|
|
168
168
|
const routePiecesByPath = {};
|
|
169
169
|
let routeNodes = [];
|
|
170
170
|
const handleNode = async (node) => {
|
|
171
|
-
var _a, _b
|
|
172
|
-
let parentRoute = hasParentRoute(routeNodes, node.routePath);
|
|
171
|
+
var _a, _b;
|
|
172
|
+
let parentRoute = hasParentRoute(routeNodes, node, node.routePath);
|
|
173
173
|
if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
|
|
174
174
|
const possibleParentRoute = hasParentRoute(
|
|
175
175
|
parentRoute.children,
|
|
176
|
+
node,
|
|
176
177
|
node.routePath
|
|
177
178
|
);
|
|
178
179
|
if (possibleParentRoute) {
|
|
@@ -181,7 +182,7 @@ async function generator(config) {
|
|
|
181
182
|
}
|
|
182
183
|
if (parentRoute)
|
|
183
184
|
node.parent = parentRoute;
|
|
184
|
-
node.path =
|
|
185
|
+
node.path = determineNodePath(node);
|
|
185
186
|
const trimmedPath = utils.trimPathLeft(node.path ?? "");
|
|
186
187
|
const split = (trimmedPath == null ? void 0 : trimmedPath.split("/")) ?? [];
|
|
187
188
|
let first2 = split[0] ?? trimmedPath ?? "";
|
|
@@ -194,7 +195,7 @@ async function generator(config) {
|
|
|
194
195
|
if (!node.isVirtualParentRoute) {
|
|
195
196
|
const routeCode = fs__namespace.readFileSync(node.fullPath, "utf-8");
|
|
196
197
|
const escapedRoutePath = removeTrailingUnderscores(
|
|
197
|
-
((
|
|
198
|
+
((_b = node.routePath) == null ? void 0 : _b.replaceAll("$", "$$")) ?? ""
|
|
198
199
|
);
|
|
199
200
|
let replaced = routeCode;
|
|
200
201
|
if (!routeCode) {
|
|
@@ -202,15 +203,15 @@ async function generator(config) {
|
|
|
202
203
|
replaced = [
|
|
203
204
|
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
204
205
|
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
207
|
+
})`
|
|
207
208
|
].join("\n\n");
|
|
208
209
|
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
209
210
|
replaced = [
|
|
210
211
|
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
211
212
|
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
214
|
+
})`
|
|
214
215
|
].join("\n\n");
|
|
215
216
|
}
|
|
216
217
|
} else {
|
|
@@ -247,10 +248,11 @@ async function generator(config) {
|
|
|
247
248
|
}
|
|
248
249
|
return;
|
|
249
250
|
}
|
|
250
|
-
|
|
251
|
-
|
|
251
|
+
const cleanedPathIsEmpty = (node.cleanedPath || "").length === 0;
|
|
252
|
+
node.isVirtualParentRequired = node.isLayout ? !cleanedPathIsEmpty && !node.parent : false;
|
|
252
253
|
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
253
254
|
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
255
|
+
const parentVariableName = routePathToVariable(parentRoutePath);
|
|
254
256
|
const anchorRoute = routeNodes.find(
|
|
255
257
|
(d) => d.routePath === parentRoutePath
|
|
256
258
|
);
|
|
@@ -261,7 +263,7 @@ async function generator(config) {
|
|
|
261
263
|
filePath: removeLastSegmentFromPath(node.filePath) || "/",
|
|
262
264
|
fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
|
|
263
265
|
routePath: parentRoutePath,
|
|
264
|
-
variableName:
|
|
266
|
+
variableName: parentVariableName,
|
|
265
267
|
isVirtual: true,
|
|
266
268
|
isLayout: false,
|
|
267
269
|
isVirtualParentRoute: true,
|
|
@@ -270,6 +272,9 @@ async function generator(config) {
|
|
|
270
272
|
parentNode.children = parentNode.children ?? [];
|
|
271
273
|
parentNode.children.push(node);
|
|
272
274
|
node.parent = parentNode;
|
|
275
|
+
if (node.isLayout) {
|
|
276
|
+
node.path = determineNodePath(node);
|
|
277
|
+
}
|
|
273
278
|
await handleNode(parentNode);
|
|
274
279
|
} else {
|
|
275
280
|
anchorRoute.children = anchorRoute.children ?? [];
|
|
@@ -290,12 +295,15 @@ async function generator(config) {
|
|
|
290
295
|
await Promise.all(preRouteNodes.map((node) => handleNode(node)));
|
|
291
296
|
async function buildRouteConfig(nodes, depth = 1) {
|
|
292
297
|
const children = nodes.map(async (node) => {
|
|
293
|
-
var _a;
|
|
298
|
+
var _a, _b;
|
|
294
299
|
if (node.isRoot) {
|
|
295
300
|
return;
|
|
296
301
|
}
|
|
302
|
+
if (node.isLayout && !((_a = node.children) == null ? void 0 : _a.length)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
297
305
|
const route = `${node.variableName}Route`;
|
|
298
|
-
if ((
|
|
306
|
+
if ((_b = node.children) == null ? void 0 : _b.length) {
|
|
299
307
|
const childConfigs = await buildRouteConfig(node.children, depth + 1);
|
|
300
308
|
return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`;
|
|
301
309
|
}
|
|
@@ -334,7 +342,15 @@ async function generator(config) {
|
|
|
334
342
|
}
|
|
335
343
|
)
|
|
336
344
|
}).filter((d) => d[1]).map((d) => d[0]);
|
|
337
|
-
const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)
|
|
345
|
+
const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual).reduce((acc, route) => {
|
|
346
|
+
const existingPreNode = preRouteNodes.filter(
|
|
347
|
+
(d) => d.routePath === route.routePath
|
|
348
|
+
);
|
|
349
|
+
if (existingPreNode.length === 0) {
|
|
350
|
+
acc.push(route);
|
|
351
|
+
}
|
|
352
|
+
return acc;
|
|
353
|
+
}, []);
|
|
338
354
|
const rootPathIdExtension = config.addExtensions && rootRouteNode ? path.extname(rootRouteNode.filePath) : "";
|
|
339
355
|
const routeImports = [
|
|
340
356
|
"/* prettier-ignore-start */",
|
|
@@ -374,7 +390,13 @@ async function generator(config) {
|
|
|
374
390
|
)}')()`;
|
|
375
391
|
}).join("\n"),
|
|
376
392
|
"// Create/Update Routes",
|
|
377
|
-
sortedRouteNodes.
|
|
393
|
+
sortedRouteNodes.reduce((acc, node) => {
|
|
394
|
+
if (acc.find((d) => d.routePath === node.routePath)) {
|
|
395
|
+
return acc;
|
|
396
|
+
}
|
|
397
|
+
acc.push(node);
|
|
398
|
+
return acc;
|
|
399
|
+
}, []).map((node) => {
|
|
378
400
|
var _a, _b, _c, _d, _e, _f;
|
|
379
401
|
const loaderNode = (_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.loader;
|
|
380
402
|
const componentNode = (_b = routePiecesByPath[node.routePath]) == null ? void 0 : _b.component;
|
|
@@ -520,6 +542,10 @@ function replaceBackslash(s) {
|
|
|
520
542
|
function removeGroups(s) {
|
|
521
543
|
return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
|
|
522
544
|
}
|
|
545
|
+
function determineNodePath(node) {
|
|
546
|
+
var _a;
|
|
547
|
+
return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath, "")) || "/" : node.routePath;
|
|
548
|
+
}
|
|
523
549
|
function removeLastSegmentFromPath(path2 = "/") {
|
|
524
550
|
const segments = path2.split("/");
|
|
525
551
|
segments.pop();
|
|
@@ -530,7 +556,7 @@ function removeLayoutSegments(path2 = "/") {
|
|
|
530
556
|
const newSegments = segments.filter((segment) => !segment.startsWith("_"));
|
|
531
557
|
return newSegments.join("/");
|
|
532
558
|
}
|
|
533
|
-
function hasParentRoute(routes, routePathToCheck) {
|
|
559
|
+
function hasParentRoute(routes, node, routePathToCheck) {
|
|
534
560
|
if (!routePathToCheck || routePathToCheck === "/") {
|
|
535
561
|
return null;
|
|
536
562
|
}
|
|
@@ -538,17 +564,28 @@ function hasParentRoute(routes, routePathToCheck) {
|
|
|
538
564
|
(d) => d.routePath.length * -1,
|
|
539
565
|
(d) => d.variableName
|
|
540
566
|
]).filter((d) => d.routePath !== `/${rootPathId}`);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
567
|
+
if (node.isLayout) {
|
|
568
|
+
for (const route of sortedNodes) {
|
|
569
|
+
if (route.routePath === "/")
|
|
570
|
+
continue;
|
|
571
|
+
const exactParentRoutePath = removeLastSegmentFromPath(node.routePath);
|
|
572
|
+
if (route.routePath === exactParentRoutePath) {
|
|
573
|
+
return route;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
} else {
|
|
577
|
+
for (const route of sortedNodes) {
|
|
578
|
+
if (route.routePath === "/")
|
|
579
|
+
continue;
|
|
580
|
+
if (routePathToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routePathToCheck) {
|
|
581
|
+
return route;
|
|
582
|
+
}
|
|
546
583
|
}
|
|
547
584
|
}
|
|
548
585
|
const segments = routePathToCheck.split("/");
|
|
549
586
|
segments.pop();
|
|
550
587
|
const parentRoutePath = segments.join("/");
|
|
551
|
-
return hasParentRoute(routes, parentRoutePath);
|
|
588
|
+
return hasParentRoute(routes, node, parentRoutePath);
|
|
552
589
|
}
|
|
553
590
|
exports.generator = generator;
|
|
554
591
|
exports.hasParentRoute = hasParentRoute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.cjs","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs'\nimport * as fsp from 'fs/promises'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, logging, trimPathLeft } from './utils'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isLayout?: boolean\n isVirtualParentRequired?: boolean\n isVirtualParentRoute?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isErrorComponent?: boolean\n isPendingComponent?: boolean\n isVirtual?: boolean\n isLazy?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n const logger = logging({ disabled: config.disableLogging })\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath =\n cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n }\n\n const variableName = routePathToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n\n let isLazy = routePath?.endsWith('/lazy')\n\n if (isLazy) {\n routePath = routePath?.replace(/\\/lazy$/, '')\n }\n\n let isRoute = routePath?.endsWith('/route')\n let isComponent = routePath?.endsWith('/component')\n let isErrorComponent = routePath?.endsWith('/errorComponent')\n let isPendingComponent = routePath?.endsWith('/pendingComponent')\n let isLoader = routePath?.endsWith('/loader')\n\n const segments = (routePath ?? '').split('/')\n let isLayout = segments[segments.length - 1]?.startsWith('_') || false\n\n ;(\n [\n [isComponent, 'component'],\n [isErrorComponent, 'errorComponent'],\n [isPendingComponent, 'pendingComponent'],\n [isLoader, 'loader'],\n ] as const\n ).forEach(([isType, type]) => {\n if (isType) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n\n routePath = routePath?.replace(\n /\\/(component|errorComponent|pendingComponent|loader|route|lazy)$/,\n '',\n )\n\n if (routePath === 'index') {\n routePath = '/'\n }\n\n routePath = routePath.replace(/\\/index$/, '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\n isLazy,\n isLayout,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n errorComponent?: RouteNode\n pendingComponent?: RouteNode\n loader?: RouteNode\n lazy?: RouteNode\n}\n\nexport async function generator(config: Config) {\n const logger = logging({ disabled: config.disableLogging })\n logger.log('')\n\n if (!first) {\n logger.log('♻️ Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n logger.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n const beforeRouteNodes = await getRouteNodes(config)\n const rootRouteNode = beforeRouteNodes.find(\n (d) => d.routePath === `/${rootPathId}`,\n )\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) =>\n d.filePath?.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = async (node: RouteNode) => {\n let parentRoute = hasParentRoute(routeNodes, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? ''\n\n node.isNonPath = lastRouteSegment.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes\n if (!node.isVirtualParentRoute) {\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n const escapedRoutePath = removeTrailingUnderscores(\n node.routePath?.replaceAll('$', '$$') ?? '',\n )\n\n let replaced = routeCode\n\n if (!routeCode) {\n if (node.isLazy) {\n replaced = [\n `import { createLazyFileRoute } from '@tanstack/react-router'`,\n `export const Route = createLazyFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n })`,\n ].join('\\n\\n')\n } else if (\n node.isRoute ||\n (!node.isComponent &&\n !node.isErrorComponent &&\n !node.isPendingComponent &&\n !node.isLoader)\n ) {\n replaced = [\n `import { createFileRoute } from '@tanstack/react-router'`,\n `export const Route = createFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n })`,\n ].join('\\n\\n')\n }\n } else {\n replaced = routeCode\n .replace(\n /(FileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createLazyFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n }\n\n if (replaced !== routeCode) {\n logger.log(`🟡 Updating ${node.fullPath}`)\n await fsp.writeFile(node.fullPath, replaced)\n }\n }\n\n if (\n !node.isVirtual &&\n (node.isLoader ||\n node.isComponent ||\n node.isErrorComponent ||\n node.isPendingComponent ||\n node.isLazy)\n ) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLazy\n ? 'lazy'\n : node.isLoader\n ? 'loader'\n : node.isErrorComponent\n ? 'errorComponent'\n : node.isPendingComponent\n ? 'pendingComponent'\n : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)\n\n if (!anchorRoute) {\n await handleNode({\n ...node,\n isVirtual: true,\n isLazy: false,\n isLoader: false,\n isComponent: false,\n isErrorComponent: false,\n isPendingComponent: false,\n })\n }\n return\n }\n\n node.isVirtualParentRequired =\n removeGroups(node.path ?? '')\n .split('')\n .filter((char) => char === '/').length >= 2 && // check that the parent route wouldn't be the root route\n !node.parent &&\n node.isLayout\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: routePathToVariable(parentRoutePath),\n isVirtual: true,\n isLayout: false,\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n await Promise.all(preRouteNodes.map((node) => handleNode(node)))\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n if (node.isRoot) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n lazyFn: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.loader,\n ),\n lazyRouteComponent: sortedRouteNodes.some(\n (node) =>\n routePiecesByPath[node.routePath!]?.component ||\n routePiecesByPath[node.routePath!]?.errorComponent ||\n routePiecesByPath[node.routePath!]?.pendingComponent,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n const rootPathIdExtension =\n config.addExtensions && rootRouteNode\n ? path.extname(rootRouteNode.filePath)\n : ''\n\n const routeImports = [\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n '// This file is auto-generated by TanStack Router',\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n '// Import Routes',\n [\n `import { Route as rootRoute } from './${replaceBackslash(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n `${routePathIdPrefix}${rootPathId}${rootPathIdExtension}`,\n ),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }Import = createFileRoute('${removeTrailingUnderscores(\n node.routePath,\n )}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n sortedRouteNodes\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n const errorComponentNode =\n routePiecesByPath[node.routePath!]?.errorComponent\n const pendingComponentNode =\n routePiecesByPath[node.routePath!]?.pendingComponent\n const lazyComponentNode = routePiecesByPath[node.routePath!]?.lazy\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode || errorComponentNode || pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n ),\n config.addExtensions,\n ),\n )}'), '${d[0]}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? `.lazy(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )}').then((d) => d.Route))`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n ...(config.disableTypes\n ? []\n : [\n '// Populate the FileRoutesByPath interface',\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${removeTrailingUnderscores(routeNode.routePath)}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent?.variableName}Import`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n ]),\n '// Create and export the route tree',\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n '/* prettier-ignore-end */',\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n })\n\n const routeTreeContent = await fsp\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {\n recursive: true,\n })\n if (!checkLatest()) return\n await fsp.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n logger.log(\n `✅ Processed ${routeNodes.length === 1 ? 'route' : 'routes'} in ${\n Date.now() - start\n }ms`,\n )\n}\n\nfunction routePathToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\/\\$\\//g, '/splat/')\n ?.replace(/\\$$/g, 'splat')\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '')\n .replace(/^(\\d)/g, 'R$1') ?? ''\n )\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replaceAll(/(^_|_$)/gi, '').replaceAll(/(\\/_|_\\/)/gi, '/')\n}\n\nfunction removeTrailingUnderscores(s?: string) {\n return s?.replaceAll(/(_$)/gi, '').replaceAll(/(_\\/)/gi, '/')\n}\n\nfunction replaceBackslash(s: string) {\n return s.replaceAll(/\\\\/gi, '/')\n}\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} path - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(path: string = '/'): string {\n const segments = path.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} path - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(path: string = '/'): string {\n const segments = path.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, parentRoutePath)\n}\n"],"names":["logging","fsp","cleanPath","trimPathLeft","first","fs","prettier","d","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAI,aAAa;AACV,MAAM,aAAa;AAC1B,MAAM,yBAAyB;AA0B/B,eAAe,cAAc,QAAgB;AACrC,QAAA,EAAE,iBAAiB,sBAA0B,IAAA;AACnD,QAAM,SAASA,MAAAA,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAE1D,MAAI,aAA0B,CAAA;AAE9B,iBAAe,QAAQ,KAAa;AAClC,UAAM,UAAU,KAAK,QAAQ,OAAO,iBAAiB,GAAG;AACpD,QAAA,UAAU,MAAMC,eAAI,QAAQ,SAAS,EAAE,eAAe,MAAM;AAEtD,cAAA,QAAQ,OAAO,CAAC,MAAM;AAE5B,UAAA,EAAE,KAAK,WAAW,GAAG,KACpB,yBAAyB,EAAE,KAAK,WAAW,qBAAqB,GACjE;AACO,eAAA;AAAA,MACT;AAEA,UAAI,iBAAiB;AACZ,eAAA,EAAE,KAAK,WAAW,eAAe;AAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACR;AAED,UAAM,QAAQ;AAAA,MACZ,QAAQ,IAAI,OAAO,WAAW;;AAC5B,cAAM,WAAW,KAAK,KAAK,SAAS,OAAO,IAAI;AAC/C,cAAM,eAAe,KAAK,KAAK,KAAK,OAAO,IAAI;AAE3C,YAA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AC,MAAM,EAAE,cAAc,IAAI,UAAU,EAAE;AAEjD,aAAW,SAAS,aAAa;AAC/B,QAAI,MAAM,cAAc;AAAK;AAG3B,QAAA,iBAAiB,WAAW,GAAG,MAAM,SAAS,GAAG,KACjD,MAAM,cAAc,kBACpB;AACO,aAAA;AAAA,IACT;AAAA,EACF;AACM,QAAA,WAAW,iBAAiB,MAAM,GAAG;AAC3C,WAAS,IAAI;AACP,QAAA,kBAAkB,SAAS,KAAK,GAAG;AAElC,SAAA,eAAe,QAAQ,eAAe;AAC/C;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"generator.cjs","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs'\nimport * as fsp from 'fs/promises'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, logging, trimPathLeft } from './utils'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isLayout?: boolean\n isVirtualParentRequired?: boolean\n isVirtualParentRoute?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isErrorComponent?: boolean\n isPendingComponent?: boolean\n isVirtual?: boolean\n isLazy?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n const logger = logging({ disabled: config.disableLogging })\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath =\n cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n }\n\n const variableName = routePathToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n\n let isLazy = routePath?.endsWith('/lazy')\n\n if (isLazy) {\n routePath = routePath?.replace(/\\/lazy$/, '')\n }\n\n let isRoute = routePath?.endsWith('/route')\n let isComponent = routePath?.endsWith('/component')\n let isErrorComponent = routePath?.endsWith('/errorComponent')\n let isPendingComponent = routePath?.endsWith('/pendingComponent')\n let isLoader = routePath?.endsWith('/loader')\n\n const segments = (routePath ?? '').split('/')\n let isLayout = segments[segments.length - 1]?.startsWith('_') || false\n\n ;(\n [\n [isComponent, 'component'],\n [isErrorComponent, 'errorComponent'],\n [isPendingComponent, 'pendingComponent'],\n [isLoader, 'loader'],\n ] as const\n ).forEach(([isType, type]) => {\n if (isType) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n\n routePath = routePath?.replace(\n /\\/(component|errorComponent|pendingComponent|loader|route|lazy)$/,\n '',\n )\n\n if (routePath === 'index') {\n routePath = '/'\n }\n\n routePath = routePath.replace(/\\/index$/, '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\n isLazy,\n isLayout,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n errorComponent?: RouteNode\n pendingComponent?: RouteNode\n loader?: RouteNode\n lazy?: RouteNode\n}\n\nexport async function generator(config: Config) {\n const logger = logging({ disabled: config.disableLogging })\n logger.log('')\n\n if (!first) {\n logger.log('♻️ Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n logger.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n const beforeRouteNodes = await getRouteNodes(config)\n const rootRouteNode = beforeRouteNodes.find(\n (d) => d.routePath === `/${rootPathId}`,\n )\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) =>\n d.filePath?.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = async (node: RouteNode) => {\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? ''\n\n node.isNonPath = lastRouteSegment.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes\n if (!node.isVirtualParentRoute) {\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n const escapedRoutePath = removeTrailingUnderscores(\n node.routePath?.replaceAll('$', '$$') ?? '',\n )\n\n let replaced = routeCode\n\n if (!routeCode) {\n if (node.isLazy) {\n replaced = [\n `import { createLazyFileRoute } from '@tanstack/react-router'`,\n `export const Route = createLazyFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n})`,\n ].join('\\n\\n')\n } else if (\n node.isRoute ||\n (!node.isComponent &&\n !node.isErrorComponent &&\n !node.isPendingComponent &&\n !node.isLoader)\n ) {\n replaced = [\n `import { createFileRoute } from '@tanstack/react-router'`,\n `export const Route = createFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n})`,\n ].join('\\n\\n')\n }\n } else {\n replaced = routeCode\n .replace(\n /(FileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createLazyFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n }\n\n if (replaced !== routeCode) {\n logger.log(`🟡 Updating ${node.fullPath}`)\n await fsp.writeFile(node.fullPath, replaced)\n }\n }\n\n if (\n !node.isVirtual &&\n (node.isLoader ||\n node.isComponent ||\n node.isErrorComponent ||\n node.isPendingComponent ||\n node.isLazy)\n ) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLazy\n ? 'lazy'\n : node.isLoader\n ? 'loader'\n : node.isErrorComponent\n ? 'errorComponent'\n : node.isPendingComponent\n ? 'pendingComponent'\n : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)\n\n if (!anchorRoute) {\n await handleNode({\n ...node,\n isVirtual: true,\n isLazy: false,\n isLoader: false,\n isComponent: false,\n isErrorComponent: false,\n isPendingComponent: false,\n })\n }\n return\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n\n node.isVirtualParentRequired = node.isLayout\n ? !cleanedPathIsEmpty && !node.parent\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n isLayout: false,\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node.isLayout) {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n await Promise.all(preRouteNodes.map((node) => handleNode(node)))\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n if (node.isRoot) {\n return\n }\n\n if (node.isLayout && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n lazyFn: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.loader,\n ),\n lazyRouteComponent: sortedRouteNodes.some(\n (node) =>\n routePiecesByPath[node.routePath!]?.component ||\n routePiecesByPath[node.routePath!]?.errorComponent ||\n routePiecesByPath[node.routePath!]?.pendingComponent,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes\n .filter((d) => d.isVirtual)\n .reduce((acc, route) => {\n // ensuring we don't have any duplicated virtual routes or clashes with pre-existing routes\n const existingPreNode = preRouteNodes.filter(\n (d) => d.routePath === route.routePath,\n )\n\n if (existingPreNode.length === 0) {\n acc.push(route)\n }\n\n return acc\n }, [] as RouteNode[])\n\n const rootPathIdExtension =\n config.addExtensions && rootRouteNode\n ? path.extname(rootRouteNode.filePath)\n : ''\n\n const routeImports = [\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n '// This file is auto-generated by TanStack Router',\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n '// Import Routes',\n [\n `import { Route as rootRoute } from './${replaceBackslash(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n `${routePathIdPrefix}${rootPathId}${rootPathIdExtension}`,\n ),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }Import = createFileRoute('${removeTrailingUnderscores(\n node.routePath,\n )}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n sortedRouteNodes\n .reduce((acc, node) => {\n // ensuring we update a unique route only once\n if (acc.find((d) => d.routePath === node.routePath)) {\n return acc\n }\n acc.push(node)\n return acc\n }, [] as RouteNode[])\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n const errorComponentNode =\n routePiecesByPath[node.routePath!]?.errorComponent\n const pendingComponentNode =\n routePiecesByPath[node.routePath!]?.pendingComponent\n const lazyComponentNode = routePiecesByPath[node.routePath!]?.lazy\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode || errorComponentNode || pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n ),\n config.addExtensions,\n ),\n )}'), '${d[0]}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? `.lazy(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )}').then((d) => d.Route))`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n ...(config.disableTypes\n ? []\n : [\n '// Populate the FileRoutesByPath interface',\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${removeTrailingUnderscores(routeNode.routePath)}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent?.variableName}Import`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n ]),\n '// Create and export the route tree',\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n '/* prettier-ignore-end */',\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n })\n\n const routeTreeContent = await fsp\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {\n recursive: true,\n })\n if (!checkLatest()) return\n await fsp.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n logger.log(\n `✅ Processed ${routeNodes.length === 1 ? 'route' : 'routes'} in ${\n Date.now() - start\n }ms`,\n )\n}\n\nfunction routePathToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\/\\$\\//g, '/splat/')\n ?.replace(/\\$$/g, 'splat')\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '')\n .replace(/^(\\d)/g, 'R$1') ?? ''\n )\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replaceAll(/(^_|_$)/gi, '').replaceAll(/(\\/_|_\\/)/gi, '/')\n}\n\nfunction removeTrailingUnderscores(s?: string) {\n return s?.replaceAll(/(_$)/gi, '').replaceAll(/(_\\/)/gi, '/')\n}\n\nfunction replaceBackslash(s: string) {\n return s.replaceAll(/\\\\/gi, '/')\n}\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} path - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(path: string = '/'): string {\n const segments = path.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} path - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(path: string = '/'): string {\n const segments = path.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n if (node.isLayout) {\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n // a layout route's parent has to exactly match the layout route minus, the layout segment\n const exactParentRoutePath = removeLastSegmentFromPath(node.routePath)\n if (route.routePath === exactParentRoutePath) {\n return route\n }\n }\n } else {\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n"],"names":["logging","fsp","cleanPath","trimPathLeft","first","fs","prettier","d","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAI,aAAa;AACV,MAAM,aAAa;AAC1B,MAAM,yBAAyB;AA0B/B,eAAe,cAAc,QAAgB;AACrC,QAAA,EAAE,iBAAiB,sBAA0B,IAAA;AACnD,QAAM,SAASA,MAAAA,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAE1D,MAAI,aAA0B,CAAA;AAE9B,iBAAe,QAAQ,KAAa;AAClC,UAAM,UAAU,KAAK,QAAQ,OAAO,iBAAiB,GAAG;AACpD,QAAA,UAAU,MAAMC,eAAI,QAAQ,SAAS,EAAE,eAAe,MAAM;AAEtD,cAAA,QAAQ,OAAO,CAAC,MAAM;AAE5B,UAAA,EAAE,KAAK,WAAW,GAAG,KACpB,yBAAyB,EAAE,KAAK,WAAW,qBAAqB,GACjE;AACO,eAAA;AAAA,MACT;AAEA,UAAI,iBAAiB;AACZ,eAAA,EAAE,KAAK,WAAW,eAAe;AAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACR;AAED,UAAM,QAAQ;AAAA,MACZ,QAAQ,IAAI,OAAO,WAAW;;AAC5B,cAAM,WAAW,KAAK,KAAK,SAAS,OAAO,IAAI;AAC/C,cAAM,eAAe,KAAK,KAAK,KAAK,OAAO,IAAI;AAE3C,YAAA,OAAO,eAAe;AACxB,gBAAM,QAAQ,YAAY;AAAA,QAC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((item: T) => any)[
|
|
|
35
35
|
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
36
36
|
*/
|
|
37
37
|
export declare function removeLastSegmentFromPath(path?: string): string;
|
|
38
|
-
export declare function hasParentRoute(routes: RouteNode[], routePathToCheck: string | undefined): RouteNode | null;
|
|
38
|
+
export declare function hasParentRoute(routes: RouteNode[], node: RouteNode, routePathToCheck: string | undefined): RouteNode | null;
|
package/dist/esm/generator.d.ts
CHANGED
|
@@ -35,4 +35,4 @@ export declare function multiSortBy<T>(arr: T[], accessors?: ((item: T) => any)[
|
|
|
35
35
|
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
36
36
|
*/
|
|
37
37
|
export declare function removeLastSegmentFromPath(path?: string): string;
|
|
38
|
-
export declare function hasParentRoute(routes: RouteNode[], routePathToCheck: string | undefined): RouteNode | null;
|
|
38
|
+
export declare function hasParentRoute(routes: RouteNode[], node: RouteNode, routePathToCheck: string | undefined): RouteNode | null;
|
package/dist/esm/generator.js
CHANGED
|
@@ -147,11 +147,12 @@ async function generator(config) {
|
|
|
147
147
|
const routePiecesByPath = {};
|
|
148
148
|
let routeNodes = [];
|
|
149
149
|
const handleNode = async (node) => {
|
|
150
|
-
var _a, _b
|
|
151
|
-
let parentRoute = hasParentRoute(routeNodes, node.routePath);
|
|
150
|
+
var _a, _b;
|
|
151
|
+
let parentRoute = hasParentRoute(routeNodes, node, node.routePath);
|
|
152
152
|
if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
|
|
153
153
|
const possibleParentRoute = hasParentRoute(
|
|
154
154
|
parentRoute.children,
|
|
155
|
+
node,
|
|
155
156
|
node.routePath
|
|
156
157
|
);
|
|
157
158
|
if (possibleParentRoute) {
|
|
@@ -160,7 +161,7 @@ async function generator(config) {
|
|
|
160
161
|
}
|
|
161
162
|
if (parentRoute)
|
|
162
163
|
node.parent = parentRoute;
|
|
163
|
-
node.path =
|
|
164
|
+
node.path = determineNodePath(node);
|
|
164
165
|
const trimmedPath = trimPathLeft(node.path ?? "");
|
|
165
166
|
const split = (trimmedPath == null ? void 0 : trimmedPath.split("/")) ?? [];
|
|
166
167
|
let first2 = split[0] ?? trimmedPath ?? "";
|
|
@@ -173,7 +174,7 @@ async function generator(config) {
|
|
|
173
174
|
if (!node.isVirtualParentRoute) {
|
|
174
175
|
const routeCode = fs.readFileSync(node.fullPath, "utf-8");
|
|
175
176
|
const escapedRoutePath = removeTrailingUnderscores(
|
|
176
|
-
((
|
|
177
|
+
((_b = node.routePath) == null ? void 0 : _b.replaceAll("$", "$$")) ?? ""
|
|
177
178
|
);
|
|
178
179
|
let replaced = routeCode;
|
|
179
180
|
if (!routeCode) {
|
|
@@ -181,15 +182,15 @@ async function generator(config) {
|
|
|
181
182
|
replaced = [
|
|
182
183
|
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
183
184
|
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
186
|
+
})`
|
|
186
187
|
].join("\n\n");
|
|
187
188
|
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
188
189
|
replaced = [
|
|
189
190
|
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
190
191
|
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
191
|
-
|
|
192
|
-
|
|
192
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
193
|
+
})`
|
|
193
194
|
].join("\n\n");
|
|
194
195
|
}
|
|
195
196
|
} else {
|
|
@@ -226,10 +227,11 @@ async function generator(config) {
|
|
|
226
227
|
}
|
|
227
228
|
return;
|
|
228
229
|
}
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
const cleanedPathIsEmpty = (node.cleanedPath || "").length === 0;
|
|
231
|
+
node.isVirtualParentRequired = node.isLayout ? !cleanedPathIsEmpty && !node.parent : false;
|
|
231
232
|
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
232
233
|
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
234
|
+
const parentVariableName = routePathToVariable(parentRoutePath);
|
|
233
235
|
const anchorRoute = routeNodes.find(
|
|
234
236
|
(d) => d.routePath === parentRoutePath
|
|
235
237
|
);
|
|
@@ -240,7 +242,7 @@ async function generator(config) {
|
|
|
240
242
|
filePath: removeLastSegmentFromPath(node.filePath) || "/",
|
|
241
243
|
fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
|
|
242
244
|
routePath: parentRoutePath,
|
|
243
|
-
variableName:
|
|
245
|
+
variableName: parentVariableName,
|
|
244
246
|
isVirtual: true,
|
|
245
247
|
isLayout: false,
|
|
246
248
|
isVirtualParentRoute: true,
|
|
@@ -249,6 +251,9 @@ async function generator(config) {
|
|
|
249
251
|
parentNode.children = parentNode.children ?? [];
|
|
250
252
|
parentNode.children.push(node);
|
|
251
253
|
node.parent = parentNode;
|
|
254
|
+
if (node.isLayout) {
|
|
255
|
+
node.path = determineNodePath(node);
|
|
256
|
+
}
|
|
252
257
|
await handleNode(parentNode);
|
|
253
258
|
} else {
|
|
254
259
|
anchorRoute.children = anchorRoute.children ?? [];
|
|
@@ -269,12 +274,15 @@ async function generator(config) {
|
|
|
269
274
|
await Promise.all(preRouteNodes.map((node) => handleNode(node)));
|
|
270
275
|
async function buildRouteConfig(nodes, depth = 1) {
|
|
271
276
|
const children = nodes.map(async (node) => {
|
|
272
|
-
var _a;
|
|
277
|
+
var _a, _b;
|
|
273
278
|
if (node.isRoot) {
|
|
274
279
|
return;
|
|
275
280
|
}
|
|
281
|
+
if (node.isLayout && !((_a = node.children) == null ? void 0 : _a.length)) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
276
284
|
const route = `${node.variableName}Route`;
|
|
277
|
-
if ((
|
|
285
|
+
if ((_b = node.children) == null ? void 0 : _b.length) {
|
|
278
286
|
const childConfigs = await buildRouteConfig(node.children, depth + 1);
|
|
279
287
|
return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`;
|
|
280
288
|
}
|
|
@@ -313,7 +321,15 @@ async function generator(config) {
|
|
|
313
321
|
}
|
|
314
322
|
)
|
|
315
323
|
}).filter((d) => d[1]).map((d) => d[0]);
|
|
316
|
-
const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)
|
|
324
|
+
const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual).reduce((acc, route) => {
|
|
325
|
+
const existingPreNode = preRouteNodes.filter(
|
|
326
|
+
(d) => d.routePath === route.routePath
|
|
327
|
+
);
|
|
328
|
+
if (existingPreNode.length === 0) {
|
|
329
|
+
acc.push(route);
|
|
330
|
+
}
|
|
331
|
+
return acc;
|
|
332
|
+
}, []);
|
|
317
333
|
const rootPathIdExtension = config.addExtensions && rootRouteNode ? path.extname(rootRouteNode.filePath) : "";
|
|
318
334
|
const routeImports = [
|
|
319
335
|
"/* prettier-ignore-start */",
|
|
@@ -353,7 +369,13 @@ async function generator(config) {
|
|
|
353
369
|
)}')()`;
|
|
354
370
|
}).join("\n"),
|
|
355
371
|
"// Create/Update Routes",
|
|
356
|
-
sortedRouteNodes.
|
|
372
|
+
sortedRouteNodes.reduce((acc, node) => {
|
|
373
|
+
if (acc.find((d) => d.routePath === node.routePath)) {
|
|
374
|
+
return acc;
|
|
375
|
+
}
|
|
376
|
+
acc.push(node);
|
|
377
|
+
return acc;
|
|
378
|
+
}, []).map((node) => {
|
|
357
379
|
var _a, _b, _c, _d, _e, _f;
|
|
358
380
|
const loaderNode = (_a = routePiecesByPath[node.routePath]) == null ? void 0 : _a.loader;
|
|
359
381
|
const componentNode = (_b = routePiecesByPath[node.routePath]) == null ? void 0 : _b.component;
|
|
@@ -499,6 +521,10 @@ function replaceBackslash(s) {
|
|
|
499
521
|
function removeGroups(s) {
|
|
500
522
|
return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
|
|
501
523
|
}
|
|
524
|
+
function determineNodePath(node) {
|
|
525
|
+
var _a;
|
|
526
|
+
return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath, "")) || "/" : node.routePath;
|
|
527
|
+
}
|
|
502
528
|
function removeLastSegmentFromPath(path2 = "/") {
|
|
503
529
|
const segments = path2.split("/");
|
|
504
530
|
segments.pop();
|
|
@@ -509,7 +535,7 @@ function removeLayoutSegments(path2 = "/") {
|
|
|
509
535
|
const newSegments = segments.filter((segment) => !segment.startsWith("_"));
|
|
510
536
|
return newSegments.join("/");
|
|
511
537
|
}
|
|
512
|
-
function hasParentRoute(routes, routePathToCheck) {
|
|
538
|
+
function hasParentRoute(routes, node, routePathToCheck) {
|
|
513
539
|
if (!routePathToCheck || routePathToCheck === "/") {
|
|
514
540
|
return null;
|
|
515
541
|
}
|
|
@@ -517,17 +543,28 @@ function hasParentRoute(routes, routePathToCheck) {
|
|
|
517
543
|
(d) => d.routePath.length * -1,
|
|
518
544
|
(d) => d.variableName
|
|
519
545
|
]).filter((d) => d.routePath !== `/${rootPathId}`);
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
546
|
+
if (node.isLayout) {
|
|
547
|
+
for (const route of sortedNodes) {
|
|
548
|
+
if (route.routePath === "/")
|
|
549
|
+
continue;
|
|
550
|
+
const exactParentRoutePath = removeLastSegmentFromPath(node.routePath);
|
|
551
|
+
if (route.routePath === exactParentRoutePath) {
|
|
552
|
+
return route;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
for (const route of sortedNodes) {
|
|
557
|
+
if (route.routePath === "/")
|
|
558
|
+
continue;
|
|
559
|
+
if (routePathToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routePathToCheck) {
|
|
560
|
+
return route;
|
|
561
|
+
}
|
|
525
562
|
}
|
|
526
563
|
}
|
|
527
564
|
const segments = routePathToCheck.split("/");
|
|
528
565
|
segments.pop();
|
|
529
566
|
const parentRoutePath = segments.join("/");
|
|
530
|
-
return hasParentRoute(routes, parentRoutePath);
|
|
567
|
+
return hasParentRoute(routes, node, parentRoutePath);
|
|
531
568
|
}
|
|
532
569
|
export {
|
|
533
570
|
generator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs'\nimport * as fsp from 'fs/promises'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, logging, trimPathLeft } from './utils'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isLayout?: boolean\n isVirtualParentRequired?: boolean\n isVirtualParentRoute?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isErrorComponent?: boolean\n isPendingComponent?: boolean\n isVirtual?: boolean\n isLazy?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n const logger = logging({ disabled: config.disableLogging })\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath =\n cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n }\n\n const variableName = routePathToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n\n let isLazy = routePath?.endsWith('/lazy')\n\n if (isLazy) {\n routePath = routePath?.replace(/\\/lazy$/, '')\n }\n\n let isRoute = routePath?.endsWith('/route')\n let isComponent = routePath?.endsWith('/component')\n let isErrorComponent = routePath?.endsWith('/errorComponent')\n let isPendingComponent = routePath?.endsWith('/pendingComponent')\n let isLoader = routePath?.endsWith('/loader')\n\n const segments = (routePath ?? '').split('/')\n let isLayout = segments[segments.length - 1]?.startsWith('_') || false\n\n ;(\n [\n [isComponent, 'component'],\n [isErrorComponent, 'errorComponent'],\n [isPendingComponent, 'pendingComponent'],\n [isLoader, 'loader'],\n ] as const\n ).forEach(([isType, type]) => {\n if (isType) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n\n routePath = routePath?.replace(\n /\\/(component|errorComponent|pendingComponent|loader|route|lazy)$/,\n '',\n )\n\n if (routePath === 'index') {\n routePath = '/'\n }\n\n routePath = routePath.replace(/\\/index$/, '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\n isLazy,\n isLayout,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n errorComponent?: RouteNode\n pendingComponent?: RouteNode\n loader?: RouteNode\n lazy?: RouteNode\n}\n\nexport async function generator(config: Config) {\n const logger = logging({ disabled: config.disableLogging })\n logger.log('')\n\n if (!first) {\n logger.log('♻️ Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n logger.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n const beforeRouteNodes = await getRouteNodes(config)\n const rootRouteNode = beforeRouteNodes.find(\n (d) => d.routePath === `/${rootPathId}`,\n )\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) =>\n d.filePath?.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = async (node: RouteNode) => {\n let parentRoute = hasParentRoute(routeNodes, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? ''\n\n node.isNonPath = lastRouteSegment.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes\n if (!node.isVirtualParentRoute) {\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n const escapedRoutePath = removeTrailingUnderscores(\n node.routePath?.replaceAll('$', '$$') ?? '',\n )\n\n let replaced = routeCode\n\n if (!routeCode) {\n if (node.isLazy) {\n replaced = [\n `import { createLazyFileRoute } from '@tanstack/react-router'`,\n `export const Route = createLazyFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n })`,\n ].join('\\n\\n')\n } else if (\n node.isRoute ||\n (!node.isComponent &&\n !node.isErrorComponent &&\n !node.isPendingComponent &&\n !node.isLoader)\n ) {\n replaced = [\n `import { createFileRoute } from '@tanstack/react-router'`,\n `export const Route = createFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n })`,\n ].join('\\n\\n')\n }\n } else {\n replaced = routeCode\n .replace(\n /(FileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createLazyFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n }\n\n if (replaced !== routeCode) {\n logger.log(`🟡 Updating ${node.fullPath}`)\n await fsp.writeFile(node.fullPath, replaced)\n }\n }\n\n if (\n !node.isVirtual &&\n (node.isLoader ||\n node.isComponent ||\n node.isErrorComponent ||\n node.isPendingComponent ||\n node.isLazy)\n ) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLazy\n ? 'lazy'\n : node.isLoader\n ? 'loader'\n : node.isErrorComponent\n ? 'errorComponent'\n : node.isPendingComponent\n ? 'pendingComponent'\n : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)\n\n if (!anchorRoute) {\n await handleNode({\n ...node,\n isVirtual: true,\n isLazy: false,\n isLoader: false,\n isComponent: false,\n isErrorComponent: false,\n isPendingComponent: false,\n })\n }\n return\n }\n\n node.isVirtualParentRequired =\n removeGroups(node.path ?? '')\n .split('')\n .filter((char) => char === '/').length >= 2 && // check that the parent route wouldn't be the root route\n !node.parent &&\n node.isLayout\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: routePathToVariable(parentRoutePath),\n isVirtual: true,\n isLayout: false,\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n await Promise.all(preRouteNodes.map((node) => handleNode(node)))\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n if (node.isRoot) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n lazyFn: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.loader,\n ),\n lazyRouteComponent: sortedRouteNodes.some(\n (node) =>\n routePiecesByPath[node.routePath!]?.component ||\n routePiecesByPath[node.routePath!]?.errorComponent ||\n routePiecesByPath[node.routePath!]?.pendingComponent,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n const rootPathIdExtension =\n config.addExtensions && rootRouteNode\n ? path.extname(rootRouteNode.filePath)\n : ''\n\n const routeImports = [\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n '// This file is auto-generated by TanStack Router',\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n '// Import Routes',\n [\n `import { Route as rootRoute } from './${replaceBackslash(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n `${routePathIdPrefix}${rootPathId}${rootPathIdExtension}`,\n ),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }Import = createFileRoute('${removeTrailingUnderscores(\n node.routePath,\n )}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n sortedRouteNodes\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n const errorComponentNode =\n routePiecesByPath[node.routePath!]?.errorComponent\n const pendingComponentNode =\n routePiecesByPath[node.routePath!]?.pendingComponent\n const lazyComponentNode = routePiecesByPath[node.routePath!]?.lazy\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode || errorComponentNode || pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n ),\n config.addExtensions,\n ),\n )}'), '${d[0]}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? `.lazy(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )}').then((d) => d.Route))`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n ...(config.disableTypes\n ? []\n : [\n '// Populate the FileRoutesByPath interface',\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${removeTrailingUnderscores(routeNode.routePath)}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent?.variableName}Import`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n ]),\n '// Create and export the route tree',\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n '/* prettier-ignore-end */',\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n })\n\n const routeTreeContent = await fsp\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {\n recursive: true,\n })\n if (!checkLatest()) return\n await fsp.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n logger.log(\n `✅ Processed ${routeNodes.length === 1 ? 'route' : 'routes'} in ${\n Date.now() - start\n }ms`,\n )\n}\n\nfunction routePathToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\/\\$\\//g, '/splat/')\n ?.replace(/\\$$/g, 'splat')\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '')\n .replace(/^(\\d)/g, 'R$1') ?? ''\n )\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replaceAll(/(^_|_$)/gi, '').replaceAll(/(\\/_|_\\/)/gi, '/')\n}\n\nfunction removeTrailingUnderscores(s?: string) {\n return s?.replaceAll(/(_$)/gi, '').replaceAll(/(_\\/)/gi, '/')\n}\n\nfunction replaceBackslash(s: string) {\n return s.replaceAll(/\\\\/gi, '/')\n}\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} path - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(path: string = '/'): string {\n const segments = path.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} path - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(path: string = '/'): string {\n const segments = path.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, parentRoutePath)\n}\n"],"names":["first","d","path"],"mappings":";;;;;AAOA,IAAI,aAAa;AACV,MAAM,aAAa;AAC1B,MAAM,yBAAyB;AA0B/B,eAAe,cAAc,QAAgB;AACrC,QAAA,EAAE,iBAAiB,sBAA0B,IAAA;AACnD,QAAM,SAAS,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAE1D,MAAI,aAA0B,CAAA;AAE9B,iBAAe,QAAQ,KAAa;AAClC,UAAM,UAAU,KAAK,QAAQ,OAAO,iBAAiB,GAAG;AACpD,QAAA,UAAU,MAAM,IAAI,QAAQ,SAAS,EAAE,eAAe,MAAM;AAEtD,cAAA,QAAQ,OAAO,CAAC,MAAM;AAE5B,UAAA,EAAE,KAAK,WAAW,GAAG,KACpB,yBAAyB,EAAE,KAAK,WAAW,qBAAqB,GACjE;AACO,eAAA;AAAA,MACT;AAEA,UAAI,iBAAiB;AACZ,eAAA,EAAE,KAAK,WAAW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C,oBAAoB,qBAAqB,KAAK;AAC1C,WAAA;AAAA,EACT;AAEM,QAAA,cAAc,YAAY,QAAQ;AAAA,IACtC,CAAC,MAAM,EAAE,UAAW,SAAS;AAAA,IAC7B,CAAC,MAAM,EAAE;AAAA,EAAA,CACV,EAAE,OAAO,CAAC,MAAM,EAAE,cAAc,IAAI,UAAU,EAAE;AAEjD,aAAW,SAAS,aAAa;AAC/B,QAAI,MAAM,cAAc;AAAK;AAG3B,QAAA,iBAAiB,WAAW,GAAG,MAAM,SAAS,GAAG,KACjD,MAAM,cAAc,kBACpB;AACO,aAAA;AAAA,IACT;AAAA,EACF;AACM,QAAA,WAAW,iBAAiB,MAAM,GAAG;AAC3C,WAAS,IAAI;AACP,QAAA,kBAAkB,SAAS,KAAK,GAAG;AAElC,SAAA,eAAe,QAAQ,eAAe;AAC/C;"}
|
|
1
|
+
{"version":3,"file":"generator.js","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs'\nimport * as fsp from 'fs/promises'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, logging, trimPathLeft } from './utils'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isLayout?: boolean\n isVirtualParentRequired?: boolean\n isVirtualParentRoute?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isErrorComponent?: boolean\n isPendingComponent?: boolean\n isVirtual?: boolean\n isLazy?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n const logger = logging({ disabled: config.disableLogging })\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath =\n cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n }\n\n const variableName = routePathToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n\n let isLazy = routePath?.endsWith('/lazy')\n\n if (isLazy) {\n routePath = routePath?.replace(/\\/lazy$/, '')\n }\n\n let isRoute = routePath?.endsWith('/route')\n let isComponent = routePath?.endsWith('/component')\n let isErrorComponent = routePath?.endsWith('/errorComponent')\n let isPendingComponent = routePath?.endsWith('/pendingComponent')\n let isLoader = routePath?.endsWith('/loader')\n\n const segments = (routePath ?? '').split('/')\n let isLayout = segments[segments.length - 1]?.startsWith('_') || false\n\n ;(\n [\n [isComponent, 'component'],\n [isErrorComponent, 'errorComponent'],\n [isPendingComponent, 'pendingComponent'],\n [isLoader, 'loader'],\n ] as const\n ).forEach(([isType, type]) => {\n if (isType) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n\n routePath = routePath?.replace(\n /\\/(component|errorComponent|pendingComponent|loader|route|lazy)$/,\n '',\n )\n\n if (routePath === 'index') {\n routePath = '/'\n }\n\n routePath = routePath.replace(/\\/index$/, '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\n isLazy,\n isLayout,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n errorComponent?: RouteNode\n pendingComponent?: RouteNode\n loader?: RouteNode\n lazy?: RouteNode\n}\n\nexport async function generator(config: Config) {\n const logger = logging({ disabled: config.disableLogging })\n logger.log('')\n\n if (!first) {\n logger.log('♻️ Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n logger.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n const beforeRouteNodes = await getRouteNodes(config)\n const rootRouteNode = beforeRouteNodes.find(\n (d) => d.routePath === `/${rootPathId}`,\n )\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) =>\n d.filePath?.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = async (node: RouteNode) => {\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? ''\n\n node.isNonPath = lastRouteSegment.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes\n if (!node.isVirtualParentRoute) {\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n const escapedRoutePath = removeTrailingUnderscores(\n node.routePath?.replaceAll('$', '$$') ?? '',\n )\n\n let replaced = routeCode\n\n if (!routeCode) {\n if (node.isLazy) {\n replaced = [\n `import { createLazyFileRoute } from '@tanstack/react-router'`,\n `export const Route = createLazyFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n})`,\n ].join('\\n\\n')\n } else if (\n node.isRoute ||\n (!node.isComponent &&\n !node.isErrorComponent &&\n !node.isPendingComponent &&\n !node.isLoader)\n ) {\n replaced = [\n `import { createFileRoute } from '@tanstack/react-router'`,\n `export const Route = createFileRoute('${escapedRoutePath}')({\n component: () => <div>Hello ${escapedRoutePath}!</div>\n})`,\n ].join('\\n\\n')\n }\n } else {\n replaced = routeCode\n .replace(\n /(FileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n .replace(\n /(createLazyFileRoute\\(\\s*['\"])([^\\s]*)(['\"],?\\s*\\))/g,\n (match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,\n )\n }\n\n if (replaced !== routeCode) {\n logger.log(`🟡 Updating ${node.fullPath}`)\n await fsp.writeFile(node.fullPath, replaced)\n }\n }\n\n if (\n !node.isVirtual &&\n (node.isLoader ||\n node.isComponent ||\n node.isErrorComponent ||\n node.isPendingComponent ||\n node.isLazy)\n ) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLazy\n ? 'lazy'\n : node.isLoader\n ? 'loader'\n : node.isErrorComponent\n ? 'errorComponent'\n : node.isPendingComponent\n ? 'pendingComponent'\n : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)\n\n if (!anchorRoute) {\n await handleNode({\n ...node,\n isVirtual: true,\n isLazy: false,\n isLoader: false,\n isComponent: false,\n isErrorComponent: false,\n isPendingComponent: false,\n })\n }\n return\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n\n node.isVirtualParentRequired = node.isLayout\n ? !cleanedPathIsEmpty && !node.parent\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n isLayout: false,\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node.isLayout) {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n await Promise.all(preRouteNodes.map((node) => handleNode(node)))\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n if (node.isRoot) {\n return\n }\n\n if (node.isLayout && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n lazyFn: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.loader,\n ),\n lazyRouteComponent: sortedRouteNodes.some(\n (node) =>\n routePiecesByPath[node.routePath!]?.component ||\n routePiecesByPath[node.routePath!]?.errorComponent ||\n routePiecesByPath[node.routePath!]?.pendingComponent,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes\n .filter((d) => d.isVirtual)\n .reduce((acc, route) => {\n // ensuring we don't have any duplicated virtual routes or clashes with pre-existing routes\n const existingPreNode = preRouteNodes.filter(\n (d) => d.routePath === route.routePath,\n )\n\n if (existingPreNode.length === 0) {\n acc.push(route)\n }\n\n return acc\n }, [] as RouteNode[])\n\n const rootPathIdExtension =\n config.addExtensions && rootRouteNode\n ? path.extname(rootRouteNode.filePath)\n : ''\n\n const routeImports = [\n '/* prettier-ignore-start */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n '// This file is auto-generated by TanStack Router',\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n '// Import Routes',\n [\n `import { Route as rootRoute } from './${replaceBackslash(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n `${routePathIdPrefix}${rootPathId}${rootPathIdExtension}`,\n ),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }Import = createFileRoute('${removeTrailingUnderscores(\n node.routePath,\n )}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n sortedRouteNodes\n .reduce((acc, node) => {\n // ensuring we update a unique route only once\n if (acc.find((d) => d.routePath === node.routePath)) {\n return acc\n }\n acc.push(node)\n return acc\n }, [] as RouteNode[])\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n const errorComponentNode =\n routePiecesByPath[node.routePath!]?.errorComponent\n const pendingComponentNode =\n routePiecesByPath[node.routePath!]?.pendingComponent\n const lazyComponentNode = routePiecesByPath[node.routePath!]?.lazy\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode || errorComponentNode || pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n ),\n config.addExtensions,\n ),\n )}'), '${d[0]}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? `.lazy(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )}').then((d) => d.Route))`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n ...(config.disableTypes\n ? []\n : [\n '// Populate the FileRoutesByPath interface',\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${removeTrailingUnderscores(routeNode.routePath)}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent?.variableName}Import`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n ]),\n '// Create and export the route tree',\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n '/* prettier-ignore-end */',\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n })\n\n const routeTreeContent = await fsp\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {\n recursive: true,\n })\n if (!checkLatest()) return\n await fsp.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n logger.log(\n `✅ Processed ${routeNodes.length === 1 ? 'route' : 'routes'} in ${\n Date.now() - start\n }ms`,\n )\n}\n\nfunction routePathToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\/\\$\\//g, '/splat/')\n ?.replace(/\\$$/g, 'splat')\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '')\n .replace(/^(\\d)/g, 'R$1') ?? ''\n )\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replaceAll(/(^_|_$)/gi, '').replaceAll(/(\\/_|_\\/)/gi, '/')\n}\n\nfunction removeTrailingUnderscores(s?: string) {\n return s?.replaceAll(/(_$)/gi, '').replaceAll(/(_\\/)/gi, '/')\n}\n\nfunction replaceBackslash(s: string) {\n return s.replaceAll(/\\\\/gi, '/')\n}\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} path - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(path: string = '/'): string {\n const segments = path.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} path - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(path: string = '/'): string {\n const segments = path.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n if (node.isLayout) {\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n // a layout route's parent has to exactly match the layout route minus, the layout segment\n const exactParentRoutePath = removeLastSegmentFromPath(node.routePath)\n if (route.routePath === exactParentRoutePath) {\n return route\n }\n }\n } else {\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n"],"names":["first","d","path"],"mappings":";;;;;AAOA,IAAI,aAAa;AACV,MAAM,aAAa;AAC1B,MAAM,yBAAyB;AA0B/B,eAAe,cAAc,QAAgB;AACrC,QAAA,EAAE,iBAAiB,sBAA0B,IAAA;AACnD,QAAM,SAAS,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAE1D,MAAI,aAA0B,CAAA;AAE9B,iBAAe,QAAQ,KAAa;AAClC,UAAM,UAAU,KAAK,QAAQ,OAAO,iBAAiB,GAAG;AACpD,QAAA,UAAU,MAAM,IAAI,QAAQ,SAAS,EAAE,eAAe,MAAM;AAEtD,cAAA,QAAQ,OAAO,CAAC,MAAM;AAE5B,UAAA,EAAE,KAAK,WAAW,GAAG,KACpB,yBAAyB,EAAE,KAAK,WAAW,qBAAqB,GACjE;AACO,eAAA;AAAA,MACT;AAEA,UAAI,iBAAiB;AACZ,eAAA,EAAE,KAAK,WAAW,eAAe;AAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACR;AAED,UAAM,QAAQ;AAAA,MACZ,QAAQ,IAAI,OAAO,WAAW;;AAC5B,cAAM,WAAW,KAAK,KAAK,SAAS,OAAO,IAAI;A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HANGED
package/src/generator.ts
CHANGED
|
@@ -212,13 +212,14 @@ export async function generator(config: Config) {
|
|
|
212
212
|
let routeNodes: RouteNode[] = []
|
|
213
213
|
|
|
214
214
|
const handleNode = async (node: RouteNode) => {
|
|
215
|
-
let parentRoute = hasParentRoute(routeNodes, node.routePath)
|
|
215
|
+
let parentRoute = hasParentRoute(routeNodes, node, node.routePath)
|
|
216
216
|
|
|
217
217
|
// if the parent route is a virtual parent route, we need to find the real parent route
|
|
218
218
|
if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {
|
|
219
219
|
// only if this sub-parent route returns a valid parent route, we use it, if not leave it as it
|
|
220
220
|
const possibleParentRoute = hasParentRoute(
|
|
221
221
|
parentRoute.children,
|
|
222
|
+
node,
|
|
222
223
|
node.routePath,
|
|
223
224
|
)
|
|
224
225
|
if (possibleParentRoute) {
|
|
@@ -228,9 +229,7 @@ export async function generator(config: Config) {
|
|
|
228
229
|
|
|
229
230
|
if (parentRoute) node.parent = parentRoute
|
|
230
231
|
|
|
231
|
-
node.path = node
|
|
232
|
-
? node.routePath?.replace(node.parent.routePath!, '') || '/'
|
|
233
|
-
: node.routePath
|
|
232
|
+
node.path = determineNodePath(node)
|
|
234
233
|
|
|
235
234
|
const trimmedPath = trimPathLeft(node.path ?? '')
|
|
236
235
|
|
|
@@ -260,8 +259,8 @@ export async function generator(config: Config) {
|
|
|
260
259
|
replaced = [
|
|
261
260
|
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
262
261
|
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
263
|
+
})`,
|
|
265
264
|
].join('\n\n')
|
|
266
265
|
} else if (
|
|
267
266
|
node.isRoute ||
|
|
@@ -273,8 +272,8 @@ export async function generator(config: Config) {
|
|
|
273
272
|
replaced = [
|
|
274
273
|
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
275
274
|
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
276
|
+
})`,
|
|
278
277
|
].join('\n\n')
|
|
279
278
|
}
|
|
280
279
|
} else {
|
|
@@ -338,15 +337,15 @@ export async function generator(config: Config) {
|
|
|
338
337
|
return
|
|
339
338
|
}
|
|
340
339
|
|
|
341
|
-
node.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
node.isLayout
|
|
340
|
+
const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0
|
|
341
|
+
|
|
342
|
+
node.isVirtualParentRequired = node.isLayout
|
|
343
|
+
? !cleanedPathIsEmpty && !node.parent
|
|
344
|
+
: false
|
|
347
345
|
|
|
348
346
|
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
349
347
|
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'
|
|
348
|
+
const parentVariableName = routePathToVariable(parentRoutePath)
|
|
350
349
|
|
|
351
350
|
const anchorRoute = routeNodes.find(
|
|
352
351
|
(d) => d.routePath === parentRoutePath,
|
|
@@ -359,7 +358,7 @@ export async function generator(config: Config) {
|
|
|
359
358
|
filePath: removeLastSegmentFromPath(node.filePath) || '/',
|
|
360
359
|
fullPath: removeLastSegmentFromPath(node.fullPath) || '/',
|
|
361
360
|
routePath: parentRoutePath,
|
|
362
|
-
variableName:
|
|
361
|
+
variableName: parentVariableName,
|
|
363
362
|
isVirtual: true,
|
|
364
363
|
isLayout: false,
|
|
365
364
|
isVirtualParentRoute: true,
|
|
@@ -371,6 +370,11 @@ export async function generator(config: Config) {
|
|
|
371
370
|
|
|
372
371
|
node.parent = parentNode
|
|
373
372
|
|
|
373
|
+
if (node.isLayout) {
|
|
374
|
+
// since `node.path` is used as the `id` on the route definition, we need to update it
|
|
375
|
+
node.path = determineNodePath(node)
|
|
376
|
+
}
|
|
377
|
+
|
|
374
378
|
await handleNode(parentNode)
|
|
375
379
|
} else {
|
|
376
380
|
anchorRoute.children = anchorRoute.children ?? []
|
|
@@ -403,6 +407,10 @@ export async function generator(config: Config) {
|
|
|
403
407
|
return
|
|
404
408
|
}
|
|
405
409
|
|
|
410
|
+
if (node.isLayout && !node.children?.length) {
|
|
411
|
+
return
|
|
412
|
+
}
|
|
413
|
+
|
|
406
414
|
const route = `${node.variableName}Route`
|
|
407
415
|
|
|
408
416
|
if (node.children?.length) {
|
|
@@ -440,7 +448,20 @@ export async function generator(config: Config) {
|
|
|
440
448
|
.filter((d) => d[1])
|
|
441
449
|
.map((d) => d[0])
|
|
442
450
|
|
|
443
|
-
const virtualRouteNodes = sortedRouteNodes
|
|
451
|
+
const virtualRouteNodes = sortedRouteNodes
|
|
452
|
+
.filter((d) => d.isVirtual)
|
|
453
|
+
.reduce((acc, route) => {
|
|
454
|
+
// ensuring we don't have any duplicated virtual routes or clashes with pre-existing routes
|
|
455
|
+
const existingPreNode = preRouteNodes.filter(
|
|
456
|
+
(d) => d.routePath === route.routePath,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
if (existingPreNode.length === 0) {
|
|
460
|
+
acc.push(route)
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return acc
|
|
464
|
+
}, [] as RouteNode[])
|
|
444
465
|
|
|
445
466
|
const rootPathIdExtension =
|
|
446
467
|
config.addExtensions && rootRouteNode
|
|
@@ -495,6 +516,14 @@ export async function generator(config: Config) {
|
|
|
495
516
|
.join('\n'),
|
|
496
517
|
'// Create/Update Routes',
|
|
497
518
|
sortedRouteNodes
|
|
519
|
+
.reduce((acc, node) => {
|
|
520
|
+
// ensuring we update a unique route only once
|
|
521
|
+
if (acc.find((d) => d.routePath === node.routePath)) {
|
|
522
|
+
return acc
|
|
523
|
+
}
|
|
524
|
+
acc.push(node)
|
|
525
|
+
return acc
|
|
526
|
+
}, [] as RouteNode[])
|
|
498
527
|
.map((node) => {
|
|
499
528
|
const loaderNode = routePiecesByPath[node.routePath!]?.loader
|
|
500
529
|
const componentNode = routePiecesByPath[node.routePath!]?.component
|
|
@@ -709,6 +738,18 @@ function removeGroups(s: string) {
|
|
|
709
738
|
return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')
|
|
710
739
|
}
|
|
711
740
|
|
|
741
|
+
/**
|
|
742
|
+
* The `node.path` is used as the `id` in the route definition.
|
|
743
|
+
* This function checks if the given node has a parent and if so, it determines the correct path for the given node.
|
|
744
|
+
* @param node - The node to determine the path for.
|
|
745
|
+
* @returns The correct path for the given node.
|
|
746
|
+
*/
|
|
747
|
+
function determineNodePath(node: RouteNode) {
|
|
748
|
+
return (node.path = node.parent
|
|
749
|
+
? node.routePath?.replace(node.parent.routePath!, '') || '/'
|
|
750
|
+
: node.routePath)
|
|
751
|
+
}
|
|
752
|
+
|
|
712
753
|
/**
|
|
713
754
|
* Removes the last segment from a given path. Segments are considered to be separated by a '/'.
|
|
714
755
|
*
|
|
@@ -739,6 +780,7 @@ function removeLayoutSegments(path: string = '/'): string {
|
|
|
739
780
|
|
|
740
781
|
export function hasParentRoute(
|
|
741
782
|
routes: RouteNode[],
|
|
783
|
+
node: RouteNode,
|
|
742
784
|
routePathToCheck: string | undefined,
|
|
743
785
|
): RouteNode | null {
|
|
744
786
|
if (!routePathToCheck || routePathToCheck === '/') {
|
|
@@ -750,19 +792,32 @@ export function hasParentRoute(
|
|
|
750
792
|
(d) => d.variableName,
|
|
751
793
|
]).filter((d) => d.routePath !== `/${rootPathId}`)
|
|
752
794
|
|
|
753
|
-
|
|
754
|
-
|
|
795
|
+
if (node.isLayout) {
|
|
796
|
+
for (const route of sortedNodes) {
|
|
797
|
+
if (route.routePath === '/') continue
|
|
755
798
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
route.routePath
|
|
759
|
-
|
|
760
|
-
|
|
799
|
+
// a layout route's parent has to exactly match the layout route minus, the layout segment
|
|
800
|
+
const exactParentRoutePath = removeLastSegmentFromPath(node.routePath)
|
|
801
|
+
if (route.routePath === exactParentRoutePath) {
|
|
802
|
+
return route
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
for (const route of sortedNodes) {
|
|
807
|
+
if (route.routePath === '/') continue
|
|
808
|
+
|
|
809
|
+
if (
|
|
810
|
+
routePathToCheck.startsWith(`${route.routePath}/`) &&
|
|
811
|
+
route.routePath !== routePathToCheck
|
|
812
|
+
) {
|
|
813
|
+
return route
|
|
814
|
+
}
|
|
761
815
|
}
|
|
762
816
|
}
|
|
817
|
+
|
|
763
818
|
const segments = routePathToCheck.split('/')
|
|
764
819
|
segments.pop() // Remove the last segment
|
|
765
820
|
const parentRoutePath = segments.join('/')
|
|
766
821
|
|
|
767
|
-
return hasParentRoute(routes, parentRoutePath)
|
|
822
|
+
return hasParentRoute(routes, node, parentRoutePath)
|
|
768
823
|
}
|