@tanstack/router-generator 1.18.1 → 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/config.cjs +2 -1
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +3 -0
- package/dist/cjs/generator.cjs +112 -49
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +12 -0
- package/dist/cjs/utils.cjs +25 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +9 -0
- package/dist/esm/config.d.ts +3 -0
- package/dist/esm/config.js +2 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/generator.d.ts +12 -0
- package/dist/esm/generator.js +113 -50
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/utils.d.ts +9 -0
- package/dist/esm/utils.js +25 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -0
- package/src/generator.ts +162 -60
- package/src/utils.ts +20 -0
package/dist/esm/generator.js
CHANGED
|
@@ -2,12 +2,13 @@ import path from "path";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as fsp from "fs/promises";
|
|
4
4
|
import * as prettier from "prettier";
|
|
5
|
-
import { trimPathLeft, cleanPath } from "./utils.js";
|
|
5
|
+
import { logging, trimPathLeft, cleanPath } from "./utils.js";
|
|
6
6
|
let latestTask = 0;
|
|
7
7
|
const rootPathId = "__root";
|
|
8
8
|
const routeGroupPatternRegex = /\(.+\)/g;
|
|
9
9
|
async function getRouteNodes(config) {
|
|
10
10
|
const { routeFilePrefix, routeFileIgnorePrefix } = config;
|
|
11
|
+
const logger = logging({ disabled: config.disableLogging });
|
|
11
12
|
let routeNodes = [];
|
|
12
13
|
async function recurse(dir) {
|
|
13
14
|
const fullDir = path.resolve(config.routesDirectory, dir);
|
|
@@ -23,6 +24,7 @@ async function getRouteNodes(config) {
|
|
|
23
24
|
});
|
|
24
25
|
await Promise.all(
|
|
25
26
|
dirList.map(async (dirent) => {
|
|
27
|
+
var _a;
|
|
26
28
|
const fullPath = path.join(fullDir, dirent.name);
|
|
27
29
|
const relativePath = path.join(dir, dirent.name);
|
|
28
30
|
if (dirent.isDirectory()) {
|
|
@@ -44,6 +46,8 @@ async function getRouteNodes(config) {
|
|
|
44
46
|
let isErrorComponent = routePath == null ? void 0 : routePath.endsWith("/errorComponent");
|
|
45
47
|
let isPendingComponent = routePath == null ? void 0 : routePath.endsWith("/pendingComponent");
|
|
46
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;
|
|
47
51
|
[
|
|
48
52
|
[isComponent, "component"],
|
|
49
53
|
[isErrorComponent, "errorComponent"],
|
|
@@ -51,7 +55,7 @@ async function getRouteNodes(config) {
|
|
|
51
55
|
[isLoader, "loader"]
|
|
52
56
|
].forEach(([isType, type]) => {
|
|
53
57
|
if (isType) {
|
|
54
|
-
|
|
58
|
+
logger.warn(
|
|
55
59
|
`WARNING: The \`.${type}.tsx\` suffix used for the ${filePath} file is deprecated. Use the new \`.lazy.tsx\` suffix instead.`
|
|
56
60
|
);
|
|
57
61
|
}
|
|
@@ -74,7 +78,8 @@ async function getRouteNodes(config) {
|
|
|
74
78
|
isErrorComponent,
|
|
75
79
|
isPendingComponent,
|
|
76
80
|
isLoader,
|
|
77
|
-
isLazy
|
|
81
|
+
isLazy,
|
|
82
|
+
isLayout
|
|
78
83
|
});
|
|
79
84
|
}
|
|
80
85
|
})
|
|
@@ -87,14 +92,15 @@ async function getRouteNodes(config) {
|
|
|
87
92
|
let first = false;
|
|
88
93
|
let skipMessage = false;
|
|
89
94
|
async function generator(config) {
|
|
90
|
-
|
|
95
|
+
const logger = logging({ disabled: config.disableLogging });
|
|
96
|
+
logger.log("");
|
|
91
97
|
if (!first) {
|
|
92
|
-
|
|
98
|
+
logger.log("♻️ Generating routes...");
|
|
93
99
|
first = true;
|
|
94
100
|
} else if (skipMessage) {
|
|
95
101
|
skipMessage = false;
|
|
96
102
|
} else {
|
|
97
|
-
|
|
103
|
+
logger.log("♻️ Regenerating routes...");
|
|
98
104
|
}
|
|
99
105
|
const taskId = latestTask + 1;
|
|
100
106
|
latestTask = taskId;
|
|
@@ -141,53 +147,67 @@ async function generator(config) {
|
|
|
141
147
|
const routePiecesByPath = {};
|
|
142
148
|
let routeNodes = [];
|
|
143
149
|
const handleNode = async (node) => {
|
|
144
|
-
var _a, _b;
|
|
145
|
-
|
|
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
|
+
}
|
|
146
161
|
if (parentRoute)
|
|
147
162
|
node.parent = parentRoute;
|
|
148
|
-
node.path = node.parent ? ((
|
|
163
|
+
node.path = node.parent ? ((_b = node.routePath) == null ? void 0 : _b.replace(node.parent.routePath, "")) || "/" : node.routePath;
|
|
149
164
|
const trimmedPath = trimPathLeft(node.path ?? "");
|
|
150
165
|
const split = (trimmedPath == null ? void 0 : trimmedPath.split("/")) ?? [];
|
|
151
166
|
let first2 = split[0] ?? trimmedPath ?? "";
|
|
152
|
-
|
|
167
|
+
const lastRouteSegment = split[split.length - 1] ?? trimmedPath ?? "";
|
|
168
|
+
node.isNonPath = lastRouteSegment.startsWith("_");
|
|
153
169
|
node.isNonLayout = first2.endsWith("_");
|
|
154
|
-
node.cleanedPath = removeGroups(
|
|
155
|
-
|
|
156
|
-
const escapedRoutePath = removeTrailingUnderscores(
|
|
157
|
-
((_b = node.routePath) == null ? void 0 : _b.replaceAll("$", "$$")) ?? ""
|
|
170
|
+
node.cleanedPath = removeGroups(
|
|
171
|
+
removeUnderscores(removeLayoutSegments(node.path)) ?? ""
|
|
158
172
|
);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
`import { createLazyFileRoute } from '@tanstack/react-router'`,
|
|
164
|
-
`export const Route = createLazyFileRoute('${escapedRoutePath}')({
|
|
165
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
166
|
-
})`
|
|
167
|
-
].join("\n\n");
|
|
168
|
-
} else if (node.isRoute || !node.isComponent && !node.isErrorComponent && !node.isPendingComponent && !node.isLoader) {
|
|
169
|
-
replaced = [
|
|
170
|
-
`import { createFileRoute } from '@tanstack/react-router'`,
|
|
171
|
-
`export const Route = createFileRoute('${escapedRoutePath}')({
|
|
172
|
-
component: () => <div>Hello ${escapedRoutePath}!</div>
|
|
173
|
-
})`
|
|
174
|
-
].join("\n\n");
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
replaced = routeCode.replace(
|
|
178
|
-
/(FileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
179
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
180
|
-
).replace(
|
|
181
|
-
/(createFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
182
|
-
(match, p1, p2, p3) => `${p1}${escapedRoutePath}${p3}`
|
|
183
|
-
).replace(
|
|
184
|
-
/(createLazyFileRoute\(\s*['"])([^\s]*)(['"],?\s*\))/g,
|
|
185
|
-
(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("$", "$$")) ?? ""
|
|
186
177
|
);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
+
}
|
|
191
211
|
}
|
|
192
212
|
if (!node.isVirtual && (node.isLoader || node.isComponent || node.isErrorComponent || node.isPendingComponent || node.isLazy)) {
|
|
193
213
|
routePiecesByPath[node.routePath] = routePiecesByPath[node.routePath] || {};
|
|
@@ -206,9 +226,41 @@ async function generator(config) {
|
|
|
206
226
|
}
|
|
207
227
|
return;
|
|
208
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
|
+
}
|
|
209
259
|
if (node.parent) {
|
|
210
|
-
|
|
211
|
-
|
|
260
|
+
if (!node.isVirtualParentRequired) {
|
|
261
|
+
node.parent.children = node.parent.children ?? [];
|
|
262
|
+
node.parent.children.push(node);
|
|
263
|
+
}
|
|
212
264
|
} else {
|
|
213
265
|
routeTree.push(node);
|
|
214
266
|
}
|
|
@@ -360,10 +412,10 @@ async function generator(config) {
|
|
|
360
412
|
`declare module '@tanstack/react-router' {
|
|
361
413
|
interface FileRoutesByPath {
|
|
362
414
|
${routeNodes.map((routeNode) => {
|
|
363
|
-
var _a, _b;
|
|
415
|
+
var _a, _b, _c;
|
|
364
416
|
return `'${removeTrailingUnderscores(routeNode.routePath)}': {
|
|
365
417
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
366
|
-
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"}
|
|
367
419
|
}`;
|
|
368
420
|
}).join("\n")}
|
|
369
421
|
}
|
|
@@ -397,7 +449,7 @@ async function generator(config) {
|
|
|
397
449
|
routeConfigFileContent
|
|
398
450
|
);
|
|
399
451
|
}
|
|
400
|
-
|
|
452
|
+
logger.log(
|
|
401
453
|
`✅ Processed ${routeNodes.length === 1 ? "route" : "routes"} in ${Date.now() - start}ms`
|
|
402
454
|
);
|
|
403
455
|
}
|
|
@@ -447,6 +499,16 @@ function replaceBackslash(s) {
|
|
|
447
499
|
function removeGroups(s) {
|
|
448
500
|
return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
|
|
449
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
|
+
}
|
|
450
512
|
function hasParentRoute(routes, routePathToCheck) {
|
|
451
513
|
if (!routePathToCheck || routePathToCheck === "/") {
|
|
452
514
|
return null;
|
|
@@ -472,6 +534,7 @@ export {
|
|
|
472
534
|
hasParentRoute,
|
|
473
535
|
multiSortBy,
|
|
474
536
|
removeExt,
|
|
537
|
+
removeLastSegmentFromPath,
|
|
475
538
|
rootPathId
|
|
476
539
|
};
|
|
477
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, 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\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 console.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 console.log('')\n\n if (!first) {\n console.log('♻️ Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n console.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 console.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 console.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;AAEnD,MAAI,aAA0B,CAAA;AAE9B,iBAAe,QAAQ,KAAa;AAClC,UAAM,UAAU,KAAK,QAAQ,OAAO,iBAAiB,GAAG;AACpD,QAAA,UAAU,MAAM,IAAI,QAAQ,SAAS,EAAE,eAAe,MAAM;AAEtD,cAAA,QAAQ,OAAO,CAAC,MAAM;AAE5B,UAAA,EAAE,KAAK,WAAW,GAAG,KACpB,yBAAyB,EAAE,KAAK,WAAW,qBAAqB,GACjE;AACO,eAAA;AAAA,MACT;AAEA,UAAI,iBAAiB;AACZ,eAAA,EAAE,KAAK,WAAW,eAAe;AAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACR;AAED,UAAM,QAAQ;AAAA,MACZ,QAAQ,IAAI,OAAO,WAAW;AAC5B,cAAM,WAAW,KAAK,KAAK,SAAS,OAAO,IAAI;AAC/C,cAAM,eAAe,KAAK,KAAK,KAAK,OAAO,IAAI;AAE3C,YAAA,OAAO,eAAe;AACxB,gBAAM,QAAQ,YAAY;AAAA,QACjB,WAAA,SAAS,MAAM,oBAAoB,GAAG;AAC/C,gBAAM,WAAW,iBAAiB,KAAK,KAAK,KAAK,OAAO,IAAI,CAAC;AACvD,gBAAA,gBAAgB,UAAU,QAAQ;AACpC,cAA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AA0B,GAAY;AAC7C,SAAO,uBAAG,WAAW,UAAU,IAAI,WAAW,WAAW;AAC3D;AAEA,SAAS,iBAAiB,GAAW;AAC5B,SAAA,EAAE,WAAW,QAAQ,GAAG;AACjC;AAEA,SAAS,aAAa,GAAW;AAC/B,SAAO,EAAE,WAAW,wBAAwB,EAAE,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.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('/')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PathLeft(path: string): string;
|
|
3
|
+
export declare function logging(config: {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
}): {
|
|
6
|
+
log: (...args: any[]) => void;
|
|
7
|
+
debug: (...args: any[]) => void;
|
|
8
|
+
info: (...args: any[]) => void;
|
|
9
|
+
warn: (...args: any[]) => void;
|
|
10
|
+
error: (...args: any[]) => void;
|
|
11
|
+
};
|
package/dist/esm/utils.js
CHANGED
|
@@ -4,8 +4,33 @@ function cleanPath(path) {
|
|
|
4
4
|
function trimPathLeft(path) {
|
|
5
5
|
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
|
6
6
|
}
|
|
7
|
+
function logging(config) {
|
|
8
|
+
return {
|
|
9
|
+
log: (...args) => {
|
|
10
|
+
if (!config.disabled)
|
|
11
|
+
console.log(...args);
|
|
12
|
+
},
|
|
13
|
+
debug: (...args) => {
|
|
14
|
+
if (!config.disabled)
|
|
15
|
+
console.debug(...args);
|
|
16
|
+
},
|
|
17
|
+
info: (...args) => {
|
|
18
|
+
if (!config.disabled)
|
|
19
|
+
console.info(...args);
|
|
20
|
+
},
|
|
21
|
+
warn: (...args) => {
|
|
22
|
+
if (!config.disabled)
|
|
23
|
+
console.warn(...args);
|
|
24
|
+
},
|
|
25
|
+
error: (...args) => {
|
|
26
|
+
if (!config.disabled)
|
|
27
|
+
console.error(...args);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
7
31
|
export {
|
|
8
32
|
cleanPath,
|
|
33
|
+
logging,
|
|
9
34
|
trimPathLeft
|
|
10
35
|
};
|
|
11
36
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n"],"names":[],"mappings":"AAAO,SAAS,UAAU,MAAc;AAE/B,SAAA,KAAK,QAAQ,WAAW,GAAG;AACpC;AAEO,SAAS,aAAa,MAAc;AACzC,SAAO,SAAS,MAAM,OAAO,KAAK,QAAQ,WAAW,EAAE;AACzD;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n\nexport function logging(config: { disabled: boolean }) {\n return {\n log: (...args: any[]) => {\n if (!config.disabled) console.log(...args)\n },\n debug: (...args: any[]) => {\n if (!config.disabled) console.debug(...args)\n },\n info: (...args: any[]) => {\n if (!config.disabled) console.info(...args)\n },\n warn: (...args: any[]) => {\n if (!config.disabled) console.warn(...args)\n },\n error: (...args: any[]) => {\n if (!config.disabled) console.error(...args)\n },\n }\n}\n"],"names":[],"mappings":"AAAO,SAAS,UAAU,MAAc;AAE/B,SAAA,KAAK,QAAQ,WAAW,GAAG;AACpC;AAEO,SAAS,aAAa,MAAc;AACzC,SAAO,SAAS,MAAM,OAAO,KAAK,QAAQ,WAAW,EAAE;AACzD;AAEO,SAAS,QAAQ,QAA+B;AAC9C,SAAA;AAAA,IACL,KAAK,IAAI,SAAgB;AACvB,UAAI,CAAC,OAAO;AAAkB,gBAAA,IAAI,GAAG,IAAI;AAAA,IAC3C;AAAA,IACA,OAAO,IAAI,SAAgB;AACzB,UAAI,CAAC,OAAO;AAAkB,gBAAA,MAAM,GAAG,IAAI;AAAA,IAC7C;AAAA,IACA,MAAM,IAAI,SAAgB;AACxB,UAAI,CAAC,OAAO;AAAkB,gBAAA,KAAK,GAAG,IAAI;AAAA,IAC5C;AAAA,IACA,MAAM,IAAI,SAAgB;AACxB,UAAI,CAAC,OAAO;AAAkB,gBAAA,KAAK,GAAG,IAAI;AAAA,IAC5C;AAAA,IACA,OAAO,IAAI,SAAgB;AACzB,UAAI,CAAC,OAAO;AAAkB,gBAAA,MAAM,GAAG,IAAI;AAAA,IAC7C;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -10,6 +10,7 @@ export const configSchema = z.object({
|
|
|
10
10
|
quoteStyle: z.enum(['single', 'double']).optional().default('single'),
|
|
11
11
|
disableTypes: z.boolean().optional().default(false),
|
|
12
12
|
addExtensions: z.boolean().optional().default(false),
|
|
13
|
+
disableLogging: z.boolean().optional().default(false),
|
|
13
14
|
})
|
|
14
15
|
|
|
15
16
|
export type Config = z.infer<typeof configSchema>
|