@tanstack/router-generator 1.19.0 → 1.19.2
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 +105 -44
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +12 -0
- package/dist/esm/generator.d.ts +12 -0
- package/dist/esm/generator.js +105 -44
- package/dist/esm/generator.js.map +1 -1
- package/package.json +1 -1
- package/src/generator.ts +154 -54
package/dist/cjs/generator.cjs
CHANGED
|
@@ -45,6 +45,7 @@ async function getRouteNodes(config) {
|
|
|
45
45
|
});
|
|
46
46
|
await Promise.all(
|
|
47
47
|
dirList.map(async (dirent) => {
|
|
48
|
+
var _a;
|
|
48
49
|
const fullPath = path.join(fullDir, dirent.name);
|
|
49
50
|
const relativePath = path.join(dir, dirent.name);
|
|
50
51
|
if (dirent.isDirectory()) {
|
|
@@ -66,6 +67,8 @@ async function getRouteNodes(config) {
|
|
|
66
67
|
let isErrorComponent = routePath == null ? void 0 : routePath.endsWith("/errorComponent");
|
|
67
68
|
let isPendingComponent = routePath == null ? void 0 : routePath.endsWith("/pendingComponent");
|
|
68
69
|
let isLoader = routePath == null ? void 0 : routePath.endsWith("/loader");
|
|
70
|
+
const segments = (routePath ?? "").split("/");
|
|
71
|
+
let isLayout = ((_a = segments[segments.length - 1]) == null ? void 0 : _a.startsWith("_")) || false;
|
|
69
72
|
[
|
|
70
73
|
[isComponent, "component"],
|
|
71
74
|
[isErrorComponent, "errorComponent"],
|
|
@@ -96,7 +99,8 @@ async function getRouteNodes(config) {
|
|
|
96
99
|
isErrorComponent,
|
|
97
100
|
isPendingComponent,
|
|
98
101
|
isLoader,
|
|
99
|
-
isLazy
|
|
102
|
+
isLazy,
|
|
103
|
+
isLayout
|
|
100
104
|
});
|
|
101
105
|
}
|
|
102
106
|
})
|
|
@@ -164,53 +168,67 @@ async function generator(config) {
|
|
|
164
168
|
const routePiecesByPath = {};
|
|
165
169
|
let routeNodes = [];
|
|
166
170
|
const handleNode = async (node) => {
|
|
167
|
-
var _a, _b;
|
|
168
|
-
|
|
171
|
+
var _a, _b, _c;
|
|
172
|
+
let parentRoute = hasParentRoute(routeNodes, node.routePath);
|
|
173
|
+
if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
|
|
174
|
+
const possibleParentRoute = hasParentRoute(
|
|
175
|
+
parentRoute.children,
|
|
176
|
+
node.routePath
|
|
177
|
+
);
|
|
178
|
+
if (possibleParentRoute) {
|
|
179
|
+
parentRoute = possibleParentRoute;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
169
182
|
if (parentRoute)
|
|
170
183
|
node.parent = parentRoute;
|
|
171
|
-
node.path = node.parent ? ((
|
|
184
|
+
node.path = node.parent ? ((_b = node.routePath) == null ? void 0 : _b.replace(node.parent.routePath, "")) || "/" : node.routePath;
|
|
172
185
|
const trimmedPath = utils.trimPathLeft(node.path ?? "");
|
|
173
186
|
const split = (trimmedPath == null ? void 0 : trimmedPath.split("/")) ?? [];
|
|
174
187
|
let first2 = split[0] ?? trimmedPath ?? "";
|
|
175
|
-
|
|
188
|
+
const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? "";
|
|
189
|
+
node.isNonPath = lastRouteSegment.startsWith("_");
|
|
176
190
|
node.isNonLayout = first2.endsWith("_");
|
|
177
|
-
node.cleanedPath = removeGroups(
|
|
178
|
-
|
|
179
|
-
const escapedRoutePath = removeTrailingUnderscores(
|
|
180
|
-
((_b = node.routePath) == null ? void 0 : _b.replaceAll("$", "$$")) ?? ""
|
|
191
|
+
node.cleanedPath = removeGroups(
|
|
192
|
+
removeUnderscores(removeLayoutSegments(node.path)) ?? ""
|
|
181
193
|
);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
187
|
-
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
188
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
189
|
-
})`
|
|
190
|
-
].join("\n\n");
|
|
191
|
-
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
192
|
-
replaced = [
|
|
193
|
-
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
194
|
-
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
195
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
196
|
-
})`
|
|
197
|
-
].join("\n\n");
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
replaced = routeCode.replace(
|
|
201
|
-
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
202
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
203
|
-
).replace(
|
|
204
|
-
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
205
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
206
|
-
).replace(
|
|
207
|
-
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
208
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
194
|
+
if (!node.isVirtualParentRoute) {
|
|
195
|
+
const routeCode = fs__namespace.readFileSync(node.fullPath, "utf-8");
|
|
196
|
+
const escapedRoutePath = removeTrailingUnderscores(
|
|
197
|
+
((_c = node.routePath) == null ? void 0 : _c.replaceAll("$", "$$")) ?? ""
|
|
209
198
|
);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
199
|
+
let replaced = routeCode;
|
|
200
|
+
if (!routeCode) {
|
|
201
|
+
if (node.isLazy) {
|
|
202
|
+
replaced = [
|
|
203
|
+
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
204
|
+
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
205
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
206
|
+
})`
|
|
207
|
+
].join("\n\n");
|
|
208
|
+
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
209
|
+
replaced = [
|
|
210
|
+
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
211
|
+
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
212
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
213
|
+
})`
|
|
214
|
+
].join("\n\n");
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
replaced = routeCode.replace(
|
|
218
|
+
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
219
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
220
|
+
).replace(
|
|
221
|
+
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
222
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
223
|
+
).replace(
|
|
224
|
+
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
225
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (replaced !== routeCode) {
|
|
229
|
+
logger.log(`🟡 Updating ${node.fullPath}`);
|
|
230
|
+
await fsp__namespace.writeFile(node.fullPath, replaced);
|
|
231
|
+
}
|
|
214
232
|
}
|
|
215
233
|
if (!node.isVirtual && (node.isLoader || node.isComponent || node.isErrorComponent || node.isPendingComponent || node.isLazy)) {
|
|
216
234
|
routePiecesByPath[node.routePath] = routePiecesByPath[node.routePath] || {};
|
|
@@ -229,9 +247,41 @@ async function generator(config) {
|
|
|
229
247
|
}
|
|
230
248
|
return;
|
|
231
249
|
}
|
|
250
|
+
node.isVirtualParentRequired = removeGroups(node.path ?? "").split("").filter((char) => char === "/").length >= 2 && // check that the parent route wouldn't be the root route
|
|
251
|
+
!node.parent && node.isLayout;
|
|
252
|
+
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
253
|
+
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
254
|
+
const anchorRoute = routeNodes.find(
|
|
255
|
+
(d) => d.routePath === parentRoutePath
|
|
256
|
+
);
|
|
257
|
+
if (!anchorRoute) {
|
|
258
|
+
const parentNode = {
|
|
259
|
+
...node,
|
|
260
|
+
path: removeLastSegmentFromPath(node.path) || "/",
|
|
261
|
+
filePath: removeLastSegmentFromPath(node.filePath) || "/",
|
|
262
|
+
fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
|
|
263
|
+
routePath: parentRoutePath,
|
|
264
|
+
variableName: routePathToVariable(parentRoutePath),
|
|
265
|
+
isVirtual: true,
|
|
266
|
+
isLayout: false,
|
|
267
|
+
isVirtualParentRoute: true,
|
|
268
|
+
isVirtualParentRequired: false
|
|
269
|
+
};
|
|
270
|
+
parentNode.children = parentNode.children ?? [];
|
|
271
|
+
parentNode.children.push(node);
|
|
272
|
+
node.parent = parentNode;
|
|
273
|
+
await handleNode(parentNode);
|
|
274
|
+
} else {
|
|
275
|
+
anchorRoute.children = anchorRoute.children ?? [];
|
|
276
|
+
anchorRoute.children.push(node);
|
|
277
|
+
node.parent = anchorRoute;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
232
280
|
if (node.parent) {
|
|
233
|
-
|
|
234
|
-
|
|
281
|
+
if (!node.isVirtualParentRequired) {
|
|
282
|
+
node.parent.children = node.parent.children ?? [];
|
|
283
|
+
node.parent.children.push(node);
|
|
284
|
+
}
|
|
235
285
|
} else {
|
|
236
286
|
routeTree.push(node);
|
|
237
287
|
}
|
|
@@ -383,10 +433,10 @@ async function generator(config) {
|
|
|
383
433
|
`declare module '@tanstack/react-router' {
|
|
384
434
|
interface FileRoutesByPath {
|
|
385
435
|
${routeNodes.map((routeNode) => {
|
|
386
|
-
var _a, _b;
|
|
436
|
+
var _a, _b, _c;
|
|
387
437
|
return `'${removeTrailingUnderscores(routeNode.routePath)}': {
|
|
388
438
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
389
|
-
parentRoute: typeof ${(
|
|
439
|
+
parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${(_c = routeNode.parent) == null ? void 0 : _c.variableName}Import` : "rootRoute"}
|
|
390
440
|
}`;
|
|
391
441
|
}).join("\n")}
|
|
392
442
|
}
|
|
@@ -470,6 +520,16 @@ function replaceBackslash(s) {
|
|
|
470
520
|
function removeGroups(s) {
|
|
471
521
|
return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
|
|
472
522
|
}
|
|
523
|
+
function removeLastSegmentFromPath(path2 = "/") {
|
|
524
|
+
const segments = path2.split("/");
|
|
525
|
+
segments.pop();
|
|
526
|
+
return segments.join("/");
|
|
527
|
+
}
|
|
528
|
+
function removeLayoutSegments(path2 = "/") {
|
|
529
|
+
const segments = path2.split("/");
|
|
530
|
+
const newSegments = segments.filter((segment) => !segment.startsWith("_"));
|
|
531
|
+
return newSegments.join("/");
|
|
532
|
+
}
|
|
473
533
|
function hasParentRoute(routes, routePathToCheck) {
|
|
474
534
|
if (!routePathToCheck || routePathToCheck === "/") {
|
|
475
535
|
return null;
|
|
@@ -494,5 +554,6 @@ exports.generator = generator;
|
|
|
494
554
|
exports.hasParentRoute = hasParentRoute;
|
|
495
555
|
exports.multiSortBy = multiSortBy;
|
|
496
556
|
exports.removeExt = removeExt;
|
|
557
|
+
exports.removeLastSegmentFromPath = removeLastSegmentFromPath;
|
|
497
558
|
exports.rootPathId = rootPathId;
|
|
498
559
|
//# sourceMappingURL=generator.cjs.map
|
|
@@ -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 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 ;(\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 })\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 const parentRoute = hasParentRoute(routeNodes, node.routePath)\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\n node.isNonPath = first.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n node.cleanedPath = removeGroups(removeUnderscores(node.path) ?? '')\n\n // Ensure the boilerplate for the route exists\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 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 if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\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.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\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;A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,EAAE,WAAW,MAAM,GAAG;AACtE;AAEgB,SAAA,eACd,QACA,kBACkB;AACd,MAAA,CAAC,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.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,cA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iB,GAAW;AAC5B,SAAA,EAAE,WAAW,QAAQ,GAAG;AACjC;AAEA,SAAS,aAAa,GAAW;AAC/B,SAAO,EAAE,WAAW,wBAAwB,EAAE,EAAE,WAAW,MAAM,GAAG;AACtE;AAUgB,SAAA,0BAA0BC,QAAe,KAAa;AAC9D,QAAA,WAAWA,MAAK,MAAM,GAAG;AAC/B,WAAS,IAAI;AACN,SAAA,SAAS,KAAK,GAAG;AAC1B;AAUA,SAAS,qBAAqBA,QAAe,KAAa;AAClD,QAAA,WAAWA,MAAK,MAAM,GAAG;AACzB,QAAA,cAAc,SAAS,OAAO,CAAC,YAAY,CAAC,QAAQ,WAAW,GAAG,CAAC;AAClE,SAAA,YAAY,KAAK,GAAG;AAC7B;AAEgB,SAAA,eACd,QACA,kBACkB;AACd,MAAA,CAAC,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;;;;;;;"}
|
package/dist/cjs/generator.d.cts
CHANGED
|
@@ -9,6 +9,9 @@ export type RouteNode = {
|
|
|
9
9
|
path?: string;
|
|
10
10
|
isNonPath?: boolean;
|
|
11
11
|
isNonLayout?: boolean;
|
|
12
|
+
isLayout?: boolean;
|
|
13
|
+
isVirtualParentRequired?: boolean;
|
|
14
|
+
isVirtualParentRoute?: boolean;
|
|
12
15
|
isRoute?: boolean;
|
|
13
16
|
isLoader?: boolean;
|
|
14
17
|
isComponent?: boolean;
|
|
@@ -23,4 +26,13 @@ export type RouteNode = {
|
|
|
23
26
|
export declare function generator(config: Config): Promise<void>;
|
|
24
27
|
export declare function removeExt(d: string, keepExtension?: boolean): string;
|
|
25
28
|
export declare function multiSortBy<T>(arr: T[], accessors?: ((item: T) => any)[]): T[];
|
|
29
|
+
/**
|
|
30
|
+
* Removes the last segment from a given path. Segments are considered to be separated by a '/'.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} path - The path from which to remove the last segment. Defaults to '/'.
|
|
33
|
+
* @returns {string} The path with the last segment removed.
|
|
34
|
+
* @example
|
|
35
|
+
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
36
|
+
*/
|
|
37
|
+
export declare function removeLastSegmentFromPath(path?: string): string;
|
|
26
38
|
export declare function hasParentRoute(routes: RouteNode[], routePathToCheck: string | undefined): RouteNode | null;
|
package/dist/esm/generator.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export type RouteNode = {
|
|
|
9
9
|
path?: string;
|
|
10
10
|
isNonPath?: boolean;
|
|
11
11
|
isNonLayout?: boolean;
|
|
12
|
+
isLayout?: boolean;
|
|
13
|
+
isVirtualParentRequired?: boolean;
|
|
14
|
+
isVirtualParentRoute?: boolean;
|
|
12
15
|
isRoute?: boolean;
|
|
13
16
|
isLoader?: boolean;
|
|
14
17
|
isComponent?: boolean;
|
|
@@ -23,4 +26,13 @@ export type RouteNode = {
|
|
|
23
26
|
export declare function generator(config: Config): Promise<void>;
|
|
24
27
|
export declare function removeExt(d: string, keepExtension?: boolean): string;
|
|
25
28
|
export declare function multiSortBy<T>(arr: T[], accessors?: ((item: T) => any)[]): T[];
|
|
29
|
+
/**
|
|
30
|
+
* Removes the last segment from a given path. Segments are considered to be separated by a '/'.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} path - The path from which to remove the last segment. Defaults to '/'.
|
|
33
|
+
* @returns {string} The path with the last segment removed.
|
|
34
|
+
* @example
|
|
35
|
+
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
36
|
+
*/
|
|
37
|
+
export declare function removeLastSegmentFromPath(path?: string): string;
|
|
26
38
|
export declare function hasParentRoute(routes: RouteNode[], routePathToCheck: string | undefined): RouteNode | null;
|
package/dist/esm/generator.js
CHANGED
|
@@ -24,6 +24,7 @@ async function getRouteNodes(config) {
|
|
|
24
24
|
});
|
|
25
25
|
await Promise.all(
|
|
26
26
|
dirList.map(async (dirent) => {
|
|
27
|
+
var _a;
|
|
27
28
|
const fullPath = path.join(fullDir, dirent.name);
|
|
28
29
|
const relativePath = path.join(dir, dirent.name);
|
|
29
30
|
if (dirent.isDirectory()) {
|
|
@@ -45,6 +46,8 @@ async function getRouteNodes(config) {
|
|
|
45
46
|
let isErrorComponent = routePath == null ? void 0 : routePath.endsWith("/errorComponent");
|
|
46
47
|
let isPendingComponent = routePath == null ? void 0 : routePath.endsWith("/pendingComponent");
|
|
47
48
|
let isLoader = routePath == null ? void 0 : routePath.endsWith("/loader");
|
|
49
|
+
const segments = (routePath ?? "").split("/");
|
|
50
|
+
let isLayout = ((_a = segments[segments.length - 1]) == null ? void 0 : _a.startsWith("_")) || false;
|
|
48
51
|
[
|
|
49
52
|
[isComponent, "component"],
|
|
50
53
|
[isErrorComponent, "errorComponent"],
|
|
@@ -75,7 +78,8 @@ async function getRouteNodes(config) {
|
|
|
75
78
|
isErrorComponent,
|
|
76
79
|
isPendingComponent,
|
|
77
80
|
isLoader,
|
|
78
|
-
isLazy
|
|
81
|
+
isLazy,
|
|
82
|
+
isLayout
|
|
79
83
|
});
|
|
80
84
|
}
|
|
81
85
|
})
|
|
@@ -143,53 +147,67 @@ async function generator(config) {
|
|
|
143
147
|
const routePiecesByPath = {};
|
|
144
148
|
let routeNodes = [];
|
|
145
149
|
const handleNode = async (node) => {
|
|
146
|
-
var _a, _b;
|
|
147
|
-
|
|
150
|
+
var _a, _b, _c;
|
|
151
|
+
let parentRoute = hasParentRoute(routeNodes, node.routePath);
|
|
152
|
+
if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
|
|
153
|
+
const possibleParentRoute = hasParentRoute(
|
|
154
|
+
parentRoute.children,
|
|
155
|
+
node.routePath
|
|
156
|
+
);
|
|
157
|
+
if (possibleParentRoute) {
|
|
158
|
+
parentRoute = possibleParentRoute;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
148
161
|
if (parentRoute)
|
|
149
162
|
node.parent = parentRoute;
|
|
150
|
-
node.path = node.parent ? ((
|
|
163
|
+
node.path = node.parent ? ((_b = node.routePath) == null ? void 0 : _b.replace(node.parent.routePath, "")) || "/" : node.routePath;
|
|
151
164
|
const trimmedPath = trimPathLeft(node.path ?? "");
|
|
152
165
|
const split = (trimmedPath == null ? void 0 : trimmedPath.split("/")) ?? [];
|
|
153
166
|
let first2 = split[0] ?? trimmedPath ?? "";
|
|
154
|
-
|
|
167
|
+
const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? "";
|
|
168
|
+
node.isNonPath = lastRouteSegment.startsWith("_");
|
|
155
169
|
node.isNonLayout = first2.endsWith("_");
|
|
156
|
-
node.cleanedPath = removeGroups(
|
|
157
|
-
|
|
158
|
-
const escapedRoutePath = removeTrailingUnderscores(
|
|
159
|
-
((_b = node.routePath) == null ? void 0 : _b.replaceAll("$", "$$")) ?? ""
|
|
170
|
+
node.cleanedPath = removeGroups(
|
|
171
|
+
removeUnderscores(removeLayoutSegments(node.path)) ?? ""
|
|
160
172
|
);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
166
|
-
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
167
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
168
|
-
})`
|
|
169
|
-
].join("\n\n");
|
|
170
|
-
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
171
|
-
replaced = [
|
|
172
|
-
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
173
|
-
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
174
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
175
|
-
})`
|
|
176
|
-
].join("\n\n");
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
replaced = routeCode.replace(
|
|
180
|
-
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
181
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
182
|
-
).replace(
|
|
183
|
-
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
184
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
185
|
-
).replace(
|
|
186
|
-
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
187
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
173
|
+
if (!node.isVirtualParentRoute) {
|
|
174
|
+
const routeCode = fs.readFileSync(node.fullPath, "utf-8");
|
|
175
|
+
const escapedRoutePath = removeTrailingUnderscores(
|
|
176
|
+
((_c = node.routePath) == null ? void 0 : _c.replaceAll("$", "$$")) ?? ""
|
|
188
177
|
);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
178
|
+
let replaced = routeCode;
|
|
179
|
+
if (!routeCode) {
|
|
180
|
+
if (node.isLazy) {
|
|
181
|
+
replaced = [
|
|
182
|
+
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
183
|
+
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
184
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
185
|
+
})`
|
|
186
|
+
].join("\n\n");
|
|
187
|
+
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
188
|
+
replaced = [
|
|
189
|
+
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
190
|
+
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
191
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
192
|
+
})`
|
|
193
|
+
].join("\n\n");
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
replaced = routeCode.replace(
|
|
197
|
+
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
198
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
199
|
+
).replace(
|
|
200
|
+
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
201
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
202
|
+
).replace(
|
|
203
|
+
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
204
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (replaced !== routeCode) {
|
|
208
|
+
logger.log(`🟡 Updating ${node.fullPath}`);
|
|
209
|
+
await fsp.writeFile(node.fullPath, replaced);
|
|
210
|
+
}
|
|
193
211
|
}
|
|
194
212
|
if (!node.isVirtual && (node.isLoader || node.isComponent || node.isErrorComponent || node.isPendingComponent || node.isLazy)) {
|
|
195
213
|
routePiecesByPath[node.routePath] = routePiecesByPath[node.routePath] || {};
|
|
@@ -208,9 +226,41 @@ async function generator(config) {
|
|
|
208
226
|
}
|
|
209
227
|
return;
|
|
210
228
|
}
|
|
229
|
+
node.isVirtualParentRequired = removeGroups(node.path ?? "").split("").filter((char) => char === "/").length >= 2 && // check that the parent route wouldn't be the root route
|
|
230
|
+
!node.parent && node.isLayout;
|
|
231
|
+
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
232
|
+
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
233
|
+
const anchorRoute = routeNodes.find(
|
|
234
|
+
(d) => d.routePath === parentRoutePath
|
|
235
|
+
);
|
|
236
|
+
if (!anchorRoute) {
|
|
237
|
+
const parentNode = {
|
|
238
|
+
...node,
|
|
239
|
+
path: removeLastSegmentFromPath(node.path) || "/",
|
|
240
|
+
filePath: removeLastSegmentFromPath(node.filePath) || "/",
|
|
241
|
+
fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
|
|
242
|
+
routePath: parentRoutePath,
|
|
243
|
+
variableName: routePathToVariable(parentRoutePath),
|
|
244
|
+
isVirtual: true,
|
|
245
|
+
isLayout: false,
|
|
246
|
+
isVirtualParentRoute: true,
|
|
247
|
+
isVirtualParentRequired: false
|
|
248
|
+
};
|
|
249
|
+
parentNode.children = parentNode.children ?? [];
|
|
250
|
+
parentNode.children.push(node);
|
|
251
|
+
node.parent = parentNode;
|
|
252
|
+
await handleNode(parentNode);
|
|
253
|
+
} else {
|
|
254
|
+
anchorRoute.children = anchorRoute.children ?? [];
|
|
255
|
+
anchorRoute.children.push(node);
|
|
256
|
+
node.parent = anchorRoute;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
211
259
|
if (node.parent) {
|
|
212
|
-
|
|
213
|
-
|
|
260
|
+
if (!node.isVirtualParentRequired) {
|
|
261
|
+
node.parent.children = node.parent.children ?? [];
|
|
262
|
+
node.parent.children.push(node);
|
|
263
|
+
}
|
|
214
264
|
} else {
|
|
215
265
|
routeTree.push(node);
|
|
216
266
|
}
|
|
@@ -362,10 +412,10 @@ async function generator(config) {
|
|
|
362
412
|
`declare module '@tanstack/react-router' {
|
|
363
413
|
interface FileRoutesByPath {
|
|
364
414
|
${routeNodes.map((routeNode) => {
|
|
365
|
-
var _a, _b;
|
|
415
|
+
var _a, _b, _c;
|
|
366
416
|
return `'${removeTrailingUnderscores(routeNode.routePath)}': {
|
|
367
417
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
368
|
-
parentRoute: typeof ${(
|
|
418
|
+
parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${(_c = routeNode.parent) == null ? void 0 : _c.variableName}Import` : "rootRoute"}
|
|
369
419
|
}`;
|
|
370
420
|
}).join("\n")}
|
|
371
421
|
}
|
|
@@ -449,6 +499,16 @@ function replaceBackslash(s) {
|
|
|
449
499
|
function removeGroups(s) {
|
|
450
500
|
return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
|
|
451
501
|
}
|
|
502
|
+
function removeLastSegmentFromPath(path2 = "/") {
|
|
503
|
+
const segments = path2.split("/");
|
|
504
|
+
segments.pop();
|
|
505
|
+
return segments.join("/");
|
|
506
|
+
}
|
|
507
|
+
function removeLayoutSegments(path2 = "/") {
|
|
508
|
+
const segments = path2.split("/");
|
|
509
|
+
const newSegments = segments.filter((segment) => !segment.startsWith("_"));
|
|
510
|
+
return newSegments.join("/");
|
|
511
|
+
}
|
|
452
512
|
function hasParentRoute(routes, routePathToCheck) {
|
|
453
513
|
if (!routePathToCheck || routePathToCheck === "/") {
|
|
454
514
|
return null;
|
|
@@ -474,6 +534,7 @@ export {
|
|
|
474
534
|
hasParentRoute,
|
|
475
535
|
multiSortBy,
|
|
476
536
|
removeExt,
|
|
537
|
+
removeLastSegmentFromPath,
|
|
477
538
|
rootPathId
|
|
478
539
|
};
|
|
479
540
|
//# sourceMappingURL=generator.js.map
|
|
@@ -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 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 ;(\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 })\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 const parentRoute = hasParentRoute(routeNodes, node.routePath)\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\n node.isNonPath = first.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n node.cleanedPath = removeGroups(removeUnderscores(node.path) ?? '')\n\n // Ensure the boilerplate for the route exists\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 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 if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\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.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\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"],"mappings":";;;;;AAOA,IAAI,aAAa;AACV,MAAM,aAAa;AAC1B,MAAM,yBAAyB;AAuB/B,eAAe,cAAc,QAAgB;AACrC,QAAA,EAAE,iBAAiB,sBAA0B,IAAA;AACnD,QAAM,SAAS,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAE1D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AM,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.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,QAA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WA,MAAK,MAAM,GAAG;AACzB,QAAA,cAAc,SAAS,OAAO,CAAC,YAAY,CAAC,QAAQ,WAAW,GAAG,CAAC;AAClE,SAAA,YAAY,KAAK,GAAG;AAC7B;AAEgB,SAAA,eACd,QACA,kBACkB;AACd,MAAA,CAAC,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;"}
|
package/package.json
CHANGED
package/src/generator.ts
CHANGED
|
@@ -18,6 +18,9 @@ export type RouteNode = {
|
|
|
18
18
|
path?: string
|
|
19
19
|
isNonPath?: boolean
|
|
20
20
|
isNonLayout?: boolean
|
|
21
|
+
isLayout?: boolean
|
|
22
|
+
isVirtualParentRequired?: boolean
|
|
23
|
+
isVirtualParentRoute?: boolean
|
|
21
24
|
isRoute?: boolean
|
|
22
25
|
isLoader?: boolean
|
|
23
26
|
isComponent?: boolean
|
|
@@ -89,6 +92,9 @@ async function getRouteNodes(config: Config) {
|
|
|
89
92
|
let isPendingComponent = routePath?.endsWith('/pendingComponent')
|
|
90
93
|
let isLoader = routePath?.endsWith('/loader')
|
|
91
94
|
|
|
95
|
+
const segments = (routePath ?? '').split('/')
|
|
96
|
+
let isLayout = segments[segments.length - 1]?.startsWith('_') || false
|
|
97
|
+
|
|
92
98
|
;(
|
|
93
99
|
[
|
|
94
100
|
[isComponent, 'component'],
|
|
@@ -126,6 +132,7 @@ async function getRouteNodes(config: Config) {
|
|
|
126
132
|
isPendingComponent,
|
|
127
133
|
isLoader,
|
|
128
134
|
isLazy,
|
|
135
|
+
isLayout,
|
|
129
136
|
})
|
|
130
137
|
}
|
|
131
138
|
}),
|
|
@@ -205,7 +212,20 @@ export async function generator(config: Config) {
|
|
|
205
212
|
let routeNodes: RouteNode[] = []
|
|
206
213
|
|
|
207
214
|
const handleNode = async (node: RouteNode) => {
|
|
208
|
-
|
|
215
|
+
let parentRoute = hasParentRoute(routeNodes, node.routePath)
|
|
216
|
+
|
|
217
|
+
// if the parent route is a virtual parent route, we need to find the real parent route
|
|
218
|
+
if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {
|
|
219
|
+
// only if this sub-parent route returns a valid parent route, we use it, if not leave it as it
|
|
220
|
+
const possibleParentRoute = hasParentRoute(
|
|
221
|
+
parentRoute.children,
|
|
222
|
+
node.routePath,
|
|
223
|
+
)
|
|
224
|
+
if (possibleParentRoute) {
|
|
225
|
+
parentRoute = possibleParentRoute
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
209
229
|
if (parentRoute) node.parent = parentRoute
|
|
210
230
|
|
|
211
231
|
node.path = node.parent
|
|
@@ -216,61 +236,67 @@ export async function generator(config: Config) {
|
|
|
216
236
|
|
|
217
237
|
const split = trimmedPath?.split('/') ?? []
|
|
218
238
|
let first = split[0] ?? trimmedPath ?? ''
|
|
239
|
+
const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? ''
|
|
219
240
|
|
|
220
|
-
node.isNonPath =
|
|
241
|
+
node.isNonPath = lastRouteSegment.startsWith('_')
|
|
221
242
|
node.isNonLayout = first.endsWith('_')
|
|
222
|
-
node.cleanedPath = removeGroups(removeUnderscores(node.path) ?? '')
|
|
223
243
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const escapedRoutePath = removeTrailingUnderscores(
|
|
228
|
-
node.routePath?.replaceAll('$', '$$') ?? '',
|
|
244
|
+
node.cleanedPath = removeGroups(
|
|
245
|
+
removeUnderscores(removeLayoutSegments(node.path)) ?? '',
|
|
229
246
|
)
|
|
230
247
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
node.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
// Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes
|
|
249
|
+
if (!node.isVirtualParentRoute) {
|
|
250
|
+
const routeCode = fs.readFileSync(node.fullPath, 'utf-8')
|
|
251
|
+
|
|
252
|
+
const escapedRoutePath = removeTrailingUnderscores(
|
|
253
|
+
node.routePath?.replaceAll('$', '$$') ?? '',
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
let replaced = routeCode
|
|
257
|
+
|
|
258
|
+
if (!routeCode) {
|
|
259
|
+
if (node.isLazy) {
|
|
260
|
+
replaced = [
|
|
261
|
+
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
262
|
+
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
263
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
264
|
+
})`,
|
|
265
|
+
].join('\n\n')
|
|
266
|
+
} else if (
|
|
267
|
+
node.isRoute ||
|
|
268
|
+
(!node.isComponent &&
|
|
269
|
+
!node.isErrorComponent &&
|
|
270
|
+
!node.isPendingComponent &&
|
|
271
|
+
!node.isLoader)
|
|
272
|
+
) {
|
|
273
|
+
replaced = [
|
|
274
|
+
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
275
|
+
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
276
|
+
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
277
|
+
})`,
|
|
278
|
+
].join('\n\n')
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
replaced = routeCode
|
|
282
|
+
.replace(
|
|
283
|
+
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
284
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
285
|
+
)
|
|
286
|
+
.replace(
|
|
287
|
+
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
288
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
289
|
+
)
|
|
290
|
+
.replace(
|
|
291
|
+
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
292
|
+
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
293
|
+
)
|
|
254
294
|
}
|
|
255
|
-
} else {
|
|
256
|
-
replaced = routeCode
|
|
257
|
-
.replace(
|
|
258
|
-
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
259
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
260
|
-
)
|
|
261
|
-
.replace(
|
|
262
|
-
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
263
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
264
|
-
)
|
|
265
|
-
.replace(
|
|
266
|
-
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
267
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`,
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
295
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
296
|
+
if (replaced !== routeCode) {
|
|
297
|
+
logger.log(`🟡 Updating ${node.fullPath}`)
|
|
298
|
+
await fsp.writeFile(node.fullPath, replaced)
|
|
299
|
+
}
|
|
274
300
|
}
|
|
275
301
|
|
|
276
302
|
if (
|
|
@@ -312,9 +338,53 @@ export async function generator(config: Config) {
|
|
|
312
338
|
return
|
|
313
339
|
}
|
|
314
340
|
|
|
341
|
+
node.isVirtualParentRequired =
|
|
342
|
+
removeGroups(node.path ?? '')
|
|
343
|
+
.split('')
|
|
344
|
+
.filter((char) => char === '/').length >= 2 && // check that the parent route wouldn't be the root route
|
|
345
|
+
!node.parent &&
|
|
346
|
+
node.isLayout
|
|
347
|
+
|
|
348
|
+
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
349
|
+
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'
|
|
350
|
+
|
|
351
|
+
const anchorRoute = routeNodes.find(
|
|
352
|
+
(d) => d.routePath === parentRoutePath,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
if (!anchorRoute) {
|
|
356
|
+
const parentNode = {
|
|
357
|
+
...node,
|
|
358
|
+
path: removeLastSegmentFromPath(node.path) || '/',
|
|
359
|
+
filePath: removeLastSegmentFromPath(node.filePath) || '/',
|
|
360
|
+
fullPath: removeLastSegmentFromPath(node.fullPath) || '/',
|
|
361
|
+
routePath: parentRoutePath,
|
|
362
|
+
variableName: routePathToVariable(parentRoutePath),
|
|
363
|
+
isVirtual: true,
|
|
364
|
+
isLayout: false,
|
|
365
|
+
isVirtualParentRoute: true,
|
|
366
|
+
isVirtualParentRequired: false,
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
parentNode.children = parentNode.children ?? []
|
|
370
|
+
parentNode.children.push(node)
|
|
371
|
+
|
|
372
|
+
node.parent = parentNode
|
|
373
|
+
|
|
374
|
+
await handleNode(parentNode)
|
|
375
|
+
} else {
|
|
376
|
+
anchorRoute.children = anchorRoute.children ?? []
|
|
377
|
+
anchorRoute.children.push(node)
|
|
378
|
+
|
|
379
|
+
node.parent = anchorRoute
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
315
383
|
if (node.parent) {
|
|
316
|
-
|
|
317
|
-
|
|
384
|
+
if (!node.isVirtualParentRequired) {
|
|
385
|
+
node.parent.children = node.parent.children ?? []
|
|
386
|
+
node.parent.children.push(node)
|
|
387
|
+
}
|
|
318
388
|
} else {
|
|
319
389
|
routeTree.push(node)
|
|
320
390
|
}
|
|
@@ -510,9 +580,11 @@ export async function generator(config: Config) {
|
|
|
510
580
|
return `'${removeTrailingUnderscores(routeNode.routePath)}': {
|
|
511
581
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
512
582
|
parentRoute: typeof ${
|
|
513
|
-
routeNode.
|
|
514
|
-
? `${routeNode.parent?.variableName}
|
|
515
|
-
:
|
|
583
|
+
routeNode.isVirtualParentRequired
|
|
584
|
+
? `${routeNode.parent?.variableName}Route`
|
|
585
|
+
: routeNode.parent?.variableName
|
|
586
|
+
? `${routeNode.parent?.variableName}Import`
|
|
587
|
+
: 'rootRoute'
|
|
516
588
|
}
|
|
517
589
|
}`
|
|
518
590
|
})
|
|
@@ -637,6 +709,34 @@ function removeGroups(s: string) {
|
|
|
637
709
|
return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')
|
|
638
710
|
}
|
|
639
711
|
|
|
712
|
+
/**
|
|
713
|
+
* Removes the last segment from a given path. Segments are considered to be separated by a '/'.
|
|
714
|
+
*
|
|
715
|
+
* @param {string} path - The path from which to remove the last segment. Defaults to '/'.
|
|
716
|
+
* @returns {string} The path with the last segment removed.
|
|
717
|
+
* @example
|
|
718
|
+
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
719
|
+
*/
|
|
720
|
+
export function removeLastSegmentFromPath(path: string = '/'): string {
|
|
721
|
+
const segments = path.split('/')
|
|
722
|
+
segments.pop() // Remove the last segment
|
|
723
|
+
return segments.join('/')
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Removes all segments from a given path that start with an underscore ('_').
|
|
728
|
+
*
|
|
729
|
+
* @param {string} path - The path from which to remove segments. Defaults to '/'.
|
|
730
|
+
* @returns {string} The path with all underscore-prefixed segments removed.
|
|
731
|
+
* @example
|
|
732
|
+
* removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'
|
|
733
|
+
*/
|
|
734
|
+
function removeLayoutSegments(path: string = '/'): string {
|
|
735
|
+
const segments = path.split('/')
|
|
736
|
+
const newSegments = segments.filter((segment) => !segment.startsWith('_'))
|
|
737
|
+
return newSegments.join('/')
|
|
738
|
+
}
|
|
739
|
+
|
|
640
740
|
export function hasParentRoute(
|
|
641
741
|
routes: RouteNode[],
|
|
642
742
|
routePathToCheck: string | undefined,
|