@chuckcchen/vite-plugin 1.0.15 → 1.0.17
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/core.d.ts.map +1 -1
- package/dist/core.js +9 -2
- package/dist/core.js.map +1 -1
- package/dist/factory/hooks.d.ts +1 -1
- package/dist/factory/hooks.d.ts.map +1 -1
- package/dist/factory/hooks.js +4 -2
- package/dist/factory/hooks.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/route/index.d.ts +7 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +8 -0
- package/dist/route/index.js.map +1 -0
- package/dist/route/parser.d.ts +55 -0
- package/dist/route/parser.d.ts.map +1 -0
- package/dist/route/parser.js +300 -0
- package/dist/route/parser.js.map +1 -0
- package/dist/route/regex.d.ts +96 -0
- package/dist/route/regex.d.ts.map +1 -0
- package/dist/route/regex.js +244 -0
- package/dist/route/regex.js.map +1 -0
- package/dist/route/types.d.ts +116 -0
- package/dist/route/types.d.ts.map +1 -0
- package/dist/route/types.js +5 -0
- package/dist/route/types.js.map +1 -0
- package/dist/route-parser.d.ts +4 -159
- package/dist/route-parser.d.ts.map +1 -1
- package/dist/route-parser.js +4 -291
- package/dist/route-parser.js.map +1 -1
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Regex - Convert dynamic routes to regular expressions
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities to convert dynamic route paths from various
|
|
5
|
+
* framework syntaxes into regular expression patterns for route matching.
|
|
6
|
+
*/
|
|
7
|
+
import type { RouteInfo, MetaRouteInfo } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Route parameter syntax types
|
|
10
|
+
*
|
|
11
|
+
* - "colon": :param style (React Router, Remix, Express, Vue Router)
|
|
12
|
+
* - "dollar": $param style (TanStack Start)
|
|
13
|
+
* - "bracket": [param] style (Next.js, Nuxt, SvelteKit)
|
|
14
|
+
* - "auto": Auto-detect based on route path
|
|
15
|
+
*/
|
|
16
|
+
export type RouteSyntax = "colon" | "dollar" | "bracket" | "auto";
|
|
17
|
+
/**
|
|
18
|
+
* Options for converting route path to regex
|
|
19
|
+
*/
|
|
20
|
+
export interface RouteToRegexOptions {
|
|
21
|
+
/** Route parameter syntax to use for parsing. Default: "auto" (auto-detect) */
|
|
22
|
+
syntax?: RouteSyntax;
|
|
23
|
+
/** Whether to make the trailing slash optional. Default: true */
|
|
24
|
+
trailingSlashOptional?: boolean;
|
|
25
|
+
/** Whether to anchor the regex at start and end. Default: true */
|
|
26
|
+
anchored?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a route path contains dynamic segments
|
|
30
|
+
*
|
|
31
|
+
* Detects patterns from multiple syntaxes:
|
|
32
|
+
* - Colon syntax: :param, :param?, * (React Router, Remix, Express)
|
|
33
|
+
* - Dollar syntax: $param, $ (TanStack Start)
|
|
34
|
+
* - Bracket syntax: [param], [[param]], [...param] (Next.js, Nuxt, SvelteKit)
|
|
35
|
+
*/
|
|
36
|
+
export declare function isDynamicRoute(routePath: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Convert a route path to a regular expression pattern
|
|
39
|
+
*
|
|
40
|
+
* Supports multiple route parameter syntaxes:
|
|
41
|
+
*
|
|
42
|
+
* **Colon syntax** (React Router, Remix, Express, Vue Router):
|
|
43
|
+
* - `:slug` → `([^/]+)` - Required dynamic parameter
|
|
44
|
+
* - `:slug?` → `([^/]+)?` - Optional dynamic parameter
|
|
45
|
+
* - `*` → `(.*)` - Wildcard/splat (catches everything)
|
|
46
|
+
*
|
|
47
|
+
* **Dollar syntax** (TanStack Start):
|
|
48
|
+
* - `$slug` → `([^/]+)` - Required dynamic parameter
|
|
49
|
+
* - `$` (at end) → `(.*)` - Wildcard/splat
|
|
50
|
+
*
|
|
51
|
+
* **Bracket syntax** (Next.js, Nuxt, SvelteKit):
|
|
52
|
+
* - `[slug]` → `([^/]+)` - Required dynamic parameter
|
|
53
|
+
* - `[[slug]]` → `([^/]+)?` - Optional dynamic parameter
|
|
54
|
+
* - `[...slug]` → `(.*)` - Catch-all
|
|
55
|
+
* - `[[...slug]]` → `(.*)?` - Optional catch-all
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Colon syntax
|
|
59
|
+
* routeToRegex("/blog/:slug") // "^/blog/([^/]+)/?$"
|
|
60
|
+
* routeToRegex("/files/*") // "^/files(?:/(.*))?$"
|
|
61
|
+
*
|
|
62
|
+
* // Dollar syntax
|
|
63
|
+
* routeToRegex("/blog/$slug") // "^/blog/([^/]+)/?$"
|
|
64
|
+
* routeToRegex("/files/$") // "^/files(?:/(.*))?$"
|
|
65
|
+
*
|
|
66
|
+
* // Bracket syntax
|
|
67
|
+
* routeToRegex("/blog/[slug]") // "^/blog/([^/]+)/?$"
|
|
68
|
+
* routeToRegex("/files/[...path]") // "^/files(?:/(.*))?$"
|
|
69
|
+
*/
|
|
70
|
+
export declare function routeToRegex(routePath: string, options?: RouteToRegexOptions): string;
|
|
71
|
+
/**
|
|
72
|
+
* Add regex patterns to routes that contain dynamic segments
|
|
73
|
+
*
|
|
74
|
+
* This function processes an array of RouteInfo and adds the `regex` field
|
|
75
|
+
* to routes that contain dynamic parameters.
|
|
76
|
+
*
|
|
77
|
+
* @param routes - Array of route info objects
|
|
78
|
+
* @param options - Options for regex conversion
|
|
79
|
+
* @returns Routes with regex patterns added where applicable
|
|
80
|
+
*/
|
|
81
|
+
export declare function addRegexToRoutes(routes: RouteInfo[], options?: RouteToRegexOptions): RouteInfo[];
|
|
82
|
+
/**
|
|
83
|
+
* Convert routes to simplified meta.json format
|
|
84
|
+
*
|
|
85
|
+
* This function converts RouteInfo array to MetaRouteInfo array,
|
|
86
|
+
* keeping only `regexPath` and `isStatic` fields for EdgeOne runtime.
|
|
87
|
+
*
|
|
88
|
+
* - Dynamic routes (with parameters like :id, $id, [id]) are converted to regex patterns
|
|
89
|
+
* - Static routes keep their original path without conversion
|
|
90
|
+
*
|
|
91
|
+
* @param routes - Array of route info objects
|
|
92
|
+
* @param options - Options for regex conversion
|
|
93
|
+
* @returns Simplified routes for meta.json
|
|
94
|
+
*/
|
|
95
|
+
export declare function convertRoutesToMetaFormat(routes: RouteInfo[], options?: RouteToRegexOptions): MetaRouteInfo[];
|
|
96
|
+
//# sourceMappingURL=regex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/route/regex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5D;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,iEAAiE;IACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAMD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAUzD;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,mBAAwB,GAChC,MAAM,CA2CR;AAoFD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,GAAE,mBAAwB,GAChC,SAAS,EAAE,CAeb;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,GAAE,mBAAwB,GAChC,aAAa,EAAE,CAmBjB"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Regex - Convert dynamic routes to regular expressions
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities to convert dynamic route paths from various
|
|
5
|
+
* framework syntaxes into regular expression patterns for route matching.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Dynamic Route Detection
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Check if a route path contains dynamic segments
|
|
12
|
+
*
|
|
13
|
+
* Detects patterns from multiple syntaxes:
|
|
14
|
+
* - Colon syntax: :param, :param?, * (React Router, Remix, Express)
|
|
15
|
+
* - Dollar syntax: $param, $ (TanStack Start)
|
|
16
|
+
* - Bracket syntax: [param], [[param]], [...param] (Next.js, Nuxt, SvelteKit)
|
|
17
|
+
*/
|
|
18
|
+
export function isDynamicRoute(routePath) {
|
|
19
|
+
// Colon syntax: :param or :param?
|
|
20
|
+
if (/:[\w]+\??/.test(routePath))
|
|
21
|
+
return true;
|
|
22
|
+
// Dollar syntax: $param or lone $
|
|
23
|
+
if (/\$[\w]*/.test(routePath))
|
|
24
|
+
return true;
|
|
25
|
+
// Bracket syntax: [param], [[param]], [...param]
|
|
26
|
+
if (/\[{1,2}\.{0,3}[\w]+\]{1,2}/.test(routePath))
|
|
27
|
+
return true;
|
|
28
|
+
// Wildcard: *
|
|
29
|
+
if (/\*/.test(routePath))
|
|
30
|
+
return true;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Detect route syntax from route path
|
|
35
|
+
*/
|
|
36
|
+
function detectRouteSyntax(routePath) {
|
|
37
|
+
// Dollar syntax: $param style
|
|
38
|
+
if (/\$[\w]+/.test(routePath) || /\/\$$/.test(routePath)) {
|
|
39
|
+
return "dollar";
|
|
40
|
+
}
|
|
41
|
+
// Bracket syntax: [param] style
|
|
42
|
+
if (/\[{1,2}\.{0,3}[\w]+\]{1,2}/.test(routePath)) {
|
|
43
|
+
return "bracket";
|
|
44
|
+
}
|
|
45
|
+
// Colon syntax: :param style (default)
|
|
46
|
+
return "colon";
|
|
47
|
+
}
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Route to Regex Conversion
|
|
50
|
+
// ============================================================================
|
|
51
|
+
/**
|
|
52
|
+
* Convert a route path to a regular expression pattern
|
|
53
|
+
*
|
|
54
|
+
* Supports multiple route parameter syntaxes:
|
|
55
|
+
*
|
|
56
|
+
* **Colon syntax** (React Router, Remix, Express, Vue Router):
|
|
57
|
+
* - `:slug` → `([^/]+)` - Required dynamic parameter
|
|
58
|
+
* - `:slug?` → `([^/]+)?` - Optional dynamic parameter
|
|
59
|
+
* - `*` → `(.*)` - Wildcard/splat (catches everything)
|
|
60
|
+
*
|
|
61
|
+
* **Dollar syntax** (TanStack Start):
|
|
62
|
+
* - `$slug` → `([^/]+)` - Required dynamic parameter
|
|
63
|
+
* - `$` (at end) → `(.*)` - Wildcard/splat
|
|
64
|
+
*
|
|
65
|
+
* **Bracket syntax** (Next.js, Nuxt, SvelteKit):
|
|
66
|
+
* - `[slug]` → `([^/]+)` - Required dynamic parameter
|
|
67
|
+
* - `[[slug]]` → `([^/]+)?` - Optional dynamic parameter
|
|
68
|
+
* - `[...slug]` → `(.*)` - Catch-all
|
|
69
|
+
* - `[[...slug]]` → `(.*)?` - Optional catch-all
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Colon syntax
|
|
73
|
+
* routeToRegex("/blog/:slug") // "^/blog/([^/]+)/?$"
|
|
74
|
+
* routeToRegex("/files/*") // "^/files(?:/(.*))?$"
|
|
75
|
+
*
|
|
76
|
+
* // Dollar syntax
|
|
77
|
+
* routeToRegex("/blog/$slug") // "^/blog/([^/]+)/?$"
|
|
78
|
+
* routeToRegex("/files/$") // "^/files(?:/(.*))?$"
|
|
79
|
+
*
|
|
80
|
+
* // Bracket syntax
|
|
81
|
+
* routeToRegex("/blog/[slug]") // "^/blog/([^/]+)/?$"
|
|
82
|
+
* routeToRegex("/files/[...path]") // "^/files(?:/(.*))?$"
|
|
83
|
+
*/
|
|
84
|
+
export function routeToRegex(routePath, options = {}) {
|
|
85
|
+
const { syntax = "auto", trailingSlashOptional = true, anchored = true, } = options;
|
|
86
|
+
// Determine which syntax to use
|
|
87
|
+
const effectiveSyntax = syntax === "auto" ? detectRouteSyntax(routePath) : syntax;
|
|
88
|
+
// Escape special regex characters (except those we'll handle)
|
|
89
|
+
let pattern = routePath.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
90
|
+
// Handle syntax-specific patterns
|
|
91
|
+
switch (effectiveSyntax) {
|
|
92
|
+
case "dollar":
|
|
93
|
+
pattern = convertDollarSyntax(pattern);
|
|
94
|
+
break;
|
|
95
|
+
case "bracket":
|
|
96
|
+
pattern = convertBracketSyntax(pattern);
|
|
97
|
+
break;
|
|
98
|
+
case "colon":
|
|
99
|
+
default:
|
|
100
|
+
pattern = convertColonSyntax(pattern);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
// Add trailing slash handling
|
|
104
|
+
if (trailingSlashOptional && !pattern.endsWith(")?$") && !pattern.endsWith(")?")) {
|
|
105
|
+
pattern = pattern + "/?";
|
|
106
|
+
}
|
|
107
|
+
// Add anchors
|
|
108
|
+
if (anchored) {
|
|
109
|
+
if (!pattern.startsWith("^")) {
|
|
110
|
+
pattern = "^" + pattern;
|
|
111
|
+
}
|
|
112
|
+
if (!pattern.endsWith("$")) {
|
|
113
|
+
pattern = pattern + "$";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return pattern;
|
|
117
|
+
}
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Syntax Converters
|
|
120
|
+
// ============================================================================
|
|
121
|
+
/**
|
|
122
|
+
* Convert colon syntax patterns (:param)
|
|
123
|
+
* Used by: React Router, Remix, Express, Vue Router
|
|
124
|
+
* - :param → ([^/]+)
|
|
125
|
+
* - :param? → ([^/]+)?
|
|
126
|
+
* - * → (.*)
|
|
127
|
+
*/
|
|
128
|
+
function convertColonSyntax(pattern) {
|
|
129
|
+
// Handle wildcard * at the end (splat route)
|
|
130
|
+
// /files/* → /files(?:/(.*))?
|
|
131
|
+
// Note: * is NOT escaped by the caller, so we match literal *
|
|
132
|
+
if (/\/\*$/.test(pattern) || pattern === "*") {
|
|
133
|
+
pattern = pattern.replace(/\/?\*$/, "(?:/(.*))?");
|
|
134
|
+
}
|
|
135
|
+
else if (/\*/.test(pattern)) {
|
|
136
|
+
// Handle inline * (rare but possible)
|
|
137
|
+
pattern = pattern.replace(/\*/g, "(.*)");
|
|
138
|
+
}
|
|
139
|
+
// Handle optional parameters :param?
|
|
140
|
+
pattern = pattern.replace(/:(\w+)\?/g, "([^/]+)?");
|
|
141
|
+
// Handle required parameters :param
|
|
142
|
+
pattern = pattern.replace(/:(\w+)/g, "([^/]+)");
|
|
143
|
+
return pattern;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Convert dollar syntax patterns ($param)
|
|
147
|
+
* Used by: TanStack Start
|
|
148
|
+
* - $param → ([^/]+)
|
|
149
|
+
* - $ (at end, lone) → (.*)
|
|
150
|
+
*/
|
|
151
|
+
function convertDollarSyntax(pattern) {
|
|
152
|
+
// Handle splat $ at the end: /files/$ → /files(?:/(.*))?
|
|
153
|
+
// Match /$ at end or lone $
|
|
154
|
+
if (pattern.endsWith("/\\$") || pattern === "\\$") {
|
|
155
|
+
pattern = pattern.replace(/\/?\\\$$/, "(?:/(.*))?");
|
|
156
|
+
}
|
|
157
|
+
else if (pattern.endsWith("\\$")) {
|
|
158
|
+
// Handle $ at end without leading slash
|
|
159
|
+
pattern = pattern.replace(/\\\$$/, "(?:/(.*))?");
|
|
160
|
+
}
|
|
161
|
+
// Handle named parameters $param (not lone $)
|
|
162
|
+
// Must be careful not to match already-converted patterns
|
|
163
|
+
pattern = pattern.replace(/\\\$(\w+)/g, "([^/]+)");
|
|
164
|
+
return pattern;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Convert bracket syntax patterns ([param])
|
|
168
|
+
* Used by: Next.js, Nuxt, SvelteKit
|
|
169
|
+
* - [param] → ([^/]+)
|
|
170
|
+
* - [[param]] → ([^/]+)?
|
|
171
|
+
* - [...param] → (.*)
|
|
172
|
+
* - [[...param]] → (.*)?
|
|
173
|
+
*/
|
|
174
|
+
function convertBracketSyntax(pattern) {
|
|
175
|
+
// Handle optional catch-all [[...param]]
|
|
176
|
+
pattern = pattern.replace(/\\\[\\\[\\\.\\\.\\\.(\w+)\\\]\\\]/g, "(.*)?");
|
|
177
|
+
// Handle catch-all [...param]
|
|
178
|
+
pattern = pattern.replace(/\\\[\\\.\\\.\\\.(\w+)\\\]/g, "(?:/(.*))?");
|
|
179
|
+
// Handle optional dynamic [[param]]
|
|
180
|
+
pattern = pattern.replace(/\\\[\\\[(\w+)\\\]\\\]/g, "([^/]+)?");
|
|
181
|
+
// Handle required dynamic [param]
|
|
182
|
+
pattern = pattern.replace(/\\\[(\w+)\\\]/g, "([^/]+)");
|
|
183
|
+
return pattern;
|
|
184
|
+
}
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// Route Array Utilities
|
|
187
|
+
// ============================================================================
|
|
188
|
+
/**
|
|
189
|
+
* Add regex patterns to routes that contain dynamic segments
|
|
190
|
+
*
|
|
191
|
+
* This function processes an array of RouteInfo and adds the `regex` field
|
|
192
|
+
* to routes that contain dynamic parameters.
|
|
193
|
+
*
|
|
194
|
+
* @param routes - Array of route info objects
|
|
195
|
+
* @param options - Options for regex conversion
|
|
196
|
+
* @returns Routes with regex patterns added where applicable
|
|
197
|
+
*/
|
|
198
|
+
export function addRegexToRoutes(routes, options = {}) {
|
|
199
|
+
return routes.map(route => {
|
|
200
|
+
// Use srcRoute if available, otherwise use path
|
|
201
|
+
const routePath = route.srcRoute || route.path;
|
|
202
|
+
// Only add regex for dynamic routes
|
|
203
|
+
if (isDynamicRoute(routePath)) {
|
|
204
|
+
return {
|
|
205
|
+
...route,
|
|
206
|
+
regex: routeToRegex(routePath, options),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return route;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Convert routes to simplified meta.json format
|
|
214
|
+
*
|
|
215
|
+
* This function converts RouteInfo array to MetaRouteInfo array,
|
|
216
|
+
* keeping only `regexPath` and `isStatic` fields for EdgeOne runtime.
|
|
217
|
+
*
|
|
218
|
+
* - Dynamic routes (with parameters like :id, $id, [id]) are converted to regex patterns
|
|
219
|
+
* - Static routes keep their original path without conversion
|
|
220
|
+
*
|
|
221
|
+
* @param routes - Array of route info objects
|
|
222
|
+
* @param options - Options for regex conversion
|
|
223
|
+
* @returns Simplified routes for meta.json
|
|
224
|
+
*/
|
|
225
|
+
export function convertRoutesToMetaFormat(routes, options = {}) {
|
|
226
|
+
return routes.map(route => {
|
|
227
|
+
// Use srcRoute if available, otherwise use path
|
|
228
|
+
const routePath = route.srcRoute || route.path;
|
|
229
|
+
let regexPath;
|
|
230
|
+
if (isDynamicRoute(routePath)) {
|
|
231
|
+
// Dynamic route: convert to regex pattern
|
|
232
|
+
regexPath = routeToRegex(routePath, options);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// Static route: keep original path, no conversion needed
|
|
236
|
+
regexPath = routePath;
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
regexPath,
|
|
240
|
+
isStatic: route.isStatic,
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.js","sourceRoot":"","sources":["../../src/route/regex.ts"],"names":[],"mappings":"A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AACL,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Types - Type definitions for route parsing
|
|
3
|
+
*/
|
|
4
|
+
import type { RouteInfo } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generic route node structure
|
|
7
|
+
*/
|
|
8
|
+
export interface RouteNode {
|
|
9
|
+
id: string;
|
|
10
|
+
path?: string;
|
|
11
|
+
index?: boolean;
|
|
12
|
+
parentId?: string;
|
|
13
|
+
children?: RouteNode[];
|
|
14
|
+
hasLoader?: boolean;
|
|
15
|
+
hasAction?: boolean;
|
|
16
|
+
hasClientLoader?: boolean;
|
|
17
|
+
hasClientAction?: boolean;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Internal route info with additional properties for parsing
|
|
22
|
+
* This extends RouteInfo with optional properties used during route parsing
|
|
23
|
+
*/
|
|
24
|
+
export interface InternalRouteInfo extends RouteInfo {
|
|
25
|
+
/** Route identifier */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** Full path including parent paths */
|
|
28
|
+
fullPath?: string;
|
|
29
|
+
/** Source file path */
|
|
30
|
+
filePath?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Route parser configuration
|
|
34
|
+
*/
|
|
35
|
+
export interface RouteParserConfig {
|
|
36
|
+
/** Convert file path patterns to route paths (e.g., $id -> :id) */
|
|
37
|
+
paramPattern?: RegExp;
|
|
38
|
+
/** Replacement for param pattern */
|
|
39
|
+
paramReplacement?: string;
|
|
40
|
+
/** Index route file names */
|
|
41
|
+
indexFiles?: string[];
|
|
42
|
+
/** Layout/root route file names to skip */
|
|
43
|
+
layoutFiles?: string[];
|
|
44
|
+
/** File extensions to include */
|
|
45
|
+
extensions?: string[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Route tree parser options
|
|
49
|
+
*/
|
|
50
|
+
export interface RouteTreeParserOptions {
|
|
51
|
+
/** Path pattern regex to extract routes */
|
|
52
|
+
pathPattern?: RegExp;
|
|
53
|
+
/** Full path pattern regex */
|
|
54
|
+
fullPathPattern?: RegExp;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Server build route source configuration
|
|
58
|
+
*/
|
|
59
|
+
export interface ServerBuildRouteSource {
|
|
60
|
+
type: "serverBuild";
|
|
61
|
+
/** Server entry path */
|
|
62
|
+
serverEntry: string;
|
|
63
|
+
/** Property path to routes object (e.g., "routes") */
|
|
64
|
+
routesProperty?: string;
|
|
65
|
+
/** Transform function for route nodes */
|
|
66
|
+
transform?: (routes: Record<string, RouteNode>) => RouteInfo[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Route tree file source configuration
|
|
70
|
+
*/
|
|
71
|
+
export interface RouteTreeFileSource {
|
|
72
|
+
type: "routeTree";
|
|
73
|
+
/** Candidate paths for route tree file */
|
|
74
|
+
paths: string[];
|
|
75
|
+
/** Parser options */
|
|
76
|
+
parserOptions?: RouteTreeParserOptions;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Directory scan source configuration
|
|
80
|
+
*/
|
|
81
|
+
export interface DirectoryScanSource {
|
|
82
|
+
type: "directory";
|
|
83
|
+
/** Candidate directories to scan */
|
|
84
|
+
paths: string[];
|
|
85
|
+
/** Parser configuration */
|
|
86
|
+
config?: RouteParserConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Route source configuration union type
|
|
90
|
+
*/
|
|
91
|
+
export type RouteSource = ServerBuildRouteSource | RouteTreeFileSource | DirectoryScanSource;
|
|
92
|
+
/**
|
|
93
|
+
* Options for flattenRouteTree function
|
|
94
|
+
*/
|
|
95
|
+
export interface FlattenRouteTreeOptions {
|
|
96
|
+
/** Parent path prefix */
|
|
97
|
+
parentPath?: string;
|
|
98
|
+
/** Whether SSR mode is enabled */
|
|
99
|
+
isSSR?: boolean;
|
|
100
|
+
/** Whether SPA mode is enabled */
|
|
101
|
+
isSpaMode?: boolean;
|
|
102
|
+
/** Root route ID to skip (default: "root") */
|
|
103
|
+
skipRootId?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Custom callback to generate additional routes for each route node.
|
|
106
|
+
* This allows framework-specific route generation (e.g., .data routes for React Router).
|
|
107
|
+
* Return an array of additional RouteInfo to add, or empty array for none.
|
|
108
|
+
*/
|
|
109
|
+
onRouteProcessed?: (route: RouteNode, routePath: string, isStatic: boolean) => RouteInfo[];
|
|
110
|
+
/**
|
|
111
|
+
* Custom callback to determine if a route should be static.
|
|
112
|
+
* If not provided, uses default logic based on isSSR, isSpaMode, and client loaders.
|
|
113
|
+
*/
|
|
114
|
+
isStaticRoute?: (route: RouteNode, isSSR: boolean, isSpaMode: boolean) => boolean;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/route/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD,uBAAuB;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,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AAW,GAAG,sBAAsB,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAM7F;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kCAAkC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;IAC3F;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC;CACnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/route/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/route-parser.d.ts
CHANGED
|
@@ -1,163 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Route Parser -
|
|
2
|
+
* Route Parser - Re-exports from route module
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* @deprecated Import from "./route/index.js" instead
|
|
5
|
+
* This file is kept for backward compatibility.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Generic route node structure
|
|
10
|
-
*/
|
|
11
|
-
export interface RouteNode {
|
|
12
|
-
id: string;
|
|
13
|
-
path?: string;
|
|
14
|
-
index?: boolean;
|
|
15
|
-
parentId?: string;
|
|
16
|
-
children?: RouteNode[];
|
|
17
|
-
hasLoader?: boolean;
|
|
18
|
-
hasAction?: boolean;
|
|
19
|
-
hasClientLoader?: boolean;
|
|
20
|
-
hasClientAction?: boolean;
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Route parser configuration
|
|
25
|
-
*/
|
|
26
|
-
export interface RouteParserConfig {
|
|
27
|
-
/** Convert file path patterns to route paths (e.g., $id -> :id) */
|
|
28
|
-
paramPattern?: RegExp;
|
|
29
|
-
/** Replacement for param pattern */
|
|
30
|
-
paramReplacement?: string;
|
|
31
|
-
/** Index route file names */
|
|
32
|
-
indexFiles?: string[];
|
|
33
|
-
/** Layout/root route file names to skip */
|
|
34
|
-
layoutFiles?: string[];
|
|
35
|
-
/** File extensions to include */
|
|
36
|
-
extensions?: string[];
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Route tree parser options
|
|
40
|
-
*/
|
|
41
|
-
export interface RouteTreeParserOptions {
|
|
42
|
-
/** Path pattern regex to extract routes */
|
|
43
|
-
pathPattern?: RegExp;
|
|
44
|
-
/** Full path pattern regex */
|
|
45
|
-
fullPathPattern?: RegExp;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Server build route source configuration
|
|
49
|
-
*/
|
|
50
|
-
export interface ServerBuildRouteSource {
|
|
51
|
-
type: "serverBuild";
|
|
52
|
-
/** Server entry path */
|
|
53
|
-
serverEntry: string;
|
|
54
|
-
/** Property path to routes object (e.g., "routes") */
|
|
55
|
-
routesProperty?: string;
|
|
56
|
-
/** Transform function for route nodes */
|
|
57
|
-
transform?: (routes: Record<string, RouteNode>) => RouteInfo[];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Route tree file source configuration
|
|
61
|
-
*/
|
|
62
|
-
export interface RouteTreeFileSource {
|
|
63
|
-
type: "routeTree";
|
|
64
|
-
/** Candidate paths for route tree file */
|
|
65
|
-
paths: string[];
|
|
66
|
-
/** Parser options */
|
|
67
|
-
parserOptions?: RouteTreeParserOptions;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Directory scan source configuration
|
|
71
|
-
*/
|
|
72
|
-
export interface DirectoryScanSource {
|
|
73
|
-
type: "directory";
|
|
74
|
-
/** Candidate directories to scan */
|
|
75
|
-
paths: string[];
|
|
76
|
-
/** Parser configuration */
|
|
77
|
-
config?: RouteParserConfig;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Route source configuration union type
|
|
81
|
-
*/
|
|
82
|
-
export type RouteSource = ServerBuildRouteSource | RouteTreeFileSource | DirectoryScanSource;
|
|
83
|
-
/**
|
|
84
|
-
* Parse routes from route tree file content
|
|
85
|
-
*/
|
|
86
|
-
export declare function parseRouteTreeContent(content: string, options?: RouteTreeParserOptions): InternalRouteInfo[];
|
|
87
|
-
/**
|
|
88
|
-
* Load and parse route tree from file
|
|
89
|
-
*/
|
|
90
|
-
export declare function parseRouteTreeFile(projectRoot: string, candidatePaths: string[], options?: RouteTreeParserOptions, logger?: Logger): Promise<InternalRouteInfo[]>;
|
|
91
|
-
/**
|
|
92
|
-
* Scan directory for route files
|
|
93
|
-
*/
|
|
94
|
-
export declare function scanRoutesDirectory(dir: string, basePath?: string, config?: RouteParserConfig): Promise<InternalRouteInfo[]>;
|
|
95
|
-
/**
|
|
96
|
-
* Scan multiple candidate directories for routes
|
|
97
|
-
*/
|
|
98
|
-
export declare function scanRoutesFromDirectories(projectRoot: string, candidateDirs: string[], config?: RouteParserConfig, logger?: Logger): Promise<InternalRouteInfo[]>;
|
|
99
|
-
/**
|
|
100
|
-
* Load server build module and extract routes
|
|
101
|
-
*/
|
|
102
|
-
export declare function loadServerBuildRoutes<T = unknown>(serverEntryPath: string, logger?: Logger): Promise<T | null>;
|
|
103
|
-
/**
|
|
104
|
-
* Options for flattenRouteTree function
|
|
105
|
-
*/
|
|
106
|
-
export interface FlattenRouteTreeOptions {
|
|
107
|
-
/** Parent path prefix */
|
|
108
|
-
parentPath?: string;
|
|
109
|
-
/** Whether SSR mode is enabled */
|
|
110
|
-
isSSR?: boolean;
|
|
111
|
-
/** Whether SPA mode is enabled */
|
|
112
|
-
isSpaMode?: boolean;
|
|
113
|
-
/** Root route ID to skip (default: "root") */
|
|
114
|
-
skipRootId?: string;
|
|
115
|
-
/**
|
|
116
|
-
* Custom callback to generate additional routes for each route node.
|
|
117
|
-
* This allows framework-specific route generation (e.g., .data routes for React Router).
|
|
118
|
-
* Return an array of additional RouteInfo to add, or empty array for none.
|
|
119
|
-
*/
|
|
120
|
-
onRouteProcessed?: (route: RouteNode, routePath: string, isStatic: boolean) => RouteInfo[];
|
|
121
|
-
/**
|
|
122
|
-
* Custom callback to determine if a route should be static.
|
|
123
|
-
* If not provided, uses default logic based on isSSR, isSpaMode, and client loaders.
|
|
124
|
-
*/
|
|
125
|
-
isStaticRoute?: (route: RouteNode, isSSR: boolean, isSpaMode: boolean) => boolean;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Flatten nested route tree to flat route list
|
|
129
|
-
*
|
|
130
|
-
* This is a generic utility that works with any route tree structure.
|
|
131
|
-
* Framework-specific behavior (like generating .data routes) should be
|
|
132
|
-
* implemented via the onRouteProcessed callback.
|
|
133
|
-
*/
|
|
134
|
-
export declare function flattenRouteTree(routes: Record<string, RouteNode>, options?: FlattenRouteTreeOptions): RouteInfo[];
|
|
135
|
-
/**
|
|
136
|
-
* Parse routes from multiple sources with fallback
|
|
137
|
-
*/
|
|
138
|
-
export declare function parseRoutesFromSources(projectRoot: string, sources: RouteSource[], options?: {
|
|
139
|
-
isSSR?: boolean;
|
|
140
|
-
logger?: Logger;
|
|
141
|
-
}): Promise<RouteInfo[]>;
|
|
142
|
-
/**
|
|
143
|
-
* Internal route info with additional properties for parsing
|
|
144
|
-
* This extends RouteInfo with optional properties used during route parsing
|
|
145
|
-
*/
|
|
146
|
-
export interface InternalRouteInfo extends RouteInfo {
|
|
147
|
-
/** Route identifier */
|
|
148
|
-
id?: string;
|
|
149
|
-
/** Full path including parent paths */
|
|
150
|
-
fullPath?: string;
|
|
151
|
-
/** Source file path */
|
|
152
|
-
filePath?: string;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Convert internal route info to standard RouteInfo
|
|
156
|
-
* Strips internal-only properties
|
|
157
|
-
*/
|
|
158
|
-
export declare function toRouteInfo(internal: InternalRouteInfo): RouteInfo;
|
|
159
|
-
/**
|
|
160
|
-
* Convert array of internal route info to standard RouteInfo array
|
|
161
|
-
*/
|
|
162
|
-
export declare function toRouteInfoArray(internals: InternalRouteInfo[]): RouteInfo[];
|
|
7
|
+
export * from "./route/index.js";
|
|
163
8
|
//# sourceMappingURL=route-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-parser.d.ts","sourceRoot":"","sources":["../src/route-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"route-parser.d.ts","sourceRoot":"","sources":["../src/route-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,kBAAkB,CAAC"}
|