@tanstack/router-generator 1.166.9 → 1.166.11
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +111 -147
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +224 -303
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -4
- package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/config.cjs +32 -30
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +164 -209
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +9 -8
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
- package/dist/cjs/generator.cjs +766 -1106
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/index.cjs +32 -34
- package/dist/cjs/logger.cjs +28 -34
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/template.cjs +144 -151
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/transform/transform.cjs +287 -426
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/utils.cjs +31 -33
- package/dist/cjs/transform/utils.cjs.map +1 -1
- package/dist/cjs/utils.cjs +534 -544
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/validate-route-params.cjs +66 -51
- package/dist/cjs/validate-route-params.cjs.map +1 -1
- package/dist/esm/config.js +106 -147
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.js +220 -286
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/physical/rootPathId.js +6 -5
- package/dist/esm/filesystem/physical/rootPathId.js.map +1 -1
- package/dist/esm/filesystem/virtual/config.js +31 -30
- package/dist/esm/filesystem/virtual/config.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.js +161 -208
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/loadConfigFile.js +7 -7
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
- package/dist/esm/generator.js +756 -1083
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.js +4 -31
- package/dist/esm/logger.js +29 -35
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/template.js +144 -152
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/transform/transform.js +285 -425
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/utils.js +31 -33
- package/dist/esm/transform/utils.js.map +1 -1
- package/dist/esm/utils.js +529 -564
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/validate-route-params.js +67 -52
- package/dist/esm/validate-route-params.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
package/dist/esm/generator.js
CHANGED
|
@@ -1,589 +1,418 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
-
import crypto from "node:crypto";
|
|
5
|
-
import { rootRouteId } from "@tanstack/router-core";
|
|
6
1
|
import { logging } from "./logger.js";
|
|
7
|
-
import { getRouteNodes as getRouteNodes$1, isVirtualConfigFile } from "./filesystem/physical/getRouteNodes.js";
|
|
8
|
-
import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
|
|
9
2
|
import { rootPathId } from "./filesystem/physical/rootPathId.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
3
|
+
import { RoutePrefixMap, buildFileRoutesByPathInterface, buildImportString, buildRouteTreeConfig, checkFileExists, checkRouteFullPathUniqueness, createRouteNodesByFullPath, createRouteNodesById, createRouteNodesByTo, createTokenRegex, determineNodePath, findParent, format, getImportForRouteNode, getImportPath, getResolvedRouteNodeVariableName, hasParentRoute, isRouteNodeValidForAugmentation, isSegmentPathless, mergeImportDeclarations, multiSortBy, removeExt, removeGroups, removeLastSegmentFromPath, removeLayoutSegmentsWithEscape, removeTrailingSlash, removeUnderscoresWithEscape, replaceBackslash, trimPathLeft } from "./utils.js";
|
|
4
|
+
import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
|
|
5
|
+
import { getRouteNodes as getRouteNodes$1, isVirtualConfigFile } from "./filesystem/physical/getRouteNodes.js";
|
|
6
|
+
import { fillTemplate, getTargetTemplate } from "./template.js";
|
|
12
7
|
import { transform } from "./transform/transform.js";
|
|
13
8
|
import { validateRouteParams } from "./validate-route-params.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
11
|
+
import * as fsp from "node:fs/promises";
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
import { rootRouteId } from "@tanstack/router-core";
|
|
14
|
+
//#region src/generator.ts
|
|
15
|
+
var DefaultFileSystem = {
|
|
16
|
+
stat: async (filePath) => {
|
|
17
|
+
const res = await fsp.stat(filePath, { bigint: true });
|
|
18
|
+
return {
|
|
19
|
+
mtimeMs: res.mtimeMs,
|
|
20
|
+
mode: Number(res.mode),
|
|
21
|
+
uid: Number(res.uid),
|
|
22
|
+
gid: Number(res.gid)
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),
|
|
26
|
+
writeFile: (filePath, content) => fsp.writeFile(filePath, content),
|
|
27
|
+
readFile: async (filePath) => {
|
|
28
|
+
try {
|
|
29
|
+
const fileHandle = await fsp.open(filePath, "r");
|
|
30
|
+
const stat = await fileHandle.stat({ bigint: true });
|
|
31
|
+
const fileContent = (await fileHandle.readFile()).toString();
|
|
32
|
+
await fileHandle.close();
|
|
33
|
+
return {
|
|
34
|
+
stat,
|
|
35
|
+
fileContent
|
|
36
|
+
};
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if ("code" in e) {
|
|
39
|
+
if (e.code === "ENOENT") return "file-not-existing";
|
|
40
|
+
}
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
chmod: (filePath, mode) => fsp.chmod(filePath, mode),
|
|
45
|
+
chown: (filePath, uid, gid) => fsp.chown(filePath, uid, gid)
|
|
44
46
|
};
|
|
45
47
|
function rerun(opts) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const { event, ...rest } = opts;
|
|
49
|
+
return {
|
|
50
|
+
rerun: true,
|
|
51
|
+
event: event ?? { type: "rerun" },
|
|
52
|
+
...rest
|
|
53
|
+
};
|
|
48
54
|
}
|
|
49
55
|
function isRerun(result) {
|
|
50
|
-
|
|
56
|
+
return typeof result === "object" && result !== null && "rerun" in result && result.rerun === true;
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.swapCaches();
|
|
340
|
-
}
|
|
341
|
-
swapCaches() {
|
|
342
|
-
this.routeNodeCache = this.routeNodeShadowCache;
|
|
343
|
-
this.routeNodeShadowCache = /* @__PURE__ */ new Map();
|
|
344
|
-
}
|
|
345
|
-
buildRouteTree(opts) {
|
|
346
|
-
const config = { ...this.config, ...opts.config || {} };
|
|
347
|
-
const { rootRouteNode, acc } = opts;
|
|
348
|
-
const indexTokenSegmentRegex = config.indexToken === this.config.indexToken ? this.indexTokenSegmentRegex : createTokenRegex(config.indexToken, { type: "segment" });
|
|
349
|
-
const sortedRouteNodes = multiSortBy(acc.routeNodes, [
|
|
350
|
-
(d) => d.routePath?.includes(`/${rootPathId}`) ? -1 : 1,
|
|
351
|
-
(d) => d.routePath?.split("/").length,
|
|
352
|
-
(d) => {
|
|
353
|
-
const segments = d.routePath?.split("/").filter(Boolean) ?? [];
|
|
354
|
-
const last = segments[segments.length - 1] ?? "";
|
|
355
|
-
return indexTokenSegmentRegex.test(last) ? -1 : 1;
|
|
356
|
-
},
|
|
357
|
-
(d) => d
|
|
358
|
-
]);
|
|
359
|
-
const routeImports = [];
|
|
360
|
-
const virtualRouteNodes = [];
|
|
361
|
-
for (const node of sortedRouteNodes) {
|
|
362
|
-
if (node.isVirtual) {
|
|
363
|
-
virtualRouteNodes.push(
|
|
364
|
-
`const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`
|
|
365
|
-
);
|
|
366
|
-
} else {
|
|
367
|
-
routeImports.push(
|
|
368
|
-
getImportForRouteNode(
|
|
369
|
-
node,
|
|
370
|
-
config,
|
|
371
|
-
this.generatedRouteTreePath,
|
|
372
|
-
this.root
|
|
373
|
-
)
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
const imports = [];
|
|
378
|
-
if (virtualRouteNodes.length > 0) {
|
|
379
|
-
imports.push({
|
|
380
|
-
specifiers: [{ imported: "createFileRoute" }],
|
|
381
|
-
source: this.targetTemplate.fullPkg
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
let hasComponentPieces = false;
|
|
385
|
-
let hasLoaderPieces = false;
|
|
386
|
-
for (const node of sortedRouteNodes) {
|
|
387
|
-
const pieces = acc.routePiecesByPath[node.routePath];
|
|
388
|
-
if (pieces) {
|
|
389
|
-
if (pieces.component || pieces.errorComponent || pieces.notFoundComponent || pieces.pendingComponent) {
|
|
390
|
-
hasComponentPieces = true;
|
|
391
|
-
}
|
|
392
|
-
if (pieces.loader) {
|
|
393
|
-
hasLoaderPieces = true;
|
|
394
|
-
}
|
|
395
|
-
if (hasComponentPieces && hasLoaderPieces) break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (hasComponentPieces || hasLoaderPieces) {
|
|
399
|
-
const runtimeImport = {
|
|
400
|
-
specifiers: [],
|
|
401
|
-
source: this.targetTemplate.fullPkg
|
|
402
|
-
};
|
|
403
|
-
if (hasComponentPieces) {
|
|
404
|
-
runtimeImport.specifiers.push({ imported: "lazyRouteComponent" });
|
|
405
|
-
}
|
|
406
|
-
if (hasLoaderPieces) {
|
|
407
|
-
runtimeImport.specifiers.push({ imported: "lazyFn" });
|
|
408
|
-
}
|
|
409
|
-
imports.push(runtimeImport);
|
|
410
|
-
}
|
|
411
|
-
if (config.verboseFileRoutes === false) {
|
|
412
|
-
const typeImport = {
|
|
413
|
-
specifiers: [],
|
|
414
|
-
source: this.targetTemplate.fullPkg,
|
|
415
|
-
importKind: "type"
|
|
416
|
-
};
|
|
417
|
-
let needsCreateFileRoute = false;
|
|
418
|
-
let needsCreateLazyFileRoute = false;
|
|
419
|
-
for (const node of sortedRouteNodes) {
|
|
420
|
-
if (isRouteNodeValidForAugmentation(node)) {
|
|
421
|
-
if (node._fsRouteType !== "lazy") {
|
|
422
|
-
needsCreateFileRoute = true;
|
|
423
|
-
}
|
|
424
|
-
if (acc.routePiecesByPath[node.routePath]?.lazy) {
|
|
425
|
-
needsCreateLazyFileRoute = true;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (needsCreateFileRoute && needsCreateLazyFileRoute) break;
|
|
429
|
-
}
|
|
430
|
-
if (needsCreateFileRoute) {
|
|
431
|
-
typeImport.specifiers.push({ imported: "CreateFileRoute" });
|
|
432
|
-
}
|
|
433
|
-
if (needsCreateLazyFileRoute) {
|
|
434
|
-
typeImport.specifiers.push({ imported: "CreateLazyFileRoute" });
|
|
435
|
-
}
|
|
436
|
-
if (typeImport.specifiers.length > 0) {
|
|
437
|
-
typeImport.specifiers.push({ imported: "FileRoutesByPath" });
|
|
438
|
-
imports.push(typeImport);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
const routeTreeConfig = buildRouteTreeConfig(
|
|
442
|
-
acc.routeTree,
|
|
443
|
-
config.disableTypes
|
|
444
|
-
);
|
|
445
|
-
const createUpdateRoutes = sortedRouteNodes.map((node) => {
|
|
446
|
-
const pieces = acc.routePiecesByPath[node.routePath];
|
|
447
|
-
const loaderNode = pieces?.loader;
|
|
448
|
-
const componentNode = pieces?.component;
|
|
449
|
-
const errorComponentNode = pieces?.errorComponent;
|
|
450
|
-
const notFoundComponentNode = pieces?.notFoundComponent;
|
|
451
|
-
const pendingComponentNode = pieces?.pendingComponent;
|
|
452
|
-
const lazyComponentNode = pieces?.lazy;
|
|
453
|
-
return [
|
|
454
|
-
[
|
|
455
|
-
`const ${node.variableName}Route = ${node.variableName}RouteImport.update({
|
|
58
|
+
var Generator = class Generator {
|
|
59
|
+
static {
|
|
60
|
+
this.routeGroupPatternRegex = /\(.+\)/;
|
|
61
|
+
}
|
|
62
|
+
static {
|
|
63
|
+
this.componentPieceRegex = /[./](component|errorComponent|notFoundComponent|pendingComponent|loader|lazy)[.]/;
|
|
64
|
+
}
|
|
65
|
+
constructor(opts) {
|
|
66
|
+
this.routeNodeCache = /* @__PURE__ */ new Map();
|
|
67
|
+
this.routeNodeShadowCache = /* @__PURE__ */ new Map();
|
|
68
|
+
this.fileEventQueue = [];
|
|
69
|
+
this.plugins = [];
|
|
70
|
+
this.physicalDirectories = [];
|
|
71
|
+
this.config = opts.config;
|
|
72
|
+
this.logger = logging({ disabled: this.config.disableLogging });
|
|
73
|
+
this.root = opts.root;
|
|
74
|
+
this.fs = opts.fs || DefaultFileSystem;
|
|
75
|
+
this.generatedRouteTreePath = this.getGeneratedRouteTreePath();
|
|
76
|
+
this.targetTemplate = getTargetTemplate(this.config);
|
|
77
|
+
this.routesDirectoryPath = this.getRoutesDirectoryPath();
|
|
78
|
+
this.plugins.push(...opts.config.plugins || []);
|
|
79
|
+
this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, { type: "filename" });
|
|
80
|
+
this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, { type: "filename" });
|
|
81
|
+
this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, { type: "segment" });
|
|
82
|
+
this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, { type: "segment" });
|
|
83
|
+
for (const plugin of this.plugins) plugin.init?.({ generator: this });
|
|
84
|
+
}
|
|
85
|
+
getGeneratedRouteTreePath() {
|
|
86
|
+
const generatedRouteTreePath = path.isAbsolute(this.config.generatedRouteTree) ? this.config.generatedRouteTree : path.resolve(this.root, this.config.generatedRouteTree);
|
|
87
|
+
const generatedRouteTreeDir = path.dirname(generatedRouteTreePath);
|
|
88
|
+
if (!existsSync(generatedRouteTreeDir)) mkdirSync(generatedRouteTreeDir, { recursive: true });
|
|
89
|
+
return generatedRouteTreePath;
|
|
90
|
+
}
|
|
91
|
+
getRoutesDirectoryPath() {
|
|
92
|
+
return path.isAbsolute(this.config.routesDirectory) ? this.config.routesDirectory : path.resolve(this.root, this.config.routesDirectory);
|
|
93
|
+
}
|
|
94
|
+
getRoutesByFileMap() {
|
|
95
|
+
return new Map([...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [filePath, { routePath: cacheEntry.routeId }]));
|
|
96
|
+
}
|
|
97
|
+
async run(event) {
|
|
98
|
+
if (event && event.type !== "rerun" && !this.isFileRelevantForRouteTreeGeneration(event.path)) return;
|
|
99
|
+
this.fileEventQueue.push(event ?? { type: "rerun" });
|
|
100
|
+
if (this.runPromise) return this.runPromise;
|
|
101
|
+
this.runPromise = (async () => {
|
|
102
|
+
do {
|
|
103
|
+
const tempQueue = this.fileEventQueue;
|
|
104
|
+
this.fileEventQueue = [];
|
|
105
|
+
if ((await Promise.all(tempQueue.map(async (e) => {
|
|
106
|
+
if (e.type === "update") {
|
|
107
|
+
let cacheEntry;
|
|
108
|
+
if (e.path === this.generatedRouteTreePath) cacheEntry = this.routeTreeFileCache;
|
|
109
|
+
else cacheEntry = this.routeNodeCache.get(e.path);
|
|
110
|
+
if ((await this.didFileChangeComparedToCache({ path: e.path }, cacheEntry)).result === false) return null;
|
|
111
|
+
}
|
|
112
|
+
return e;
|
|
113
|
+
}))).filter((e) => e !== null).length === 0) break;
|
|
114
|
+
try {
|
|
115
|
+
await this.generatorInternal();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
const errArray = !Array.isArray(err) ? [err] : err;
|
|
118
|
+
const recoverableErrors = errArray.filter((e) => isRerun(e));
|
|
119
|
+
if (recoverableErrors.length === errArray.length) {
|
|
120
|
+
this.fileEventQueue.push(...recoverableErrors.map((e) => e.event));
|
|
121
|
+
recoverableErrors.forEach((e) => {
|
|
122
|
+
if (e.msg) this.logger.info(e.msg);
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
const unrecoverableErrors = errArray.filter((e) => !isRerun(e));
|
|
126
|
+
this.runPromise = void 0;
|
|
127
|
+
throw new Error(unrecoverableErrors.map((e) => e.message).join());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} while (this.fileEventQueue.length);
|
|
131
|
+
this.runPromise = void 0;
|
|
132
|
+
})();
|
|
133
|
+
return this.runPromise;
|
|
134
|
+
}
|
|
135
|
+
async generatorInternal() {
|
|
136
|
+
let writeRouteTreeFile = false;
|
|
137
|
+
let getRouteNodesResult;
|
|
138
|
+
if (this.config.virtualRouteConfig) getRouteNodesResult = await getRouteNodes(this.config, this.root, {
|
|
139
|
+
indexTokenSegmentRegex: this.indexTokenSegmentRegex,
|
|
140
|
+
routeTokenSegmentRegex: this.routeTokenSegmentRegex
|
|
141
|
+
});
|
|
142
|
+
else getRouteNodesResult = await getRouteNodes$1(this.config, this.root, {
|
|
143
|
+
indexTokenSegmentRegex: this.indexTokenSegmentRegex,
|
|
144
|
+
routeTokenSegmentRegex: this.routeTokenSegmentRegex
|
|
145
|
+
});
|
|
146
|
+
const { rootRouteNode, routeNodes: beforeRouteNodes, physicalDirectories } = getRouteNodesResult;
|
|
147
|
+
if (rootRouteNode === void 0) {
|
|
148
|
+
let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`;
|
|
149
|
+
if (!this.config.virtualRouteConfig) errorMessage += `\nMake sure that you add a "${rootPathId}.${this.config.disableTypes ? "js" : "tsx"}" file to your routes directory.\nAdd the file in: "${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? "js" : "tsx"}"`;
|
|
150
|
+
throw new Error(errorMessage);
|
|
151
|
+
}
|
|
152
|
+
this.physicalDirectories = physicalDirectories;
|
|
153
|
+
await this.handleRootNode(rootRouteNode);
|
|
154
|
+
const preRouteNodes = multiSortBy(beforeRouteNodes, [
|
|
155
|
+
(d) => d.routePath === "/" ? -1 : 1,
|
|
156
|
+
(d) => d.routePath?.split("/").length,
|
|
157
|
+
(d) => d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1,
|
|
158
|
+
(d) => d.filePath.match(Generator.componentPieceRegex) ? 1 : -1,
|
|
159
|
+
(d) => d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1,
|
|
160
|
+
(d) => d.routePath?.endsWith("/") ? -1 : 1,
|
|
161
|
+
(d) => d.routePath
|
|
162
|
+
]).filter((d) => {
|
|
163
|
+
if (d.routePath === `/__root`) return [
|
|
164
|
+
"component",
|
|
165
|
+
"errorComponent",
|
|
166
|
+
"notFoundComponent",
|
|
167
|
+
"pendingComponent",
|
|
168
|
+
"loader",
|
|
169
|
+
"lazy"
|
|
170
|
+
].includes(d._fsRouteType);
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
const routeFileAllResult = await Promise.allSettled(preRouteNodes.filter((n) => !n.isVirtualParentRoute && !n.isVirtual).map((n) => this.processRouteNodeFile(n)));
|
|
174
|
+
const rejections = routeFileAllResult.filter((result) => result.status === "rejected");
|
|
175
|
+
if (rejections.length > 0) throw rejections.map((e) => e.reason);
|
|
176
|
+
const routeFileResult = routeFileAllResult.flatMap((result) => {
|
|
177
|
+
if (result.status === "fulfilled" && result.value !== null) {
|
|
178
|
+
if (result.value.shouldWriteTree) writeRouteTreeFile = true;
|
|
179
|
+
return result.value.node;
|
|
180
|
+
}
|
|
181
|
+
return [];
|
|
182
|
+
});
|
|
183
|
+
routeFileResult.forEach((r) => r.children = void 0);
|
|
184
|
+
const acc = {
|
|
185
|
+
routeTree: [],
|
|
186
|
+
routeNodes: [],
|
|
187
|
+
routePiecesByPath: {},
|
|
188
|
+
routeNodesByPath: /* @__PURE__ */ new Map()
|
|
189
|
+
};
|
|
190
|
+
const prefixMap = new RoutePrefixMap(routeFileResult);
|
|
191
|
+
for (const node of routeFileResult) Generator.handleNode(node, acc, prefixMap, this.config);
|
|
192
|
+
this.crawlingResult = {
|
|
193
|
+
rootRouteNode,
|
|
194
|
+
routeFileResult,
|
|
195
|
+
acc
|
|
196
|
+
};
|
|
197
|
+
if (!this.routeTreeFileCache) {
|
|
198
|
+
const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath);
|
|
199
|
+
if (routeTreeFile !== "file-not-existing") this.routeTreeFileCache = {
|
|
200
|
+
fileContent: routeTreeFile.fileContent,
|
|
201
|
+
mtimeMs: routeTreeFile.stat.mtimeMs
|
|
202
|
+
};
|
|
203
|
+
writeRouteTreeFile = true;
|
|
204
|
+
} else {
|
|
205
|
+
const routeTreeFileChange = await this.didFileChangeComparedToCache({ path: this.generatedRouteTreePath }, this.routeTreeFileCache);
|
|
206
|
+
if (routeTreeFileChange.result !== false) {
|
|
207
|
+
writeRouteTreeFile = "force";
|
|
208
|
+
if (routeTreeFileChange.result === true) {
|
|
209
|
+
const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath);
|
|
210
|
+
if (routeTreeFile !== "file-not-existing") this.routeTreeFileCache = {
|
|
211
|
+
fileContent: routeTreeFile.fileContent,
|
|
212
|
+
mtimeMs: routeTreeFile.stat.mtimeMs
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!writeRouteTreeFile) {
|
|
218
|
+
if (this.routeNodeCache.size !== this.routeNodeShadowCache.size) writeRouteTreeFile = true;
|
|
219
|
+
else for (const fullPath of this.routeNodeCache.keys()) if (!this.routeNodeShadowCache.has(fullPath)) {
|
|
220
|
+
writeRouteTreeFile = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!writeRouteTreeFile) {
|
|
225
|
+
this.swapCaches();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const buildResult = this.buildRouteTree({
|
|
229
|
+
rootRouteNode,
|
|
230
|
+
acc,
|
|
231
|
+
routeFileResult
|
|
232
|
+
});
|
|
233
|
+
let routeTreeContent = buildResult.routeTreeContent;
|
|
234
|
+
routeTreeContent = this.config.enableRouteTreeFormatting ? await format(routeTreeContent, this.config) : routeTreeContent;
|
|
235
|
+
let newMtimeMs;
|
|
236
|
+
if (this.routeTreeFileCache) if (writeRouteTreeFile !== "force" && this.routeTreeFileCache.fileContent === routeTreeContent) {} else newMtimeMs = (await this.safeFileWrite({
|
|
237
|
+
filePath: this.generatedRouteTreePath,
|
|
238
|
+
newContent: routeTreeContent,
|
|
239
|
+
strategy: {
|
|
240
|
+
type: "mtime",
|
|
241
|
+
expectedMtimeMs: this.routeTreeFileCache.mtimeMs
|
|
242
|
+
}
|
|
243
|
+
})).mtimeMs;
|
|
244
|
+
else newMtimeMs = (await this.safeFileWrite({
|
|
245
|
+
filePath: this.generatedRouteTreePath,
|
|
246
|
+
newContent: routeTreeContent,
|
|
247
|
+
strategy: { type: "new-file" }
|
|
248
|
+
})).mtimeMs;
|
|
249
|
+
if (newMtimeMs !== void 0) this.routeTreeFileCache = {
|
|
250
|
+
fileContent: routeTreeContent,
|
|
251
|
+
mtimeMs: newMtimeMs
|
|
252
|
+
};
|
|
253
|
+
this.plugins.map((plugin) => {
|
|
254
|
+
return plugin.onRouteTreeChanged?.({
|
|
255
|
+
routeTree: buildResult.routeTree,
|
|
256
|
+
routeNodes: buildResult.routeNodes,
|
|
257
|
+
acc,
|
|
258
|
+
rootRouteNode
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
this.swapCaches();
|
|
262
|
+
}
|
|
263
|
+
swapCaches() {
|
|
264
|
+
this.routeNodeCache = this.routeNodeShadowCache;
|
|
265
|
+
this.routeNodeShadowCache = /* @__PURE__ */ new Map();
|
|
266
|
+
}
|
|
267
|
+
buildRouteTree(opts) {
|
|
268
|
+
const config = {
|
|
269
|
+
...this.config,
|
|
270
|
+
...opts.config || {}
|
|
271
|
+
};
|
|
272
|
+
const { rootRouteNode, acc } = opts;
|
|
273
|
+
const indexTokenSegmentRegex = config.indexToken === this.config.indexToken ? this.indexTokenSegmentRegex : createTokenRegex(config.indexToken, { type: "segment" });
|
|
274
|
+
const sortedRouteNodes = multiSortBy(acc.routeNodes, [
|
|
275
|
+
(d) => d.routePath?.includes(`/__root`) ? -1 : 1,
|
|
276
|
+
(d) => d.routePath?.split("/").length,
|
|
277
|
+
(d) => {
|
|
278
|
+
const segments = d.routePath?.split("/").filter(Boolean) ?? [];
|
|
279
|
+
const last = segments[segments.length - 1] ?? "";
|
|
280
|
+
return indexTokenSegmentRegex.test(last) ? -1 : 1;
|
|
281
|
+
},
|
|
282
|
+
(d) => d
|
|
283
|
+
]);
|
|
284
|
+
const routeImports = [];
|
|
285
|
+
const virtualRouteNodes = [];
|
|
286
|
+
for (const node of sortedRouteNodes) if (node.isVirtual) virtualRouteNodes.push(`const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`);
|
|
287
|
+
else routeImports.push(getImportForRouteNode(node, config, this.generatedRouteTreePath, this.root));
|
|
288
|
+
const imports = [];
|
|
289
|
+
if (virtualRouteNodes.length > 0) imports.push({
|
|
290
|
+
specifiers: [{ imported: "createFileRoute" }],
|
|
291
|
+
source: this.targetTemplate.fullPkg
|
|
292
|
+
});
|
|
293
|
+
let hasComponentPieces = false;
|
|
294
|
+
let hasLoaderPieces = false;
|
|
295
|
+
for (const node of sortedRouteNodes) {
|
|
296
|
+
const pieces = acc.routePiecesByPath[node.routePath];
|
|
297
|
+
if (pieces) {
|
|
298
|
+
if (pieces.component || pieces.errorComponent || pieces.notFoundComponent || pieces.pendingComponent) hasComponentPieces = true;
|
|
299
|
+
if (pieces.loader) hasLoaderPieces = true;
|
|
300
|
+
if (hasComponentPieces && hasLoaderPieces) break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (hasComponentPieces || hasLoaderPieces) {
|
|
304
|
+
const runtimeImport = {
|
|
305
|
+
specifiers: [],
|
|
306
|
+
source: this.targetTemplate.fullPkg
|
|
307
|
+
};
|
|
308
|
+
if (hasComponentPieces) runtimeImport.specifiers.push({ imported: "lazyRouteComponent" });
|
|
309
|
+
if (hasLoaderPieces) runtimeImport.specifiers.push({ imported: "lazyFn" });
|
|
310
|
+
imports.push(runtimeImport);
|
|
311
|
+
}
|
|
312
|
+
if (config.verboseFileRoutes === false) {
|
|
313
|
+
const typeImport = {
|
|
314
|
+
specifiers: [],
|
|
315
|
+
source: this.targetTemplate.fullPkg,
|
|
316
|
+
importKind: "type"
|
|
317
|
+
};
|
|
318
|
+
let needsCreateFileRoute = false;
|
|
319
|
+
let needsCreateLazyFileRoute = false;
|
|
320
|
+
for (const node of sortedRouteNodes) {
|
|
321
|
+
if (isRouteNodeValidForAugmentation(node)) {
|
|
322
|
+
if (node._fsRouteType !== "lazy") needsCreateFileRoute = true;
|
|
323
|
+
if (acc.routePiecesByPath[node.routePath]?.lazy) needsCreateLazyFileRoute = true;
|
|
324
|
+
}
|
|
325
|
+
if (needsCreateFileRoute && needsCreateLazyFileRoute) break;
|
|
326
|
+
}
|
|
327
|
+
if (needsCreateFileRoute) typeImport.specifiers.push({ imported: "CreateFileRoute" });
|
|
328
|
+
if (needsCreateLazyFileRoute) typeImport.specifiers.push({ imported: "CreateLazyFileRoute" });
|
|
329
|
+
if (typeImport.specifiers.length > 0) {
|
|
330
|
+
typeImport.specifiers.push({ imported: "FileRoutesByPath" });
|
|
331
|
+
imports.push(typeImport);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const routeTreeConfig = buildRouteTreeConfig(acc.routeTree, config.disableTypes);
|
|
335
|
+
const createUpdateRoutes = sortedRouteNodes.map((node) => {
|
|
336
|
+
const pieces = acc.routePiecesByPath[node.routePath];
|
|
337
|
+
const loaderNode = pieces?.loader;
|
|
338
|
+
const componentNode = pieces?.component;
|
|
339
|
+
const errorComponentNode = pieces?.errorComponent;
|
|
340
|
+
const notFoundComponentNode = pieces?.notFoundComponent;
|
|
341
|
+
const pendingComponentNode = pieces?.pendingComponent;
|
|
342
|
+
const lazyComponentNode = pieces?.lazy;
|
|
343
|
+
return [[
|
|
344
|
+
`const ${node.variableName}Route = ${node.variableName}RouteImport.update({
|
|
456
345
|
${[
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
346
|
+
`id: '${node.path}'`,
|
|
347
|
+
!node.isNonPath || node._fsRouteType === "pathless_layout" && node.cleanedPath ? `path: '${node.cleanedPath}'` : void 0,
|
|
348
|
+
`getParentRoute: () => ${findParent(node)}`
|
|
349
|
+
].filter(Boolean).join(",")}
|
|
461
350
|
}${config.disableTypes ? "" : "as any"})`,
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
path.relative(
|
|
465
|
-
path.dirname(config.generatedRouteTree),
|
|
466
|
-
path.resolve(config.routesDirectory, loaderNode.filePath)
|
|
467
|
-
),
|
|
468
|
-
config.addExtensions
|
|
469
|
-
)
|
|
470
|
-
)}'), 'loader') })` : "",
|
|
471
|
-
componentNode || errorComponentNode || notFoundComponentNode || pendingComponentNode ? `.update({
|
|
351
|
+
loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, loaderNode.filePath)), config.addExtensions))}'), 'loader') })` : "",
|
|
352
|
+
componentNode || errorComponentNode || notFoundComponentNode || pendingComponentNode ? `.update({
|
|
472
353
|
${[
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
path.resolve(
|
|
484
|
-
config.routesDirectory,
|
|
485
|
-
d[1].filePath
|
|
486
|
-
)
|
|
487
|
-
) : removeExt(
|
|
488
|
-
path.relative(
|
|
489
|
-
path.dirname(config.generatedRouteTree),
|
|
490
|
-
path.resolve(
|
|
491
|
-
config.routesDirectory,
|
|
492
|
-
d[1].filePath
|
|
493
|
-
)
|
|
494
|
-
),
|
|
495
|
-
config.addExtensions
|
|
496
|
-
)
|
|
497
|
-
);
|
|
498
|
-
return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`;
|
|
499
|
-
}).join("\n,")}
|
|
354
|
+
["component", componentNode],
|
|
355
|
+
["errorComponent", errorComponentNode],
|
|
356
|
+
["notFoundComponent", notFoundComponentNode],
|
|
357
|
+
["pendingComponent", pendingComponentNode]
|
|
358
|
+
].filter((d) => d[1]).map((d) => {
|
|
359
|
+
const isVueFile = d[1].filePath.endsWith(".vue");
|
|
360
|
+
const exportName = isVueFile ? "default" : d[0];
|
|
361
|
+
const importPath = replaceBackslash(isVueFile ? path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, d[1].filePath)) : removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, d[1].filePath)), config.addExtensions));
|
|
362
|
+
return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`;
|
|
363
|
+
}).join("\n,")}
|
|
500
364
|
})` : "",
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
lazyComponentNode.filePath
|
|
517
|
-
)
|
|
518
|
-
),
|
|
519
|
-
config.addExtensions
|
|
520
|
-
)
|
|
521
|
-
);
|
|
522
|
-
return `.lazy(() => import('./${importPath}').then((d) => ${exportAccessor}))`;
|
|
523
|
-
})() : ""
|
|
524
|
-
].join("")
|
|
525
|
-
].join("\n\n");
|
|
526
|
-
});
|
|
527
|
-
const rootRoutePath = `/${rootPathId}`;
|
|
528
|
-
const rootPieces = acc.routePiecesByPath[rootRoutePath];
|
|
529
|
-
const rootComponentNode = rootPieces?.component;
|
|
530
|
-
const rootErrorComponentNode = rootPieces?.errorComponent;
|
|
531
|
-
const rootNotFoundComponentNode = rootPieces?.notFoundComponent;
|
|
532
|
-
const rootPendingComponentNode = rootPieces?.pendingComponent;
|
|
533
|
-
let rootRouteUpdate = "";
|
|
534
|
-
if (rootComponentNode || rootErrorComponentNode || rootNotFoundComponentNode || rootPendingComponentNode) {
|
|
535
|
-
rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${rootComponentNode || rootErrorComponentNode || rootNotFoundComponentNode || rootPendingComponentNode ? `.update({
|
|
365
|
+
lazyComponentNode ? (() => {
|
|
366
|
+
const isVueFile = lazyComponentNode.filePath.endsWith(".vue");
|
|
367
|
+
const exportAccessor = isVueFile ? "d.default" : "d.Route";
|
|
368
|
+
return `.lazy(() => import('./${replaceBackslash(isVueFile ? path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, lazyComponentNode.filePath)) : removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, lazyComponentNode.filePath)), config.addExtensions))}').then((d) => ${exportAccessor}))`;
|
|
369
|
+
})() : ""
|
|
370
|
+
].join("")].join("\n\n");
|
|
371
|
+
});
|
|
372
|
+
const rootRoutePath = `/${rootPathId}`;
|
|
373
|
+
const rootPieces = acc.routePiecesByPath[rootRoutePath];
|
|
374
|
+
const rootComponentNode = rootPieces?.component;
|
|
375
|
+
const rootErrorComponentNode = rootPieces?.errorComponent;
|
|
376
|
+
const rootNotFoundComponentNode = rootPieces?.notFoundComponent;
|
|
377
|
+
const rootPendingComponentNode = rootPieces?.pendingComponent;
|
|
378
|
+
let rootRouteUpdate = "";
|
|
379
|
+
if (rootComponentNode || rootErrorComponentNode || rootNotFoundComponentNode || rootPendingComponentNode) rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${rootComponentNode || rootErrorComponentNode || rootNotFoundComponentNode || rootPendingComponentNode ? `.update({
|
|
536
380
|
${[
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
path.resolve(config.routesDirectory, d[1].filePath)
|
|
548
|
-
) : removeExt(
|
|
549
|
-
path.relative(
|
|
550
|
-
path.dirname(config.generatedRouteTree),
|
|
551
|
-
path.resolve(
|
|
552
|
-
config.routesDirectory,
|
|
553
|
-
d[1].filePath
|
|
554
|
-
)
|
|
555
|
-
),
|
|
556
|
-
config.addExtensions
|
|
557
|
-
)
|
|
558
|
-
);
|
|
559
|
-
return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`;
|
|
560
|
-
}).join("\n,")}
|
|
381
|
+
["component", rootComponentNode],
|
|
382
|
+
["errorComponent", rootErrorComponentNode],
|
|
383
|
+
["notFoundComponent", rootNotFoundComponentNode],
|
|
384
|
+
["pendingComponent", rootPendingComponentNode]
|
|
385
|
+
].filter((d) => d[1]).map((d) => {
|
|
386
|
+
const isVueFile = d[1].filePath.endsWith(".vue");
|
|
387
|
+
const exportName = isVueFile ? "default" : d[0];
|
|
388
|
+
const importPath = replaceBackslash(isVueFile ? path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, d[1].filePath)) : removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, d[1].filePath)), config.addExtensions));
|
|
389
|
+
return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`;
|
|
390
|
+
}).join("\n,")}
|
|
561
391
|
})` : ""}._addFileChildren(rootRouteChildren)${config.disableTypes ? "" : `._addFileTypes<FileRouteTypes>()`}`;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
`export interface FileRoutesByFullPath {
|
|
392
|
+
let fileRoutesByPathInterface = "";
|
|
393
|
+
let fileRoutesByFullPath = "";
|
|
394
|
+
if (!config.disableTypes) {
|
|
395
|
+
const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes);
|
|
396
|
+
const routeNodesByTo = createRouteNodesByTo(acc.routeNodes);
|
|
397
|
+
const routeNodesById = createRouteNodesById(acc.routeNodes);
|
|
398
|
+
fileRoutesByFullPath = [
|
|
399
|
+
`export interface FileRoutesByFullPath {
|
|
571
400
|
${[...routeNodesByFullPath.entries()].filter(([fullPath]) => fullPath).map(([fullPath, routeNode]) => {
|
|
572
|
-
|
|
573
|
-
|
|
401
|
+
return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
402
|
+
})}
|
|
574
403
|
}`,
|
|
575
|
-
|
|
404
|
+
`export interface FileRoutesByTo {
|
|
576
405
|
${[...routeNodesByTo.entries()].filter(([to]) => to).map(([to, routeNode]) => {
|
|
577
|
-
|
|
578
|
-
|
|
406
|
+
return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
407
|
+
})}
|
|
579
408
|
}`,
|
|
580
|
-
|
|
409
|
+
`export interface FileRoutesById {
|
|
581
410
|
'${rootRouteId}': typeof rootRouteImport,
|
|
582
411
|
${[...routeNodesById.entries()].map(([id, routeNode]) => {
|
|
583
|
-
|
|
584
|
-
|
|
412
|
+
return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
413
|
+
})}
|
|
585
414
|
}`,
|
|
586
|
-
|
|
415
|
+
`export interface FileRouteTypes {
|
|
587
416
|
fileRoutesByFullPath: FileRoutesByFullPath
|
|
588
417
|
fullPaths: ${acc.routeNodes.length > 0 ? [...routeNodesByFullPath.keys()].filter((fullPath) => fullPath).map((fullPath) => `'${fullPath}'`).join("|") : "never"}
|
|
589
418
|
fileRoutesByTo: FileRoutesByTo
|
|
@@ -591,534 +420,378 @@ to: ${acc.routeNodes.length > 0 ? [...routeNodesByTo.keys()].filter((to) => to).
|
|
|
591
420
|
id: ${[`'${rootRouteId}'`, ...[...routeNodesById.keys()].map((id) => `'${id}'`)].join("|")}
|
|
592
421
|
fileRoutesById: FileRoutesById
|
|
593
422
|
}`,
|
|
594
|
-
|
|
423
|
+
`export interface RootRouteChildren {
|
|
595
424
|
${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
596
425
|
}`
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
${acc.routeTree.map(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
config
|
|
620
|
-
);
|
|
621
|
-
let mergedImports = mergeImportDeclarations(imports);
|
|
622
|
-
if (config.disableTypes) {
|
|
623
|
-
mergedImports = mergedImports.filter((d) => d.importKind !== "type");
|
|
624
|
-
}
|
|
625
|
-
const importStatements = mergedImports.map(buildImportString);
|
|
626
|
-
let moduleAugmentation = "";
|
|
627
|
-
if (config.verboseFileRoutes === false && !config.disableTypes) {
|
|
628
|
-
moduleAugmentation = opts.routeFileResult.map((node) => {
|
|
629
|
-
const getModuleDeclaration = (routeNode) => {
|
|
630
|
-
if (!isRouteNodeValidForAugmentation(routeNode)) {
|
|
631
|
-
return "";
|
|
632
|
-
}
|
|
633
|
-
let moduleAugmentation2 = "";
|
|
634
|
-
if (routeNode._fsRouteType === "lazy") {
|
|
635
|
-
moduleAugmentation2 = `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`;
|
|
636
|
-
} else {
|
|
637
|
-
moduleAugmentation2 = `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',
|
|
426
|
+
].join("\n");
|
|
427
|
+
fileRoutesByPathInterface = buildFileRoutesByPathInterface({
|
|
428
|
+
module: this.targetTemplate.fullPkg,
|
|
429
|
+
interfaceName: "FileRoutesByPath",
|
|
430
|
+
routeNodes: sortedRouteNodes,
|
|
431
|
+
config
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
const routeTree = [`const rootRouteChildren${config.disableTypes ? "" : `: RootRouteChildren`} = {
|
|
435
|
+
${acc.routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
436
|
+
}`, rootRouteUpdate ? rootRouteUpdate.replace("const rootRouteWithChildren = ", "export const routeTree = ") : `export const routeTree = rootRouteImport._addFileChildren(rootRouteChildren)${config.disableTypes ? "" : `._addFileTypes<FileRouteTypes>()`}`].join("\n");
|
|
437
|
+
checkRouteFullPathUniqueness(sortedRouteNodes.filter((d) => d.children === void 0 && "lazy" !== d._fsRouteType), config);
|
|
438
|
+
let mergedImports = mergeImportDeclarations(imports);
|
|
439
|
+
if (config.disableTypes) mergedImports = mergedImports.filter((d) => d.importKind !== "type");
|
|
440
|
+
const importStatements = mergedImports.map(buildImportString);
|
|
441
|
+
let moduleAugmentation = "";
|
|
442
|
+
if (config.verboseFileRoutes === false && !config.disableTypes) moduleAugmentation = opts.routeFileResult.map((node) => {
|
|
443
|
+
const getModuleDeclaration = (routeNode) => {
|
|
444
|
+
if (!isRouteNodeValidForAugmentation(routeNode)) return "";
|
|
445
|
+
let moduleAugmentation = "";
|
|
446
|
+
if (routeNode._fsRouteType === "lazy") moduleAugmentation = `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`;
|
|
447
|
+
else moduleAugmentation = `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',
|
|
638
448
|
FileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
639
449
|
FileRoutesByPath['${routeNode.routePath}']['id'],
|
|
640
450
|
FileRoutesByPath['${routeNode.routePath}']['path'],
|
|
641
451
|
FileRoutesByPath['${routeNode.routePath}']['fullPath']
|
|
642
452
|
>
|
|
643
453
|
`;
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
${moduleAugmentation2}
|
|
454
|
+
return `declare module './${getImportPath(routeNode, config, this.generatedRouteTreePath)}' {
|
|
455
|
+
${moduleAugmentation}
|
|
647
456
|
}`;
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
if (config.routeTreeFileFooter) {
|
|
661
|
-
if (Array.isArray(config.routeTreeFileFooter)) {
|
|
662
|
-
footer = config.routeTreeFileFooter;
|
|
663
|
-
} else {
|
|
664
|
-
footer = config.routeTreeFileFooter();
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
const routeTreeContent = [
|
|
668
|
-
...config.routeTreeFileHeader,
|
|
669
|
-
`// This file was automatically generated by TanStack Router.
|
|
457
|
+
};
|
|
458
|
+
return getModuleDeclaration(node);
|
|
459
|
+
}).join("\n");
|
|
460
|
+
const rootRouteImport = getImportForRouteNode(rootRouteNode, config, this.generatedRouteTreePath, this.root);
|
|
461
|
+
routeImports.unshift(rootRouteImport);
|
|
462
|
+
let footer = [];
|
|
463
|
+
if (config.routeTreeFileFooter) if (Array.isArray(config.routeTreeFileFooter)) footer = config.routeTreeFileFooter;
|
|
464
|
+
else footer = config.routeTreeFileFooter();
|
|
465
|
+
return {
|
|
466
|
+
routeTreeContent: [
|
|
467
|
+
...config.routeTreeFileHeader,
|
|
468
|
+
`// This file was automatically generated by TanStack Router.
|
|
670
469
|
// You should NOT make any changes in this file as it will be overwritten.
|
|
671
470
|
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
}
|
|
995
|
-
if (node._virtualParentRoutePath !== void 0) {
|
|
996
|
-
const explicitParent = acc.routeNodesByPath.get(
|
|
997
|
-
node._virtualParentRoutePath
|
|
998
|
-
);
|
|
999
|
-
if (explicitParent) {
|
|
1000
|
-
parentRoute = explicitParent;
|
|
1001
|
-
} else if (node._virtualParentRoutePath === `/${rootPathId}`) {
|
|
1002
|
-
parentRoute = null;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
if (parentRoute) node.parent = parentRoute;
|
|
1006
|
-
node.path = determineNodePath(node);
|
|
1007
|
-
const trimmedPath = trimPathLeft(node.path ?? "");
|
|
1008
|
-
const trimmedOriginalPath = trimPathLeft(
|
|
1009
|
-
node.originalRoutePath?.replace(
|
|
1010
|
-
node.parent?.originalRoutePath ?? "",
|
|
1011
|
-
""
|
|
1012
|
-
) ?? ""
|
|
1013
|
-
);
|
|
1014
|
-
const split = trimmedPath.split("/");
|
|
1015
|
-
const originalSplit = trimmedOriginalPath.split("/");
|
|
1016
|
-
const lastRouteSegment = split[split.length - 1] ?? trimmedPath;
|
|
1017
|
-
const lastOriginalSegment = originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath;
|
|
1018
|
-
node.isNonPath = isSegmentPathless(lastRouteSegment, lastOriginalSegment) || split.every((part) => this.routeGroupPatternRegex.test(part));
|
|
1019
|
-
node.cleanedPath = removeGroups(
|
|
1020
|
-
removeUnderscoresWithEscape(
|
|
1021
|
-
removeLayoutSegmentsWithEscape(node.path, node.originalRoutePath),
|
|
1022
|
-
node.originalRoutePath
|
|
1023
|
-
)
|
|
1024
|
-
);
|
|
1025
|
-
if (node._fsRouteType === "layout" || node._fsRouteType === "pathless_layout") {
|
|
1026
|
-
node.cleanedPath = removeTrailingSlash(node.cleanedPath);
|
|
1027
|
-
}
|
|
1028
|
-
if (!node.isVirtual && [
|
|
1029
|
-
"lazy",
|
|
1030
|
-
"loader",
|
|
1031
|
-
"component",
|
|
1032
|
-
"pendingComponent",
|
|
1033
|
-
"errorComponent",
|
|
1034
|
-
"notFoundComponent"
|
|
1035
|
-
].some((d) => d === node._fsRouteType)) {
|
|
1036
|
-
acc.routePiecesByPath[node.routePath] = acc.routePiecesByPath[node.routePath] || {};
|
|
1037
|
-
const pieceKey = node._fsRouteType === "lazy" ? "lazy" : node._fsRouteType;
|
|
1038
|
-
acc.routePiecesByPath[node.routePath][pieceKey] = node;
|
|
1039
|
-
const anchorRoute = acc.routeNodesByPath.get(node.routePath);
|
|
1040
|
-
if (!anchorRoute && node.routePath !== `/${rootPathId}`) {
|
|
1041
|
-
this.handleNode(
|
|
1042
|
-
{
|
|
1043
|
-
...node,
|
|
1044
|
-
isVirtual: true,
|
|
1045
|
-
_fsRouteType: "static"
|
|
1046
|
-
},
|
|
1047
|
-
acc,
|
|
1048
|
-
prefixMap,
|
|
1049
|
-
config
|
|
1050
|
-
);
|
|
1051
|
-
}
|
|
1052
|
-
return;
|
|
1053
|
-
}
|
|
1054
|
-
const isPathlessLayoutWithPath = node._fsRouteType === "pathless_layout" && node.cleanedPath && node.cleanedPath.length > 0;
|
|
1055
|
-
if (!node.isVirtual && isPathlessLayoutWithPath) {
|
|
1056
|
-
const immediateParentPath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
1057
|
-
const immediateParentOriginalPath = removeLastSegmentFromPath(node.originalRoutePath) || "/";
|
|
1058
|
-
let searchPath = immediateParentPath;
|
|
1059
|
-
while (searchPath) {
|
|
1060
|
-
const candidate = acc.routeNodesByPath.get(searchPath);
|
|
1061
|
-
if (candidate && !candidate.isVirtual && candidate.path !== "/") {
|
|
1062
|
-
node.parent = candidate;
|
|
1063
|
-
node.path = node.routePath?.replace(candidate.routePath ?? "", "") || "/";
|
|
1064
|
-
const pathRelativeToParent = immediateParentPath.replace(candidate.routePath ?? "", "") || "/";
|
|
1065
|
-
const originalPathRelativeToParent = immediateParentOriginalPath.replace(
|
|
1066
|
-
candidate.originalRoutePath ?? "",
|
|
1067
|
-
""
|
|
1068
|
-
) || "/";
|
|
1069
|
-
node.cleanedPath = removeGroups(
|
|
1070
|
-
removeUnderscoresWithEscape(
|
|
1071
|
-
removeLayoutSegmentsWithEscape(
|
|
1072
|
-
pathRelativeToParent,
|
|
1073
|
-
originalPathRelativeToParent
|
|
1074
|
-
),
|
|
1075
|
-
originalPathRelativeToParent
|
|
1076
|
-
)
|
|
1077
|
-
);
|
|
1078
|
-
break;
|
|
1079
|
-
}
|
|
1080
|
-
if (searchPath === "/") break;
|
|
1081
|
-
searchPath = removeLastSegmentFromPath(searchPath) || "/";
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
if (node.parent) {
|
|
1085
|
-
node.parent.children = node.parent.children ?? [];
|
|
1086
|
-
node.parent.children.push(node);
|
|
1087
|
-
} else {
|
|
1088
|
-
acc.routeTree.push(node);
|
|
1089
|
-
}
|
|
1090
|
-
acc.routeNodes.push(node);
|
|
1091
|
-
if (node.routePath) {
|
|
1092
|
-
acc.routeNodesByPath.set(node.routePath, node);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
// only process files that are relevant for the route tree generation
|
|
1096
|
-
isFileRelevantForRouteTreeGeneration(filePath) {
|
|
1097
|
-
if (filePath === this.generatedRouteTreePath) {
|
|
1098
|
-
return true;
|
|
1099
|
-
}
|
|
1100
|
-
if (filePath.startsWith(this.routesDirectoryPath)) {
|
|
1101
|
-
return true;
|
|
1102
|
-
}
|
|
1103
|
-
if (typeof this.config.virtualRouteConfig === "string" && filePath === this.config.virtualRouteConfig) {
|
|
1104
|
-
return true;
|
|
1105
|
-
}
|
|
1106
|
-
if (this.routeNodeCache.has(filePath)) {
|
|
1107
|
-
return true;
|
|
1108
|
-
}
|
|
1109
|
-
if (isVirtualConfigFile(path.basename(filePath))) {
|
|
1110
|
-
return true;
|
|
1111
|
-
}
|
|
1112
|
-
if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {
|
|
1113
|
-
return true;
|
|
1114
|
-
}
|
|
1115
|
-
return false;
|
|
1116
|
-
}
|
|
471
|
+
[...importStatements].join("\n"),
|
|
472
|
+
mergeImportDeclarations(routeImports).map(buildImportString).join("\n"),
|
|
473
|
+
virtualRouteNodes.join("\n"),
|
|
474
|
+
createUpdateRoutes.join("\n"),
|
|
475
|
+
fileRoutesByFullPath,
|
|
476
|
+
fileRoutesByPathInterface,
|
|
477
|
+
moduleAugmentation,
|
|
478
|
+
routeTreeConfig.join("\n"),
|
|
479
|
+
routeTree,
|
|
480
|
+
...footer
|
|
481
|
+
].filter(Boolean).join("\n\n"),
|
|
482
|
+
routeTree: acc.routeTree,
|
|
483
|
+
routeNodes: acc.routeNodes
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
async processRouteNodeFile(node) {
|
|
487
|
+
const result = await this.isRouteFileCacheFresh(node);
|
|
488
|
+
if (result.status === "fresh") return {
|
|
489
|
+
node: result.cacheEntry.node,
|
|
490
|
+
shouldWriteTree: false,
|
|
491
|
+
cacheEntry: result.cacheEntry
|
|
492
|
+
};
|
|
493
|
+
const previousCacheEntry = result.cacheEntry;
|
|
494
|
+
const existingRouteFile = await this.fs.readFile(node.fullPath);
|
|
495
|
+
if (existingRouteFile === "file-not-existing") throw new Error(`⚠️ File ${node.fullPath} does not exist`);
|
|
496
|
+
if (node.routePath) validateRouteParams(node.routePath, node.filePath, this.logger);
|
|
497
|
+
const updatedCacheEntry = {
|
|
498
|
+
fileContent: existingRouteFile.fileContent,
|
|
499
|
+
mtimeMs: existingRouteFile.stat.mtimeMs,
|
|
500
|
+
routeId: node.routePath ?? "$$TSR_NO_ROUTE_PATH_ASSIGNED$$",
|
|
501
|
+
node
|
|
502
|
+
};
|
|
503
|
+
const escapedRoutePath = node.routePath?.replaceAll("$", "$$") ?? "";
|
|
504
|
+
let shouldWriteRouteFile = false;
|
|
505
|
+
let shouldWriteTree = false;
|
|
506
|
+
if (!existingRouteFile.fileContent) {
|
|
507
|
+
shouldWriteRouteFile = true;
|
|
508
|
+
shouldWriteTree = true;
|
|
509
|
+
if (node._fsRouteType === "lazy") {
|
|
510
|
+
const tLazyRouteTemplate = this.targetTemplate.lazyRoute;
|
|
511
|
+
updatedCacheEntry.fileContent = await fillTemplate(this.config, (this.config.customScaffolding?.lazyRouteTemplate || this.config.customScaffolding?.routeTemplate) ?? tLazyRouteTemplate.template(), {
|
|
512
|
+
tsrImports: tLazyRouteTemplate.imports.tsrImports(),
|
|
513
|
+
tsrPath: escapedRoutePath.replaceAll(/\{(.+?)\}/gm, "$1"),
|
|
514
|
+
tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
|
|
515
|
+
tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
|
|
516
|
+
});
|
|
517
|
+
} else if (["layout", "static"].some((d) => d === node._fsRouteType) || [
|
|
518
|
+
"component",
|
|
519
|
+
"pendingComponent",
|
|
520
|
+
"errorComponent",
|
|
521
|
+
"notFoundComponent",
|
|
522
|
+
"loader"
|
|
523
|
+
].every((d) => d !== node._fsRouteType)) {
|
|
524
|
+
const tRouteTemplate = this.targetTemplate.route;
|
|
525
|
+
updatedCacheEntry.fileContent = await fillTemplate(this.config, this.config.customScaffolding?.routeTemplate ?? tRouteTemplate.template(), {
|
|
526
|
+
tsrImports: tRouteTemplate.imports.tsrImports(),
|
|
527
|
+
tsrPath: escapedRoutePath.replaceAll(/\{(.+?)\}/gm, "$1"),
|
|
528
|
+
tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
|
|
529
|
+
tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
|
|
530
|
+
});
|
|
531
|
+
} else return null;
|
|
532
|
+
}
|
|
533
|
+
if (!node.filePath.endsWith(".vue")) {
|
|
534
|
+
const transformResult = await transform({
|
|
535
|
+
source: updatedCacheEntry.fileContent,
|
|
536
|
+
ctx: {
|
|
537
|
+
target: this.config.target,
|
|
538
|
+
routeId: escapedRoutePath,
|
|
539
|
+
lazy: node._fsRouteType === "lazy",
|
|
540
|
+
verboseFileRoutes: !(this.config.verboseFileRoutes === false)
|
|
541
|
+
},
|
|
542
|
+
node
|
|
543
|
+
});
|
|
544
|
+
if (transformResult.result === "no-route-export") {
|
|
545
|
+
const fileName = path.basename(node.fullPath);
|
|
546
|
+
const dirName = path.dirname(node.fullPath);
|
|
547
|
+
const ignorePrefix = this.config.routeFileIgnorePrefix;
|
|
548
|
+
const ignorePattern = this.config.routeFileIgnorePattern;
|
|
549
|
+
const suggestedFileName = `${ignorePrefix}${fileName}`;
|
|
550
|
+
const suggestedFullPath = path.join(dirName, suggestedFileName);
|
|
551
|
+
let message = `Warning: Route file "${node.fullPath}" does not export a Route. This file will not be included in the route tree.`;
|
|
552
|
+
message += `\n\nIf this file is not intended to be a route, you can exclude it using one of these options:`;
|
|
553
|
+
message += `\n 1. Rename the file to "${suggestedFullPath}" (prefix with "${ignorePrefix}")`;
|
|
554
|
+
message += `\n 2. Use 'routeFileIgnorePattern' in your config to match this file`;
|
|
555
|
+
message += `\n\nCurrent configuration:`;
|
|
556
|
+
message += `\n routeFileIgnorePrefix: "${ignorePrefix}"`;
|
|
557
|
+
message += `\n routeFileIgnorePattern: ${ignorePattern ? `"${ignorePattern}"` : "undefined"}`;
|
|
558
|
+
this.logger.warn(message);
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
if (transformResult.result === "error") throw new Error(`Error transforming route file ${node.fullPath}: ${transformResult.error}`);
|
|
562
|
+
if (transformResult.result === "modified") {
|
|
563
|
+
updatedCacheEntry.fileContent = transformResult.output;
|
|
564
|
+
shouldWriteRouteFile = true;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
for (const plugin of this.plugins) plugin.afterTransform?.({
|
|
568
|
+
node,
|
|
569
|
+
prevNode: previousCacheEntry?.node
|
|
570
|
+
});
|
|
571
|
+
if (shouldWriteRouteFile) updatedCacheEntry.mtimeMs = (await this.safeFileWrite({
|
|
572
|
+
filePath: node.fullPath,
|
|
573
|
+
newContent: updatedCacheEntry.fileContent,
|
|
574
|
+
strategy: {
|
|
575
|
+
type: "mtime",
|
|
576
|
+
expectedMtimeMs: updatedCacheEntry.mtimeMs
|
|
577
|
+
}
|
|
578
|
+
})).mtimeMs;
|
|
579
|
+
this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
|
|
580
|
+
return {
|
|
581
|
+
node,
|
|
582
|
+
shouldWriteTree,
|
|
583
|
+
cacheEntry: updatedCacheEntry
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
async didRouteFileChangeComparedToCache(file, cache) {
|
|
587
|
+
const cacheEntry = this[cache].get(file.path);
|
|
588
|
+
return this.didFileChangeComparedToCache(file, cacheEntry);
|
|
589
|
+
}
|
|
590
|
+
async didFileChangeComparedToCache(file, cacheEntry) {
|
|
591
|
+
if (!cacheEntry) return { result: "file-not-in-cache" };
|
|
592
|
+
let mtimeMs = file.mtimeMs;
|
|
593
|
+
if (mtimeMs === void 0) try {
|
|
594
|
+
mtimeMs = (await this.fs.stat(file.path)).mtimeMs;
|
|
595
|
+
} catch {
|
|
596
|
+
return { result: "cannot-stat-file" };
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
result: mtimeMs !== cacheEntry.mtimeMs,
|
|
600
|
+
mtimeMs,
|
|
601
|
+
cacheEntry
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
async safeFileWrite(opts) {
|
|
605
|
+
const tmpPath = this.getTempFileName(opts.filePath);
|
|
606
|
+
await this.fs.writeFile(tmpPath, opts.newContent);
|
|
607
|
+
if (opts.strategy.type === "mtime") {
|
|
608
|
+
const beforeStat = await this.fs.stat(opts.filePath);
|
|
609
|
+
if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) throw rerun({
|
|
610
|
+
msg: `File ${opts.filePath} was modified by another process during processing.`,
|
|
611
|
+
event: {
|
|
612
|
+
type: "update",
|
|
613
|
+
path: opts.filePath
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
const newFileState = await this.fs.stat(tmpPath);
|
|
617
|
+
if (newFileState.mode !== beforeStat.mode) await this.fs.chmod(tmpPath, beforeStat.mode);
|
|
618
|
+
if (newFileState.uid !== beforeStat.uid || newFileState.gid !== beforeStat.gid) try {
|
|
619
|
+
await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid);
|
|
620
|
+
} catch (err) {
|
|
621
|
+
if (typeof err === "object" && err !== null && "code" in err && err.code === "EPERM") console.warn(`[safeFileWrite] chown failed: ${err.message}`);
|
|
622
|
+
else throw err;
|
|
623
|
+
}
|
|
624
|
+
} else if (await checkFileExists(opts.filePath)) throw rerun({
|
|
625
|
+
msg: `File ${opts.filePath} already exists. Cannot overwrite.`,
|
|
626
|
+
event: {
|
|
627
|
+
type: "update",
|
|
628
|
+
path: opts.filePath
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
const stat = await this.fs.stat(tmpPath);
|
|
632
|
+
await this.fs.rename(tmpPath, opts.filePath);
|
|
633
|
+
return stat;
|
|
634
|
+
}
|
|
635
|
+
getTempFileName(filePath) {
|
|
636
|
+
const absPath = path.resolve(filePath);
|
|
637
|
+
const hash = crypto.createHash("md5").update(absPath).digest("hex");
|
|
638
|
+
if (!this.sessionId) {
|
|
639
|
+
mkdirSync(this.config.tmpDir, { recursive: true });
|
|
640
|
+
this.sessionId = crypto.randomBytes(4).toString("hex");
|
|
641
|
+
}
|
|
642
|
+
return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`);
|
|
643
|
+
}
|
|
644
|
+
async isRouteFileCacheFresh(node) {
|
|
645
|
+
const fileChangedCache = await this.didRouteFileChangeComparedToCache({ path: node.fullPath }, "routeNodeCache");
|
|
646
|
+
if (fileChangedCache.result === false) {
|
|
647
|
+
this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry);
|
|
648
|
+
return {
|
|
649
|
+
status: "fresh",
|
|
650
|
+
cacheEntry: fileChangedCache.cacheEntry
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
if (fileChangedCache.result === "cannot-stat-file") throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`);
|
|
654
|
+
const mtimeMs = fileChangedCache.result === true ? fileChangedCache.mtimeMs : void 0;
|
|
655
|
+
const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache({
|
|
656
|
+
path: node.fullPath,
|
|
657
|
+
mtimeMs
|
|
658
|
+
}, "routeNodeShadowCache");
|
|
659
|
+
if (shadowCacheFileChange.result === "cannot-stat-file") throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`);
|
|
660
|
+
if (shadowCacheFileChange.result === false) {
|
|
661
|
+
if (fileChangedCache.result === true) return {
|
|
662
|
+
status: "fresh",
|
|
663
|
+
cacheEntry: shadowCacheFileChange.cacheEntry
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
if (fileChangedCache.result === "file-not-in-cache") return { status: "stale" };
|
|
667
|
+
return {
|
|
668
|
+
status: "stale",
|
|
669
|
+
cacheEntry: fileChangedCache.cacheEntry
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
async handleRootNode(node) {
|
|
673
|
+
const result = await this.isRouteFileCacheFresh(node);
|
|
674
|
+
if (result.status === "fresh") this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry);
|
|
675
|
+
const rootNodeFile = await this.fs.readFile(node.fullPath);
|
|
676
|
+
if (rootNodeFile === "file-not-existing") throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`);
|
|
677
|
+
const updatedCacheEntry = {
|
|
678
|
+
fileContent: rootNodeFile.fileContent,
|
|
679
|
+
mtimeMs: rootNodeFile.stat.mtimeMs,
|
|
680
|
+
routeId: node.routePath ?? "$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$",
|
|
681
|
+
node
|
|
682
|
+
};
|
|
683
|
+
if (!rootNodeFile.fileContent) {
|
|
684
|
+
const rootTemplate = this.targetTemplate.rootRoute;
|
|
685
|
+
const rootRouteContent = await fillTemplate(this.config, rootTemplate.template(), {
|
|
686
|
+
tsrImports: rootTemplate.imports.tsrImports(),
|
|
687
|
+
tsrPath: rootPathId,
|
|
688
|
+
tsrExportStart: rootTemplate.imports.tsrExportStart(),
|
|
689
|
+
tsrExportEnd: rootTemplate.imports.tsrExportEnd()
|
|
690
|
+
});
|
|
691
|
+
this.logger.log(`🟡 Creating ${node.fullPath}`);
|
|
692
|
+
const stats = await this.safeFileWrite({
|
|
693
|
+
filePath: node.fullPath,
|
|
694
|
+
newContent: rootRouteContent,
|
|
695
|
+
strategy: {
|
|
696
|
+
type: "mtime",
|
|
697
|
+
expectedMtimeMs: rootNodeFile.stat.mtimeMs
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
updatedCacheEntry.fileContent = rootRouteContent;
|
|
701
|
+
updatedCacheEntry.mtimeMs = stats.mtimeMs;
|
|
702
|
+
}
|
|
703
|
+
this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
|
|
704
|
+
}
|
|
705
|
+
async getCrawlingResult() {
|
|
706
|
+
await this.runPromise;
|
|
707
|
+
return this.crawlingResult;
|
|
708
|
+
}
|
|
709
|
+
static handleNode(node, acc, prefixMap, config) {
|
|
710
|
+
let parentRoute = hasParentRoute(prefixMap, node, node.routePath);
|
|
711
|
+
if (node.routePath) {
|
|
712
|
+
let searchPath = node.routePath;
|
|
713
|
+
while (searchPath.length > 0) {
|
|
714
|
+
const lastSlash = searchPath.lastIndexOf("/");
|
|
715
|
+
if (lastSlash <= 0) break;
|
|
716
|
+
searchPath = searchPath.substring(0, lastSlash);
|
|
717
|
+
const candidate = acc.routeNodesByPath.get(searchPath);
|
|
718
|
+
if (candidate && candidate.routePath !== node.routePath) {
|
|
719
|
+
if (candidate !== parentRoute) {
|
|
720
|
+
if (!parentRoute || (candidate.routePath?.length ?? 0) > (parentRoute.routePath?.length ?? 0)) parentRoute = candidate;
|
|
721
|
+
}
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (node._virtualParentRoutePath !== void 0) {
|
|
727
|
+
const explicitParent = acc.routeNodesByPath.get(node._virtualParentRoutePath);
|
|
728
|
+
if (explicitParent) parentRoute = explicitParent;
|
|
729
|
+
else if (node._virtualParentRoutePath === `/__root`) parentRoute = null;
|
|
730
|
+
}
|
|
731
|
+
if (parentRoute) node.parent = parentRoute;
|
|
732
|
+
node.path = determineNodePath(node);
|
|
733
|
+
const trimmedPath = trimPathLeft(node.path ?? "");
|
|
734
|
+
const trimmedOriginalPath = trimPathLeft(node.originalRoutePath?.replace(node.parent?.originalRoutePath ?? "", "") ?? "");
|
|
735
|
+
const split = trimmedPath.split("/");
|
|
736
|
+
const originalSplit = trimmedOriginalPath.split("/");
|
|
737
|
+
node.isNonPath = isSegmentPathless(split[split.length - 1] ?? trimmedPath, originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath) || split.every((part) => this.routeGroupPatternRegex.test(part));
|
|
738
|
+
node.cleanedPath = removeGroups(removeUnderscoresWithEscape(removeLayoutSegmentsWithEscape(node.path, node.originalRoutePath), node.originalRoutePath));
|
|
739
|
+
if (node._fsRouteType === "layout" || node._fsRouteType === "pathless_layout") node.cleanedPath = removeTrailingSlash(node.cleanedPath);
|
|
740
|
+
if (!node.isVirtual && [
|
|
741
|
+
"lazy",
|
|
742
|
+
"loader",
|
|
743
|
+
"component",
|
|
744
|
+
"pendingComponent",
|
|
745
|
+
"errorComponent",
|
|
746
|
+
"notFoundComponent"
|
|
747
|
+
].some((d) => d === node._fsRouteType)) {
|
|
748
|
+
acc.routePiecesByPath[node.routePath] = acc.routePiecesByPath[node.routePath] || {};
|
|
749
|
+
const pieceKey = node._fsRouteType === "lazy" ? "lazy" : node._fsRouteType;
|
|
750
|
+
acc.routePiecesByPath[node.routePath][pieceKey] = node;
|
|
751
|
+
if (!acc.routeNodesByPath.get(node.routePath) && node.routePath !== `/__root`) this.handleNode({
|
|
752
|
+
...node,
|
|
753
|
+
isVirtual: true,
|
|
754
|
+
_fsRouteType: "static"
|
|
755
|
+
}, acc, prefixMap, config);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const isPathlessLayoutWithPath = node._fsRouteType === "pathless_layout" && node.cleanedPath && node.cleanedPath.length > 0;
|
|
759
|
+
if (!node.isVirtual && isPathlessLayoutWithPath) {
|
|
760
|
+
const immediateParentPath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
761
|
+
const immediateParentOriginalPath = removeLastSegmentFromPath(node.originalRoutePath) || "/";
|
|
762
|
+
let searchPath = immediateParentPath;
|
|
763
|
+
while (searchPath) {
|
|
764
|
+
const candidate = acc.routeNodesByPath.get(searchPath);
|
|
765
|
+
if (candidate && !candidate.isVirtual && candidate.path !== "/") {
|
|
766
|
+
node.parent = candidate;
|
|
767
|
+
node.path = node.routePath?.replace(candidate.routePath ?? "", "") || "/";
|
|
768
|
+
const pathRelativeToParent = immediateParentPath.replace(candidate.routePath ?? "", "") || "/";
|
|
769
|
+
const originalPathRelativeToParent = immediateParentOriginalPath.replace(candidate.originalRoutePath ?? "", "") || "/";
|
|
770
|
+
node.cleanedPath = removeGroups(removeUnderscoresWithEscape(removeLayoutSegmentsWithEscape(pathRelativeToParent, originalPathRelativeToParent), originalPathRelativeToParent));
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
if (searchPath === "/") break;
|
|
774
|
+
searchPath = removeLastSegmentFromPath(searchPath) || "/";
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (node.parent) {
|
|
778
|
+
node.parent.children = node.parent.children ?? [];
|
|
779
|
+
node.parent.children.push(node);
|
|
780
|
+
} else acc.routeTree.push(node);
|
|
781
|
+
acc.routeNodes.push(node);
|
|
782
|
+
if (node.routePath) acc.routeNodesByPath.set(node.routePath, node);
|
|
783
|
+
}
|
|
784
|
+
isFileRelevantForRouteTreeGeneration(filePath) {
|
|
785
|
+
if (filePath === this.generatedRouteTreePath) return true;
|
|
786
|
+
if (filePath.startsWith(this.routesDirectoryPath)) return true;
|
|
787
|
+
if (typeof this.config.virtualRouteConfig === "string" && filePath === this.config.virtualRouteConfig) return true;
|
|
788
|
+
if (this.routeNodeCache.has(filePath)) return true;
|
|
789
|
+
if (isVirtualConfigFile(path.basename(filePath))) return true;
|
|
790
|
+
if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) return true;
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
1117
793
|
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
Generator
|
|
1123
|
-
};
|
|
1124
|
-
//# sourceMappingURL=generator.js.map
|
|
794
|
+
//#endregion
|
|
795
|
+
export { Generator };
|
|
796
|
+
|
|
797
|
+
//# sourceMappingURL=generator.js.map
|