@tanstack/router-generator 1.20.0 → 1.20.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/config.cjs +93 -13
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +126 -9
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +191 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +14 -0
- package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -0
- package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -0
- package/dist/cjs/filesystem/physical/rootPathId.d.cts +1 -0
- package/dist/cjs/filesystem/virtual/config.cjs +37 -0
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/config.d.cts +3 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +186 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +5 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +11 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.d.cts +1 -0
- package/dist/cjs/generator.cjs +516 -328
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +1 -37
- package/dist/cjs/index.cjs +24 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -1
- package/dist/cjs/template.cjs +110 -0
- package/dist/cjs/template.cjs.map +1 -0
- package/dist/cjs/template.d.cts +33 -0
- package/dist/cjs/types.d.cts +20 -0
- package/dist/cjs/utils.cjs +177 -10
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +47 -5
- package/dist/esm/config.d.ts +126 -9
- package/dist/esm/config.js +88 -8
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.d.ts +14 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js +174 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -0
- package/dist/esm/filesystem/physical/rootPathId.d.ts +1 -0
- package/dist/esm/filesystem/physical/rootPathId.js +5 -0
- package/dist/esm/filesystem/physical/rootPathId.js.map +1 -0
- package/dist/esm/filesystem/virtual/config.d.ts +3 -0
- package/dist/esm/filesystem/virtual/config.js +37 -0
- package/dist/esm/filesystem/virtual/config.js.map +1 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +5 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.js +186 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.d.ts +1 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.js +11 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -0
- package/dist/esm/generator.d.ts +1 -37
- package/dist/esm/generator.js +509 -320
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.d.ts +7 -1
- package/dist/esm/index.js +26 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/template.d.ts +33 -0
- package/dist/esm/template.js +110 -0
- package/dist/esm/template.js.map +1 -0
- package/dist/esm/types.d.ts +20 -0
- package/dist/esm/utils.d.ts +47 -5
- package/dist/esm/utils.js +160 -11
- package/dist/esm/utils.js.map +1 -1
- package/package.json +27 -22
- package/src/config.ts +112 -8
- package/src/filesystem/physical/getRouteNodes.ts +295 -0
- package/src/filesystem/physical/rootPathId.ts +1 -0
- package/src/filesystem/virtual/config.ts +45 -0
- package/src/filesystem/virtual/getRouteNodes.ts +260 -0
- package/src/filesystem/virtual/loadConfigFile.ts +8 -0
- package/src/generator.ts +712 -395
- package/src/index.ts +33 -1
- package/src/template.ts +156 -0
- package/src/types.ts +31 -0
- package/src/utils.ts +237 -10
package/dist/cjs/utils.cjs
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const prettier = require("prettier");
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
22
|
+
const prettier__namespace = /* @__PURE__ */ _interopNamespaceDefault(prettier);
|
|
23
|
+
function multiSortBy(arr, accessors = [(d) => d]) {
|
|
24
|
+
return arr.map((d, i) => [d, i]).sort(([a, ai], [b, bi]) => {
|
|
25
|
+
for (const accessor of accessors) {
|
|
26
|
+
const ao = accessor(a);
|
|
27
|
+
const bo = accessor(b);
|
|
28
|
+
if (typeof ao === "undefined") {
|
|
29
|
+
if (typeof bo === "undefined") {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
if (ao === bo) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
return ao > bo ? 1 : -1;
|
|
38
|
+
}
|
|
39
|
+
return ai - bi;
|
|
40
|
+
}).map(([d]) => d);
|
|
41
|
+
}
|
|
3
42
|
function cleanPath(path) {
|
|
4
43
|
return path.replace(/\/{2,}/g, "/");
|
|
5
44
|
}
|
|
@@ -7,30 +46,158 @@ function trimPathLeft(path) {
|
|
|
7
46
|
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
|
8
47
|
}
|
|
9
48
|
function logging(config) {
|
|
49
|
+
function stripEmojis(str) {
|
|
50
|
+
return str.replace(
|
|
51
|
+
/[\p{Emoji_Presentation}\p{Extended_Pictographic}]/gu,
|
|
52
|
+
""
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function formatLogArgs(args) {
|
|
56
|
+
if (process.env.CI) {
|
|
57
|
+
return args.map(
|
|
58
|
+
(arg) => typeof arg === "string" ? stripEmojis(arg) : arg
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return args;
|
|
62
|
+
}
|
|
10
63
|
return {
|
|
11
64
|
log: (...args) => {
|
|
12
|
-
if (!config.disabled)
|
|
13
|
-
console.log(...args);
|
|
65
|
+
if (!config.disabled) console.log(...formatLogArgs(args));
|
|
14
66
|
},
|
|
15
67
|
debug: (...args) => {
|
|
16
|
-
if (!config.disabled)
|
|
17
|
-
console.debug(...args);
|
|
68
|
+
if (!config.disabled) console.debug(...formatLogArgs(args));
|
|
18
69
|
},
|
|
19
70
|
info: (...args) => {
|
|
20
|
-
if (!config.disabled)
|
|
21
|
-
console.info(...args);
|
|
71
|
+
if (!config.disabled) console.info(...formatLogArgs(args));
|
|
22
72
|
},
|
|
23
73
|
warn: (...args) => {
|
|
24
|
-
if (!config.disabled)
|
|
25
|
-
console.warn(...args);
|
|
74
|
+
if (!config.disabled) console.warn(...formatLogArgs(args));
|
|
26
75
|
},
|
|
27
76
|
error: (...args) => {
|
|
28
|
-
if (!config.disabled)
|
|
29
|
-
console.error(...args);
|
|
77
|
+
if (!config.disabled) console.error(...formatLogArgs(args));
|
|
30
78
|
}
|
|
31
79
|
};
|
|
32
80
|
}
|
|
81
|
+
function removeLeadingSlash(path) {
|
|
82
|
+
return path.replace(/^\//, "");
|
|
83
|
+
}
|
|
84
|
+
function removeTrailingSlash(s) {
|
|
85
|
+
return s.replace(/\/$/, "");
|
|
86
|
+
}
|
|
87
|
+
function determineInitialRoutePath(routePath) {
|
|
88
|
+
const DISALLOWED_ESCAPE_CHARS = /* @__PURE__ */ new Set([
|
|
89
|
+
"/",
|
|
90
|
+
"\\",
|
|
91
|
+
"?",
|
|
92
|
+
"#",
|
|
93
|
+
":",
|
|
94
|
+
"*",
|
|
95
|
+
"<",
|
|
96
|
+
">",
|
|
97
|
+
"|",
|
|
98
|
+
"!",
|
|
99
|
+
"$",
|
|
100
|
+
"%"
|
|
101
|
+
]);
|
|
102
|
+
const parts = routePath.split(new RegExp("(?<!\\[)\\.(?!\\])", "g"));
|
|
103
|
+
const escapedParts = parts.map((part) => {
|
|
104
|
+
const BRACKET_CONTENT_RE = /\[(.*?)\]/g;
|
|
105
|
+
let match;
|
|
106
|
+
while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
|
|
107
|
+
const character = match[1];
|
|
108
|
+
if (character === void 0) continue;
|
|
109
|
+
if (DISALLOWED_ESCAPE_CHARS.has(character)) {
|
|
110
|
+
console.error(
|
|
111
|
+
`Error: Disallowed character "${character}" found in square brackets in route path "${routePath}".
|
|
112
|
+
You cannot use any of the following characters in square brackets: ${Array.from(
|
|
113
|
+
DISALLOWED_ESCAPE_CHARS
|
|
114
|
+
).join(", ")}
|
|
115
|
+
Please remove and/or replace them.`
|
|
116
|
+
);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return part.replace(/\[(.)\]/g, "$1");
|
|
121
|
+
});
|
|
122
|
+
const final = cleanPath(`/${escapedParts.join("/")}`) || "";
|
|
123
|
+
return final;
|
|
124
|
+
}
|
|
125
|
+
function replaceBackslash(s) {
|
|
126
|
+
return s.replaceAll(/\\/gi, "/");
|
|
127
|
+
}
|
|
128
|
+
function routePathToVariable(routePath) {
|
|
129
|
+
var _a;
|
|
130
|
+
const toVariableSafeChar = (char) => {
|
|
131
|
+
if (/[a-zA-Z0-9_]/.test(char)) {
|
|
132
|
+
return char;
|
|
133
|
+
}
|
|
134
|
+
switch (char) {
|
|
135
|
+
case ".":
|
|
136
|
+
return "Dot";
|
|
137
|
+
case "-":
|
|
138
|
+
return "Dash";
|
|
139
|
+
case "@":
|
|
140
|
+
return "At";
|
|
141
|
+
case "(":
|
|
142
|
+
return "";
|
|
143
|
+
// Removed since route groups use parentheses
|
|
144
|
+
case ")":
|
|
145
|
+
return "";
|
|
146
|
+
// Removed since route groups use parentheses
|
|
147
|
+
case " ":
|
|
148
|
+
return "";
|
|
149
|
+
// Remove spaces
|
|
150
|
+
default:
|
|
151
|
+
return `Char${char.charCodeAt(0)}`;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return ((_a = removeUnderscores(routePath)) == null ? void 0 : _a.replace(/\/\$\//g, "/splat/").replace(/\$$/g, "splat").replace(/\$\{\$\}/g, "splat").replace(/\$/g, "").split(/[/-]/g).map((d, i) => i > 0 ? capitalize(d) : d).join("").split("").map(toVariableSafeChar).join("").replace(/^(\d)/g, "R$1")) ?? "";
|
|
155
|
+
}
|
|
156
|
+
function removeUnderscores(s) {
|
|
157
|
+
return s == null ? void 0 : s.replaceAll(/(^_|_$)/gi, "").replaceAll(/(\/_|_\/)/gi, "/");
|
|
158
|
+
}
|
|
159
|
+
function capitalize(s) {
|
|
160
|
+
if (typeof s !== "string") return "";
|
|
161
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
162
|
+
}
|
|
163
|
+
function removeExt(d, keepExtension = false) {
|
|
164
|
+
return keepExtension ? d : d.substring(0, d.lastIndexOf(".")) || d;
|
|
165
|
+
}
|
|
166
|
+
async function writeIfDifferent(filepath, content, incomingContent, callbacks) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
if (content !== incomingContent) {
|
|
169
|
+
(_a = callbacks == null ? void 0 : callbacks.beforeWrite) == null ? void 0 : _a.call(callbacks);
|
|
170
|
+
fs__namespace.writeFileSync(filepath, incomingContent);
|
|
171
|
+
(_b = callbacks == null ? void 0 : callbacks.afterWrite) == null ? void 0 : _b.call(callbacks);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
async function format(source, config) {
|
|
177
|
+
const prettierOptions = {
|
|
178
|
+
semi: config.semicolons,
|
|
179
|
+
singleQuote: config.quoteStyle === "single",
|
|
180
|
+
parser: "typescript"
|
|
181
|
+
};
|
|
182
|
+
return prettier__namespace.format(source, prettierOptions);
|
|
183
|
+
}
|
|
184
|
+
function resetRegex(regex) {
|
|
185
|
+
regex.lastIndex = 0;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
exports.capitalize = capitalize;
|
|
33
189
|
exports.cleanPath = cleanPath;
|
|
190
|
+
exports.determineInitialRoutePath = determineInitialRoutePath;
|
|
191
|
+
exports.format = format;
|
|
34
192
|
exports.logging = logging;
|
|
193
|
+
exports.multiSortBy = multiSortBy;
|
|
194
|
+
exports.removeExt = removeExt;
|
|
195
|
+
exports.removeLeadingSlash = removeLeadingSlash;
|
|
196
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
197
|
+
exports.removeUnderscores = removeUnderscores;
|
|
198
|
+
exports.replaceBackslash = replaceBackslash;
|
|
199
|
+
exports.resetRegex = resetRegex;
|
|
200
|
+
exports.routePathToVariable = routePathToVariable;
|
|
35
201
|
exports.trimPathLeft = trimPathLeft;
|
|
202
|
+
exports.writeIfDifferent = writeIfDifferent;
|
|
36
203
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/cjs/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","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;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as fs from 'node:fs'\nimport * as prettier from 'prettier'\n\nexport function multiSortBy<T>(\n arr: Array<T>,\n accessors: Array<(item: T) => any> = [(d) => d],\n): Array<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\nexport 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 function stripEmojis(str: string) {\n return str.replace(\n /[\\p{Emoji_Presentation}\\p{Extended_Pictographic}]/gu,\n '',\n )\n }\n\n function formatLogArgs(args: Array<any>): Array<any> {\n if (process.env.CI) {\n return args.map((arg) =>\n typeof arg === 'string' ? stripEmojis(arg) : arg,\n )\n }\n return args\n }\n\n return {\n log: (...args: Array<any>) => {\n if (!config.disabled) console.log(...formatLogArgs(args))\n },\n debug: (...args: Array<any>) => {\n if (!config.disabled) console.debug(...formatLogArgs(args))\n },\n info: (...args: Array<any>) => {\n if (!config.disabled) console.info(...formatLogArgs(args))\n },\n warn: (...args: Array<any>) => {\n if (!config.disabled) console.warn(...formatLogArgs(args))\n },\n error: (...args: Array<any>) => {\n if (!config.disabled) console.error(...formatLogArgs(args))\n },\n }\n}\n\nexport function removeLeadingSlash(path: string): string {\n return path.replace(/^\\//, '')\n}\n\nexport function removeTrailingSlash(s: string) {\n return s.replace(/\\/$/, '')\n}\n\nexport function determineInitialRoutePath(routePath: string) {\n const DISALLOWED_ESCAPE_CHARS = new Set([\n '/',\n '\\\\',\n '?',\n '#',\n ':',\n '*',\n '<',\n '>',\n '|',\n '!',\n '$',\n '%',\n ])\n\n const parts = routePath.split(/(?<!\\[)\\.(?!\\])/g)\n\n // Escape any characters that in square brackets\n const escapedParts = parts.map((part) => {\n // Check if any disallowed characters are used in brackets\n const BRACKET_CONTENT_RE = /\\[(.*?)\\]/g\n\n let match\n while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {\n const character = match[1]\n if (character === undefined) continue\n if (DISALLOWED_ESCAPE_CHARS.has(character)) {\n console.error(\n `Error: Disallowed character \"${character}\" found in square brackets in route path \"${routePath}\".\\nYou cannot use any of the following characters in square brackets: ${Array.from(\n DISALLOWED_ESCAPE_CHARS,\n ).join(', ')}\\nPlease remove and/or replace them.`,\n )\n process.exit(1)\n }\n }\n\n // Since this split segment is safe at this point, we can\n // remove the brackets and replace them with the content inside\n return part.replace(/\\[(.)\\]/g, '$1')\n })\n\n // If the syntax for prefix/suffix is different, from the path\n // matching internals of router-core, we'd perform those changes here\n // on the `escapedParts` array before it is joined back together in\n // `final`\n\n const final = cleanPath(`/${escapedParts.join('/')}`) || ''\n\n return final\n}\n\nexport function replaceBackslash(s: string) {\n return s.replaceAll(/\\\\/gi, '/')\n}\n\nexport function routePathToVariable(routePath: string): string {\n const toVariableSafeChar = (char: string): string => {\n if (/[a-zA-Z0-9_]/.test(char)) {\n return char // Keep alphanumeric characters and underscores as is\n }\n\n // Replace special characters with meaningful text equivalents\n switch (char) {\n case '.':\n return 'Dot'\n case '-':\n return 'Dash'\n case '@':\n return 'At'\n case '(':\n return '' // Removed since route groups use parentheses\n case ')':\n return '' // Removed since route groups use parentheses\n case ' ':\n return '' // Remove spaces\n default:\n return `Char${char.charCodeAt(0)}` // For any other characters\n }\n }\n\n return (\n removeUnderscores(routePath)\n ?.replace(/\\/\\$\\//g, '/splat/')\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 .split('')\n .map(toVariableSafeChar)\n .join('')\n // .replace(/([^a-zA-Z0-9]|[.])/gm, '')\n .replace(/^(\\d)/g, 'R$1') ?? ''\n )\n}\n\nexport function removeUnderscores(s?: string) {\n return s?.replaceAll(/(^_|_$)/gi, '').replaceAll(/(\\/_|_\\/)/gi, '/')\n}\n\nexport function capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\n/**\n * This function writes to a file if the content is different.\n *\n * @param filepath The path to the file\n * @param content Original content\n * @param incomingContent New content\n * @param callbacks Callbacks to run before and after writing\n * @returns Whether the file was written\n */\nexport async function writeIfDifferent(\n filepath: string,\n content: string,\n incomingContent: string,\n callbacks?: { beforeWrite?: () => void; afterWrite?: () => void },\n): Promise<boolean> {\n if (content !== incomingContent) {\n callbacks?.beforeWrite?.()\n fs.writeFileSync(filepath, incomingContent)\n callbacks?.afterWrite?.()\n return true\n }\n return false\n}\n\n/**\n * This function formats the source code using the default formatter (Prettier).\n *\n * @param source The content to format\n * @param config The configuration object\n * @returns The formatted content\n */\nexport async function format(\n source: string,\n config: {\n quoteStyle: 'single' | 'double'\n semicolons: boolean\n },\n): Promise<string> {\n const prettierOptions: prettier.Config = {\n semi: config.semicolons,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n }\n return prettier.format(source, prettierOptions)\n}\n\n/**\n * This function resets the regex index to 0 so that it can be reused\n * without having to create a new regex object or worry about the last\n * state when using the global flag.\n *\n * @param regex The regex object to reset\n * @returns\n */\nexport function resetRegex(regex: RegExp) {\n regex.lastIndex = 0\n return\n}\n"],"names":["fs","prettier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGO,SAAS,YACd,KACA,YAAqC,CAAC,CAAC,MAAM,CAAC,GACpC;AACV,SAAO,IACJ,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAU,EAC7B,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM;AAC1B,eAAW,YAAY,WAAW;AAC1B,YAAA,KAAK,SAAS,CAAC;AACf,YAAA,KAAK,SAAS,CAAC;AAEjB,UAAA,OAAO,OAAO,aAAa;AACzB,YAAA,OAAO,OAAO,aAAa;AAC7B;AAAA,QAAA;AAEK,eAAA;AAAA,MAAA;AAGT,UAAI,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
|
+
export declare function multiSortBy<T>(arr: Array<T>, accessors?: Array<(item: T) => any>): Array<T>;
|
|
1
2
|
export declare function cleanPath(path: string): string;
|
|
2
3
|
export declare function trimPathLeft(path: string): string;
|
|
3
4
|
export declare function logging(config: {
|
|
4
5
|
disabled: boolean;
|
|
5
6
|
}): {
|
|
6
|
-
log: (...args: any
|
|
7
|
-
debug: (...args: any
|
|
8
|
-
info: (...args: any
|
|
9
|
-
warn: (...args: any
|
|
10
|
-
error: (...args: any
|
|
7
|
+
log: (...args: Array<any>) => void;
|
|
8
|
+
debug: (...args: Array<any>) => void;
|
|
9
|
+
info: (...args: Array<any>) => void;
|
|
10
|
+
warn: (...args: Array<any>) => void;
|
|
11
|
+
error: (...args: Array<any>) => void;
|
|
11
12
|
};
|
|
13
|
+
export declare function removeLeadingSlash(path: string): string;
|
|
14
|
+
export declare function removeTrailingSlash(s: string): string;
|
|
15
|
+
export declare function determineInitialRoutePath(routePath: string): string;
|
|
16
|
+
export declare function replaceBackslash(s: string): string;
|
|
17
|
+
export declare function routePathToVariable(routePath: string): string;
|
|
18
|
+
export declare function removeUnderscores(s?: string): string | undefined;
|
|
19
|
+
export declare function capitalize(s: string): string;
|
|
20
|
+
export declare function removeExt(d: string, keepExtension?: boolean): string;
|
|
21
|
+
/**
|
|
22
|
+
* This function writes to a file if the content is different.
|
|
23
|
+
*
|
|
24
|
+
* @param filepath The path to the file
|
|
25
|
+
* @param content Original content
|
|
26
|
+
* @param incomingContent New content
|
|
27
|
+
* @param callbacks Callbacks to run before and after writing
|
|
28
|
+
* @returns Whether the file was written
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeIfDifferent(filepath: string, content: string, incomingContent: string, callbacks?: {
|
|
31
|
+
beforeWrite?: () => void;
|
|
32
|
+
afterWrite?: () => void;
|
|
33
|
+
}): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* This function formats the source code using the default formatter (Prettier).
|
|
36
|
+
*
|
|
37
|
+
* @param source The content to format
|
|
38
|
+
* @param config The configuration object
|
|
39
|
+
* @returns The formatted content
|
|
40
|
+
*/
|
|
41
|
+
export declare function format(source: string, config: {
|
|
42
|
+
quoteStyle: 'single' | 'double';
|
|
43
|
+
semicolons: boolean;
|
|
44
|
+
}): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* This function resets the regex index to 0 so that it can be reused
|
|
47
|
+
* without having to create a new regex object or worry about the last
|
|
48
|
+
* state when using the global flag.
|
|
49
|
+
*
|
|
50
|
+
* @param regex The regex object to reset
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export declare function resetRegex(regex: RegExp): void;
|
package/dist/esm/config.d.ts
CHANGED
|
@@ -1,34 +1,151 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const baseConfigSchema: z.ZodObject<{
|
|
3
|
+
target: z.ZodDefault<z.ZodOptional<z.ZodEnum<["react", "solid"]>>>;
|
|
4
|
+
virtualRouteConfig: z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>, z.ZodString]>>;
|
|
3
5
|
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
4
6
|
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
5
7
|
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
6
8
|
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
|
-
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
8
9
|
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
9
|
-
|
|
10
|
-
addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
|
+
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
11
11
|
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
|
+
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
13
|
+
indexToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
14
|
+
routeToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
+
pathParamsAllowedCharacters: z.ZodOptional<z.ZodArray<z.ZodEnum<[";", ":", "@", "&", "=", "+", "$", ","]>, "many">>;
|
|
12
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
target: "react" | "solid";
|
|
13
18
|
routeFileIgnorePrefix: string;
|
|
14
19
|
routesDirectory: string;
|
|
15
|
-
generatedRouteTree: string;
|
|
16
20
|
quoteStyle: "single" | "double";
|
|
21
|
+
semicolons: boolean;
|
|
22
|
+
disableLogging: boolean;
|
|
23
|
+
routeTreeFileHeader: string[];
|
|
24
|
+
indexToken: string;
|
|
25
|
+
routeToken: string;
|
|
26
|
+
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
27
|
+
routeFilePrefix?: string | undefined;
|
|
28
|
+
routeFileIgnorePattern?: string | undefined;
|
|
29
|
+
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
target?: "react" | "solid" | undefined;
|
|
32
|
+
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
33
|
+
routeFilePrefix?: string | undefined;
|
|
34
|
+
routeFileIgnorePrefix?: string | undefined;
|
|
35
|
+
routeFileIgnorePattern?: string | undefined;
|
|
36
|
+
routesDirectory?: string | undefined;
|
|
37
|
+
quoteStyle?: "single" | "double" | undefined;
|
|
38
|
+
semicolons?: boolean | undefined;
|
|
39
|
+
disableLogging?: boolean | undefined;
|
|
40
|
+
routeTreeFileHeader?: string[] | undefined;
|
|
41
|
+
indexToken?: string | undefined;
|
|
42
|
+
routeToken?: string | undefined;
|
|
43
|
+
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export type BaseConfig = z.infer<typeof baseConfigSchema>;
|
|
46
|
+
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
47
|
+
target: z.ZodDefault<z.ZodOptional<z.ZodEnum<["react", "solid"]>>>;
|
|
48
|
+
virtualRouteConfig: z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>, z.ZodString]>>;
|
|
49
|
+
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
50
|
+
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
51
|
+
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
52
|
+
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
53
|
+
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
54
|
+
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
55
|
+
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
56
|
+
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
57
|
+
indexToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
58
|
+
routeToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
59
|
+
pathParamsAllowedCharacters: z.ZodOptional<z.ZodArray<z.ZodEnum<[";", ":", "@", "&", "=", "+", "$", ","]>, "many">>;
|
|
60
|
+
}, {
|
|
61
|
+
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
62
|
+
disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
63
|
+
verboseFileRoutes: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
65
|
+
disableManifestGeneration: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
66
|
+
enableRouteTreeFormatting: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
67
|
+
routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
68
|
+
autoCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
customScaffolding: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
routeTemplate: z.ZodOptional<z.ZodString>;
|
|
71
|
+
lazyRouteTemplate: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
routeTemplate?: string | undefined;
|
|
74
|
+
lazyRouteTemplate?: string | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
routeTemplate?: string | undefined;
|
|
77
|
+
lazyRouteTemplate?: string | undefined;
|
|
78
|
+
}>>;
|
|
79
|
+
experimental: z.ZodOptional<z.ZodObject<{
|
|
80
|
+
enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
enableCodeSplitting?: boolean | undefined;
|
|
83
|
+
}, {
|
|
84
|
+
enableCodeSplitting?: boolean | undefined;
|
|
85
|
+
}>>;
|
|
86
|
+
}>, "strip", z.ZodTypeAny, {
|
|
87
|
+
target: "react" | "solid";
|
|
88
|
+
routeFileIgnorePrefix: string;
|
|
89
|
+
routesDirectory: string;
|
|
90
|
+
quoteStyle: "single" | "double";
|
|
91
|
+
semicolons: boolean;
|
|
92
|
+
disableLogging: boolean;
|
|
93
|
+
routeTreeFileHeader: string[];
|
|
94
|
+
indexToken: string;
|
|
95
|
+
routeToken: string;
|
|
96
|
+
generatedRouteTree: string;
|
|
17
97
|
disableTypes: boolean;
|
|
18
98
|
addExtensions: boolean;
|
|
19
|
-
|
|
99
|
+
disableManifestGeneration: boolean;
|
|
100
|
+
enableRouteTreeFormatting: boolean;
|
|
101
|
+
routeTreeFileFooter: string[];
|
|
102
|
+
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
20
103
|
routeFilePrefix?: string | undefined;
|
|
21
104
|
routeFileIgnorePattern?: string | undefined;
|
|
105
|
+
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
106
|
+
verboseFileRoutes?: boolean | undefined;
|
|
107
|
+
autoCodeSplitting?: boolean | undefined;
|
|
108
|
+
customScaffolding?: {
|
|
109
|
+
routeTemplate?: string | undefined;
|
|
110
|
+
lazyRouteTemplate?: string | undefined;
|
|
111
|
+
} | undefined;
|
|
112
|
+
experimental?: {
|
|
113
|
+
enableCodeSplitting?: boolean | undefined;
|
|
114
|
+
} | undefined;
|
|
22
115
|
}, {
|
|
116
|
+
target?: "react" | "solid" | undefined;
|
|
117
|
+
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
23
118
|
routeFilePrefix?: string | undefined;
|
|
24
119
|
routeFileIgnorePrefix?: string | undefined;
|
|
25
120
|
routeFileIgnorePattern?: string | undefined;
|
|
26
121
|
routesDirectory?: string | undefined;
|
|
27
|
-
generatedRouteTree?: string | undefined;
|
|
28
122
|
quoteStyle?: "single" | "double" | undefined;
|
|
123
|
+
semicolons?: boolean | undefined;
|
|
124
|
+
disableLogging?: boolean | undefined;
|
|
125
|
+
routeTreeFileHeader?: string[] | undefined;
|
|
126
|
+
indexToken?: string | undefined;
|
|
127
|
+
routeToken?: string | undefined;
|
|
128
|
+
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
129
|
+
generatedRouteTree?: string | undefined;
|
|
29
130
|
disableTypes?: boolean | undefined;
|
|
131
|
+
verboseFileRoutes?: boolean | undefined;
|
|
30
132
|
addExtensions?: boolean | undefined;
|
|
31
|
-
|
|
133
|
+
disableManifestGeneration?: boolean | undefined;
|
|
134
|
+
enableRouteTreeFormatting?: boolean | undefined;
|
|
135
|
+
routeTreeFileFooter?: string[] | undefined;
|
|
136
|
+
autoCodeSplitting?: boolean | undefined;
|
|
137
|
+
customScaffolding?: {
|
|
138
|
+
routeTemplate?: string | undefined;
|
|
139
|
+
lazyRouteTemplate?: string | undefined;
|
|
140
|
+
} | undefined;
|
|
141
|
+
experimental?: {
|
|
142
|
+
enableCodeSplitting?: boolean | undefined;
|
|
143
|
+
} | undefined;
|
|
32
144
|
}>;
|
|
33
145
|
export type Config = z.infer<typeof configSchema>;
|
|
34
|
-
|
|
146
|
+
type ResolveParams = {
|
|
147
|
+
configDirectory: string;
|
|
148
|
+
};
|
|
149
|
+
export declare function resolveConfigPath({ configDirectory }: ResolveParams): string;
|
|
150
|
+
export declare function getConfig(inlineConfig?: Partial<Config>, configDirectory?: string): Config;
|
|
151
|
+
export {};
|
package/dist/esm/config.js
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { existsSync, readFileSync } from "fs";
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
|
|
4
|
+
import { virtualRootRouteSchema } from "./filesystem/virtual/config.js";
|
|
5
|
+
const baseConfigSchema = z.object({
|
|
6
|
+
target: z.enum(["react", "solid"]).optional().default("react"),
|
|
7
|
+
virtualRouteConfig: virtualRootRouteSchema.or(z.string()).optional(),
|
|
5
8
|
routeFilePrefix: z.string().optional(),
|
|
6
9
|
routeFileIgnorePrefix: z.string().optional().default("-"),
|
|
7
10
|
routeFileIgnorePattern: z.string().optional(),
|
|
8
11
|
routesDirectory: z.string().optional().default("./src/routes"),
|
|
9
|
-
generatedRouteTree: z.string().optional().default("./src/routeTree.gen.ts"),
|
|
10
12
|
quoteStyle: z.enum(["single", "double"]).optional().default("single"),
|
|
13
|
+
semicolons: z.boolean().optional().default(false),
|
|
14
|
+
disableLogging: z.boolean().optional().default(false),
|
|
15
|
+
routeTreeFileHeader: z.array(z.string()).optional().default([
|
|
16
|
+
"/* eslint-disable */",
|
|
17
|
+
"// @ts-nocheck",
|
|
18
|
+
"// noinspection JSUnusedGlobalSymbols"
|
|
19
|
+
]),
|
|
20
|
+
indexToken: z.string().optional().default("index"),
|
|
21
|
+
routeToken: z.string().optional().default("route"),
|
|
22
|
+
pathParamsAllowedCharacters: z.array(z.enum([";", ":", "@", "&", "=", "+", "$", ","])).optional()
|
|
23
|
+
});
|
|
24
|
+
const configSchema = baseConfigSchema.extend({
|
|
25
|
+
generatedRouteTree: z.string().optional().default("./src/routeTree.gen.ts"),
|
|
11
26
|
disableTypes: z.boolean().optional().default(false),
|
|
27
|
+
verboseFileRoutes: z.boolean().optional(),
|
|
12
28
|
addExtensions: z.boolean().optional().default(false),
|
|
13
|
-
|
|
29
|
+
disableManifestGeneration: z.boolean().optional().default(false),
|
|
30
|
+
enableRouteTreeFormatting: z.boolean().optional().default(true),
|
|
31
|
+
routeTreeFileFooter: z.array(z.string()).optional().default([]),
|
|
32
|
+
autoCodeSplitting: z.boolean().optional(),
|
|
33
|
+
customScaffolding: z.object({
|
|
34
|
+
routeTemplate: z.string().optional(),
|
|
35
|
+
lazyRouteTemplate: z.string().optional()
|
|
36
|
+
}).optional(),
|
|
37
|
+
experimental: z.object({
|
|
38
|
+
// TODO: This has been made stable and is now "autoCodeSplitting". Remove in next major version.
|
|
39
|
+
enableCodeSplitting: z.boolean().optional()
|
|
40
|
+
}).optional()
|
|
14
41
|
});
|
|
15
|
-
|
|
42
|
+
function resolveConfigPath({ configDirectory }) {
|
|
43
|
+
return path.resolve(configDirectory, "tsr.config.json");
|
|
44
|
+
}
|
|
45
|
+
function getConfig(inlineConfig = {}, configDirectory) {
|
|
16
46
|
if (configDirectory === void 0) {
|
|
17
47
|
configDirectory = process.cwd();
|
|
18
48
|
}
|
|
19
|
-
const configFilePathJson =
|
|
49
|
+
const configFilePathJson = resolveConfigPath({ configDirectory });
|
|
20
50
|
const exists = existsSync(configFilePathJson);
|
|
21
51
|
let config;
|
|
22
52
|
if (exists) {
|
|
@@ -33,10 +63,60 @@ async function getConfig(inlineConfig = {}, configDirectory) {
|
|
|
33
63
|
".js"
|
|
34
64
|
);
|
|
35
65
|
}
|
|
66
|
+
if (configDirectory) {
|
|
67
|
+
if (path.isAbsolute(configDirectory)) {
|
|
68
|
+
config.routesDirectory = path.resolve(
|
|
69
|
+
configDirectory,
|
|
70
|
+
config.routesDirectory
|
|
71
|
+
);
|
|
72
|
+
config.generatedRouteTree = path.resolve(
|
|
73
|
+
configDirectory,
|
|
74
|
+
config.generatedRouteTree
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
config.routesDirectory = path.resolve(
|
|
78
|
+
process.cwd(),
|
|
79
|
+
configDirectory,
|
|
80
|
+
config.routesDirectory
|
|
81
|
+
);
|
|
82
|
+
config.generatedRouteTree = path.resolve(
|
|
83
|
+
process.cwd(),
|
|
84
|
+
configDirectory,
|
|
85
|
+
config.generatedRouteTree
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
validateConfig(config);
|
|
90
|
+
return config;
|
|
91
|
+
}
|
|
92
|
+
function validateConfig(config) {
|
|
93
|
+
var _a;
|
|
94
|
+
if (typeof ((_a = config.experimental) == null ? void 0 : _a.enableCodeSplitting) !== "undefined") {
|
|
95
|
+
const message = `
|
|
96
|
+
------
|
|
97
|
+
⚠️ ⚠️ ⚠️
|
|
98
|
+
ERROR: The "experimental.enableCodeSplitting" flag has been made stable and is now "autoCodeSplitting". Please update your configuration file to use "autoCodeSplitting" instead of "experimental.enableCodeSplitting".
|
|
99
|
+
------
|
|
100
|
+
`;
|
|
101
|
+
console.error(message);
|
|
102
|
+
throw new Error(message);
|
|
103
|
+
}
|
|
104
|
+
if (config.indexToken === config.routeToken) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`The "indexToken" and "routeToken" options must be different.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (config.routeFileIgnorePrefix && config.routeFileIgnorePrefix.trim() === "_") {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`The "routeFileIgnorePrefix" cannot be an underscore ("_"). This is a reserved character used to denote a pathless route. Please use a different prefix.`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
36
114
|
return config;
|
|
37
115
|
}
|
|
38
116
|
export {
|
|
117
|
+
baseConfigSchema,
|
|
39
118
|
configSchema,
|
|
40
|
-
getConfig
|
|
119
|
+
getConfig,
|
|
120
|
+
resolveConfigPath
|
|
41
121
|
};
|
|
42
122
|
//# sourceMappingURL=config.js.map
|
package/dist/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import path from 'path'\nimport {
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import path from 'node:path'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { z } from 'zod'\nimport { virtualRootRouteSchema } from './filesystem/virtual/config'\n\nexport const baseConfigSchema = z.object({\n target: z.enum(['react', 'solid']).optional().default('react'),\n virtualRouteConfig: virtualRootRouteSchema.or(z.string()).optional(),\n routeFilePrefix: z.string().optional(),\n routeFileIgnorePrefix: z.string().optional().default('-'),\n routeFileIgnorePattern: z.string().optional(),\n routesDirectory: z.string().optional().default('./src/routes'),\n quoteStyle: z.enum(['single', 'double']).optional().default('single'),\n semicolons: z.boolean().optional().default(false),\n disableLogging: z.boolean().optional().default(false),\n routeTreeFileHeader: z\n .array(z.string())\n .optional()\n .default([\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// noinspection JSUnusedGlobalSymbols',\n ]),\n indexToken: z.string().optional().default('index'),\n routeToken: z.string().optional().default('route'),\n pathParamsAllowedCharacters: z\n .array(z.enum([';', ':', '@', '&', '=', '+', '$', ',']))\n .optional(),\n})\n\nexport type BaseConfig = z.infer<typeof baseConfigSchema>\n\nexport const configSchema = baseConfigSchema.extend({\n generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),\n disableTypes: z.boolean().optional().default(false),\n verboseFileRoutes: z.boolean().optional(),\n addExtensions: z.boolean().optional().default(false),\n disableManifestGeneration: z.boolean().optional().default(false),\n enableRouteTreeFormatting: z.boolean().optional().default(true),\n routeTreeFileFooter: z.array(z.string()).optional().default([]),\n autoCodeSplitting: z.boolean().optional(),\n customScaffolding: z\n .object({\n routeTemplate: z.string().optional(),\n lazyRouteTemplate: z.string().optional(),\n })\n .optional(),\n experimental: z\n .object({\n // TODO: This has been made stable and is now \"autoCodeSplitting\". Remove in next major version.\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\ntype ResolveParams = {\n configDirectory: string\n}\n\nexport function resolveConfigPath({ configDirectory }: ResolveParams) {\n return path.resolve(configDirectory, 'tsr.config.json')\n}\n\nexport function getConfig(\n inlineConfig: Partial<Config> = {},\n configDirectory?: string,\n): Config {\n if (configDirectory === undefined) {\n configDirectory = process.cwd()\n }\n const configFilePathJson = resolveConfigPath({ configDirectory })\n const exists = existsSync(configFilePathJson)\n\n let config: Config\n\n if (exists) {\n config = configSchema.parse({\n ...JSON.parse(readFileSync(configFilePathJson, 'utf-8')),\n ...inlineConfig,\n })\n } else {\n config = configSchema.parse(inlineConfig)\n }\n\n // If typescript is disabled, make sure the generated route tree is a .js file\n if (config.disableTypes) {\n config.generatedRouteTree = config.generatedRouteTree.replace(\n /\\.(ts|tsx)$/,\n '.js',\n )\n }\n\n // if a configDirectory is used, paths should be relative to that directory\n if (configDirectory) {\n // if absolute configDirectory is provided, use it as the root\n if (path.isAbsolute(configDirectory)) {\n config.routesDirectory = path.resolve(\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n configDirectory,\n config.generatedRouteTree,\n )\n } else {\n config.routesDirectory = path.resolve(\n process.cwd(),\n configDirectory,\n config.routesDirectory,\n )\n config.generatedRouteTree = path.resolve(\n process.cwd(),\n configDirectory,\n config.generatedRouteTree,\n )\n }\n }\n\n validateConfig(config)\n return config\n}\n\nfunction validateConfig(config: Config) {\n if (typeof config.experimental?.enableCodeSplitting !== 'undefined') {\n const message = `\n------\n⚠️ ⚠️ ⚠️\nERROR: The \"experimental.enableCodeSplitting\" flag has been made stable and is now \"autoCodeSplitting\". Please update your configuration file to use \"autoCodeSplitting\" instead of \"experimental.enableCodeSplitting\".\n------\n`\n console.error(message)\n throw new Error(message)\n }\n\n if (config.indexToken === config.routeToken) {\n throw new Error(\n `The \"indexToken\" and \"routeToken\" options must be different.`,\n )\n }\n\n if (\n config.routeFileIgnorePrefix &&\n config.routeFileIgnorePrefix.trim() === '_'\n ) {\n throw new Error(\n `The \"routeFileIgnorePrefix\" cannot be an underscore (\"_\"). This is a reserved character used to denote a pathless route. Please use a different prefix.`,\n )\n }\n\n return config\n}\n"],"names":[],"mappings":";;;;AAKa,MAAA,mBAAmB,EAAE,OAAO;AAAA,EACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,OAAO,CAAC,EAAE,SAAA,EAAW,QAAQ,OAAO;AAAA,EAC7D,oBAAoB,uBAAuB,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACnE,iBAAiB,EAAE,OAAO,EAAE,SAAS;AAAA,EACrC,uBAAuB,EAAE,OAAA,EAAS,SAAS,EAAE,QAAQ,GAAG;AAAA,EACxD,wBAAwB,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5C,iBAAiB,EAAE,OAAA,EAAS,SAAS,EAAE,QAAQ,cAAc;AAAA,EAC7D,YAAY,EAAE,KAAK,CAAC,UAAU,QAAQ,CAAC,EAAE,SAAA,EAAW,QAAQ,QAAQ;AAAA,EACpE,YAAY,EAAE,QAAA,EAAU,SAAS,EAAE,QAAQ,KAAK;AAAA,EAChD,g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AAO,eAAe,OAAO,YAAY;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGF,MACE,OAAO,yBACP,OAAO,sBAAsB,WAAW,KACxC;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGK,SAAA;AACT;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FsRouteType, GetRouteNodesResult } from '../../types.js';
|
|
2
|
+
import { Config } from '../../config.js';
|
|
3
|
+
export declare function getRouteNodes(config: Pick<Config, 'routesDirectory' | 'routeFilePrefix' | 'routeFileIgnorePrefix' | 'routeFileIgnorePattern' | 'disableLogging' | 'routeToken' | 'indexToken'>, root: string): Promise<GetRouteNodesResult>;
|
|
4
|
+
/**
|
|
5
|
+
* Determines the metadata for a given route path based on the provided configuration.
|
|
6
|
+
*
|
|
7
|
+
* @param routePath - The determined initial routePath.
|
|
8
|
+
* @param config - The user configuration object.
|
|
9
|
+
* @returns An object containing the type of the route and the variable name derived from the route path.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getRouteMeta(routePath: string, config: Pick<Config, 'routeToken' | 'indexToken'>): {
|
|
12
|
+
fsRouteType: Extract<FsRouteType, 'static' | 'layout' | 'api' | 'lazy' | 'loader' | 'component' | 'pendingComponent' | 'errorComponent'>;
|
|
13
|
+
variableName: string;
|
|
14
|
+
};
|